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