/*
* Copyright (c) 2017 Jonathan A. Kollasch
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
for (size_t i = 0; i < __arraycount(int_ctl); i++) {
val = regread_1(sc, VLPCI_INT_CTL_REG(int_ctl[i]));
val &= ~VLPCI_INT_CTL_INT2IRQ(int_ctl[i]);
val |= VLPCI_INT_CTL_ENA(int_ctl[i]);
val |= __SHIFTIN(VLPCI_INT_CTL_IRQ(VLPCI_IRQ),
VLPCI_INT_CTL_INT2IRQ(int_ctl[i]));
regwrite_1(sc, VLPCI_INT_CTL_REG(int_ctl[i]), val);
}
}
static int
vlpci_match(device_t parent, struct cfdata *match, void *aux)
{
struct ofbus_attach_args * const oba = aux;
if (bus_space_map(&isa_io_bs_tag, VLPCI_INTREG_BASE, VLPCI_INTREG_SZ,
0, &sc->sc_reg_ioh) != 0) {
aprint_error_dev(self, "failed to map internal reg port\n");
return;
}
if (bus_space_map(&isa_io_bs_tag, VLPCI_CFGREG_BASE, VLPCI_CFGREG_SZ,
0, &sc->sc_conf_ioh) != 0) {
aprint_error_dev(self, "failed to map configuration port\n");
return;
}
/* Enable VLB/PCI bridge */
regwrite_1(sc, VLPCI_MISC_1_REG, VLPCI_MISC_1_LOCAL_PIN |
VLPCI_MISC_1_COMPAT_ISA_BOFF);
regwrite_1(sc, VLPCI_MISC_CTL_REG, __SHIFTIN(VLPCI_MISC_CTL_HIADDR_DIS,
VLPCI_MISC_CTL_HIADDR) | VLPCI_MISC_CTL_IOCHCK_PIN);
regwrite_1(sc, VLPCI_CFG_MISC_CTL_REG,
__SHIFTIN(VLPCI_CFG_MISC_CTL_INT_CTL_CONV,
VLPCI_CFG_MISC_CTL_INT_CTL) | VLPCI_CFG_MISC_CTL_LREQI_LGNTO_PIN);
regwrite_1(sc, VLPCI_IRQ_MODE_REG, 0x00); /* don't do per-INTx conversions */
vlpci_steer_irq(sc);
/*
* XXX
* set memory size to 255MB, so the bridge knows which cycles go to RAM
* shark's RAM is in the upper half of the lower 256MB, part of the
* lower half is occupied by the graphics chip
* ... or that's the theory. OF puts PCI BARS at 0x02000000 which
* overlaps with when we do this and pci memory access doesn't work.
*/
regwrite_1(sc, VLPCI_OBD_MEM_SZ_REG, 1);
vlpci_mem_paddr = VLPCI_PCI_MEM_BASE; /* get from OF! */
/*
* we map in 1MB at 0x02000000, so program window #1 accordingly
*/
regwrite_1(sc, VLPCI_PCI_WND_HIADDR_REG(VLPCI_PCI_WND_NO_2),
VLPCI_PCI_WND_HIADDR_MEM(vlpci_mem_paddr));
regwrite_1(sc, VLPCI_PCI_WND_LOADDR_REG(VLPCI_PCI_WND_NO_2),
VLPCI_PCI_WND_LOADDR_MEM(vlpci_mem_paddr));
regwrite_1(sc, VLPCI_PCI_WND_ATTR_REG(VLPCI_PCI_WND_NO_2),
VLPCI_PCI_WND_ATTR_PCI |
__SHIFTIN(VLPCI_PCI_WND_ATTR_SZ_MEM(VLPCI_PCI_MEM_SZ),
VLPCI_PCI_WND_ATTR_SZ));
/* now map in some of the memory space */
printf("vlpci_mem_vaddr %08lx\n", vlpci_mem_vaddr);
memcpy(&vlpci_memt, &isa_io_bs_tag, sizeof(struct bus_space));
vlpci_memt.bs_cookie = (void *)vlpci_mem_vaddr;
vlpci_memt.bs_map = vlpci_map;
vlpci_memt.bs_mmap = vlpci_mmap;
/* try to assure IO space is enabled on the default device-function */
tag = vlpci_pc_make_tag(sc, 0, VLPCI_ADDON_DEV_NO, 0);
cmd = vlpci_pc_conf_read(sc, tag, PCI_COMMAND_STATUS_REG);
vlpci_pc_conf_write(sc, tag, PCI_COMMAND_STATUS_REG,
cmd | PCI_COMMAND_IO_ENABLE);