source: trunk/kernel/devices/dev_ioc.h @ 635

Last change on this file since 635 was 627, checked in by alain, 6 years ago

Replace the queuelock protectingthe FAT by a rwlock in the FATFS.

File size: 11.1 KB
RevLine 
[1]1/*
2 * dev_ioc.h - IOC (Block Device Controler) generic device API definition.
3 *
[626]4 * Author  Alain Greiner    (2016,2017,2018,2019)
[1]5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-kernel; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef _DEV_IOC_H
25#define _DEV_IOC_H
26
[14]27#include <kernel_config.h>
[457]28#include <hal_kernel_types.h>
[1]29
30/****  Forward declarations  ****/
31
[3]32struct chdev_s;
[1]33
34/*****************************************************************************************
35 *     Generic Block Device Controler definition
36 *
37 * This device provide access to an external mass storage peripheral such as a
38 * magnetic hard disk or a SD card, that can store blocks of data in a linear array
39 * of sectors indexed by a simple lba (logic block address).
[614]40 * It supports four command types:
41 * - READ       : move blocks from device to memory, with a descheduling policy.
42 * - WRITE      : move blocks from memory to device, with a descheduling policy.
43 * - SYNC_READ  : move blocks from device to memory, with a busy waiting policy.
44 * - SYNC_WRITE : move blocks from memory to device, with a busy waiting policy.
[23]45
[626]46 * The READ or WRITE operations require dynamic ressource allocation. The calling thread
[23]47 * is descheduled, and the work is done by the server thread associated to IOC device.
48 * The general scenario is detailed below.
[1]49 * A) the client thread start the I/O operation, by calling the dev_ioc_read()
50 *    or the dev_ioc_write() kernel functions that perform the following actions:
51 *    1) it get a free WTI mailbox from the client cluster WTI allocator.
52 *    2) it enables the WTI IRQ on the client cluster ICU and update interrupt vector.
53 *    3) it access the PIC to link the WTI mailbox to the IOC IRQ.
54 *    4) it builds the command descriptor.
[23]55 *    5) it registers in the IOC device waiting queue.
[1]56 *    6) itblock on the THREAD_BLOCKED_IO condition and deschedule.
57 * B) The server thread attached to the IOC device descriptor handles the commands
58 *    registered in the waiting queue, calling the IOC driver function.
59 *    Most hardware implementation have a DMA capability, but some implementations,
60 *    such as the RDK (Ram Disk) implementation does not use DMA.
61 * C) The ISR signaling the I/O operation completion reactivates the client thread,
62 *    that releases the allocated resources:
63 *    1) access the PIC to unlink the IOC IRQ.
64 *    2) disable the WTI IRQ in the client cluster ICU and update interrupt vector.
65 *    3) release the WTI mailbox to the client cluster WTI allocator.
[23]66 *
[614]67 * The SYNC_READ and SYNC_WRITE operations are used by the kernel in the initialisation
[626]68 * phase, to update the FAT (both the FAT mapper and the FAT on IOC device), or to update
69 * a directory on IOC device when a new file is created.
70 * - These synchronous operations do not not use the IOC device waiting queue,
71 *   the server thread, and the IOC IRQ, but implement a busy-waiting policy
72 *   for the calling thread.
73 * - As the work
[1]74 *****************************************************************************************/
75
76/******************************************************************************************
77 * This defines the (implementation independant) extension for the generic IOC device.
78 *****************************************************************************************/
79
80typedef struct ioc_extend_s
81{
82    uint32_t    size;      /*! number of bytes in a block                               */
83    uint32_t    count;     /*! total number of blocks in physical device                */
84}
85ioc_extend_t;
86
87/******************************************************************************************
88 * This enum defines the various implementations of the generic IOC peripheral.
89 * It must be kept consistent with the define in arch_info.h file.
90 *****************************************************************************************/
91
[614]92typedef enum
[1]93{
94    IMPL_IOC_BDV =   0,     
95    IMPL_IOC_HBA =   1, 
96    IMPL_IOC_SDC =   2,
97    IMPL_IOC_SPI =   3,
98    IMPL_IOC_RDK =   4,
99}
100ioc_impl_t;
101
102/******************************************************************************************
103 * This defines the (implementation independant)  command passed to the driver.
104 *****************************************************************************************/
105
[614]106typedef enum
[23]107{
108    IOC_READ       = 0,
109    IOC_WRITE      = 1,
110    IOC_SYNC_READ  = 2,
[614]111    IOC_SYNC_WRITE = 3,
112}
113cmd_type_t;
[23]114
[1]115typedef struct ioc_command_s
116{
[188]117    xptr_t      dev_xp;     /*! extended pointer on IOC device descriptor                */
[23]118    uint32_t    type;       /*! IOC_READ / IOC_WRITE / IOC_SYNC_READ                     */
[1]119    uint32_t    lba;        /*! first block index                                        */
120    uint32_t    count;      /*! number of blocks                                         */
121    xptr_t      buf_xp;     /*! extended pointer on memory buffer                        */
122    uint32_t    error;      /*! operation status (0 if success)                          */
123}
124ioc_command_t;
125
126/******************************************************************************************
[626]127 * This function returns a printable string for a IOC command type.
128 ******************************************************************************************
129 * @ cmd  : command type.
130 * @ return pointer on string.
131 *****************************************************************************************/
132char * dev_ioc_cmd_str( cmd_type_t cmd );
133
134/******************************************************************************************
[3]135 * This function completes the IOC chdev descriptor initialisation,
[1]136 * namely the link with the implementation specific driver.
[3]137 * The func, impl, channel, is_rx, base fields have been previously initialised.
[1]138 * It calls the specific driver initialisation function, to initialise the hardware
139 * device and the specific data structures when required.
[3]140 * It creates the associated server thread and allocates a WTI from local ICU.
141 * It must de executed by a local thread.
[1]142 ******************************************************************************************
[3]143 * @ chdev     : local pointer on IOC chdev descriptor.
[1]144 *****************************************************************************************/
[3]145void dev_ioc_init( struct chdev_s * chdev );
[1]146
147/******************************************************************************************
[614]148 * This blocking function moves one or several contiguous blocks of data
[23]149 * from the block device to a local memory buffer. The corresponding request is actually
[1]150 * registered in the device pending request queue, and the calling thread is descheduled,
151 * waiting on transfer completion. It will be resumed by the IRQ signaling completion.
[626]152 * It must be called by a local thread.
[1]153 ******************************************************************************************
[23]154 * @ buffer    : local pointer on target buffer in memory (must be block aligned).
[1]155 * @ lba       : first block index on device.
156 * @ count     : number of blocks to transfer.
[626]157 * @ returns 0 if success / returns -1 if error.
[1]158 *****************************************************************************************/
[23]159error_t dev_ioc_read( uint8_t      * buffer,
[1]160                      uint32_t       lba,
161                      uint32_t       count );
162
163/******************************************************************************************
[614]164 * This blocking function moves one or several contiguous blocks of data
[23]165 * from a local memory buffer to the block device. The corresponding request is actually
[1]166 * registered in the device pending request queue, and the calling thread is descheduled,
167 * waiting on transfer completion. It will be resumed by the IRQ signaling completion.
[626]168 * It must be called by a local thread.
[1]169 ******************************************************************************************
[23]170 * @ buffer    : local pointer on source buffer in memory (must be block aligned).
[1]171 * @ lba       : first block index on device.
172 * @ count     : number of blocks to transfer.
[626]173 * @ returns 0 if success / returns -1 if error.
[1]174 *****************************************************************************************/
[23]175error_t dev_ioc_write( uint8_t      * buffer,
[1]176                       uint32_t       lba,
177                       uint32_t       count );
178
[23]179/******************************************************************************************
[614]180 * This blocking function moves one or several contiguous blocks of data
[626]181 * from the block device to a - possibly remote - memory buffer.
[627]182 * It uses an extended pointer, because the target buffer is generally a remote mapper.
[23]183 * It does  not uses the IOC device waiting queue and server thread, and does not use
[246]184 * the IOC IRQ, but call directly the relevant IOC driver, implementing a busy-waiting
[23]185 * policy for the calling thread.
[626]186 * It can be called by a thread running in any cluster.
[23]187 ******************************************************************************************
[626]188 * @ buffer_xp : extended pointer on target buffer in memory (must be block aligned).
[23]189 * @ lba       : first block index on device.
190 * @ count     : number of blocks to transfer.
[626]191 * @ returns 0 if success / returns -1 if error.
[23]192 *****************************************************************************************/
[626]193error_t dev_ioc_sync_read( xptr_t         buffer_xp,
[23]194                           uint32_t       lba,
195                           uint32_t       count );
196
[614]197/******************************************************************************************
198 * This blocking function moves one or several contiguous blocks of data
[626]199 * from a - possibly remote - memory buffer to the block device.
[627]200 * It uses an extended pointer, because the target buffer is generally a remote mapper.
[614]201 * It does  not uses the IOC device waiting queue and server thread, and does not use
202 * the IOC IRQ, but call directly the relevant IOC driver, implementing a busy-waiting
203 * policy for the calling thread.
[626]204 * It can be called by a thread running in any cluster.
[614]205 ******************************************************************************************
[626]206 * @ buffer_xp : extended pointer on source buffer in memory (must be block aligned).
[614]207 * @ lba       : first block index on device.
208 * @ count     : number of blocks to transfer.
[626]209 * @ returns 0 if success / returns -1 if error.
[614]210 *****************************************************************************************/
[626]211error_t dev_ioc_sync_write( xptr_t         buffer_xp,
[614]212                            uint32_t       lba,
213                            uint32_t       count );
214
[1]215#endif  /* _DEV_IOC_H */
Note: See TracBrowser for help on using the repository browser.