diff options
author | attilio <attilio@FreeBSD.org> | 2013-02-06 11:49:43 +0000 |
---|---|---|
committer | attilio <attilio@FreeBSD.org> | 2013-02-06 11:49:43 +0000 |
commit | b38f2c588482cd27717fe15da339c1dd8829f502 (patch) | |
tree | 622ca590788634ec1ab9a1dabec8c09265f6b2b2 /sys | |
parent | d3b7ec3a087fe017933d12d65a35cae1d1a00914 (diff) | |
parent | 7280eb0924ffd1922c50d6f2fafbd523b47c9210 (diff) | |
download | FreeBSD-src-b38f2c588482cd27717fe15da339c1dd8829f502.zip FreeBSD-src-b38f2c588482cd27717fe15da339c1dd8829f502.tar.gz |
MFC
Diffstat (limited to 'sys')
36 files changed, 836 insertions, 219 deletions
diff --git a/sys/amd64/amd64/minidump_machdep.c b/sys/amd64/amd64/minidump_machdep.c index c1b03c1..79d8bde 100644 --- a/sys/amd64/amd64/minidump_machdep.c +++ b/sys/amd64/amd64/minidump_machdep.c @@ -232,7 +232,7 @@ minidumpsys(struct dumperinfo *di) /* Walk page table pages, set bits in vm_page_dump */ pmapsize = 0; pdp = (uint64_t *)PHYS_TO_DMAP(KPDPphys); - for (va = VM_MIN_KERNEL_ADDRESS; va < MAX(KERNBASE + NKPT * NBPDR, + for (va = VM_MIN_KERNEL_ADDRESS; va < MAX(KERNBASE + nkpt * NBPDR, kernel_vm_end); ) { /* * We always write a page, even if it is zero. Each @@ -364,7 +364,7 @@ minidumpsys(struct dumperinfo *di) /* Dump kernel page directory pages */ bzero(fakepd, sizeof(fakepd)); pdp = (uint64_t *)PHYS_TO_DMAP(KPDPphys); - for (va = VM_MIN_KERNEL_ADDRESS; va < MAX(KERNBASE + NKPT * NBPDR, + for (va = VM_MIN_KERNEL_ADDRESS; va < MAX(KERNBASE + nkpt * NBPDR, kernel_vm_end); va += NBPDP) { i = (va >> PDPSHIFT) & ((1ul << NPDPEPGSHIFT) - 1); diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c index 5436b6f..c63d8f2 100644 --- a/sys/amd64/amd64/pmap.c +++ b/sys/amd64/amd64/pmap.c @@ -202,6 +202,10 @@ struct pmap kernel_pmap_store; vm_offset_t virtual_avail; /* VA of first avail page (after kernel bss) */ vm_offset_t virtual_end; /* VA of last avail page (end of kernel AS) */ +int nkpt; +SYSCTL_INT(_machdep, OID_AUTO, nkpt, CTLFLAG_RD, &nkpt, 0, + "Number of kernel page table pages allocated on bootup"); + static int ndmpdp; static vm_paddr_t dmaplimit; vm_offset_t kernel_vm_end = VM_MIN_KERNEL_ADDRESS; @@ -496,17 +500,42 @@ allocpages(vm_paddr_t *firstaddr, int n) CTASSERT(powerof2(NDMPML4E)); +/* number of kernel PDP slots */ +#define NKPDPE(ptpgs) howmany((ptpgs), NPDEPG) + static void -create_pagetables(vm_paddr_t *firstaddr) +nkpt_init(vm_paddr_t addr) { - int i, j, ndm1g; + int pt_pages; + +#ifdef NKPT + pt_pages = NKPT; +#else + pt_pages = howmany(addr, 1 << PDRSHIFT); + pt_pages += NKPDPE(pt_pages); - /* Allocate pages */ - KPTphys = allocpages(firstaddr, NKPT); - KPML4phys = allocpages(firstaddr, 1); - KPDPphys = allocpages(firstaddr, NKPML4E); - KPDphys = allocpages(firstaddr, NKPDPE); + /* + * Add some slop beyond the bare minimum required for bootstrapping + * the kernel. + * + * This is quite important when allocating KVA for kernel modules. + * The modules are required to be linked in the negative 2GB of + * the address space. If we run out of KVA in this region then + * pmap_growkernel() will need to allocate page table pages to map + * the entire 512GB of KVA space which is an unnecessary tax on + * physical memory. + */ + pt_pages += 8; /* 16MB additional slop for kernel modules */ +#endif + nkpt = pt_pages; +} +static void +create_pagetables(vm_paddr_t *firstaddr) +{ + int i, j, ndm1g, nkpdpe; + + /* Allocate page table pages for the direct map */ ndmpdp = (ptoa(Maxmem) + NBPDP - 1) >> PDPSHIFT; if (ndmpdp < 4) /* Minimum 4GB of dirmap */ ndmpdp = 4; @@ -518,6 +547,22 @@ create_pagetables(vm_paddr_t *firstaddr) DMPDphys = allocpages(firstaddr, ndmpdp - ndm1g); dmaplimit = (vm_paddr_t)ndmpdp << PDPSHIFT; + /* Allocate pages */ + KPML4phys = allocpages(firstaddr, 1); + KPDPphys = allocpages(firstaddr, NKPML4E); + + /* + * Allocate the initial number of kernel page table pages required to + * bootstrap. We defer this until after all memory-size dependent + * allocations are done (e.g. direct map), so that we don't have to + * build in too much slop in our estimate. + */ + nkpt_init(*firstaddr); + nkpdpe = NKPDPE(nkpt); + + KPTphys = allocpages(firstaddr, nkpt); + KPDphys = allocpages(firstaddr, nkpdpe); + /* Fill in the underlying page table pages */ /* Read-only from zero to physfree */ /* XXX not fully used, underneath 2M pages */ @@ -527,7 +572,7 @@ create_pagetables(vm_paddr_t *firstaddr) } /* Now map the page tables at their location within PTmap */ - for (i = 0; i < NKPT; i++) { + for (i = 0; i < nkpt; i++) { ((pd_entry_t *)KPDphys)[i] = KPTphys + (i << PAGE_SHIFT); ((pd_entry_t *)KPDphys)[i] |= PG_RW | PG_V; } @@ -540,7 +585,7 @@ create_pagetables(vm_paddr_t *firstaddr) } /* And connect up the PD to the PDP */ - for (i = 0; i < NKPDPE; i++) { + for (i = 0; i < nkpdpe; i++) { ((pdp_entry_t *)KPDPphys)[i + KPDPI] = KPDphys + (i << PAGE_SHIFT); ((pdp_entry_t *)KPDPphys)[i + KPDPI] |= PG_RW | PG_V | PG_U; @@ -769,7 +814,7 @@ pmap_init(void) * Initialize the vm page array entries for the kernel pmap's * page table pages. */ - for (i = 0; i < NKPT; i++) { + for (i = 0; i < nkpt; i++) { mpte = PHYS_TO_VM_PAGE(KPTphys + (i << PAGE_SHIFT)); KASSERT(mpte >= vm_page_array && mpte < &vm_page_array[vm_page_array_size], @@ -2058,7 +2103,7 @@ pmap_growkernel(vm_offset_t addr) * any new kernel page table pages between "kernel_vm_end" and * "KERNBASE". */ - if (KERNBASE < addr && addr <= KERNBASE + NKPT * NBPDR) + if (KERNBASE < addr && addr <= KERNBASE + nkpt * NBPDR) return; addr = roundup2(addr, NBPDR); diff --git a/sys/amd64/include/pmap.h b/sys/amd64/include/pmap.h index 492354d..24fd2bc 100644 --- a/sys/amd64/include/pmap.h +++ b/sys/amd64/include/pmap.h @@ -113,13 +113,7 @@ ((unsigned long)(l2) << PDRSHIFT) | \ ((unsigned long)(l1) << PAGE_SHIFT)) -/* Initial number of kernel page tables. */ -#ifndef NKPT -#define NKPT 32 -#endif - #define NKPML4E 1 /* number of kernel PML4 slots */ -#define NKPDPE howmany(NKPT, NPDEPG)/* number of kernel PDP slots */ #define NUPML4E (NPML4EPG/2) /* number of userland PML4 pages */ #define NUPDPE (NUPML4E*NPDPEPG)/* number of userland PDP pages */ @@ -181,6 +175,7 @@ typedef u_int64_t pml4_entry_t; #define PML4map ((pd_entry_t *)(addr_PML4map)) #define PML4pml4e ((pd_entry_t *)(addr_PML4pml4e)) +extern int nkpt; /* Initial number of kernel page tables */ extern u_int64_t KPDPphys; /* physical address of kernel level 3 */ extern u_int64_t KPML4phys; /* physical address of kernel level 4 */ diff --git a/sys/arm/allwinner/a10_clk.c b/sys/arm/allwinner/a10_clk.c index 2d7699e..275ec4b 100644 --- a/sys/arm/allwinner/a10_clk.c +++ b/sys/arm/allwinner/a10_clk.c @@ -62,10 +62,10 @@ struct a10_ccm_softc { static struct a10_ccm_softc *a10_ccm_sc = NULL; -#define ccm_read_4(reg) \ - bus_space_read_4(a10_ccm_sc->bst, a10_ccm_sc->bsh, reg) -#define ccm_write_4(reg, val) \ - bus_space_write_4(a10_ccm_sc->bst, a10_ccm_sc->bsh, reg, val) +#define ccm_read_4(sc, reg) \ + bus_space_read_4((sc)->bst, (sc)->bsh, (reg)) +#define ccm_write_4(sc, reg, val) \ + bus_space_write_4((sc)->bst, (sc)->bsh, (reg), (val)) static int a10_ccm_probe(device_t dev) @@ -121,24 +121,24 @@ int a10_clk_usb_activate(void) { struct a10_ccm_softc *sc = a10_ccm_sc; - uint32_t reg_value = 0; + uint32_t reg_value; if (sc == NULL) return ENXIO; /* Gating AHB clock for USB */ - reg_value = ccm_read_4(CCM_AHB_GATING0); + reg_value = ccm_read_4(sc, CCM_AHB_GATING0); reg_value |= CCM_AHB_GATING_USB0; /* AHB clock gate usb0 */ reg_value |= CCM_AHB_GATING_EHCI1; /* AHB clock gate ehci1 */ - ccm_write_4(CCM_AHB_GATING0, reg_value); + ccm_write_4(sc, CCM_AHB_GATING0, reg_value); /* Enable clock for USB */ - reg_value = ccm_read_4(CCM_USB_CLK); + reg_value = ccm_read_4(sc, CCM_USB_CLK); reg_value |= CCM_USB_PHY; /* USBPHY */ reg_value |= CCM_USB0_RESET; /* disable reset for USB0 */ reg_value |= CCM_USB1_RESET; /* disable reset for USB1 */ reg_value |= CCM_USB2_RESET; /* disable reset for USB2 */ - ccm_write_4(CCM_USB_CLK, reg_value); + ccm_write_4(sc, CCM_USB_CLK, reg_value); return (0); } @@ -147,24 +147,24 @@ int a10_clk_usb_deactivate(void) { struct a10_ccm_softc *sc = a10_ccm_sc; - uint32_t reg_value = 0; + uint32_t reg_value; if (sc == NULL) return ENXIO; /* Disable clock for USB */ - reg_value = ccm_read_4(CCM_USB_CLK); + reg_value = ccm_read_4(sc, CCM_USB_CLK); reg_value &= ~CCM_USB_PHY; /* USBPHY */ reg_value &= ~CCM_USB0_RESET; /* reset for USB0 */ reg_value &= ~CCM_USB1_RESET; /* reset for USB1 */ reg_value &= ~CCM_USB2_RESET; /* reset for USB2 */ - ccm_write_4(CCM_USB_CLK, reg_value); + ccm_write_4(sc, CCM_USB_CLK, reg_value); /* Disable gating AHB clock for USB */ - reg_value = ccm_read_4(CCM_AHB_GATING0); + reg_value = ccm_read_4(sc, CCM_AHB_GATING0); reg_value &= ~CCM_AHB_GATING_USB0; /* disable AHB clock gate usb0 */ reg_value &= ~CCM_AHB_GATING_EHCI1; /* disable AHB clock gate ehci1 */ - ccm_write_4(CCM_AHB_GATING0, reg_value); + ccm_write_4(sc, CCM_AHB_GATING0, reg_value); return (0); } diff --git a/sys/arm/allwinner/a10_ehci.c b/sys/arm/allwinner/a10_ehci.c index d3a90d0..0d1636b 100644 --- a/sys/arm/allwinner/a10_ehci.c +++ b/sys/arm/allwinner/a10_ehci.c @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include <sys/condvar.h> #include <sys/kernel.h> #include <sys/module.h> +#include <sys/gpio.h> #include <machine/bus.h> #include <dev/ofw/ofw_bus.h> @@ -58,6 +59,8 @@ __FBSDID("$FreeBSD$"); #include <dev/usb/controller/ehci.h> #include <dev/usb/controller/ehcireg.h> +#include "gpio_if.h" + #include "a10_clk.h" #define EHCI_HC_DEVSTR "Allwinner Integrated USB 2.0 controller" @@ -70,8 +73,9 @@ __FBSDID("$FreeBSD$"); #define SW_ULPI_BYPASS (1 << 0) #define SW_AHB_INCRX_ALIGN (1 << 8) -#define SW_AHB_INCR4 (1 << 9) +#define SW_AHB_INCR4 (1 << 9) #define SW_AHB_INCR8 (1 << 10) +#define GPIO_USB2_PWR 227 #define A10_READ_4(sc, reg) \ bus_space_read_4((sc)->sc_io_tag, (sc)->sc_io_hdl, reg) @@ -101,6 +105,7 @@ a10_ehci_attach(device_t self) { ehci_softc_t *sc = device_get_softc(self); bus_space_handle_t bsh; + device_t sc_gpio_dev; int err; int rid; uint32_t reg_value = 0; @@ -153,6 +158,13 @@ a10_ehci_attach(device_t self) sprintf(sc->sc_vendor, "Allwinner"); + /* Get the GPIO device, we need this to give power to USB */ + sc_gpio_dev = devclass_get_device(devclass_find("gpio"), 0); + if (sc_gpio_dev == NULL) { + device_printf(self, "Error: failed to get the GPIO device\n"); + goto error; + } + err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE, NULL, (driver_intr_t *)ehci_interrupt, sc, &sc->sc_intr_hdl); if (err) { @@ -166,6 +178,10 @@ a10_ehci_attach(device_t self) /* Enable clock for USB */ a10_clk_usb_activate(); + /* Give power to USB */ + GPIO_PIN_SETFLAGS(sc_gpio_dev, GPIO_USB2_PWR, GPIO_PIN_OUTPUT); + GPIO_PIN_SET(sc_gpio_dev, GPIO_USB2_PWR, GPIO_PIN_HIGH); + /* Enable passby */ reg_value = A10_READ_4(sc, SW_USB_PMU_IRQ_ENABLE); reg_value |= SW_AHB_INCR8; /* AHB INCR8 enable */ diff --git a/sys/arm/allwinner/a10_gpio.c b/sys/arm/allwinner/a10_gpio.c new file mode 100644 index 0000000..b70d036 --- /dev/null +++ b/sys/arm/allwinner/a10_gpio.c @@ -0,0 +1,521 @@ +/*- + * Copyright (c) 2013 Ganbold Tsagaankhuu <ganbold@gmail.com> + * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org> + * Copyright (c) 2012 Luiz Otavio O Souza. + * 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 AUTHOR 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 AUTHOR 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. + * + */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/bus.h> + +#include <sys/kernel.h> +#include <sys/module.h> +#include <sys/rman.h> +#include <sys/lock.h> +#include <sys/mutex.h> +#include <sys/gpio.h> + +#include <machine/bus.h> +#include <machine/cpu.h> +#include <machine/cpufunc.h> +#include <machine/resource.h> +#include <machine/fdt.h> +#include <machine/frame.h> +#include <machine/intr.h> + +#include <dev/fdt/fdt_common.h> +#include <dev/ofw/ofw_bus.h> +#include <dev/ofw/ofw_bus_subr.h> + +#include "gpio_if.h" + +/* + * A10 have 9 banks of gpio. + * 32 pins per bank: + * PA0 - PA17 | PB0 - PB23 | PC0 - PC24 + * PD0 - PD27 | PE0 - PE31 | PF0 - PF5 + * PG0 - PG9 | PH0 - PH27 | PI0 - PI12 + */ + +#define A10_GPIO_PINS 288 +#define A10_GPIO_DEFAULT_CAPS (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT | \ + GPIO_PIN_PULLUP | GPIO_PIN_PULLDOWN) + +struct a10_gpio_softc { + device_t sc_dev; + struct mtx sc_mtx; + struct resource * sc_mem_res; + struct resource * sc_irq_res; + bus_space_tag_t sc_bst; + bus_space_handle_t sc_bsh; + void * sc_intrhand; + int sc_gpio_npins; + struct gpio_pin sc_gpio_pins[A10_GPIO_PINS]; +}; + +enum a10_gpio_fsel { + A10_GPIO_INPUT, + A10_GPIO_OUTPUT, +}; + +enum a10_gpio_pud { + A10_GPIO_NONE, + A10_GPIO_PULLDOWN, + A10_GPIO_PULLUP, +}; + +#define A10_GPIO_LOCK(_sc) mtx_lock(&_sc->sc_mtx) +#define A10_GPIO_UNLOCK(_sc) mtx_unlock(&_sc->sc_mtx) +#define A10_GPIO_LOCK_ASSERT(_sc) mtx_assert(&_sc->sc_mtx, MA_OWNED) + +#define A10_GPIO_GP_CFG(_bank, _pin) 0x00 + ((_bank) * 0x24) + ((_pin)<<2) +#define A10_GPIO_GP_DAT(_bank) 0x10 + ((_bank) * 0x24) +#define A10_GPIO_GP_DRV(_bank, _pin) 0x14 + ((_bank) * 0x24) + ((_pin)<<2) +#define A10_GPIO_GP_PUL(_bank, _pin) 0x1c + ((_bank) * 0x24) + ((_pin)<<2) + +#define A10_GPIO_GP_INT_CFG0 0x200 +#define A10_GPIO_GP_INT_CFG1 0x204 +#define A10_GPIO_GP_INT_CFG2 0x208 +#define A10_GPIO_GP_INT_CFG3 0x20c + +#define A10_GPIO_GP_INT_CTL 0x210 +#define A10_GPIO_GP_INT_STA 0x214 +#define A10_GPIO_GP_INT_DEB 0x218 + +#define A10_GPIO_WRITE(_sc, _off, _val) \ + bus_space_write_4(_sc->sc_bst, _sc->sc_bsh, _off, _val) +#define A10_GPIO_READ(_sc, _off) \ + bus_space_read_4(_sc->sc_bst, _sc->sc_bsh, _off) + +static uint32_t +a10_gpio_get_function(struct a10_gpio_softc *sc, uint32_t pin) +{ + uint32_t bank, func, offset; + + bank = pin / 32; + pin = pin - 32 * bank; + func = pin >> 3; + offset = ((pin & 0x07) << 2); + + A10_GPIO_LOCK(sc); + func = (A10_GPIO_READ(sc, A10_GPIO_GP_CFG(bank, func)) >> offset) & 7; + A10_GPIO_UNLOCK(sc); + + return (func); +} + +static uint32_t +a10_gpio_func_flag(uint32_t nfunc) +{ + + switch (nfunc) { + case A10_GPIO_INPUT: + return (GPIO_PIN_INPUT); + case A10_GPIO_OUTPUT: + return (GPIO_PIN_OUTPUT); + } + return (0); +} + +static void +a10_gpio_set_function(struct a10_gpio_softc *sc, uint32_t pin, uint32_t f) +{ + uint32_t bank, func, data, offset; + + /* Must be called with lock held. */ + A10_GPIO_LOCK_ASSERT(sc); + + bank = pin / 32; + pin = pin - 32 * bank; + func = pin >> 3; + offset = ((pin & 0x07) << 2); + + data = A10_GPIO_READ(sc, A10_GPIO_GP_CFG(bank, func)); + data &= ~(7 << offset); + data |= (f << offset); + A10_GPIO_WRITE(sc, A10_GPIO_GP_CFG(bank, func), data); +} + +static void +a10_gpio_set_pud(struct a10_gpio_softc *sc, uint32_t pin, uint32_t state) +{ + uint32_t bank, offset, pull, val; + + /* Must be called with lock held. */ + A10_GPIO_LOCK_ASSERT(sc); + + bank = pin / 32; + pin = pin - 32 * bank; + pull = pin >> 4; + offset = ((pin & 0x0f) << 1); + + val = A10_GPIO_READ(sc, A10_GPIO_GP_PUL(bank, pull)); + val &= ~(0x03 << offset); + val |= (state << offset); + A10_GPIO_WRITE(sc, A10_GPIO_GP_PUL(bank, pull), val); +} + +static void +a10_gpio_pin_configure(struct a10_gpio_softc *sc, struct gpio_pin *pin, + unsigned int flags) +{ + + A10_GPIO_LOCK(sc); + + /* + * Manage input/output. + */ + if (flags & (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT)) { + pin->gp_flags &= ~(GPIO_PIN_INPUT|GPIO_PIN_OUTPUT); + if (flags & GPIO_PIN_OUTPUT) { + pin->gp_flags |= GPIO_PIN_OUTPUT; + a10_gpio_set_function(sc, pin->gp_pin, + A10_GPIO_OUTPUT); + } else { + pin->gp_flags |= GPIO_PIN_INPUT; + a10_gpio_set_function(sc, pin->gp_pin, + A10_GPIO_INPUT); + } + } + + /* Manage Pull-up/pull-down. */ + pin->gp_flags &= ~(GPIO_PIN_PULLUP|GPIO_PIN_PULLDOWN); + if (flags & (GPIO_PIN_PULLUP|GPIO_PIN_PULLDOWN)) { + if (flags & GPIO_PIN_PULLUP) { + pin->gp_flags |= GPIO_PIN_PULLUP; + a10_gpio_set_pud(sc, pin->gp_pin, A10_GPIO_PULLUP); + } else { + pin->gp_flags |= GPIO_PIN_PULLDOWN; + a10_gpio_set_pud(sc, pin->gp_pin, A10_GPIO_PULLDOWN); + } + } else + a10_gpio_set_pud(sc, pin->gp_pin, A10_GPIO_NONE); + + A10_GPIO_UNLOCK(sc); +} + +static int +a10_gpio_pin_max(device_t dev, int *maxpin) +{ + + *maxpin = A10_GPIO_PINS - 1; + return (0); +} + +static int +a10_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps) +{ + struct a10_gpio_softc *sc = device_get_softc(dev); + int i; + + for (i = 0; i < sc->sc_gpio_npins; i++) { + if (sc->sc_gpio_pins[i].gp_pin == pin) + break; + } + + if (i >= sc->sc_gpio_npins) + return (EINVAL); + + A10_GPIO_LOCK(sc); + *caps = sc->sc_gpio_pins[i].gp_caps; + A10_GPIO_UNLOCK(sc); + + return (0); +} + +static int +a10_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags) +{ + struct a10_gpio_softc *sc = device_get_softc(dev); + int i; + + for (i = 0; i < sc->sc_gpio_npins; i++) { + if (sc->sc_gpio_pins[i].gp_pin == pin) + break; + } + + if (i >= sc->sc_gpio_npins) + return (EINVAL); + + A10_GPIO_LOCK(sc); + *flags = sc->sc_gpio_pins[i].gp_flags; + A10_GPIO_UNLOCK(sc); + + return (0); +} + +static int +a10_gpio_pin_getname(device_t dev, uint32_t pin, char *name) +{ + struct a10_gpio_softc *sc = device_get_softc(dev); + int i; + + for (i = 0; i < sc->sc_gpio_npins; i++) { + if (sc->sc_gpio_pins[i].gp_pin == pin) + break; + } + + if (i >= sc->sc_gpio_npins) + return (EINVAL); + + A10_GPIO_LOCK(sc); + memcpy(name, sc->sc_gpio_pins[i].gp_name, GPIOMAXNAME); + A10_GPIO_UNLOCK(sc); + + return (0); +} + +static int +a10_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags) +{ + struct a10_gpio_softc *sc = device_get_softc(dev); + int i; + + for (i = 0; i < sc->sc_gpio_npins; i++) { + if (sc->sc_gpio_pins[i].gp_pin == pin) + break; + } + + if (i >= sc->sc_gpio_npins) + return (EINVAL); + + /* Filter out unwanted flags. */ + if ((flags &= sc->sc_gpio_pins[i].gp_caps) != flags) + return (EINVAL); + + /* Can't mix input/output together. */ + if ((flags & (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT)) == + (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT)) + return (EINVAL); + + /* Can't mix pull-up/pull-down together. */ + if ((flags & (GPIO_PIN_PULLUP|GPIO_PIN_PULLDOWN)) == + (GPIO_PIN_PULLUP|GPIO_PIN_PULLDOWN)) + return (EINVAL); + + a10_gpio_pin_configure(sc, &sc->sc_gpio_pins[i], flags); + + return (0); +} + +static int +a10_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value) +{ + struct a10_gpio_softc *sc = device_get_softc(dev); + uint32_t bank, offset, data; + int i; + + for (i = 0; i < sc->sc_gpio_npins; i++) { + if (sc->sc_gpio_pins[i].gp_pin == pin) + break; + } + + if (i >= sc->sc_gpio_npins) + return (EINVAL); + + bank = pin / 32; + pin = pin - 32 * bank; + offset = pin & 0x1f; + + A10_GPIO_LOCK(sc); + data = A10_GPIO_READ(sc, A10_GPIO_GP_DAT(bank)); + if (value) + data |= (1 << offset); + else + data &= ~(1 << offset); + A10_GPIO_WRITE(sc, A10_GPIO_GP_DAT(bank), data); + A10_GPIO_UNLOCK(sc); + + return (0); +} + +static int +a10_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val) +{ + struct a10_gpio_softc *sc = device_get_softc(dev); + uint32_t bank, offset, reg_data; + int i; + + for (i = 0; i < sc->sc_gpio_npins; i++) { + if (sc->sc_gpio_pins[i].gp_pin == pin) + break; + } + + if (i >= sc->sc_gpio_npins) + return (EINVAL); + + bank = pin / 32; + pin = pin - 32 * bank; + offset = pin & 0x1f; + + A10_GPIO_LOCK(sc); + reg_data = A10_GPIO_READ(sc, A10_GPIO_GP_DAT(bank)); + A10_GPIO_UNLOCK(sc); + *val = (reg_data & (1 << offset)) ? 1 : 0; + + return (0); +} + +static int +a10_gpio_pin_toggle(device_t dev, uint32_t pin) +{ + struct a10_gpio_softc *sc = device_get_softc(dev); + uint32_t bank, data, offset; + int i; + + for (i = 0; i < sc->sc_gpio_npins; i++) { + if (sc->sc_gpio_pins[i].gp_pin == pin) + break; + } + + if (i >= sc->sc_gpio_npins) + return (EINVAL); + + bank = pin / 32; + pin = pin - 32 * bank; + offset = pin & 0x1f; + + A10_GPIO_LOCK(sc); + data = A10_GPIO_READ(sc, A10_GPIO_GP_DAT(bank)); + if (data & (1 << offset)) + data &= ~(1 << offset); + else + data |= (1 << offset); + A10_GPIO_WRITE(sc, A10_GPIO_GP_DAT(bank), data); + A10_GPIO_UNLOCK(sc); + + return (0); +} + +static int +a10_gpio_probe(device_t dev) +{ + if (!ofw_bus_is_compatible(dev, "allwinner,sun4i-gpio")) + return (ENXIO); + + device_set_desc(dev, "Allwinner GPIO controller"); + return (BUS_PROBE_DEFAULT); +} + +static int +a10_gpio_attach(device_t dev) +{ + struct a10_gpio_softc *sc = device_get_softc(dev); + uint32_t func; + int i, rid; + phandle_t gpio; + + sc->sc_dev = dev; + + mtx_init(&sc->sc_mtx, "a10 gpio", "gpio", MTX_DEF); + + rid = 0; + sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, + RF_ACTIVE); + if (!sc->sc_mem_res) { + device_printf(dev, "cannot allocate memory window\n"); + return (ENXIO); + } + + sc->sc_bst = rman_get_bustag(sc->sc_mem_res); + sc->sc_bsh = rman_get_bushandle(sc->sc_mem_res); + + rid = 0; + sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, + RF_ACTIVE); + if (!sc->sc_irq_res) { + bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); + device_printf(dev, "cannot allocate interrupt\n"); + return (ENXIO); + } + + /* Find our node. */ + gpio = ofw_bus_get_node(sc->sc_dev); + + if (!OF_hasprop(gpio, "gpio-controller")) + /* Node is not a GPIO controller. */ + goto fail; + + /* Initialize the software controlled pins. */ + for (i = 0; i < A10_GPIO_PINS; i++) { + snprintf(sc->sc_gpio_pins[i].gp_name, GPIOMAXNAME, + "pin %d", i); + func = a10_gpio_get_function(sc, i); + sc->sc_gpio_pins[i].gp_pin = i; + sc->sc_gpio_pins[i].gp_caps = A10_GPIO_DEFAULT_CAPS; + sc->sc_gpio_pins[i].gp_flags = a10_gpio_func_flag(func); + } + sc->sc_gpio_npins = i; + + device_add_child(dev, "gpioc", device_get_unit(dev)); + device_add_child(dev, "gpiobus", device_get_unit(dev)); + return (bus_generic_attach(dev)); + +fail: + if (sc->sc_irq_res) + bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res); + if (sc->sc_mem_res) + bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); + return (ENXIO); +} + +static int +a10_gpio_detach(device_t dev) +{ + + return (EBUSY); +} + +static device_method_t a10_gpio_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, a10_gpio_probe), + DEVMETHOD(device_attach, a10_gpio_attach), + DEVMETHOD(device_detach, a10_gpio_detach), + + /* GPIO protocol */ + DEVMETHOD(gpio_pin_max, a10_gpio_pin_max), + DEVMETHOD(gpio_pin_getname, a10_gpio_pin_getname), + DEVMETHOD(gpio_pin_getflags, a10_gpio_pin_getflags), + DEVMETHOD(gpio_pin_getcaps, a10_gpio_pin_getcaps), + DEVMETHOD(gpio_pin_setflags, a10_gpio_pin_setflags), + DEVMETHOD(gpio_pin_get, a10_gpio_pin_get), + DEVMETHOD(gpio_pin_set, a10_gpio_pin_set), + DEVMETHOD(gpio_pin_toggle, a10_gpio_pin_toggle), + + DEVMETHOD_END +}; + +static devclass_t a10_gpio_devclass; + +static driver_t a10_gpio_driver = { + "gpio", + a10_gpio_methods, + sizeof(struct a10_gpio_softc), +}; + +DRIVER_MODULE(a10_gpio, simplebus, a10_gpio_driver, a10_gpio_devclass, 0, 0); diff --git a/sys/arm/allwinner/files.a10 b/sys/arm/allwinner/files.a10 index 9d056fc..5cf2023 100644 --- a/sys/arm/allwinner/files.a10 +++ b/sys/arm/allwinner/files.a10 @@ -10,6 +10,7 @@ arm/arm/cpufunc_asm_armv7.S standard arm/arm/irq_dispatch.S standard arm/allwinner/a10_clk.c standard +arm/allwinner/a10_gpio.c optional gpio arm/allwinner/a10_ehci.c optional ehci arm/allwinner/timer.c standard arm/allwinner/aintc.c standard diff --git a/sys/arm/conf/CUBIEBOARD b/sys/arm/conf/CUBIEBOARD index 82f484b..fa5bfc8 100644 --- a/sys/arm/conf/CUBIEBOARD +++ b/sys/arm/conf/CUBIEBOARD @@ -99,7 +99,7 @@ device random # Entropy device #device iic # GPIO -#device gpio +device gpio device scbus # SCSI bus (required for SCSI) device da # Direct Access (disks) diff --git a/sys/boot/arm/uboot/Makefile b/sys/boot/arm/uboot/Makefile index c3c4bd8..1974218 100644 --- a/sys/boot/arm/uboot/Makefile +++ b/sys/boot/arm/uboot/Makefile @@ -112,8 +112,8 @@ CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ # clang doesn't understand %D as a specifier to printf NO_WERROR.clang= -DPADD= ${LIBFICL} ${LIBUBOOT} ${LIBFDT} ${LIBSTAND} ${LIBGCC} -LDADD= ${LIBFICL} ${LIBUBOOT} ${LIBFDT} -lstand -lgcc +DPADD= ${LIBFICL} ${LIBUBOOT} ${LIBFDT} ${LIBSTAND} +LDADD= ${LIBFICL} ${LIBUBOOT} ${LIBFDT} -lstand vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT} diff --git a/sys/boot/fdt/dts/cubieboard.dts b/sys/boot/fdt/dts/cubieboard.dts index c4dd2a8..2d90720 100644 --- a/sys/boot/fdt/dts/cubieboard.dts +++ b/sys/boot/fdt/dts/cubieboard.dts @@ -76,6 +76,15 @@ clock-frequency = < 24000000 >; }; + GPIO: gpio@01c20800 { + #gpio-cells = <3>; + compatible = "allwinner,sun4i-gpio"; + gpio-controller; + reg =< 0x01c20800 0x400 >; + interrupts = < 28 >; + interrupt-parent = <&AINTC>; + }; + usb1: usb@01c1c000 { compatible = "allwinner,usb-ehci", "usb-ehci"; reg = <0x01c1c000 0x1000>; diff --git a/sys/boot/usb/Makefile b/sys/boot/usb/Makefile index b71b10d..3ed12c8 100644 --- a/sys/boot/usb/Makefile +++ b/sys/boot/usb/Makefile @@ -42,13 +42,13 @@ OBJCOPY?= objcopy SYSCC?= cc CFLAGS+= -DBOOTPROG=\"usbloader\" -CFLAGS+= -DUSB_GLOBAL_INCLUDE_FILE="\"bsd_global.h\"" +CFLAGS+= -DUSB_GLOBAL_INCLUDE_FILE=\"bsd_global.h\" CFLAGS+= -ffunction-sections -fdata-sections CFLAGS+= -ffreestanding CFLAGS+= -Wformat -Wall -CFLAGS+= -I ${S} -CFLAGS+= -I ${T} -CFLAGS+= -I ${.CURDIR} +CFLAGS+= -I${S} +CFLAGS+= -I${T} +CFLAGS+= -I${.CURDIR} CFLAGS+= -g .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" diff --git a/sys/boot/usb/bsd_global.h b/sys/boot/usb/bsd_global.h index 9fe1c8c..80cbd63 100644 --- a/sys/boot/usb/bsd_global.h +++ b/sys/boot/usb/bsd_global.h @@ -60,4 +60,6 @@ #include <dev/usb/quirk/usb_quirk.h> #include <dev/usb/template/usb_template.h> +extern struct usb_process usb_process[USB_PROC_MAX]; + #endif /* _BSD_GLOBAL_H_ */ diff --git a/sys/boot/usb/bsd_kernel.c b/sys/boot/usb/bsd_kernel.c index 5f24c2d..d3daa63 100644 --- a/sys/boot/usb/bsd_kernel.c +++ b/sys/boot/usb/bsd_kernel.c @@ -26,7 +26,8 @@ #include <bsd_global.h> -static struct usb_process usb_process[USB_PROC_MAX]; +struct usb_process usb_process[USB_PROC_MAX]; + static device_t usb_pci_root; /*------------------------------------------------------------------------* @@ -977,41 +978,6 @@ repeat: return (worked); } -int -usb_proc_create(struct usb_process *up, struct mtx *p_mtx, - const char *pmesg, uint8_t prio) -{ -#define USB_PROC_OFFSET(a,b) \ - ((int)(((long)&((struct usb_bus *)0)->a) - \ - ((long)&((struct usb_bus *)0)->b))) - - /* figure out which process we are creating */ - switch ((int)((long)up - (long)p_mtx)) { - case USB_PROC_OFFSET(giant_callback_proc, bus_mtx): - up->up_ptr = (void *)(usb_process + 2); - break; - case USB_PROC_OFFSET(non_giant_callback_proc, bus_mtx): - up->up_ptr = (void *)(usb_process + 2); - break; - case USB_PROC_OFFSET(explore_proc, bus_mtx): - up->up_ptr = (void *)(usb_process + 0); - break; - case USB_PROC_OFFSET(control_xfer_proc, bus_mtx): - up->up_ptr = (void *)(usb_process + 1); - break; - default: - up->up_ptr = (void *)(usb_process + 1); - break; - } - return (0); /* success */ -} - -void -usb_proc_free(struct usb_process *up) -{ - /* NOP */ -} - void * usb_proc_msignal(struct usb_process *up, void *_pm0, void *_pm1) { @@ -1021,10 +987,6 @@ usb_proc_msignal(struct usb_process *up, void *_pm0, void *_pm1) usb_size_t d; uint8_t t; - /* find the correct parent */ - while (up->up_ptr != NULL) - up = (struct usb_process *)up->up_ptr; - t = 0; if (pm0->pm_qentry.tqe_prev) { @@ -1104,10 +1066,6 @@ usb_proc_mwait(struct usb_process *up, void *_pm0, void *_pm1) struct usb_proc_msg *pm0 = _pm0; struct usb_proc_msg *pm1 = _pm1; - /* find the correct parent */ - while (up->up_ptr != NULL) - up = (struct usb_process *)up->up_ptr; - /* Just remove the messages from the queue. */ if (pm0->pm_qentry.tqe_prev) { TAILQ_REMOVE(&up->up_qhead, pm0, pm_qentry); diff --git a/sys/boot/usb/bsd_kernel.h b/sys/boot/usb/bsd_kernel.h index 4c94721..e9d9602 100644 --- a/sys/boot/usb/bsd_kernel.h +++ b/sys/boot/usb/bsd_kernel.h @@ -40,6 +40,10 @@ #define M_USB 0 #define M_USBDEV 0 #define USB_PROC_MAX 3 +#define USB_BUS_GIANT_PROC(bus) (usb_process + 2) +#define USB_BUS_NON_GIANT_PROC(bus) (usb_process + 2) +#define USB_BUS_EXPLORE_PROC(bus) (usb_process + 0) +#define USB_BUS_CONTROL_XFER_PROC(bus) (usb_process + 1) #define SYSCTL_DECL(...) #define SYSCTL_NODE(name,...) struct { } name __used #define SYSCTL_INT(...) diff --git a/sys/dev/age/if_age.c b/sys/dev/age/if_age.c index 829f350..7fab237 100644 --- a/sys/dev/age/if_age.c +++ b/sys/dev/age/if_age.c @@ -142,6 +142,9 @@ static int age_init_rx_ring(struct age_softc *); static void age_init_rr_ring(struct age_softc *); static void age_init_cmb_block(struct age_softc *); static void age_init_smb_block(struct age_softc *); +#ifndef __NO_STRICT_ALIGNMENT +static struct mbuf *age_fixup_rx(struct ifnet *, struct mbuf *); +#endif static int age_newbuf(struct age_softc *, struct age_rxdesc *); static void age_rxvlan(struct age_softc *); static void age_rxfilter(struct age_softc *); @@ -1133,7 +1136,7 @@ again: /* Create tag for Rx buffers. */ error = bus_dma_tag_create( sc->age_cdata.age_buffer_tag, /* parent */ - 1, 0, /* alignment, boundary */ + AGE_RX_BUF_ALIGN, 0, /* alignment, boundary */ BUS_SPACE_MAXADDR, /* lowaddr */ BUS_SPACE_MAXADDR, /* highaddr */ NULL, NULL, /* filter, filterarg */ @@ -2268,16 +2271,53 @@ age_txintr(struct age_softc *sc, int tpd_cons) } } +#ifndef __NO_STRICT_ALIGNMENT +static struct mbuf * +age_fixup_rx(struct ifnet *ifp, struct mbuf *m) +{ + struct mbuf *n; + int i; + uint16_t *src, *dst; + + src = mtod(m, uint16_t *); + dst = src - 3; + + if (m->m_next == NULL) { + for (i = 0; i < (m->m_len / sizeof(uint16_t) + 1); i++) + *dst++ = *src++; + m->m_data -= 6; + return (m); + } + /* + * Append a new mbuf to received mbuf chain and copy ethernet + * header from the mbuf chain. This can save lots of CPU + * cycles for jumbo frame. + */ + MGETHDR(n, M_NOWAIT, MT_DATA); + if (n == NULL) { + ifp->if_iqdrops++; + m_freem(m); + return (NULL); + } + bcopy(m->m_data, n->m_data, ETHER_HDR_LEN); + m->m_data += ETHER_HDR_LEN; + m->m_len -= ETHER_HDR_LEN; + n->m_len = ETHER_HDR_LEN; + M_MOVE_PKTHDR(n, m); + n->m_next = m; + return (n); +} +#endif + /* Receive a frame. */ static void age_rxeof(struct age_softc *sc, struct rx_rdesc *rxrd) { struct age_rxdesc *rxd; - struct rx_desc *desc; struct ifnet *ifp; struct mbuf *mp, *m; uint32_t status, index, vtag; - int count, nsegs, pktlen; + int count, nsegs; int rx_cons; AGE_LOCK_ASSERT(sc); @@ -2289,9 +2329,7 @@ age_rxeof(struct age_softc *sc, struct rx_rdesc *rxrd) nsegs = AGE_RX_NSEGS(index); sc->age_cdata.age_rxlen = AGE_RX_BYTES(le32toh(rxrd->len)); - if ((status & AGE_RRD_ERROR) != 0 && - (status & (AGE_RRD_CRC | AGE_RRD_CODE | AGE_RRD_DRIBBLE | - AGE_RRD_RUNT | AGE_RRD_OFLOW | AGE_RRD_TRUNC)) != 0) { + if ((status & (AGE_RRD_ERROR | AGE_RRD_LENGTH_NOK)) != 0) { /* * We want to pass the following frames to upper * layer regardless of error status of Rx return @@ -2301,33 +2339,31 @@ age_rxeof(struct age_softc *sc, struct rx_rdesc *rxrd) * o frame length and protocol specific length * does not match. */ - sc->age_cdata.age_rx_cons += nsegs; - sc->age_cdata.age_rx_cons %= AGE_RX_RING_CNT; - return; + status |= AGE_RRD_IPCSUM_NOK | AGE_RRD_TCP_UDPCSUM_NOK; + if ((status & (AGE_RRD_CRC | AGE_RRD_CODE | AGE_RRD_DRIBBLE | + AGE_RRD_RUNT | AGE_RRD_OFLOW | AGE_RRD_TRUNC)) != 0) + return; } - pktlen = 0; for (count = 0; count < nsegs; count++, AGE_DESC_INC(rx_cons, AGE_RX_RING_CNT)) { rxd = &sc->age_cdata.age_rxdesc[rx_cons]; mp = rxd->rx_m; - desc = rxd->rx_desc; /* Add a new receive buffer to the ring. */ if (age_newbuf(sc, rxd) != 0) { ifp->if_iqdrops++; /* Reuse Rx buffers. */ - if (sc->age_cdata.age_rxhead != NULL) { + if (sc->age_cdata.age_rxhead != NULL) m_freem(sc->age_cdata.age_rxhead); - AGE_RXCHAIN_RESET(sc); - } break; } - /* The length of the first mbuf is computed last. */ - if (count != 0) { - mp->m_len = AGE_RX_BYTES(le32toh(desc->len)); - pktlen += mp->m_len; - } + /* + * Assume we've received a full sized frame. + * Actual size is fixed when we encounter the end of + * multi-segmented frame. + */ + mp->m_len = AGE_RX_BUF_SIZE; /* Chain received mbufs. */ if (sc->age_cdata.age_rxhead == NULL) { @@ -2342,14 +2378,20 @@ age_rxeof(struct age_softc *sc, struct rx_rdesc *rxrd) } if (count == nsegs - 1) { + /* Last desc. for this frame. */ + m = sc->age_cdata.age_rxhead; + m->m_flags |= M_PKTHDR; /* * It seems that L1 controller has no way * to tell hardware to strip CRC bytes. */ - sc->age_cdata.age_rxlen -= ETHER_CRC_LEN; + m->m_pkthdr.len = sc->age_cdata.age_rxlen - + ETHER_CRC_LEN; if (nsegs > 1) { + /* Set last mbuf size. */ + mp->m_len = sc->age_cdata.age_rxlen - + ((nsegs - 1) * AGE_RX_BUF_SIZE); /* Remove the CRC bytes in chained mbufs. */ - pktlen -= ETHER_CRC_LEN; if (mp->m_len <= ETHER_CRC_LEN) { sc->age_cdata.age_rxtail = sc->age_cdata.age_rxprev_tail; @@ -2360,15 +2402,9 @@ age_rxeof(struct age_softc *sc, struct rx_rdesc *rxrd) } else { mp->m_len -= ETHER_CRC_LEN; } - } - - m = sc->age_cdata.age_rxhead; - m->m_flags |= M_PKTHDR; + } else + m->m_len = m->m_pkthdr.len; m->m_pkthdr.rcvif = ifp; - m->m_pkthdr.len = sc->age_cdata.age_rxlen; - /* Set the first mbuf length. */ - m->m_len = sc->age_cdata.age_rxlen - pktlen; - /* * Set checksum information. * It seems that L1 controller can compute partial @@ -2383,9 +2419,9 @@ age_rxeof(struct age_softc *sc, struct rx_rdesc *rxrd) */ if ((ifp->if_capenable & IFCAP_RXCSUM) != 0 && (status & AGE_RRD_IPV4) != 0) { - m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED; if ((status & AGE_RRD_IPCSUM_NOK) == 0) - m->m_pkthdr.csum_flags |= CSUM_IP_VALID; + m->m_pkthdr.csum_flags |= + CSUM_IP_CHECKED | CSUM_IP_VALID; if ((status & (AGE_RRD_TCP | AGE_RRD_UDP)) && (status & AGE_RRD_TCP_UDPCSUM_NOK) == 0) { m->m_pkthdr.csum_flags |= @@ -2406,22 +2442,21 @@ age_rxeof(struct age_softc *sc, struct rx_rdesc *rxrd) m->m_pkthdr.ether_vtag = AGE_RX_VLAN_TAG(vtag); m->m_flags |= M_VLANTAG; } - +#ifndef __NO_STRICT_ALIGNMENT + m = age_fixup_rx(ifp, m); + if (m != NULL) +#endif + { /* Pass it on. */ AGE_UNLOCK(sc); (*ifp->if_input)(ifp, m); AGE_LOCK(sc); - - /* Reset mbuf chains. */ - AGE_RXCHAIN_RESET(sc); + } } } - if (count != nsegs) { - sc->age_cdata.age_rx_cons += nsegs; - sc->age_cdata.age_rx_cons %= AGE_RX_RING_CNT; - } else - sc->age_cdata.age_rx_cons = rx_cons; + /* Reset mbuf chains. */ + AGE_RXCHAIN_RESET(sc); } static int @@ -2456,16 +2491,16 @@ age_rxintr(struct age_softc *sc, int rr_prod, int count) * I'm not sure whether this check is really needed. */ pktlen = AGE_RX_BYTES(le32toh(rxrd->len)); - if (nsegs != ((pktlen + (MCLBYTES - ETHER_ALIGN - 1)) / - (MCLBYTES - ETHER_ALIGN))) + if (nsegs != (pktlen + (AGE_RX_BUF_SIZE - 1)) / AGE_RX_BUF_SIZE) break; - prog++; /* Received a frame. */ age_rxeof(sc, rxrd); /* Clear return ring. */ rxrd->index = 0; AGE_DESC_INC(rr_cons, AGE_RR_RING_CNT); + sc->age_cdata.age_rx_cons += nsegs; + sc->age_cdata.age_rx_cons %= AGE_RX_RING_CNT; } if (prog > 0) { @@ -3065,7 +3100,9 @@ age_newbuf(struct age_softc *sc, struct age_rxdesc *rxd) if (m == NULL) return (ENOBUFS); m->m_len = m->m_pkthdr.len = MCLBYTES; - m_adj(m, ETHER_ALIGN); +#ifndef __NO_STRICT_ALIGNMENT + m_adj(m, AGE_RX_BUF_ALIGN); +#endif if (bus_dmamap_load_mbuf_sg(sc->age_cdata.age_rx_tag, sc->age_cdata.age_rx_sparemap, m, segs, &nsegs, 0) != 0) { diff --git a/sys/dev/age/if_agevar.h b/sys/dev/age/if_agevar.h index db98eb1..6ee5423 100644 --- a/sys/dev/age/if_agevar.h +++ b/sys/dev/age/if_agevar.h @@ -43,6 +43,12 @@ #define AGE_TSO_MAXSEGSIZE 4096 #define AGE_TSO_MAXSIZE (65535 + sizeof(struct ether_vlan_header)) #define AGE_MAXTXSEGS 32 +#define AGE_RX_BUF_ALIGN 8 +#ifndef __NO_STRICT_ALIGNMENT +#define AGE_RX_BUF_SIZE (MCLBYTES - AGE_RX_BUF_ALIGN) +#else +#define AGE_RX_BUF_SIZE (MCLBYTES) +#endif #define AGE_ADDR_LO(x) ((uint64_t) (x) & 0xFFFFFFFF) #define AGE_ADDR_HI(x) ((uint64_t) (x) >> 32) diff --git a/sys/dev/cxgbe/common/t4_hw.c b/sys/dev/cxgbe/common/t4_hw.c index 902a4e8..099f5a9 100644 --- a/sys/dev/cxgbe/common/t4_hw.c +++ b/sys/dev/cxgbe/common/t4_hw.c @@ -35,7 +35,12 @@ __FBSDID("$FreeBSD$"); #include "firmware/t4fw_interface.h" #undef msleep -#define msleep(x) pause("t4hw", (x) * hz / 1000) +#define msleep(x) do { \ + if (cold) \ + DELAY((x) * 1000); \ + else \ + pause("t4hw", (x) * hz / 1000); \ +} while (0) /** * t4_wait_op_done_val - wait until an operation is completed diff --git a/sys/dev/syscons/syscons.c b/sys/dev/syscons/syscons.c index beb0c67..8094ea3 100644 --- a/sys/dev/syscons/syscons.c +++ b/sys/dev/syscons/syscons.c @@ -253,11 +253,13 @@ static struct ttydevsw sc_ttydevsw = { }; static d_ioctl_t consolectl_ioctl; +static d_close_t consolectl_close; static struct cdevsw consolectl_devsw = { .d_version = D_VERSION, - .d_flags = D_NEEDGIANT, + .d_flags = D_NEEDGIANT | D_TRACKCLOSE, .d_ioctl = consolectl_ioctl, + .d_close = consolectl_close, .d_name = "consolectl", }; @@ -1561,6 +1563,23 @@ consolectl_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, return sctty_ioctl(dev->si_drv1, cmd, data, td); } +static int +consolectl_close(struct cdev *dev, int flags, int mode, struct thread *td) +{ +#ifndef SC_NO_SYSMOUSE + mouse_info_t info; + memset(&info, 0, sizeof(info)); + info.operation = MOUSE_ACTION; + + /* + * Make sure all buttons are released when moused and other + * console daemons exit, so that no buttons are left pressed. + */ + (void) sctty_ioctl(dev->si_drv1, CONS_MOUSECTL, (caddr_t)&info, td); +#endif + return (0); +} + static void sc_cnprobe(struct consdev *cp) { diff --git a/sys/dev/usb/controller/usb_controller.c b/sys/dev/usb/controller/usb_controller.c index 204569f..cf2ae7a 100644 --- a/sys/dev/usb/controller/usb_controller.c +++ b/sys/dev/usb/controller/usb_controller.c @@ -214,27 +214,29 @@ usb_detach(device_t dev) USB_BUS_LOCK(bus); /* Queue detach job */ - usb_proc_msignal(&bus->explore_proc, + usb_proc_msignal(USB_BUS_EXPLORE_PROC(bus), &bus->detach_msg[0], &bus->detach_msg[1]); /* Wait for detach to complete */ - usb_proc_mwait(&bus->explore_proc, + usb_proc_mwait(USB_BUS_EXPLORE_PROC(bus), &bus->detach_msg[0], &bus->detach_msg[1]); USB_BUS_UNLOCK(bus); +#if USB_HAVE_PER_BUS_PROCESS /* Get rid of USB callback processes */ - usb_proc_free(&bus->giant_callback_proc); - usb_proc_free(&bus->non_giant_callback_proc); + usb_proc_free(USB_BUS_GIANT_PROC(bus)); + usb_proc_free(USB_BUS_NON_GIANT_PROC(bus)); /* Get rid of USB explore process */ - usb_proc_free(&bus->explore_proc); + usb_proc_free(USB_BUS_EXPLORE_PROC(bus)); /* Get rid of control transfer process */ - usb_proc_free(&bus->control_xfer_proc); + usb_proc_free(USB_BUS_CONTROL_XFER_PROC(bus)); +#endif #if USB_HAVE_PF usbpf_detach(bus); @@ -258,11 +260,11 @@ usb_suspend(device_t dev) } USB_BUS_LOCK(bus); - usb_proc_msignal(&bus->explore_proc, + usb_proc_msignal(USB_BUS_EXPLORE_PROC(bus), &bus->suspend_msg[0], &bus->suspend_msg[1]); if (usb_no_suspend_wait == 0) { /* wait for suspend callback to be executed */ - usb_proc_mwait(&bus->explore_proc, + usb_proc_mwait(USB_BUS_EXPLORE_PROC(bus), &bus->suspend_msg[0], &bus->suspend_msg[1]); } USB_BUS_UNLOCK(bus); @@ -286,7 +288,7 @@ usb_resume(device_t dev) } USB_BUS_LOCK(bus); - usb_proc_msignal(&bus->explore_proc, + usb_proc_msignal(USB_BUS_EXPLORE_PROC(bus), &bus->resume_msg[0], &bus->resume_msg[1]); USB_BUS_UNLOCK(bus); @@ -311,11 +313,11 @@ usb_shutdown(device_t dev) device_printf(bus->bdev, "Controller shutdown\n"); USB_BUS_LOCK(bus); - usb_proc_msignal(&bus->explore_proc, + usb_proc_msignal(USB_BUS_EXPLORE_PROC(bus), &bus->shutdown_msg[0], &bus->shutdown_msg[1]); if (usb_no_shutdown_wait == 0) { /* wait for shutdown callback to be executed */ - usb_proc_mwait(&bus->explore_proc, + usb_proc_mwait(USB_BUS_EXPLORE_PROC(bus), &bus->shutdown_msg[0], &bus->shutdown_msg[1]); } USB_BUS_UNLOCK(bus); @@ -358,9 +360,9 @@ usb_bus_explore(struct usb_proc_msg *pm) * The following three lines of code are only here to * recover from DDB: */ - usb_proc_rewakeup(&bus->control_xfer_proc); - usb_proc_rewakeup(&bus->giant_callback_proc); - usb_proc_rewakeup(&bus->non_giant_callback_proc); + usb_proc_rewakeup(USB_BUS_CONTROL_XFER_PROC(bus)); + usb_proc_rewakeup(USB_BUS_GIANT_PROC(bus)); + usb_proc_rewakeup(USB_BUS_NON_GIANT_PROC(bus)); #endif USB_BUS_UNLOCK(bus); @@ -585,7 +587,7 @@ usb_power_wdog(void *arg) * The following line of code is only here to recover from * DDB: */ - usb_proc_rewakeup(&bus->explore_proc); /* recover from DDB */ + usb_proc_rewakeup(USB_BUS_EXPLORE_PROC(bus)); /* recover from DDB */ #endif #if USB_HAVE_POWERD @@ -708,8 +710,6 @@ usb_bus_attach(struct usb_proc_msg *pm) static void usb_attach_sub(device_t dev, struct usb_bus *bus) { - const char *pname = device_get_nameunit(dev); - mtx_lock(&Giant); if (usb_devclass_ptr == NULL) usb_devclass_ptr = devclass_find("usbus"); @@ -749,28 +749,31 @@ usb_attach_sub(device_t dev, struct usb_bus *bus) bus->shutdown_msg[1].hdr.pm_callback = &usb_bus_shutdown; bus->shutdown_msg[1].bus = bus; +#if USB_HAVE_PER_BUS_PROCESS /* Create USB explore and callback processes */ - if (usb_proc_create(&bus->giant_callback_proc, - &bus->bus_mtx, pname, USB_PRI_MED)) { + if (usb_proc_create(USB_BUS_GIANT_PROC(bus), + &bus->bus_mtx, device_get_nameunit(dev), USB_PRI_MED)) { device_printf(dev, "WARNING: Creation of USB Giant " "callback process failed.\n"); - } else if (usb_proc_create(&bus->non_giant_callback_proc, - &bus->bus_mtx, pname, USB_PRI_HIGH)) { + } else if (usb_proc_create(USB_BUS_NON_GIANT_PROC(bus), + &bus->bus_mtx, device_get_nameunit(dev), USB_PRI_HIGH)) { device_printf(dev, "WARNING: Creation of USB non-Giant " "callback process failed.\n"); - } else if (usb_proc_create(&bus->explore_proc, - &bus->bus_mtx, pname, USB_PRI_MED)) { + } else if (usb_proc_create(USB_BUS_EXPLORE_PROC(bus), + &bus->bus_mtx, device_get_nameunit(dev), USB_PRI_MED)) { device_printf(dev, "WARNING: Creation of USB explore " "process failed.\n"); - } else if (usb_proc_create(&bus->control_xfer_proc, - &bus->bus_mtx, pname, USB_PRI_MED)) { + } else if (usb_proc_create(USB_BUS_CONTROL_XFER_PROC(bus), + &bus->bus_mtx, device_get_nameunit(dev), USB_PRI_MED)) { device_printf(dev, "WARNING: Creation of USB control transfer " "process failed.\n"); - } else { + } else +#endif + { /* Get final attach going */ USB_BUS_LOCK(bus); - usb_proc_msignal(&bus->explore_proc, + usb_proc_msignal(USB_BUS_EXPLORE_PROC(bus), &bus->attach_msg[0], &bus->attach_msg[1]); USB_BUS_UNLOCK(bus); @@ -778,7 +781,6 @@ usb_attach_sub(device_t dev, struct usb_bus *bus) usb_needs_explore(bus, 1); } } - SYSUNINIT(usb_bus_unload, SI_SUB_KLD, SI_ORDER_ANY, usb_bus_unload, NULL); /*------------------------------------------------------------------------* diff --git a/sys/dev/usb/controller/xhci.c b/sys/dev/usb/controller/xhci.c index 4023ecc..9f84b39 100644 --- a/sys/dev/usb/controller/xhci.c +++ b/sys/dev/usb/controller/xhci.c @@ -547,19 +547,12 @@ xhci_init(struct xhci_softc *sc, device_t self) sc->sc_config_msg[1].hdr.pm_callback = &xhci_configure_msg; sc->sc_config_msg[1].bus = &sc->sc_bus; - if (usb_proc_create(&sc->sc_config_proc, - &sc->sc_bus.bus_mtx, device_get_nameunit(self), USB_PRI_MED)) { - printf("WARNING: Creation of XHCI configure " - "callback process failed.\n"); - } return (0); } void xhci_uninit(struct xhci_softc *sc) { - usb_proc_free(&sc->sc_config_proc); - usb_bus_mem_free_all(&sc->sc_bus, &xhci_iterate_hw_softc); cv_destroy(&sc->sc_cmd_cv); @@ -2684,7 +2677,7 @@ xhci_transfer_insert(struct usb_xfer *xfer) DPRINTFN(8, "Not running\n"); /* start configuration */ - (void)usb_proc_msignal(&sc->sc_config_proc, + (void)usb_proc_msignal(USB_BUS_CONTROL_XFER_PROC(&sc->sc_bus), &sc->sc_config_msg[0], &sc->sc_config_msg[1]); return (0); } @@ -3652,7 +3645,7 @@ xhci_start_dma_delay(struct usb_xfer *xfer) /* put transfer on interrupt queue (again) */ usbd_transfer_enqueue(&sc->sc_bus.intr_q, xfer); - (void)usb_proc_msignal(&sc->sc_config_proc, + (void)usb_proc_msignal(USB_BUS_CONTROL_XFER_PROC(&sc->sc_bus), &sc->sc_config_msg[0], &sc->sc_config_msg[1]); } diff --git a/sys/dev/usb/controller/xhci.h b/sys/dev/usb/controller/xhci.h index 01e60ee..2a08ba7 100644 --- a/sys/dev/usb/controller/xhci.h +++ b/sys/dev/usb/controller/xhci.h @@ -434,8 +434,7 @@ struct xhci_softc { struct xhci_hw_softc sc_hw; /* base device */ struct usb_bus sc_bus; - /* configure process */ - struct usb_process sc_config_proc; + /* configure message */ struct usb_bus_msg sc_config_msg[2]; union xhci_hub_desc sc_hub_desc; diff --git a/sys/dev/usb/usb_bus.h b/sys/dev/usb/usb_bus.h index 07207cf..dea15f8 100644 --- a/sys/dev/usb/usb_bus.h +++ b/sys/dev/usb/usb_bus.h @@ -51,7 +51,16 @@ struct usb_bus_stat { struct usb_bus { struct usb_bus_stat stats_err; struct usb_bus_stat stats_ok; +#if USB_HAVE_ROOT_MOUNT_HOLD struct root_hold_token *bus_roothold; +#endif + +#if USB_HAVE_PER_BUS_PROCESS +#define USB_BUS_GIANT_PROC(bus) (&(bus)->giant_callback_proc) +#define USB_BUS_NON_GIANT_PROC(bus) (&(bus)->non_giant_callback_proc) +#define USB_BUS_EXPLORE_PROC(bus) (&(bus)->explore_proc) +#define USB_BUS_CONTROL_XFER_PROC(bus) (&(bus)->control_xfer_proc) + /* * There are two callback processes. One for Giant locked * callbacks. One for non-Giant locked callbacks. This should @@ -65,6 +74,7 @@ struct usb_bus { /* Control request process */ struct usb_process control_xfer_proc; +#endif struct usb_bus_msg explore_msg[2]; struct usb_bus_msg detach_msg[2]; diff --git a/sys/dev/usb/usb_device.c b/sys/dev/usb/usb_device.c index 8d88bf5..a9aab53 100644 --- a/sys/dev/usb/usb_device.c +++ b/sys/dev/usb/usb_device.c @@ -2128,7 +2128,7 @@ usb_free_device(struct usb_device *udev, uint8_t flag) * anywhere: */ USB_BUS_LOCK(udev->bus); - usb_proc_mwait(&udev->bus->non_giant_callback_proc, + usb_proc_mwait(USB_BUS_NON_GIANT_PROC(udev->bus), &udev->cs_msg[0], &udev->cs_msg[1]); USB_BUS_UNLOCK(udev->bus); diff --git a/sys/dev/usb/usb_dynamic.c b/sys/dev/usb/usb_dynamic.c index f8bb03f..58deb4e 100644 --- a/sys/dev/usb/usb_dynamic.c +++ b/sys/dev/usb/usb_dynamic.c @@ -68,7 +68,7 @@ usb_temp_setup_by_index_t *usb_temp_setup_by_index_p = &usb_temp_setup_by_index_ usb_temp_unsetup_t *usb_temp_unsetup_p = &usb_temp_unsetup_w; usb_test_quirk_t *usb_test_quirk_p = &usb_test_quirk_w; usb_quirk_ioctl_t *usb_quirk_ioctl_p = &usb_quirk_ioctl_w; -devclass_t usb_devclass_ptr = NULL; +devclass_t usb_devclass_ptr; static usb_error_t usb_temp_setup_by_index_w(struct usb_device *udev, uint16_t index) diff --git a/sys/dev/usb/usb_freebsd.h b/sys/dev/usb/usb_freebsd.h index e93bee7..026baab 100644 --- a/sys/dev/usb/usb_freebsd.h +++ b/sys/dev/usb/usb_freebsd.h @@ -44,6 +44,7 @@ #define USB_HAVE_PF 1 #define USB_HAVE_ROOT_MOUNT_HOLD 1 #define USB_HAVE_ID_SECTION 1 +#define USB_HAVE_PER_BUS_PROCESS 1 #define USB_TD_GET_PROC(td) (td)->td_proc #define USB_PROC_GET_GID(td) (td)->p_pgid diff --git a/sys/dev/usb/usb_freebsd_loader.h b/sys/dev/usb/usb_freebsd_loader.h index 566f922..b21c229 100644 --- a/sys/dev/usb/usb_freebsd_loader.h +++ b/sys/dev/usb/usb_freebsd_loader.h @@ -44,6 +44,7 @@ #define USB_HAVE_PF 0 #define USB_HAVE_ROOT_MOUNT_HOLD 0 #define USB_HAVE_ID_SECTION 0 +#define USB_HAVE_PER_BUS_PROCESS 0 #define USB_TD_GET_PROC(td) (td)->td_proc #define USB_PROC_GET_GID(td) (td)->p_pgid diff --git a/sys/dev/usb/usb_hub.c b/sys/dev/usb/usb_hub.c index 5e372c8..1d87a3f 100644 --- a/sys/dev/usb/usb_hub.c +++ b/sys/dev/usb/usb_hub.c @@ -1917,7 +1917,7 @@ usb_needs_explore(struct usb_bus *bus, uint8_t do_probe) if (do_probe) { bus->do_probe = 1; } - if (usb_proc_msignal(&bus->explore_proc, + if (usb_proc_msignal(USB_BUS_EXPLORE_PROC(bus), &bus->explore_msg[0], &bus->explore_msg[1])) { /* ignore */ } diff --git a/sys/dev/usb/usb_msctest.c b/sys/dev/usb/usb_msctest.c index 497e382..a1bc5fc 100644 --- a/sys/dev/usb/usb_msctest.c +++ b/sys/dev/usb/usb_msctest.c @@ -848,7 +848,7 @@ usb_msc_eject(struct usb_device *udev, uint8_t iface_index, int method) sizeof(scsi_tct_eject), USB_MS_HZ); break; default: - printf("usb_msc_eject: unknown eject method (%d)\n", method); + DPRINTF("Unknown eject method (%d)\n", method); break; } DPRINTF("Eject CD command status: %s\n", usbd_errstr(err)); diff --git a/sys/dev/usb/usb_process.c b/sys/dev/usb/usb_process.c index 34314f4..7493e39 100644 --- a/sys/dev/usb/usb_process.c +++ b/sys/dev/usb/usb_process.c @@ -24,8 +24,6 @@ * SUCH DAMAGE. */ -#define USB_DEBUG_VAR usb_proc_debug - #ifdef USB_GLOBAL_INCLUDE_FILE #include USB_GLOBAL_INCLUDE_FILE #else @@ -52,6 +50,8 @@ #include <dev/usb/usbdi.h> #include <dev/usb/usbdi_util.h> #include <dev/usb/usb_process.h> + +#define USB_DEBUG_VAR usb_proc_debug #include <dev/usb/usb_debug.h> #include <dev/usb/usb_util.h> diff --git a/sys/dev/usb/usb_request.c b/sys/dev/usb/usb_request.c index 6a81945..4db5b7d 100644 --- a/sys/dev/usb/usb_request.c +++ b/sys/dev/usb/usb_request.c @@ -800,8 +800,6 @@ usbd_req_reset_port(struct usb_device *udev, struct mtx *mtx, uint8_t port) /* check for errors */ if (err) goto done; -#ifdef USB_DEBUG -#endif n = 0; while (1) { /* wait for the device to recover from reset */ diff --git a/sys/dev/usb/usb_transfer.c b/sys/dev/usb/usb_transfer.c index 397b0b7..edcc596 100644 --- a/sys/dev/usb/usb_transfer.c +++ b/sys/dev/usb/usb_transfer.c @@ -965,14 +965,14 @@ usbd_transfer_setup(struct usb_device *udev, * deadlock! */ if (setup_start == usb_control_ep_cfg) - info->done_p = - &udev->bus->control_xfer_proc; + info->done_p = + USB_BUS_CONTROL_XFER_PROC(udev->bus); else if (xfer_mtx == &Giant) - info->done_p = - &udev->bus->giant_callback_proc; + info->done_p = + USB_BUS_GIANT_PROC(udev->bus); else - info->done_p = - &udev->bus->non_giant_callback_proc; + info->done_p = + USB_BUS_NON_GIANT_PROC(udev->bus); } /* reset sizes */ @@ -2614,7 +2614,7 @@ usbd_pipe_start(struct usb_xfer_queue *pq) } else if (udev->ctrl_xfer[1]) { info = udev->ctrl_xfer[1]->xroot; usb_proc_msignal( - &info->bus->non_giant_callback_proc, + USB_BUS_NON_GIANT_PROC(info->bus), &udev->cs_msg[0], &udev->cs_msg[1]); } else { /* should not happen */ @@ -3216,10 +3216,10 @@ usbd_transfer_poll(struct usb_xfer **ppxfer, uint16_t max) } /* Make sure cv_signal() and cv_broadcast() is not called */ - udev->bus->control_xfer_proc.up_msleep = 0; - udev->bus->explore_proc.up_msleep = 0; - udev->bus->giant_callback_proc.up_msleep = 0; - udev->bus->non_giant_callback_proc.up_msleep = 0; + USB_BUS_CONTROL_XFER_PROC(udev->bus)->up_msleep = 0; + USB_BUS_EXPLORE_PROC(udev->bus)->up_msleep = 0; + USB_BUS_GIANT_PROC(udev->bus)->up_msleep = 0; + USB_BUS_NON_GIANT_PROC(udev->bus)->up_msleep = 0; /* poll USB hardware */ (udev->bus->methods->xfer_poll) (udev->bus); diff --git a/sys/fs/ext2fs/ext2_lookup.c b/sys/fs/ext2fs/ext2_lookup.c index 9aadb6a..8827550 100644 --- a/sys/fs/ext2fs/ext2_lookup.c +++ b/sys/fs/ext2fs/ext2_lookup.c @@ -88,9 +88,8 @@ static u_char ext2_ft_to_dt[] = { DT_SOCK, /* EXT2_FT_SOCK */ DT_LNK, /* EXT2_FT_SYMLINK */ }; -#define FTTODT(ft) \ - ((ft) > sizeof(ext2_ft_to_dt) / sizeof(ext2_ft_to_dt[0]) ? \ - DT_UNKNOWN : ext2_ft_to_dt[(ft)]) +#define FTTODT(ft) \ + ((ft) < nitems(ext2_ft_to_dt) ? ext2_ft_to_dt[(ft)] : DT_UNKNOWN) static u_char dt_to_ext2_ft[] = { EXT2_FT_UNKNOWN, /* DT_UNKNOWN */ @@ -109,9 +108,8 @@ static u_char dt_to_ext2_ft[] = { EXT2_FT_UNKNOWN, /* unused */ EXT2_FT_UNKNOWN, /* DT_WHT */ }; -#define DTTOFT(dt) \ - ((dt) > sizeof(dt_to_ext2_ft) / sizeof(dt_to_ext2_ft[0]) ? \ - EXT2_FT_UNKNOWN : dt_to_ext2_ft[(dt)]) +#define DTTOFT(dt) \ + ((dt) < nitems(dt_to_ext2_ft) ? dt_to_ext2_ft[(dt)] : EXT2_FT_UNKNOWN) static int ext2_dirbadentry(struct vnode *dp, struct ext2fs_direct_2 *de, int entryoffsetinblock); @@ -1088,7 +1086,7 @@ ext2_checkpath(source, target, cred) struct ucred *cred; { struct vnode *vp; - int error, rootino, namlen; + int error, namlen; struct dirtemplate dirbuf; vp = ITOV(target); @@ -1096,10 +1094,10 @@ ext2_checkpath(source, target, cred) error = EEXIST; goto out; } - rootino = EXT2_ROOTINO; - error = 0; - if (target->i_number == rootino) + if (target->i_number == EXT2_ROOTINO) { + error = 0; goto out; + } for (;;) { if (vp->v_type != VDIR) { @@ -1123,7 +1121,7 @@ ext2_checkpath(source, target, cred) error = EINVAL; break; } - if (dirbuf.dotdot_ino == rootino) + if (dirbuf.dotdot_ino == EXT2_ROOTINO) break; vput(vp); if ((error = VFS_VGET(vp->v_mount, dirbuf.dotdot_ino, diff --git a/sys/fs/ext2fs/ext2_mount.h b/sys/fs/ext2fs/ext2_mount.h index f995267..7c598f6 100644 --- a/sys/fs/ext2fs/ext2_mount.h +++ b/sys/fs/ext2fs/ext2_mount.h @@ -48,7 +48,6 @@ struct ext2mount { struct vnode *um_devvp; /* block device mounted vnode */ struct m_ext2fs *um_e2fs; /* EXT2FS */ -#define em_e2fsb um_e2fs->e2fs u_long um_nindir; /* indirect ptrs per block */ u_long um_bptrtodb; /* indir ptr to disk block */ diff --git a/sys/fs/ext2fs/ext2_vnops.c b/sys/fs/ext2fs/ext2_vnops.c index 4f8f6a9..7cfc64b 100644 --- a/sys/fs/ext2fs/ext2_vnops.c +++ b/sys/fs/ext2fs/ext2_vnops.c @@ -730,7 +730,7 @@ ext2_link(ap) goto out; } ip = VTOI(vp); - if ((nlink_t)ip->i_nlink >= LINK_MAX) { + if ((nlink_t)ip->i_nlink >= EXT2_LINK_MAX) { error = EMLINK; goto out; } @@ -841,7 +841,7 @@ abortit: goto abortit; dp = VTOI(fdvp); ip = VTOI(fvp); - if (ip->i_nlink >= LINK_MAX) { + if (ip->i_nlink >= EXT2_LINK_MAX) { VOP_UNLOCK(fvp, 0); error = EMLINK; goto abortit; @@ -939,7 +939,7 @@ abortit: * parent we don't fool with the link count. */ if (doingdirectory && newparent) { - if ((nlink_t)dp->i_nlink >= LINK_MAX) { + if ((nlink_t)dp->i_nlink >= EXT2_LINK_MAX) { error = EMLINK; goto bad; } @@ -1160,7 +1160,7 @@ ext2_mkdir(ap) panic("ext2_mkdir: no name"); #endif dp = VTOI(dvp); - if ((nlink_t)dp->i_nlink >= LINK_MAX) { + if ((nlink_t)dp->i_nlink >= EXT2_LINK_MAX) { error = EMLINK; goto out; } @@ -1524,7 +1524,7 @@ ext2_pathconf(ap) switch (ap->a_name) { case _PC_LINK_MAX: - *ap->a_retval = LINK_MAX; + *ap->a_retval = EXT2_LINK_MAX; return (0); case _PC_NAME_MAX: *ap->a_retval = NAME_MAX; diff --git a/sys/kern/subr_blist.c b/sys/kern/subr_blist.c index 788b5eb..5c45b81 100644 --- a/sys/kern/subr_blist.c +++ b/sys/kern/subr_blist.c @@ -52,14 +52,10 @@ * radix tree should be able to operate well no matter how much * fragmentation there is and no matter how large a bitmap is used. * - * Unlike the rlist code, the blist code wires all necessary memory at - * creation time. Neither allocations nor frees require interaction with - * the memory subsystem. In contrast, the rlist code may allocate memory - * on an rlist_free() call. The non-blocking features of the blist code - * are used to great advantage in the swap code (vm/nswap_pager.c). The - * rlist code uses a little less overall memory than the blist code (but - * due to swap interleaving not all that much less), but the blist code - * scales much, much better. + * The blist code wires all necessary memory at creation time. Neither + * allocations nor frees require interaction with the memory subsystem. + * The non-blocking features of the blist code are used in the swap code + * (vm/swap_pager.c). * * LAYOUT: The radix tree is layed out recursively using a * linear array. Each meta node is immediately followed (layed out diff --git a/sys/sys/queue.h b/sys/sys/queue.h index e65b1ce..368d69e 100644 --- a/sys/sys/queue.h +++ b/sys/sys/queue.h @@ -105,13 +105,14 @@ #ifdef QUEUE_MACRO_DEBUG /* Store the last 2 places the queue element or head was altered */ struct qm_trace { - char * lastfile; - int lastline; - char * prevfile; - int prevline; + unsigned long lastline; + unsigned long prevline; + const char *lastfile; + const char *prevfile; }; #define TRACEBUF struct qm_trace trace; +#define TRACEBUF_INITIALIZER { __FILE__, __LINE__, NULL, 0 } , #define TRASHIT(x) do {(x) = (void *)-1;} while (0) #define QMD_SAVELINK(name, link) void **name = (void *)&(link) @@ -134,6 +135,7 @@ struct qm_trace { #define QMD_TRACE_HEAD(head) #define QMD_SAVELINK(name, link) #define TRACEBUF +#define TRACEBUF_INITIALIZER #define TRASHIT(x) #endif /* QUEUE_MACRO_DEBUG */ @@ -461,7 +463,7 @@ struct name { \ } #define TAILQ_HEAD_INITIALIZER(head) \ - { NULL, &(head).tqh_first } + { NULL, &(head).tqh_first, TRACEBUF_INITIALIZER } #define TAILQ_ENTRY(type) \ struct { \ |