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