您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

sanboot.h 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. #ifndef _IPXE_SANBOOT_H
  2. #define _IPXE_SANBOOT_H
  3. /** @file
  4. *
  5. * iPXE sanboot API
  6. *
  7. * The sanboot API provides methods for hooking, unhooking,
  8. * describing, and booting from SAN devices.
  9. */
  10. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  11. #include <ipxe/api.h>
  12. #include <ipxe/refcnt.h>
  13. #include <ipxe/list.h>
  14. #include <ipxe/uri.h>
  15. #include <ipxe/retry.h>
  16. #include <ipxe/process.h>
  17. #include <ipxe/blockdev.h>
  18. #include <config/sanboot.h>
  19. /** A SAN path */
  20. struct san_path {
  21. /** Containing SAN device */
  22. struct san_device *sandev;
  23. /** Path index */
  24. unsigned int index;
  25. /** SAN device URI */
  26. struct uri *uri;
  27. /** List of open/closed paths */
  28. struct list_head list;
  29. /** Underlying block device interface */
  30. struct interface block;
  31. /** Process */
  32. struct process process;
  33. /** Path status */
  34. int path_rc;
  35. };
  36. /** A SAN device */
  37. struct san_device {
  38. /** Reference count */
  39. struct refcnt refcnt;
  40. /** List of SAN devices */
  41. struct list_head list;
  42. /** Drive number */
  43. unsigned int drive;
  44. /** Command interface */
  45. struct interface command;
  46. /** Command timeout timer */
  47. struct retry_timer timer;
  48. /** Command status */
  49. int command_rc;
  50. /** Raw block device capacity */
  51. struct block_device_capacity capacity;
  52. /** Block size shift
  53. *
  54. * To allow for emulation of CD-ROM access, this represents
  55. * the left-shift required to translate from exposed logical
  56. * I/O blocks to underlying blocks.
  57. */
  58. unsigned int blksize_shift;
  59. /** Drive is a CD-ROM */
  60. int is_cdrom;
  61. /** Driver private data */
  62. void *priv;
  63. /** Current active path */
  64. struct san_path *active;
  65. /** List of opened SAN paths */
  66. struct list_head opened;
  67. /** List of closed SAN paths */
  68. struct list_head closed;
  69. /** SAN paths */
  70. struct san_path path[0];
  71. };
  72. /**
  73. * Calculate static inline sanboot API function name
  74. *
  75. * @v _prefix Subsystem prefix
  76. * @v _api_func API function
  77. * @ret _subsys_func Subsystem API function
  78. */
  79. #define SANBOOT_INLINE( _subsys, _api_func ) \
  80. SINGLE_API_INLINE ( SANBOOT_PREFIX_ ## _subsys, _api_func )
  81. /**
  82. * Provide a sanboot API implementation
  83. *
  84. * @v _prefix Subsystem prefix
  85. * @v _api_func API function
  86. * @v _func Implementing function
  87. */
  88. #define PROVIDE_SANBOOT( _subsys, _api_func, _func ) \
  89. PROVIDE_SINGLE_API ( SANBOOT_PREFIX_ ## _subsys, _api_func, _func )
  90. /**
  91. * Provide a static inline sanboot API implementation
  92. *
  93. * @v _prefix Subsystem prefix
  94. * @v _api_func API function
  95. */
  96. #define PROVIDE_SANBOOT_INLINE( _subsys, _api_func ) \
  97. PROVIDE_SINGLE_API_INLINE ( SANBOOT_PREFIX_ ## _subsys, _api_func )
  98. /* Include all architecture-independent sanboot API headers */
  99. #include <ipxe/null_sanboot.h>
  100. #include <ipxe/dummy_sanboot.h>
  101. #include <ipxe/efi/efi_block.h>
  102. /* Include all architecture-dependent sanboot API headers */
  103. #include <bits/sanboot.h>
  104. /**
  105. * Hook SAN device
  106. *
  107. * @v drive Drive number
  108. * @v uris List of URIs
  109. * @v count Number of URIs
  110. * @ret drive Drive number, or negative error
  111. */
  112. int san_hook ( unsigned int drive, struct uri **uris, unsigned int count );
  113. /**
  114. * Unhook SAN device
  115. *
  116. * @v drive Drive number
  117. */
  118. void san_unhook ( unsigned int drive );
  119. /**
  120. * Attempt to boot from a SAN device
  121. *
  122. * @v drive Drive number
  123. * @ret rc Return status code
  124. */
  125. int san_boot ( unsigned int drive );
  126. /**
  127. * Describe SAN device for SAN-booted operating system
  128. *
  129. * @v drive Drive number
  130. * @ret rc Return status code
  131. */
  132. int san_describe ( unsigned int drive );
  133. extern struct list_head san_devices;
  134. /** Iterate over all SAN devices */
  135. #define for_each_sandev( sandev ) \
  136. list_for_each_entry ( (sandev), &san_devices, list )
  137. /** There exist some SAN devices
  138. *
  139. * @ret existence Existence of SAN devices
  140. */
  141. static inline int have_sandevs ( void ) {
  142. return ( ! list_empty ( &san_devices ) );
  143. }
  144. /**
  145. * Get reference to SAN device
  146. *
  147. * @v sandev SAN device
  148. * @ret sandev SAN device
  149. */
  150. static inline __attribute__ (( always_inline )) struct san_device *
  151. sandev_get ( struct san_device *sandev ) {
  152. ref_get ( &sandev->refcnt );
  153. return sandev;
  154. }
  155. /**
  156. * Drop reference to SAN device
  157. *
  158. * @v sandev SAN device
  159. */
  160. static inline __attribute__ (( always_inline )) void
  161. sandev_put ( struct san_device *sandev ) {
  162. ref_put ( &sandev->refcnt );
  163. }
  164. /**
  165. * Calculate SAN device block size
  166. *
  167. * @v sandev SAN device
  168. * @ret blksize Sector size
  169. */
  170. static inline size_t sandev_blksize ( struct san_device *sandev ) {
  171. return ( sandev->capacity.blksize << sandev->blksize_shift );
  172. }
  173. /**
  174. * Calculate SAN device capacity
  175. *
  176. * @v sandev SAN device
  177. * @ret blocks Number of blocks
  178. */
  179. static inline uint64_t sandev_capacity ( struct san_device *sandev ) {
  180. return ( sandev->capacity.blocks >> sandev->blksize_shift );
  181. }
  182. /**
  183. * Check if SAN device needs to be reopened
  184. *
  185. * @v sandev SAN device
  186. * @ret needs_reopen SAN device needs to be reopened
  187. */
  188. static inline int sandev_needs_reopen ( struct san_device *sandev ) {
  189. return ( sandev->active == NULL );
  190. }
  191. extern struct san_device * sandev_find ( unsigned int drive );
  192. extern int sandev_reopen ( struct san_device *sandev );
  193. extern int sandev_reset ( struct san_device *sandev );
  194. extern int sandev_rw ( struct san_device *sandev, uint64_t lba,
  195. unsigned int count, userptr_t buffer,
  196. int ( * block_rw ) ( struct interface *control,
  197. struct interface *data,
  198. uint64_t lba, unsigned int count,
  199. userptr_t buffer, size_t len ) );
  200. extern struct san_device * alloc_sandev ( struct uri **uris, unsigned int count,
  201. size_t priv_size );
  202. extern int register_sandev ( struct san_device *sandev );
  203. extern void unregister_sandev ( struct san_device *sandev );
  204. extern unsigned int san_default_drive ( void );
  205. #endif /* _IPXE_SANBOOT_H */