Deleted Added
full compact
42c42
< __FBSDID("$FreeBSD: head/sys/arm/mv/mv_pci.c 240489 2012-09-14 09:57:41Z gber $");
---
> __FBSDID("$FreeBSD: head/sys/arm/mv/mv_pci.c 240493 2012-09-14 10:06:56Z gber $");
55a56,57
> #include <machine/intr.h>
>
75a78,83
> #ifdef DEBUG
> #define debugf(fmt, args...) do { printf(fmt,##args); } while (0)
> #else
> #define debugf(fmt, args...)
> #endif
>
84d91
< #define PCI_REG_P2P_CONF 0x1D14
129a137,139
> struct mtx sc_msi_mtx;
> uint32_t sc_msi_bitmap;
>
168a179,183
> #if defined(SOC_MV_ARMADAXP)
> static int mv_pcib_alloc_msi(device_t, device_t, int, int, int *);
> static int mv_pcib_map_msi(device_t, device_t, int, uint64_t *, uint32_t *);
> static int mv_pcib_release_msi(device_t, device_t, int, int *);
> #endif
193c208,214
<
---
>
> #if defined(SOC_MV_ARMADAXP)
> DEVMETHOD(pcib_alloc_msi, mv_pcib_alloc_msi),
> DEVMETHOD(pcib_release_msi, mv_pcib_release_msi),
> DEVMETHOD(pcib_map_msi, mv_pcib_map_msi),
> #endif
>
320a342
> mtx_init(&sc->sc_msi_mtx, "msi_mtx", NULL, MTX_DEF);
929a952,1028
> #if defined(SOC_MV_ARMADAXP)
> static int
> mv_pcib_map_msi(device_t dev, device_t child, int irq, uint64_t *addr,
> uint32_t *data)
> {
> struct mv_pcib_softc *sc;
>
> sc = device_get_softc(dev);
> irq = irq - MSI_IRQ;
>
> /* validate parameters */
> if (isclr(&sc->sc_msi_bitmap, irq)) {
> device_printf(dev, "invalid MSI 0x%x\n", irq);
> return (EINVAL);
> }
>
> mv_msi_data(irq, addr, data);
>
> debugf("%s: irq: %d addr: %jx data: %x\n",
> __func__, irq, *addr, *data);
>
> return (0);
> }
>
> static int
> mv_pcib_alloc_msi(device_t dev, device_t child, int count,
> int maxcount __unused, int *irqs)
> {
> struct mv_pcib_softc *sc;
> u_int start = 0, i;
>
> if (powerof2(count) == 0 || count > MSI_IRQ_NUM)
> return (EINVAL);
>
> sc = device_get_softc(dev);
> mtx_lock(&sc->sc_msi_mtx);
>
> for (start = 0; (start + count) < MSI_IRQ_NUM; start++) {
> for (i = start; i < start + count; i++) {
> if (isset(&sc->sc_msi_bitmap, i))
> break;
> }
> if (i == start + count)
> break;
> }
>
> if ((start + count) == MSI_IRQ_NUM) {
> mtx_unlock(&sc->sc_msi_mtx);
> return (ENXIO);
> }
>
> for (i = start; i < start + count; i++) {
> setbit(&sc->sc_msi_bitmap, i);
> irqs[i] = MSI_IRQ + i;
> }
> debugf("%s: start: %x count: %x\n", __func__, start, count);
>
> mtx_unlock(&sc->sc_msi_mtx);
> return (0);
> }
>
> static int
> mv_pcib_release_msi(device_t dev, device_t child, int count, int *irqs)
> {
> struct mv_pcib_softc *sc;
> u_int i;
>
> sc = device_get_softc(dev);
> mtx_lock(&sc->sc_msi_mtx);
>
> for (i = 0; i < count; i++)
> clrbit(&sc->sc_msi_bitmap, irqs[i] - MSI_IRQ);
>
> mtx_unlock(&sc->sc_msi_mtx);
> return (0);
> }
> #endif