#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.38 2015/10/02 05:22:50 msaitoh Exp $");
#define _MIPS_BUS_DMA_PRIVATE
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/cpu.h>
#include <sys/device.h>
#include <sys/errno.h>
#include <sys/extent.h>
#include <sys/intr.h>
#include <sys/systm.h>
#include <sys/time.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcidevs.h>
#include <dev/pci/pciconf.h>
#include <dev/pci/pciide_apollo_reg.h>
#include <cobalt/dev/gtreg.h>
struct mips_bus_dma_tag pci_bus_dma_tag = {
._dmamap_ops = _BUS_DMAMAP_OPS_INITIALIZER,
._dmamem_ops = _BUS_DMAMEM_OPS_INITIALIZER,
._dmatag_ops = _BUS_DMATAG_OPS_INITIALIZER,
};
void
pci_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba)
{
return;
}
int
pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
{
return 32;
}
pcitag_t
pci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function)
{
return (bus << 16) | (device << 11) | (function << 8);
}
void
pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp)
{
if (bp != NULL)
*bp = (tag >> 16) & 0xff;
if (dp != NULL)
*dp = (tag >> 11) & 0x1f;
if (fp != NULL)
*fp = (tag >> 8) & 0x07;
}
pcireg_t
pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
{
pcireg_t data;
int bus, dev, func;
KASSERT(pc != NULL);
if ((unsigned int)reg >= PCI_CONF_SIZE)
return (pcireg_t) -1;
pci_decompose_tag(pc, tag, &bus, &dev, &func);
if (bus == 0 && dev == 6)
return 0;
if (bus == 0 && dev == 31)
return 0;
bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR,
PCICFG_ENABLE | tag | reg);
data = bus_space_read_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_DATA);
bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 0);
return data;
}
void
pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
{
if ((unsigned int)reg >= PCI_CONF_SIZE)
return;
bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR,
PCICFG_ENABLE | tag | reg);
bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_DATA, data);
bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 0);
}
int
pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
{
pci_chipset_tag_t pc = pa->pa_pc;
pcitag_t intrtag = pa->pa_intrtag;
int pin = pa->pa_intrpin;
int line = pa->pa_intrline;
int bus, dev, func;
pci_decompose_tag(pc, intrtag, &bus, &dev, &func);
if (cobalt_id == COBALT_ID_QUBE2700) {
if (bus == 0 && dev == 7 && pin == PCI_INTERRUPT_PIN_A) {
*ihp = NICU_INT + 2;
return 0;
}
} else {
if (bus == 0 && dev == 7 && pin == PCI_INTERRUPT_PIN_A) {
*ihp = NICU_INT + 1;
return 0;
}
if (bus == 0 && dev == 12 && pin == PCI_INTERRUPT_PIN_A) {
*ihp = NICU_INT + 2;
return 0;
}
}
if (line == 0 || line >= NICU_INT)
return -1;
*ihp = line;
return 0;
}
const char *
pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf, size_t len)
{
if (ih >= NICU_INT)
snprintf(buf, len, "level %d", ih - NICU_INT);
else
snprintf(buf, len, "irq %d", ih);
return buf;
}
const struct evcnt *
pci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih)
{
return NULL;
}
int
pci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ih,
int attr, uint64_t data)
{
switch (attr) {
case PCI_INTR_MPSAFE:
return 0;
default:
return ENODEV;
}
}
void *
pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
int (*func)(void *), void *arg)
{
if (ih >= NICU_INT)
return cpu_intr_establish(ih - NICU_INT, level, func, arg);
else
return icu_intr_establish(ih, IST_LEVEL, level, func, arg);
}
void
pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
{
cpu_intr_disestablish(cookie);
icu_intr_disestablish(cookie);
}
void
pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin, int swiz,
int *iline)
{
if (bus == 0 && dev == 10 && pin != PCI_INTERRUPT_PIN_NONE)
*iline = 9;
}
int
pci_conf_hook(pci_chipset_tag_t pc, int bus, int dev, int func, pcireg_t id)
{
if (PCI_VENDOR(id) == 0)
return 0;
if (bus == 0 && dev == 6)
return 0;
if (bus == 0 && dev == 31)
return 0;
if (PCI_VENDOR(id) == PCI_VENDOR_MARVELL &&
PCI_PRODUCT(id) == PCI_PRODUCT_MARVELL_GT64011)
return 0;
if (bus == 0 && dev == 9 && (func == 0 || func == 2))
return 0;
if (bus == 0 && dev == 9 && func == 1) {
pcitag_t tag;
pcireg_t csr;
#define APO_VIAIDECONF (APO_VIA_REGBASE + 0x00)
tag = pci_make_tag(pc, bus, dev, func);
csr = pci_conf_read(pc, tag, APO_VIAIDECONF);
pci_conf_write(pc, tag, APO_VIAIDECONF,
csr | APO_IDECONF_EN(1));
}
return PCI_CONF_DEFAULT & ~(PCI_COMMAND_SERR_ENABLE |
PCI_COMMAND_PARITY_ENABLE);
}