Presentation is loading. Please wait.

Presentation is loading. Please wait.

The World Leader in High Performance Signal Processing Solutions Linux: Blackfin Guts.

Similar presentations


Presentation on theme: "The World Leader in High Performance Signal Processing Solutions Linux: Blackfin Guts."— Presentation transcript:

1 The World Leader in High Performance Signal Processing Solutions Linux: Blackfin Guts

2 http://blackfin.uclinux.org/ Agenda Background Operating Modes (user / supervisor) Hardware usage CEC / SIC / etc... Example Driver Paradigms

3 http://blackfin.uclinux.org/ Terms and Concepts Linux – the kernel / operating system MMU – memory management unit VM – Virtual Memory support Blackfin lacks this today MPU – Memory Protection Unit Blackfin has this today via CPLBs Operating mode Supervisor – privileged mode Userspace – unprivileged mode Device Driver Generic term – any code that manages a device Character Device Data is handled as a stream – think arrays or buffers Block Device Data is handled in blocks – think sectors or pages

4 http://blackfin.uclinux.org/ Linux Background Started in 1991 by Linus Torvalds Free software – everything is under the GPL-2 Support for more architectures than any other OS Support for more devices than any other OS Every file system under the sun Every storage device Frameworks to configure hardware No mucking with MMRs! Easy to port across boards and processors Resource management Detect and prevent conflicts Stability!

5 http://blackfin.uclinux.org/ Linux Initialization (Blackfin-specific) Much like U-Boot initialization … Program SYSCFG Initialize C runtime ABI Zero out loop / circular buffer / etc... registers Zero out BSS sections Load specific functions/data into on-chip memory Initialize stack pointer Lower execution to EVT15 Load kernel command line from boot loader Initialize core timer Initialize CEC and SIC Initialize EBIU Initialize CPLBs and cache Initialize GPIO framework

6 http://blackfin.uclinux.org/ Root File System The root file system can be located anywhere Only need block driver built into the kernel Common methods Initramfs Initrd / uClinux RAM MTD External flash External storage Initramfs is a root file system compiled into the kernel and then dynamically decompressed into RAM Can grow dynamically within limits of available RAM Initrd / uClinux RAM MTD is a root file system appended to the kernel and dynamically copied into a dedicated chunk of RAM at the end of memory File system size is fixed, but end of memory avoids ICPLB anomaly External storage is simple – kernel mounts and reads at init

7 http://blackfin.uclinux.org/ Privileged execution Manages hardware Core settings (arch/blackfin/) CEC / SIC / GPIOs / etc... Peripherals & Devices (drivers/) Interrupts / Device Communication / etc... ADI' responsibility All Blackfin core code Drivers for on-chip peripherals Drivers for ADI devices Customers' responsibility Develop drivers for unsupported devices Don't buy TI! Declare board-specific resources (device ↔ pin mappings) Operating Modes – kernelspace (supervisor)

8 http://blackfin.uclinux.org/ Operating Modes – userspace Applications live here All software libraries No access to hardware Must ask kernel for access to all resources Cannot just take random DMA channels Cannot just take random on-chip memory Communicate with device drivers Device drivers communicate with hardware Standard POSIX programming environment With GNU and Linux extensions Policy and behavior

9 http://blackfin.uclinux.org/ Userspace Operating Modes – Big Picture B / Hardware Linux Kernel (supervisor) Application (Customer) C Library (uClibc) Device Driver Framework Opensource Library

10 http://blackfin.uclinux.org/ Clocks and Memory Default settings come from U-Boot Linux can reprogram during init Safe settings in U-Boot for recovery Ricer settings in Linux for maximum performance Memory settings do not change on the fly CPU Frequency framework Can do dynamic Core Clock scaling based on governor ondemand – scale as needed by system load powersave – always run at slowest clock performance – always run at fastest clock userspace – let userspace dictate clock speeds Don't touch clock settings yourself!

11 http://blackfin.uclinux.org/ Memory Layout Null page Fixed Code Linux kernel static:.text,.data,.bss Async Banks On Chip Regions (L1, L2, MMRs, Boot ROM) Dynamic Kernel Memory & Userspace Applications 0x00000000 0x00000400 0x00001000 0x20000000 0x30000000 ~0x00400000

12 http://blackfin.uclinux.org/ Core Event Controller NMI Not supported under Linux (see linux-kernel:nmi in wiki) Exceptions Custom exceptions may be allocated dynamically with framework Rarely used, so little documentation on this feature Interrupts HWERR – bad mojo Core Timer – increment jiffies IVG7 – IVG13 – provide user-configuration SIC prioritization IVG14 – Linux soft IRQs IVG15 – Linux system calls Do not touch the CEC!

