gapspci_pci.c revision 1.3 1 1.3 uch /* $NetBSD: gapspci_pci.c,v 1.3 2002/03/24 18:21:24 uch Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.1 thorpej * Copyright (c) 2001 Marcus Comstedt.
5 1.1 thorpej * Copyright (c) 2001 Jason R. Thorpe.
6 1.1 thorpej * All rights reserved.
7 1.1 thorpej *
8 1.1 thorpej * Redistribution and use in source and binary forms, with or without
9 1.1 thorpej * modification, are permitted provided that the following conditions
10 1.1 thorpej * are met:
11 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
12 1.1 thorpej * notice, this list of conditions and the following disclaimer.
13 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
15 1.1 thorpej * documentation and/or other materials provided with the distribution.
16 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
17 1.1 thorpej * must display the following acknowledgement:
18 1.1 thorpej * This product includes software developed by Marcus Comstedt.
19 1.1 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
20 1.1 thorpej * contributors may be used to endorse or promote products derived
21 1.1 thorpej * from this software without specific prior written permission.
22 1.1 thorpej *
23 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
34 1.1 thorpej */
35 1.1 thorpej
36 1.1 thorpej /*
37 1.1 thorpej * PCI configuraiton space implementation for the SEGA GAPS PCI bridge.
38 1.1 thorpej */
39 1.1 thorpej
40 1.1 thorpej #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
41 1.1 thorpej
42 1.1 thorpej #include <sys/param.h>
43 1.1 thorpej #include <sys/systm.h>
44 1.1 thorpej #include <sys/kernel.h>
45 1.1 thorpej #include <sys/device.h>
46 1.1 thorpej
47 1.1 thorpej #include <machine/cpu.h>
48 1.1 thorpej #include <machine/bus.h>
49 1.2 marcus #include <machine/sysasicvar.h>
50 1.1 thorpej
51 1.1 thorpej #include <dev/pci/pcivar.h>
52 1.1 thorpej #include <dev/pci/pcireg.h>
53 1.1 thorpej
54 1.1 thorpej #include <dreamcast/dev/g2/gapspcivar.h>
55 1.1 thorpej
56 1.1 thorpej void gaps_attach_hook(struct device *, struct device *,
57 1.1 thorpej struct pcibus_attach_args *);
58 1.1 thorpej int gaps_bus_maxdevs(void *, int);
59 1.1 thorpej pcitag_t gaps_make_tag(void *, int, int, int);
60 1.1 thorpej pcireg_t gaps_conf_read(void *, pcitag_t, int);
61 1.1 thorpej void gaps_conf_write(void *, pcitag_t, int, pcireg_t);
62 1.1 thorpej
63 1.1 thorpej int gaps_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
64 1.1 thorpej const char *gaps_intr_string(void *, pci_intr_handle_t);
65 1.1 thorpej void *gaps_intr_establish(void *, pci_intr_handle_t,
66 1.1 thorpej int, int (*)(void *), void *);
67 1.1 thorpej void gaps_intr_disestablish(void *, void *);
68 1.1 thorpej
69 1.1 thorpej void
70 1.1 thorpej gaps_pci_init(struct gaps_softc *sc)
71 1.1 thorpej {
72 1.1 thorpej pci_chipset_tag_t pc = &sc->sc_pc;
73 1.1 thorpej
74 1.1 thorpej memset(pc, 0, sizeof(*pc));
75 1.1 thorpej
76 1.1 thorpej pc->pc_attach_hook = gaps_attach_hook;
77 1.1 thorpej pc->pc_bus_maxdevs = gaps_bus_maxdevs;
78 1.1 thorpej pc->pc_make_tag = gaps_make_tag;
79 1.1 thorpej pc->pc_conf_read = gaps_conf_read;
80 1.1 thorpej pc->pc_conf_write = gaps_conf_write;
81 1.1 thorpej pc->pc_conf_v = sc;
82 1.1 thorpej
83 1.1 thorpej pc->pc_intr_map = gaps_intr_map;
84 1.1 thorpej pc->pc_intr_string = gaps_intr_string;
85 1.1 thorpej pc->pc_intr_establish = gaps_intr_establish;
86 1.1 thorpej pc->pc_intr_disestablish = gaps_intr_disestablish;
87 1.1 thorpej
88 1.1 thorpej if (bus_space_map(sc->sc_memt, 0x01001600, 0x100,
89 1.1 thorpej 0, &sc->sc_pci_memh) != 0)
90 1.1 thorpej panic("gaps_pci_init: can't map PCI configuration space");
91 1.1 thorpej }
92 1.1 thorpej
93 1.1 thorpej #define GAPS_PCITAG_MAGIC 0x022473
94 1.1 thorpej
95 1.1 thorpej void
96 1.1 thorpej gaps_attach_hook(struct device *bus, struct device *pci,
97 1.1 thorpej struct pcibus_attach_args *pba)
98 1.1 thorpej {
99 1.1 thorpej struct gaps_softc *sc = (void *) bus;
100 1.1 thorpej
101 1.1 thorpej /*
102 1.1 thorpej * Now that we know there's a bus configured, go ahead and
103 1.1 thorpej * program the BAR on the device.
104 1.1 thorpej */
105 1.1 thorpej pci_conf_write(&sc->sc_pc, GAPS_PCITAG_MAGIC,
106 1.1 thorpej PCI_MAPREG_START + 4, 0x01000000);
107 1.1 thorpej pci_conf_write(&sc->sc_pc, GAPS_PCITAG_MAGIC, PCI_COMMAND_STATUS_REG,
108 1.1 thorpej pci_conf_read(&sc->sc_pc, 0, PCI_COMMAND_STATUS_REG) |
109 1.1 thorpej PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE);
110 1.1 thorpej }
111 1.1 thorpej
112 1.1 thorpej int
113 1.1 thorpej gaps_bus_maxdevs(void *v, int bus)
114 1.1 thorpej {
115 1.1 thorpej
116 1.1 thorpej return (1);
117 1.1 thorpej }
118 1.1 thorpej
119 1.1 thorpej pcitag_t
120 1.1 thorpej gaps_make_tag(void *v, int bus, int dev, int func)
121 1.1 thorpej {
122 1.1 thorpej
123 1.1 thorpej if (bus == 0 && dev == 0 && func == 0)
124 1.1 thorpej return (GAPS_PCITAG_MAGIC);
125 1.1 thorpej
126 1.1 thorpej return (0);
127 1.1 thorpej }
128 1.1 thorpej
129 1.1 thorpej pcireg_t
130 1.1 thorpej gaps_conf_read(void *v, pcitag_t tag, int reg)
131 1.1 thorpej {
132 1.1 thorpej struct gaps_softc *sc = v;
133 1.1 thorpej
134 1.1 thorpej if (tag != GAPS_PCITAG_MAGIC)
135 1.1 thorpej return (-1);
136 1.1 thorpej
137 1.1 thorpej if (reg == (PCI_MAPREG_START + 4)) {
138 1.1 thorpej /*
139 1.1 thorpej * We fake the BAR -- just return the physical address
140 1.1 thorpej * to which the device is mapped.
141 1.1 thorpej */
142 1.1 thorpej return (0x01001700);
143 1.1 thorpej }
144 1.1 thorpej
145 1.1 thorpej return (bus_space_read_4(sc->sc_memt, sc->sc_pci_memh, reg));
146 1.1 thorpej }
147 1.1 thorpej
148 1.1 thorpej void
149 1.1 thorpej gaps_conf_write(void *v, pcitag_t tag, int reg, pcireg_t val)
150 1.1 thorpej {
151 1.1 thorpej struct gaps_softc *sc = v;
152 1.1 thorpej
153 1.1 thorpej if (tag != GAPS_PCITAG_MAGIC)
154 1.1 thorpej return;
155 1.1 thorpej
156 1.1 thorpej /* Disallow writing to the "BAR" ... it doesn't actually exist. */
157 1.1 thorpej if (reg == (PCI_MAPREG_START + 4) && val != 0x01000000)
158 1.1 thorpej return;
159 1.1 thorpej
160 1.1 thorpej bus_space_write_4(sc->sc_memt, sc->sc_pci_memh, reg, val);
161 1.1 thorpej }
162 1.1 thorpej
163 1.1 thorpej int
164 1.1 thorpej gaps_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
165 1.1 thorpej {
166 1.1 thorpej
167 1.3 uch *ihp = SYSASIC_EVENT_EXT;
168 1.1 thorpej return (0);
169 1.1 thorpej }
170 1.1 thorpej
171 1.1 thorpej const char *
172 1.1 thorpej gaps_intr_string(void *v, pci_intr_handle_t ih)
173 1.1 thorpej {
174 1.1 thorpej
175 1.3 uch return ("SH4 IRL 11");
176 1.1 thorpej }
177 1.1 thorpej
178 1.1 thorpej void *
179 1.1 thorpej gaps_intr_establish(void *v, pci_intr_handle_t ih, int level,
180 1.1 thorpej int (*func)(void *), void *arg)
181 1.1 thorpej {
182 1.3 uch
183 1.3 uch return (sysasic_intr_establish(ih, func, arg));
184 1.1 thorpej }
185 1.1 thorpej
186 1.1 thorpej void
187 1.1 thorpej gaps_intr_disestablish(void *v, void *ih)
188 1.1 thorpej {
189 1.1 thorpej
190 1.1 thorpej panic("gaps_intr_disestablish: not implemented");
191 1.1 thorpej }
192