Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

sanboot.h 5.1KB

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