13 http://blackfin.uclinux.org/ System Interrupt Controller(s) Entire SIC is controlled by IRQ framework No one outside of Linux team needs to know the details Drivers deal with IRQs Request IRQs with certain triggering conditions Register IRQ handler for specific IRQs Free IRQs Never look at SIC_ISR / SIC_IMASK again! Drivers also deal with power management Wake up framework provides hooks for people Declare an IRQ as a wakeup source Never look at SIC_IWR again! Kernel configuration option to bind different System Interrupts to specific Core Event Levels (EVTs) Never look at SIC_IAR again!

14 http://blackfin.uclinux.org/ Core Blackfin Resources CEC / SIC Use IRQ framework to obtain an IRQ Core Timer Used to keep track of passage of time CPLBs Protection, caching, etc... – all transparent All SRAM (L1 / L2 / scratch) Use sram allocator framework to dynamically acquire pieces MDMA Channel 0 Reserved for dedicated dma_memcpy() GPIO / Port Muxing Use irq / gpio / peripheral frameworks to reserve resources Never touch any of these resources directly! You will kill the poor little Blackfin system Nobody likes that (I asked)

15 http://blackfin.uclinux.org/ Null Pointers “Without a MMU, how do you detect NULL pointers?” Lock two CPLB entries at start of memory First is standard 4MB size Second is small 1KB size We reserve first 1KB (0x400 bytes) of memory No one will miss 1k Any access to first 1KB causes exception DCPLB/ICPLB Multiple Hit exceptions Kernel catches exception Prints crash message (register state / hardware trace buffer) Kills application User cries No runtime overhead! Well, for large memory systems (64MB+), loose 1 entry in CPLB table … but with 4MB size entries, not a big deal

16 http://blackfin.uclinux.org/ Atomic Operations Blackfin ISA only supports TESTSET Does not work on cached memory Software method needed Userspace uses “Fixed Code” section Dedicated set of functions starting at address 0x400 If kernel interrupts userspace in the middle of fixed code Before returning to userspace, finish the atomic operation Userspace always sees atomic behavior If kernel does not interrupt userspace, little overhead! Jump to fixed address and execute one/two register load/store Kernel space turns off interrupts for operation Slightly increased latency Only way to prevent interruption when doing operation

17 http://blackfin.uclinux.org/ System Calls System call Calling specific function in kernel space from userspace Looked up via numeric table Pass system call number via register P0 Pass arguments via registers R0 – R5 Invoke custom exception 0 – excpt 0; EVT3 runs Find out exception reason in EXCAUSE For custom exception 0, lower self to EVT15 EVT15 runs Look up actual function address in system call table with P0 Call function Return to userspace

18 http://blackfin.uclinux.org/ MPU – Memory Protection Unit Default setting is to turn MPU off Pros Speed – no overhead from page misses Caches – keep everything cached Cons No protection – rogue userspace can kill kernel or other processes All of external memory is covered with 4 meg CPLBs Turning MPU on provides standard memory protection Pros Real protection between userspace/userspace and userspace/kernel Cons Much slower on some workloads – up to ~10x for memory intensive operations such as MPEG decoding with FFMPEG Page granularity of 4KB

19 http://blackfin.uclinux.org/ Device Driver Paradigms How to work with drivers in end system Existing Drivers Userspace SPI Userspace I2C Userspace I/O Userspace GPIO SRAM Allocator Resource Frameworks Character Device

20 http://blackfin.uclinux.org/ Working with Device Drivers The term “Device Driver” is generic Any code that manages a device Drivers implement interfaces, not policy How to communicate with a device Not what is communicated If hardware supports something, so does the driver Policy is the business of userspace Difference between “can” and “may” Device nodes are special files that live in /dev/ Every node has Type (character or block) Major number (unique number in system to identify class) Minor number (unique per-major to identify specific device) Major & Minor numbers tend to all be dynamic nowadays

21 http://blackfin.uclinux.org/ Reuse Existing Blackfin Drivers For many peripherals, Blackfin driver is OK SPI bus master MMC/SD bus I2C/TWI bus UART driver USB bus Storage subsystems: NAND / NOR / ATAPI Watchdog RTC Ethernet MAC CAN OTP Rotary Encoder

22 http://blackfin.uclinux.org/ Reuse Existing Blackfin Drivers (cont) For busses, we handle the bus layer You implement client driver SPI / I2C client Some devices hook into existing frameworks Input: Rotary encoder, GPIO push buttons RTC / Watchdog: Common Linux interface for userspace Storage: higher block layers are all common For non-standard peripherals, you must manage peripheral- specific MMRs yourself (does not mean SIC/portmux MMRs) PPI / EPPI Pixel Composilator SPORT We provide examples of existing usage SPORT: audio codecs PPI: LCDs and cameras

