PCI driver cleanup

- Moved to KNF
 - Whitespace cleanup
 - Removed useless static functions prototypes
 - Renamed some file private functions by prepending '__'
 - Renamed some server-specific function by prepending '_'
 - Fixed compilation warning for WARNS= 3

Change-Id: Ie44d35839177d5ee0630cdf576660c852452ab80
This commit is contained in:
Lionel Sambuc 2014-10-14 21:38:39 +02:00
parent 3d3105466a
commit 6e7bb62853
5 changed files with 1889 additions and 2011 deletions

View file

@ -5,4 +5,6 @@ SRCS= main.c pci.c pci_table.c
DPADD+= ${LIBSYS} ${LIBTIMERS}
LDADD+= -lsys -ltimers
WARNS?= 3
.include <minix.service.mk>

View file

@ -1,96 +1,13 @@
/*
main.c
*/
#include <minix/driver.h>
#include <minix/rs.h>
#include "pci.h"
int debug = 0;
struct pci_acl pci_acl[NR_DRIVERS];
static void do_init(message *mp);
static void do_first_dev(message *mp);
static void do_next_dev(message *mp);
static void do_find_dev(message *mp);
static void do_ids(message *mp);
static void do_dev_name_s(message *mp);
static void do_slot_name_s(message *mp);
static void do_set_acl(message *mp);
static void do_del_acl(message *mp);
static void do_reserve(message *mp);
static void do_attr_r8(message *mp);
static void do_attr_r16(message *mp);
static void do_attr_r32(message *mp);
static void do_attr_w8(message *mp);
static void do_attr_w16(message *mp);
static void do_attr_w32(message *mp);
static void do_get_bar(message *mp);
static void do_rescan_bus(message *mp);
static void reply(message *mp, int result);
static struct rs_pci *find_acl(int endpoint);
extern int debug;
/* SEF functions and variables. */
static void sef_local_startup(void);
int main(void)
{
int r;
message m;
int ipc_status;
/* SEF local startup. */
sef_local_startup();
for(;;)
{
r= driver_receive(ANY, &m, &ipc_status);
if (r < 0)
{
printf("PCI: driver_receive failed: %d\n", r);
break;
}
if (is_ipc_notify(ipc_status)) {
printf("PCI: got notify from %d\n", m.m_source);
/* done, get a new message */
continue;
}
switch(m.m_type)
{
case BUSC_PCI_INIT: do_init(&m); break;
case BUSC_PCI_FIRST_DEV: do_first_dev(&m); break;
case BUSC_PCI_NEXT_DEV: do_next_dev(&m); break;
case BUSC_PCI_FIND_DEV: do_find_dev(&m); break;
case BUSC_PCI_IDS: do_ids(&m); break;
case BUSC_PCI_RESERVE: do_reserve(&m); break;
case BUSC_PCI_ATTR_R8: do_attr_r8(&m); break;
case BUSC_PCI_ATTR_R16: do_attr_r16(&m); break;
case BUSC_PCI_ATTR_R32: do_attr_r32(&m); break;
case BUSC_PCI_ATTR_W8: do_attr_w8(&m); break;
case BUSC_PCI_ATTR_W16: do_attr_w16(&m); break;
case BUSC_PCI_ATTR_W32: do_attr_w32(&m); break;
case BUSC_PCI_RESCAN: do_rescan_bus(&m); break;
case BUSC_PCI_DEV_NAME_S: do_dev_name_s(&m); break;
case BUSC_PCI_SLOT_NAME_S: do_slot_name_s(&m); break;
case BUSC_PCI_SET_ACL: do_set_acl(&m); break;
case BUSC_PCI_DEL_ACL: do_del_acl(&m); break;
case BUSC_PCI_GET_BAR: do_get_bar(&m); break;
default:
printf("PCI: got message from %d, type %d\n",
m.m_source, m.m_type);
break;
}
}
return 0;
}
/*===========================================================================*
* sef_local_startup *
*===========================================================================*/
static void sef_local_startup()
static void
sef_local_startup()
{
/* Register init callbacks. */
sef_setcb_init_fresh(sef_cb_init_fresh);
@ -105,8 +22,37 @@ static void sef_local_startup()
sef_startup();
}
static void do_init(mp)
message *mp;
static struct rs_pci *
find_acl(int endpoint)
{
int i;
/* Find ACL entry for caller */
for (i= 0; i<NR_DRIVERS; i++)
{
if (!pci_acl[i].inuse)
continue;
if (pci_acl[i].acl.rsp_endpoint == endpoint)
return &pci_acl[i].acl;
}
return NULL;
}
static void
reply(message *mp, int result)
{
int r;
message m;
m.m_type= result;
r= ipc_send(mp->m_source, &m);
if (r != 0)
printf("reply: unable to send to %d: %d\n", mp->m_source, r);
}
static void
do_init(message *mp)
{
int r;
@ -121,7 +67,8 @@ message *mp;
mp->m_source, r);
}
static void do_first_dev(message *mp)
static void
do_first_dev(message *mp)
{
int r, devind;
u16_t vid, did;
@ -133,7 +80,7 @@ static void do_first_dev(message *mp)
printf("PCI: do_first_dev: no acl for caller %d\n",
mp->m_source);
r= pci_first_dev_a(aclp, &devind, &vid, &did);
r= _pci_first_dev(aclp, &devind, &vid, &did);
if (r == 1)
{
mp->m1_i1= devind;
@ -149,7 +96,8 @@ static void do_first_dev(message *mp)
}
}
static void do_next_dev(message *mp)
static void
do_next_dev(message *mp)
{
int r, devind;
u16_t vid, did;
@ -158,7 +106,7 @@ static void do_next_dev(message *mp)
devind= mp->m1_i1;
aclp= find_acl(mp->m_source);
r= pci_next_dev_a(aclp, &devind, &vid, &did);
r= _pci_next_dev(aclp, &devind, &vid, &did);
if (r == 1)
{
mp->m1_i1= devind;
@ -174,8 +122,8 @@ static void do_next_dev(message *mp)
}
}
static void do_find_dev(mp)
message *mp;
static void
do_find_dev(message *mp)
{
int r, devind;
u8_t bus, dev, func;
@ -184,7 +132,7 @@ message *mp;
dev= mp->m1_i2;
func= mp->m1_i3;
r= pci_find_dev(bus, dev, func, &devind);
r= _pci_find_dev(bus, dev, func, &devind);
if (r == 1)
mp->m1_i1= devind;
mp->m_type= r;
@ -196,15 +144,15 @@ message *mp;
}
}
static void do_ids(mp)
message *mp;
static void
do_ids(message *mp)
{
int r, devind;
u16_t vid, did;
devind= mp->m1_i1;
r= pci_ids_s(devind, &vid, &did);
r= _pci_ids(devind, &vid, &did);
if (r != OK)
{
printf("pci:do_ids: failed for devind %d: %d\n",
@ -222,20 +170,20 @@ message *mp;
}
}
static void do_dev_name_s(mp)
message *mp;
static void
do_dev_name(message *mp)
{
int r, name_len, len;
u16_t vid, did;
cp_grant_id_t name_gid;
char *name;
const char *name;
vid= mp->m7_i1;
did= mp->m7_i2;
name_len= mp->m7_i3;
name_gid= mp->m7_i4;
name= pci_dev_name(vid, did);
name= _pci_dev_name(vid, did);
if (name == NULL)
{
/* No name */
@ -259,8 +207,8 @@ message *mp;
}
}
static void do_slot_name_s(mp)
message *mp;
static void
do_slot_name(message *mp)
{
int r, devind, name_len, len;
cp_grant_id_t gid;
@ -270,7 +218,7 @@ message *mp;
name_len= mp->m1_i2;
gid= mp->m1_i3;
r= pci_slot_name_s(devind, &name);
r= _pci_slot_name(devind, &name);
if (r != OK)
{
printf("pci:do_slot_name_s: failed for devind %d: %d\n",
@ -295,8 +243,8 @@ message *mp;
}
}
static void do_set_acl(mp)
message *mp;
static void
do_set_acl(message *mp)
{
int i, r, gid;
@ -338,7 +286,8 @@ message *mp;
reply(mp, OK);
}
static void do_del_acl(message *mp)
static void
do_del_acl(message *mp)
{
int i, proc_nr;
@ -373,12 +322,13 @@ static void do_del_acl(message *mp)
#endif
/* Also release all devices held by this process */
pci_release(proc_nr);
_pci_release(proc_nr);
reply(mp, OK);
}
static void do_reserve(message *mp)
static void
do_reserve(message *mp)
{
struct rs_pci *aclp;
int r, devind;
@ -387,7 +337,7 @@ static void do_reserve(message *mp)
aclp= find_acl(mp->m_source);
mp->m_type= pci_reserve_a(devind, mp->m_source, aclp);
mp->m_type= _pci_reserve(devind, mp->m_source, aclp);
r= ipc_send(mp->m_source, mp);
if (r != 0)
{
@ -396,8 +346,8 @@ static void do_reserve(message *mp)
}
}
static void do_attr_r8(mp)
message *mp;
static void
do_attr_r8(message *mp)
{
int r, devind, port;
u8_t v;
@ -405,11 +355,11 @@ message *mp;
devind= mp->m2_i1;
port= mp->m2_i2;
r= pci_attr_r8_s(devind, port, &v);
r= _pci_attr_r8(devind, port, &v);
if (r != OK)
{
printf(
"pci:do_attr_r8: pci_attr_r8_s(%d, %d, ...) failed: %d\n",
"pci:do_attr_r8: pci_attr_r8(%d, %d, ...) failed: %d\n",
devind, port, r);
}
mp->m2_l1= v;
@ -422,16 +372,22 @@ message *mp;
}
}
static void do_attr_r16(mp)
message *mp;
static void
do_attr_r16(message *mp)
{
int r, devind, port;
u32_t v;
u16_t v;
devind= mp->m2_i1;
port= mp->m2_i2;
v= pci_attr_r16(devind, port);
r= _pci_attr_r16(devind, port, &v);
if (r != OK)
{
printf(
"pci:do_attr_r16: pci_attr_r16(%d, %d, ...) failed: %d\n",
devind, port, r);
}
mp->m2_l1= v;
mp->m_type= OK;
r= ipc_send(mp->m_source, mp);
@ -442,8 +398,8 @@ message *mp;
}
}
static void do_attr_r32(mp)
message *mp;
static void
do_attr_r32(message *mp)
{
int r, devind, port;
u32_t v;
@ -451,11 +407,11 @@ message *mp;
devind= mp->m2_i1;
port= mp->m2_i2;
r= pci_attr_r32_s(devind, port, &v);
r= _pci_attr_r32(devind, port, &v);
if (r != OK)
{
printf(
"pci:do_attr_r32: pci_attr_r32_s(%d, %d, ...) failed: %d\n",
"pci:do_attr_r32: pci_attr_r32(%d, %d, ...) failed: %d\n",
devind, port, r);
}
mp->m2_l1= v;
@ -468,8 +424,8 @@ message *mp;
}
}
static void do_attr_w8(mp)
message *mp;
static void
do_attr_w8(message *mp)
{
int r, devind, port;
u8_t v;
@ -478,7 +434,7 @@ message *mp;
port= mp->m2_i2;
v= mp->m2_l1;
pci_attr_w8(devind, port, v);
_pci_attr_w8(devind, port, v);
mp->m_type= OK;
r= ipc_send(mp->m_source, mp);
if (r != 0)
@ -488,8 +444,8 @@ message *mp;
}
}
static void do_attr_w16(mp)
message *mp;
static void
do_attr_w16(message *mp)
{
int r, devind, port;
u16_t v;
@ -498,7 +454,7 @@ message *mp;
port= mp->m2_i2;
v= mp->m2_l1;
pci_attr_w16(devind, port, v);
_pci_attr_w16(devind, port, v);
mp->m_type= OK;
r= ipc_send(mp->m_source, mp);
if (r != 0)
@ -508,8 +464,8 @@ message *mp;
}
}
static void do_attr_w32(mp)
message *mp;
static void
do_attr_w32(message *mp)
{
int r, devind, port;
u32_t v;
@ -518,7 +474,7 @@ message *mp;
port= mp->m2_i2;
v= mp->m2_l1;
pci_attr_w32(devind, port, v);
_pci_attr_w32(devind, port, v);
mp->m_type= OK;
r= ipc_send(mp->m_source, mp);
if (r != 0)
@ -528,8 +484,8 @@ message *mp;
}
}
static void do_get_bar(mp)
message *mp;
static void
do_get_bar(message *mp)
{
int r, devind, port, ioflag;
u32_t base, size;
@ -537,7 +493,7 @@ message *mp;
devind= mp->m_lsys_pci_busc_get_bar.devind;
port= mp->m_lsys_pci_busc_get_bar.port;
mp->m_type= pci_get_bar_s(devind, port, &base, &size, &ioflag);
mp->m_type= _pci_get_bar(devind, port, &base, &size, &ioflag);
if (mp->m_type == OK)
{
@ -554,14 +510,14 @@ message *mp;
}
}
static void do_rescan_bus(mp)
message *mp;
static void
do_rescan_bus(message *mp)
{
int r, busnr;
busnr= mp->m2_i1;
pci_rescan_bus(busnr);
_pci_rescan_bus(busnr);
mp->m_type= OK;
r= ipc_send(mp->m_source, mp);
if (r != 0)
@ -571,33 +527,58 @@ message *mp;
}
}
static void reply(mp, result)
message *mp;
int result;
int
main(void)
{
int r;
message m;
int ipc_status;
m.m_type= result;
r= ipc_send(mp->m_source, &m);
if (r != 0)
printf("reply: unable to send to %d: %d\n", mp->m_source, r);
}
/* SEF local startup. */
sef_local_startup();
static struct rs_pci *find_acl(endpoint)
int endpoint;
{
int i;
/* Find ACL entry for caller */
for (i= 0; i<NR_DRIVERS; i++)
for(;;)
{
if (!pci_acl[i].inuse)
r= driver_receive(ANY, &m, &ipc_status);
if (r < 0)
{
printf("PCI: driver_receive failed: %d\n", r);
break;
}
if (is_ipc_notify(ipc_status)) {
printf("PCI: got notify from %d\n", m.m_source);
/* done, get a new message */
continue;
if (pci_acl[i].acl.rsp_endpoint == endpoint)
return &pci_acl[i].acl;
}
switch(m.m_type)
{
case BUSC_PCI_INIT: do_init(&m); break;
case BUSC_PCI_FIRST_DEV: do_first_dev(&m); break;
case BUSC_PCI_NEXT_DEV: do_next_dev(&m); break;
case BUSC_PCI_FIND_DEV: do_find_dev(&m); break;
case BUSC_PCI_IDS: do_ids(&m); break;
case BUSC_PCI_RESERVE: do_reserve(&m); break;
case BUSC_PCI_ATTR_R8: do_attr_r8(&m); break;
case BUSC_PCI_ATTR_R16: do_attr_r16(&m); break;
case BUSC_PCI_ATTR_R32: do_attr_r32(&m); break;
case BUSC_PCI_ATTR_W8: do_attr_w8(&m); break;
case BUSC_PCI_ATTR_W16: do_attr_w16(&m); break;
case BUSC_PCI_ATTR_W32: do_attr_w32(&m); break;
case BUSC_PCI_RESCAN: do_rescan_bus(&m); break;
case BUSC_PCI_DEV_NAME_S: do_dev_name(&m); break;
case BUSC_PCI_SLOT_NAME_S: do_slot_name(&m); break;
case BUSC_PCI_SET_ACL: do_set_acl(&m); break;
case BUSC_PCI_DEL_ACL: do_del_acl(&m); break;
case BUSC_PCI_GET_BAR: do_get_bar(&m); break;
default:
printf("PCI: got message from %d, type %d\n",
m.m_source, m.m_type);
break;
}
}
return NULL;
return 0;
}

