Module Name: src
Committed By: riz
Date: Mon Nov 19 19:13:01 UTC 2012
Modified Files:
src/sys/arch/arm/broadcom [netbsd-6]: bcm2835_emmc.c bcm2835reg.h
files.bcm2835
src/sys/arch/evbarm/rpi [netbsd-6]: rpi_machdep.c rpi_start.S
Added Files:
src/sys/arch/arm/broadcom [netbsd-6]: bcm2835_mbox.h
bcm2835_mbox_subr.c bcm2835_mboxreg.h
src/sys/arch/evbarm/rpi [netbsd-6]: vcio.h vcprop.h
Log Message:
sys/arch/arm/broadcom/bcm2835_emmc.c patch
sys/arch/arm/broadcom/bcm2835reg.h patch
sys/arch/arm/broadcom/bcm2835_mbox.h 1.1-1.3 via patch
sys/arch/arm/broadcom/bcm2835_mbox_subr.c 1.1-1.3 via patch
sys/arch/arm/broadcom/bcm2835_mboxreg.h 1.1 via patch
sys/arch/arm/broadcom/files.bcm2835 patch
sys/arch/evbarm/rpi/rpi_machdep.c patch
sys/arch/evbarm/rpi/rpi_start.S patch
sys/arch/evbarm/rpi/vcio.h 1.1 via patch
sys/arch/evbarm/rpi/vcprop.h 1.1-1.2 via patch
Improve Raspberry PI support: memory layout and clock for the
sdhc(4) controller are queried via the mailbox properties
channel.
[skrll, ticket #660]
To generate a diff of this commit:
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 src/sys/arch/arm/broadcom/bcm2835_emmc.c \
src/sys/arch/arm/broadcom/bcm2835reg.h \
src/sys/arch/arm/broadcom/files.bcm2835
cvs rdiff -u -r0 -r1.3.4.2 src/sys/arch/arm/broadcom/bcm2835_mbox.h \
src/sys/arch/arm/broadcom/bcm2835_mbox_subr.c
cvs rdiff -u -r0 -r1.1.6.2 src/sys/arch/arm/broadcom/bcm2835_mboxreg.h
cvs rdiff -u -r1.3.2.2 -r1.3.2.3 src/sys/arch/evbarm/rpi/rpi_machdep.c
cvs rdiff -u -r1.2.2.2 -r1.2.2.3 src/sys/arch/evbarm/rpi/rpi_start.S
cvs rdiff -u -r0 -r1.1.4.2 src/sys/arch/evbarm/rpi/vcio.h
cvs rdiff -u -r0 -r1.2.2.2 src/sys/arch/evbarm/rpi/vcprop.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/arm/broadcom/bcm2835_emmc.c
diff -u src/sys/arch/arm/broadcom/bcm2835_emmc.c:1.1.2.2 src/sys/arch/arm/broadcom/bcm2835_emmc.c:1.1.2.3
--- src/sys/arch/arm/broadcom/bcm2835_emmc.c:1.1.2.2 Thu Aug 9 06:36:49 2012
+++ src/sys/arch/arm/broadcom/bcm2835_emmc.c Mon Nov 19 19:12:57 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: bcm2835_emmc.c,v 1.1.2.2 2012/08/09 06:36:49 jdc Exp $ */
+/* $NetBSD: bcm2835_emmc.c,v 1.1.2.3 2012/11/19 19:12:57 riz Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_emmc.c,v 1.1.2.2 2012/08/09 06:36:49 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_emmc.c,v 1.1.2.3 2012/11/19 19:12:57 riz Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -77,7 +77,9 @@ static void
bcmemmc_attach(device_t parent, device_t self, void *aux)
{
struct bcmemmc_softc *sc = device_private(self);
+ prop_dictionary_t dict = device_properties(self);
struct amba_attach_args *aaa = aux;
+ prop_number_t frequency;
int error;
sc->sc.sc_dev = self;
@@ -88,9 +90,15 @@ bcmemmc_attach(device_t parent, device_t
sc->sc.sc_flags |= SDHC_FLAG_HOSTCAPS;
sc->sc.sc_caps = SDHC_VOLTAGE_SUPP_3_3V;
sc->sc.sc_host = sc->sc_hosts;
- sc->sc.sc_clkbase = 50000; /* 50MHz */
+ sc->sc.sc_clkbase = 50000; /* Default to 50MHz */
sc->sc_iot = aaa->aaa_iot;
+ /* Fetch the EMMC clock frequency from property if set. */
+ frequency = prop_dictionary_get(dict, "frequency");
+ if (frequency != NULL) {
+ sc->sc.sc_clkbase = prop_number_integer_value(frequency) / 1000;
+ }
+
error = bus_space_map(sc->sc_iot, aaa->aaa_addr, aaa->aaa_size, 0,
&sc->sc_ioh);
if (error) {
@@ -107,7 +115,7 @@ bcmemmc_attach(device_t parent, device_t
if (sc->sc_ih == NULL) {
aprint_error_dev(self, "failed to establish interrupt %d\n",
- aaa->aaa_intr);
+ aaa->aaa_intr);
goto fail;
}
aprint_normal_dev(self, "interrupting on intr %d\n", aaa->aaa_intr);
Index: src/sys/arch/arm/broadcom/bcm2835reg.h
diff -u src/sys/arch/arm/broadcom/bcm2835reg.h:1.1.2.2 src/sys/arch/arm/broadcom/bcm2835reg.h:1.1.2.3
--- src/sys/arch/arm/broadcom/bcm2835reg.h:1.1.2.2 Thu Aug 9 06:36:50 2012
+++ src/sys/arch/arm/broadcom/bcm2835reg.h Mon Nov 19 19:12:59 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: bcm2835reg.h,v 1.1.2.2 2012/08/09 06:36:50 jdc Exp $ */
+/* $NetBSD: bcm2835reg.h,v 1.1.2.3 2012/11/19 19:12:59 riz Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -65,6 +65,9 @@
#define BCM2835_ARMICU_BASE (BCM2835_ARM_BASE + 0x0200)
#define BCM2835_ARMICU_SIZE 0x200
+#define BCM2835_ARMMBOX_BASE (BCM2835_ARM_BASE + 0x0880)
+#define BCM2835_ARMMBOX_SIZE 0x40
+
#define BCM2835_ARMICU_VBASE BCM2835_IOPHYSTOVIRT(BCM2835_ARMICU_BASE)
#define BCM2835_INTC_BASE (0x0) /* Relative to BCM2835_ARMICU_BASE */
Index: src/sys/arch/arm/broadcom/files.bcm2835
diff -u src/sys/arch/arm/broadcom/files.bcm2835:1.1.2.2 src/sys/arch/arm/broadcom/files.bcm2835:1.1.2.3
--- src/sys/arch/arm/broadcom/files.bcm2835:1.1.2.2 Thu Aug 9 06:36:50 2012
+++ src/sys/arch/arm/broadcom/files.bcm2835 Mon Nov 19 19:12:59 2012
@@ -1,4 +1,4 @@
-# $NetBSD: files.bcm2835,v 1.1.2.2 2012/08/09 06:36:50 jdc Exp $
+# $NetBSD: files.bcm2835,v 1.1.2.3 2012/11/19 19:12:59 riz Exp $
#
# Configuration info for Broadcom BCM2835 ARM Peripherals
#
@@ -7,6 +7,7 @@ include "arch/arm/pic/files.pic"
file arch/arm/arm32/irq_dispatch.S
file arch/arm/broadcom/bcm2835_dma.c
+file arch/arm/broadcom/bcm2835_mbox_subr.c
# Memory size in megabytes
defparam opt_broadcom.h MEMSIZE
Index: src/sys/arch/evbarm/rpi/rpi_machdep.c
diff -u src/sys/arch/evbarm/rpi/rpi_machdep.c:1.3.2.2 src/sys/arch/evbarm/rpi/rpi_machdep.c:1.3.2.3
--- src/sys/arch/evbarm/rpi/rpi_machdep.c:1.3.2.2 Thu Aug 9 06:36:51 2012
+++ src/sys/arch/evbarm/rpi/rpi_machdep.c Mon Nov 19 19:12:59 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: rpi_machdep.c,v 1.3.2.2 2012/08/09 06:36:51 jdc Exp $ */
+/* $NetBSD: rpi_machdep.c,v 1.3.2.3 2012/11/19 19:12:59 riz Exp $ */
/*
* Copyright (c) 2002, 2003, 2005 Genetec Corporation. All rights reserved.
@@ -122,7 +122,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rpi_machdep.c,v 1.3.2.2 2012/08/09 06:36:51 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rpi_machdep.c,v 1.3.2.3 2012/11/19 19:12:59 riz Exp $");
#include "opt_evbarm_boardtype.h"
#include "opt_broadcom.h"
@@ -143,11 +143,17 @@ __KERNEL_RCSID(0, "$NetBSD: rpi_machdep.
#include <arm/arm32/machdep.h>
#include <machine/vmparam.h>
+#include <machine/autoconf.h>
#include <machine/bootconfig.h>
#include <machine/pmap.h>
+#include <arm/broadcom/bcm2835reg.h>
#include <arm/broadcom/bcm2835var.h>
#include <arm/broadcom/bcm2835_pmvar.h>
+#include <arm/broadcom/bcm2835_mbox.h>
+
+#include <evbarm/rpi/vcio.h>
+#include <evbarm/rpi/vcprop.h>
#include <evbarm/rpi/rpi.h>
@@ -160,6 +166,8 @@ __KERNEL_RCSID(0, "$NetBSD: rpi_machdep.
#include "ksyms.h"
static void setup_real_page_tables(void);
+static void rpi_bootparams(void);
+static void rpi_device_register(device_t, void *);
/*
* Address to call from cpu_reset() to reset the machine.
@@ -204,6 +212,9 @@ extern char __data_start[], _edata[];
extern char __bss_start[], __bss_end__[];
extern char _end[];
+extern int KERNEL_BASE_phys[];
+extern int KERNEL_BASE_virt[];
+
#define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
#define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
#define KERNEL_PT_KERNEL_NUM 4
@@ -219,11 +230,10 @@ pv_addr_t kernel_pt_table[NUM_KERNEL_PTS
* Macros to translate between physical and virtual for a subset of the
* kernel address space. *Not* for general use.
*/
-#define KERNEL_BASE_PHYS physical_start
-#define KERN_VTOPHYS(va) \
- ((paddr_t)((vaddr_t)va - KERNEL_BASE + KERNEL_BASE_PHYS))
-#define KERN_PHYSTOV(pa) \
- ((vaddr_t)((paddr_t)pa - KERNEL_BASE_PHYS + KERNEL_BASE))
+
+#define KERN_VTOPDIFF ((vaddr_t)KERNEL_BASE_phys - (vaddr_t)KERNEL_BASE_virt)
+#define KERN_VTOPHYS(va) ((paddr_t)((vaddr_t)va + KERN_VTOPDIFF))
+#define KERN_PHYSTOV(pa) ((vaddr_t)((paddr_t)pa - KERN_VTOPDIFF))
#define PLCONADDR 0x20201000
@@ -305,6 +315,151 @@ cpu_reboot(int howto, char *bootstr)
/*NOTREACHED*/
}
+/* Smallest amount of RAM start.elf could give us. */
+#define RPI_MINIMUM_SPLIT (128U * 1024 * 1024)
+
+static struct {
+ struct vcprop_buffer_hdr vb_hdr;
+ struct vcprop_tag_fwrev vbt_fwrev;
+ struct vcprop_tag_boardmodel vbt_boardmodel;
+ struct vcprop_tag_boardrev vbt_boardrev;
+ struct vcprop_tag_macaddr vbt_macaddr;
+ struct vcprop_tag_memory vbt_memory;
+ struct vcprop_tag_boardserial vbt_serial;
+ struct vcprop_tag_cmdline vbt_cmdline;
+ struct vcprop_tag_clockrate vbt_emmcclockrate;
+ struct vcprop_tag end;
+} vb __packed __aligned(16) =
+{
+ .vb_hdr = {
+ .vpb_len = sizeof(vb),
+ .vpb_rcode = VCPROP_PROCESS_REQUEST,
+ },
+ .vbt_fwrev = {
+ .tag = {
+ .vpt_tag = VCPROPTAG_GET_FIRMWAREREV,
+ .vpt_len = VCPROPTAG_LEN(vb.vbt_fwrev),
+ .vpt_rcode = VCPROPTAG_REQUEST
+ },
+ },
+ .vbt_boardmodel = {
+ .tag = {
+ .vpt_tag = VCPROPTAG_GET_BOARDMODEL,
+ .vpt_len = VCPROPTAG_LEN(vb.vbt_boardmodel),
+ .vpt_rcode = VCPROPTAG_REQUEST
+ },
+ },
+ .vbt_boardrev = {
+ .tag = {
+ .vpt_tag = VCPROPTAG_GET_BOARDREVISION,
+ .vpt_len = VCPROPTAG_LEN(vb.vbt_boardrev),
+ .vpt_rcode = VCPROPTAG_REQUEST
+ },
+ },
+ .vbt_macaddr = {
+ .tag = {
+ .vpt_tag = VCPROPTAG_GET_MACADDRESS,
+ .vpt_len = VCPROPTAG_LEN(vb.vbt_macaddr),
+ .vpt_rcode = VCPROPTAG_REQUEST
+ },
+ },
+ .vbt_memory = {
+ .tag = {
+ .vpt_tag = VCPROPTAG_GET_ARMMEMORY,
+ .vpt_len = VCPROPTAG_LEN(vb.vbt_memory),
+ .vpt_rcode = VCPROPTAG_REQUEST
+ },
+ },
+ .vbt_serial = {
+ .tag = {
+ .vpt_tag = VCPROPTAG_GET_BOARDSERIAL,
+ .vpt_len = VCPROPTAG_LEN(vb.vbt_serial),
+ .vpt_rcode = VCPROPTAG_REQUEST
+ },
+ },
+ .vbt_cmdline = {
+ .tag = {
+ .vpt_tag = VCPROPTAG_GET_CMDLINE,
+ .vpt_len = VCPROPTAG_LEN(vb.vbt_cmdline),
+ .vpt_rcode = VCPROPTAG_REQUEST
+ },
+ },
+ .vbt_emmcclockrate = {
+ .tag = {
+ .vpt_tag = VCPROPTAG_GET_CLOCKRATE,
+ .vpt_len = VCPROPTAG_LEN(vb.vbt_emmcclockrate),
+ .vpt_rcode = VCPROPTAG_REQUEST
+ },
+ .id = VCPROP_CLK_EMMC
+ },
+ .end = {
+ .vpt_tag = VCPROPTAG_NULL
+ }
+};
+
+static void
+rpi_bootparams(void)
+{
+ bus_space_tag_t iot = &bcm2835_bs_tag;
+ bus_space_handle_t ioh = BCM2835_IOPHYSTOVIRT(BCM2835_ARMMBOX_BASE);
+ uint32_t res;
+
+ bcm2835_mbox_write(iot, ioh, BCMMBOX_CHANARM2VC, KERN_VTOPHYS(&vb));
+
+ bcm2835_mbox_read(iot, ioh, BCMMBOX_CHANARM2VC, &res);
+
+ /*
+ * No need to invalid the cache as the memory has never been referenced
+ * by the ARM.
+ *
+ * cpu_dcache_inv_range((vaddr_t)&vb, sizeof(vb));
+ *
+ */
+
+ if (!vcprop_buffer_success_p(&vb.vb_hdr)) {
+ bootconfig.dramblocks = 1;
+ bootconfig.dram[0].address = 0x0;
+ bootconfig.dram[0].pages = atop(RPI_MINIMUM_SPLIT);
+ return;
+ }
+
+ struct vcprop_tag_memory *vptp_mem = &vb.vbt_memory;
+
+ if (vcprop_tag_success_p(&vptp_mem->tag)) {
+ size_t n = vcprop_tag_resplen(&vptp_mem->tag) /
+ sizeof(struct vcprop_memory);
+
+ bootconfig.dramblocks = 0;
+
+ for (int i = 0; i < n && i < DRAM_BLOCKS; i++) {
+ bootconfig.dram[i].address = vptp_mem->mem[i].base;
+ bootconfig.dram[i].pages = atop(vptp_mem->mem[i].size);
+ bootconfig.dramblocks++;
+ }
+ }
+
+#ifdef VERBOSE_INIT_ARM
+ if (vcprop_tag_success_p(&vb.vbt_fwrev.tag))
+ printf("%s: firmware rev %x\n", __func__,
+ vb.vbt_fwrev.rev);
+ if (vcprop_tag_success_p(&vb.vbt_macaddr.tag))
+ printf("%s: mac-address %llx\n", __func__,
+ vb.vbt_macaddr.addr);
+ if (vcprop_tag_success_p(&vb.vbt_boardmodel.tag))
+ printf("%s: board model %x\n", __func__,
+ vb.vbt_boardmodel.model);
+ if (vcprop_tag_success_p(&vb.vbt_boardrev.tag))
+ printf("%s: board rev %x\n", __func__,
+ vb.vbt_boardrev.rev);
+ if (vcprop_tag_success_p(&vb.vbt_serial.tag))
+ printf("%s: board serial %llx\n", __func__,
+ vb.vbt_serial.sn);
+ if (vcprop_tag_success_p(&vb.vbt_cmdline.tag))
+ printf("%s: cmdline %s\n", __func__,
+ vb.vbt_cmdline.cmdline);
+#endif
+}
+
/*
* Static device mappings. These peripheral registers are mapped at
* fixed virtual addresses very early in initarm() so that we can use
@@ -384,20 +539,18 @@ initarm(void *arg)
#define _BDSTR(s) #s
printf("\nNetBSD/evbarm (" BDSTR(EVBARM_BOARDTYPE) ") booting ...\n");
- bootargs[0] = '\0';
+ boot_args = bootargs;
+ rpi_bootparams();
#ifdef VERBOSE_INIT_ARM
printf("initarm: Configuring system ...\n");
#endif
bootconfig.dramblocks = 1;
- physical_end = (MEMSIZE * 1024 * 1024); /* MEMSIZE */
- physmem = physical_end / PAGE_SIZE;
+ physical_end = bootconfig.dram[0].pages * PAGE_SIZE;
+ physmem = bootconfig.dram[0].pages;
physical_start = 0;
- bootconfig.dram[0].address = 0x0;
- bootconfig.dram[0].pages = physmem;
-
/*
* Our kernel is at the beginning of memory, so set our free space to
* all the memory after the kernel.
@@ -546,6 +699,9 @@ initarm(void *arg)
Debugger();
#endif
+ /* we've a specific device_register routine */
+ evbarm_device_register = rpi_device_register;
+
/* We return the new stack pointer address */
return kernelstack.pv_va + USPACE_SVC_STACK_TOP;
}
@@ -827,3 +983,15 @@ setup_real_page_tables(void)
printf("OK.\n");
#endif
}
+
+static void
+rpi_device_register(device_t dev, void *aux)
+{
+ prop_dictionary_t dict = device_properties(dev);
+
+ if (device_is_a(dev, "sdhc") &&
+ vcprop_tag_success_p(&vb.vbt_emmcclockrate.tag)) {
+ prop_dictionary_set_uint32(dict,
+ "frequency", vb.vbt_emmcclockrate.rate);
+ }
+}
Index: src/sys/arch/evbarm/rpi/rpi_start.S
diff -u src/sys/arch/evbarm/rpi/rpi_start.S:1.2.2.2 src/sys/arch/evbarm/rpi/rpi_start.S:1.2.2.3
--- src/sys/arch/evbarm/rpi/rpi_start.S:1.2.2.2 Thu Aug 9 06:36:51 2012
+++ src/sys/arch/evbarm/rpi/rpi_start.S Mon Nov 19 19:13:01 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: rpi_start.S,v 1.2.2.2 2012/08/09 06:36:51 jdc Exp $ */
+/* $NetBSD: rpi_start.S,v 1.2.2.3 2012/11/19 19:13:01 riz Exp $ */
/*
* Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved.
@@ -88,7 +88,7 @@
#include <arm/armreg.h>
#include "assym.h"
-RCSID("$NetBSD: rpi_start.S,v 1.2.2.2 2012/08/09 06:36:51 jdc Exp $")
+RCSID("$NetBSD: rpi_start.S,v 1.2.2.3 2012/11/19 19:13:01 riz Exp $")
/*
* Workaround Erratum 411920
@@ -171,6 +171,7 @@ _C_LABEL(rpi_start):
bhi 2b
3: ldmia itable!, {va,pa,n_sec,attr}
+ mov n_sec, n_sec, lsr #L1_S_SHIFT
/* Convert va to l1 offset: va = 4 * (va >> L1_S_SHIFT) */
mov va, va, LSR #L1_S_SHIFT
mov va, va, LSL #2
@@ -253,8 +254,8 @@ Ll1_s_frame:
.word L1_S_FRAME
Ltemp_l1_table:
- /* Put the temporary L1 translation table at the end of SDRAM. */
- .word 0x00000000 + MEMSIZE * 0x100000 - L1_TABLE_SIZE
+ /* Put the temporary L1 translation table just below the kernel. */
+ .word 0x4000
Lstart:
.word start
@@ -305,16 +306,16 @@ Lctl_ID_dis:
mmu_init_table:
/* Add 1MB of VA==PA at 0x00000000 so we can keep the kernel going */
MMU_INIT(0x00000000, 0x00000000,
- (MEMSIZE * L1_S_SIZE + L1_S_SIZE - 1) / L1_S_SIZE,
+ (_end - KERNEL_BASE + 2 * L1_S_SIZE - 1),
L1_S_PROTO | L1_S_AP_KRW)
MMU_INIT(KERNEL_BASE, 0x0,
- (MEMSIZE * L1_S_SIZE + L1_S_SIZE - 1) / L1_S_SIZE,
+ (_end - KERNEL_BASE + 2 * L1_S_SIZE - 1),
L1_S_PROTO | L1_S_AP_KRW | L1_S_B | L1_S_C)
/* Map the 16MB of peripherals */
MMU_INIT(RPI_KERNEL_IO_VBASE, RPI_KERNEL_IO_PBASE,
- (RPI_KERNEL_IO_VSIZE + L1_S_SIZE - 1) / L1_S_SIZE,
+ (RPI_KERNEL_IO_VSIZE + L1_S_SIZE - 1),
L1_S_PROTO | L1_S_AP_KRW)
/* end of table */
Added files:
Index: src/sys/arch/arm/broadcom/bcm2835_mbox.h
diff -u /dev/null src/sys/arch/arm/broadcom/bcm2835_mbox.h:1.3.4.2
--- /dev/null Mon Nov 19 19:13:02 2012
+++ src/sys/arch/arm/broadcom/bcm2835_mbox.h Mon Nov 19 19:12:58 2012
@@ -0,0 +1,45 @@
+/* $NetBSD: bcm2835_mbox.h,v 1.3.4.2 2012/11/19 19:12:58 riz Exp $ */
+
+/*-
+ * 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_
+
+#include <sys/bus.h>
+
+void bcm2835_mbox_read(bus_space_tag_t, bus_space_handle_t, uint8_t,
+ uint32_t *);
+void bcm2835_mbox_write(bus_space_tag_t, bus_space_handle_t, uint8_t,
+ uint32_t);
+
+void bcmmbox_read(uint8_t, uint32_t *);
+void bcmmbox_write(uint8_t, uint32_t);
+
+#endif /* _BCM2835_MBOX_H_ */
Index: src/sys/arch/arm/broadcom/bcm2835_mbox_subr.c
diff -u /dev/null src/sys/arch/arm/broadcom/bcm2835_mbox_subr.c:1.3.4.2
--- /dev/null Mon Nov 19 19:13:02 2012
+++ src/sys/arch/arm/broadcom/bcm2835_mbox_subr.c Mon Nov 19 19:12:58 2012
@@ -0,0 +1,107 @@
+/* $NetBSD: bcm2835_mbox_subr.c,v 1.3.4.2 2012/11/19 19:12:58 riz Exp $ */
+
+/*-
+ * 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/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_mbox_subr.c,v 1.3.4.2 2012/11/19 19:12:58 riz Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/kernel.h>
+#include <sys/timetc.h>
+#include <sys/bus.h>
+
+#include <arm/broadcom/bcm_amba.h>
+#include <arm/broadcom/bcm2835_mbox.h>
+#include <arm/broadcom/bcm2835_mboxreg.h>
+#include <arm/broadcom/bcm2835reg.h>
+
+
+#define BCM2835_MBOX_CHAN(chan) ((chan) & 0xf)
+#define BCM2835_MBOX_DATA(data) ((data) & ~0xf)
+
+#define BCM2835_MBOX_MSG(chan, data) (((chan) & 0xf) | ((data) & ~0xf))
+
+void
+bcm2835_mbox_read(bus_space_tag_t iot, bus_space_handle_t ioh, uint8_t chan,
+ uint32_t *data)
+{
+ uint32_t mbox;
+
+ KASSERT((chan & 0xf) == chan);
+
+ for (;;) {
+ uint8_t rchan;
+ uint32_t rdata;
+
+ bus_space_barrier(iot, ioh, 0, BCM2835_MBOX_SIZE,
+ BUS_SPACE_BARRIER_READ);
+
+ if ((bus_space_read_4(iot, ioh,
+ BCM2835_MBOX0_STATUS) & BCM2835_MBOX_STATUS_EMPTY) != 0)
+ continue;
+
+ mbox = bus_space_read_4(iot, ioh, BCM2835_MBOX0_READ);
+
+ rchan = BCM2835_MBOX_CHAN(mbox);
+ rdata = BCM2835_MBOX_DATA(mbox);
+
+ if (rchan == chan) {
+ *data = rdata;
+ return;
+ }
+ }
+}
+
+void
+bcm2835_mbox_write(bus_space_tag_t iot, bus_space_handle_t ioh, uint8_t chan,
+ uint32_t data)
+{
+ uint32_t rdata;
+
+ KASSERT((chan & 0xf) == chan);
+ KASSERT((data & 0xf) == 0);
+ for (;;) {
+
+ bus_space_barrier(iot, ioh, 0, BCM2835_MBOX_SIZE,
+ BUS_SPACE_BARRIER_READ);
+
+ if ((rdata = bus_space_read_4(iot, ioh,
+ BCM2835_MBOX0_STATUS) & BCM2835_MBOX_STATUS_FULL) == 0)
+ break;
+ }
+
+ bus_space_write_4(iot, ioh, BCM2835_MBOX1_WRITE,
+ BCM2835_MBOX_MSG(chan, data));
+
+ bus_space_barrier(iot, ioh, 0, BCM2835_MBOX_SIZE,
+ BUS_SPACE_BARRIER_WRITE);
+}
Index: src/sys/arch/arm/broadcom/bcm2835_mboxreg.h
diff -u /dev/null src/sys/arch/arm/broadcom/bcm2835_mboxreg.h:1.1.6.2
--- /dev/null Mon Nov 19 19:13:02 2012
+++ src/sys/arch/arm/broadcom/bcm2835_mboxreg.h Mon Nov 19 19:12:59 2012
@@ -0,0 +1,75 @@
+/* $NetBSD: bcm2835_mboxreg.h,v 1.1.6.2 2012/11/19 19:12:59 riz Exp $ */
+
+/*-
+ * 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_MBOXREG_H_
+#define _BCM2835_MBOXREG_H_
+
+/* mailbox 0 (from VC) and mailbox 1 (to VC) */
+#define BCM2835_MBOX_SIZE 0x80
+
+#define BCM2835_MBOX_READ 0x00
+#define BCM2835_MBOX_WRITE 0x00
+#define BCM2835_MBOX_POLL 0x10 /* read without popping the fifo */
+#define BCM2835_MBOX_ID 0x14 /* sender ID (bottom two bits) */
+#define BCM2835_MBOX_STATUS 0x18 /* status */
+#define BCM2835_MBOX_STATUS_FULL 0x80000000
+#define BCM2835_MBOX_STATUS_EMPTY 0x40000000
+#define BCM2835_MBOX_STATUS_LEVEL 0x400000FF
+#define BCM2835_MBOX_CFG 0x1C /* configuration */
+#define BCM2835_MBOX_CFG_DATAIRQEN 0x00000001
+#define BCM2835_MBOX_CFG_SPACEIRQEN 0x00000002
+#define BCM2835_MBOX_CFG_EMPTYOPIRQEN 0x00000004
+#define BCM2835_MBOX_CFG_MAILCLEAR 0x00000008
+#define BCM2835_MBOX_CFG_DATAPENDING 0x00000010
+#define BCM2835_MBOX_CFG_SPACEPENDING 0x00000020
+#define BCM2835_MBOX_CFG_EMPTYOPPENDING 0x00000040
+#define BCM2835_MBOX_CFG_ENOOWN 0x00000100
+#define BCM2835_MBOX_CFG_EOVERFLOW 0x00000200
+#define BCM2835_MBOX_CFG_EUNDERFLOW 0x00000400
+
+#define BCM2835_MBOX0_BASE 0x00
+#define BCM2835_MBOX1_BASE 0x20
+
+#define BCM2835_MBOX0_READ (BCM2835_MBOX0_BASE + BCM2835_MBOX_READ)
+#define BCM2835_MBOX0_WRITE (BCM2835_MBOX0_BASE + BCM2835_MBOX_WRITE)
+#define BCM2835_MBOX0_POLL (BCM2835_MBOX0_BASE + BCM2835_MBOX_POLL)
+#define BCM2835_MBOX0_ID (BCM2835_MBOX0_BASE + BCM2835_MBOX_ID)
+#define BCM2835_MBOX0_STATUS (BCM2835_MBOX0_BASE + BCM2835_MBOX_STATUS)
+#define BCM2835_MBOX0_CFG (BCM2835_MBOX0_BASE + BCM2835_MBOX_READ)
+
+#define BCM2835_MBOX1_READ (BCM2835_MBOX1_BASE + BCM2835_MBOX_READ)
+#define BCM2835_MBOX1_WRITE (BCM2835_MBOX1_BASE + BCM2835_MBOX_WRITE)
+#define BCM2835_MBOX1_POLL (BCM2835_MBOX1_BASE + BCM2835_MBOX_POLL)
+#define BCM2835_MBOX1_ID (BCM2835_MBOX1_BASE + BCM2835_MBOX_ID)
+#define BCM2835_MBOX1_STATUS (BCM2835_MBOX1_BASE + BCM2835_MBOX_STATUS)
+#define BCM2835_MBOX1_CFG (BCM2835_MBOX1_BASE + BCM2835_MBOX_READ)
+
+#endif /* _BCM2835_MBOXREG_H_ */
Index: src/sys/arch/evbarm/rpi/vcio.h
diff -u /dev/null src/sys/arch/evbarm/rpi/vcio.h:1.1.4.2
--- /dev/null Mon Nov 19 19:13:02 2012
+++ src/sys/arch/evbarm/rpi/vcio.h Mon Nov 19 19:13:01 2012
@@ -0,0 +1,45 @@
+/* $NetBSD: vcio.h,v 1.1.4.2 2012/11/19 19:13:01 riz Exp $ */
+
+/*-
+ * 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 _EVBARM_RPI_VCIO_H_
+#define _EVBARM_RPI_VCIO_H_
+
+#define BCMMBOX_CHANPM 0
+#define BCMMBOX_CHANFB 1 /* will be depreciated */
+#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 /* _EVBARM_RPI_VCIO_H_ */
Index: src/sys/arch/evbarm/rpi/vcprop.h
diff -u /dev/null src/sys/arch/evbarm/rpi/vcprop.h:1.2.2.2
--- /dev/null Mon Nov 19 19:13:02 2012
+++ src/sys/arch/evbarm/rpi/vcprop.h Mon Nov 19 19:13:01 2012
@@ -0,0 +1,178 @@
+/* $NetBSD: vcprop.h,v 1.2.2.2 2012/11/19 19:13:01 riz Exp $ */
+
+/*-
+ * 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 _EVBARM_RPI_VCPROP_H_
+#define _EVBARM_RPI_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_CLOCKSTATE 0x00030001
+#define VCPROPTAG_SET_CLOCKSTATE 0x00038001
+#define VCPROPTAG_GET_CLOCKRATE 0x00030002
+#define VCPROPTAG_SET_CLOCKRATE 0x00038002
+
+#define VCPROPTAG_GET_CMDLINE 0x00050001
+#define VCPROPTAG_GET_DMACHAN 0x00060001
+ uint32_t vpt_len;
+ uint32_t vpt_rcode;
+#define VCPROPTAG_REQUEST (0U << 31)
+#define VCPROPTAG_RESPONSE (1U << 31)
+
+};
+
+#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;
+} ;
+
+struct vcprop_tag_macaddr {
+ struct vcprop_tag tag;
+ uint64_t addr;
+};
+
+struct vcprop_tag_boardserial {
+ struct vcprop_tag tag;
+ uint64_t sn;
+};
+
+
+#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
+
+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];
+};
+
+#define VCPROP_MAXCMDLINE 256
+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;
+};
+
+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)
+};
+
+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);
+}
+
+#endif /* _EVBARM_RPI_VCPROP_H_ */