1 /* $NetBSD: rbus_machdep.c,v 1.18 2011/07/01 18:43:05 dyoung 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/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: rbus_machdep.c,v 1.18 2011/07/01 18:43:05 dyoung Exp $");
32
33 #include <sys/param.h>
34 #include <sys/device.h>
35 #include <sys/systm.h>
36
37 #include <powerpc/oea/bat.h>
38 #include <sys/bus.h>
39
40 #include <dev/pci/pcivar.h>
41 #include <dev/pci/pcidevs.h>
42 #include <dev/cardbus/rbus.h>
43 #include <dev/ofw/openfirm.h>
44
45 static void macppc_cardbus_init(pci_chipset_tag_t, pcitag_t);
46
47 #ifdef DEBUG_ALLOC
48 # define DPRINTF printf
49 #else
50 # define DPRINTF while (0) printf
51 #endif
52
53 int
md_space_map(bus_space_tag_t t,bus_addr_t bpa,bus_size_t size,int flags,bus_space_handle_t * bshp)54 md_space_map(bus_space_tag_t t, bus_addr_t bpa, bus_size_t size,
55 int flags, bus_space_handle_t *bshp)
56 {
57 DPRINTF("md_space_map: %p, 0x%x, 0x%x\n", t, bpa, size);
58
59 return bus_space_map(t, bpa, size, flags, bshp);
60 }
61
62 void
md_space_unmap(bus_space_tag_t t,bus_space_handle_t bsh,bus_size_t size,bus_addr_t * adrp)63 md_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size,
64 bus_addr_t *adrp)
65 {
66 DPRINTF("md_space_unmap: %p 0x%x\n", t, bsh);
67
68 if (adrp)
69 *adrp = bsh - t->pbs_offset;
70
71 bus_space_unmap(t, bsh, size);
72 }
73
74 rbus_tag_t
rbus_pccbb_parent_mem(struct pci_attach_args * pa)75 rbus_pccbb_parent_mem(struct pci_attach_args *pa)
76 {
77 bus_addr_t start;
78 bus_size_t size;
79 int node, reg[5];
80
81 macppc_cardbus_init(pa->pa_pc, pa->pa_tag);
82
83 node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
84 OF_getprop(node, "assigned-addresses", reg, sizeof(reg));
85
86 start = reg[2];
87 size = reg[4];
88
89 /* XXX PowerBook G3 */
90 if (size < 0x10000) {
91 start = 0x90000000;
92 size = 0x10000000;
93 }
94
95 battable[start >> 28].batl = BATL(start, BAT_I, BAT_PP_RW);
96 battable[start >> 28].batu = BATU(start, BAT_BL_256M, BAT_Vs);
97
98 return rbus_new_root_delegate(pa->pa_memt, start, size, 0);
99 }
100
101 rbus_tag_t
rbus_pccbb_parent_io(struct pci_attach_args * pa)102 rbus_pccbb_parent_io(struct pci_attach_args *pa)
103 {
104 bus_addr_t start = 0x2000;
105 bus_size_t size = 0x0800;
106
107 start += pa->pa_function * size;
108 return rbus_new_root_delegate(pa->pa_iot, start, size, 0);
109
110 /* XXX we should use ``offset''? */
111 }
112
113 void
macppc_cardbus_init(pci_chipset_tag_t pc,pcitag_t tag)114 macppc_cardbus_init(pci_chipset_tag_t pc, pcitag_t tag)
115 {
116 u_int x;
117 static int initted = 0;
118
119 if (initted)
120 return;
121 initted = 1;
122
123 /* XXX What about other bridges? */
124
125 x = pci_conf_read(pc, tag, PCI_ID_REG);
126 if (PCI_VENDOR(x) == PCI_VENDOR_TI &&
127 PCI_PRODUCT(x) == PCI_PRODUCT_TI_PCI1211) {
128 /* For CardBus card. */
129 pci_conf_write(pc, tag, 0x18, 0x10010100);
130
131 /* Route INTA to MFUNC0 */
132 x = pci_conf_read(pc, tag, 0x8c);
133 x |= 0x02;
134 pci_conf_write(pc, tag, 0x8c, x);
135
136 tag = pci_make_tag(pc, 0, 0, 0);
137 x = pci_conf_read(pc, tag, PCI_ID_REG);
138 if (PCI_VENDOR(x) == PCI_VENDOR_MOT &&
139 PCI_PRODUCT(x) == PCI_PRODUCT_MOT_MPC106) {
140 /* Set subordinate bus number to 1. */
141 x = pci_conf_read(pc, tag, 0x40);
142 x |= 1 << 8;
143 pci_conf_write(pc, tag, 0x40, x);
144 }
145 }
146 }
147