2 * \file tpl_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 _TPL_DRV_DISK_H
\r
25 #define _TPL_DRV_DISK_H
\r
27 #include <tpl_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 *Region)
\r
44 * \brief Sets the cache importantce and protocol for a section of
\r
46 * \param Region 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 Info 64-bit Address and Size pair describing the area to cache
\r
55 * \return Number of blocks cached
\r
60 typedef struct sTplDisk_CacheRegion
\r
62 Uint64 Base; //!< Base of cache region
\r
63 Uint64 Length; //!< Size of cache region
\r
65 * \brief Cache Protocol & Flags
\r
67 * The low 4 bits denot the cache protocol to be used by the
\r
68 * region (see ::eTplDisk_CacheProtocols for a list).
\r
69 * The high 4 bits denote flags to apply to the cache (see
\r
70 * ::eTplDisk_CacheFlags)
\r
73 Uint8 Priority; //!< Lower is a higher proritory
\r
74 Uint16 CacheSize; //!< Maximum size of cache, in blocks
\r
75 } tTplDisk_CacheRegion;
\r
78 * \brief Cache protocols to use
\r
80 enum eTplDisk_CacheProtocols
\r
83 * \brief Region is not cached
\r
85 DISK_CACHEPROTO_DONTCACHE,
\r
87 * \brief Most recently used blocks cached
\r
88 * \note This is the default action for undefined regions
\r
90 DISK_CACHEPROTO_RECENTLYUSED,
\r
92 * \brief Cache the entire region in memory
\r
94 * This is a faster version of setting Length to CacheSize*BlockSize
\r
96 DISK_CACHEPROTO_FULLCACHE,
\r
99 * \brief Cache only on demand
\r
101 * Only cache when the ::DISK_IOCTL_PRECACHE ioctl is used
\r
103 DISK_CACHEPROTO_EXPLICIT
\r
105 enum eTplDisk_CacheFlags
\r
107 DISK_CACHEFLAG_WRITETHROUGH
\r
111 * \brief IOCtl name strings
\r
113 #define DRV_DISK_IOCTLNAMES "get_block_size", "set_cache_region"
\r
116 * \section Disk Driver Utilities
\r
120 * \brief Callback function type used by DrvUtil_ReadBlock and DrvUtil_WriteBlock
\r
121 * \param Address Zero based block number to read
\r
122 * \param Count Number of blocks to read
\r
123 * \param Buffer Destination for read blocks
\r
124 * \param Argument Argument provided in ::DrvUtil_ReadBlock and ::DrvUtil_WriteBlock
\r
126 typedef Uint (*tDrvUtil_Callback)(Uint64 Address, Uint Count, void *Buffer, Uint Argument);
\r
129 * \brief Reads a range from a block device using aligned reads
\r
130 * \param Start Base byte offset
\r
131 * \param Length Number of bytes to read
\r
132 * \param Buffer Destination for read data
\r
133 * \param ReadBlocks Callback function to read a sequence of blocks
\r
134 * \param BlockSize Size of an individual block
\r
135 * \param Argument An argument to pass to \a ReadBlocks
\r
136 * \return Number of bytes read
\r
138 extern Uint64 DrvUtil_ReadBlock(Uint64 Start, Uint64 Length, void *Buffer,
\r
139 tDrvUtil_Callback ReadBlocks, Uint64 BlockSize, Uint Argument);
\r
141 * \brief Writes a range to a block device using aligned writes
\r
142 * \param Start Base byte offset
\r
143 * \param Length Number of bytes to write
\r
144 * \param Buffer Destination for read data
\r
145 * \param ReadBlocks Callback function to read a sequence of blocks
\r
146 * \param WriteBlocks Callback function to write a sequence of blocks
\r
147 * \param BlockSize Size of an individual block
\r
148 * \param Argument An argument to pass to \a ReadBlocks and \a WriteBlocks
\r
149 * \return Number of bytes written
\r
151 extern Uint64 DrvUtil_WriteBlock(Uint64 Start, Uint64 Length, void *Buffer,
\r
152 tDrvUtil_Callback ReadBlocks, tDrvUtil_Callback WriteBlocks,
\r
153 Uint64 BlockSize, Uint Argument);
\r