[258] | 1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : ioc_driver.c |
---|
| 3 | // Date : 23/05/2013 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 7 | // The ioc_driver.c and ioc_driver.h files are part ot the GIET-VM kernel. |
---|
| 8 | // This driver supports the SocLib vci_block_device component, that is |
---|
| 9 | // a single channel, block oriented, external storage contrÃŽler. |
---|
| 10 | // |
---|
| 11 | // It can exist only one block-device controler in the architecture. |
---|
| 12 | // |
---|
| 13 | // The _ioc_read() and _ioc_write() functions use the _ioc_access() function, |
---|
| 14 | // that is always blocking, but can be called in 4 modes: |
---|
| 15 | // |
---|
| 16 | // - In BOOT_PA mode, the _ioc_access() function use the buffer virtual address |
---|
| 17 | // as a physical address (as the page tables are not build) and use a polling |
---|
| 18 | // policy on the IOC_STATUS register to detect transfer completion, as |
---|
| 19 | // hardware interrupts are not activated. This mode is used by the |
---|
| 20 | // boot code to load the map.bin file into memory. |
---|
| 21 | // |
---|
| 22 | // - In BOOT_VA mode, the _ioc_access() function makes a V2P translation to |
---|
| 23 | // compute the buffer physical address, and use a polling policy on IOC_STATUS |
---|
| 24 | // register to detect transfer completion. This mode is used by the boot code |
---|
| 25 | // to load the various .elf files into memory. |
---|
| 26 | // |
---|
| 27 | // - In KERNEL mode, the _ioc_access() function makes a V2P translation to |
---|
| 28 | // compute the buffer physical address, and use a descheduling strategy: |
---|
| 29 | // The ISR executed when transfer completes should restart the calling task. |
---|
| 30 | // There is no checking of user access right to the memory buffer. |
---|
| 31 | // This mode must be used to access IOC, for an "open" system call. |
---|
| 32 | // |
---|
| 33 | // - In USER mode, the _ioc_access() function makes a V2P translation to |
---|
| 34 | // compute the buffer physical address, and use a descheduling strategy: |
---|
| 35 | // The ISR executed when transfer completes should restart the calling task, |
---|
| 36 | // The user access right to the memory buffer must be checked. |
---|
| 37 | // This mode must be used to access IOC, for a "read/write" system call. |
---|
| 38 | // |
---|
| 39 | // As the IOC component can be used by several programs running in parallel, |
---|
| 40 | // the _ioc_lock variable guaranties exclusive access to the device. The |
---|
| 41 | // _ioc_read() and _ioc_write() functions use atomic LL/SC to get the lock. |
---|
| 42 | // |
---|
| 43 | // The IOMMU can be activated or not: |
---|
| 44 | // |
---|
| 45 | // 1) When the IOMMU is used, a fixed size 2Mbytes vseg is allocated to |
---|
| 46 | // the IOC peripheral, in the I/O virtual space, and the user buffer is |
---|
| 47 | // dynamically remapped in the IOMMU page table. The corresponding entry |
---|
| 48 | // in the IOMMU PT1 is defined by the kernel _ioc_iommu_ix1 variable. |
---|
| 49 | // The number of pages to be unmapped is stored in the _ioc_npages variable. |
---|
| 50 | // The number of PT2 entries is dynamically computed and stored in the |
---|
| 51 | // kernel _ioc_iommu_npages variable. It cannot be larger than 512. |
---|
| 52 | // The user buffer is unmapped by the _ioc_completed() function when |
---|
| 53 | // the transfer is completed. |
---|
| 54 | // |
---|
| 55 | // 2/ If the IOMMU is not used, we check that the user buffer is mapped to a |
---|
| 56 | // contiguous physical buffer (this is generally true because the user space |
---|
| 57 | // page tables are statically constructed to use contiguous physical memory). |
---|
| 58 | // |
---|
| 59 | // Finally, the memory buffer must fulfill the following conditions: |
---|
| 60 | // - The buffer must be word aligned, |
---|
| 61 | // - The buffer must be mapped in user space for an user access, |
---|
| 62 | // - The buffer must be writable in case of (to_mem) access, |
---|
| 63 | // - The total number of physical pages occupied by the user buffer cannot |
---|
| 64 | // be larger than 512 pages if the IOMMU is activated, |
---|
| 65 | // - All physical pages occupied by the user buffer must be contiguous |
---|
| 66 | // if the IOMMU is not activated. |
---|
| 67 | // An error code is returned if these conditions are not verified. |
---|
| 68 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 69 | // The seg_ioc_base virtual base addresses must be defined in giet_vsegs.ld file. |
---|
| 70 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 71 | |
---|
| 72 | #include <giet_config.h> |
---|
| 73 | #include <ioc_driver.h> |
---|
| 74 | #include <utils.h> |
---|
| 75 | #include <tty_driver.h> |
---|
| 76 | #include <iob_driver.h> |
---|
| 77 | #include <ctx_handler.h> |
---|
| 78 | #include <mmc_driver.h> |
---|
| 79 | #include <vmem.h> |
---|
| 80 | |
---|
| 81 | #if !defined( USE_IOB ) |
---|
| 82 | # error: You must define USE_IOB in the hard_config.h file |
---|
| 83 | #endif |
---|
| 84 | |
---|
| 85 | #if !defined(GIET_USE_IOMMU) |
---|
| 86 | # error: You must define GIET_USE_IOMMU in the giet_config.h file |
---|
| 87 | #endif |
---|
| 88 | |
---|
| 89 | #define in_unckdata __attribute__((section (".unckdata"))) |
---|
| 90 | |
---|
| 91 | ///////////////////// IOC global variables |
---|
| 92 | |
---|
| 93 | in_unckdata unsigned int _ioc_lock = 0; |
---|
| 94 | in_unckdata volatile unsigned int _ioc_status = 0; |
---|
| 95 | in_unckdata volatile unsigned int _ioc_gtid; |
---|
| 96 | in_unckdata volatile unsigned int _ioc_iommu_ix1 = 0; |
---|
| 97 | in_unckdata volatile unsigned int _ioc_iommu_npages; |
---|
| 98 | |
---|
| 99 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 100 | // _ioc_access() |
---|
| 101 | // This function transfer data between a memory buffer and the block device. |
---|
| 102 | // The buffer lentgth is (count*block_size) bytes. |
---|
| 103 | // Arguments are: |
---|
| 104 | // - to_mem : from external storage to memory when non 0. |
---|
| 105 | // - kernel : kernel buffer with identity mapping when non 0. |
---|
| 106 | // - lba : first block index on the external storage. |
---|
| 107 | // - buf_vaddr : virtual base address of the memory buffer. |
---|
| 108 | // - count : number of blocks to be transfered. |
---|
| 109 | // Returns 0 if success, > 0 if error. |
---|
| 110 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 111 | static unsigned int _ioc_access( unsigned int to_mem, |
---|
| 112 | unsigned int mode, |
---|
| 113 | unsigned int lba, |
---|
| 114 | unsigned int buf_vaddr, |
---|
| 115 | unsigned int count) |
---|
| 116 | { |
---|
| 117 | |
---|
| 118 | #if GIET_DEBUG_IOC_DRIVER |
---|
| 119 | _tty_get_lock( 0 ); |
---|
| 120 | _puts("\n[IOC DEBUG] Enter _ioc_access() at cycle "); |
---|
| 121 | _putd( _get_proctime() ); |
---|
| 122 | _puts(" for processor "); |
---|
| 123 | _putd( _get_procid() ); |
---|
| 124 | _puts("\n - mode = "); |
---|
| 125 | _putd( mode ); |
---|
| 126 | _puts("\n - vaddr = "); |
---|
| 127 | _putx( buf_vaddr ); |
---|
| 128 | _puts("\n - sectors = "); |
---|
| 129 | _putd( count ); |
---|
| 130 | _puts("\n - lba = "); |
---|
| 131 | _putx( lba ); |
---|
| 132 | _puts("\n"); |
---|
| 133 | _tty_release_lock( 0 ); |
---|
| 134 | #endif |
---|
| 135 | |
---|
| 136 | unsigned int error; // return value |
---|
| 137 | unsigned int pt_vbase; // page table vbase address |
---|
| 138 | unsigned int vpn_min; // first virtuel page index covering buffer |
---|
| 139 | unsigned int vpn_max; // last virtual page index covering buffer |
---|
| 140 | unsigned int vpn; // current virtual page index |
---|
| 141 | unsigned int ppn; // physical page number |
---|
| 142 | unsigned int flags; // page protection flags |
---|
| 143 | unsigned int ix2; // page index in IOMMU PT1 page table |
---|
| 144 | unsigned int ppn_first; // first physical page number for user buffer |
---|
| 145 | unsigned int buf_xaddr = 0; // user buffer virtual address in IO space (if IOMMU) |
---|
| 146 | paddr_t buf_paddr = 0; // user buffer physical address (if no IOMMU), |
---|
| 147 | |
---|
| 148 | // check buffer alignment |
---|
| 149 | if ((unsigned int) buf_vaddr & 0x3) |
---|
| 150 | { |
---|
| 151 | _tty_get_lock( 0 ); |
---|
| 152 | _puts("\n[GIET ERROR] in _ioc_access() : buffer not word aligned\n"); |
---|
| 153 | _tty_release_lock( 0 ); |
---|
| 154 | return 1; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | unsigned int * ioc_address = (unsigned int *) &seg_ioc_base ; |
---|
| 158 | |
---|
| 159 | unsigned int length = count << 9; // count * 512 bytes |
---|
| 160 | |
---|
| 161 | // computing target buffer physical address |
---|
| 162 | if ( mode == IOC_BOOT_PA_MODE ) // identity mapping |
---|
| 163 | { |
---|
| 164 | buf_paddr = (paddr_t)buf_vaddr; |
---|
| 165 | } |
---|
| 166 | else // V2P translation |
---|
| 167 | { |
---|
| 168 | // get page table virtual address |
---|
| 169 | pt_vbase = _get_context_slot(CTX_PTAB_ID); |
---|
| 170 | vpn_min = buf_vaddr >> 12; |
---|
| 171 | vpn_max = (buf_vaddr + length - 1) >> 12; |
---|
| 172 | |
---|
| 173 | // loop on all virtual pages covering the user buffer |
---|
| 174 | for (vpn = vpn_min, ix2 = 0 ; |
---|
| 175 | vpn <= vpn_max ; |
---|
| 176 | vpn++, ix2++ ) |
---|
| 177 | { |
---|
| 178 | // get ppn and flags for each vpn |
---|
| 179 | unsigned int ko = _v2p_translate( (page_table_t*)pt_vbase, |
---|
| 180 | vpn, |
---|
| 181 | &ppn, |
---|
| 182 | &flags); |
---|
| 183 | // check access rights |
---|
| 184 | if ( ko ) |
---|
| 185 | { |
---|
| 186 | _tty_get_lock( 0 ); |
---|
| 187 | _puts("\n[GIET ERROR] in _ioc_access() : buffer unmapped\n"); |
---|
| 188 | _tty_release_lock( 0 ); |
---|
| 189 | return 1; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | if ( (mode == IOC_USER_MODE) && ((flags & PTE_U) == 0) ) |
---|
| 193 | { |
---|
| 194 | _tty_get_lock( 0 ); |
---|
| 195 | _puts("\n[GIET ERROR] in _ioc_access() : buffer not user accessible\n"); |
---|
| 196 | _tty_release_lock( 0 ); |
---|
| 197 | return 1; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | if ( ((flags & PTE_W) == 0 ) && to_mem ) |
---|
| 201 | { |
---|
| 202 | _tty_get_lock( 0 ); |
---|
| 203 | _puts("\n[GIET ERROR] in _ioc_access() : buffer not writable\n"); |
---|
| 204 | _tty_release_lock( 0 ); |
---|
| 205 | return 1; |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | // save first ppn value |
---|
| 209 | if (ix2 == 0) ppn_first = ppn; |
---|
| 210 | |
---|
| 211 | #if GIET_USE_IOMMU |
---|
| 212 | |
---|
| 213 | // check buffer length < 2 Mbytes |
---|
| 214 | if (ix2 > 511) // check buffer length < 2 Mbytes |
---|
| 215 | { |
---|
| 216 | _tty_get_lock( 0 ); |
---|
| 217 | _puts("\n[GIET ERROR] in _ioc_access() : user buffer > 2 Mbytes\n"); |
---|
| 218 | _tty_release_lock( 0 ); |
---|
| 219 | return 1; |
---|
| 220 | } |
---|
| 221 | // map the physical page in IOMMU page table |
---|
| 222 | _iommu_add_pte2( _ioc_iommu_ix1, // PT1 index |
---|
| 223 | ix2, // PT2 index |
---|
| 224 | ppn, // Physical page number |
---|
| 225 | flags ); // Protection flags |
---|
| 226 | |
---|
| 227 | // compute user buffer virtual adress in IO space |
---|
| 228 | buf_xaddr = (_ioc_iommu_ix1) << 21 | (buf_vaddr & 0xFFF); |
---|
| 229 | |
---|
| 230 | #else |
---|
| 231 | |
---|
| 232 | // check that physical pages are contiguous |
---|
| 233 | if ((ppn - ppn_first) != ix2) |
---|
| 234 | { |
---|
| 235 | _tty_get_lock( 0 ); |
---|
| 236 | _puts("[GIET ERROR] in _ioc_access() : split physical buffer\n"); |
---|
| 237 | _tty_release_lock( 0 ); |
---|
| 238 | return 1; |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | // compute user buffer physical adress |
---|
| 242 | buf_paddr = (((paddr_t)ppn_first) << 12) | (buf_vaddr & 0xFFF); |
---|
| 243 | #endif |
---|
| 244 | |
---|
| 245 | } // end for vpn |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | #if GIET_USE_IOMMU |
---|
| 249 | |
---|
| 250 | // register the number of pages to be unmapped in IOMMU |
---|
| 251 | _ioc_iommu_npages = (vpn_max - vpn_min) + 1; |
---|
| 252 | |
---|
| 253 | #endif |
---|
| 254 | |
---|
| 255 | if ( to_mem ) // memory write : invalidate data caches |
---|
| 256 | { |
---|
| 257 | // L1 cache |
---|
| 258 | if ( GIET_NO_HARD_CC ) _dcache_buf_invalidate((void *) buf_vaddr, length); |
---|
| 259 | |
---|
| 260 | // L2 cache (only if IOB used) |
---|
| 261 | if ( USE_IOB ) _memc_inval( buf_paddr, length ); |
---|
| 262 | } |
---|
| 263 | else // memory read : update data caches |
---|
| 264 | { |
---|
| 265 | // L1 cache : nothing to do if L1 write-through |
---|
| 266 | |
---|
| 267 | // L2 cache (only if IOB used) |
---|
| 268 | if ( USE_IOB ) _memc_sync( buf_paddr, length ); |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | // get the lock protecting IOC |
---|
| 272 | _get_lock(&_ioc_lock); |
---|
| 273 | |
---|
| 274 | // set the _ioc_status polling variable |
---|
| 275 | _ioc_status = BLOCK_DEVICE_BUSY; |
---|
| 276 | |
---|
| 277 | #if GIET_DEBUG_IOC_DRIVER |
---|
| 278 | _tty_get_lock( 0 ); |
---|
| 279 | _puts("\n[IOC DEBUG] _ioc_access() : configure IOC\n"); |
---|
| 280 | _puts(" - buf_paddr = "); |
---|
| 281 | _putl( buf_paddr ); |
---|
| 282 | _puts("\n"); |
---|
| 283 | _puts(" - count = "); |
---|
| 284 | _putd( count ); |
---|
| 285 | _puts("\n"); |
---|
| 286 | _puts(" - lba = "); |
---|
| 287 | _putd( lba ); |
---|
| 288 | _puts("\n"); |
---|
| 289 | _tty_release_lock( 0 ); |
---|
| 290 | #endif |
---|
| 291 | |
---|
| 292 | // send command to IOC |
---|
| 293 | if ( GIET_USE_IOMMU ) |
---|
| 294 | { |
---|
| 295 | ioc_address[BLOCK_DEVICE_BUFFER] = buf_xaddr; |
---|
| 296 | ioc_address[BLOCK_DEVICE_COUNT] = count; |
---|
| 297 | ioc_address[BLOCK_DEVICE_LBA] = lba; |
---|
| 298 | } |
---|
| 299 | else |
---|
| 300 | { |
---|
| 301 | ioc_address[BLOCK_DEVICE_BUFFER] = (unsigned int)buf_paddr; |
---|
| 302 | ioc_address[BLOCK_DEVICE_BUFFER_EXT] = (unsigned int)(buf_paddr>>32); |
---|
| 303 | ioc_address[BLOCK_DEVICE_COUNT] = count; |
---|
| 304 | ioc_address[BLOCK_DEVICE_LBA] = lba; |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | // There is two policies for transfer completion |
---|
| 308 | // detection, depending on the mode argument: |
---|
| 309 | |
---|
| 310 | if ( (mode == IOC_BOOT_PA_MODE) || // We poll directly the IOC_STATUS register |
---|
| 311 | (mode == IOC_BOOT_VA_MODE) ) // as IRQs are masked. |
---|
| 312 | { |
---|
| 313 | // Launch transfert |
---|
| 314 | if (to_mem == 0) ioc_address[BLOCK_DEVICE_OP] = BLOCK_DEVICE_WRITE; |
---|
| 315 | else ioc_address[BLOCK_DEVICE_OP] = BLOCK_DEVICE_READ; |
---|
| 316 | |
---|
| 317 | unsigned int status = _ioc_get_status(); |
---|
| 318 | while( (status != BLOCK_DEVICE_READ_SUCCESS) && |
---|
| 319 | (status != BLOCK_DEVICE_READ_ERROR) && |
---|
| 320 | (status != BLOCK_DEVICE_WRITE_SUCCESS) && |
---|
| 321 | (status != BLOCK_DEVICE_WRITE_ERROR) ) |
---|
| 322 | { |
---|
| 323 | status = _ioc_get_status(); |
---|
| 324 | |
---|
| 325 | #if GIET_DEBUG_IOC_DRIVER |
---|
| 326 | _tty_get_lock( 0 ); |
---|
| 327 | _puts("\n[IOC DEBUG] _ioc_access() : ... waiting on IOC_STATUS register ...\n"); |
---|
| 328 | _tty_release_lock( 0 ); |
---|
| 329 | #endif |
---|
| 330 | |
---|
| 331 | } |
---|
| 332 | // analyse status |
---|
| 333 | error = ( (status == BLOCK_DEVICE_READ_ERROR) || |
---|
| 334 | (status == BLOCK_DEVICE_WRITE_ERROR) ); |
---|
| 335 | |
---|
| 336 | // release lock |
---|
| 337 | _release_lock(&_ioc_lock); |
---|
| 338 | } |
---|
| 339 | else // in USER or KERNEL mode, we deschedule the task. |
---|
| 340 | // When the task is rescheduled by the ISR, we reset |
---|
| 341 | // the _ioc_status variable, and release the lock |
---|
| 342 | { |
---|
| 343 | // We need a critical section, because we must reset the RUN bit |
---|
| 344 | // before to launch the transfer, and we want to avoid to be descheduled |
---|
| 345 | // between these two operations. |
---|
| 346 | |
---|
| 347 | // Enter critical section |
---|
| 348 | _it_disable(); |
---|
| 349 | |
---|
| 350 | // set _ioc_gtid and reset runnable |
---|
| 351 | unsigned int ltid = _get_proc_task_id(); |
---|
| 352 | unsigned int pid = _get_procid(); |
---|
| 353 | _ioc_gtid = (pid<<16) + ltid; |
---|
| 354 | _set_task_slot( pid, ltid, CTX_RUN_ID, 0 ); |
---|
| 355 | |
---|
| 356 | // Launch transfert |
---|
| 357 | if (to_mem == 0) ioc_address[BLOCK_DEVICE_OP] = BLOCK_DEVICE_WRITE; |
---|
| 358 | else ioc_address[BLOCK_DEVICE_OP] = BLOCK_DEVICE_READ; |
---|
| 359 | |
---|
| 360 | // Exit critical section |
---|
| 361 | _it_enable(); |
---|
| 362 | |
---|
| 363 | // deschedule task |
---|
| 364 | _ctx_switch(); |
---|
| 365 | |
---|
| 366 | // analyse status |
---|
| 367 | error = ( (_ioc_status == BLOCK_DEVICE_READ_ERROR) || |
---|
| 368 | (_ioc_status == BLOCK_DEVICE_WRITE_ERROR) ); |
---|
| 369 | |
---|
| 370 | // reset _ioc_status and release lock |
---|
| 371 | _ioc_status = BLOCK_DEVICE_IDLE; |
---|
| 372 | _release_lock(&_ioc_lock); |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | #if GIET_DEBUG_IOC_DRIVER |
---|
| 376 | _tty_get_lock( 0 ); |
---|
| 377 | _puts("\n[IOC DEBUG] _ioc_access completed at cycle "); |
---|
| 378 | _putd( _get_proctime() ); |
---|
| 379 | _puts(" for processor "); |
---|
| 380 | _putd( _get_procid() ); |
---|
| 381 | _puts("\n"); |
---|
| 382 | _tty_release_lock( 0 ); |
---|
| 383 | #endif |
---|
| 384 | |
---|
| 385 | return error; |
---|
| 386 | } // end _ioc_access() |
---|
| 387 | |
---|
| 388 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 389 | // _ioc_init() |
---|
| 390 | // This function cheks block size, and activates the IOC interrupts. |
---|
| 391 | // Return 0 for success. |
---|
| 392 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 393 | unsigned int _ioc_init() |
---|
| 394 | { |
---|
| 395 | unsigned int * ioc_address = (unsigned int *) &seg_ioc_base ; |
---|
| 396 | |
---|
| 397 | if ( ioc_address[BLOCK_DEVICE_BLOCK_SIZE] != 512 ) |
---|
| 398 | { |
---|
| 399 | _puts("\n[GIET ERROR] in _ioc_init() : block size must be 512 bytes\n"); |
---|
| 400 | _exit(); |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | ioc_address[BLOCK_DEVICE_IRQ_ENABLE] = 1; |
---|
| 404 | return 0; |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 408 | // _ioc_read() |
---|
| 409 | // Transfer data from the block device to a memory buffer. |
---|
| 410 | // - mode : BOOT / KERNEL / USER |
---|
| 411 | // - lba : first block index on the block device |
---|
| 412 | // - buffer : base address of the memory buffer (must be word aligned) |
---|
| 413 | // - count : number of blocks to be transfered. |
---|
| 414 | // Returns 0 if success, > 0 if error. |
---|
| 415 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 416 | unsigned int _ioc_read( unsigned int mode, |
---|
| 417 | unsigned int lba, |
---|
| 418 | void* buffer, |
---|
| 419 | unsigned int count) |
---|
| 420 | { |
---|
| 421 | return _ioc_access( 1, // read access |
---|
| 422 | mode, |
---|
| 423 | lba, |
---|
| 424 | (unsigned int) buffer, |
---|
| 425 | count ); |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 429 | // _ioc_write() |
---|
| 430 | // Transfer data from a memory buffer to the block device. |
---|
| 431 | // - mode : BOOT / KERNEL / USER |
---|
| 432 | // - lba : first block index on the block device |
---|
| 433 | // - buffer : base address of the memory buffer (must be word aligned) |
---|
| 434 | // - count : number of blocks to be transfered. |
---|
| 435 | // Returns 0 if success, > 0 if error. |
---|
| 436 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 437 | unsigned int _ioc_write( unsigned int mode, |
---|
| 438 | unsigned int lba, |
---|
| 439 | const void* buffer, |
---|
| 440 | unsigned int count ) |
---|
| 441 | { |
---|
| 442 | return _ioc_access( 0, // write access |
---|
| 443 | mode, |
---|
| 444 | lba, |
---|
| 445 | (unsigned int) buffer, |
---|
| 446 | count ); |
---|
| 447 | } |
---|
| 448 | |
---|
| 449 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 450 | // _ioc_get_status() |
---|
| 451 | // This function returns the transfert status, and acknowledge the IRQ |
---|
| 452 | // if the IOC controler is not busy. |
---|
| 453 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 454 | unsigned int _ioc_get_status() |
---|
| 455 | { |
---|
| 456 | // get IOC base address |
---|
| 457 | unsigned int * ioc_address = (unsigned int *) &seg_ioc_base; |
---|
| 458 | |
---|
| 459 | return ioc_address[BLOCK_DEVICE_STATUS]; |
---|
| 460 | } |
---|
| 461 | |
---|
| 462 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 463 | // _ioc_get_block_size() |
---|
| 464 | // This function returns the block_size with which the IOC has been configured. |
---|
| 465 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 466 | unsigned int _ioc_get_block_size() |
---|
| 467 | { |
---|
| 468 | // get IOC base address |
---|
| 469 | unsigned int * ioc_address = (unsigned int *) &seg_ioc_base; |
---|
| 470 | |
---|
| 471 | return ioc_address[BLOCK_DEVICE_BLOCK_SIZE]; |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | |
---|
| 475 | // Local Variables: |
---|
| 476 | // tab-width: 4 |
---|
| 477 | // c-basic-offset: 4 |
---|
| 478 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 479 | // indent-tabs-mode: nil |
---|
| 480 | // End: |
---|
| 481 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 482 | |
---|