23 | | To represent the available peripherals in a given manicore architecture, ALMOS-MK uses device descriptors, implemented as the '''device_t''' structure. A device descriptor describes a single channel of a peripheral. It contains the functional index, the implementation index, the channel index, the physical base address, and the size of the physical segment containing the addressable registers for this peripheral channel. |
| 23 | To represent the available peripherals in a given manicore architecture, ALMOS-MK uses generic ''device descriptors'', implemented by the '''device_t''' structure. For multi-channels peripherals, ALMOS-MK defines one ''device descriptor'' per channel. this descriptor contains the functional index, the implementation index, the channel index, the physical base address of the segment containing the addressable registers for this peripheral channel. |
25 | | Each device descriptor contains also an embedded waiting queue containing the pending requests registered by the various clients. A client can be any thread, running on any core, in any cluster of the manicure architecture. |
| 25 | Each device descriptor contains a waiting queue of pending commands registered by the various clients threads. This waiting queue is implemented as a distributed XLIST, rooted in the device descriptor. Any thread, running in any cluster can register a command in this queue. |
| 26 | |
| 27 | For each generic device type, the device specific API defines the list of available commands, and the specific structure defining the command descriptor (containing the command type and arguments). This structure is embedded (as an union of the various device types) in the thread descriptor, to be passed to the hardware specific driver. |
| 28 | |
| 29 | The set of supported generic devices, and the associated APIs are defined below: |
| 30 | |
| 31 | || type || usage || |
| 32 | || IOC || Block device controller || |
| 33 | || TXT || text terminal controller || |
| 34 | || NIC || network interface controller || || |
| 35 | For all I/O operations, ALMOS-MK implements a blocking policy: The thread calling a command function to launch an I/O operation on device XYZ is blocked on the THREAD_BLOCKED_IO condition, and deschedule. It will be re-activated by the driver ISR (Interrupt Service Routine) signaling the completion of he I/O operation. |
| 36 | |
| 37 | The waiting queue is handled as a Multi-Writers / Single-Reader FIFO. The N writers are the clients threads, whose number is not bounded. |
| 38 | The single reader is the server thread associated to the device descriptor. This thread is in charge of consuming the pending commands from the waiting queue. When the queue is empty, the server thread blocks on the THREAD_BLOCKED_QUEUE condition, and deschedule. It is re-activated by the client thread when a new command is registered in the queue. |
32 | | |
| 45 | == C) Driver API == |
| 46 | |
| 47 | To start an I/O operation the server thread associated to the device must call the specific driver corresponding to the hardware peripheral available in the manycore architecture. |
| 48 | |
| 49 | To signal the completion of a given I/O operation, the peripheral rises an IRQ to execute a specific ISR (Interrupt Service Routine) in the client cluster, on the core running the client thread. This requires to dynamically route the IRQ to this core. |
| 50 | |
| 51 | Any driver must therefore implement the three following functions: |
| 52 | |
| 53 | === '''driver_init()''' === |
| 54 | This functions initialises both the peripheral hardware registers, and the specific global variables defined by a given hardware implementation. It is called in the kernel initialization phase. |
| 55 | |
| 56 | === '''driver_cmd( xptr_t thread , device_t * device ) === |
| 57 | This function is called by the server thread. It access to the peripheral hardware registers to start the I/O operation. Depending on the hardware peripheral implementation, can be blocking or non-blocking for the server thread. |
| 58 | * It is blocking on the THREAD_BLOCKED_DEV_ISR condition, if the hardware peripheral supports only one simultaneous I/O operation. Examples are a simple disk controller, or a text terminal controller. The blocked server thread must be re-activated by the ISR signaling completion of the current I/O operation. |
| 59 | * It is non-blocking if the hardware peripheral supports several simultaneous I/O operations. Example is an AHCI compliant disk controller. It blocks only if the number of simultaneous I/O operations becomes is larger than the max number supported by the hardware. |
| 60 | The ''thread'' argument is the extended pointer on the client thread, containing the embedded command descriptor. The ''device'' argument |
| 61 | is the local pointer on the device descriptor. |
| 62 | |
| 63 | === '''diver_isr( xptr_t device )''' === |
| 64 | This function is executed in the client cluster, on the core running the client thread. It access the peripheral hardware register to get the I/O operation error status, acknowledge the IRQ, and unblock the client thread. |
| 65 | If the server thread has been blocked, it unblock also the server thread. |
| 66 | The ''device'' argument is the extended pointer on the device descriptor. |
| 67 | |
| 68 | == D) Implementation == |
| 69 | |
| 70 | It is worth to note that this general I/O operation mechanism involve generally three clusters (client cluster / server cluster / IO cluster), but does not use any RPC: |
| 71 | * to post a new command in the waiting queue of a given (remote) device descriptor, the client thread uses only few remote access to be registered in the distributed XLIST rooted in the server cluster. |
| 72 | * to launch the I/O operation on the (remote) peripheral, the server thread uses only remote access access the physical registers located in the I/O cluster. |
| 73 | * To complete the I/O operation, the ISR running on the client cluster access peripheral registers in I/O clusters, reports I/O operation status in the command descriptor, and unblock client and server thread using only remote accesses. |
| 74 | |