diff options
author | tobhe <tobhe@cvs.openbsd.org> | 2020-04-19 14:51:53 +0000 |
---|---|---|
committer | tobhe <tobhe@cvs.openbsd.org> | 2020-04-19 14:51:53 +0000 |
commit | c96c108bcd88088f9321a743ff19d5907682e66c (patch) | |
tree | 72aa7c632811cb502ee13eaceca7b0243bd3f6d3 /sys/dev | |
parent | 6b8c8bf0fd25360abd0c16c2ee6a5d114aa79a98 (diff) |
Add bcmmbox, a driver for the VideoCore messagebox interface on BCM283X.
Original work by Neil Ashford and dlg@
Feedback from jsg@
ok kettenis@, dlg@
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/fdt/bcm2835_mbox.c | 313 | ||||
-rw-r--r-- | sys/dev/fdt/files.fdt | 6 | ||||
-rw-r--r-- | sys/dev/ic/bcm2835_mbox.h | 100 | ||||
-rw-r--r-- | sys/dev/ic/bcm2835_vcprop.h | 409 |
4 files changed, 827 insertions, 1 deletions
diff --git a/sys/dev/fdt/bcm2835_mbox.c b/sys/dev/fdt/bcm2835_mbox.c new file mode 100644 index 00000000000..1fb756843be --- /dev/null +++ b/sys/dev/fdt/bcm2835_mbox.c @@ -0,0 +1,313 @@ +/* $OpenBSD: bcm2835_mbox.c,v 1.1 2020/04/19 14:51:52 tobhe Exp $ */ + +/* + * Copyright (c) 2020 Tobias Heider <tobhe@openbsd.org> + * Copyright (c) 2019 Neil Ashford <ashfordneil0@gmail.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Nick Hudson + * + * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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/types.h> +#include <sys/systm.h> + +#include <machine/bus.h> +#include <machine/fdt.h> +#include <machine/intr.h> + +#include <dev/ofw/fdt.h> +#include <dev/ofw/openfirm.h> + +#include <dev/ic/bcm2835_mbox.h> +#include <dev/ic/bcm2835_vcprop.h> + +#define DEVNAME(sc) ((sc)->sc_dev.dv_xname) + +struct cfdriver bcmmbox_cd = { NULL, "bcmmbox", DV_DULL }; + +struct bcmmbox_softc { + struct device sc_dev; + bus_space_tag_t sc_iot; + bus_space_handle_t sc_ioh; + + bus_dma_tag_t sc_dmat; + bus_dmamap_t sc_dmamap; + + void *sc_ih; + + struct mutex sc_lock; + struct mutex sc_intr_lock; + int sc_chan[BCMMBOX_NUM_CHANNELS]; + uint32_t sc_mbox[BCMMBOX_NUM_CHANNELS]; +}; + +static struct bcmmbox_softc *bcmmbox_sc; + +int bcmmbox_match(struct device *, void *, void *); +void bcmmbox_attach(struct device *, struct device *, void *); + +struct cfattach bcmmbox_ca = { + sizeof(struct bcmmbox_softc), + bcmmbox_match, + bcmmbox_attach, +}; + +uint32_t bcmmbox_reg_read(struct bcmmbox_softc *, int); +void bcmmbox_reg_write(struct bcmmbox_softc *, int, uint32_t); +void bcmmbox_reg_flush(struct bcmmbox_softc *, int); +int bcmmbox_intr(void *); +int bcmmbox_intr_helper(struct bcmmbox_softc *, int); + +int +bcmmbox_match(struct device *parent, void *match, void *aux) +{ + struct fdt_attach_args *faa = aux; + + return OF_is_compatible(faa->fa_node, "brcm,bcm2835-mbox"); +} + +void +bcmmbox_attach(struct device *parent, struct device *self, void *aux) +{ + struct bcmmbox_softc *sc = (struct bcmmbox_softc *)self; + struct fdt_attach_args *faa = aux; + bus_addr_t addr; + bus_size_t size; + + if (bcmmbox_sc) { + printf(": a similar device as already attached\n"); + return; + } + bcmmbox_sc = sc; + + mtx_init(&sc->sc_lock, IPL_NONE); + mtx_init(&sc->sc_intr_lock, IPL_VM); + + if (faa->fa_nreg < 1) { + printf(": no registers\n"); + return; + } + + addr = faa->fa_reg[0].addr; + size = faa->fa_reg[0].size; + + sc->sc_dmat = faa->fa_dmat; + sc->sc_iot = faa->fa_iot; + if (bus_space_map(sc->sc_iot, addr, size, 0, &sc->sc_ioh)) { + printf(": can't map registers\n"); + return; + } + + if (bus_dmamap_create(sc->sc_dmat, ~0UL, 1, ~0UL, 0, + BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW, &sc->sc_dmamap) != 0) { + printf(": unable to create dma map\n"); + goto clean_bus_space_map; + } + + sc->sc_ih = fdt_intr_establish(faa->fa_node, IPL_VM, bcmmbox_intr, sc, + DEVNAME(sc)); + if (sc->sc_ih == NULL) { + printf(": failed to establish interrupt\n"); + goto clean_dmamap; + } + + /* enable interrupt in hardware */ + bcmmbox_reg_write(sc, BCMMBOX_CFG, BCMMBOX_CFG_DATA_IRQ_EN); + + printf("\n"); + + bcmmbox_write(BCMMBOX_CHANPM, ( + (1 << VCPROP_POWER_SDCARD) | + (1 << VCPROP_POWER_UART0) | + (1 << VCPROP_POWER_USB) | + (1 << VCPROP_POWER_I2C0) | + (1 << VCPROP_POWER_I2C1) | + (1 << VCPROP_POWER_SPI) | + 0) << 4); + + return; + + clean_dmamap: + bus_dmamap_destroy(sc->sc_dmat, sc->sc_dmamap); + + clean_bus_space_map: + bus_space_unmap(sc->sc_iot, sc->sc_ioh, size); +} + +uint32_t +bcmmbox_reg_read(struct bcmmbox_softc *sc, int addr) +{ + return bus_space_read_4(sc->sc_iot, sc->sc_ioh, addr); +} + +void +bcmmbox_reg_write(struct bcmmbox_softc *sc, int addr, uint32_t val) +{ + bus_space_write_4(sc->sc_iot, sc->sc_ioh, addr, val); +} + +void +bcmmbox_reg_flush(struct bcmmbox_softc *sc, int flags) +{ + bus_space_barrier(sc->sc_iot, sc->sc_ioh, 0, BCMMBOX_SIZE, flags); +} + +int +bcmmbox_intr(void *cookie) +{ + struct bcmmbox_softc *sc = cookie; + int ret; + + mtx_enter(&sc->sc_intr_lock); + ret = bcmmbox_intr_helper(sc, 1); + mtx_leave(&sc->sc_intr_lock); + + return ret; +} + +int +bcmmbox_intr_helper(struct bcmmbox_softc *sc, int broadcast) +{ + uint32_t mbox, chan, data; + int ret = 0; + + bcmmbox_reg_flush(sc, BUS_SPACE_BARRIER_READ); + + while (!ISSET(bcmmbox_reg_read(sc, BCMMBOX_STATUS), BCMMBOX_STATUS_EMPTY)) { + mbox = bcmmbox_reg_read(sc, BCMMBOX0_READ); + + chan = mbox & BCMMBOX_CHANNEL_MASK; + data = mbox & ~BCMMBOX_CHANNEL_MASK; + ret = 1; + + if ((sc->sc_mbox[chan] & BCMMBOX_CHANNEL_MASK) != 0) { + printf("%s: chan %d overflow\n", DEVNAME(sc), chan); + continue; + } + + sc->sc_mbox[chan] = data | BCMMBOX_CHANNEL_MASK; + + if (broadcast) + wakeup(&sc->sc_chan[chan]); + } + + return ret; +} + +void +bcmmbox_read(uint8_t chan, uint32_t *data) +{ + struct bcmmbox_softc *sc = bcmmbox_sc; + uint32_t mbox, rchan, rdata, status; + + KASSERT(sc != NULL); + KASSERT(chan == (chan & BCMMBOX_CHANNEL_MASK)); + + while (1) { + bcmmbox_reg_flush(sc, BUS_SPACE_BARRIER_READ); + status = bcmmbox_reg_read(sc, BCMMBOX0_STATUS); + if (ISSET(status, BCMMBOX_STATUS_EMPTY)) + continue; + + mbox = bcmmbox_reg_read(sc, BCMMBOX0_READ); + + rchan = mbox & BCMMBOX_CHANNEL_MASK; + rdata = mbox & ~BCMMBOX_CHANNEL_MASK; + + if (rchan == chan) { + *data = rdata; + return; + } + } +} + +void +bcmmbox_write(uint8_t chan, uint32_t data) +{ + struct bcmmbox_softc *sc = bcmmbox_sc; + uint32_t rdata; + + KASSERT(sc != NULL); + KASSERT(chan == (chan & BCMMBOX_CHANNEL_MASK)); + KASSERT(data == (data & ~BCMMBOX_CHANNEL_MASK)); + + while (1) { + bcmmbox_reg_flush(sc, BUS_SPACE_BARRIER_READ); + rdata = bcmmbox_reg_read(sc, BCMMBOX0_STATUS); + if (!ISSET(rdata, BCMMBOX_STATUS_FULL)) + break; + } + + bcmmbox_reg_write(sc, BCMMBOX1_WRITE, chan | data); + bcmmbox_reg_flush(sc, BUS_SPACE_BARRIER_WRITE); +} + +int +bcmmbox_post(uint8_t chan, void *buf, size_t len, uint32_t *res) +{ + struct bcmmbox_softc *sc = bcmmbox_sc; + bus_dmamap_t map; + int error; + + KASSERT(sc != NULL); + if (sc == NULL) + return (ENXIO); + + map = sc->sc_dmamap; + + error = bus_dmamap_load(sc->sc_dmat, map, buf, len, NULL, + BUS_DMA_NOWAIT | BUS_DMA_READ | BUS_DMA_WRITE); + if (error != 0) + return (error); + + bus_dmamap_sync(sc->sc_dmat, map, 0, len, + BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); + + bcmmbox_write(chan, map->dm_segs[0].ds_addr); + bcmmbox_read(chan, res); + + bus_dmamap_sync(sc->sc_dmat, map, 0, len, + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); + + bus_dmamap_unload(sc->sc_dmat, map); + + return (0); +} diff --git a/sys/dev/fdt/files.fdt b/sys/dev/fdt/files.fdt index 45cb91e0cbc..e83a84585c1 100644 --- a/sys/dev/fdt/files.fdt +++ b/sys/dev/fdt/files.fdt @@ -1,4 +1,4 @@ -# $OpenBSD: files.fdt,v 1.119 2020/04/19 09:20:45 kettenis Exp $ +# $OpenBSD: files.fdt,v 1.120 2020/04/19 14:51:52 tobhe Exp $ # # Config file and device description for machine-independent FDT code. # Included by ports that need it. @@ -85,6 +85,10 @@ device bcmdog attach bcmdog at fdt file dev/fdt/bcm2835_dog.c bcmdog +device bcmmbox +attach bcmmbox at fdt +file dev/fdt/bcm2835_mbox.c bcmmbox + device bcmpcie: pcibus attach bcmpcie at fdt file dev/fdt/bcm2711_pcie.c bcmpcie diff --git a/sys/dev/ic/bcm2835_mbox.h b/sys/dev/ic/bcm2835_mbox.h new file mode 100644 index 00000000000..cdd5a4a437d --- /dev/null +++ b/sys/dev/ic/bcm2835_mbox.h @@ -0,0 +1,100 @@ +/* $OpenBSD: bcm2835_mbox.h,v 1.1 2020/04/19 14:51:52 tobhe Exp $ */ + +/* + * Copyright (c) 2020 Tobias Heider <tobhe@openbsd.org> + * Copyright (c) 2019 Neil Ashford <ashfordneil0@gmail.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Nick Hudson + * + * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#ifndef BCM2835_MBOX_H +#define BCM2835_MBOX_H + +#define BCMMBOX_NUM_CHANNELS 16 +#define BCMMBOX_CHANNEL_MASK 0xf + +/* mailbox 0 (from VC) and mailbox 1 (to VC) */ +#define BCMMBOX_SIZE 0x80 + +#define BCMMBOX_READ 0x00 +#define BCMMBOX_WRITE 0x00 +#define BCMMBOX_POLL 0x10 /* read without popping the fifo */ +#define BCMMBOX_ID 0x14 /* sender ID (bottom two bits) */ +#define BCMMBOX_STATUS 0x18 /* status */ +#define BCMMBOX_STATUS_FULL 0x80000000 +#define BCMMBOX_STATUS_EMPTY 0x40000000 +#define BCMMBOX_STATUS_LEVEL 0x400000FF +#define BCMMBOX_CFG 0x1C /* configuration */ +#define BCMMBOX_CFG_DATA_IRQ_EN 0x00000001 +#define BCMMBOX_CFG_SPACE_IRQ_EN 0x00000002 +#define BCMMBOX_CFG_EMPTYOP_IRQ_EN 0x00000004 +#define BCMMBOX_CFG_MAIL_CLEAR 0x00000008 +#define BCMMBOX_CFG_DATA_PENDING 0x00000010 +#define BCMMBOX_CFG_SPACE_PENDING 0x00000020 +#define BCMMBOX_CFG_EMPTY_OP_PENDING 0x00000040 +#define BCMMBOX_CFG_E_NO_OWN 0x00000100 +#define BCMMBOX_CFG_E_OVERFLOW 0x00000200 +#define BCMMBOX_CFG_E_UNDERFLOW 0x00000400 + +#define BCMMBOX0_BASE 0x00 +#define BCMMBOX1_BASE 0x20 + +#define BCMMBOX0_READ (BCMMBOX0_BASE + BCMMBOX_READ) +#define BCMMBOX0_WRITE (BCMMBOX0_BASE + BCMMBOX_WRITE) +#define BCMMBOX0_POLL (BCMMBOX0_BASE + BCMMBOX_POLL) +#define BCMMBOX0_ID (BCMMBOX0_BASE + BCMMBOX_ID) +#define BCMMBOX0_STATUS (BCMMBOX0_BASE + BCMMBOX_STATUS) +#define BCMMBOX0_CFG (BCMMBOX0_BASE + BCMMBOX_READ) + +#define BCMMBOX1_READ (BCMMBOX1_BASE + BCMMBOX_READ) +#define BCMMBOX1_WRITE (BCMMBOX1_BASE + BCMMBOX_WRITE) +#define BCMMBOX1_POLL (BCMMBOX1_BASE + BCMMBOX_POLL) +#define BCMMBOX1_ID (BCMMBOX1_BASE + BCMMBOX_ID) +#define BCMMBOX1_STATUS (BCMMBOX1_BASE + BCMMBOX_STATUS) +#define BCMMBOX1_CFG (BCMMBOX1_BASE + BCMMBOX_READ) + +void bcmmbox_read(uint8_t chan, uint32_t *data); +void bcmmbox_write(uint8_t chan, uint32_t data); + +int bcmmbox_post(uint8_t, void *, size_t, uint32_t *); + +#endif /* BCM2835_MBOX_H */ diff --git a/sys/dev/ic/bcm2835_vcprop.h b/sys/dev/ic/bcm2835_vcprop.h new file mode 100644 index 00000000000..c0ddfe54026 --- /dev/null +++ b/sys/dev/ic/bcm2835_vcprop.h @@ -0,0 +1,409 @@ +/* $OpenBSD: bcm2835_vcprop.h,v 1.1 2020/04/19 14:51:52 tobhe Exp $ */ + +/* + * Copyright (c) 2020 Tobias Heider <tobhe@openbsd.org> + * Copyright (c) 2019 Neil Ashford <ashfordneil0@gmail.com> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Nick Hudson + * + * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +/* + * Mailbox property interface + */ + +#ifndef BCM2835_VCPROP_H +#define BCM2835_VCPROP_H + +struct vcprop_tag { + uint32_t vpt_tag; +#define VCPROPTAG_NULL 0x00000000 +#define VCPROPTAG_GET_FIRMWAREREV 0x00000001 +#define VCPROPTAG_GET_BOARDMODEL 0x00010001 +#define VCPROPTAG_GET_BOARDREVISION 0x00010002 +#define VCPROPTAG_GET_MACADDRESS 0x00010003 +#define VCPROPTAG_GET_BOARDSERIAL 0x00010004 +#define VCPROPTAG_GET_ARMMEMORY 0x00010005 +#define VCPROPTAG_GET_VCMEMORY 0x00010006 +#define VCPROPTAG_GET_CLOCKS 0x00010007 + +#define VCPROPTAG_GET_POWERSTATE 0x00020001 +#define VCPROPTAG_GET_POWERTIMING 0x00020002 +#define VCPROPTAG_SET_POWERSTATE 0x00028001 + +#define VCPROPTAG_GET_CLOCKSTATE 0x00030001 +#define VCPROPTAG_SET_CLOCKSTATE 0x00038001 +#define VCPROPTAG_GET_CLOCKRATE 0x00030002 +#define VCPROPTAG_SET_CLOCKRATE 0x00038002 +#define VCPROPTAG_GET_MIN_CLOCKRATE 0x00030007 +#define VCPROPTAG_GET_MAX_CLOCKRATE 0x00030004 +#define VCPROPTAG_GET_TURBO 0x00030009 +#define VCPROPTAG_SET_TURBO 0x00038009 + +#define VCPROPTAG_GET_VOLTAGE 0x00030003 +#define VCPROPTAG_SET_VOLTAGE 0x00038003 +#define VCPROPTAG_GET_MIN_VOLTAGE 0x00030008 +#define VCPROPTAG_GET_MAX_VOLTAGE 0x00030005 + +#define VCPROPTAG_GET_TEMPERATURE 0x00030006 +#define VCPROPTAG_GET_MAX_TEMPERATURE 0x0003000a + +#define VCPROPTAG_GET_CMDLINE 0x00050001 +#define VCPROPTAG_GET_DMACHAN 0x00060001 + +#define VCPROPTAG_ALLOCATE_BUFFER 0x00040001 +#define VCPROPTAG_BLANK_SCREEN 0x00040002 +#define VCPROPTAG_GET_FB_RES 0x00040003 +#define VCPROPTAG_SET_FB_RES 0x00048003 +#define VCPROPTAG_GET_FB_VRES 0x00040004 +#define VCPROPTAG_SET_FB_VRES 0x00048004 +#define VCPROPTAG_GET_FB_DEPTH 0x00040005 +#define VCPROPTAG_SET_FB_DEPTH 0x00048005 +#define VCPROPTAG_GET_FB_PIXEL_ORDER 0x00040006 +#define VCPROPTAG_SET_FB_PIXEL_ORDER 0x00048006 +#define VCPROPTAG_GET_FB_ALPHA_MODE 0x00040007 +#define VCPROPTAG_SET_FB_ALPHA_MODE 0x00048007 +#define VCPROPTAG_GET_FB_PITCH 0x00040008 + +#define VCPROPTAG_GET_EDID_BLOCK 0x00030020 + +#define VCPROPTAG_ALLOCMEM 0x0003000c +#define VCPROPTAG_LOCKMEM 0x0003000d +#define VCPROPTAG_UNLOCKMEM 0x0003000e +#define VCPROPTAG_RELEASEMEM 0x0003000f +#define VCPROPTAG_EXECUTE_CODE 0x00030010 +#define VCPROPTAG_EXECUTE_QPU 0x00030011 +#define VCPROPTAG_SET_ENABLE_QPU 0x00030012 +#define VCPROPTAG_GET_DISPMANX_HANDLE 0x00030014 + +#define VCPROPTAG_SET_CURSOR_INFO 0x00008010 +#define VCPROPTAG_SET_CURSOR_STATE 0x00008011 + + uint32_t vpt_len; + uint32_t vpt_rcode; +#define VCPROPTAG_REQUEST (0U << 31) +#define VCPROPTAG_RESPONSE (1U << 31) + +} __packed; + +#define VCPROPTAG_LEN(x) (sizeof((x)) - sizeof(struct vcprop_tag)) + +struct vcprop_memory { + uint32_t base; + uint32_t size; +}; + +#define VCPROP_MAXMEMBLOCKS 4 +struct vcprop_tag_memory { + struct vcprop_tag tag; + struct vcprop_memory mem[VCPROP_MAXMEMBLOCKS]; +}; + +struct vcprop_tag_fwrev { + struct vcprop_tag tag; + uint32_t rev; +}; + +struct vcprop_tag_boardmodel { + struct vcprop_tag tag; + uint32_t model; +}; + +struct vcprop_tag_boardrev { + struct vcprop_tag tag; + uint32_t rev; +}; +#define VCPROP_REV_PCBREV 15 +#define VCPROP_REV_MODEL (255 << 4) +#define RPI_MODEL_A 0 +#define RPI_MODEL_B 1 +#define RPI_MODEL_A_PLUS 2 +#define RPI_MODEL_B_PLUS 3 +#define RPI_MODEL_B_PI2 4 +#define RPI_MODEL_ALPHA 5 +#define RPI_MODEL_COMPUTE 6 +#define RPI_MODEL_ZERO 7 +#define RPI_MODEL_B_PI3 8 +#define RPI_MODEL_COMPUTE_PI3 9 +#define RPI_MODEL_ZERO_W 10 +#define VCPROP_REV_PROCESSOR (15 << 12) +#define RPI_PROCESSOR_BCM2835 0 +#define RPI_PROCESSOR_BCM2836 1 +#define RPI_PROCESSOR_BCM2837 2 +#define VCPROP_REV_MANUF (15 << 16) +#define VCPROP_REV_MEMSIZE (7 << 20) +#define VCPROP_REV_ENCFLAG (1 << 23) +#define VCPROP_REV_WARRANTY (3 << 24) + +struct vcprop_tag_macaddr { + struct vcprop_tag tag; + uint64_t addr; +} __packed; + +struct vcprop_tag_boardserial { + struct vcprop_tag tag; + uint64_t sn; +} __packed; + +#define VCPROP_CLK_EMMC 1 +#define VCPROP_CLK_UART 2 +#define VCPROP_CLK_ARM 3 +#define VCPROP_CLK_CORE 4 +#define VCPROP_CLK_V3D 5 +#define VCPROP_CLK_H264 6 +#define VCPROP_CLK_ISP 7 +#define VCPROP_CLK_SDRAM 8 +#define VCPROP_CLK_PIXEL 9 +#define VCPROP_CLK_PWM 10 +#define VCPROP_CLK_EMMC2 12 + +struct vcprop_clock { + uint32_t pclk; + uint32_t cclk; +}; + +#define VCPROP_MAXCLOCKS 16 +struct vcprop_tag_clock { + struct vcprop_tag tag; + struct vcprop_clock clk[VCPROP_MAXCLOCKS]; +}; + +#ifndef VCPROP_MAXCMDLINE +#define VCPROP_MAXCMDLINE 1024 +#endif +struct vcprop_tag_cmdline { + struct vcprop_tag tag; + uint8_t cmdline[VCPROP_MAXCMDLINE]; +}; + +struct vcprop_tag_dmachan { + struct vcprop_tag tag; + uint32_t mask; +}; + +struct vcprop_tag_clockstate { + struct vcprop_tag tag; + uint32_t id; + uint32_t state; +}; + +struct vcprop_tag_clockrate { + struct vcprop_tag tag; + uint32_t id; + uint32_t rate; + uint32_t noturbo; +} __packed; + +#define VCPROP_VOLTAGE_CORE 1 +#define VCPROP_VOLTAGE_SDRAM_C 2 +#define VCPROP_VOLTAGE_SDRAM_P 3 +#define VCPROP_VOLTAGE_SDRAM_I 4 + +struct vcprop_tag_voltage { + struct vcprop_tag tag; + uint32_t id; + uint32_t value; +}; + +#define VCPROP_TEMP_SOC 0 + +struct vcprop_tag_temperature { + struct vcprop_tag tag; + uint32_t id; + uint32_t value; +}; + +#define VCPROP_POWER_SDCARD 0 +#define VCPROP_POWER_UART0 1 +#define VCPROP_POWER_UART1 2 +#define VCPROP_POWER_USB 3 +#define VCPROP_POWER_I2C0 4 +#define VCPROP_POWER_I2C1 5 +#define VCPROP_POWER_I2C2 6 +#define VCPROP_POWER_SPI 7 +#define VCPROP_POWER_CCP2TX 8 + +struct vcprop_tag_powertiming { + struct vcprop_tag tag; + uint32_t id; + uint32_t waitusec; +}; + +struct vcprop_tag_powerstate { + struct vcprop_tag tag; + uint32_t id; + uint32_t state; +}; + +struct vcprop_tag_allocbuf { + struct vcprop_tag tag; + uint32_t address; /* alignment for request */ + uint32_t size; +}; + +#define VCPROP_BLANK_OFF 0 +#define VCPROP_BLANK_ON 1 + +struct vcprop_tag_blankscreen { + struct vcprop_tag tag; + uint32_t state; +}; + +struct vcprop_tag_fbres { + struct vcprop_tag tag; + uint32_t width; + uint32_t height; +}; + +struct vcprop_tag_fbdepth { + struct vcprop_tag tag; + uint32_t bpp; +}; + +#define VCPROP_PIXEL_BGR 0 +#define VCPROP_PIXEL_RGB 1 + +struct vcprop_tag_fbpixelorder { + struct vcprop_tag tag; + uint32_t state; +}; + +struct vcprop_tag_fbpitch { + struct vcprop_tag tag; + uint32_t linebytes; +}; + +#define VCPROP_ALPHA_ENABLED 0 +#define VCPROP_ALPHA_REVERSED 1 +#define VCPROP_ALPHA_IGNORED 2 + +struct vcprop_tag_fbalpha { + struct vcprop_tag tag; + uint32_t state; +}; + +struct vcprop_tag_edidblock { + struct vcprop_tag tag; + uint32_t blockno; + uint32_t status; + uint8_t data[128]; +}; + +struct vcprop_tag_cursorinfo { + struct vcprop_tag tag; + uint32_t width; + uint32_t height; + uint32_t format; + uint32_t pixels; /* bus address in VC memory */ + uint32_t hotspot_x; + uint32_t hotspot_y; +}; + +struct vcprop_tag_cursorstate { + struct vcprop_tag tag; + uint32_t enable; /* 1 - visible */ + uint32_t x; + uint32_t y; + uint32_t flags; /* 0 - display coord. 1 - fb coord. */ +}; + +struct vcprop_tag_allocmem { + struct vcprop_tag tag; + uint32_t size; /* handle returned here */ + uint32_t align; + uint32_t flags; +/* + * flag definitions from + * https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface + */ +#define MEM_FLAG_DISCARDABLE (1 << 0) /* can be resized to 0 at any time. Use for cached data */ +#define MEM_FLAG_NORMAL (0 << 2) /* normal allocating alias. Don't use from ARM */ +#define MEM_FLAG_DIRECT (1 << 2) /* 0xC alias uncached */ +#define MEM_FLAG_COHERENT (2 << 2) /* 0x8 alias. Non-allocating in L2 but coherent */ +#define MEM_FLAG_L1_NONALLOCATING (MEM_FLAG_DIRECT | MEM_FLAG_COHERENT) /* Allocating in L2 */ +#define MEM_FLAG_ZERO (1 << 4) /* initialise buffer to all zeros */ +#define MEM_FLAG_NO_INIT (1 << 5) /* don't initialise (default is initialise to all ones */ +#define MEM_FLAG_HINT_PERMALOCK (1 << 6) /* Likely to be locked for long periods of time. */ +}; + +/* also for unlock and release */ +struct vcprop_tag_lockmem { + struct vcprop_tag tag; + uint32_t handle; /* bus address returned here */ +}; + +struct vcprop_buffer_hdr { + uint32_t vpb_len; + uint32_t vpb_rcode; +#define VCPROP_PROCESS_REQUEST 0 +#define VCPROP_REQ_SUCCESS (1U << 31) +#define VCPROP_REQ_EPARSE (1U << 0) +} __packed; + +static inline bool +vcprop_buffer_success_p(struct vcprop_buffer_hdr *vpbh) +{ + return (vpbh->vpb_rcode & VCPROP_REQ_SUCCESS); +} + +static inline bool +vcprop_tag_success_p(struct vcprop_tag *vpbt) +{ + return (vpbt->vpt_rcode & VCPROPTAG_RESPONSE); +} + +static inline size_t +vcprop_tag_resplen(struct vcprop_tag *vpbt) +{ + return (vpbt->vpt_rcode & ~VCPROPTAG_RESPONSE); +} + +#define BCMMBOX_CHANPM 0 +#define BCMMBOX_CHANFB 1 /* will be deprecated */ +#define BCMMBOX_CHANVUART 2 +#define BCMMBOX_CHANVCHIQ 3 +#define BCMMBOX_CHANLEDS 4 +#define BCMMBOX_CHANBUTTONS 5 +#define BCMMBOX_CHANTOUCHSCR 6 +#define BCMMBOX_CHANARM2VC 8 +#define BCMMBOX_CHANVC2ARM 9 + +#endif /* BCM2835_VCPROP_H */ |