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