#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: footbridge.c,v 1.30 2022/09/27 06:36:41 skrll Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <uvm/uvm_extern.h>
#include <dev/pci/pcivar.h>
#define _ARM32_BUS_DMA_PRIVATE
#include <sys/bus.h>
#include <machine/intr.h>
#include <machine/bootconfig.h>
#include <arm/cpuconf.h>
#include <arm/cpufunc.h>
#include <arm/footbridge/footbridgevar.h>
#include <arm/footbridge/dc21285reg.h>
#include <arm/footbridge/dc21285mem.h>
#include <arm/footbridge/footbridge.h>
static int footbridge_match(device_t parent, cfdata_t cf, void *aux);
static void footbridge_attach(device_t parent, device_t self, void *aux);
static int footbridge_print(void *aux, const char *pnp);
static int footbridge_intr(void *arg);
CFATTACH_DECL_NEW(footbridge, sizeof(struct footbridge_softc),
footbridge_match, footbridge_attach, NULL, NULL);
extern struct bus_space footbridge_bs_tag;
extern void footbridge_create_io_bs_tag(bus_space_tag_t t, void *cookie);
extern void footbridge_create_mem_bs_tag(bus_space_tag_t t, void *cookie);
struct bus_space footbridge_csr_tag;
struct bus_space footbridge_pci_io_bs_tag;
struct bus_space footbridge_pci_mem_bs_tag;
extern struct arm32_pci_chipset footbridge_pci_chipset;
extern struct arm32_bus_dma_tag footbridge_pci_bus_dma_tag;
extern struct arm32_dma_range footbridge_dma_ranges[1];
struct footbridge_softc *clock_sc;
int footbridge_intr_report = 0;
int footbridge_found;
void
footbridge_pci_bs_tag_init(void)
{
footbridge_create_io_bs_tag(&footbridge_pci_io_bs_tag,
(void *)DC21285_PCI_IO_VBASE);
footbridge_create_mem_bs_tag(&footbridge_pci_mem_bs_tag,
(void *)DC21285_PCI_MEM_BASE);
}
static int
footbridge_print(void *aux, const char *pnp)
{
union footbridge_attach_args *fba = aux;
if (pnp)
aprint_normal("%s at %s", fba->fba_name, pnp);
return(UNCONF);
}
static int
footbridge_match(device_t parent, cfdata_t cf, void *aux)
{
if (footbridge_found)
return(0);
return(1);
}
static void
footbridge_attach(device_t parent, device_t self, void *aux)
{
struct footbridge_softc *sc = device_private(self);
union footbridge_attach_args fba;
int vendor, device, rev;
footbridge_found = 1;
clock_sc = sc;
sc->sc_dev = self;
sc->sc_iot = &footbridge_bs_tag;
if (bus_space_map(sc->sc_iot, DC21285_ARMCSR_VBASE,
DC21285_ARMCSR_VSIZE, 0, &sc->sc_ioh))
panic("%s: Cannot map registers", device_xname(self));
vendor = bus_space_read_2(sc->sc_iot, sc->sc_ioh, VENDOR_ID);
device = bus_space_read_2(sc->sc_iot, sc->sc_ioh, DEVICE_ID);
rev = bus_space_read_1(sc->sc_iot, sc->sc_ioh, REVISION);
if (vendor != DC21285_VENDOR_ID && device != DC21285_DEVICE_ID)
panic("%s: Unrecognised ID", device_xname(self));
aprint_normal(": DC21285 rev %d\n", rev);
bus_space_write_4(sc->sc_iot, sc->sc_ioh, IRQ_ENABLE_CLEAR, 0xffffffff);
bus_space_write_4(sc->sc_iot, sc->sc_ioh, FIQ_ENABLE_CLEAR, 0xffffffff);
sc->sc_serr_ih = footbridge_intr_claim(IRQ_SERR, IPL_HIGH,
"serr", footbridge_intr, sc);
sc->sc_sdram_par_ih = footbridge_intr_claim(IRQ_SDRAM_PARITY, IPL_HIGH,
"sdram parity", footbridge_intr, sc);
sc->sc_data_par_ih = footbridge_intr_claim(IRQ_DATA_PARITY, IPL_HIGH,
"data parity", footbridge_intr, sc);
sc->sc_master_abt_ih = footbridge_intr_claim(IRQ_MASTER_ABORT, IPL_HIGH,
"mast abt", footbridge_intr, sc);
sc->sc_target_abt_ih = footbridge_intr_claim(IRQ_TARGET_ABORT, IPL_HIGH,
"targ abt", footbridge_intr, sc);
sc->sc_parity_ih = footbridge_intr_claim(IRQ_PARITY, IPL_HIGH,
"parity", footbridge_intr, sc);
footbridge_create_io_bs_tag(&footbridge_pci_io_bs_tag,
(void *)DC21285_PCI_IO_VBASE);
footbridge_create_mem_bs_tag(&footbridge_pci_mem_bs_tag,
(void *)DC21285_PCI_MEM_BASE);
calibrate_delay();
{
int memory_size = bootconfig.dram[0].pages * PAGE_SIZE;
uint32_t mask;
for (mask = 0x00040000; mask < 0x10000000; mask <<= 1)
if (mask >= memory_size)
break;
mask--;
mask &= SDRAM_MASK_256MB;
bus_space_write_4(sc->sc_iot, sc->sc_ioh, SDRAM_BA_MASK, mask);
bus_space_write_4(sc->sc_iot, sc->sc_ioh, SDRAM_BA_OFFSET, 0);
bus_space_write_4(sc->sc_iot, sc->sc_ioh, SDRAM_MEMORY_ADDR, 0x20000000);
footbridge_dma_ranges[0].dr_sysbase = bootconfig.dram[0].address;
footbridge_dma_ranges[0].dr_busbase = 0x20000000;
footbridge_dma_ranges[0].dr_len = memory_size;
}
fba.fba_pba.pba_pc = &footbridge_pci_chipset;
fba.fba_pba.pba_iot = &footbridge_pci_io_bs_tag;
fba.fba_pba.pba_memt = &footbridge_pci_mem_bs_tag;
fba.fba_pba.pba_dmat = &footbridge_pci_bus_dma_tag;
fba.fba_pba.pba_dmat64 = NULL;
fba.fba_pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY;
fba.fba_pba.pba_bus = 0;
fba.fba_pba.pba_bridgetag = NULL;
config_found(self, &fba.fba_pba, pcibusprint,
CFARGS(.iattr = "pcibus"));
fba.fba_fca.fca_name = "fcom";
fba.fba_fca.fca_iot = sc->sc_iot;
fba.fba_fca.fca_ioh = sc->sc_ioh;
fba.fba_fca.fca_rx_irq = IRQ_SERIAL_RX;
fba.fba_fca.fca_tx_irq = IRQ_SERIAL_TX;
config_found(self, &fba.fba_fca, footbridge_print,
CFARGS(.iattr = "footbridge"));
#ifdef CPU_SA110
if (cputype == CPU_ID_SA110)
footbridge_sa110_cc_setup();
#endif
}
int
footbridge_intr(void *arg)
{
struct footbridge_softc *sc = arg;
u_int ctrl, intr;
ctrl = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SA_CONTROL);
intr = ctrl & (RECEIVED_SERR | SA_SDRAM_PARITY_ERROR |
PCI_SDRAM_PARITY_ERROR | DMA_SDRAM_PARITY_ERROR);
if (intr) {
if (footbridge_intr_report)
printf("footbridge_intr: ctrl=%08x\n", intr);
bus_space_write_4(sc->sc_iot, sc->sc_ioh, SA_CONTROL,
ctrl | intr);
}
ctrl = bus_space_read_4(sc->sc_iot, sc->sc_ioh, PCI_COMMAND_STATUS_REG);
intr = ctrl & (PCI_STATUS_PARITY_ERROR | PCI_STATUS_MASTER_TARGET_ABORT
| PCI_STATUS_MASTER_ABORT | PCI_STATUS_SPECIAL_ERROR
| PCI_STATUS_PARITY_DETECT);
if (intr) {
if (footbridge_intr_report)
printf("footbridge_intr: pcistat=%08x\n", intr);
bus_space_write_4(sc->sc_iot, sc->sc_ioh,
PCI_COMMAND_STATUS_REG, ctrl | intr);
}
return(0);
}