23 http://blackfin.uclinux.org/ New Driver – user or kernel ? Since many frameworks provide userspace interfaces, first question: is userspace OK? Latency: userspace has higher latency For many devices, this is OK – SPI voltage regulator (AD5304) Throughput: userspace has lower throughput For many devices, this is OK – communication is a few bytes or very slow anyways (I2C EEPROMs) Other frameworks If you need to leverage other kernel frameworks that do not have userspace interfaces, then you'll need to be an in-kernel driver Unsure? Ask!

24 http://blackfin.uclinux.org/ Userspace SPI Declare the SPI client settings in kernel board resources SPI mode (CPHA / CPOL) DMA usage Bits per word CS behavior Max speed Character device node is created automatically /dev/spidev. Userspace application uses character device node Read – perform half-duplex read Write – perform half-duplex write Ioctl Commands to change some SPI parameters dynamically Perform full duplex transfers http://docs.blackfin.uclinux.org/doku.php?id=spi

25 http://blackfin.uclinux.org/ Userspace I2C No kernel space setup required (other than enable bus driver) Character device node is created automatically /dev/i2c- Userspace application uses character device node Ioctl Command to set slave address to work with Command to read and write data Exact ioctl commands are hidden behind simple API #include i2c_smbus_read_word_data(fd, 0x40) – read device register 0x40 i2c_smbus_write_word_data(fd, 0x40, 0x1234) – write device register http://docs.blackfin.uclinux.org/doku.php?id=i2c

26 http://blackfin.uclinux.org/ Userspace I/O Expose some resources directly to userspace Memory regions – like asynchronous banks Not really a big deal – no MPU means userspace has full access anyways … Generic interrupts Only useful for catching and acknowledging an interrupt – nothing else Push button via GPIO Inter-core signals (CoreA ↔ CoreB on BF561) Declare resource in kernel board resources Declare function to clear interrupt Character device node is created automatically /dev/uio Userspace application uses character device node Read – got to sleep until IRQ fires MMAP – get handle to memory region

27 http://blackfin.uclinux.org/ Userspace GPIO No kernel space setup required (other than enable bus driver) Character device node is created automatically /dev/gpio Userspace application uses character device node Open – reserve GPIO for userspace app Write – set GPIO parameters Direction – input and output Value – 0 or 1 or toggle Read – get GPIO value (0 or 1) Useful only for simple things Polling for value Setting lines high / low Cannot handle interrupts http://docs.blackfin.uclinux.org/doku.php?id=linux- kernel:drivers:simple-gpio

28 http://blackfin.uclinux.org/ SRAM Allocator Linux manages the regions Dynamically ask for chunks of on-chip memory L1 Data Bank A Bank B L1 Inst L1 Scratch L2 Just like malloc() and free() Also use GCC attributes to selectively mark certain functions and/or variables to be stored in specific regions Space is automatically reserved and things loaded Can be used in both kernel and user space

29 http://blackfin.uclinux.org/ Resource Frameworks GPIO Framework: #include gpio_request(GPIO_PF8, “my driver”); gpio_direction_output(GPIO_PF8, 1); gpio_free(GPIO_PF8); Peripheral Framework: #include peripheral_request(P_TMR6, “another driver”); peripheral_free(P_TMR6); IRQ Framework request_irq(IRQ_PG10, irq_handler, IRQF_FLAGS, “my irq”, data); free_irq(IRQ_PG10, data); No need to touch core MMRs again – no GPIO, PORT_MUX, SIC, etc..., or worry about inter-processor differences

30 http://blackfin.uclinux.org/ Character Device The swiss army knife of interfacing with userspace Simple to implement Easy to move large buffers of memory Read (kernel → user) Write (user → kernel) MMAP (share a buffer) Easy to pass structures and send commands Ioctl – ugly, but functional Pass a structure Send a command Easy to sleep and wait for event (like an interrupt) Go to sleep in read() by calling wait_for_completion() Interrupt handler runs and wakes process with complete()

31 http://blackfin.uclinux.org/ Character Device (cont) Character Device is just a means to an end Communicate with userspace Real work is done by other code “Drivers within drivers” One kernel module Registers multiple sub-drivers SPI client I2C client Registers IRQ handlers Registers GPIO pins Registers character device Userspace talks to character device Character device passes things to other drivers Application ↔ char device ↔ SPI client ↔ SPI bus ↔ hardware

32 http://blackfin.uclinux.org/ References If you want to learn more, plenty of good books out there Many are free! http://docs.blackfin.uclinux.org/doku.php?id=references_and_pointers Check out or wiki for info as well http://docs.blackfin.uclinux.org/doku.php

33 http://blackfin.uclinux.org/ Questions ?


Download ppt "The World Leader in High Performance Signal Processing Solutions Linux: Blackfin Guts."

Similar presentations


Ads by Google