You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sanboot.h 6.0KB

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