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

Last change on this file since 619 was 614, checked in by alain, 5 years ago

1) introduce a dev_ioc_sync_write() function in IOC API,

to improve the DEVFS synchronous update.

2) fix a big bug in both the user_dir_create() and user_dir_destroy()

functions: add an extended pointer on the reference client process
in the function's arguments.

File size: 10.2 KB
Line 
1/*
2 * dev_ioc.h - IOC (Block Device Controler) generic device API definition.
3 *
4 * Author  Alain Greiner    (2016,2017,2018)
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
27#include <kernel_config.h>
28#include <hal_kernel_types.h>
29
30/****  Forward declarations  ****/
31
32struct chdev_s;
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).
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.
45
46 * A READ or WRITE operation requires dynamic ressource allocation. The calling thread
47 * is descheduled, and the work is done by the server thread associated to IOC device.
48 * The general scenario is detailed below.
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.
55 *    5) it registers in the IOC device waiting queue.
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.
66 *
67 * The SYNC_READ and SYNC_WRITE operations are used by the kernel in the initialisation
68 * phase. These operations do not not use the IOC device waiting queue, the server thread,
69 * and the IOC IRQ, but implement a busy-waiting policy for the calling thread.
70 *****************************************************************************************/
71
72/******************************************************************************************
73 * This defines the (implementation independant) extension for the generic IOC device.
74 *****************************************************************************************/
75
76typedef struct ioc_extend_s
77{
78    uint32_t    size;      /*! number of bytes in a block                               */
79    uint32_t    count;     /*! total number of blocks in physical device                */
80}
81ioc_extend_t;
82
83/******************************************************************************************
84 * This enum defines the various implementations of the generic IOC peripheral.
85 * It must be kept consistent with the define in arch_info.h file.
86 *****************************************************************************************/
87
88typedef enum
89{
90    IMPL_IOC_BDV =   0,     
91    IMPL_IOC_HBA =   1, 
92    IMPL_IOC_SDC =   2,
93    IMPL_IOC_SPI =   3,
94    IMPL_IOC_RDK =   4,
95}
96ioc_impl_t;
97
98/******************************************************************************************
99 * This defines the (implementation independant)  command passed to the driver.
100 *****************************************************************************************/
101
102typedef enum
103{
104    IOC_READ       = 0,
105    IOC_WRITE      = 1,
106    IOC_SYNC_READ  = 2,
107    IOC_SYNC_WRITE = 3,
108}
109cmd_type_t;
110
111typedef struct ioc_command_s
112{
113    xptr_t      dev_xp;     /*! extended pointer on IOC device descriptor                */
114    uint32_t    type;       /*! IOC_READ / IOC_WRITE / IOC_SYNC_READ                     */
115    uint32_t    lba;        /*! first block index                                        */
116    uint32_t    count;      /*! number of blocks                                         */
117    xptr_t      buf_xp;     /*! extended pointer on memory buffer                        */
118    uint32_t    error;      /*! operation status (0 if success)                          */
119}
120ioc_command_t;
121
122/******************************************************************************************
123 * This function completes the IOC chdev descriptor initialisation,
124 * namely the link with the implementation specific driver.
125 * The func, impl, channel, is_rx, base fields have been previously initialised.
126 * It calls the specific driver initialisation function, to initialise the hardware
127 * device and the specific data structures when required.
128 * It creates the associated server thread and allocates a WTI from local ICU.
129 * It must de executed by a local thread.
130 ******************************************************************************************
131 * @ chdev     : local pointer on IOC chdev descriptor.
132 *****************************************************************************************/
133void dev_ioc_init( struct chdev_s * chdev );
134
135/******************************************************************************************
136 * This blocking function moves one or several contiguous blocks of data
137 * from the block device to a local memory buffer. The corresponding request is actually
138 * registered in the device pending request queue, and the calling thread is descheduled,
139 * waiting on transfer completion. It will be resumed by the IRQ signaling completion.
140 * It must be called in the client cluster.
141 ******************************************************************************************
142 * @ buffer    : local pointer on target buffer in memory (must be block aligned).
143 * @ lba       : first block index on device.
144 * @ count     : number of blocks to transfer.
145 * @ returns 0 if success / returns EINVAL if error.
146 *****************************************************************************************/
147error_t dev_ioc_read( uint8_t      * buffer,
148                      uint32_t       lba,
149                      uint32_t       count );
150
151/******************************************************************************************
152 * This blocking function moves one or several contiguous blocks of data
153 * from a local memory buffer to the block device. The corresponding request is actually
154 * registered in the device pending request queue, and the calling thread is descheduled,
155 * waiting on transfer completion. It will be resumed by the IRQ signaling completion.
156 * It must be called in the client cluster.
157 ******************************************************************************************
158 * @ buffer    : local pointer on source buffer in memory (must be block aligned).
159 * @ lba       : first block index on device.
160 * @ count     : number of blocks to transfer.
161 * @ returns 0 if success / returns EINVAL if error.
162 *****************************************************************************************/
163error_t dev_ioc_write( uint8_t      * buffer,
164                       uint32_t       lba,
165                       uint32_t       count );
166
167/******************************************************************************************
168 * This blocking function moves one or several contiguous blocks of data
169 * from the block device to a local memory buffer.
170 * It does  not uses the IOC device waiting queue and server thread, and does not use
171 * the IOC IRQ, but call directly the relevant IOC driver, implementing a busy-waiting
172 * policy for the calling thread.
173 * It must be called in the client cluster.
174 ******************************************************************************************
175 * @ buffer    : local pointer on target buffer in memory (must be block aligned).
176 * @ lba       : first block index on device.
177 * @ count     : number of blocks to transfer.
178 * @ returns 0 if success / returns EINVAL if error.
179 *****************************************************************************************/
180error_t dev_ioc_sync_read( uint8_t      * buffer,
181                           uint32_t       lba,
182                           uint32_t       count );
183
184/******************************************************************************************
185 * This blocking function moves one or several contiguous blocks of data
186 * from a local memory buffer to the block device.
187 * It does  not uses the IOC device waiting queue and server thread, and does not use
188 * the IOC IRQ, but call directly the relevant IOC driver, implementing a busy-waiting
189 * policy for the calling thread.
190 * It must be called in the client cluster.
191 ******************************************************************************************
192 * @ buffer    : local pointer on source buffer in memory (must be block aligned).
193 * @ lba       : first block index on device.
194 * @ count     : number of blocks to transfer.
195 * @ returns 0 if success / returns EINVAL if error.
196 *****************************************************************************************/
197error_t dev_ioc_sync_write( uint8_t      * buffer,
198                            uint32_t       lba,
199                            uint32_t       count );
200
201#endif  /* _DEV_IOC_H */
Note: See TracBrowser for help on using the repository browser.