Home | History | Annotate | Line # | Download | only in pci
pci_machdep.c revision 1.18
      1 /*	$NetBSD: pci_machdep.c,v 1.18 1999/09/22 07:18:45 leo Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1996 Leo Weppelman.  All rights reserved.
      5  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
      6  * Copyright (c) 1994 Charles M. Hannum.  All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by Charles M. Hannum.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #include <sys/types.h>
     35 #include <sys/param.h>
     36 #include <sys/time.h>
     37 #include <sys/systm.h>
     38 #include <sys/errno.h>
     39 #include <sys/device.h>
     40 #include <sys/malloc.h>
     41 
     42 #include <vm/vm.h>
     43 #include <vm/vm_kern.h>
     44 
     45 #include <dev/pci/pcivar.h>
     46 #include <dev/pci/pcireg.h>
     47 
     48 #include <machine/cpu.h>
     49 #include <machine/iomap.h>
     50 #include <machine/mfp.h>
     51 #include <machine/bswap.h>
     52 #include <machine/bus.h>
     53 
     54 #include <atari/atari/device.h>
     55 #include <atari/pci/pci_vga.h>
     56 
     57 /*
     58  * Sizes of pci memory and I/O area.
     59  */
     60 #define PCI_MEM_END     0x10000000      /* 256 MByte */
     61 #define PCI_IO_END      0x10000000      /* 256 MByte */
     62 
     63 /*
     64  * We preserve some space at the begin of the pci area for 32BIT_1M
     65  * devices and standard vga.
     66  */
     67 #define PCI_MEM_START   0x00100000      /*   1 MByte */
     68 #define PCI_IO_START    0x00004000      /*  16 kByte (some PCI cards allow only
     69 					    I/O addresses up to 0xffff) */
     70 
     71 /*
     72  * Struct to hold the memory and I/O datas of the pci devices
     73  */
     74 struct pci_memreg {
     75     LIST_ENTRY(pci_memreg) link;
     76     int dev;
     77     pcitag_t tag;
     78     pcireg_t reg, address, mask;
     79     u_int32_t size;
     80     u_int32_t csr;
     81 };
     82 
     83 typedef LIST_HEAD(pci_memreg_head, pci_memreg) PCI_MEMREG;
     84 
     85 int	pcibusprint __P((void *auxp, const char *));
     86 int	pcibusmatch __P((struct device *, struct cfdata *, void *));
     87 void	pcibusattach __P((struct device *, struct device *, void *));
     88 
     89 static void enable_pci_devices __P((void));
     90 static void insert_into_list __P((PCI_MEMREG *head, struct pci_memreg *elem));
     91 static int overlap_pci_areas __P((struct pci_memreg *p,
     92 	struct pci_memreg *self, u_int addr, u_int size, u_int what));
     93 static int pci_config_offset __P((pcitag_t));
     94 
     95 struct cfattach pcibus_ca = {
     96 	sizeof(struct device), pcibusmatch, pcibusattach
     97 };
     98 
     99 int
    100 pcibusmatch(pdp, cfp, auxp)
    101 struct device	*pdp;
    102 struct cfdata	*cfp;
    103 void		*auxp;
    104 {
    105 	if(atari_realconfig == 0)
    106 		return (0);
    107 	if (strcmp((char *)auxp, "pcibus") || cfp->cf_unit != 0)
    108 		return(0);
    109 	return(machineid & ATARI_HADES ? 1 : 0);
    110 }
    111 
    112 void
    113 pcibusattach(pdp, dp, auxp)
    114 struct device	*pdp, *dp;
    115 void		*auxp;
    116 {
    117 	struct pcibus_attach_args	pba;
    118 	bus_space_tag_t			leb_alloc_bus_space_tag __P((void));
    119 
    120 
    121 	enable_pci_devices();
    122 
    123 	pba.pba_busname = "pci";
    124 	pba.pba_pc      = NULL;
    125 	pba.pba_bus     = 0;
    126 	pba.pba_flags	= PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
    127 	pba.pba_dmat	= BUS_PCI_DMA_TAG;
    128 	pba.pba_iot     = leb_alloc_bus_space_tag();
    129 	pba.pba_memt    = leb_alloc_bus_space_tag();
    130 	if ((pba.pba_iot == NULL) || (pba.pba_memt == NULL)) {
    131 		printf("leb_alloc_bus_space_tag failed!\n");
    132 		return;
    133 	}
    134 	pba.pba_iot->base  = PCI_IO_PHYS;
    135 	pba.pba_memt->base = PCI_MEM_PHYS;
    136 
    137 	MFP2->mf_aer &= ~(0x27); /* PCI interrupts: HIGH -> LOW */
    138 
    139 	printf("\n");
    140 
    141 	config_found(dp, &pba, pcibusprint);
    142 }
    143 
    144 int
    145 pcibusprint(auxp, name)
    146 void		*auxp;
    147 const char	*name;
    148 {
    149 	if(name == NULL)
    150 		return(UNCONF);
    151 	return(QUIET);
    152 }
    153 
    154 void
    155 pci_attach_hook(parent, self, pba)
    156 	struct device *parent, *self;
    157 	struct pcibus_attach_args *pba;
    158 {
    159 }
    160 
    161 /*
    162  * Initialize the PCI-bus. The Atari-BIOS does not do this, so....
    163  * We only disable all devices here. Memory and I/O enabling is done
    164  * later at pcibusattach.
    165  */
    166 void
    167 init_pci_bus()
    168 {
    169 	pci_chipset_tag_t	pc = NULL; /* XXX */
    170 	pcitag_t		tag;
    171 	pcireg_t		csr;
    172 	int			device, id, maxndevs;
    173 
    174 	tag   = 0;
    175 	id    = 0;
    176 
    177 	maxndevs = pci_bus_maxdevs(pc, 0);
    178 
    179 	for (device = 0; device < maxndevs; device++) {
    180 
    181 		tag = pci_make_tag(pc, 0, device, 0);
    182 		id  = pci_conf_read(pc, tag, PCI_ID_REG);
    183 		if (id == 0 || id == 0xffffffff)
    184 			continue;
    185 
    186 		csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
    187 		csr &= ~(PCI_COMMAND_MEM_ENABLE|PCI_COMMAND_IO_ENABLE);
    188 		csr &= ~PCI_COMMAND_MASTER_ENABLE;
    189 		pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr);
    190 	}
    191 
    192 	/*
    193 	 * Scan the bus for a VGA-card that we support. If we find
    194 	 * one, try to initialize it to a 'standard' text mode (80x25).
    195 	 */
    196 	check_for_vga();
    197 }
    198 
    199 /*
    200  * insert a new element in an existing list that the ID's (size in struct
    201  * pci_memreg) are sorted.
    202  */
    203 static void
    204 insert_into_list(head, elem)
    205     PCI_MEMREG *head;
    206     struct pci_memreg *elem;
    207 {
    208     struct pci_memreg *p, *q;
    209 
    210     p = LIST_FIRST(head);
    211     q = NULL;
    212 
    213     for (; p != NULL && p->size < elem->size; q = p, p = LIST_NEXT(p, link));
    214 
    215     if (q == NULL) {
    216 	LIST_INSERT_HEAD(head, elem, link);
    217     } else {
    218 	LIST_INSERT_AFTER(q, elem, link);
    219     }
    220 }
    221 
    222 /*
    223  * Test if a new selected area overlaps with an already (probably preselected)
    224  * pci area.
    225  */
    226 static int
    227 overlap_pci_areas(p, self, addr, size, what)
    228     struct pci_memreg *p, *self;
    229     u_int addr, size, what;
    230 {
    231     struct pci_memreg *q;
    232 
    233     if (p == NULL)
    234 	return 0;
    235 
    236     q = p;
    237     while (q != NULL) {
    238 	if ((q != self) && (q->csr & what)) {
    239 	    if ((addr >= q->address) && (addr < (q->address + q->size))) {
    240 #ifdef DEBUG_PCI_MACHDEP
    241 		printf("\noverlap area dev %d reg 0x%02x with dev %d reg 0x%02x",
    242 			self->dev, self->reg, q->dev, q->reg);
    243 #endif
    244 		return 1;
    245 	    }
    246 	    if ((q->address >= addr) && (q->address < (addr + size))) {
    247 #ifdef DEBUG_PCI_MACHDEP
    248 		printf("\noverlap area dev %d reg 0x%02x with dev %d reg 0x%02x",
    249 			self->dev, self->reg, q->dev, q->reg);
    250 #endif
    251 		return 1;
    252 	    }
    253 	}
    254 	q = LIST_NEXT(q, link);
    255     }
    256     return 0;
    257 }
    258 
    259 /*
    260  * Enable memory and I/O on pci devices. Care about already enabled devices
    261  * (probabaly by the console driver).
    262  *
    263  * The idea behind the following code is:
    264  * We build a by sizes sorted list of the requirements of the different
    265  * pci devices. After that we choose the start addresses of that areas
    266  * in such a way that they are placed as closed as possible together.
    267  */
    268 static void
    269 enable_pci_devices()
    270 {
    271     PCI_MEMREG memlist;
    272     PCI_MEMREG iolist;
    273     struct pci_memreg *p, *q;
    274     int dev, reg, id, class;
    275     pcitag_t tag;
    276     pcireg_t csr, address, mask;
    277     pci_chipset_tag_t pc;
    278     int sizecnt, membase_1m;
    279 
    280     pc = 0;
    281     csr = 0;
    282     tag = 0;
    283 
    284     LIST_INIT(&memlist);
    285     LIST_INIT(&iolist);
    286 
    287     /*
    288      * first step: go through all devices and gather memory and I/O
    289      * sizes
    290      */
    291     for (dev = 0; dev < pci_bus_maxdevs(pc,0); dev++) {
    292 
    293 	tag = pci_make_tag(pc, 0, dev, 0);
    294 	id  = pci_conf_read(pc, tag, PCI_ID_REG);
    295 	if (id == 0 || id == 0xffffffff)
    296 	    continue;
    297 
    298 	csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
    299 
    300 	/*
    301 	 * special case: if a display card is found and memory is enabled
    302 	 * preserve 128k at 0xa0000 as vga memory.
    303 	 * XXX: if a display card is found without being enabled, leave
    304 	 *      it alone! You will usually only create conflicts by enabeling
    305 	 *      it.
    306 	 */
    307 	class = pci_conf_read(pc, tag, PCI_CLASS_REG);
    308 	switch (PCI_CLASS(class)) {
    309 	    case PCI_CLASS_PREHISTORIC:
    310 	    case PCI_CLASS_DISPLAY:
    311 	      if (csr & (PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE)) {
    312 		    p = (struct pci_memreg *)malloc(sizeof(struct pci_memreg),
    313 				M_TEMP, M_WAITOK);
    314 		    memset(p, '\0', sizeof(struct pci_memreg));
    315 		    p->dev = dev;
    316 		    p->csr = csr;
    317 		    p->tag = tag;
    318 		    p->reg = 0;     /* there is no register about this */
    319 		    p->size = 0x20000;  /* 128kByte */
    320 		    p->mask = 0xfffe0000;
    321 		    p->address = 0xa0000;
    322 
    323 		    insert_into_list(&memlist, p);
    324 	      }
    325 	      else continue;
    326 	}
    327 
    328 	for (reg = PCI_MAPREG_START; reg < PCI_MAPREG_END; reg += 4) {
    329 
    330 	    address = pci_conf_read(pc, tag, reg);
    331 	    pci_conf_write(pc, tag, reg, 0xffffffff);
    332 	    mask    = pci_conf_read(pc, tag, reg);
    333 	    pci_conf_write(pc, tag, reg, address);
    334 	    if (mask == 0)
    335 		continue; /* Register unused */
    336 
    337 	    p = (struct pci_memreg *)malloc(sizeof(struct pci_memreg),
    338 			M_TEMP, M_WAITOK);
    339 	    memset(p, '\0', sizeof(struct pci_memreg));
    340 	    p->dev = dev;
    341 	    p->csr = csr;
    342 	    p->tag = tag;
    343 	    p->reg = reg;
    344 	    p->mask = mask;
    345 	    p->address = 0;
    346 
    347 	    if (mask & PCI_MAPREG_TYPE_IO) {
    348 		p->size = PCI_MAPREG_IO_SIZE(mask);
    349 
    350 		/*
    351 		 * if I/O is already enabled (probably by the console driver)
    352 		 * save the address in order to take care about it later.
    353 		 */
    354 		if (csr & PCI_COMMAND_IO_ENABLE)
    355 		    p->address = address;
    356 
    357 		insert_into_list(&iolist, p);
    358 	    } else {
    359 		p->size = PCI_MAPREG_MEM_SIZE(mask);
    360 
    361 		/*
    362 		 * if memory is already enabled (probably by the console driver)
    363 		 * save the address in order to take care about it later.
    364 		 */
    365 		if (csr & PCI_COMMAND_MEM_ENABLE)
    366 		    p->address = address;
    367 
    368 		insert_into_list(&memlist, p);
    369 
    370 		if (PCI_MAPREG_MEM_TYPE(mask) == PCI_MAPREG_MEM_TYPE_64BIT)
    371 		    reg++;
    372 	    }
    373 	}
    374 
    375 	/*
    376 	 * Both interrupt pin & line are set to the device (== slot)
    377 	 * number. This makes sense on the atari because the
    378 	 * individual slots are hard-wired to a specific MFP-pin.
    379 	 */
    380 	csr  = (dev << PCI_INTERRUPT_PIN_SHIFT);
    381 	csr |= (dev << PCI_INTERRUPT_LINE_SHIFT);
    382 	pci_conf_write(pc, tag, PCI_INTERRUPT_REG, csr);
    383     }
    384 
    385     /*
    386      * second step: calculate the memory and I/O adresses beginning from
    387      * PCI_MEM_START and PCI_IO_START. Care about already mapped areas.
    388      *
    389      * beginn with memory list
    390      */
    391 
    392     address = PCI_MEM_START;
    393     sizecnt = 0;
    394     membase_1m = 0;
    395     p = LIST_FIRST(&memlist);
    396     while (p != NULL) {
    397 	if (!(p->csr & PCI_COMMAND_MEM_ENABLE)) {
    398 	    if (PCI_MAPREG_MEM_TYPE(p->mask) == PCI_MAPREG_MEM_TYPE_32BIT_1M) {
    399 		if (p->size > membase_1m)
    400 		    membase_1m = p->size;
    401 		do {
    402 		    p->address = membase_1m;
    403 		    membase_1m += p->size;
    404 		} while (overlap_pci_areas(LIST_FIRST(&memlist), p, p->address,
    405 					   p->size, PCI_COMMAND_MEM_ENABLE));
    406 		if (membase_1m > 0x00100000) {
    407 		    /*
    408 		     * Should we panic here?
    409 		     */
    410 		    printf("\npcibus0: dev %d reg %d: memory not configured",
    411 			    p->dev, p->reg);
    412 		    p->reg = 0;
    413 		}
    414 	    } else {
    415 
    416 		if (sizecnt && (p->size > sizecnt))
    417 		    sizecnt = ((p->size + sizecnt) & p->mask) &
    418 			      PCI_MAPREG_MEM_ADDR_MASK;
    419 		if (sizecnt > address) {
    420 		    address = sizecnt;
    421 		    sizecnt = 0;
    422 		}
    423 
    424 		do {
    425 		    p->address = address + sizecnt;
    426 		    sizecnt += p->size;
    427 		} while (overlap_pci_areas(LIST_FIRST(&memlist), p, p->address,
    428 					   p->size, PCI_COMMAND_MEM_ENABLE));
    429 
    430 		if ((address + sizecnt) > PCI_MEM_END) {
    431 		    /*
    432 		     * Should we panic here?
    433 		     */
    434 		    printf("\npcibus0: dev %d reg %d: memory not configured",
    435 			    p->dev, p->reg);
    436 		    p->reg = 0;
    437 		}
    438 	    }
    439 	    if (p->reg > 0) {
    440 		pci_conf_write(pc, p->tag, p->reg, p->address);
    441 		csr = pci_conf_read(pc, p->tag, PCI_COMMAND_STATUS_REG);
    442 		csr |= PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE;
    443 		pci_conf_write(pc, p->tag, PCI_COMMAND_STATUS_REG, csr);
    444 	    }
    445 	}
    446 	p = LIST_NEXT(p, link);
    447     }
    448 
    449     /*
    450      * now the I/O list
    451      */
    452 
    453     address = PCI_IO_START;
    454     sizecnt = 0;
    455     p = LIST_FIRST(&iolist);
    456     while (p != NULL) {
    457 	if (!(p->csr & PCI_COMMAND_IO_ENABLE)) {
    458 
    459 	    if (sizecnt && (p->size > sizecnt))
    460 		sizecnt = ((p->size + sizecnt) & p->mask) &
    461 			  PCI_MAPREG_IO_ADDR_MASK;
    462 	    if (sizecnt > address) {
    463 		address = sizecnt;
    464 		sizecnt = 0;
    465 	    }
    466 
    467 	    do {
    468 		p->address = address + sizecnt;
    469 		sizecnt += p->size;
    470 	    } while (overlap_pci_areas(LIST_FIRST(&iolist), p, p->address,
    471 				       p->size, PCI_COMMAND_IO_ENABLE));
    472 
    473 	    if ((address + sizecnt) > PCI_IO_END) {
    474 		/*
    475 		 * Should we panic here?
    476 		 */
    477 		printf("\npcibus0: dev %d reg %d: io not configured",
    478 			p->dev, p->reg);
    479 	    } else {
    480 		pci_conf_write(pc, p->tag, p->reg, p->address);
    481 		csr = pci_conf_read(pc, p->tag, PCI_COMMAND_STATUS_REG);
    482 		csr |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MASTER_ENABLE;
    483 		pci_conf_write(pc, p->tag, PCI_COMMAND_STATUS_REG, csr);
    484 	    }
    485 	}
    486 	p = LIST_NEXT(p, link);
    487     }
    488 
    489 #ifdef DEBUG_PCI_MACHDEP
    490     printf("\nI/O List:\n");
    491     p = LIST_FIRST(&iolist);
    492 
    493     while (p != NULL) {
    494 	printf("\ndev: %d, reg: 0x%02x, size: 0x%08x, addr: 0x%08x", p->dev,
    495 			p->reg, p->size, p->address);
    496 	p = LIST_NEXT(p, link);
    497     }
    498     printf("\nMemlist:");
    499     p = LIST_FIRST(&memlist);
    500 
    501     while (p != NULL) {
    502 	printf("\ndev: %d, reg: 0x%02x, size: 0x%08x, addr: 0x%08x", p->dev,
    503 			p->reg, p->size, p->address);
    504 	p = LIST_NEXT(p, link);
    505     }
    506 #endif
    507 
    508     /*
    509      * Free the lists
    510      */
    511     p = LIST_FIRST(&iolist);
    512     while (p != NULL) {
    513 	q = p;
    514 	LIST_REMOVE(q, link);
    515 	free(p, M_WAITOK);
    516 	p = LIST_FIRST(&iolist);
    517     }
    518     p = LIST_FIRST(&memlist);
    519     while (p != NULL) {
    520 	q = p;
    521 	LIST_REMOVE(q, link);
    522 	free(p, M_WAITOK);
    523 	p = LIST_FIRST(&memlist);
    524     }
    525 }
    526 
    527 /*
    528  * Atari_init.c maps the config areas NBPG bytes apart....
    529  */
    530 static int pci_config_offset(tag)
    531 pcitag_t	tag;
    532 {
    533 	int	device;
    534 
    535 	device = (tag >> 11) & 0x1f;
    536 	return(device * NBPG);
    537 }
    538 
    539 int
    540 pci_bus_maxdevs(pc, busno)
    541 	pci_chipset_tag_t pc;
    542 	int busno;
    543 {
    544 	return (4);
    545 }
    546 
    547 pcitag_t
    548 pci_make_tag(pc, bus, device, function)
    549 	pci_chipset_tag_t pc;
    550 	int bus, device, function;
    551 {
    552 	return ((bus << 16) | (device << 11) | (function << 8));
    553 }
    554 
    555 pcireg_t
    556 pci_conf_read(pc, tag, reg)
    557 	pci_chipset_tag_t pc;
    558 	pcitag_t tag;
    559 	int reg;
    560 {
    561 	u_long	data;
    562 
    563 	data = *(u_long *)(pci_conf_addr + pci_config_offset(tag) + reg);
    564 	return (bswap32(data));
    565 }
    566 
    567 void
    568 pci_conf_write(pc, tag, reg, data)
    569 	pci_chipset_tag_t pc;
    570 	pcitag_t tag;
    571 	int reg;
    572 	pcireg_t data;
    573 {
    574 	*((u_long *)(pci_conf_addr + pci_config_offset(tag) + reg))
    575 		= bswap32(data);
    576 }
    577 
    578 int
    579 pci_intr_map(pc, intrtag, pin, line, ihp)
    580 	pci_chipset_tag_t pc;
    581 	pcitag_t intrtag;
    582 	int pin, line;
    583 	pci_intr_handle_t *ihp;
    584 {
    585 	/*
    586 	 * According to the PCI-spec, 255 means `unknown' or `no connection'.
    587 	 * Interpret this as 'no interrupt assigned'.
    588 	 */
    589 	if (line == 255) {
    590 		*ihp = -1;
    591 		return 1;
    592 	}
    593 
    594 	/*
    595 	 * Values are pretty useless because the on the Hades all interrupt
    596 	 * lines for a card are tied together and hardwired to the TT-MFP
    597 	 * I/O port.
    598 	 */
    599 	*ihp = line;
    600 	return 0;
    601 }
    602 
    603 const char *
    604 pci_intr_string(pc, ih)
    605 	pci_chipset_tag_t pc;
    606 	pci_intr_handle_t ih;
    607 {
    608 	static char irqstr[8];		/* 4 + 2 + NULL + sanity */
    609 
    610 	if (ih == -1)
    611 		panic("pci_intr_string: bogus handle 0x%x\n", ih);
    612 
    613 	sprintf(irqstr, "irq %d", ih);
    614 	return (irqstr);
    615 
    616 }
    617 
    618 /*
    619  * The interrupt stuff is rather ugly. On the Hades, all interrupt lines
    620  * for a slot are wired together and connected to IO 0,1,2 or 5 (slots:
    621  * (0-3) on the TT-MFP. The Pci-config code initializes the irq. number
    622  * to the slot position.
    623  */
    624 static pci_intr_info_t iinfo[4] = { { -1 }, { -1 }, { -1 }, { -1 } };
    625 
    626 static int	iifun __P((int, int));
    627 
    628 static int
    629 iifun(slot, sr)
    630 int	slot;
    631 int	sr;
    632 {
    633 	pci_intr_info_t *iinfo_p;
    634 	int		s;
    635 
    636 	iinfo_p = &iinfo[slot];
    637 
    638 	/*
    639 	 * Disable the interrupts
    640 	 */
    641 	MFP2->mf_imrb  &= ~iinfo_p->imask;
    642 
    643 	if ((sr & PSL_IPL) >= (iinfo_p->ipl & PSL_IPL)) {
    644 		/*
    645 		 * We're running at a too high priority now.
    646 		 */
    647 		add_sicallback((si_farg)iifun, (void*)slot, 0);
    648 	}
    649 	else {
    650 		s = splx(iinfo_p->ipl);
    651 		(void) (iinfo_p->ifunc)(iinfo_p->iarg);
    652 		splx(s);
    653 
    654 		/*
    655 		 * Re-enable interrupts after handling
    656 		 */
    657 		MFP2->mf_imrb |= iinfo_p->imask;
    658 	}
    659 	return 1;
    660 }
    661 
    662 void *
    663 pci_intr_establish(pc, ih, level, ih_fun, ih_arg)
    664 	pci_chipset_tag_t	pc;
    665 	pci_intr_handle_t	ih;
    666 	int			level;
    667 	int			(*ih_fun) __P((void *));
    668 	void			*ih_arg;
    669 {
    670 	pci_intr_info_t *iinfo_p;
    671 	struct intrhand	*ihand;
    672 	int		slot;
    673 
    674 	slot    = ih;
    675 	iinfo_p = &iinfo[slot];
    676 
    677 	if (iinfo_p->ipl > 0)
    678 	    panic("pci_intr_establish: interrupt was already established\n");
    679 
    680 	ihand = intr_establish((slot == 3) ? 23 : 16 + slot, USER_VEC, 0,
    681 				(hw_ifun_t)iifun, (void *)slot);
    682 	if (ihand != NULL) {
    683 		iinfo_p->ipl   = level;
    684 		iinfo_p->imask = (slot == 3) ? 0x80 : (0x01 << slot);
    685 		iinfo_p->ifunc = ih_fun;
    686 		iinfo_p->iarg  = ih_arg;
    687 		iinfo_p->ihand = ihand;
    688 
    689 		/*
    690 		 * Enable (unmask) the interrupt
    691 		 */
    692 		MFP2->mf_imrb |= iinfo_p->imask;
    693 		MFP2->mf_ierb |= iinfo_p->imask;
    694 		return(iinfo_p);
    695 	}
    696 	return NULL;
    697 }
    698 
    699 void
    700 pci_intr_disestablish(pc, cookie)
    701 	pci_chipset_tag_t pc;
    702 	void *cookie;
    703 {
    704 	pci_intr_info_t *iinfo_p = (pci_intr_info_t *)cookie;
    705 
    706 	if (iinfo->ipl < 0)
    707 	    panic("pci_intr_disestablish: interrupt was not established\n");
    708 
    709 	MFP2->mf_imrb &= ~iinfo->imask;
    710 	MFP2->mf_ierb &= ~iinfo->imask;
    711 	(void) intr_disestablish(iinfo_p->ihand);
    712 	iinfo_p->ipl = -1;
    713 }
    714