pci_machdep.c revision 1.2.8.2 1 1.2.8.2 matt /* $NetBSD: pci_machdep.c,v 1.2.8.2 2007/11/06 23:16:25 matt Exp $ */
2 1.2.8.2 matt
3 1.2.8.2 matt /*
4 1.2.8.2 matt * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
5 1.2.8.2 matt * Copyright (c) 1994 Charles M. Hannum. All rights reserved.
6 1.2.8.2 matt *
7 1.2.8.2 matt * Redistribution and use in source and binary forms, with or without
8 1.2.8.2 matt * modification, are permitted provided that the following conditions
9 1.2.8.2 matt * are met:
10 1.2.8.2 matt * 1. Redistributions of source code must retain the above copyright
11 1.2.8.2 matt * notice, this list of conditions and the following disclaimer.
12 1.2.8.2 matt * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.8.2 matt * notice, this list of conditions and the following disclaimer in the
14 1.2.8.2 matt * documentation and/or other materials provided with the distribution.
15 1.2.8.2 matt * 3. All advertising materials mentioning features or use of this software
16 1.2.8.2 matt * must display the following acknowledgement:
17 1.2.8.2 matt * This product includes software developed by Charles M. Hannum.
18 1.2.8.2 matt * 4. The name of the author may not be used to endorse or promote products
19 1.2.8.2 matt * derived from this software without specific prior written permission.
20 1.2.8.2 matt *
21 1.2.8.2 matt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.2.8.2 matt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.2.8.2 matt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.2.8.2 matt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.2.8.2 matt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.2.8.2 matt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.2.8.2 matt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.2.8.2 matt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.2.8.2 matt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.2.8.2 matt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.2.8.2 matt */
32 1.2.8.2 matt
33 1.2.8.2 matt /*
34 1.2.8.2 matt * Machine-specific functions for PCI autoconfiguration.
35 1.2.8.2 matt *
36 1.2.8.2 matt * On PCs, there are two methods of generating PCI configuration cycles.
37 1.2.8.2 matt * We try to detect the appropriate mechanism for this machine and set
38 1.2.8.2 matt * up a few function pointers to access the correct method directly.
39 1.2.8.2 matt *
40 1.2.8.2 matt * The configuration method can be hard-coded in the config file by
41 1.2.8.2 matt * using `options PCI_CONF_MODE=N', where `N' is the configuration mode
42 1.2.8.2 matt * as defined section 3.6.4.1, `Generating Configuration Cycles'.
43 1.2.8.2 matt */
44 1.2.8.2 matt
45 1.2.8.2 matt #include <sys/cdefs.h>
46 1.2.8.2 matt __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.2.8.2 2007/11/06 23:16:25 matt Exp $");
47 1.2.8.2 matt
48 1.2.8.2 matt #include <sys/types.h>
49 1.2.8.2 matt #include <sys/param.h>
50 1.2.8.2 matt #include <sys/device.h>
51 1.2.8.2 matt #include <sys/errno.h>
52 1.2.8.2 matt #include <sys/extent.h>
53 1.2.8.2 matt #include <sys/malloc.h>
54 1.2.8.2 matt #include <sys/queue.h>
55 1.2.8.2 matt #include <sys/systm.h>
56 1.2.8.2 matt #include <sys/time.h>
57 1.2.8.2 matt #include <machine/pcb.h>
58 1.2.8.2 matt
59 1.2.8.2 matt #include <uvm/uvm.h>
60 1.2.8.2 matt
61 1.2.8.2 matt #define _POWERPC_BUS_DMA_PRIVATE
62 1.2.8.2 matt #include <machine/bus.h>
63 1.2.8.2 matt #include <machine/pio.h>
64 1.2.8.2 matt #include <machine/intr.h>
65 1.2.8.2 matt
66 1.2.8.2 matt #include <dev/ic/cpc700reg.h>
67 1.2.8.2 matt #include <machine/pmppc.h>
68 1.2.8.2 matt
69 1.2.8.2 matt #include <dev/pci/pcivar.h>
70 1.2.8.2 matt #include <dev/pci/pcireg.h>
71 1.2.8.2 matt #include <dev/pci/pcidevs.h>
72 1.2.8.2 matt #include <dev/pci/pciconf.h>
73 1.2.8.2 matt
74 1.2.8.2 matt #include <machine/pmppc_pci_machdep.h>
75 1.2.8.2 matt
76 1.2.8.2 matt /*
77 1.2.8.2 matt * Address conversion as seen from a PCI master.
78 1.2.8.2 matt * XXX Shouldn't use 0x80000000, the actual value
79 1.2.8.2 matt * should come from the BAR.
80 1.2.8.2 matt */
81 1.2.8.2 matt #define PHYS_TO_PCI_MEM(x) ((x) + 0x80000000)
82 1.2.8.2 matt #define PCI_MEM_TO_PHYS(x) ((x) - 0x80000000)
83 1.2.8.2 matt
84 1.2.8.2 matt static bus_addr_t phys_to_pci(bus_dma_tag_t, bus_addr_t);
85 1.2.8.2 matt static bus_addr_t pci_to_phys(bus_dma_tag_t, bus_addr_t);
86 1.2.8.2 matt
87 1.2.8.2 matt extern struct powerpc_bus_dma_tag pci_bus_dma_tag;
88 1.2.8.2 matt
89 1.2.8.2 matt void
90 1.2.8.2 matt pmppc_pci_get_chipset_tag(pci_chipset_tag_t pc)
91 1.2.8.2 matt {
92 1.2.8.2 matt pc->pc_conf_v = (void *)pc;
93 1.2.8.2 matt
94 1.2.8.2 matt pc->pc_attach_hook = genppc_pci_indirect_attach_hook;
95 1.2.8.2 matt pc->pc_bus_maxdevs = genppc_pci_bus_maxdevs;
96 1.2.8.2 matt pc->pc_make_tag = genppc_pci_indirect_make_tag;
97 1.2.8.2 matt pc->pc_conf_read = genppc_pci_indirect_conf_read;
98 1.2.8.2 matt pc->pc_conf_write = genppc_pci_indirect_conf_write;
99 1.2.8.2 matt
100 1.2.8.2 matt pc->pc_intr_v = (void *)pc;
101 1.2.8.2 matt
102 1.2.8.2 matt pc->pc_intr_map = pmppc_pci_intr_map;
103 1.2.8.2 matt pc->pc_intr_string = genppc_pci_intr_string;
104 1.2.8.2 matt pc->pc_intr_evcnt = genppc_pci_intr_evcnt;
105 1.2.8.2 matt pc->pc_intr_establish = genppc_pci_intr_establish;
106 1.2.8.2 matt pc->pc_intr_disestablish = genppc_pci_intr_disestablish;
107 1.2.8.2 matt
108 1.2.8.2 matt pc->pc_conf_interrupt = pmppc_pci_conf_interrupt;
109 1.2.8.2 matt pc->pc_decompose_tag = genppc_pci_indirect_decompose_tag;
110 1.2.8.2 matt pc->pc_conf_hook = genppc_pci_conf_hook;
111 1.2.8.2 matt
112 1.2.8.2 matt pc->pc_addr = mapiodev(CPC_PCICFGADR, 4);
113 1.2.8.2 matt pc->pc_data = mapiodev(CPC_PCICFGDATA, 4);
114 1.2.8.2 matt pc->pc_bus = 0;
115 1.2.8.2 matt pc->pc_node = 0;
116 1.2.8.2 matt pc->pc_memt = 0;
117 1.2.8.2 matt pc->pc_iot = 0;
118 1.2.8.2 matt
119 1.2.8.2 matt /* the following two lines are required because unlike other ports,
120 1.2.8.2 matt * we cannot just add PHYS_TO_BUS_MEM/BUS_MEM_TO_PHYS defines to
121 1.2.8.2 matt * bus.h, because it would impact other evbppc ports.
122 1.2.8.2 matt */
123 1.2.8.2 matt pci_bus_dma_tag._dma_phys_to_bus_mem = phys_to_pci;
124 1.2.8.2 matt pci_bus_dma_tag._dma_bus_mem_to_phys = pci_to_phys;
125 1.2.8.2 matt }
126 1.2.8.2 matt
127 1.2.8.2 matt
128 1.2.8.2 matt static bus_addr_t
129 1.2.8.2 matt phys_to_pci(bus_dma_tag_t t, bus_addr_t a)
130 1.2.8.2 matt {
131 1.2.8.2 matt return PHYS_TO_PCI_MEM(a);
132 1.2.8.2 matt }
133 1.2.8.2 matt
134 1.2.8.2 matt static bus_addr_t pci_to_phys(bus_dma_tag_t t, bus_addr_t a)
135 1.2.8.2 matt {
136 1.2.8.2 matt return PCI_MEM_TO_PHYS(a);
137 1.2.8.2 matt }
138 1.2.8.2 matt
139 1.2.8.2 matt int
140 1.2.8.2 matt pmppc_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
141 1.2.8.2 matt {
142 1.2.8.2 matt int pin = pa->pa_intrpin;
143 1.2.8.2 matt int line = pa->pa_intrline;
144 1.2.8.2 matt
145 1.2.8.2 matt if (pin == 0) {
146 1.2.8.2 matt /* No IRQ used. */
147 1.2.8.2 matt goto bad;
148 1.2.8.2 matt }
149 1.2.8.2 matt
150 1.2.8.2 matt if (pin > 4) {
151 1.2.8.2 matt printf("pci_intr_map: bad interrupt pin %d\n", pin);
152 1.2.8.2 matt goto bad;
153 1.2.8.2 matt }
154 1.2.8.2 matt
155 1.2.8.2 matt if (line == 255) {
156 1.2.8.2 matt printf("pci_intr_map: no mapping for pin %c\n", '@' + pin);
157 1.2.8.2 matt goto bad;
158 1.2.8.2 matt }
159 1.2.8.2 matt /*printf("pci_intr_map pin=%d line=%d\n", pin, line);*/
160 1.2.8.2 matt
161 1.2.8.2 matt switch (line & 3) { /* XXX what should this be? */
162 1.2.8.2 matt case 0: *ihp = PMPPC_I_BPMC_INTA; break;
163 1.2.8.2 matt case 1: *ihp = PMPPC_I_BPMC_INTB; break;
164 1.2.8.2 matt case 2: *ihp = PMPPC_I_BPMC_INTC; break;
165 1.2.8.2 matt case 3: *ihp = PMPPC_I_BPMC_INTD; break;
166 1.2.8.2 matt }
167 1.2.8.2 matt return 0;
168 1.2.8.2 matt
169 1.2.8.2 matt bad:
170 1.2.8.2 matt *ihp = -1;
171 1.2.8.2 matt return 1;
172 1.2.8.2 matt }
173 1.2.8.2 matt
174 1.2.8.2 matt void
175 1.2.8.2 matt pmppc_pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin,
176 1.2.8.2 matt int swiz, int *iline)
177 1.2.8.2 matt {
178 1.2.8.2 matt int line;
179 1.2.8.2 matt
180 1.2.8.2 matt line = (swiz + dev) & 3;
181 1.2.8.2 matt /* XXX UGLY UGLY, figure out the real interrupt mapping */
182 1.2.8.2 matt if (bus==3&&dev==2&&pin==1&&swiz==3) line=2;
183 1.2.8.2 matt /*
184 1.2.8.2 matt printf("pci_conf_interrupt: bus=%d dev=%d pin=%d swiz=%d => line=%d\n",
185 1.2.8.2 matt bus, dev, pin, swiz, line);
186 1.2.8.2 matt */
187 1.2.8.2 matt *iline = line;
188 1.2.8.2 matt }
189