Version 1 (modified by alain, 3 years ago) (diff)


TXT device API

A) General principles

The TXT device allows the kernel to access a text terminal peripheral. It is a multi-channel device, and there is one chdev per terminal, and per direction (TX/RX). The TXT0 (channel 0) is the kernel terminal.

The "user" API, contains the functions used the user-level system calls, and by the kernel itself for debug. It defines three operation types : TXT_READ, TXT_WRITE, and TXT_SYNC_WRITE. This API is detailed in section C below.

  • The asynchronous READ and WRITE operations are not directly executed by the client thread. The READ and WRITE requests are registered in the waiting queue rooted in the TXT chdev descriptor. These requests are actually handled by a dedicated server thread running in the cluster containing the chdev descriptor, that call the txt_driver_cmd() function.

A WRITE operation (TX direction) moves N characters from a kernel buffer to the TXT terminal. A READ operation moves one single character from the TXT terminal to a kernel buffer.

  • The synchronous SYNC_WRITE operation is used by the kernel to display debug messages on the TXT0. It does not use the waiting queue, and it does not use the server thread. The client thread calls directly the txt_driver_aux() function, without using the the txt_command_t structure to communicate with the driver.

Most TXT device implementation use two (hardware or software) FIFOs for asynchronous READ and WRITE operations. These FIFOs are not controlled by the kernel, but are controlled by the txt_driver_cmd() and txt_cxd_isr(). When they are used by the driver, the TXT_TX_IRQ and TXT_RX_IRQ are routed to the core executing the corresponding TXT server thread. (ISR stand for Interrupt Service Routine).

To access the various drivers, the TXT device defines a lower-level "driver" API, that is detailed in section D below.

All TXT device structures and access functions are defined in the dev_txt.c et dev_txt.h files.

B) Initialisation

The TXT device dev_txt_init( chdev_t * chdev ) function makes the following initializations :

  • It selects a core in cluster containing the TXT chdev to execute the server thread.
  • it links the TXT channel IRQ to the core executing the server thread.
  • it initialises the TXT specific fields of the chdev descriptor.
  • it initialises the implementation specific TXT hardware device,
  • it initializes the specific software data structures required by the hardware implementation.

It must be called by a local thread.

C) The "user" API

These three I/O operations are blocking, and return only when the transfer is completed, but the blocking policy depends on the operation type.

C.1) Asynchronous operations

  • The dev_txt_read( uint32_t channel , char * buffer ) function moves one character from the terminal identified by the <channel> argument to the local kernel buffer identified by the <buffer> pointer.
  • The dev_txt_write( uint32_t channel , char * buffer , uint32_t count ) function moves <count> characters from a local kernel buffer identified by the <buffer> pointer, to the terminal identified by the <channel> argument.

The kernel buffer is allocated in the kernel stack of the client thread.

Almos-mkh uses these asynchronous operations, for most data transfers required by the user processes.

The scenario is the following :

  1. When a client thread request an I/O operation, the request is registered in the ioc_command_t structure embedded in the client thread descriptor, and the client thread registers itself in the waiting queue rooted in the IOC chdev. Then the client thread blocks on the THREAD_BLOCKED_IO condition, and deschedules.
  2. The DEV server thread attached to the IOC device descriptor handles all commands registered in the IOC device waiting queue. For each pending request, it calls the IOC driver CMD (command) function to ask the hardware device to do the transfer. Then, the server thread blocks on the THREAD_BLOCKED_ISR condition, and deschedules.
  3. When the I/O operation completed, the IOC driver ISR (Interrupt Service Routine) signaling completion reactivates the server thread.
  4. The server thread reactivates the client thread, and handle the next request in the IOC waiting queue, or reschedules if the queue is empty.

Note : According to the scheduler policy, the DEV thread has an higher priority than any user thread, but it is not selected when the associated waiting queue is empty.

C.2) Synchronous operations

  • The dev_txt_sync_write( char * buffer , uint32_t count ) function moves <count> characters from the the kernel buffer identified by the <buffer> pointer, to the kernel TXT0 terminal.

Almost-mkh uses this operation to synchronously display debug or log information on the kernel terminal using the print() kernel function, and we want to avoid any interference with another TXT I/O operation. We don't want to use the TXT device waiting queue, the associated server thread, and the txt_command_t structures used by the txt_driver_cmd() function. Therefore, this function directly call the txt_driver_aux() function, and the txt_sync_args_s structure for the arguments. These synchronous operations use neither the IOC device waiting queue, nor the DEV server thread, and the IRQ. The client thread does not deschedules : it registers the arguments in the IOC command structure embedded in the client thread descriptor, and calls directly the blocking IOC driver CMD function,

D) The "driver" API

All TXT drivers must define four functions :

  • void txt_driver_init( chdev_t *ioc_chdev )
  • void txt_driver_cmd( xptr_t thread_xp )
  • void txt_driver_isr( chdev_t * ioc_chdev )
  • void txt_driver_aux( char * buffer , uint32_t count )

The txt_driver_cmd() function arguments are registered in the txt_command_t structure embedded in the client thread descriptor. One command contains four informations:

  • type : operation type (TXT_READ / TXT_WRITE)
  • buf_xp : extended pointer on kernel buffer.
  • count : number of characters (only for TXT_WRITE).

For asynchronous operations the txt_driver_cmd() function is called by the server thread, that blocks and deschedules after launching the I/O transfer. When the TXT_IRQ is raised by the hardware, the ioc_driver_isr() function reports the I/O operation status, and re-activates the server thread.

The txt_driver_aux() function doesn't use the txt_command_t structure embedded in the thread descriptor. The two arguments are the <buffer> pointer on the kernel buffer, and the number of characters <count>.