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