xref: /netbsd/sys/arch/macppc/macppc/rbus_machdep.c (revision bf9ec67e)
1 /*	$NetBSD: rbus_machdep.c,v 1.10 2001/06/10 15:32:58 tsubai Exp $	*/
2 
3 /*
4  * Copyright (c) 1999
5  *     TSUBAI Masanari.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <sys/param.h>
31 #include <sys/device.h>
32 #include <sys/systm.h>
33 
34 #include <uvm/uvm_extern.h>
35 
36 #include <machine/bat.h>
37 #include <machine/bus.h>
38 
39 #include <dev/pci/pcivar.h>
40 #include <dev/pci/pcidevs.h>
41 #include <dev/cardbus/rbus.h>
42 #include <dev/ofw/openfirm.h>
43 
44 static void macppc_cardbus_init __P((pci_chipset_tag_t, pcitag_t));
45 
46 #ifdef DEBUG_ALLOC
47 # define DPRINTF printf
48 #else
49 # define DPRINTF while (0) printf
50 #endif
51 
52 int
53 md_space_map(t, bpa, size, flags, bshp)
54 	bus_space_tag_t t;
55 	bus_addr_t bpa;
56 	bus_size_t size;
57 	int flags;
58 	bus_space_handle_t *bshp;
59 {
60 	DPRINTF("md_space_map: 0x%x, 0x%x, 0x%x\n", t, bpa, size);
61 
62 	/* XXX */
63 	*bshp = t + bpa;
64 	return 0;
65 }
66 
67 void
68 md_space_unmap(t, bsh, size, adrp)
69 	bus_space_tag_t t;
70 	bus_space_handle_t bsh;
71 	bus_size_t size;
72 	bus_addr_t *adrp;
73 {
74 	DPRINTF("md_space_unmap: 0x%x 0x%x\n", t, bsh);
75 
76 	/* XXX */
77 	if (adrp)
78 		*adrp = bsh - t;
79 }
80 
81 rbus_tag_t
82 rbus_pccbb_parent_mem(pa)
83 	struct pci_attach_args *pa;
84 {
85 	bus_addr_t start;
86 	bus_size_t size;
87 	int node, reg[5];
88 
89 	macppc_cardbus_init(pa->pa_pc, pa->pa_tag);
90 
91 	node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
92 	OF_getprop(node, "assigned-addresses", reg, sizeof(reg));
93 
94 	start = reg[2];
95 	size = reg[4];
96 
97 	/* XXX PowerBook G3 */
98 	if (size < 0x10000) {
99 		start = 0x90000000;
100 		size  = 0x10000000;
101 	}
102 
103 	battable[start >> 28].batl = BATL(start, BAT_I, BAT_PP_RW);
104 	battable[start >> 28].batu = BATU(start, BAT_BL_256M, BAT_Vs);
105 
106 	return rbus_new_root_delegate(pa->pa_memt, start, size, 0);
107 }
108 
109 rbus_tag_t
110 rbus_pccbb_parent_io(pa)
111 	struct pci_attach_args *pa;
112 {
113 	bus_addr_t start = 0x2000;
114 	bus_size_t size  = 0x0800;
115 
116 	start += pa->pa_function * size;
117 	return rbus_new_root_delegate(pa->pa_iot, start, size, 0);
118 
119 	/* XXX we should use ``offset''? */
120 }
121 
122 void
123 macppc_cardbus_init(pc, tag)
124 	pci_chipset_tag_t pc;
125 	pcitag_t tag;
126 {
127 	u_int x;
128 	static int initted = 0;
129 
130 	if (initted)
131 		return;
132 	initted = 1;
133 
134 	/* XXX What about other bridges? */
135 
136 	x = pci_conf_read(pc, tag, PCI_ID_REG);
137 	if (PCI_VENDOR(x) == PCI_VENDOR_TI &&
138 	    PCI_PRODUCT(x) == PCI_PRODUCT_TI_PCI1211) {
139 		/* For CardBus card. */
140 		pci_conf_write(pc, tag, 0x18, 0x10010100);
141 
142 		/* Route INTA to MFUNC0 */
143 		x = pci_conf_read(pc, tag, 0x8c);
144 		x |= 0x02;
145 		pci_conf_write(pc, tag, 0x8c, x);
146 
147 		tag = pci_make_tag(pc, 0, 0, 0);
148 		x = pci_conf_read(pc, tag, PCI_ID_REG);
149 		if (PCI_VENDOR(x) == PCI_VENDOR_MOT &&
150 		    PCI_PRODUCT(x) == PCI_PRODUCT_MOT_MPC106) {
151 			/* Set subordinate bus number to 1. */
152 			x = pci_conf_read(pc, tag, 0x40);
153 			x |= 1 << 8;
154 			pci_conf_write(pc, tag, 0x40, x);
155 		}
156 	}
157 }
158