2 * \file api_drv_disk.h
\r
3 * \brief Disk Driver Interface Definitions
\r
4 * \author John Hodge (thePowersGang)
\r
6 * \section Nomeclature
\r
7 * All addreses are 64-bit counts of bytes from the logical beginning of
\r
8 * the disk unless explicitly stated.
\r
10 * \section dirs VFS Layout
\r
11 * Disk drivers have a flexible directory layout. The root directory can
\r
12 * contain subdirectories, with the only conditions being that all nodes
\r
13 * must support ::eTplDrv_IOCtl with DRV_IOCTL_TYPE returning DRV_TYPE_DISK.
\r
14 * And all file nodes representing disk devices (or partitions) and implemeting
\r
15 * ::eTplDisk_IOCtl fully
\r
17 * \section files Files
\r
18 * When a read or write occurs on a normal file in the disk driver it will
\r
19 * read/write the represented device. The accesses need not be aligned to
\r
20 * the block size, however aligned reads/writes should be handled specially
\r
21 * to improve speed (this can be aided by using ::DrvUtil_ReadBlock and
\r
22 * ::DrvUtil_WriteBlock)
\r
24 #ifndef _API_DRV_DISK_H
\r
25 #define _API_DRV_DISK_H
\r
27 #include <api_drv_common.h>
\r
30 * \enum eTplDisk_IOCtl
\r
31 * \brief Common Disk IOCtl Calls
\r
32 * \extends eTplDrv_IOCtl
\r
34 enum eTplDisk_IOCtl {
\r
37 * \brief Get the block size
\r
38 * \return Size of a hardware block for this device
\r
40 DISK_IOCTL_GETBLOCKSIZE = 4,
\r
43 * ioctl(..., tTplDisk_CacheRegion *RegionInfo)
\r
44 * \brief Sets the cache importantce and protocol for a section of
\r
46 * \param RegionInfo Pointer to a region information structure
\r
47 * \return Boolean failure
\r
49 DISK_IOCTL_SETCACHEREGION,
\r
52 * ioctl(..., Uint64 *Info[2])
\r
53 * \brief Asks the driver to precache a region of disk.
\r
54 * \param Region 64-bit Address and Size pair describing the area to cache
\r
55 * \return Number of blocks cached
\r
57 DISK_IOCTL_PRECACHE,
\r
60 * ioclt(..., Uint64 *Region[2])
\r
61 * \brief Asks to driver to flush the region back to disk
\r
62 * \param Region 64-bit Address and Size pair describing the area to flush
\r
63 * \note If Region[0] == -1 then the entire disk's cache is flushed
\r
64 * \return Number of blocks flushed (or 0 for entire disk)
\r
70 * \brief Describes the cache parameters of a region on the disk
\r
72 typedef struct sTplDisk_CacheRegion
\r
74 Uint64 Base; //!< Base of cache region
\r
75 Uint64 Length; //!< Size of cache region
\r
77 * \brief Cache Protocol & Flags
\r
79 * The low 4 bits denot the cache protocol to be used by the
\r
80 * region (see ::eTplDisk_CacheProtocols for a list).
\r
81 * The high 4 bits denote flags to apply to the cache (see
\r
82 * ::eTplDisk_CacheFlags)
\r
85 Uint8 Priority; //!< Lower is a higher proritory
\r
87 * \brief Maximum size of cache, in blocks
\r
88 * \note If CacheSize is zero, the implemenation defined limit is used
\r
91 } tTplDisk_CacheRegion;
\r
94 * \brief Cache protocols to use
\r
96 enum eTplDisk_CacheProtocols
\r
99 * \brief Don't cache the region
\r
102 DISK_CACHEPROTO_DONTCACHE,
\r
104 * \brief Most recently used blocks cached
\r
105 * \note This is the default action for undefined regions
\r
107 DISK_CACHEPROTO_RECENTLYUSED,
\r
109 * \brief Cache the entire region in memory
\r
111 * This is a faster version of setting Length to CacheSize*BlockSize
\r
113 DISK_CACHEPROTO_FULLCACHE,
\r
116 * \brief Cache only on demand
\r
118 * Only cache when the ::DISK_IOCTL_PRECACHE IOCtl is used
\r
120 DISK_CACHEPROTO_EXPLICIT
\r
124 * \brief Flags for the cache
\r
126 enum eTplDisk_CacheFlags
\r
129 * \brief Write all changes to the region straight back to media
\r
131 DISK_CACHEFLAG_WRITETHROUGH = 0x10
\r
135 * \brief IOCtl name strings
\r
137 #define DRV_DISK_IOCTLNAMES "get_block_size","set_cache_region","set_precache"
\r
140 * \name Disk Driver Utilities
\r
145 * \brief Callback function type used by DrvUtil_ReadBlock and DrvUtil_WriteBlock
\r
146 * \param Address Zero based block number to read
\r
147 * \param Count Number of blocks to read
\r
148 * \param Buffer Destination for read blocks
\r
149 * \param Argument Argument provided in ::DrvUtil_ReadBlock and ::DrvUtil_WriteBlock
\r
151 typedef Uint (*tDrvUtil_Callback)(Uint64 Address, Uint Count, void *Buffer, Uint Argument);
\r
154 * \brief Reads a range from a block device using aligned reads
\r
155 * \param Start Base byte offset
\r
156 * \param Length Number of bytes to read
\r
157 * \param Buffer Destination for read data
\r
158 * \param ReadBlocks Callback function to read a sequence of blocks
\r
159 * \param BlockSize Size of an individual block
\r
160 * \param Argument An argument to pass to \a ReadBlocks
\r
161 * \return Number of bytes read
\r
163 extern Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer,
\r
164 tDrvUtil_Callback ReadBlocks, Uint64 BlockSize, Uint Argument);
\r
166 * \brief Writes a range to a block device using aligned writes
\r
167 * \param Start Base byte offset
\r
168 * \param Length Number of bytes to write
\r
169 * \param Buffer Destination for read data
\r
170 * \param ReadBlocks Callback function to read a sequence of blocks
\r
171 * \param WriteBlocks Callback function to write a sequence of blocks
\r
172 * \param BlockSize Size of an individual block
\r
173 * \param Argument An argument to pass to \a ReadBlocks and \a WriteBlocks
\r
174 * \return Number of bytes written
\r
176 extern Uint64 DrvUtil_WriteBlock(Uint64 Start, Uint64 Length, void *Buffer,
\r
177 tDrvUtil_Callback ReadBlocks, tDrvUtil_Callback WriteBlocks,
\r
178 Uint64 BlockSize, Uint Argument);
\r