File diff suppressed because it is too large Load diff

View file

@ -4,36 +4,23 @@ pci.h
Created: Jan 2000 by Philip Homburg <philip@cs.vu.nl>
*/
#include <minix/drivers.h>
#include <minix/driver.h>
#include <minix/rs.h>
/* tempory functions: to be replaced later (see pci_intel.h) */
unsigned pci_inb(u16_t port);
unsigned pci_inw(u16_t port);
unsigned pci_inl(u16_t port);
void pci_outb(u16_t port, u8_t value);
void pci_outw(u16_t port, u16_t value);
void pci_outl(u16_t port, u32_t value);
struct pci_vendor
{
u16_t vid;
char *name;
const char *name;
};
struct pci_device
{
u16_t vid;
u16_t did;
char *name;
const char *name;
};
struct pci_baseclass
{
u8_t baseclass;
char *name;
const char *name;
};
struct pci_subclass
@ -41,7 +28,7 @@ struct pci_subclass
u8_t baseclass;
u8_t subclass;
u16_t infclass;
char *name;
const char *name;
};
struct pci_intel_ctrl
@ -83,6 +70,8 @@ struct pci_acl
/* Still needed? */
#define PCI_AGPB_VIA 3 /* VIA compatible AGP bridge */
extern int debug;
extern struct pci_vendor pci_vendor_table[];
extern struct pci_device pci_device_table[];
extern struct pci_baseclass pci_baseclass_table[];
@ -92,24 +81,36 @@ extern struct pci_intel_ctrl pci_intel_ctrl[];
#endif
extern struct pci_isabridge pci_isabridge[];
extern struct pci_pcibridge pci_pcibridge[];
extern struct pci_acl pci_acl[NR_DRIVERS];
/* Function prototypes. */
int sef_cb_init_fresh(int type, sef_init_info_t *info);
int map_service(struct rprocpub *rpub);
int pci_reserve_a(int devind, endpoint_t proc, struct rs_pci *aclp);
void pci_release(endpoint_t proc);
int pci_first_dev_a(struct rs_pci *aclp, int *devindp, u16_t *vidp,
int _pci_reserve(int devind, endpoint_t proc, struct rs_pci *aclp);
void _pci_release(endpoint_t proc);
int _pci_first_dev(struct rs_pci *aclp, int *devindp, u16_t *vidp,
u16_t *didp);
int pci_next_dev_a(struct rs_pci *aclp, int *devindp, u16_t *vidp, u16_t
int _pci_next_dev(struct rs_pci *aclp, int *devindp, u16_t *vidp, u16_t
*didp);
int _pci_find_dev(u8_t bus, u8_t dev, u8_t func, int *devindp);
int pci_attr_r8_s(int devind, int port, u8_t *vp);
int pci_attr_r32_s(int devind, int port, u32_t *vp);
int pci_get_bar_s(int devind, int port, u32_t *base, u32_t *size, int
void _pci_rescan_bus(u8_t busnr);
const char *_pci_dev_name(u16_t vid, u16_t did);
int _pci_get_bar(int devind, int port, u32_t *base, u32_t *size, int
*ioflag);
int pci_slot_name_s(int devind, char **cpp);
int pci_ids_s(int devind, u16_t *vidp, u16_t *didp);
int _pci_slot_name(int devind, char **cpp);
int _pci_ids(int devind, u16_t *vidp, u16_t *didp);
/*
* $PchId: pci.h,v 1.4 2001/12/06 20:21:22 philip Exp $
*/
/* PCI Config Read functions */
int _pci_attr_r8(int devind, int port, u8_t *vp);
int _pci_attr_r16(int devind, int port, u16_t *vp);
int _pci_attr_r32(int devind, int port, u32_t *vp);
/* PCI Config Write functions */
int _pci_attr_w8(int devind, int port, u8_t value);
int _pci_attr_w16(int devind, int port, u16_t value);
int _pci_attr_w32(int devind, int port, u32_t value);

View file

@ -14,10 +14,9 @@ See the Linux PCI ID Repository <http://pciids.sourceforge.net/>.
*/
#include <minix/drivers.h>
#include <minix/rs.h>
#include "pci.h"
#if __minix_vmd
#include "config.h"
#endif
struct pci_vendor pci_vendor_table[]=
{