diff options
Diffstat (limited to 'sys/arm')
-rw-r--r-- | sys/arm/broadcom/bcm2835/bcm2835_fb.c | 714 | ||||
-rw-r--r-- | sys/arm/broadcom/bcm2835/bcm2835_intr.c | 203 | ||||
-rw-r--r-- | sys/arm/broadcom/bcm2835/bcm2835_machdep.c | 603 | ||||
-rw-r--r-- | sys/arm/broadcom/bcm2835/bcm2835_mbox.c | 249 | ||||
-rw-r--r-- | sys/arm/broadcom/bcm2835/bcm2835_mbox.h | 44 | ||||
-rw-r--r-- | sys/arm/broadcom/bcm2835/bcm2835_systimer.c | 298 | ||||
-rw-r--r-- | sys/arm/broadcom/bcm2835/bcm2835_vcbus.h | 52 | ||||
-rw-r--r-- | sys/arm/broadcom/bcm2835/bcm2835_wdog.c | 167 | ||||
-rw-r--r-- | sys/arm/broadcom/bcm2835/bcm2835_wdog.h | 32 | ||||
-rw-r--r-- | sys/arm/broadcom/bcm2835/bus_space.c | 113 | ||||
-rw-r--r-- | sys/arm/broadcom/bcm2835/common.c | 75 | ||||
-rw-r--r-- | sys/arm/broadcom/bcm2835/files.bcm2835 | 19 | ||||
-rw-r--r-- | sys/arm/conf/RPI-B | 101 |
13 files changed, 2670 insertions, 0 deletions
diff --git a/sys/arm/broadcom/bcm2835/bcm2835_fb.c b/sys/arm/broadcom/bcm2835/bcm2835_fb.c new file mode 100644 index 0000000..f6a4d7b --- /dev/null +++ b/sys/arm/broadcom/bcm2835/bcm2835_fb.c @@ -0,0 +1,714 @@ +/*- + * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org> + * 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/bio.h> +#include <sys/bus.h> +#include <sys/conf.h> +#include <sys/endian.h> +#include <sys/kernel.h> +#include <sys/kthread.h> +#include <sys/lock.h> +#include <sys/malloc.h> +#include <sys/module.h> +#include <sys/mutex.h> +#include <sys/queue.h> +#include <sys/resource.h> +#include <sys/rman.h> +#include <sys/time.h> +#include <sys/timetc.h> +#include <sys/fbio.h> +#include <sys/consio.h> + +#include <sys/kdb.h> + +#include <machine/bus.h> +#include <machine/cpu.h> +#include <machine/cpufunc.h> +#include <machine/resource.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 <dev/fb/fbreg.h> +#include <dev/syscons/syscons.h> + +#include <arm/broadcom/bcm2835/bcm2835_mbox.h> +#include <arm/broadcom/bcm2835/bcm2835_vcbus.h> + +#define BCMFB_FONT_HEIGHT 16 + +#define FB_WIDTH 640 +#define FB_HEIGHT 480 + +struct bcm_fb_config { + uint32_t xres; + uint32_t yres; + uint32_t vxres; + uint32_t vyres; + uint32_t pitch; + uint32_t bpp; + uint32_t xoffset; + uint32_t yoffset; + /* Filled by videocore */ + uint32_t base; + uint32_t screen_size; +}; + +struct bcmsc_softc { + device_t dev; + struct cdev * cdev; + struct mtx mtx; + bus_dma_tag_t dma_tag; + bus_dmamap_t dma_map; + struct bcm_fb_config* fb_config; + bus_addr_t fb_config_phys; + struct intr_config_hook init_hook; + +}; + +struct video_adapter_softc { + /* Videoadpater part */ + video_adapter_t va; + int console; + + intptr_t fb_addr; + unsigned int fb_size; + + unsigned int height; + unsigned int width; + unsigned int stride; + + unsigned int xmargin; + unsigned int ymargin; + + unsigned char *font; + int initialized; +}; + +static struct bcmsc_softc *bcmsc_softc; +static struct video_adapter_softc va_softc; + +#define bcm_fb_lock(_sc) mtx_lock(&(_sc)->mtx) +#define bcm_fb_unlock(_sc) mtx_unlock(&(_sc)->mtx) +#define bcm_fb_lock_assert(sc) mtx_assert(&(_sc)->mtx, MA_OWNED) + +static int bcm_fb_probe(device_t); +static int bcm_fb_attach(device_t); +static void bcm_fb_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int err); + +static void +bcm_fb_init(void *arg) +{ + struct bcmsc_softc *sc = arg; + struct video_adapter_softc *va_sc = &va_softc; + int err; + volatile struct bcm_fb_config* fb_config = sc->fb_config; + + /* TODO: replace it with FDT stuff */ + fb_config->xres = FB_WIDTH; + fb_config->yres = FB_HEIGHT; + fb_config->vxres = 0; + fb_config->vyres = 0; + fb_config->xoffset = 0; + fb_config->yoffset = 0; + fb_config->bpp = 24; + fb_config->base = 0; + fb_config->pitch = 0; + fb_config->screen_size = 0; + + bus_dmamap_sync(sc->dma_tag, sc->dma_map, + BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); + bcm_mbox_write(BCM2835_MBOX_CHAN_FB, sc->fb_config_phys); + bcm_mbox_read(BCM2835_MBOX_CHAN_FB, &err); + bus_dmamap_sync(sc->dma_tag, sc->dma_map, + BUS_DMASYNC_POSTREAD); + + if (err == 0) { + device_printf(sc->dev, "%dx%d(%dx%d@%d,%d) %dbpp\n", + fb_config->xres, fb_config->yres, + fb_config->vxres, fb_config->vyres, + fb_config->xoffset, fb_config->yoffset, + fb_config->bpp); + + + device_printf(sc->dev, "pitch %d, base 0x%08x, screen_size %d\n", + fb_config->pitch, fb_config->base, + fb_config->screen_size); + + if (fb_config->base) { + va_sc->fb_addr = (intptr_t)pmap_mapdev(fb_config->base, fb_config->screen_size); + va_sc->fb_size = fb_config->screen_size; + va_sc->stride = fb_config->pitch; + } + } + else + device_printf(sc->dev, "Failed to set framebuffer info\n"); + + config_intrhook_disestablish(&sc->init_hook); +} + +static int +bcm_fb_probe(device_t dev) +{ + int error; + + if (!ofw_bus_is_compatible(dev, "broadcom,bcm2835-fb")) + return (ENXIO); + + device_set_desc(dev, "BCM2835 framebuffer device"); + + error = sc_probe_unit(device_get_unit(dev), + device_get_flags(dev) | SC_AUTODETECT_KBD); + + if (error != 0) + return (error); + + return (BUS_PROBE_DEFAULT); +} + +static int +bcm_fb_attach(device_t dev) +{ + struct bcmsc_softc *sc = device_get_softc(dev); + int dma_size = sizeof(struct bcm_fb_config); + int err; + + if (bcmsc_softc) + return (ENXIO); + + bcmsc_softc = sc; + + sc->dev = dev; + mtx_init(&sc->mtx, "bcm2835fb", "fb", MTX_DEF); + + err = bus_dma_tag_create( + bus_get_dma_tag(sc->dev), + PAGE_SIZE, 0, /* alignment, boundary */ + BUS_SPACE_MAXADDR_32BIT, /* lowaddr */ + BUS_SPACE_MAXADDR, /* highaddr */ + NULL, NULL, /* filter, filterarg */ + dma_size, 1, /* maxsize, nsegments */ + dma_size, 0, /* maxsegsize, flags */ + NULL, NULL, /* lockfunc, lockarg */ + &sc->dma_tag); + + err = bus_dmamem_alloc(sc->dma_tag, (void **)&sc->fb_config, + 0, &sc->dma_map); + if (err) { + device_printf(dev, "cannot allocate framebuffer\n"); + goto fail; + } + + err = bus_dmamap_load(sc->dma_tag, sc->dma_map, sc->fb_config, + dma_size, bcm_fb_dmamap_cb, &sc->fb_config_phys, BUS_DMA_NOWAIT); + + if (err) { + device_printf(dev, "cannot load DMA map\n"); + goto fail; + } + + err = (sc_attach_unit(device_get_unit(dev), + device_get_flags(dev) | SC_AUTODETECT_KBD)); + + if (err) { + device_printf(dev, "failed to attach syscons\n"); + goto fail; + } + + /* + * We have to wait until interrupts are enabled. + * Mailbox relies on it to get data from VideoCore + */ + sc->init_hook.ich_func = bcm_fb_init; + sc->init_hook.ich_arg = sc; + + if (config_intrhook_establish(&sc->init_hook) != 0) { + device_printf(dev, "failed to establish intrhook\n"); + return (ENOMEM); + } + + return (0); + +fail: + return (ENXIO); +} + + +static void +bcm_fb_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int err) +{ + bus_addr_t *addr; + + if (err) + return; + + addr = (bus_addr_t*)arg; + *addr = PHYS_TO_VCBUS(segs[0].ds_addr); +} + +static device_method_t bcm_fb_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, bcm_fb_probe), + DEVMETHOD(device_attach, bcm_fb_attach), + + { 0, 0 } +}; + +static devclass_t bcm_fb_devclass; + +static driver_t bcm_fb_driver = { + "fb", + bcm_fb_methods, + sizeof(struct bcmsc_softc), +}; + +DRIVER_MODULE(bcm2835fb, simplebus, bcm_fb_driver, bcm_fb_devclass, 0, 0); + +/* + * Video driver routines and glue. + */ +static int bcmfb_configure(int); +static vi_probe_t bcmfb_probe; +static vi_init_t bcmfb_init; +static vi_get_info_t bcmfb_get_info; +static vi_query_mode_t bcmfb_query_mode; +static vi_set_mode_t bcmfb_set_mode; +static vi_save_font_t bcmfb_save_font; +static vi_load_font_t bcmfb_load_font; +static vi_show_font_t bcmfb_show_font; +static vi_save_palette_t bcmfb_save_palette; +static vi_load_palette_t bcmfb_load_palette; +static vi_set_border_t bcmfb_set_border; +static vi_save_state_t bcmfb_save_state; +static vi_load_state_t bcmfb_load_state; +static vi_set_win_org_t bcmfb_set_win_org; +static vi_read_hw_cursor_t bcmfb_read_hw_cursor; +static vi_set_hw_cursor_t bcmfb_set_hw_cursor; +static vi_set_hw_cursor_shape_t bcmfb_set_hw_cursor_shape; +static vi_blank_display_t bcmfb_blank_display; +static vi_mmap_t bcmfb_mmap; +static vi_ioctl_t bcmfb_ioctl; +static vi_clear_t bcmfb_clear; +static vi_fill_rect_t bcmfb_fill_rect; +static vi_bitblt_t bcmfb_bitblt; +static vi_diag_t bcmfb_diag; +static vi_save_cursor_palette_t bcmfb_save_cursor_palette; +static vi_load_cursor_palette_t bcmfb_load_cursor_palette; +static vi_copy_t bcmfb_copy; +static vi_putp_t bcmfb_putp; +static vi_putc_t bcmfb_putc; +static vi_puts_t bcmfb_puts; +static vi_putm_t bcmfb_putm; + +static video_switch_t bcmfbvidsw = { + .probe = bcmfb_probe, + .init = bcmfb_init, + .get_info = bcmfb_get_info, + .query_mode = bcmfb_query_mode, + .set_mode = bcmfb_set_mode, + .save_font = bcmfb_save_font, + .load_font = bcmfb_load_font, + .show_font = bcmfb_show_font, + .save_palette = bcmfb_save_palette, + .load_palette = bcmfb_load_palette, + .set_border = bcmfb_set_border, + .save_state = bcmfb_save_state, + .load_state = bcmfb_load_state, + .set_win_org = bcmfb_set_win_org, + .read_hw_cursor = bcmfb_read_hw_cursor, + .set_hw_cursor = bcmfb_set_hw_cursor, + .set_hw_cursor_shape = bcmfb_set_hw_cursor_shape, + .blank_display = bcmfb_blank_display, + .mmap = bcmfb_mmap, + .ioctl = bcmfb_ioctl, + .clear = bcmfb_clear, + .fill_rect = bcmfb_fill_rect, + .bitblt = bcmfb_bitblt, + .diag = bcmfb_diag, + .save_cursor_palette = bcmfb_save_cursor_palette, + .load_cursor_palette = bcmfb_load_cursor_palette, + .copy = bcmfb_copy, + .putp = bcmfb_putp, + .putc = bcmfb_putc, + .puts = bcmfb_puts, + .putm = bcmfb_putm, +}; + +VIDEO_DRIVER(bcmfb, bcmfbvidsw, bcmfb_configure); + +extern sc_rndr_sw_t txtrndrsw; +RENDERER(bcmfb, 0, txtrndrsw, gfb_set); +RENDERER_MODULE(bcmfb, gfb_set); + +static uint16_t bcmfb_static_window[ROW*COL]; +extern u_char dflt_font_16[]; + +static int +bcmfb_configure(int flags) +{ + struct video_adapter_softc *sc; + + sc = &va_softc; + + if (sc->initialized) + return 0; + + sc->height = FB_HEIGHT; + sc->width = FB_WIDTH; + + bcmfb_init(0, &sc->va, 0); + + sc->initialized = 1; + + return (0); +} + +static int +bcmfb_probe(int unit, video_adapter_t **adp, void *arg, int flags) +{ + + return (0); +} + +static int +bcmfb_init(int unit, video_adapter_t *adp, int flags) +{ + struct video_adapter_softc *sc; + video_info_t *vi; + + sc = (struct video_adapter_softc *)adp; + vi = &adp->va_info; + + vid_init_struct(adp, "bcmfb", -1, unit); + + sc->font = dflt_font_16; + vi->vi_cheight = BCMFB_FONT_HEIGHT; + vi->vi_cwidth = 8; + vi->vi_width = sc->width/8; + vi->vi_height = sc->height/vi->vi_cheight; + + /* + * Clamp width/height to syscons maximums + */ + if (vi->vi_width > COL) + vi->vi_width = COL; + if (vi->vi_height > ROW) + vi->vi_height = ROW; + + sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2; + sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2; + + adp->va_window = (vm_offset_t) bcmfb_static_window; + adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */; + + vid_register(&sc->va); + + return (0); +} + +static int +bcmfb_get_info(video_adapter_t *adp, int mode, video_info_t *info) +{ + bcopy(&adp->va_info, info, sizeof(*info)); + return (0); +} + +static int +bcmfb_query_mode(video_adapter_t *adp, video_info_t *info) +{ + return (0); +} + +static int +bcmfb_set_mode(video_adapter_t *adp, int mode) +{ + return (0); +} + +static int +bcmfb_save_font(video_adapter_t *adp, int page, int size, int width, + u_char *data, int c, int count) +{ + return (0); +} + +static int +bcmfb_load_font(video_adapter_t *adp, int page, int size, int width, + u_char *data, int c, int count) +{ + struct video_adapter_softc *sc = (struct video_adapter_softc *)adp; + + sc->font = data; + + return (0); +} + +static int +bcmfb_show_font(video_adapter_t *adp, int page) +{ + return (0); +} + +static int +bcmfb_save_palette(video_adapter_t *adp, u_char *palette) +{ + return (0); +} + +static int +bcmfb_load_palette(video_adapter_t *adp, u_char *palette) +{ + return (0); +} + +static int +bcmfb_set_border(video_adapter_t *adp, int border) +{ + return (bcmfb_blank_display(adp, border)); +} + +static int +bcmfb_save_state(video_adapter_t *adp, void *p, size_t size) +{ + return (0); +} + +static int +bcmfb_load_state(video_adapter_t *adp, void *p) +{ + return (0); +} + +static int +bcmfb_set_win_org(video_adapter_t *adp, off_t offset) +{ + return (0); +} + +static int +bcmfb_read_hw_cursor(video_adapter_t *adp, int *col, int *row) +{ + *col = *row = 0; + + return (0); +} + +static int +bcmfb_set_hw_cursor(video_adapter_t *adp, int col, int row) +{ + return (0); +} + +static int +bcmfb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, + int celsize, int blink) +{ + return (0); +} + +static int +bcmfb_blank_display(video_adapter_t *adp, int mode) +{ + + return (0); +} + +static int +bcmfb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr, + int prot, vm_memattr_t *memattr) +{ + struct video_adapter_softc *sc; + + sc = (struct video_adapter_softc *)adp; + + /* + * This might be a legacy VGA mem request: if so, just point it at the + * framebuffer, since it shouldn't be touched + */ + if (offset < sc->stride*sc->height) { + *paddr = sc->fb_addr + offset; + return (0); + } + + return (EINVAL); +} + +static int +bcmfb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data) +{ + + return (0); +} + +static int +bcmfb_clear(video_adapter_t *adp) +{ + + return (bcmfb_blank_display(adp, 0)); +} + +static int +bcmfb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) +{ + + return (0); +} + +static int +bcmfb_bitblt(video_adapter_t *adp, ...) +{ + + return (0); +} + +static int +bcmfb_diag(video_adapter_t *adp, int level) +{ + + return (0); +} + +static int +bcmfb_save_cursor_palette(video_adapter_t *adp, u_char *palette) +{ + + return (0); +} + +static int +bcmfb_load_cursor_palette(video_adapter_t *adp, u_char *palette) +{ + + return (0); +} + +static int +bcmfb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n) +{ + + return (0); +} + +static int +bcmfb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a, + int size, int bpp, int bit_ltor, int byte_ltor) +{ + + return (0); +} + +static int +bcmfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a) +{ + struct video_adapter_softc *sc; + int row; + int col; + int i, j, k; + uint8_t *addr; + u_char *p; + uint8_t fg, bg, color; + + sc = (struct video_adapter_softc *)adp; + + if (sc->fb_addr == 0) + return (0); + + row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; + col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; + p = sc->font + c*BCMFB_FONT_HEIGHT; + addr = (uint8_t *)sc->fb_addr + + (row + sc->ymargin)*(sc->stride) + + 3 * (col + sc->xmargin); + + /* + * FIXME: hardcoded + */ + bg = 0x00; + fg = 0x80; + + for (i = 0; i < BCMFB_FONT_HEIGHT; i++) { + for (j = 0, k = 7; j < 8; j++, k--) { + if ((p[i] & (1 << k)) == 0) + color = bg; + else + color = fg; + + addr[3*j] = color; + addr[3*j+1] = color; + addr[3*j+2] = color; + } + + addr += (sc->stride); + } + + return (0); +} + +static int +bcmfb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len) +{ + int i; + + for (i = 0; i < len; i++) + bcmfb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8); + + return (0); +} + +static int +bcmfb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image, + uint32_t pixel_mask, int size, int width) +{ + + return (0); +} + +/* + * Define a stub keyboard driver in case one hasn't been + * compiled into the kernel + */ +#include <sys/kbio.h> +#include <dev/kbd/kbdreg.h> + +static int dummy_kbd_configure(int flags); + +keyboard_switch_t bcmdummysw; + +static int +dummy_kbd_configure(int flags) +{ + + return (0); +} +KEYBOARD_DRIVER(bcmdummy, bcmdummysw, dummy_kbd_configure); diff --git a/sys/arm/broadcom/bcm2835/bcm2835_intr.c b/sys/arm/broadcom/bcm2835/bcm2835_intr.c new file mode 100644 index 0000000..09092a0 --- /dev/null +++ b/sys/arm/broadcom/bcm2835/bcm2835_intr.c @@ -0,0 +1,203 @@ +/*- + * Copyright (c) 2012 Damjan Marion <dmarion@Freebsd.org> + * All rights reserved. + * + * Based on OMAP3 INTC code by Ben Gray + * + * 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/ktr.h> +#include <sys/module.h> +#include <sys/rman.h> +#include <machine/bus.h> +#include <machine/intr.h> + +#include <dev/fdt/fdt_common.h> +#include <dev/ofw/openfirm.h> +#include <dev/ofw/ofw_bus.h> +#include <dev/ofw/ofw_bus_subr.h> + +#define INTC_PENDING_BASIC 0x00 +#define INTC_PENDING_BANK1 0x04 +#define INTC_PENDING_BANK2 0x08 +#define INTC_FIQ_CONTROL 0x0C +#define INTC_ENABLE_BANK1 0x10 +#define INTC_ENABLE_BANK2 0x14 +#define INTC_ENABLE_BASIC 0x18 +#define INTC_DISABLE_BANK1 0x1C +#define INTC_DISABLE_BANK2 0x20 +#define INTC_DISABLE_BASIC 0x24 + +#define BANK1_START 8 +#define BANK1_END (BANK1_START + 32 - 1) +#define BANK2_START (BANK1_START + 32) +#define BANK2_END (BANK2_START + 32 - 1) + +#define IS_IRQ_BASIC(n) (((n) >= 0) && ((n) < BANK1_START)) +#define IS_IRQ_BANK1(n) (((n) >= BANK1_START) && ((n) <= BANK1_END)) +#define IS_IRQ_BANK2(n) (((n) >= BANK2_START) && ((n) <= BANK2_END)) +#define IRQ_BANK1(n) ((n) - BANK1_START) +#define IRQ_BANK2(n) ((n) - BANK2_START) + +#ifdef DEBUG +#define dprintf(fmt, args...) printf(fmt, ##args) +#else +#define dprintf(fmt, args...) +#endif + +struct bcm_intc_softc { + device_t sc_dev; + struct resource * intc_res; + bus_space_tag_t intc_bst; + bus_space_handle_t intc_bsh; +}; + +static struct bcm_intc_softc *bcm_intc_sc = NULL; + +#define intc_read_4(reg) \ + bus_space_read_4(bcm_intc_sc->intc_bst, bcm_intc_sc->intc_bsh, reg) +#define intc_write_4(reg, val) \ + bus_space_write_4(bcm_intc_sc->intc_bst, bcm_intc_sc->intc_bsh, reg, val) + +static int +bcm_intc_probe(device_t dev) +{ + if (!ofw_bus_is_compatible(dev, "broadcom,bcm2835-armctrl-ic")) + return (ENXIO); + device_set_desc(dev, "BCM2835 Interrupt Controller"); + return (BUS_PROBE_DEFAULT); +} + +static int +bcm_intc_attach(device_t dev) +{ + struct bcm_intc_softc *sc = device_get_softc(dev); + int rid = 0; + + sc->sc_dev = dev; + + if (bcm_intc_sc) + return (ENXIO); + + sc->intc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); + if (sc->intc_res == NULL) { + device_printf(dev, "could not allocate memory resource\n"); + return (ENXIO); + } + + sc->intc_bst = rman_get_bustag(sc->intc_res); + sc->intc_bsh = rman_get_bushandle(sc->intc_res); + + bcm_intc_sc = sc; + + return (0); +} + +static device_method_t bcm_intc_methods[] = { + DEVMETHOD(device_probe, bcm_intc_probe), + DEVMETHOD(device_attach, bcm_intc_attach), + { 0, 0 } +}; + +static driver_t bcm_intc_driver = { + "intc", + bcm_intc_methods, + sizeof(struct bcm_intc_softc), +}; + +static devclass_t bcm_intc_devclass; + +DRIVER_MODULE(intc, simplebus, bcm_intc_driver, bcm_intc_devclass, 0, 0); + +int +arm_get_next_irq(int last_irq) +{ + uint32_t pending; + int32_t irq = last_irq + 1; + + /* Sanity check */ + if (irq < 0) + irq = 0; + + /* TODO: should we mask last_irq? */ + pending = intc_read_4(INTC_PENDING_BASIC); + while (irq < BANK1_START) { + if (pending & (1 << irq)) + return irq; + irq++; + } + + pending = intc_read_4(INTC_PENDING_BANK1); + while (irq < BANK2_START) { + if (pending & (1 << IRQ_BANK1(irq))) + return irq; + irq++; + } + + pending = intc_read_4(INTC_PENDING_BANK2); + while (irq <= BANK2_END) { + if (pending & (1 << IRQ_BANK2(irq))) + return irq; + irq++; + } + + return (-1); +} + +void +arm_mask_irq(uintptr_t nb) +{ + dprintf("%s: %d\n", __func__, nb); + + if (IS_IRQ_BASIC(nb)) + intc_write_4(INTC_DISABLE_BASIC, (1 << nb)); + else if (IS_IRQ_BANK1(nb)) + intc_write_4(INTC_DISABLE_BANK1, (1 << IRQ_BANK1(nb))); + else if (IS_IRQ_BANK2(nb)) + intc_write_4(INTC_DISABLE_BANK2, (1 << IRQ_BANK2(nb))); + else + printf("arm_mask_irq: Invalid IRQ number: %d\n", nb); +} + +void +arm_unmask_irq(uintptr_t nb) +{ + dprintf("%s: %d\n", __func__, nb); + + if (IS_IRQ_BASIC(nb)) + intc_write_4(INTC_ENABLE_BASIC, (1 << nb)); + else if (IS_IRQ_BANK1(nb)) + intc_write_4(INTC_ENABLE_BANK1, (1 << IRQ_BANK1(nb))); + else if (IS_IRQ_BANK2(nb)) + intc_write_4(INTC_ENABLE_BANK2, (1 << IRQ_BANK2(nb))); + else + printf("arm_mask_irq: Invalid IRQ number: %d\n", nb); +} diff --git a/sys/arm/broadcom/bcm2835/bcm2835_machdep.c b/sys/arm/broadcom/bcm2835/bcm2835_machdep.c new file mode 100644 index 0000000..f26480f --- /dev/null +++ b/sys/arm/broadcom/bcm2835/bcm2835_machdep.c @@ -0,0 +1,603 @@ +/*- + * Copyright (c) 2012 Oleksandr Tymoshenko. + * Copyright (c) 1994-1998 Mark Brinicombe. + * Copyright (c) 1994 Brini. + * All rights reserved. + * + * This code is derived from software written for Brini by Mark Brinicombe + * + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Brini. + * 4. The name of the company nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY BRINI ``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 BRINI 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. + * + * from: FreeBSD: //depot/projects/arm/src/sys/arm/at91/kb920x_machdep.c, rev 45 + */ + +#include "opt_ddb.h" +#include "opt_platform.h" +#include "opt_global.h" + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#define _ARM32_BUS_DMA_PRIVATE +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/sysproto.h> +#include <sys/signalvar.h> +#include <sys/imgact.h> +#include <sys/kernel.h> +#include <sys/ktr.h> +#include <sys/linker.h> +#include <sys/lock.h> +#include <sys/malloc.h> +#include <sys/mutex.h> +#include <sys/pcpu.h> +#include <sys/proc.h> +#include <sys/ptrace.h> +#include <sys/cons.h> +#include <sys/bio.h> +#include <sys/bus.h> +#include <sys/buf.h> +#include <sys/exec.h> +#include <sys/kdb.h> +#include <sys/msgbuf.h> +#include <machine/reg.h> +#include <machine/cpu.h> +#include <machine/fdt.h> + +#include <dev/fdt/fdt_common.h> +#include <dev/ofw/openfirm.h> + +#include <vm/vm.h> +#include <vm/pmap.h> +#include <vm/vm_object.h> +#include <vm/vm_page.h> +#include <vm/vm_pager.h> +#include <vm/vm_map.h> +#include <machine/pte.h> +#include <machine/pmap.h> +#include <machine/vmparam.h> +#include <machine/pcb.h> +#include <machine/undefined.h> +#include <machine/machdep.h> +#include <machine/metadata.h> +#include <machine/armreg.h> +#include <machine/bus.h> +#include <sys/reboot.h> + +#include <arm/broadcom/bcm2835/bcm2835_wdog.h> + +#define DEBUG +#ifdef DEBUG +#define debugf(fmt, args...) printf(fmt, ##args) +#else +#define debugf(fmt, args...) +#endif + +/* Start of address space used for bootstrap map */ +#define DEVMAP_BOOTSTRAP_MAP_START 0xE0000000 + +/* + * This is the number of L2 page tables required for covering max + * (hypothetical) memsize of 4GB and all kernel mappings (vectors, msgbuf, + * stacks etc.), uprounded to be divisible by 4. + */ +#define KERNEL_PT_MAX 78 + +/* Define various stack sizes in pages */ +#define IRQ_STACK_SIZE 1 +#define ABT_STACK_SIZE 1 +#define UND_STACK_SIZE 1 + +extern unsigned char kernbase[]; +extern unsigned char _etext[]; +extern unsigned char _edata[]; +extern unsigned char __bss_start[]; +extern unsigned char _end[]; + +#ifdef DDB +extern vm_offset_t ksym_start, ksym_end; +#endif + +extern u_int data_abort_handler_address; +extern u_int prefetch_abort_handler_address; +extern u_int undefined_handler_address; + +extern vm_offset_t pmap_bootstrap_lastaddr; +extern int *end; + +struct pv_addr kernel_pt_table[KERNEL_PT_MAX]; + +/* Physical and virtual addresses for some global pages */ +vm_paddr_t phys_avail[10]; +vm_paddr_t dump_avail[4]; +vm_offset_t physical_pages; +vm_offset_t pmap_bootstrap_lastaddr; +vm_paddr_t pmap_pa; + +const struct pmap_devmap *pmap_devmap_bootstrap_table; +struct pv_addr systempage; +struct pv_addr msgbufpv; +struct pv_addr irqstack; +struct pv_addr undstack; +struct pv_addr abtstack; +struct pv_addr kernelstack; + +void set_stackptrs(int cpu); + +static struct mem_region availmem_regions[FDT_MEM_REGIONS]; +static int availmem_regions_sz; + +static void print_kenv(void); +static void print_kernel_section_addr(void); + +static void physmap_init(void); +static int platform_devmap_init(void); + +static char * +kenv_next(char *cp) +{ + + if (cp != NULL) { + while (*cp != 0) + cp++; + cp++; + if (*cp == 0) + cp = NULL; + } + return (cp); +} + +static void +print_kenv(void) +{ + int len; + char *cp; + + debugf("loader passed (static) kenv:\n"); + if (kern_envp == NULL) { + debugf(" no env, null ptr\n"); + return; + } + debugf(" kern_envp = 0x%08x\n", (uint32_t)kern_envp); + + len = 0; + for (cp = kern_envp; cp != NULL; cp = kenv_next(cp)) + debugf(" %x %s\n", (uint32_t)cp, cp); +} + +static void +print_kernel_section_addr(void) +{ + + debugf("kernel image addresses:\n"); + debugf(" kernbase = 0x%08x\n", (uint32_t)kernbase); + debugf(" _etext (sdata) = 0x%08x\n", (uint32_t)_etext); + debugf(" _edata = 0x%08x\n", (uint32_t)_edata); + debugf(" __bss_start = 0x%08x\n", (uint32_t)__bss_start); + debugf(" _end = 0x%08x\n", (uint32_t)_end); +} + +static void +physmap_init(void) +{ + int i, j, cnt; + vm_offset_t phys_kernelend, kernload; + uint32_t s, e, sz; + struct mem_region *mp, *mp1; + + phys_kernelend = KERNPHYSADDR + (virtual_avail - KERNVIRTADDR); + kernload = KERNPHYSADDR; + + /* + * Remove kernel physical address range from avail + * regions list. Page align all regions. + * Non-page aligned memory isn't very interesting to us. + * Also, sort the entries for ascending addresses. + */ + sz = 0; + cnt = availmem_regions_sz; + debugf("processing avail regions:\n"); + for (mp = availmem_regions; mp->mr_size; mp++) { + s = mp->mr_start; + e = mp->mr_start + mp->mr_size; + debugf(" %08x-%08x -> ", s, e); + /* Check whether this region holds all of the kernel. */ + if (s < kernload && e > phys_kernelend) { + availmem_regions[cnt].mr_start = phys_kernelend; + availmem_regions[cnt++].mr_size = e - phys_kernelend; + e = kernload; + } + /* Look whether this regions starts within the kernel. */ + if (s >= kernload && s < phys_kernelend) { + if (e <= phys_kernelend) + goto empty; + s = phys_kernelend; + } + /* Now look whether this region ends within the kernel. */ + if (e > kernload && e <= phys_kernelend) { + if (s >= kernload) { + goto empty; + } + e = kernload; + } + /* Now page align the start and size of the region. */ + s = round_page(s); + e = trunc_page(e); + if (e < s) + e = s; + sz = e - s; + debugf("%08x-%08x = %x\n", s, e, sz); + + /* Check whether some memory is left here. */ + if (sz == 0) { + empty: + printf("skipping\n"); + bcopy(mp + 1, mp, + (cnt - (mp - availmem_regions)) * sizeof(*mp)); + cnt--; + mp--; + continue; + } + + /* Do an insertion sort. */ + for (mp1 = availmem_regions; mp1 < mp; mp1++) + if (s < mp1->mr_start) + break; + if (mp1 < mp) { + bcopy(mp1, mp1 + 1, (char *)mp - (char *)mp1); + mp1->mr_start = s; + mp1->mr_size = sz; + } else { + mp->mr_start = s; + mp->mr_size = sz; + } + } + availmem_regions_sz = cnt; + + /* Fill in phys_avail table, based on availmem_regions */ + debugf("fill in phys_avail:\n"); + for (i = 0, j = 0; i < availmem_regions_sz; i++, j += 2) { + + debugf(" region: 0x%08x - 0x%08x (0x%08x)\n", + availmem_regions[i].mr_start, + availmem_regions[i].mr_start + availmem_regions[i].mr_size, + availmem_regions[i].mr_size); + + phys_avail[j] = availmem_regions[i].mr_start; + phys_avail[j + 1] = availmem_regions[i].mr_start + + availmem_regions[i].mr_size; + } + phys_avail[j] = 0; + phys_avail[j + 1] = 0; +} + +void * +initarm(struct arm_boot_params *abp) +{ + struct pv_addr kernel_l1pt; + struct pv_addr dpcpu; + vm_offset_t dtbp, freemempos, l2_start, lastaddr; + uint32_t memsize, l2size; + void *kmdp; + u_int l1pagetable; + int i = 0, j = 0; + + lastaddr = fake_preload_metadata(abp); + memsize = 0; + set_cpufuncs(); + + kmdp = preload_search_by_type("elf kernel"); + if (kmdp != NULL) + dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t); + else + dtbp = (vm_offset_t)NULL; + +#if defined(FDT_DTB_STATIC) + /* + * In case the device tree blob was not retrieved (from metadata) try + * to use the statically embedded one. + */ + if (dtbp == (vm_offset_t)NULL) + dtbp = (vm_offset_t)&fdt_static_dtb; +#endif + + if (OF_install(OFW_FDT, 0) == FALSE) + while (1); + + if (OF_init((void *)dtbp) != 0) + while (1); + + /* Grab physical memory regions information from device tree. */ + if (fdt_get_mem_regions(availmem_regions, &availmem_regions_sz, + &memsize) != 0) + while(1); + + /* Platform-specific initialisation */ + pmap_bootstrap_lastaddr = DEVMAP_BOOTSTRAP_MAP_START - ARM_NOCACHE_KVA_SIZE; + + pcpu0_init(); + + /* Calculate number of L2 tables needed for mapping vm_page_array */ + l2size = (memsize / PAGE_SIZE) * sizeof(struct vm_page); + l2size = (l2size >> L1_S_SHIFT) + 1; + + /* + * Add one table for end of kernel map, one for stacks, msgbuf and + * L1 and L2 tables map and one for vectors map. + */ + l2size += 3; + + /* Make it divisible by 4 */ + l2size = (l2size + 3) & ~3; + +#define KERNEL_TEXT_BASE (KERNBASE) + freemempos = (lastaddr + PAGE_MASK) & ~PAGE_MASK; + + /* Define a macro to simplify memory allocation */ +#define valloc_pages(var, np) \ + alloc_pages((var).pv_va, (np)); \ + (var).pv_pa = (var).pv_va + (KERNPHYSADDR - KERNVIRTADDR); + +#define alloc_pages(var, np) \ + (var) = freemempos; \ + freemempos += (np * PAGE_SIZE); \ + memset((char *)(var), 0, ((np) * PAGE_SIZE)); + + while (((freemempos - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) != 0) + freemempos += PAGE_SIZE; + valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE); + + for (i = 0; i < l2size; ++i) { + if (!(i % (PAGE_SIZE / L2_TABLE_SIZE_REAL))) { + valloc_pages(kernel_pt_table[i], + L2_TABLE_SIZE / PAGE_SIZE); + j = i; + } else { + kernel_pt_table[i].pv_va = kernel_pt_table[j].pv_va + + L2_TABLE_SIZE_REAL * (i - j); + kernel_pt_table[i].pv_pa = + kernel_pt_table[i].pv_va - KERNVIRTADDR + + KERNPHYSADDR; + + } + } + /* + * Allocate a page for the system page mapped to 0x00000000 + * or 0xffff0000. This page will just contain the system vectors + * and can be shared by all processes. + */ + valloc_pages(systempage, 1); + + /* Allocate dynamic per-cpu area. */ + valloc_pages(dpcpu, DPCPU_SIZE / PAGE_SIZE); + dpcpu_init((void *)dpcpu.pv_va, 0); + + /* Allocate stacks for all modes */ + valloc_pages(irqstack, (IRQ_STACK_SIZE * MAXCPU)); + valloc_pages(abtstack, (ABT_STACK_SIZE * MAXCPU)); + valloc_pages(undstack, (UND_STACK_SIZE * MAXCPU)); + valloc_pages(kernelstack, (KSTACK_PAGES * MAXCPU)); + + init_param1(); + + valloc_pages(msgbufpv, round_page(msgbufsize) / PAGE_SIZE); + + /* + * Now we start construction of the L1 page table + * We start by mapping the L2 page tables into the L1. + * This means that we can replace L1 mappings later on if necessary + */ + l1pagetable = kernel_l1pt.pv_va; + + /* + * Try to map as much as possible of kernel text and data using + * 1MB section mapping and for the rest of initial kernel address + * space use L2 coarse tables. + * + * Link L2 tables for mapping remainder of kernel (modulo 1MB) + * and kernel structures + */ + l2_start = lastaddr & ~(L1_S_OFFSET); + for (i = 0 ; i < l2size - 1; i++) + pmap_link_l2pt(l1pagetable, l2_start + i * L1_S_SIZE, + &kernel_pt_table[i]); + + pmap_curmaxkvaddr = l2_start + (l2size - 1) * L1_S_SIZE; + + /* Map kernel code and data */ + pmap_map_chunk(l1pagetable, KERNVIRTADDR, KERNPHYSADDR, + (((uint32_t)(lastaddr) - KERNVIRTADDR) + PAGE_MASK) & ~PAGE_MASK, + VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); + + /* Map L1 directory and allocated L2 page tables */ + pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, + L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); + + pmap_map_chunk(l1pagetable, kernel_pt_table[0].pv_va, + kernel_pt_table[0].pv_pa, + L2_TABLE_SIZE_REAL * l2size, + VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); + + /* Map allocated DPCPU, stacks and msgbuf */ + pmap_map_chunk(l1pagetable, dpcpu.pv_va, dpcpu.pv_pa, + freemempos - dpcpu.pv_va, + VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); + + + /* Map allocated DPCPU, stacks and msgbuf */ + pmap_map_chunk(l1pagetable, 0xf2200000, 0x20200000, + 0x00100000, + VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); + + /* Link and map the vector page */ + pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH, + &kernel_pt_table[l2size - 1]); + pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa, + VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE, PTE_CACHE); + + /* Map pmap_devmap[] entries */ + if (platform_devmap_init() != 0) + while (1); + pmap_devmap_bootstrap(l1pagetable, pmap_devmap_bootstrap_table); + + cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL * 2)) | + DOMAIN_CLIENT); + + pmap_pa = kernel_l1pt.pv_pa; + + setttb(kernel_l1pt.pv_pa); + cpu_tlb_flushID(); + cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL * 2)); + + /* + * Only after the SOC registers block is mapped we can perform device + * tree fixups, as they may attempt to read parameters from hardware. + */ + OF_interpret("perform-fixup", 0); + + cninit(); + + physmem = memsize / PAGE_SIZE; + + debugf("initarm: console initialized\n"); + debugf(" arg1 mmdp = 0x%08x\n", (uint32_t)kmdp); + debugf(" boothowto = 0x%08x\n", boothowto); + debugf(" dtbp = 0x%08x\n", (uint32_t)dtbp); + print_kernel_section_addr(); + print_kenv(); + + /* + * Pages were allocated during the secondary bootstrap for the + * stacks for different CPU modes. + * We must now set the r13 registers in the different CPU modes to + * point to these stacks. + * Since the ARM stacks use STMFD etc. we must set r13 to the top end + * of the stack memory. + */ + cpu_control(CPU_CONTROL_MMU_ENABLE, CPU_CONTROL_MMU_ENABLE); + + set_stackptrs(0); + + /* + * We must now clean the cache again.... + * Cleaning may be done by reading new data to displace any + * dirty data in the cache. This will have happened in setttb() + * but since we are boot strapping the addresses used for the read + * may have just been remapped and thus the cache could be out + * of sync. A re-clean after the switch will cure this. + * After booting there are no gross relocations of the kernel thus + * this problem will not occur after initarm(). + */ + cpu_idcache_wbinv_all(); + + /* Set stack for exception handlers */ + data_abort_handler_address = (u_int)data_abort_handler; + prefetch_abort_handler_address = (u_int)prefetch_abort_handler; + undefined_handler_address = (u_int)undefinedinstruction_bounce; + undefined_init(); + + init_proc0(kernelstack.pv_va); + + arm_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL); + + arm_dump_avail_init(memsize, sizeof(dump_avail) / sizeof(dump_avail[0])); + pmap_bootstrap(freemempos, pmap_bootstrap_lastaddr, &kernel_l1pt); + msgbufp = (void *)msgbufpv.pv_va; + msgbufinit(msgbufp, msgbufsize); + mutex_init(); + + /* + * Prepare map of physical memory regions available to vm subsystem. + */ + physmap_init(); + + /* Do basic tuning, hz etc */ + init_param2(physmem); + kdb_init(); + + return ((void *)(kernelstack.pv_va + USPACE_SVC_STACK_TOP - + sizeof(struct pcb))); +} + +void +set_stackptrs(int cpu) +{ + + set_stackptr(PSR_IRQ32_MODE, + irqstack.pv_va + ((IRQ_STACK_SIZE * PAGE_SIZE) * (cpu + 1))); + set_stackptr(PSR_ABT32_MODE, + abtstack.pv_va + ((ABT_STACK_SIZE * PAGE_SIZE) * (cpu + 1))); + set_stackptr(PSR_UND32_MODE, + undstack.pv_va + ((UND_STACK_SIZE * PAGE_SIZE) * (cpu + 1))); +} + +#define FDT_DEVMAP_MAX (2) // FIXME +static struct pmap_devmap fdt_devmap[FDT_DEVMAP_MAX] = { + { 0, 0, 0, 0, 0, } +}; + + +/* + * Construct pmap_devmap[] with DT-derived config data. + */ +static int +platform_devmap_init(void) +{ + int i = 0; + + fdt_devmap[i].pd_va = 0xf2000000; + fdt_devmap[i].pd_pa = 0x20000000; + fdt_devmap[i].pd_size = 0x01000000; /* 1 MB */ + fdt_devmap[i].pd_prot = VM_PROT_READ | VM_PROT_WRITE; + fdt_devmap[i].pd_cache = PTE_DEVICE; + i++; + + pmap_devmap_bootstrap_table = &fdt_devmap[0]; + return (0); +} + +struct arm32_dma_range * +bus_dma_get_range(void) +{ + + return (NULL); +} + +int +bus_dma_get_range_nb(void) +{ + + return (0); +} + +void +cpu_reset() +{ + bcmwd_watchdog_reset(); + while (1); +} diff --git a/sys/arm/broadcom/bcm2835/bcm2835_mbox.c b/sys/arm/broadcom/bcm2835/bcm2835_mbox.c new file mode 100644 index 0000000..a262ad7 --- /dev/null +++ b/sys/arm/broadcom/bcm2835/bcm2835_mbox.c @@ -0,0 +1,249 @@ +/*- + * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org> + * 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/malloc.h> +#include <sys/rman.h> +#include <sys/timeet.h> +#include <sys/timetc.h> +#include <sys/watchdog.h> +#include <machine/bus.h> +#include <machine/cpu.h> +#include <machine/frame.h> +#include <machine/intr.h> + +#include <dev/fdt/fdt_common.h> +#include <dev/ofw/openfirm.h> +#include <dev/ofw/ofw_bus.h> +#include <dev/ofw/ofw_bus_subr.h> + +#include <machine/bus.h> +#include <machine/fdt.h> +#include <arm/broadcom/bcm2835/bcm2835_mbox.h> + +#define REG_READ 0x00 +#define REG_POL 0x10 +#define REG_SENDER 0x14 +#define REG_STATUS 0x18 +#define STATUS_FULL 0x80000000 +#define STATUS_EMPTY 0x40000000 +#define REG_CONFIG 0x1C +#define CONFIG_DATA_IRQ 0x00000001 +#define REG_WRITE 0x20 /* This is Mailbox 1 address */ + +#define MBOX_MSG(chan, data) (((data) & ~0xf) | ((chan) & 0xf)) +#define MBOX_CHAN(msg) ((msg) & 0xf) +#define MBOX_DATA(msg) ((msg) & ~0xf) + +#define MBOX_LOCK do { \ + mtx_lock(&bcm_mbox_sc->lock); \ +} while(0) + +#define MBOX_UNLOCK do { \ + mtx_unlock(&bcm_mbox_sc->lock); \ +} while(0) + +#ifdef DEBUG +#define dprintf(fmt, args...) printf(fmt, ##args) +#else +#define dprintf(fmt, args...) +#endif + +struct bcm_mbox_softc { + struct mtx lock; + struct resource * mem_res; + struct resource * irq_res; + void* intr_hl; + bus_space_tag_t bst; + bus_space_handle_t bsh; + int valid[BCM2835_MBOX_CHANS]; + int msg[BCM2835_MBOX_CHANS]; +}; + +static struct bcm_mbox_softc *bcm_mbox_sc = NULL; + +#define mbox_read_4(reg) \ + bus_space_read_4(bcm_mbox_sc->bst, bcm_mbox_sc->bsh, reg) +#define mbox_write_4(reg, val) \ + bus_space_write_4(bcm_mbox_sc->bst, bcm_mbox_sc->bsh, reg, val) + +static void +bcm_mbox_intr(void *arg) +{ + struct bcm_mbox_softc *sc = arg; + int chan; + uint32_t data; + uint32_t msg; + + MBOX_LOCK; + while (!(mbox_read_4(REG_STATUS) & STATUS_EMPTY)) { + msg = mbox_read_4(REG_READ); + dprintf("bcm_mbox_intr: raw data %08x\n", msg); + chan = MBOX_CHAN(msg); + data = MBOX_DATA(msg); + if (sc->valid[chan]) { + printf("bcm_mbox_intr: channel %d oveflow\n", chan); + continue; + } + dprintf("bcm_mbox_intr: chan %d, data %08x\n", chan, data); + sc->msg[chan] = data; + sc->valid[chan] = 1; + wakeup(&sc->msg[chan]); + + } + MBOX_UNLOCK; +} + +static int +bcm_mbox_probe(device_t dev) +{ + + if (ofw_bus_is_compatible(dev, "broadcom,bcm2835-mbox")) { + device_set_desc(dev, "BCM2835 VideoCore Mailbox"); + return(BUS_PROBE_DEFAULT); + } + + return (ENXIO); +} + +static int +bcm_mbox_attach(device_t dev) +{ + struct bcm_mbox_softc *sc = device_get_softc(dev); + int i; + int rid = 0; + + if (bcm_mbox_sc != NULL) + return (EINVAL); + + sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); + if (sc->mem_res == NULL) { + device_printf(dev, "could not allocate memory resource\n"); + return (ENXIO); + } + + sc->bst = rman_get_bustag(sc->mem_res); + sc->bsh = rman_get_bushandle(sc->mem_res); + + rid = 0; + sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); + if (sc->irq_res == NULL) { + device_printf(dev, "could not allocate interrupt resource\n"); + return (ENXIO); + } + + /* Setup and enable the timer */ + if (bus_setup_intr(dev, sc->irq_res, INTR_TYPE_MISC, + NULL, bcm_mbox_intr, sc, + &sc->intr_hl) != 0) { + bus_release_resource(dev, SYS_RES_IRQ, rid, + sc->irq_res); + device_printf(dev, "Unable to setup the clock irq handler.\n"); + return (ENXIO); + } + + mtx_init(&sc->lock, "vcio mbox", MTX_DEF, 0); + for (i = 0; i < BCM2835_MBOX_CHANS; i++) { + sc->valid[0] = 0; + sc->msg[0] = 0; + } + + bcm_mbox_sc = sc; + /* Read all pending messages */ + bcm_mbox_intr(sc); + + /* Should be called after bcm_mbox_sc initialization */ + mbox_write_4(REG_CONFIG, CONFIG_DATA_IRQ); + + return (0); +} + +static device_method_t bcm_mbox_methods[] = { + DEVMETHOD(device_probe, bcm_mbox_probe), + DEVMETHOD(device_attach, bcm_mbox_attach), + { 0, 0 } +}; + +static driver_t bcm_mbox_driver = { + "mbox", + bcm_mbox_methods, + sizeof(struct bcm_mbox_softc), +}; + +static devclass_t bcm_mbox_devclass; + +DRIVER_MODULE(mbox, simplebus, bcm_mbox_driver, bcm_mbox_devclass, 0, 0); + +/* + * Mailbox API + */ +int +bcm_mbox_write(int chan, uint32_t data) +{ + int limit = 20000; + + dprintf("bcm_mbox_write: chan %d, data %08x\n", chan, data); + MBOX_LOCK; + + while ((mbox_read_4(REG_STATUS) & STATUS_FULL) && limit--) { + DELAY(2); + } + + if (limit == 0) { + printf("bcm_mbox_write: STATUS_FULL stuck"); + MBOX_UNLOCK; + return (EAGAIN); + } + + mbox_write_4(REG_WRITE, MBOX_MSG(chan, data)); + + MBOX_UNLOCK; + return (0); +} + +int +bcm_mbox_read(int chan, uint32_t *data) +{ + struct bcm_mbox_softc *sc = bcm_mbox_sc; + + dprintf("bcm_mbox_read: chan %d\n", chan); + MBOX_LOCK; + while (!sc->valid[chan]) + msleep(&sc->msg[chan], &sc->lock, PZERO, "vcio mbox read", 0); + *data = bcm_mbox_sc->msg[chan]; + bcm_mbox_sc->valid[chan] = 0; + MBOX_UNLOCK; + dprintf("bcm_mbox_read: chan %d, data %08x\n", chan, *data); + + return (0); +} diff --git a/sys/arm/broadcom/bcm2835/bcm2835_mbox.h b/sys/arm/broadcom/bcm2835/bcm2835_mbox.h new file mode 100644 index 0000000..edb9d5b --- /dev/null +++ b/sys/arm/broadcom/bcm2835/bcm2835_mbox.h @@ -0,0 +1,44 @@ +/*- + * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org> + * 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. + * + * $FreeBSD$ + */ + +#ifndef _BCM2835_MBOX_H_ +#define _BCM2835_MBOX_H_ + +#define BCM2835_MBOX_CHAN_POWER 0 +#define BCM2835_MBOX_CHAN_FB 1 +#define BCM2835_MBOX_CHAN_VUART 2 +#define BCM2835_MBOX_CHAN_VCHIQ 3 +#define BCM2835_MBOX_CHAN_LEDS 4 +#define BCM2835_MBOX_CHAN_BUTTONS 5 +#define BCM2835_MBOX_CHAN_TS 6 +#define BCM2835_MBOX_CHANS 7 + +int bcm_mbox_write(int chan, uint32_t data); +int bcm_mbox_read(int chan, uint32_t *data); + +#endif /* _BCM2835_MBOX_H_ */ diff --git a/sys/arm/broadcom/bcm2835/bcm2835_systimer.c b/sys/arm/broadcom/bcm2835/bcm2835_systimer.c new file mode 100644 index 0000000..e027d52 --- /dev/null +++ b/sys/arm/broadcom/bcm2835/bcm2835_systimer.c @@ -0,0 +1,298 @@ +/*- + * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org> + * Copyright (c) 2012 Damjan Marion <dmarion@freebsd.org> + * 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/malloc.h> +#include <sys/rman.h> +#include <sys/timeet.h> +#include <sys/timetc.h> +#include <sys/watchdog.h> +#include <machine/bus.h> +#include <machine/cpu.h> +#include <machine/frame.h> +#include <machine/intr.h> + +#include <dev/fdt/fdt_common.h> +#include <dev/ofw/openfirm.h> +#include <dev/ofw/ofw_bus.h> +#include <dev/ofw/ofw_bus_subr.h> + +#include <machine/bus.h> +#include <machine/fdt.h> + +#define BCM2835_NUM_TIMERS 4 + +#define DEFAULT_TIMER 3 +#define DEFAULT_FREQUENCY 1000000 + +#define SYSTIMER_CS 0x00 +#define SYSTIMER_CLO 0x04 +#define SYSTIMER_CHI 0x08 +#define SYSTIMER_C0 0x0C +#define SYSTIMER_C1 0x10 +#define SYSTIMER_C2 0x14 +#define SYSTIMER_C3 0x18 + +struct systimer { + int index; + bool enabled; + struct eventtimer et; +}; + +struct bcm_systimer_softc { + struct resource* mem_res; + struct resource* irq_res[BCM2835_NUM_TIMERS]; + void* intr_hl[BCM2835_NUM_TIMERS]; + uint32_t sysclk_freq; + bus_space_tag_t bst; + bus_space_handle_t bsh; + struct systimer st[BCM2835_NUM_TIMERS]; +}; + +static struct resource_spec bcm_systimer_irq_spec[] = { + { SYS_RES_IRQ, 0, RF_ACTIVE }, + { SYS_RES_IRQ, 1, RF_ACTIVE }, + { SYS_RES_IRQ, 2, RF_ACTIVE }, + { SYS_RES_IRQ, 3, RF_ACTIVE }, + { -1, 0, 0 } +}; + +static struct bcm_systimer_softc *bcm_systimer_sc = NULL; + +/* Read/Write macros for Timer used as timecounter */ +#define bcm_systimer_tc_read_4(reg) \ + bus_space_read_4(bcm_systimer_sc->bst, \ + bcm_systimer_sc->bsh, reg) + +#define bcm_systimer_tc_write_4(reg, val) \ + bus_space_write_4(bcm_systimer_sc->bst, \ + bcm_systimer_sc->bsh, reg, val) + +static unsigned bcm_systimer_tc_get_timecount(struct timecounter *); + +static struct timecounter bcm_systimer_tc = { + .tc_name = "BCM2835 Timecouter", + .tc_get_timecount = bcm_systimer_tc_get_timecount, + .tc_poll_pps = NULL, + .tc_counter_mask = ~0u, + .tc_frequency = 0, + .tc_quality = 1000, +}; + +static unsigned +bcm_systimer_tc_get_timecount(struct timecounter *tc) +{ + return bcm_systimer_tc_read_4(SYSTIMER_CLO); +} + +static int +bcm_systimer_start(struct eventtimer *et, struct bintime *first, + struct bintime *period) +{ + struct systimer *st = et->et_priv; + uint32_t clo; + uint32_t count; + + if (first != NULL) { + st->enabled = 1; + + count = (st->et.et_frequency * (first->frac >> 32)) >> 32; + if (first->sec != 0) + count += st->et.et_frequency * first->sec; + + clo = bcm_systimer_tc_read_4(SYSTIMER_CLO); + clo += count; + bcm_systimer_tc_write_4(SYSTIMER_C0 + st->index*4, clo); + + return (0); + } + + return (EINVAL); +} + +static int +bcm_systimer_stop(struct eventtimer *et) +{ + struct systimer *st = et->et_priv; + st->enabled = 0; + + return (0); +} + +static int +bcm_systimer_intr(void *arg) +{ + struct systimer *st = (struct systimer *)arg; + + bcm_systimer_tc_write_4(SYSTIMER_CS, (1 << st->index)); + if (st->enabled) { + if (st->et.et_active) { + st->et.et_event_cb(&st->et, st->et.et_arg); + } + } + + return (FILTER_HANDLED); +} + +static int +bcm_systimer_probe(device_t dev) +{ + + if (ofw_bus_is_compatible(dev, "broadcom,bcm2835-system-timer")) { + device_set_desc(dev, "BCM2835 System Timer"); + return (BUS_PROBE_DEFAULT); + } + + return (ENXIO); +} + +static int +bcm_systimer_attach(device_t dev) +{ + struct bcm_systimer_softc *sc = device_get_softc(dev); + int err; + int rid = 0; + + if (bcm_systimer_sc != NULL) + return (EINVAL); + + sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); + if (sc->mem_res == NULL) { + device_printf(dev, "could not allocate memory resource\n"); + return (ENXIO); + } + + sc->bst = rman_get_bustag(sc->mem_res); + sc->bsh = rman_get_bushandle(sc->mem_res); + + /* Request the IRQ resources */ + err = bus_alloc_resources(dev, bcm_systimer_irq_spec, + sc->irq_res); + if (err) { + device_printf(dev, "Error: could not allocate irq resources\n"); + return (ENXIO); + } + + /* TODO: get frequency from FDT */ + sc->sysclk_freq = DEFAULT_FREQUENCY; + + /* Setup and enable the timer */ + if (bus_setup_intr(dev, sc->irq_res[DEFAULT_TIMER], INTR_TYPE_CLK, + bcm_systimer_intr, NULL, &sc->st[DEFAULT_TIMER], + &sc->intr_hl[DEFAULT_TIMER]) != 0) { + bus_release_resources(dev, bcm_systimer_irq_spec, + sc->irq_res); + device_printf(dev, "Unable to setup the clock irq handler.\n"); + return (ENXIO); + } + + sc->st[DEFAULT_TIMER].index = DEFAULT_TIMER; + sc->st[DEFAULT_TIMER].enabled = 0; + sc->st[DEFAULT_TIMER].et.et_name = malloc(64, M_DEVBUF, M_NOWAIT | M_ZERO); + sprintf(sc->st[DEFAULT_TIMER].et.et_name, "BCM2835 Event Timer %d", DEFAULT_TIMER); + sc->st[DEFAULT_TIMER].et.et_flags = ET_FLAGS_ONESHOT; + sc->st[DEFAULT_TIMER].et.et_quality = 1000; + sc->st[DEFAULT_TIMER].et.et_frequency = sc->sysclk_freq; + sc->st[DEFAULT_TIMER].et.et_min_period.sec = 0; + sc->st[DEFAULT_TIMER].et.et_min_period.frac = + ((0x00000002LLU << 32) / sc->st[DEFAULT_TIMER].et.et_frequency) << 32; + sc->st[DEFAULT_TIMER].et.et_max_period.sec = 0xfffffff0U / sc->st[DEFAULT_TIMER].et.et_frequency; + sc->st[DEFAULT_TIMER].et.et_max_period.frac = + ((0xfffffffeLLU << 32) / sc->st[DEFAULT_TIMER].et.et_frequency) << 32; + sc->st[DEFAULT_TIMER].et.et_start = bcm_systimer_start; + sc->st[DEFAULT_TIMER].et.et_stop = bcm_systimer_stop; + sc->st[DEFAULT_TIMER].et.et_priv = &sc->st[DEFAULT_TIMER]; + et_register(&sc->st[DEFAULT_TIMER].et); + + bcm_systimer_sc = sc; + + bcm_systimer_tc.tc_frequency = DEFAULT_FREQUENCY; + tc_init(&bcm_systimer_tc); + + return (0); +} + +static device_method_t bcm_systimer_methods[] = { + DEVMETHOD(device_probe, bcm_systimer_probe), + DEVMETHOD(device_attach, bcm_systimer_attach), + { 0, 0 } +}; + +static driver_t bcm_systimer_driver = { + "systimer", + bcm_systimer_methods, + sizeof(struct bcm_systimer_softc), +}; + +static devclass_t bcm_systimer_devclass; + +DRIVER_MODULE(bcm_systimer, simplebus, bcm_systimer_driver, bcm_systimer_devclass, 0, 0); + +void +cpu_initclocks(void) +{ + cpu_initclocks_bsp(); +} + +void +DELAY(int usec) +{ + int32_t counts; + uint32_t first, last; + + if (bcm_systimer_sc == NULL) { + for (; usec > 0; usec--) + for (counts = 200; counts > 0; counts--) + /* Prevent gcc from optimizing out the loop */ + cpufunc_nullop(); + return; + } + + /* Get the number of times to count */ + counts = usec * ((bcm_systimer_tc.tc_frequency / 1000000) + 1);; + + first = bcm_systimer_tc_read_4(SYSTIMER_CLO); + + while (counts > 0) { + last = bcm_systimer_tc_read_4(SYSTIMER_CLO); + if (last == first) + continue; + if (last>first) { + counts -= (int32_t)(last - first); + } else { + counts -= (int32_t)((0xFFFFFFFF - first) + last); + } + first = last; + } +} diff --git a/sys/arm/broadcom/bcm2835/bcm2835_vcbus.h b/sys/arm/broadcom/bcm2835/bcm2835_vcbus.h new file mode 100644 index 0000000..1d91046 --- /dev/null +++ b/sys/arm/broadcom/bcm2835/bcm2835_vcbus.h @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org> + * 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. + * + * $FreeBSD$ + */ + +/* + * Defines for converting physical address to VideoCore bus address and back + */ + +#ifndef _BCM2835_VCBUS_H_ +#define _BCM2835_VCBUS_H_ + +#define BCM2835_VCBUS_SDRAM_CACHED 0x40000000 +#define BCM2835_VCBUS_SDRAM_UNCACHED 0xC0000000 + +/* + * Convert physical address to VC bus address. Should be used + * when submitting address over mailbox interface + */ +#define PHYS_TO_VCBUS(pa) ((pa) + BCM2835_VCBUS_SDRAM_CACHED) + +/* + * Convert address from VC bus space to physical. Should be used + * when address is returned by VC over mailbox interface. e.g. + * framebuffer base + */ +#define VCBUS_TO_PHYS(vca) ((vca) - BCM2835_VCBUS_SDRAM_CACHED) + +#endif /* _BCM2835_VCBUS_H_ */ diff --git a/sys/arm/broadcom/bcm2835/bcm2835_wdog.c b/sys/arm/broadcom/bcm2835/bcm2835_wdog.c new file mode 100644 index 0000000..c8570cb --- /dev/null +++ b/sys/arm/broadcom/bcm2835/bcm2835_wdog.c @@ -0,0 +1,167 @@ +/*- + * Copyright (c) 2012 Alexander Rybalko <ray@freebsd.org> + * 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/watchdog.h> +#include <sys/bus.h> +#include <sys/kernel.h> +#include <sys/module.h> +#include <sys/rman.h> + +#include <dev/fdt/fdt_common.h> +#include <dev/ofw/openfirm.h> +#include <dev/ofw/ofw_bus.h> +#include <dev/ofw/ofw_bus_subr.h> + +#include <machine/bus.h> +#include <machine/cpufunc.h> +#include <machine/machdep.h> +#include <machine/fdt.h> + +#include <arm/broadcom/bcm2835/bcm2835_wdog.h> + +#define BCM2835_PASWORD 0x5a + +#define BCM2835_WDOG_RESET 0 +#define BCM2835_PASSWORD_MASK 0xff000000 +#define BCM2835_PASSWORD_SHIFT 24 +#define BCM2835_WDOG_TIME_MASK 0x000fffff +#define BCM2835_WDOG_TIME_SHIFT 0 + +#define READ(_sc, _r) bus_space_read_4((_sc)->bst, (_sc)->bsh, (_r)) +#define WRITE(_sc, _r, _v) bus_space_write_4((_sc)->bst, (_sc)->bsh, (_r), (_v)) + +#define BCM2835_RSTC_WRCFG_CLR 0xffffffcf +#define BCM2835_RSTC_WRCFG_SET 0x00000030 +#define BCM2835_RSTC_WRCFG_FULL_RESET 0x00000020 +#define BCM2835_RSTC_RESET 0x00000102 + +#define BCM2835_RSTC_REG 0x00 +#define BCM2835_RSTS_REG 0x04 +#define BCM2835_WDOG_REG 0x08 + +static struct bcmwd_softc *bcmwd_lsc = NULL; + +struct bcmwd_softc { + device_t dev; + struct resource * res; + bus_space_tag_t bst; + bus_space_handle_t bsh; + int wdog_armed; + int wdog_period; + char wdog_passwd; +}; + +#ifdef notyet +static void bcmwd_watchdog_fn(void *private, u_int cmd, int *error); +#endif + +static int +bcmwd_probe(device_t dev) +{ + + if (ofw_bus_is_compatible(dev, "broadcom,bcm2835-wdt")) { + device_set_desc(dev, "BCM2708/2835 Watchdog"); + return (BUS_PROBE_DEFAULT); + } + + return (ENXIO); +} + +static int +bcmwd_attach(device_t dev) +{ + struct bcmwd_softc *sc; + int rid; + + if (bcmwd_lsc != NULL) + return (ENXIO); + + sc = device_get_softc(dev); + sc->wdog_period = 7; + sc->wdog_passwd = BCM2835_PASWORD; + sc->wdog_armed = 0; + sc->dev = dev; + + rid = 0; + sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); + if (sc->res == NULL) { + device_printf(dev, "could not allocate memory resource\n"); + return (ENXIO); + } + + sc->bst = rman_get_bustag(sc->res); + sc->bsh = rman_get_bushandle(sc->res); + + bcmwd_lsc = sc; +#ifdef notyet + EVENTHANDLER_REGISTER(watchdog_list, bcmwd_watchdog_fn, sc, 0); +#endif + return (0); +} + +#ifdef notyet +static void +bcmwd_watchdog_fn(void *private, u_int cmd, int *error) +{ + /* XXX: not yet */ +} +#endif + +void +bcmwd_watchdog_reset() +{ + + if (bcmwd_lsc == NULL) + return; + + WRITE(bcmwd_lsc, BCM2835_WDOG_REG, + (BCM2835_PASWORD << BCM2835_PASSWORD_SHIFT) | 10); + + WRITE(bcmwd_lsc, BCM2835_RSTC_REG, + (READ(bcmwd_lsc, BCM2835_RSTC_REG) & BCM2835_RSTC_WRCFG_CLR) | + (BCM2835_PASWORD << BCM2835_PASSWORD_SHIFT) | + BCM2835_RSTC_WRCFG_FULL_RESET); +} + +static device_method_t bcmwd_methods[] = { + DEVMETHOD(device_probe, bcmwd_probe), + DEVMETHOD(device_attach, bcmwd_attach), + + DEVMETHOD_END +}; + +static driver_t bcmwd_driver = { + "bcmwd", + bcmwd_methods, + sizeof(struct bcmwd_softc), +}; +static devclass_t bcmwd_devclass; + +DRIVER_MODULE(bcmwd, simplebus, bcmwd_driver, bcmwd_devclass, 0, 0); diff --git a/sys/arm/broadcom/bcm2835/bcm2835_wdog.h b/sys/arm/broadcom/bcm2835/bcm2835_wdog.h new file mode 100644 index 0000000..55569d9 --- /dev/null +++ b/sys/arm/broadcom/bcm2835/bcm2835_wdog.h @@ -0,0 +1,32 @@ +/*- + * Copyright (c) 2012 Alexander Rybalko <ray@freebsd.org> + * 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. + * + * $FreeBSD$ + */ +#ifndef _BCM2835_WDOG_H_ +#define _BCM2835_WDOG_H_ + +void bcmwd_watchdog_reset(void); +#endif diff --git a/sys/arm/broadcom/bcm2835/bus_space.c b/sys/arm/broadcom/bcm2835/bus_space.c new file mode 100644 index 0000000..4cce820 --- /dev/null +++ b/sys/arm/broadcom/bcm2835/bus_space.c @@ -0,0 +1,113 @@ +/*- + * Copyright (C) 2012 FreeBSD Foundation + * 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. + * 3. Neither the name of MARVELL nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY 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 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/malloc.h> + +#include <machine/bus.h> + +/* Prototypes for all the bus_space structure functions */ +bs_protos(generic); +bs_protos(generic_armv4); + +struct bus_space _base_tag = { + /* cookie */ + .bs_cookie = (void *) 0, + + /* mapping/unmapping */ + .bs_map = generic_bs_map, + .bs_unmap = generic_bs_unmap, + .bs_subregion = generic_bs_subregion, + + /* allocation/deallocation */ + .bs_alloc = generic_bs_alloc, + .bs_free = generic_bs_free, + + /* barrier */ + .bs_barrier = generic_bs_barrier, + + /* read (single) */ + .bs_r_1 = generic_bs_r_1, + .bs_r_2 = generic_armv4_bs_r_2, + .bs_r_4 = generic_bs_r_4, + .bs_r_8 = NULL, + + /* read multiple */ + .bs_rm_1 = generic_bs_rm_1, + .bs_rm_2 = generic_armv4_bs_rm_2, + .bs_rm_4 = generic_bs_rm_4, + .bs_rm_8 = NULL, + + /* read region */ + .bs_rr_1 = generic_bs_rr_1, + .bs_rr_2 = generic_armv4_bs_rr_2, + .bs_rr_4 = generic_bs_rr_4, + .bs_rr_8 = NULL, + + /* write (single) */ + .bs_w_1 = generic_bs_w_1, + .bs_w_2 = generic_armv4_bs_w_2, + .bs_w_4 = generic_bs_w_4, + .bs_w_8 = NULL, + + /* write multiple */ + .bs_wm_1 = generic_bs_wm_1, + .bs_wm_2 = generic_armv4_bs_wm_2, + .bs_wm_4 = generic_bs_wm_4, + .bs_wm_8 = NULL, + + /* write region */ + .bs_wr_1 = generic_bs_wr_1, + .bs_wr_2 = generic_armv4_bs_wr_2, + .bs_wr_4 = generic_bs_wr_4, + .bs_wr_8 = NULL, + + /* set multiple */ + /* XXX not implemented */ + + /* set region */ + .bs_sr_1 = NULL, + .bs_sr_2 = generic_armv4_bs_sr_2, + .bs_sr_4 = generic_bs_sr_4, + .bs_sr_8 = NULL, + + /* copy */ + .bs_c_1 = NULL, + .bs_c_2 = generic_armv4_bs_c_2, + .bs_c_4 = NULL, + .bs_c_8 = NULL, +}; + +bus_space_tag_t fdtbus_bs_tag = &_base_tag; diff --git a/sys/arm/broadcom/bcm2835/common.c b/sys/arm/broadcom/bcm2835/common.c new file mode 100644 index 0000000..5c3c258 --- /dev/null +++ b/sys/arm/broadcom/bcm2835/common.c @@ -0,0 +1,75 @@ +/*- + * Copyright (C) 2008-2011 MARVELL INTERNATIONAL LTD. + * All rights reserved. + * + * Developed by Semihalf. + * + * 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. + * 3. Neither the name of MARVELL nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY 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 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 "opt_global.h" + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/bus.h> +#include <sys/kernel.h> +#include <sys/malloc.h> +#include <sys/kdb.h> +#include <sys/reboot.h> + +#include <dev/fdt/fdt_common.h> +#include <dev/ofw/openfirm.h> + +#include <machine/bus.h> +#include <machine/fdt.h> +#include <machine/vmparam.h> + +struct fdt_fixup_entry fdt_fixup_table[] = { + { NULL, NULL } +}; + +static int +fdt_intc_decode_ic(phandle_t node, pcell_t *intr, int *interrupt, int *trig, + int *pol) +{ + + if (!fdt_is_compatible(node, "broadcom,bcm2835-armctrl-ic")) + return (ENXIO); + + *interrupt = fdt32_to_cpu(intr[0]); + *trig = INTR_TRIGGER_CONFORM; + *pol = INTR_POLARITY_CONFORM; + + return (0); +} + + +fdt_pic_decode_t fdt_pic_table[] = { + &fdt_intc_decode_ic, + NULL +}; diff --git a/sys/arm/broadcom/bcm2835/files.bcm2835 b/sys/arm/broadcom/bcm2835/files.bcm2835 new file mode 100644 index 0000000..827ae90 --- /dev/null +++ b/sys/arm/broadcom/bcm2835/files.bcm2835 @@ -0,0 +1,19 @@ +# $FreeBSD$ + +arm/broadcom/bcm2835/bcm2835_fb.c optional sc +arm/broadcom/bcm2835/bcm2835_intr.c standard +arm/broadcom/bcm2835/bcm2835_machdep.c standard +arm/broadcom/bcm2835/bcm2835_mbox.c standard +arm/broadcom/bcm2835/bcm2835_systimer.c standard +arm/broadcom/bcm2835/bcm2835_wdog.c standard +arm/broadcom/bcm2835/bus_space.c optional fdt +arm/broadcom/bcm2835/common.c optional fdt + +arm/arm/bus_space_generic.c standard +arm/arm/bus_space_asm_generic.S standard +arm/arm/cpufunc_asm_arm11.S standard +arm/arm/cpufunc_asm_armv5.S standard +arm/arm/cpufunc_asm_armv6.S standard +arm/arm/irq_dispatch.S standard + +kern/kern_clocksource.c standard diff --git a/sys/arm/conf/RPI-B b/sys/arm/conf/RPI-B new file mode 100644 index 0000000..6c4bce7 --- /dev/null +++ b/sys/arm/conf/RPI-B @@ -0,0 +1,101 @@ +# RPI-B -- Custom configuration for the Raspberry Pi +# +# For more information on this file, please read the handbook section on +# Kernel Configuration Files: +# +# http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig-config.html +# +# The handbook is also available locally in /usr/share/doc/handbook +# if you've installed the doc distribution, otherwise always see the +# FreeBSD World Wide Web server (http://www.FreeBSD.org/) for the +# latest information. +# +# An exhaustive list of options and more detailed explanations of the +# device lines is also present in the ../../conf/NOTES and NOTES files. +# If you are in doubt as to the purpose or necessity of a line, check first +# in NOTES. +# +# $FreeBSD$ + +ident RPI-B +machine arm armv6 +cpu CPU_ARM11 + +files "../broadcom/bcm2835/files.bcm2835" +makeoptions MODULES_OVERRIDE="" + +options KERNVIRTADDR=0xc0100000 +makeoptions KERNVIRTADDR=0xc0100000 +options KERNPHYSADDR=0x00100000 +makeoptions KERNPHYSADDR=0x00100000 +options PHYSADDR=0x00000000 +options STARTUP_PAGETABLE_ADDR=0x01000000 + +makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols +options HZ=100 + +options SCHED_4BSD #4BSD scheduler +options INET #InterNETworking +options FFS #Berkeley Fast Filesystem +options SOFTUPDATES #Enable FFS soft updates support +options UFS_ACL #Support for access control lists +options UFS_DIRHASH #Improve performance on big directories +device snp + +# options NFSCL #Network Filesystem Client +# options NFS_ROOT #NFS usable as /, requires NFSCLIENT +# options BOOTP_NFSROOT +# options BOOTP_COMPAT +# options BOOTP +# options BOOTP_NFSV3 +# options BOOTP_WIRED_TO=ue0 + +options PSEUDOFS #Pseudo-filesystem framework +options COMPAT_43 #Compatible with BSD 4.3 [KEEP THIS!] +options SCSI_DELAY=5000 #Delay (in ms) before probing SCSI +options KTRACE #ktrace(1) support +options SYSVSHM #SYSV-style shared memory +options SYSVMSG #SYSV-style message queues +options SYSVSEM #SYSV-style semaphores +options _KPOSIX_PRIORITY_SCHEDULING #Posix P1003_1B real-time extensions +options KBD_INSTALL_CDEV # install a CDEV entry in /dev + +options PREEMPTION + +device bpf +device loop +device ether +device uart +device pl011 + +device pty + +# NOTE: serial console will be disabled if syscons enabled +# Uncomment following lines for framebuffer/syscons support +# device sc +# device kbdmux +# options SC_DFLT_FONT # compile font in +# makeoptions SC_DFLT_FONT=cp437 + +options KDB +options DDB #Enable the kernel debugger +options INVARIANTS #Enable calls of extra sanity checking +options INVARIANT_SUPPORT #Extra sanity checks of internal structures, required by INVARIANTS + +device md +device random # Entropy device + +# Not yet: USB support +# device usb +# options USB_DEBUG + + +# Not yet: USB Ethernet support, requires miibus +# device mii +# device smc +# device smcphy + +# Flattened Device Tree +options FDT +options FDT_DTB_STATIC +makeoptions FDT_DTS_FILE=bcm2835-rpi-b.dts |