An important point to note in this example is that most of the arguments to pio_map_alloc() can simply be passed as the values from the edt_t received by the entry point.
Example 17-1 : Sketch of EISA Initialization
#include <sys/types.h> #include <sys/edt.h> #include <sys/pio.h> #include <sys/eisa.h> #include <sys/cmn_err.h> #define MAX_DEVICE 4 /* Array of info structures about each device. A device ** that does not initialize OK ought to be marked, but ** no such logic is shown. */ struct edrv_info { caddr_t e_addr[NBASE]; /* pio mapped addr per space */ int e_dmachan; /* dma chan in use */ } einfo[MAX_DEVICE]; #define CARD_ID 0x0163b30a /* mfr. ID */ #define IRQ_MASK 0x0018 /* acceptable IRQs */ #define DMACHAN_MASK 0x7a /* acceptable chans */ edrv_edtinit(edt_t *e) { int iospace; /* index over iospace array */ int eirq; /* allocated IRQ # */ int edma_chan; /* allocated chan # */ struct edrv_info *einf; /* -> einfo[n] */ piomap_t *pmap; if (e->e_ctlr < MAX_DEVICE) einf = &einfo[e->e_ctlr]; else { /* unknown device, nowhere to put info */ cmn_err(CE_WARN,"devno too large:%d",e->e_ctlr); return; } /* for each nonempty iospace parameter, ** set up a PIO map and save the kv address. */ for (iospace = 0; iospace < NBASE; iospace++) { if (!e->e_space[iospace].ios_iopaddr) einf->e_addr[iospace] = 0; /* note no addr */ pmap = pio_mapalloc( /* make a PIO map */ e->e_bus_type, /* pass bus type given */ e->e_adap, /* pass adapter # given */ &e->e_space[iospace], /* given iospace too */ PIOMAP_FIXED, /* always fixed for EISA */ "edrv"); einf->e_addr[iospace] = pio_mapaddr(pmap, e->e_space[iospace].ios_iopaddr); } /* Set up an edge-triggered IRQ for this device. ** Associate it with our interrupt entry point. ** There is no need to remember the assigned IRQ. */ eirq = eisa_ivec_alloc(e->e_adap,IRQ_MASK,EISA_EDGE_IRQ); if (eirq < 0) { cmn_err(CE_WARN, "edrv: ctlr %d could not allocate IRQ\n", e->e_ctlr); /* should mark einfo unusable */ return; } eisa_ivec_set(e->e_adap, eirq, edrv_intr, e->e_ctlr); /* Allocate a DMA Channel for this device and note ** the number in the device info array. */ edma_chan = eisa_dmachan_alloc(e->e_adap,DMACHAN_MASK); if (edma_chan < 0) { cmn_err(CE_WARN, "edrv: ctlr %d could not allocate DMA Chan\n", e->e_ctlr); /* should mark einfo unusable */ return; } einf->e_dmachan = edma_chan; }