Documentation
¶
Overview ¶
Package rpimemmap is used for allocating uncached memory and physical devices on Raspberry Pi's using plain GO.
Index ¶
- Constants
- func Dump(m MemMap, size uint32) string
- func MapSegment(curMap MemMap, memDev string) ([]byte, error)
- func Reg32(m MemMap, memOffsetToBase uint32) *uint32
- func Reg8(m MemMap, memOffsetToBase uint32) *byte
- func UnmapSegment(ref []byte) error
- type MemMap
- type PeripheralMap
- func (m *PeripheralMap) BusAddr() uint32
- func (m *PeripheralMap) Map(physAddr uint32, memDev string, unused uint32) error
- func (m *PeripheralMap) PhysAddr() uint32
- func (m *PeripheralMap) Size() uint32
- func (m *PeripheralMap) String() string
- func (m *PeripheralMap) Unmap() error
- func (m *PeripheralMap) VirtAddr() unsafe.Pointer
- type UncachedMap
- func (m *UncachedMap) BusAddr() uint32
- func (m *UncachedMap) Map(unused uint32, unused2 string, uncachedMemFlags uint32) error
- func (m *UncachedMap) PhysAddr() uint32
- func (m *UncachedMap) Size() uint32
- func (m *UncachedMap) String() string
- func (m *UncachedMap) Unmap() error
- func (m *UncachedMap) VirtAddr() unsafe.Pointer
Constants ¶
const ( MemDevDefault = "/dev/mem" MemDevGPIO = "/dev/gpiomem" )
Valid MemDev to use for mapping of peripherals.
const ( UncachedMemFlagDiscardable = 1 << 0 // can be resized to 0 at any time. Use for cached data UncachedMemFlagNormal = 0 << 2 // normal allocating alias. Don't use from ARM UncachedMemFlagDirect uint32 = 1 << 2 // 0xC alias uncached UncachedMemFlagCoherent = 2 << 2 // 0x8 alias. Non-allocating in L2 but coherent UncachedMemFlagZero = 1 << 4 // initialise buffer to all zeros UncachedMemFlagNoInit = 1 << 5 // don't initialise (default is initialise to all ones) UncachedMemFlagHintPermaLock = 1 << 6 // Likely to be locked for long periods of time UncachedMemFlagL1Nonallocation = UncachedMemFlagDirect | UncachedMemFlagCoherent // Allocating in L2 )
Memory flags for uncached memory
Variables ¶
This section is empty.
Functions ¶
func Dump ¶
Dump will output the content of the memory. If size == 0, the size of the allocated memory will be used.
func MapSegment ¶
MapSegment maps a MemMap to virtual memory from physical memory address. See const MemDev for possible memDev.
func Reg32 ¶
Reg32 returns a pointer to 4 bytes (32 bits as uint32) of memory from m which starts with an offset by memOffsetToBase bytes. You should be aware that the order of the bits does not have to be the actual order in memory as uint32 does not have to store the bits in the correct order (endian). Use multiple Reg8 calls to get the same memory region in the correct bit order.
Example:
The virtual memory address of the MemMap 'm' is 0xa6c1e000.
`pointerToMemory := Reg32(m, 0)` will be 32 bits which start at 0xa6c1e000
`pointerToMemory := Reg32(m, 1)` will be 32 bits which start at 0xa6c1e001 as 1 byte was added
`pointerToMemory := Reg32(m, 8)` will be 32 bits which start at 0xa6c1e008 as 8 bytes were added
func Reg8 ¶
Reg8 returns a pointer to 1 byte of memory from m which starts with an offset by memOffsetToBase bytes. The order of bits is unaltered. See Reg32 for detailed description of usage.
func UnmapSegment ¶
UnmapSegment unmaps a MemMap from virtual memory
Types ¶
type MemMap ¶
type MemMap interface { fmt.Stringer Map(physAddr uint32, memDev string, flags uint32) error Unmap() error PhysAddr() uint32 BusAddr() uint32 VirtAddr() unsafe.Pointer Size() uint32 }
MemMap defines a memory device.
type PeripheralMap ¶
type PeripheralMap struct {
// contains filtered or unexported fields
}
PeripheralMap is the representation of memory to a peripheral.
func NewPeripheral ¶
func NewPeripheral(sizeInBytes uint32) *PeripheralMap
NewPeripheral creates a new PeripheralMap by supplying the desired size. The size is rounded up to the nearest pageSize.
func (*PeripheralMap) BusAddr ¶
func (m *PeripheralMap) BusAddr() uint32
BusAddr returns the current bus address if available.
func (*PeripheralMap) Map ¶
func (m *PeripheralMap) Map(physAddr uint32, memDev string, unused uint32) error
Map maps a peripheral to virtual memory by physical address. memDev can be MemDevDefault (requires root) or MemDevGPIO (only for GPIOs).
func (*PeripheralMap) PhysAddr ¶
func (m *PeripheralMap) PhysAddr() uint32
PhysAddr returns the current physical address if available.
func (*PeripheralMap) String ¶
func (m *PeripheralMap) String() string
String implements Stringer interface
func (*PeripheralMap) VirtAddr ¶
func (m *PeripheralMap) VirtAddr() unsafe.Pointer
VirtAddr returns the current virtual address if available.
type UncachedMap ¶
type UncachedMap struct {
// contains filtered or unexported fields
}
UncachedMap is the representation of uncached memory via videocore.
func NewUncached ¶
func NewUncached(sizeInBytes uint32) *UncachedMap
NewUncached creates a new UncachedMap by supplying the desired size.
func (*UncachedMap) BusAddr ¶
func (m *UncachedMap) BusAddr() uint32
BusAddr returns the current bus address if available.
func (*UncachedMap) Map ¶
func (m *UncachedMap) Map(unused uint32, unused2 string, uncachedMemFlags uint32) error
Map maps a uncached memory to virtual memory.
func (*UncachedMap) PhysAddr ¶
func (m *UncachedMap) PhysAddr() uint32
PhysAddr returns the current physical address if available.
func (*UncachedMap) String ¶
func (m *UncachedMap) String() string
String implements Stringer interface.
func (*UncachedMap) VirtAddr ¶
func (m *UncachedMap) VirtAddr() unsafe.Pointer
VirtAddr returns the current virtual address if available.