From 0cc67e3dd6389b2da4066c7af7f554e906983b18 Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Sun, 25 Sep 2005 21:06:50 +0000 Subject: [PATCH] Fix multiple abuses of __RMAN_RESOURCE_VISIBLE in the arm code. Spotted out by: phk --- sys/arm/arm/nexus.c | 7 +++---- sys/arm/sa11x0/sa11x0.c | 24 +++++++++++++++--------- sys/arm/sa11x0/sa11x0_irqhandler.c | 5 ++++- sys/arm/sa11x0/sa11x0_var.h | 2 ++ sys/arm/xscale/i80321/i80321_pci.c | 10 +--------- sys/arm/xscale/i80321/i80321var.h | 2 ++ sys/arm/xscale/i80321/iq80321.c | 20 ++++++++++++-------- sys/arm/xscale/i80321/obio.c | 24 +++++++++++++----------- sys/arm/xscale/i80321/obiovar.h | 5 +++-- 9 files changed, 55 insertions(+), 44 deletions(-) diff --git a/sys/arm/arm/nexus.c b/sys/arm/arm/nexus.c index 131bbc61c664..c4b77b946996 100644 --- a/sys/arm/arm/nexus.c +++ b/sys/arm/arm/nexus.c @@ -42,7 +42,6 @@ #include __FBSDID("$FreeBSD$"); -#define __RMAN_RESOURCE_VISIBLE #include #include #include @@ -129,7 +128,7 @@ nexus_setup_intr(device_t dev, device_t child, struct resource *res, int flags, driver_intr_t *intr, void *arg, void **cookiep) { arm_setup_irqhandler(device_get_nameunit(child), - intr, arg, res->r_start, flags, cookiep); + intr, arg, rman_get_start(res), flags, cookiep); return (0); } @@ -138,7 +137,7 @@ nexus_teardown_intr(device_t dev, device_t child, struct resource *r, void *ih) { int error; - arm_mask_irq(r->r_start); + arm_mask_irq(rman_get_start(r)); error = arm_remove_irqhandler(ih); return (error); } @@ -216,7 +215,7 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid, return 0; rman_set_bustag(rv, (void*)ARM_BUS_SPACE_MEM); - rman_set_bushandle(rv, rv->r_start); + rman_set_bushandle(rv, rman_get_start(rv)); if (needactivate) { if (bus_activate_resource(child, type, *rid, rv)) { diff --git a/sys/arm/sa11x0/sa11x0.c b/sys/arm/sa11x0/sa11x0.c index 57fc7192bdf3..f0d64566eda1 100644 --- a/sys/arm/sa11x0/sa11x0.c +++ b/sys/arm/sa11x0/sa11x0.c @@ -59,7 +59,6 @@ #include __FBSDID("$FreeBSD$"); -#define __RMAN_RESOURCE_VISIBLE #include #include #include @@ -70,6 +69,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -83,7 +83,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include extern void sa11x0_activateirqs(void); @@ -105,12 +104,12 @@ sa1110_setup_intr(device_t dev, device_t child, int saved_cpsr; if (flags & INTR_TYPE_TTY) - ires->r_start = 15; + rman_set_start(ires, 15); else if (flags & INTR_TYPE_CLK) { - if (ires->r_start == 0) - ires->r_start = 26; + if (rman_get_start(ires) == 0) + rman_set_start(ires, 26); else - ires->r_start = 27; + rman_set_start(ires, 27); } saved_cpsr = SetCPSR(I32_bit, I32_bit); @@ -124,9 +123,11 @@ static struct resource * sa1110_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { - struct resource *res = malloc(sizeof(*res), M_DEVBUF, M_WAITOK); -/* XXX */ - res->r_start = *rid; + struct resource *res; + + res = rman_reserve_resource(&sa11x0_softc->sa11x0_rman, *rid, *rid, + count, flags, child); + return (res); } static int @@ -227,6 +228,11 @@ sa11x0_attach(device_t dev) /* * Attach each devices */ + sc->sa11x0_rman.rm_type = RMAN_ARRAY; + sc->sa11x0_rman.rm_descr = "SA11x0 IRQs"; + if (rman_init(&sc->sa11x0_rman) != 0 || + rman_manage_region(&sc->sa11x0_rman, 0, 32) != 0) + panic("sa11x0_attach: failed to set up rman"); device_add_child(dev, "uart", 0); device_add_child(dev, "saost", 0); bus_generic_probe(dev); diff --git a/sys/arm/sa11x0/sa11x0_irqhandler.c b/sys/arm/sa11x0/sa11x0_irqhandler.c index 5cda4c6d299e..ba6475142c82 100644 --- a/sys/arm/sa11x0/sa11x0_irqhandler.c +++ b/sys/arm/sa11x0/sa11x0_irqhandler.c @@ -86,6 +86,8 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include + #include #include @@ -111,7 +113,8 @@ arm_get_next_irq() { int irq; - if ((irq = (bus_space_read_4(sc->sc_iot, sc->sc_ioh, SAIPIC_IP) & + if ((irq = (bus_space_read_4(sa11x0_softc->sc_iot, sa11x0_softc->sc_ioh, + SAIPIC_IP) & sa11x0_irq_mask)) != 0) return (ffs(irq) - 1); return (-1); diff --git a/sys/arm/sa11x0/sa11x0_var.h b/sys/arm/sa11x0/sa11x0_var.h index b1bf2a018757..1ee4d663f2cb 100644 --- a/sys/arm/sa11x0/sa11x0_var.h +++ b/sys/arm/sa11x0/sa11x0_var.h @@ -45,6 +45,7 @@ #include #include +#include struct sa11x0_softc { device_t sc_dev; @@ -55,6 +56,7 @@ struct sa11x0_softc { bus_space_handle_t sc_dmach; bus_space_handle_t sc_reseth; u_int32_t sc_intrmask; + struct rman sa11x0_rman; }; /* Attach args all devices */ diff --git a/sys/arm/xscale/i80321/i80321_pci.c b/sys/arm/xscale/i80321/i80321_pci.c index 50ebe494db77..0c21b34d301e 100644 --- a/sys/arm/xscale/i80321/i80321_pci.c +++ b/sys/arm/xscale/i80321/i80321_pci.c @@ -48,7 +48,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#define __RMAN_RESOURCE_VISIBLE #include #include @@ -353,16 +352,9 @@ i80321_pci_alloc_resource(device_t bus, device_t child, int type, int *rid, bus_space_tag_t bt = NULL; bus_space_handle_t bh = 0; - if (type == SYS_RES_IRQ) { - rv = malloc(sizeof(*rv), M_DEVBUF, M_WAITOK); - rv->r_start = start; - rv->r_end = end; - rv->r_rid = *rid; - return (rv); - } switch (type) { case SYS_RES_IRQ: - rm = &sc->sc_mem_rman; + rm = &sc->sc_irq_rman; break; case SYS_RES_MEMORY: rm = &sc->sc_mem_rman; diff --git a/sys/arm/xscale/i80321/i80321var.h b/sys/arm/xscale/i80321/i80321var.h index fef194ba5333..903b18e580c0 100644 --- a/sys/arm/xscale/i80321/i80321var.h +++ b/sys/arm/xscale/i80321/i80321var.h @@ -43,6 +43,7 @@ #include #include +#include /* * There are roughly 32 interrupt sources. @@ -107,6 +108,7 @@ struct i80321_softc { /* GPIO state */ uint8_t sc_gpio_dir; /* GPIO pin direction (1 == output) */ uint8_t sc_gpio_val; /* GPIO output pin value */ + struct rman sc_irq_rman; }; void i80321_sdram_bounds(bus_space_tag_t, bus_space_handle_t, diff --git a/sys/arm/xscale/i80321/iq80321.c b/sys/arm/xscale/i80321/iq80321.c index 32924063d91c..32a9981094a6 100644 --- a/sys/arm/xscale/i80321/iq80321.c +++ b/sys/arm/xscale/i80321/iq80321.c @@ -51,7 +51,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#define __RMAN_RESOURCE_VISIBLE #include #include #include @@ -251,6 +250,12 @@ iq80321_attach(device_t dev) busno = PCIXSR_BUSNO(busno); if (busno == 0xff) busno = 0; + sc->sc_irq_rman.rm_type = RMAN_ARRAY; + sc->sc_irq_rman.rm_descr = "i80321 IRQs"; + if (rman_init(&sc->sc_irq_rman) != 0 || + rman_manage_region(&sc->sc_irq_rman, 0, 25) != 0) + panic("i80321_attach: failed to set up IRQ rman"); + device_add_child(dev, "obio", 0); device_add_child(dev, "itimer", 0); device_add_child(dev, "iopwdog", 0); @@ -291,12 +296,11 @@ static struct resource * iq80321_alloc_resource(device_t dev, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { - if (type == SYS_RES_IRQ) { - struct resource *res = malloc(sizeof(*res), M_DEVBUF, M_WAITOK); - res->r_start = start; - res->r_end = end; - return (res); - } + struct i80321_softc *sc = device_get_softc(dev); + + if (type == SYS_RES_IRQ) + return (rman_reserve_resource(&sc->sc_irq_rman, + start, end, count, flags, child)); return (NULL); } @@ -307,7 +311,7 @@ iq80321_setup_intr(device_t dev, device_t child, { BUS_SETUP_INTR(device_get_parent(dev), child, ires, flags, intr, arg, cookiep); - intr_enabled |= 1 << ires->r_start; + intr_enabled |= 1 << rman_get_start(ires); i80321_set_intrmask(); return (0); diff --git a/sys/arm/xscale/i80321/obio.c b/sys/arm/xscale/i80321/obio.c index 523f14e451f8..a79dcf09c672 100644 --- a/sys/arm/xscale/i80321/obio.c +++ b/sys/arm/xscale/i80321/obio.c @@ -48,7 +48,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#define __RMAN_RESOURCE_VISIBLE #include #include @@ -82,6 +81,11 @@ obio_attach(device_t dev) rman_manage_region(&sc->oba_rman, sc->oba_addr, sc->oba_addr + sc->oba_size) != 0) panic("obio_attach: failed to set up I/O rman"); + sc->oba_irq_rman.rm_type = RMAN_ARRAY; + sc->oba_irq_rman.rm_descr = "OBIO IRQ"; + if (rman_init(&sc->oba_irq_rman) != 0 || + rman_manage_region(&sc->oba_irq_rman, 28, 28) != 0) + panic("obio_attach: failed to set up IRQ rman"); device_add_child(dev, "uart", 0); bus_generic_probe(dev); bus_generic_attach(dev); @@ -94,34 +98,32 @@ obio_alloc_resource(device_t bus, device_t child, int type, int *rid, { struct resource *rv; struct rman *rm; - bus_space_tag_t bt; - bus_space_handle_t bh; + bus_space_tag_t bt = NULL; + bus_space_handle_t bh = 0; struct obio_softc *sc = device_get_softc(bus); - if (type == SYS_RES_IRQ) { - rv = malloc(sizeof(*rv), M_DEVBUF, M_WAITOK); - rv->r_start = 28; - rv->r_end = 28; - rv->r_rid = *rid; - return (rv); - } switch (type) { + case SYS_RES_IRQ: + rm = &sc->oba_irq_rman; + break; case SYS_RES_MEMORY: return (NULL); case SYS_RES_IOPORT: rm = &sc->oba_rman; bt = sc->oba_st; bh = sc->oba_addr; + start = bh; break; default: return (NULL); } - start = bh; rv = rman_reserve_resource(rm, start, end, count, flags, child); if (rv == NULL) return (NULL); + if (type == SYS_RES_IRQ) + return (rv); rman_set_bustag(rv, bt); rman_set_bushandle(rv, bh); diff --git a/sys/arm/xscale/i80321/obiovar.h b/sys/arm/xscale/i80321/obiovar.h index 8d8c5c577183..8e0c1459d708 100644 --- a/sys/arm/xscale/i80321/obiovar.h +++ b/sys/arm/xscale/i80321/obiovar.h @@ -41,7 +41,8 @@ #ifndef _IQ80321_OBIOVAR_H_ #define _IQ80321_OBIOVAR_H_ -#ifdef __RMAN_RESOURCE_VISIBLE +#include + struct obio_softc { bus_space_tag_t oba_st; /* bus space tag */ bus_addr_t oba_addr; /* address of device */ @@ -49,9 +50,9 @@ struct obio_softc { int oba_width; /* bus width */ int oba_irq; /* XINT interrupt bit # */ struct rman oba_rman; + struct rman oba_irq_rman; }; -#endif /* __RMAN_RESOURCE_VISIBLE */ extern struct bus_space obio_bs_tag; #endif /* _IQ80321_OBIOVAR_H_ */