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