Fixed releasing PCI resources after a driver terminates.

This commit is contained in:
Philip Homburg 2007-04-24 12:55:37 +00:00
parent ac64c1b3dc
commit 0dc0d3fe5b
3 changed files with 15 additions and 62 deletions

View file

@ -11,12 +11,6 @@ main.c
#define NR_DRIVERS 16 #define NR_DRIVERS 16
PRIVATE struct name
{
char name[M3_STRING];
int tasknr;
} names[NR_DRIVERS];
PRIVATE struct acl PRIVATE struct acl
{ {
int inuse; int inuse;
@ -55,9 +49,6 @@ int main(void)
pci_init(); pci_init();
for (i= 0; i<NR_DRIVERS; i++)
names[i].tasknr= ANY;
for(;;) for(;;)
{ {
r= receive(ANY, &m); r= receive(ANY, &m);
@ -118,35 +109,11 @@ PRIVATE void do_sig_handler()
PRIVATE void do_init(mp) PRIVATE void do_init(mp)
message *mp; message *mp;
{ {
int i, r, empty; int r;
#if DEBUG #if DEBUG
printf("PCI: pci_init: called by '%s'\n", mp->m3_ca1); printf("PCI: pci_init: called by '%d'\n", mp->m_source);
#endif #endif
empty= -1;
for (i= 0; i<NR_DRIVERS; i++)
{
if (empty == -1 && names[i].tasknr == ANY)
empty= i;
if (strcmp(names[i].name, mp->m3_ca1) == 0)
break;
}
if (i >= NR_DRIVERS)
{
if (empty == -1)
panic("pci", "do_init: too many clients", NR_DRIVERS);
i= empty;
strcpy(names[i].name, mp->m3_ca1);
}
else if (names[i].tasknr == mp->m_source)
{
/* Ignore all init calls for a process after the first one */
}
#if 0
else
pci_release(names[i].name);
#endif
names[i].tasknr= mp->m_source;
mp->m_type= 0; mp->m_type= 0;
r= send(mp->m_source, mp); r= send(mp->m_source, mp);
@ -457,6 +424,9 @@ message *mp;
printf("do_acl: deleting ACL for %d ('%s') at entry %d\n", printf("do_acl: deleting ACL for %d ('%s') at entry %d\n",
acl[i].acl.rsp_endpoint, acl[i].acl.rsp_label, i); acl[i].acl.rsp_endpoint, acl[i].acl.rsp_label, i);
/* Also release all devices held by this process */
pci_release(proc_nr);
reply(mp, OK); reply(mp, OK);
} }
@ -465,23 +435,9 @@ message *mp;
{ {
int i, r, devind; int i, r, devind;
/* Find the name of the caller */
for (i= 0; i<NR_DRIVERS; i++)
{
if (names[i].tasknr == mp->m_source)
break;
}
if (i >= NR_DRIVERS)
{
printf("pci`do_reserve: task %d did not call pci_init\n",
mp->m_source);
return;
}
devind= mp->m1_i1; devind= mp->m1_i1;
mp->m_type= pci_reserve2(devind, mp->m_source);
mp->m_type= pci_reserve3(devind, mp->m_source, names[i].name);
r= send(mp->m_source, mp); r= send(mp->m_source, mp);
if (r != 0) if (r != 0)
{ {

View file

@ -76,7 +76,9 @@ PRIVATE struct pcidev
u16_t pd_vid; u16_t pd_vid;
u16_t pd_did; u16_t pd_did;
u8_t pd_ilr; u8_t pd_ilr;
u8_t pd_inuse; u8_t pd_inuse;
endpoint_t pd_proc;
struct bar struct bar
{ {
@ -86,8 +88,6 @@ PRIVATE struct pcidev
u32_t pb_size; u32_t pb_size;
} pd_bar[BAM_NR]; } pd_bar[BAM_NR];
int pd_bar_nr; int pd_bar_nr;
char pd_name[M3_STRING];
} pcidev[NR_PCIDEV]; } pcidev[NR_PCIDEV];
/* pb_flags */ /* pb_flags */
@ -312,10 +312,9 @@ u16_t *didp;
/*===========================================================================* /*===========================================================================*
* pci_reserve3 * * pci_reserve3 *
*===========================================================================*/ *===========================================================================*/
PUBLIC int pci_reserve3(devind, proc, name) PUBLIC int pci_reserve2(devind, proc)
int devind; int devind;
int proc; int proc;
char *name;
{ {
int i, r; int i, r;
u8_t ilr; u8_t ilr;
@ -326,7 +325,7 @@ char *name;
if(pcidev[devind].pd_inuse) if(pcidev[devind].pd_inuse)
return EBUSY; return EBUSY;
pcidev[devind].pd_inuse= 1; pcidev[devind].pd_inuse= 1;
strcpy(pcidev[devind].pd_name, name); pcidev[devind].pd_proc= proc;
for (i= 0; i<pcidev[devind].pd_bar_nr; i++) for (i= 0; i<pcidev[devind].pd_bar_nr; i++)
{ {
@ -387,12 +386,11 @@ char *name;
return OK; return OK;
} }
#if 0
/*===========================================================================* /*===========================================================================*
* pci_release * * pci_release *
*===========================================================================*/ *===========================================================================*/
PUBLIC void pci_release(name) PUBLIC void pci_release(proc)
char *name; endpoint_t proc;
{ {
int i; int i;
@ -400,12 +398,11 @@ char *name;
{ {
if (!pcidev[i].pd_inuse) if (!pcidev[i].pd_inuse)
continue; continue;
if (strcmp(pcidev[i].pd_name, name) != 0) if (pcidev[i].pd_proc != proc)
continue; continue;
pcidev[i].pd_inuse= 0; pcidev[i].pd_inuse= 0;
} }
} }
#endif
/*===========================================================================* /*===========================================================================*
* pci_ids * * pci_ids *

View file

@ -82,8 +82,8 @@ extern struct pci_isabridge pci_isabridge[];
extern struct pci_pcibridge pci_pcibridge[]; extern struct pci_pcibridge pci_pcibridge[];
/* Utility functions */ /* Utility functions */
_PROTOTYPE( int pci_reserve3, (int devind, int proc, char name[M3_STRING])); _PROTOTYPE( int pci_reserve2, (int devind, endpoint_t proc) );
_PROTOTYPE( void pci_release, (char name[M3_STRING]) ); _PROTOTYPE( void pci_release, (endpoint_t proc) );
_PROTOTYPE( int pci_first_dev_a, (struct rs_pci *aclp, int *devindp, _PROTOTYPE( int pci_first_dev_a, (struct rs_pci *aclp, int *devindp,
u16_t *vidp, u16_t *didp) ); u16_t *vidp, u16_t *didp) );
_PROTOTYPE( int pci_next_dev_a, (struct rs_pci *aclp, int *devindp, _PROTOTYPE( int pci_next_dev_a, (struct rs_pci *aclp, int *devindp,