scsi.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2008 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef GRUB_SCSI_H
  19. #define GRUB_SCSI_H 1
  20. #include <grub/disk.h>
  21. typedef struct grub_scsi_dev *grub_scsi_dev_t;
  22. void grub_scsi_dev_register (grub_scsi_dev_t dev);
  23. void grub_scsi_dev_unregister (grub_scsi_dev_t dev);
  24. struct grub_scsi;
  25. enum
  26. {
  27. GRUB_SCSI_SUBSYSTEM_USBMS,
  28. GRUB_SCSI_SUBSYSTEM_PATA,
  29. GRUB_SCSI_SUBSYSTEM_AHCI,
  30. GRUB_SCSI_NUM_SUBSYSTEMS
  31. };
  32. extern const char grub_scsi_names[GRUB_SCSI_NUM_SUBSYSTEMS][5];
  33. #define GRUB_SCSI_ID_SUBSYSTEM_SHIFT 24
  34. #define GRUB_SCSI_ID_BUS_SHIFT 8
  35. #define GRUB_SCSI_ID_LUN_SHIFT 0
  36. static inline grub_uint32_t
  37. grub_make_scsi_id (int subsystem, int bus, int lun)
  38. {
  39. return (subsystem << GRUB_SCSI_ID_SUBSYSTEM_SHIFT)
  40. | (bus << GRUB_SCSI_ID_BUS_SHIFT) | (lun << GRUB_SCSI_ID_LUN_SHIFT);
  41. }
  42. typedef int (*grub_scsi_dev_iterate_hook_t) (int id, int bus, int luns,
  43. void *data);
  44. struct grub_scsi_dev
  45. {
  46. /* Call HOOK with each device name, until HOOK returns non-zero. */
  47. int (*iterate) (grub_scsi_dev_iterate_hook_t hook, void *hook_data,
  48. grub_disk_pull_t pull);
  49. /* Open the device named NAME, and set up SCSI. */
  50. grub_err_t (*open) (int id, int bus, struct grub_scsi *scsi);
  51. /* Close the scsi device SCSI. */
  52. void (*close) (struct grub_scsi *scsi);
  53. /* Read SIZE bytes from the device SCSI into BUF after sending the
  54. command CMD of size CMDSIZE. */
  55. grub_err_t (*read) (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
  56. grub_size_t size, char *buf);
  57. /* Write SIZE bytes from BUF to the device SCSI after sending the
  58. command CMD of size CMDSIZE. */
  59. grub_err_t (*write) (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
  60. grub_size_t size, const char *buf);
  61. /* The next scsi device. */
  62. struct grub_scsi_dev *next;
  63. };
  64. struct grub_scsi
  65. {
  66. /* The underlying scsi device. */
  67. grub_scsi_dev_t dev;
  68. /* Type of SCSI device. XXX: Make enum. */
  69. grub_uint8_t devtype;
  70. int bus;
  71. /* Number of LUNs. */
  72. int luns;
  73. /* LUN for this `struct grub_scsi'. */
  74. int lun;
  75. /* Set to 0 when not removable, 1 when removable. */
  76. int removable;
  77. /* Size of the device in blocks - 1. */
  78. grub_uint64_t last_block;
  79. /* Size of one block. */
  80. grub_uint32_t blocksize;
  81. /* Device-specific data. */
  82. void *data;
  83. };
  84. typedef struct grub_scsi *grub_scsi_t;
  85. #endif /* GRUB_SCSI_H */