ixp12x0.c revision 1.13 1 /* $NetBSD: ixp12x0.c,v 1.13 2004/08/30 15:05:16 drochner Exp $ */
2 /*
3 * Copyright (c) 2002, 2003
4 * Ichiro FUKUHARA <ichiro (at) ichiro.org>.
5 * 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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Ichiro FUKUHARA.
18 * 4. The name of the company nor the name of the author may be used to
19 * endorse or promote products derived from this software without specific
20 * prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: ixp12x0.c,v 1.13 2004/08/30 15:05:16 drochner Exp $");
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/device.h>
41 #include <uvm/uvm.h>
42
43 #include <machine/bus.h>
44
45 #include <arm/ixp12x0/ixp12x0reg.h>
46 #include <arm/ixp12x0/ixp12x0var.h>
47 #include <arm/ixp12x0/ixp12x0_pcireg.h>
48
49 static struct ixp12x0_softc *ixp12x0_softc;
50
51 void
52 ixp12x0_attach(sc)
53 struct ixp12x0_softc *sc;
54 {
55 struct pcibus_attach_args pba;
56 pcireg_t reg;
57
58 ixp12x0_softc = sc;
59
60 printf("\n");
61
62 sc->sc_iot = &ixp12x0_bs_tag;
63
64 /*
65 * Mapping for PCI Configuration Spase Registers
66 */
67 if (bus_space_map(sc->sc_iot, IXP12X0_PCI_HWBASE, IXP12X0_PCI_SIZE,
68 0, &sc->sc_pci_ioh))
69 panic("%s: unable to map PCI registers", sc->sc_dev.dv_xname);
70 if (bus_space_map(sc->sc_iot, IXP12X0_PCI_TYPE0_HWBASE,
71 IXP12X0_PCI_TYPE0_SIZE, 0, &sc->sc_conf0_ioh))
72 panic("%s: unable to map PCI Configutation 0\n",
73 sc->sc_dev.dv_xname);
74 if (bus_space_map(sc->sc_iot, IXP12X0_PCI_TYPE1_HWBASE,
75 IXP12X0_PCI_TYPE0_SIZE, 1, &sc->sc_conf1_ioh))
76 panic("%s: unable to map PCI Configutation 1\n",
77 sc->sc_dev.dv_xname);
78
79 /*
80 * PCI bus reset
81 */
82 /* disable PCI command */
83 bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
84 PCI_COMMAND_STATUS_REG, 0xffff0000);
85 /* XXX assert PCI reset Mode */
86 reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh,
87 SA_CONTROL) &~ SA_CONTROL_PNR;
88 bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
89 SA_CONTROL, reg);
90 DELAY(10);
91
92 /* XXX Disable door bell and outbound interrupt */
93 bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
94 PCI_CAP_PTR, 0xc);
95 /* Disable door bell int to PCI */
96 bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
97 DBELL_PCI_MASK, 0x0);
98 /* Disable door bell int to SA-core */
99 bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
100 DBELL_SA_MASK, 0x0);
101
102 /* We setup a 1:1 memory map of bus<->physical addresses */
103 bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
104 PCI_ADDR_EXT,
105 PCI_ADDR_EXT_PMSA(IXP12X0_PCI_MEM_HWBASE));
106
107 /* XXX Negate PCI reset */
108 reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh,
109 SA_CONTROL) | SA_CONTROL_PNR;
110 bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
111 SA_CONTROL, reg);
112 DELAY(10);
113 /*
114 * specify window size of memory access and SDRAM.
115 */
116 bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_MEM_BAR,
117 IXP1200_PCI_MEM_BAR & IXP_PCI_MEM_BAR_MASK);
118
119 bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_IO_BAR,
120 IXP1200_PCI_IO_BAR & IXP_PCI_IO_BAR_MASK);
121
122 bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_DRAM_BAR,
123 IXP1200_PCI_DRAM_BAR & IXP_PCI_DRAM_BAR_MASK);
124
125 bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
126 CSR_BASE_ADDR_MASK, CSR_BASE_ADDR_MASK_1M);
127 bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
128 DRAM_BASE_ADDR_MASK, DRAM_BASE_ADDR_MASK_256MB);
129
130 #ifdef PCI_DEBUG
131 printf("IXP_PCI_MEM_BAR = 0x%08x\nIXP_PCI_IO_BAR = 0x%08x\nIXP_PCI_DRAM_BAR = 0x%08x\nPCI_ADDR_EXT = 0x%08x\nCSR_BASE_ADDR_MASK = 0x%08x\nDRAM_BASE_ADDR_MASK = 0x%08x\n",
132 bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_MEM_BAR),
133 bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_IO_BAR),
134 bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_DRAM_BAR),
135 bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, PCI_ADDR_EXT),
136 bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, CSR_BASE_ADDR_MASK),
137 bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, DRAM_BASE_ADDR_MASK));
138 #endif
139 /* Initialize complete */
140 reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh,
141 SA_CONTROL) | 0x1;
142 bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
143 SA_CONTROL, reg);
144 #ifdef PCI_DEBUG
145 printf("SA_CONTROL = 0x%08x\n",
146 bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, SA_CONTROL));
147 #endif
148 /*
149 * Enable bus mastering and I/O,memory access
150 */
151 /* host only */
152 reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh,
153 PCI_COMMAND_STATUS_REG) |
154 PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
155 PCI_COMMAND_PARITY_ENABLE | PCI_COMMAND_SERR_ENABLE |
156 PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_INVALIDATE_ENABLE;
157 bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
158 PCI_COMMAND_STATUS_REG, reg);
159 #ifdef PCI_DEBUG
160 printf("PCI_COMMAND_STATUS_REG = 0x%08x\n",
161 bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, PCI_COMMAND_STATUS_REG));
162 #endif
163 /*
164 * Initialize the PCI chipset tag.
165 */
166 ixp12x0_pci_init(&sc->ia_pci_chipset, sc);
167
168 /*
169 * Initialize the DMA tags.
170 */
171 ixp12x0_pci_dma_init(sc);
172
173 /*
174 * Attach the PCI bus.
175 */
176 pba.pba_pc = &sc->ia_pci_chipset;
177 pba.pba_iot = &ixp12x0_bs_tag;
178 pba.pba_memt = &ixp12x0_bs_tag;
179 pba.pba_dmat = &sc->ia_pci_dmat;
180 pba.pba_dmat64 = NULL;
181 pba.pba_bus = 0; /* bus number = 0 */
182 pba.pba_intrswiz = 0; /* XXX */
183 pba.pba_intrtag = 0;
184 pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
185 PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
186 (void) config_found_ia(&sc->sc_dev, "pcibus", &pba, pcibusprint);
187 }
188
189 void
190 ixp12x0_reset(void)
191 {
192 bus_space_write_4(ixp12x0_softc->sc_iot, ixp12x0_softc->sc_pci_ioh,
193 IXPPCI_IXP1200_RESET, RESET_FULL);
194 }
195