| 1 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | // File : bdv_driver.h |
|---|
| 3 | // Date : 01/11/2013 |
|---|
| 4 | // Author : alain greiner |
|---|
| 5 | // Maintainer: cesar fuguet |
|---|
| 6 | // Copyright (c) UPMC-LIP6 |
|---|
| 7 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 8 | // The bdv_driver.c and bdv_driver.h files are part ot the GIET-VM kernel. |
|---|
| 9 | // This driver supports the SocLib vci_block_device component, that is |
|---|
| 10 | // a single channel, block oriented, external storage contrÃŽler. |
|---|
| 11 | // |
|---|
| 12 | // The _bdv_access() function supports both read and write access to block device, |
|---|
| 13 | // and implement two operating modes: |
|---|
| 14 | // |
|---|
| 15 | // - in "synchronous" mode, it uses a polling policy on the BDV STATUS |
|---|
| 16 | // register to detect transfer completion, as interrupts are not activated. |
|---|
| 17 | // This mode must be used by the boot code to load the map.bin file into memory |
|---|
| 18 | // (before MMU activation), or to load the .elf files (after MMU activation). |
|---|
| 19 | // As only one processor acces the block device, it doesn't take the _bdv_lock. |
|---|
| 20 | // |
|---|
| 21 | // - In "descheduling" mode, ir uses a descheduling + IRQ policy. |
|---|
| 22 | // This mode mus be used by the kernel code tho handle system calls. |
|---|
| 23 | // The ISR executed when transfer completes should restart the calling task, |
|---|
| 24 | // as the calling task global index has been saved in the _bdv_gtid variable. |
|---|
| 25 | // As the BDV component can be used by several programs running in parallel, |
|---|
| 26 | // it takes the _bdv_lock and registers it in the calling task context. |
|---|
| 27 | // |
|---|
| 28 | // The SEG_IOC_BASE address must be defined in the hard_config.h file. |
|---|
| 29 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 30 | |
|---|
| 31 | #ifndef _GIET_BDV_DRIVER_H_ |
|---|
| 32 | #define _GIET_BDV_DRIVER_H_ |
|---|
| 33 | |
|---|
| 34 | #include "kernel_locks.h" |
|---|
| 35 | |
|---|
| 36 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 37 | // BDV registers, operations and status values |
|---|
| 38 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 39 | |
|---|
| 40 | enum BDV_registers |
|---|
| 41 | { |
|---|
| 42 | BLOCK_DEVICE_BUFFER, |
|---|
| 43 | BLOCK_DEVICE_LBA, |
|---|
| 44 | BLOCK_DEVICE_COUNT, |
|---|
| 45 | BLOCK_DEVICE_OP, |
|---|
| 46 | BLOCK_DEVICE_STATUS, |
|---|
| 47 | BLOCK_DEVICE_IRQ_ENABLE, |
|---|
| 48 | BLOCK_DEVICE_SIZE, |
|---|
| 49 | BLOCK_DEVICE_BLOCK_SIZE, |
|---|
| 50 | BLOCK_DEVICE_BUFFER_EXT, |
|---|
| 51 | }; |
|---|
| 52 | |
|---|
| 53 | enum BDV_operations |
|---|
| 54 | { |
|---|
| 55 | BLOCK_DEVICE_NOOP, |
|---|
| 56 | BLOCK_DEVICE_READ, |
|---|
| 57 | BLOCK_DEVICE_WRITE, |
|---|
| 58 | }; |
|---|
| 59 | |
|---|
| 60 | enum BDV_status |
|---|
| 61 | { |
|---|
| 62 | BLOCK_DEVICE_IDLE, |
|---|
| 63 | BLOCK_DEVICE_BUSY, |
|---|
| 64 | BLOCK_DEVICE_READ_SUCCESS, |
|---|
| 65 | BLOCK_DEVICE_WRITE_SUCCESS, |
|---|
| 66 | BLOCK_DEVICE_READ_ERROR, |
|---|
| 67 | BLOCK_DEVICE_WRITE_ERROR, |
|---|
| 68 | BLOCK_DEVICE_ERROR, |
|---|
| 69 | }; |
|---|
| 70 | |
|---|
| 71 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 72 | // Global variables |
|---|
| 73 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 74 | |
|---|
| 75 | extern spin_lock_t _bdv_lock; |
|---|
| 76 | |
|---|
| 77 | extern unsigned int _bdv_gtid; |
|---|
| 78 | |
|---|
| 79 | extern unsigned int _bdv_status; |
|---|
| 80 | |
|---|
| 81 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 82 | // Low level access function |
|---|
| 83 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 84 | |
|---|
| 85 | unsigned int _bdv_get_register( unsigned int index ); |
|---|
| 86 | |
|---|
| 87 | void _bdv_set_register( unsigned int index, |
|---|
| 88 | unsigned int value ); |
|---|
| 89 | |
|---|
| 90 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 91 | // This function cheks block size == 512, and desactivates the interrupts. |
|---|
| 92 | // Return 0 for success, > 0 if error |
|---|
| 93 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 94 | extern unsigned int _bdv_init(); |
|---|
| 95 | |
|---|
| 96 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 97 | // Transfer data to/from the block device from/to a memory buffer. |
|---|
| 98 | // - use_irq : descheduling + IRQ if non zero / polling if zero |
|---|
| 99 | // - to_mem : from external storage to memory when non 0. |
|---|
| 100 | // - lba : first block index on the block device |
|---|
| 101 | // - buffer : pbase address of the memory buffer (must be word aligned) |
|---|
| 102 | // - count : number of blocks to be transfered. |
|---|
| 103 | // Returns 0 if success, > 0 if error. |
|---|
| 104 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 105 | extern unsigned int _bdv_access( unsigned int use_irq, |
|---|
| 106 | unsigned int to_mem, |
|---|
| 107 | unsigned int lba, |
|---|
| 108 | unsigned long long buffer, |
|---|
| 109 | unsigned int count ); |
|---|
| 110 | |
|---|
| 111 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 112 | // This ISR save the status, acknowledge the IRQ, and activates the task |
|---|
| 113 | // waiting on IO transfer. It can be an HWI or a SWI. |
|---|
| 114 | // |
|---|
| 115 | // TODO the _set_task_slot access should be replaced by an atomic LL/SC |
|---|
| 116 | // when the CTX_RUN bool will be replaced by a bit_vector. |
|---|
| 117 | /////////////////////////////////////////////////////////////////////////////////// |
|---|
| 118 | extern void _bdv_isr( unsigned irq_type, |
|---|
| 119 | unsigned irq_id, |
|---|
| 120 | unsigned channel ); |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | #endif |
|---|
| 124 | |
|---|
| 125 | // Local Variables: |
|---|
| 126 | // tab-width: 4 |
|---|
| 127 | // c-basic-offset: 4 |
|---|
| 128 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
|---|
| 129 | // indent-tabs-mode: nil |
|---|
| 130 | // End: |
|---|
| 131 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
|---|
| 132 | |
|---|