Embedded Xinu Operating System
An ongoing research project and educational operating system.
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
bcm2837_mbox.h
1 /* Mailbox driver for the BCM2837B0 (Pi 3 B+).
2  *
3  * Embedded Xinu Copyright (C) 2009, 2013, 2018. All rights reserved.
4  *
5  * Authors: Patrick J. McGee
6  * Rade Latinovich
7  */
8 
9 #include "bcm2837.h"
10 #include <stdint.h>
11 
12 /* Mailbox functions */
13 void bcm2837_mailbox_write(uint, uint);
14 uint bcm2837_mailbox_read(uint);
15 void add_mailbox_tag(volatile uint32_t*, uint32_t, uint32_t, uint32_t, uint32_t*);
16 void build_mailbox_request(volatile uint32_t*);
17 void dump_response(volatile uint32_t*, const char*, int);
18 void print_parameter(volatile uint32_t*, const char*, uint32_t, int);
19 void get_mac_mailbox(volatile uint32_t*);
20 
21 /* Mailbox base offset */
22 #define MAILBOX_REGS_BASE (PERIPHERALS_BASE + 0xB880)
23 
24 static volatile uint *const mailbox_regs = (volatile uint*)MAILBOX_REGS_BASE;
25 
26 /* BCM2837 mailbox register indices */
27 #define MAILBOX_READ 0
28 #define MAILBOX_STATUS 6
29 #define MAILBOX_WRITE 8
30 
31 /* BCM2837 mailbox status flags */
32 #define MAILBOX_FULL 0x80000000
33 #define MAILBOX_EMPTY 0x40000000
34 
35 /* BCM2837 mailbox channels */
36 #define MAILBOX_CHANNEL_POWER_MGMT 0
37 #define MAILBOX_CHANNEL_1 1
38 
39 /* The BCM2837 mailboxes are used for passing 28-bit messages. The low 4 bits
40  * * of the 32-bit value are used to specify the channel over which the message is
41  * * being transferred */
42 #define MAILBOX_CHANNEL_MASK 0xf
43 
44 
45 
46 /* Length of mailbox buffer. */
47 #define MBOX_BUFLEN 1024
48 
49 /* States for the mailbox. */
50 #define RR_REQUEST 0x00000000
51 #define RR_RESPONSE_OK 0x80000000
52 #define RR_RESPONSE_ERROR 0x80000001
53 
54 #define SLOT_OVERALL_LENGTH 0
55 #define SLOT_RR 1
56 #define SLOT_TAGSTART 2
57 
58 #define SLOT_TAG_ID 0
59 #define SLOT_TAG_BUFLEN 1
60 #define SLOT_TAG_DATALEN 2
61 #define SLOT_TAG_DATA 3
62 
63 #define MBOX_HEADER_LENGTH 2
64 #define TAG_HEADER_LENGTH 3
65 
66 #define MBX_DEVICE_SDCARD 0x00000000
67 #define MBX_DEVICE_UART0 0x00000001
68 #define MBX_DEVICE_UART1 0x00000002
69 #define MBX_DEVICE_USBHCD 0x00000003
70 #define MBX_DEVICE_I2C0 0x00000004
71 #define MBX_DEVICE_I2C1 0x00000005
72 #define MBX_DEVICE_I2C2 0x00000006
73 #define MBX_DEVICE_SPI 0x00000007
74 #define MBX_DEVICE_CCP2TX 0x00000008
75 
76 /* Mailbox tags for receiving board information. */
77 #define MBX_TAG_GET_FIRMWARE 0x00000001 /* in 0, out 4 */
78 #define MBX_TAG_GET_BOARD_MODEL 0x00010001 /* in 0, out 4 */
79 #define MBX_TAG_GET_BOARD_REVISION 0x00010002 /* in 0, out 4 */
80 #define MBX_TAG_GET_MAC_ADDRESS 0x00010003 /* in 0, out 6 */
81 #define MBX_TAG_GET_BOARD_SERIAL 0x00010004 /* in 0, out 8 */
82 #define MBX_TAG_GET_ARM_MEMORY 0x00010005 /* in 0, out 8 (4 -> base addr, 4 -> len in bytes) */
83 #define MBX_TAG_GET_VC_MEMORY 0x00010006 /* in 0, out 8 (4 -> base addr, 4 -> len in bytes) */
84 #define MBX_TAG_GET_COMMANDLINE 0x00050001 /* in 0, out variable */
85 #define MBX_TAG_GET_DMA_CHANNELS 0x00060001 /* in 0, out 4 */
86 #define MBX_TAG_GET_POWER_STATE 0x00020001 /* in 4 -> dev id, out 8 (4 -> device, 4 -> status) */
87 #define MBX_TAG_GET_TIMING 0x00020002 /* in 0, out 4 */
88 #define MBX_TAG_GET_FIRMWARE 0x00000001 /* in 0, out 4 */
void add_mailbox_tag(volatile uint32_t *buffer, uint32_t tag, uint32_t buflen, uint32_t len, uint32_t *data)
Definition: bcm2837_mbox.c:27
void bcm2837_mailbox_write(uint, uint)
Definition: bcm2837_power.c:19
uint bcm2837_mailbox_read(uint)
Definition: bcm2837_power.c:35
void build_mailbox_request(volatile uint32_t *mailbuffer)
Definition: bcm2837_mbox.c:53
void get_mac_mailbox(volatile uint32_t *mailbuffer)
Definition: bcm2837_mbox.c:67