Documentation ¶
Overview ¶
Package bcm2835 provides support to Go bare metal unikernels written using the TamaGo framework on BCM2835/BCM2836 SoCs.
This package is only meant to be used with `GOOS=tamago GOARCH=arm` as supported by the TamaGo framework for bare metal Go on ARM SoCs, see https://github.com/f-secure-foundry/tamago.
Index ¶
- Constants
- Variables
- func AllocateGPUMemory(size uint32, alignment uint32, flags uint32) (handle uint32)
- func BoardModel() uint32
- func CPUAvailableDMAChannels() (bitmask uint32)
- func CPUMemory() (start uint32, size uint32)
- func FirmwareRevision() uint32
- func GPUMemory() (start uint32, size uint32)
- func Init(base uint32)
- func LockGPUMemory(handle uint32) (addr uint32)
- func MACAddress() []byte
- func PeripheralAddress(offset uint32) uint32
- func Serial() uint32
- type DMAChannel
- type DMAController
- type DMADebugInfo
- func (i DMADebugInfo) FIFOError() bool
- func (i DMADebugInfo) ID() int
- func (i DMADebugInfo) Lite() bool
- func (i DMADebugInfo) OutstandingWrites() int
- func (i DMADebugInfo) ReadError() bool
- func (i DMADebugInfo) ReadLastNotSetError() bool
- func (i DMADebugInfo) State() int
- func (i DMADebugInfo) String() string
- func (i DMADebugInfo) Version() int
- type DMAStatus
- func (s DMAStatus) Active() bool
- func (s DMAStatus) DReq() bool
- func (s DMAStatus) DReqStopsDMA() bool
- func (s DMAStatus) DisableDebug() bool
- func (s DMAStatus) End() bool
- func (s DMAStatus) Error() bool
- func (s DMAStatus) Int() bool
- func (s DMAStatus) PanicPriority() int
- func (s DMAStatus) Paused() bool
- func (s DMAStatus) Priority() int
- func (s DMAStatus) String() string
- func (s DMAStatus) WaitForOutstandingWrites() bool
- func (s DMAStatus) WaitingForOutstandingWrites() bool
- type GPIO
- type GPIOFunction
- type MailboxMessage
- type MailboxTag
- type Rng
Constants ¶
const ( // Base address of the first channel. DMA_CH_BASE0 = 0x7000 // Base address of the 16th channel (ch 15). // // Channel 15 is register space is non-contiguous with other // channels. DMA_CH_BASE15 = 0x5000 // Offset of each channel's registers from previous. DMA_CH_SPAN = 0x100 )
Channel base addresses
const ( // Control and Status DMA_CH_REG_CS = 0x00 // Control Block Address DMA_CH_REG_CONBLK_AD = 0x04 // Debug DMA_CH_REG_DEBUG = 0x20 )
Layout of registers for each channel
const ( // Activate (start) the DMA transfer DMA_CS_ACTIVE = 1 << 0 // Indicates the DMA transfer is complete DMA_CS_END = 1 << 1 // Interrupt Status DMA_CS_INT = 1 << 2 // DREQ Status DMA_CS_DREQ = 1 << 3 // Indicates the DMA transfer has been paused DMA_CS_PAUSED = 1 << 4 // Indicates DMA is paused due to DREQ DMA_CS_DREQ_STOPS_DMA = 1 << 5 // Indicates if the DMA is waiting for outstanding writes DMA_CS_WAITING_FOR_OUTSTANDING_WRITES = 1 << 6 // Indicates if a DMA error occured DMA_CS_ERROR = 1 << 8 // Sets Priority on the AXI bus DMA_CS_PRIORITY_SHIFT = 16 DMA_CS_PRIORITY_MASK = 0xF // Sets the Panic priority on the AXI bus DMA_CS_PANIC_PRIORITY_SHIFT = 20 DMA_CS_PANIC_PRIORITY_MASK = 0xF // Limits outstanding writes and waits for completion at end of transfer DMA_CS_WAIT_FOR_OUTSTANDING_WRITES = 1 << 28 // Disables debug pause DMA_CS_DISDEBUG = 1 << 29 // Aborts the current control block (transfer segment) DMA_CS_ABORT = 1 << 30 // Resets the DMA channel DMA_CS_RESET = 1 << 31 )
DMA Control and Status flags
These are a mix of read-only, write-only, read/write
const ( // Interrupt Enable (signal on transfer complete) DMA_TI_INTEN = 0x1 << 0 // Use two-dimensional (striped) mode DMA_TI_TDMODE = 0x1 << 1 // Wait for write response DMA_TI_WAITRESP = 0x1 << 3 // Increment destination address DMA_TI_DEST_INC = 0x1 << 4 // Destination transfer width (1 = 128bit, 0 = 32bit) DMA_TI_DEST_WIDTH = 0x1 << 5 // Control writes with DREQ (allow peripheral to control speed) DMA_TI_DEST_DREQ = 0x1 << 6 // Ignore writes (do not perform writes) DMA_TI_DEST_IGNORE = 0x1 << 7 // Increment source address DMA_TI_SRC_INC = 0x1 << 8 // Source transfer width (1 = 128bit, 0 = 32bit) DMA_TI_SRC_WIDTH = 0x1 << 9 // Control reads with DREQ (allow peripheral to control speed) DMA_TI_SRC_DREQ = 0x1 << 10 // Ignore reads (do not perform reads) DMA_TI_SRC_IGNORE = 0x1 << 11 // 4-bit burst length requested DMA_TI_BURST_LENGTH_SHIFT = 12 DMA_TI_BURST_LENGTH_MASK = 0xF // Peripheral ID for DREQ rate control DMA_TI_BURST_PERMAP_SHIFT = 16 DMA_TI_BURST_PREMAP_MASK = 0x1F // Add wait cycles between each DMA read or write DMA_TI_WAITS_SHIFT = 21 DMA_TI_WAITS_MASK = 0x1F // Don't do wide bursts DMA_TI_NO_WIDE_BURSTS = 0x1 << 26 )
DMA Transfer Information control flags
const ( // Indicates AXI read last signal was not set when expected DMA_DEBUG_READ_LAST_NOT_SET_ERROR = 0x1 << 0 // Indicates FIFO error DMA_DEBUG_FIFO_ERROR = 0x1 << 1 // Indicates read error DMA_DEBUG_READ_ERROR = 0x1 << 2 // Indicates outstanding writes DMA_DEBUG_OUTSTANDING_WRITES_SHIFT = 4 DMA_DEBUG_OUTSTANDING_WRITE_MASK = 0xF // Gets the AXI ID of this channel DMA_DEBUG_DMA_ID_SHIFT = 8 DMA_DEBUG_DMA_ID_MASK = 0xFF // Gets the DMA engine state DMA_DEBUG_DMA_STATE_SHIFT = 16 DMA_DEBUG_DMA_STATE_MASK = 0xFF // Gets the DMA version DMA_DEBUG_VERSION_SHIFT = 25 DMA_DEBUG_VERSION_MASK = 0x7 // Indicates if this is a reduced performance channel DMA_DEBUG_LITE = 1 << 28 )
DMA Debug flags
const ( GPIO_BASE = 0x200000 GPFSEL0 = GPIO_BASE GPFSEL1 = GPIO_BASE + 0x04 GPSET0 = GPIO_BASE + 0x1c GPCLR0 = GPIO_BASE + 0x28 GPLEV0 = GPIO_BASE + 0x34 GPPUD = GPIO_BASE + 0x94 GPPUDCLK0 = GPIO_BASE + 0x98 )
GPIO registers
const ( GPIO_INPUT = 0b000 GPIO_OUTPUT = 0b001 GPIO_FN0 = 0b100 GPIO_FN1 = 0b101 GPIO_FN2 = 0b110 GPIO_FN3 = 0b111 GPIO_FN4 = 0b011 GPIO_FN5 = 0b010 )
GPIO function selections (p92, BCM2835 ARM Peripherals)
const ( MAILBOX_REGION_BASE = 0xC000 MAILBOX_REGION_SIZE = 0x4000 )
We reserve the 'gap' above excStack and below TEXT segment start for mailbox usage. There is nothing requiring use of this region, but it is convenient since it is always available. Other regions could be used by adjusting ramSize to provide space at top of address range.
const ( MAILBOX_BASE = 0xB880 MAILBOX_READ_REG = MAILBOX_BASE + 0x00 MAILBOX_STATUS_REG = MAILBOX_BASE + 0x18 MAILBOX_WRITE_REG = MAILBOX_BASE + 0x20 MAILBOX_FULL = 0x80000000 MAILBOX_EMPTY = 0x40000000 )
Registers for using mailbox
const ( VC_CH_POWERMGMT = 0 VC_CH_FRAMEBUFFER = 1 VC_CH_VIRTUALUART = 2 VC_CH_VCHIQ = 3 VC_CH_LEDS = 4 VC_CH_BUTTONS = 5 VC_CH_TOUCHSCREEN = 6 VC_CH_PROPERTYTAGS_A_TO_VC = 8 VC_CH_PROPERTYTAGS_VC_TO_A = 9 )
Channels (see <https://github.com/raspberrypi/firmware/wiki/Mailboxes>)
const ( VC_FIRMWARE_GET_REV = 0x00000001 VC_FIRMWARE_GET_REV_LEN = 4 VC_BOARD_GET_MODEL = 0x00010001 VC_BOARD_GET_MODEL_LEN = 4 VC_BOARD_GET_REV = 0x00010002 VC_BOARD_GET_REV_LEN = 4 VC_BOARD_GET_MAC = 0x00010003 VC_BOARD_GET_MAC_LEN = 6 VC_BOARD_GET_SERIAL = 0x00010004 VC_BOARD_GET_SERIAL_LEN = 8 VC_BOARD_GET_ARM_MEMORY = 0x00010005 VC_BOARD_GET_ARM_MEMORY_LEN = 8 VC_BOARD_GET_VC_MEMORY = 0x00010006 VC_BOARD_GET_VC_MEMORY_LEN = 8 VC_BOARD_GET_CLOCKS = 0x00010007 VC_CFG_GET_CMDLINE = 0x00050001 VC_RES_GET_DMACHANNELS = 0x00060001 VC_RES_GET_DMACHANNELS_LEN = 4 VC_POWER_GET_STATE = 0x00020001 VC_POWER_GET_STATE_LEN = 8 VC_POWER_GET_TIMING = 0x00020002 VC_POWER_GET_TIMING_LEN = 8 VC_POWER_SET_STATE = 0x00028001 VC_POWER_SET_STATE_LEN = 8 VC_CLOCK_GET_STATE = 0x00030001 VC_CLOCK_GET_STATE_LEN = 8 VC_CLOCK_SET_STATE = 0x00038001 VC_CLOCK_SET_STATE_LEN = 8 VC_CLOCK_GET_RATE = 0x00030002 VC_CLOCK_GET_RATE_LEN = 8 VC_CLOCK_SET_RATE = 0x00038002 VC_CLOCK_SET_RATE_LEN = 12 VC_CLOCK_GET_MAX_RATE = 0x00030004 VC_CLOCK_GET_MAX_RATE_LEN = 8 VC_CLOCK_GET_MIN_RATE = 0x00030007 VC_CLOCK_GET_MIN_RATE_LEN = 8 VC_CLOCK_GET_TURBO = 0x00030009 VC_CLOCK_GET_TURBO_LEN = 8 VC_CLOCK_SET_TURBO = 0x00038009 VC_CLOCK_SET_TURBO_LEN = 8 VC_VOLT_GET = 0x00030003 VC_VOLT_GET_LEN = 8 VC_VOLT_SET = 0x00038003 VC_VOLT_SET_LEN = 8 VC_VOLT_GET_MAX = 0x00030005 VC_VOLT_GET_MAX_LEN = 8 VC_VOLT_GET_MIN = 0x00030008 VC_VOLT_GET_MIN_LEN = 8 VC_TEMP_GET = 0x00030006 VC_TEMP_GET_LEN = 8 VC_TEMP_GET_MAX = 0x0003000a VC_TEMP_GET_MAX_LEN = 8 VC_MEM_ALLOCATE = 0x0003000c VC_MEM_ALLOCATE_LEN = 12 VC_MEM_LOCK = 0x0003000d VC_MEM_LOCK_LEN = 4 VC_MEM_UNLOCK = 0x0003000e VC_MEM_UNLOCK_LEN = 4 VC_MEM_RELEASE = 0x0003000f VC_MEM_RELEASE_LEN = 4 VC_MEM_EXEC = 0x00030010 VC_MEM_EXEC_LEN = 28 VC_MEM_GET_DISPMANX_HANDLE = 0x00030014 VC_MEM_GET_DISPMANX_HANDLE_LEN = 8 VC_MEM_GET_EDID_BLOCK = 0x00030020 VC_MEM_GET_EDID_BLOCK_LEN = 136 VC_FB_ALLOC_BUFFER = 0x00040001 VC_FB_ALLOC_BUFFER_LEN = 8 VC_FB_RELEASE_BUFFER = 0x00048001 VC_FB_RELEASE_BUFFER_LEN = 0 VC_FB_BLANK_SCREEN = 0x00040002 VC_FB_BLANK_SCREEN_LEN = 0 VC_FB_GET_PHYSICAL_SIZE = 0x00040003 VC_FB_GET_PHYSICAL_SIZE_LEN = 8 VC_FB_TEST_PHYSICAL_SIZE = 0x00044003 VC_FB_TEST_PHYSICAL_SIZE_LEN = 8 VC_FB_SET_PHYSICAL_SIZE = 0x00048003 VC_FB_SET_PHYSICAL_SIZE_LEN = 8 VC_FB_GET_VIRTUAL_SIZE = 0x00040004 VC_FB_GET_VIRTUAL_SIZE_LEN = 8 VC_FB_TEST_VIRTUAL_SIZE = 0x00044004 VC_FB_TEST_VIRTUAL_SIZE_LEN = 8 VC_FB_SET_VIRTUAL_SIZE = 0x00048004 VC_FB_SET_VIRTUAL_SIZE_LEN = 8 VC_FB_GET_DEPTH = 0x00040005 VC_FB_GET_DEPTH_LEN = 4 VC_FB_TEST_DEPTH = 0x00044005 VC_FB_TEST_DEPTH_LEN = 4 VC_FB_SET_DEPTH = 0x00048005 VC_FB_SET_DEPTH_LEN = 4 VC_FB_GET_PIXEL_ORDER = 0x00040006 VC_FB_GET_PIXEL_ORDER_LEN = 4 VC_FB_TEST_PIXEL_ORDER = 0x00044006 VC_FB_TEST_PIXEL_ORDER_LEN = 4 VC_FB_SET_PIXEL_ORDER = 0x00048006 VC_FB_SET_PIXEL_ORDER_LEN = 4 VC_FB_GET_ALPHA_MODE = 0x00040007 VC_FB_GET_ALPHA_MODE_LEN = 4 VC_FB_TEST_ALPHA_MODE = 0x00044007 VC_FB_TEST_ALPHA_MODE_LEN = 4 VC_FB_SET_ALPHA_MODE = 0x00048007 VC_FB_SET_ALPHA_MODE_LEN = 4 VC_FB_GET_PITCH = 0x00040008 VC_FB_GET_PITCH_LEN = 4 VC_FB_GET_VIRTUAL_OFFSET = 0x00040009 VC_FB_GET_VIRTUAL_OFFSET_LEN = 8 VC_FB_TEST_VIRTUAL_OFFSET = 0x00044009 VC_FB_TEST_VIRTUAL_OFFSET_LEN = 8 VC_FB_SET_VIRTUAL_OFFSET = 0x00048009 VC_FB_SET_VIRTUAL_OFFSET_LEN = 8 VC_FB_GET_OVERSCAN = 0x0004000a VC_FB_GET_OVERSCAN_LEN = 16 VC_FB_TEST_OVERSCAN = 0x0004400a VC_FB_TEST_OVERSCAN_LEN = 16 VC_FB_SET_OVERSCAN = 0x0004800a VC_FB_SET_OVERSCAN_LEN = 16 VC_FB_GET_PALETTE = 0x0004000b VC_FB_GET_PALETTE_LEN = 1024 VC_FB_TEST_PALETTE = 0x0004400b VC_FB_SET_PALETTE = 0x0004800b VC_FB_SET_CURSOR_INFO = 0x00008010 VC_FB_SET_CURSOR_INFO_LEN = 24 VC_FB_SET_CURSOR_STATE = 0x00008011 VC_FB_SET_CURSOR_STATE_LEN = 16 )
Tags (see <https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface>)
For fixed length messages, message lengths are provided as the larger of the request or response size, since response overwrites the request buffer and caller is responsible for allocation.
const ( AUX_ENABLES = 0x215004 AUX_MU_IO_REG = 0x215040 AUX_MU_IER_REG = 0x215044 AUX_MU_IIR_REG = 0x215048 AUX_MU_LCR_REG = 0x21504C AUX_MU_MCR_REG = 0x215050 AUX_MU_LSR_REG = 0x215054 AUX_MU_MSR_REG = 0x215058 AUX_MU_SCRATCH = 0x21505C AUX_MU_CNTL_REG = 0x215060 AUX_MU_STAT_REG = 0x215064 AUX_MU_BAUD_REG = 0x215068 )
const ( RNG_BASE = 0x104000 RNG_CTRL = RNG_BASE + 0x0 CTRL_EN = 1 RNG_STATUS = RNG_BASE + 0x4 RNG_DATA = RNG_BASE + 0x8 )
RNG registers
const ( GPU_MEMORY_FLAG_DISCARDABLE = 1 << 0 GPU_MEMORY_FLAG_NORMAL = 0 << 2 GPU_MEMORY_FLAG_DIRECT = 1 << 2 GPU_MEMORY_FLAG_COHERENT = 2 << 2 GPU_MEMORY_FLAG_L1_NONALLOCATING = 3 << 2 GPU_MEMORY_FLAG_ZERO = 1 << 4 GPU_MEMORY_FLAG_NO_INIT = 1 << 5 GPU_MEMORY_FLAG_HINT_PERMALOCK = 1 << 6 )
const DRAM_FLAG_NOCACHE = 0xC0000000
DRAM_FLAG_NOCACHE disables caching by setting to high bits
const SysTimerFreq = 1000000
SysTimerFreq is the frequency (Hz) of the BCM2835 free-running timer (fixed at 1Hz).
const WatchdogPeriod = uint64(16 * time.Microsecond)
WatchdogPeriod is the fixed 16us frequency of the BCM2835 watchdog.
Variables ¶
var ARM = &arm.CPU{}
ARM processor instance
var DMA = DMAController{}
DMA provides access to the DMA controller
var Mailbox = mailbox{}
Mailbox provides access to the BCM2835 mailbox used to communicate with the VideoCore CPU
var MiniUART = &miniUART{}
MiniUART is a secondary low throughput UART intended to be used as a console.
var RNG = &Rng{}
RNG (Random Number Generator) instance
Functions ¶
func AllocateGPUMemory ¶
AllocateGPUMemory allocates space from the GPU address space
The returned value is a handle, use LockMemory to convert to an address.
func CPUAvailableDMAChannels ¶
func CPUAvailableDMAChannels() (bitmask uint32)
CPUAvailableDMAChannels gets the DMA channels available to the ARM core(s)
func FirmwareRevision ¶
func FirmwareRevision() uint32
FirmwareRevision gets the firmware rev of the VideoCore GPU
func Init ¶
func Init(base uint32)
Init takes care of the lower level SoC initialization triggered early in runtime setup.
func LockGPUMemory ¶
LockGPUMemory provides the address of previously allocated memory
func PeripheralAddress ¶
PeripheralAddress returns the absolute address for a peripheral. The Pi boards map 'bus addresses' to board specific base addresses but with consistent layout otherwise.
Types ¶
type DMAChannel ¶
type DMAChannel struct {
// contains filtered or unexported fields
}
DMAChannel controls a specific DMA channel on the DMA controller
func (*DMAChannel) Copy ¶
func (ch *DMAChannel) Copy(from uint32, size int, to uint32)
Do a RAM to RAM transfer.
This method blocks until the transfer is complete, but does allow the Go scheduler to schedule other Go routines.
func (*DMAChannel) DebugInfo ¶
func (ch *DMAChannel) DebugInfo() DMADebugInfo
Debug state for the channel
type DMAController ¶
func (*DMAController) AllocChannel ¶
func (c *DMAController) AllocChannel() (*DMAChannel, error)
AllocChannel provides exclusive use of a DMA channel
func (*DMAController) FreeChannel ¶
func (c *DMAController) FreeChannel(ch *DMAChannel) error
FreeChannel surrenders exclusive use of a DMA channel
func (*DMAController) Init ¶
func (c *DMAController) Init(rgn *dma.Region)
Initialize the controller.
The given region provides a memory region dedicated for DMA transfer purposes
type DMADebugInfo ¶
type DMADebugInfo uint32
Access to the debug flag bitfield
func (DMADebugInfo) FIFOError ¶
func (i DMADebugInfo) FIFOError() bool
Indicates a FIFO error condition
func (DMADebugInfo) Lite ¶
func (i DMADebugInfo) Lite() bool
Indicates if reduced performance 'lite' engine
func (DMADebugInfo) OutstandingWrites ¶
func (i DMADebugInfo) OutstandingWrites() int
Currently outstanding writes
func (DMADebugInfo) ReadLastNotSetError ¶
func (i DMADebugInfo) ReadLastNotSetError() bool
Indicates the last AXI read signal was not set when expected
func (DMADebugInfo) String ¶
func (i DMADebugInfo) String() string
Compat representation of the DMA debug status for debugging
type DMAStatus ¶
type DMAStatus uint32
Access to the status flag bitfield
func (DMAStatus) DReqStopsDMA ¶
Indicates if the transfer is currently paused due to DREQ state
func (DMAStatus) DisableDebug ¶
Indicates if the debug pause signal is disabled
func (DMAStatus) PanicPriority ¶
Gets the AXI panic priority level of the channel
func (DMAStatus) WaitForOutstandingWrites ¶
Indicates if the channel will wait for all writes to complete
func (DMAStatus) WaitingForOutstandingWrites ¶
Indicates if the transfer is waiting for last write to complete
type GPIO ¶
type GPIO struct {
// contains filtered or unexported fields
}
GPIO instance
func (*GPIO) GetFunction ¶
func (gpio *GPIO) GetFunction(line int) GPIOFunction
GetFunction gets the current function of a GPIO line
func (*GPIO) PullUpDown ¶
PullUpDown controls the pull-up or pull-down state of the line.
The pull-up / pull-down state persists across power-down state of the CPU (i.e. always set the pull-up / pull-down to desired state before using a GPIO pin).
func (*GPIO) SelectFunction ¶
func (gpio *GPIO) SelectFunction(n GPIOFunction) (err error)
SelectFunction selects the function of a GPIO line.
type GPIOFunction ¶
type GPIOFunction uint32
type MailboxMessage ¶
type MailboxMessage struct { MinSize int Code uint32 Tags []MailboxTag }
func (*MailboxMessage) Error ¶
func (m *MailboxMessage) Error() bool
func (*MailboxMessage) Tag ¶
func (m *MailboxMessage) Tag(code uint32) *MailboxTag