Home | History | Annotate | Line # | Download | only in pci
bandit.c revision 1.3
      1 /*	$NetBSD: bandit.c,v 1.3 1998/07/17 18:40:31 tsubai Exp $	*/
      2 
      3 /*
      4  * Copyright 1991-1998 by Open Software Foundation, Inc.
      5  *              All Rights Reserved
      6  *
      7  * Permission to use, copy, modify, and distribute this software and
      8  * its documentation for any purpose and without fee is hereby granted,
      9  * provided that the above copyright notice appears in all copies and
     10  * that both the copyright notice and this permission notice appear in
     11  * supporting documentation.
     12  *
     13  * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
     14  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     15  * FOR A PARTICULAR PURPOSE.
     16  *
     17  * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
     18  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
     19  * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
     20  * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
     21  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     22  */
     23 /*
     24  * Copyright 1991-1998 by Apple Computer, Inc.
     25  *              All Rights Reserved
     26  *
     27  * Permission to use, copy, modify, and distribute this software and
     28  * its documentation for any purpose and without fee is hereby granted,
     29  * provided that the above copyright notice appears in all copies and
     30  * that both the copyright notice and this permission notice appear in
     31  * supporting documentation.
     32  *
     33  * APPLE COMPUTER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
     34  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     35  * FOR A PARTICULAR PURPOSE.
     36  *
     37  * IN NO EVENT SHALL APPLE COMPUTER BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
     38  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
     39  * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
     40  * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
     41  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     42  */
     43 
     44 #include <sys/param.h>
     45 #include <sys/device.h>
     46 
     47 #include <dev/pci/pcireg.h>
     48 #include <dev/pci/pcivar.h>
     49 #include <dev/ofw/openfirm.h>
     50 
     51 #include <machine/bus.h>
     52 
     53 #define	PCI_BANDIT		11
     54 
     55 #define	PCI_REG_BANDIT_CFG	0x40
     56 #define	PCI_REG_ADDR_MASK	0x48
     57 #define	PCI_REG_MODE_SELECT	0x50
     58 #define	PCI_REG_ARBUS_HOLDOFF	0x58
     59 
     60 #define	PCI_MS_BYTESWAP		0x001	/* Enable Big Endian mode. (R/W)*/
     61 #define	PCI_MS_PASSATOMIC	0x002	/* PCI Bus to ARBus Lock are always allowed (R)*/
     62 #define	PCI_MS_NUMBER_MASK	0x00C	/* PCI Bus Number (R) */
     63 #define	PCI_MS_IS_SYNC		0x010	/* Is Synchronous (1) or Async (0) ? (R)*/
     64 #define	PCI_MS_VGA_SPACE	0x020	/* Map VGA I/O space  (R/W) */
     65 #define	PCI_MS_IO_COHERENT	0x040	/* I/O Coherent (R/W) */
     66 #define	PCI_MS_INT_ENABLE	0x080	/* Allow TEA or PCI Abort INT to pass to Grand Central (R/W) */
     67 
     68 #define	BANDIT_SPECIAL_CYCLE	0xe00000	/* Special Cycle offset */
     69 
     70 static void bandit_init __P((pci_chipset_tag_t));
     71 static void scan_pci_devs __P((void));
     72 static void config_slot __P((int, pci_chipset_tag_t));
     73 
     74 void
     75 pci_init()
     76 {
     77 	scan_pci_devs();
     78 }
     79 
     80 void
     81 bandit_init(pc)
     82 	pci_chipset_tag_t pc;
     83 {
     84 	u_int status;
     85 	pcitag_t tag;
     86 
     87 	tag = pci_make_tag(pc, 0, PCI_BANDIT, 0);
     88 	if ((pci_conf_read(pc, tag, PCI_ID_REG) & 0xffff) == 0xffff)
     89 		return;
     90 
     91 	status  = pci_conf_read(pc, tag, PCI_REG_MODE_SELECT);
     92 
     93 	if ((status & PCI_MS_IO_COHERENT) == 0) {
     94 		status |= PCI_MS_IO_COHERENT;
     95 		pci_conf_write(pc, tag, PCI_REG_MODE_SELECT, status);
     96 	}
     97 
     98 	return;
     99 }
    100 
    101 
    102 void
    103 scan_pci_devs()
    104 {
    105 	int node;
    106 	char name[64];
    107 	int n = 0;
    108 	u_int reg[2];
    109 
    110 	bzero(pci_bridges, sizeof(pci_bridges));
    111 
    112 	node = OF_peer(0);
    113 	node = OF_child(node);
    114 
    115 	while (node) {
    116 		if (OF_getprop(node, "name", name, sizeof(name)) <= 0)
    117 			continue;
    118 		if (strcmp(name, "bandit") == 0 ||
    119 		    strcmp(name, "chaos") == 0) {
    120 			int child;
    121 
    122 			if (OF_getprop(node, "reg", reg, sizeof(reg)) != 8)
    123 				continue;
    124 
    125 			pci_bridges[n].iot  = (bus_space_tag_t)reg[0];
    126 			pci_bridges[n].addr = mapiodev(reg[0] + 0x800000, 4);
    127 			pci_bridges[n].data = mapiodev(reg[0] + 0xc00000, 4);
    128 			pci_bridges[n].pc = n;
    129 			bandit_init(n);
    130 
    131 			child = OF_child(node);
    132 			while (child) {
    133 				config_slot(child, n);
    134 				child = OF_peer(child);
    135 			}
    136 			n++;
    137 		}
    138 		if (strcmp(name, "pci") == 0) {	/* XXX This is not a bandit :) */
    139 			int child;
    140 
    141 			if (OF_getprop(node, "reg", reg, sizeof(reg)) != 8)
    142 				continue;
    143 
    144 			pci_bridges[n].iot  = (bus_space_tag_t)reg[0];
    145 			pci_bridges[n].addr = mapiodev(0xfec00000, 4); /* XXX */
    146 			pci_bridges[n].data = mapiodev(0xfee00000, 4); /* XXX */
    147 			pci_bridges[n].pc = PCI_CHIPSET_MPC106; /* for now */
    148 		}
    149 
    150 		node = OF_peer(node);
    151 	}
    152 }
    153 
    154 void
    155 config_slot(node, pc)
    156 	int node;
    157 	pci_chipset_tag_t pc;
    158 {
    159 	pcitag_t tag;
    160 	int sp, irq, intr, csr;
    161 	int bus, dev, func;
    162 	int sz;
    163 	u_int reg[40], *rp;
    164 
    165 	sz = OF_getprop(node, "assigned-addresses", reg, sizeof(reg));
    166 	if (sz < 4)
    167 		return;
    168 
    169 	/*
    170 	 * npt000ss bbbbbbbb dddddfff rrrrrrrr
    171 	 *
    172 	 * ss	space code (01:I/O, 10:32bit mem)
    173 	 * b...	8-bit Bus Number
    174 	 * d...	5-bit Device Number
    175 	 * f...	3-bit Function Number
    176 	 * r... 8-bit Register Number
    177 	 */
    178 	rp = &reg[0];
    179 	bus = (*rp >> 16) & 0xff;
    180 	dev = (*rp >> 11) & 0x1f;
    181 	func = (*rp >> 8) & 0x07;
    182 
    183 	tag = pci_make_tag(pc, bus, dev, func);
    184 	csr  = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
    185 
    186 	/* Fix mem/io bits */
    187 	while (sz > 0) {
    188 		sp = (*rp >> 24) & 0x03;
    189 		if (sp == 1)
    190 			csr |= PCI_COMMAND_IO_ENABLE;
    191 		if (sp == 2)
    192 			csr |= PCI_COMMAND_MEM_ENABLE;
    193 		sz -= 5 * sizeof(int);
    194 		rp += 5;
    195 	}
    196 
    197 	pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr);
    198 
    199 	/* Fix intr bits */
    200 	if (OF_getprop(node, "AAPL,interrupts", &irq, sizeof(irq)) ==
    201 			sizeof(irq)) {
    202 
    203 		intr = pci_conf_read(pc, tag, PCI_INTERRUPT_REG);
    204 		intr = (intr & 0xffffff00) | (irq & 0xff);
    205 		pci_conf_write(pc, tag, PCI_INTERRUPT_REG, intr);
    206 	}
    207 
    208 }
    209 
    210 /*
    211  * slot A1 pci0 dev 13 irq 23
    212  *      B1 pci0 dev 14 irq 24
    213  *      C1 pci0 dev 15 irq 25
    214  *      D2 pci1 dev 13 irq 27
    215  *      E2 pci1 dev 14 irq 28
    216  *      F2 pci1 dev 15 irq 29
    217  */
    218