1 1.22 andvar /* $NetBSD: ixp12x0.c,v 1.22 2025/06/25 06:21:28 andvar Exp $ */ 2 1.1 ichiro /* 3 1.6 ichiro * Copyright (c) 2002, 2003 4 1.1 ichiro * Ichiro FUKUHARA <ichiro (at) ichiro.org>. 5 1.1 ichiro * All rights reserved. 6 1.1 ichiro * 7 1.1 ichiro * Redistribution and use in source and binary forms, with or without 8 1.1 ichiro * modification, are permitted provided that the following conditions 9 1.1 ichiro * are met: 10 1.1 ichiro * 1. Redistributions of source code must retain the above copyright 11 1.1 ichiro * notice, this list of conditions and the following disclaimer. 12 1.1 ichiro * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 ichiro * notice, this list of conditions and the following disclaimer in the 14 1.1 ichiro * documentation and/or other materials provided with the distribution. 15 1.1 ichiro * 16 1.1 ichiro * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR 17 1.1 ichiro * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 1.1 ichiro * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 1.1 ichiro * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR 20 1.1 ichiro * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 1.1 ichiro * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 1.1 ichiro * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 1.1 ichiro * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 1.1 ichiro * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 1.1 ichiro * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 1.1 ichiro * SUCH DAMAGE. 27 1.1 ichiro */ 28 1.7 igy 29 1.7 igy #include <sys/cdefs.h> 30 1.22 andvar __KERNEL_RCSID(0, "$NetBSD: ixp12x0.c,v 1.22 2025/06/25 06:21:28 andvar Exp $"); 31 1.1 ichiro 32 1.1 ichiro #include <sys/param.h> 33 1.1 ichiro #include <sys/systm.h> 34 1.1 ichiro #include <sys/device.h> 35 1.1 ichiro #include <uvm/uvm.h> 36 1.1 ichiro 37 1.18 dyoung #include <sys/bus.h> 38 1.1 ichiro 39 1.1 ichiro #include <arm/ixp12x0/ixp12x0reg.h> 40 1.1 ichiro #include <arm/ixp12x0/ixp12x0var.h> 41 1.1 ichiro #include <arm/ixp12x0/ixp12x0_pcireg.h> 42 1.1 ichiro 43 1.1 ichiro static struct ixp12x0_softc *ixp12x0_softc; 44 1.1 ichiro 45 1.1 ichiro void 46 1.15 dsl ixp12x0_attach(struct ixp12x0_softc *sc) 47 1.1 ichiro { 48 1.1 ichiro struct pcibus_attach_args pba; 49 1.1 ichiro pcireg_t reg; 50 1.1 ichiro 51 1.1 ichiro ixp12x0_softc = sc; 52 1.1 ichiro 53 1.1 ichiro printf("\n"); 54 1.11 igy 55 1.11 igy sc->sc_iot = &ixp12x0_bs_tag; 56 1.11 igy 57 1.1 ichiro /* 58 1.22 andvar * Mapping for PCI Configuration Space Registers 59 1.1 ichiro */ 60 1.11 igy if (bus_space_map(sc->sc_iot, IXP12X0_PCI_HWBASE, IXP12X0_PCI_SIZE, 61 1.11 igy 0, &sc->sc_pci_ioh)) 62 1.19 chs panic("%s: unable to map PCI registers", device_xname(sc->sc_dev)); 63 1.11 igy if (bus_space_map(sc->sc_iot, IXP12X0_PCI_TYPE0_HWBASE, 64 1.11 igy IXP12X0_PCI_TYPE0_SIZE, 0, &sc->sc_conf0_ioh)) 65 1.11 igy panic("%s: unable to map PCI Configutation 0\n", 66 1.19 chs device_xname(sc->sc_dev)); 67 1.11 igy if (bus_space_map(sc->sc_iot, IXP12X0_PCI_TYPE1_HWBASE, 68 1.11 igy IXP12X0_PCI_TYPE0_SIZE, 1, &sc->sc_conf1_ioh)) 69 1.11 igy panic("%s: unable to map PCI Configutation 1\n", 70 1.19 chs device_xname(sc->sc_dev)); 71 1.11 igy 72 1.1 ichiro /* 73 1.1 ichiro * PCI bus reset 74 1.1 ichiro */ 75 1.6 ichiro /* disable PCI command */ 76 1.6 ichiro bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, 77 1.6 ichiro PCI_COMMAND_STATUS_REG, 0xffff0000); 78 1.2 ichiro /* XXX assert PCI reset Mode */ 79 1.1 ichiro reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, 80 1.1 ichiro SA_CONTROL) &~ SA_CONTROL_PNR; 81 1.1 ichiro bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, 82 1.1 ichiro SA_CONTROL, reg); 83 1.1 ichiro DELAY(10); 84 1.1 ichiro 85 1.1 ichiro /* XXX Disable door bell and outbound interrupt */ 86 1.1 ichiro bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, 87 1.1 ichiro PCI_CAP_PTR, 0xc); 88 1.1 ichiro /* Disable door bell int to PCI */ 89 1.1 ichiro bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, 90 1.2 ichiro DBELL_PCI_MASK, 0x0); 91 1.1 ichiro /* Disable door bell int to SA-core */ 92 1.1 ichiro bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, 93 1.2 ichiro DBELL_SA_MASK, 0x0); 94 1.1 ichiro 95 1.6 ichiro /* We setup a 1:1 memory map of bus<->physical addresses */ 96 1.1 ichiro bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, 97 1.6 ichiro PCI_ADDR_EXT, 98 1.6 ichiro PCI_ADDR_EXT_PMSA(IXP12X0_PCI_MEM_HWBASE)); 99 1.1 ichiro 100 1.2 ichiro /* XXX Negate PCI reset */ 101 1.1 ichiro reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, 102 1.1 ichiro SA_CONTROL) | SA_CONTROL_PNR; 103 1.1 ichiro bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, 104 1.1 ichiro SA_CONTROL, reg); 105 1.1 ichiro DELAY(10); 106 1.1 ichiro /* 107 1.1 ichiro * specify window size of memory access and SDRAM. 108 1.1 ichiro */ 109 1.6 ichiro bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_MEM_BAR, 110 1.6 ichiro IXP1200_PCI_MEM_BAR & IXP_PCI_MEM_BAR_MASK); 111 1.1 ichiro 112 1.6 ichiro bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_IO_BAR, 113 1.6 ichiro IXP1200_PCI_IO_BAR & IXP_PCI_IO_BAR_MASK); 114 1.1 ichiro 115 1.6 ichiro bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_DRAM_BAR, 116 1.6 ichiro IXP1200_PCI_DRAM_BAR & IXP_PCI_DRAM_BAR_MASK); 117 1.1 ichiro 118 1.1 ichiro bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, 119 1.1 ichiro CSR_BASE_ADDR_MASK, CSR_BASE_ADDR_MASK_1M); 120 1.1 ichiro bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, 121 1.1 ichiro DRAM_BASE_ADDR_MASK, DRAM_BASE_ADDR_MASK_256MB); 122 1.1 ichiro 123 1.6 ichiro #ifdef PCI_DEBUG 124 1.6 ichiro 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", 125 1.1 ichiro bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_MEM_BAR), 126 1.1 ichiro bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_IO_BAR), 127 1.1 ichiro bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_DRAM_BAR), 128 1.6 ichiro bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, PCI_ADDR_EXT), 129 1.6 ichiro bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, CSR_BASE_ADDR_MASK), 130 1.1 ichiro bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, DRAM_BASE_ADDR_MASK)); 131 1.1 ichiro #endif 132 1.1 ichiro /* Initialize complete */ 133 1.1 ichiro reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, 134 1.1 ichiro SA_CONTROL) | 0x1; 135 1.1 ichiro bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, 136 1.1 ichiro SA_CONTROL, reg); 137 1.12 ichiro #ifdef PCI_DEBUG 138 1.1 ichiro printf("SA_CONTROL = 0x%08x\n", 139 1.1 ichiro bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, SA_CONTROL)); 140 1.1 ichiro #endif 141 1.1 ichiro /* 142 1.1 ichiro * Enable bus mastering and I/O,memory access 143 1.1 ichiro */ 144 1.1 ichiro /* host only */ 145 1.1 ichiro reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, 146 1.1 ichiro PCI_COMMAND_STATUS_REG) | 147 1.1 ichiro PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE | 148 1.6 ichiro PCI_COMMAND_PARITY_ENABLE | PCI_COMMAND_SERR_ENABLE | 149 1.1 ichiro PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_INVALIDATE_ENABLE; 150 1.1 ichiro bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, 151 1.1 ichiro PCI_COMMAND_STATUS_REG, reg); 152 1.6 ichiro #ifdef PCI_DEBUG 153 1.1 ichiro printf("PCI_COMMAND_STATUS_REG = 0x%08x\n", 154 1.1 ichiro bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, PCI_COMMAND_STATUS_REG)); 155 1.1 ichiro #endif 156 1.1 ichiro /* 157 1.10 igy * Initialize the PCI chipset tag. 158 1.1 ichiro */ 159 1.1 ichiro ixp12x0_pci_init(&sc->ia_pci_chipset, sc); 160 1.6 ichiro 161 1.6 ichiro /* 162 1.6 ichiro * Initialize the DMA tags. 163 1.6 ichiro */ 164 1.6 ichiro ixp12x0_pci_dma_init(sc); 165 1.1 ichiro 166 1.1 ichiro /* 167 1.1 ichiro * Attach the PCI bus. 168 1.1 ichiro */ 169 1.1 ichiro pba.pba_pc = &sc->ia_pci_chipset; 170 1.10 igy pba.pba_iot = &ixp12x0_bs_tag; 171 1.10 igy pba.pba_memt = &ixp12x0_bs_tag; 172 1.1 ichiro pba.pba_dmat = &sc->ia_pci_dmat; 173 1.8 fvdl pba.pba_dmat64 = NULL; 174 1.1 ichiro pba.pba_bus = 0; /* bus number = 0 */ 175 1.1 ichiro pba.pba_intrswiz = 0; /* XXX */ 176 1.1 ichiro pba.pba_intrtag = 0; 177 1.17 dyoung pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY | 178 1.1 ichiro PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY; 179 1.21 thorpej config_found(sc->sc_dev, &pba, pcibusprint, CFARGS_NONE); 180 1.1 ichiro } 181 1.1 ichiro 182 1.1 ichiro void 183 1.1 ichiro ixp12x0_reset(void) 184 1.1 ichiro { 185 1.1 ichiro bus_space_write_4(ixp12x0_softc->sc_iot, ixp12x0_softc->sc_pci_ioh, 186 1.1 ichiro IXPPCI_IXP1200_RESET, RESET_FULL); 187 1.1 ichiro } 188