#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: npwr_fc_pci.c,v 1.5 2019/01/09 07:49:22 msaitoh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <machine/autoconf.h>
#include <sys/bus.h>
#include <evbarm/iq80321/iq80321reg.h>
#include <evbarm/iq80321/iq80321var.h>
#include <arm/xscale/i80321reg.h>
#include <arm/xscale/i80321var.h>
#include <dev/pci/pcidevs.h>
#include <dev/pci/ppbreg.h>
int iq80321_pci_intr_map(const struct pci_attach_args *,
pci_intr_handle_t *);
const char *iq80321_pci_intr_string(void *, pci_intr_handle_t, char *, size_t);
const struct evcnt *iq80321_pci_intr_evcnt(void *, pci_intr_handle_t);
void *iq80321_pci_intr_establish(void *, pci_intr_handle_t,
int, int (*func)(void *), void *, const char *);
void iq80321_pci_intr_disestablish(void *, void *);
void
iq80321_pci_init(pci_chipset_tag_t pc, void *cookie)
{
pc->pc_intr_v = cookie;
pc->pc_intr_map = iq80321_pci_intr_map;
pc->pc_intr_string = iq80321_pci_intr_string;
pc->pc_intr_evcnt = iq80321_pci_intr_evcnt;
pc->pc_intr_establish = iq80321_pci_intr_establish;
pc->pc_intr_disestablish = iq80321_pci_intr_disestablish;
}
int
iq80321_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
{
struct i80321_softc *sc = pa->pa_pc->pc_intr_v;
int b, d, f;
uint32_t busno;
busno = bus_space_read_4(sc->sc_st, sc->sc_atu_sh, ATU_PCIXSR);
busno = PCIXSR_BUSNO(busno);
if (busno == 0xff)
busno = 0;
pci_decompose_tag(pa->pa_pc, pa->pa_intrtag, &b, &d, &f);
if (b != busno)
goto no_mapping;
switch (d) {
case 0:
if (pa->pa_intrpin == 1) {
*ihp = ICU_INT_XINT(0);
return (0);
}
if (pa->pa_intrpin == 2) {
*ihp = ICU_INT_XINT(1);
return (0);
}
goto no_mapping;
case 1:
if (pa->pa_intrpin == 1) {
*ihp = ICU_INT_XINT(2);
return (0);
}
goto no_mapping;
case 2:
if (pa->pa_intrpin == 1) {
*ihp = ICU_INT_XINT(3);
return (0);
}
goto no_mapping;
default:
no_mapping:
printf("iq80321_pci_intr_map: no mapping for %d/%d/%d\n",
pa->pa_bus, pa->pa_device, pa->pa_function);
return (1);
}
return (0);
}
const char *
iq80321_pci_intr_string(void *v, pci_intr_handle_t ih, char *buf, size_t len)
{
strlcpy(buf, i80321_irqnames[ih], len);
return buf;
}
const struct evcnt *
iq80321_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
{
return (NULL);
}
void *
iq80321_pci_intr_establish(void *v, pci_intr_handle_t ih, int ipl,
int (*func)(void *), void *arg, const char *xname)
{
return (i80321_intr_establish(ih, ipl, func, arg));
}
void
iq80321_pci_intr_disestablish(void *v, void *cookie)
{
i80321_intr_disestablish(cookie);
}