scsi.h 3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 *  GRUB  --  GRand Unified Bootloader
 *  Copyright (C) 2008  Free Software Foundation, Inc.
 *
 *  GRUB is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  GRUB is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef	GRUB_SCSI_H
#define	GRUB_SCSI_H	1

22 23
#include <grub/disk.h>

24 25 26 27 28 29 30
typedef struct grub_scsi_dev *grub_scsi_dev_t;

void grub_scsi_dev_register (grub_scsi_dev_t dev);
void grub_scsi_dev_unregister (grub_scsi_dev_t dev);

struct grub_scsi;

31 32 33
enum
  {
    GRUB_SCSI_SUBSYSTEM_USBMS,
34 35 36
    GRUB_SCSI_SUBSYSTEM_PATA,
    GRUB_SCSI_SUBSYSTEM_AHCI,
    GRUB_SCSI_NUM_SUBSYSTEMS
37 38
  };

39
extern const char grub_scsi_names[GRUB_SCSI_NUM_SUBSYSTEMS][5];
40

41 42 43 44 45 46 47 48
#define GRUB_SCSI_ID_SUBSYSTEM_SHIFT 24
#define GRUB_SCSI_ID_BUS_SHIFT 8
#define GRUB_SCSI_ID_LUN_SHIFT 0

static inline grub_uint32_t
grub_make_scsi_id (int subsystem, int bus, int lun)
{
  return (subsystem << GRUB_SCSI_ID_SUBSYSTEM_SHIFT)
starous's avatar
starous committed
49
    | (bus << GRUB_SCSI_ID_BUS_SHIFT) | (lun << GRUB_SCSI_ID_LUN_SHIFT);
50 51
}

52 53 54
typedef int (*grub_scsi_dev_iterate_hook_t) (int id, int bus, int luns,
					     void *data);

55 56 57
struct grub_scsi_dev
{
  /* Call HOOK with each device name, until HOOK returns non-zero.  */
58
  int (*iterate) (grub_scsi_dev_iterate_hook_t hook, void *hook_data,
59
		  grub_disk_pull_t pull);
60 61

  /* Open the device named NAME, and set up SCSI.  */
62
  grub_err_t (*open) (int id, int bus, struct grub_scsi *scsi);
63 64 65 66 67 68 69 70 71 72 73 74

  /* Close the scsi device SCSI.  */
  void (*close) (struct grub_scsi *scsi);

  /* Read SIZE bytes from the device SCSI into BUF after sending the
     command CMD of size CMDSIZE.  */
  grub_err_t (*read) (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
		      grub_size_t size, char *buf);

  /* Write SIZE  bytes from BUF to  the device SCSI  after sending the
     command CMD of size CMDSIZE.  */
  grub_err_t (*write) (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
75
		       grub_size_t size, const char *buf);
76 77 78 79 80 81 82 83 84 85 86 87 88

  /* The next scsi device.  */
  struct grub_scsi_dev *next;
};

struct grub_scsi
{
  /* The underlying scsi device.  */
  grub_scsi_dev_t dev;

  /* Type of SCSI device.  XXX: Make enum.  */
  grub_uint8_t devtype;

89 90
  int bus;

91 92 93 94 95 96 97 98 99
  /* Number of LUNs.  */
  int luns;

  /* LUN for this `struct grub_scsi'.  */
  int lun;

  /* Set to 0 when not removable, 1 when removable.  */
  int removable;

100 101
  /* Size of the device in blocks - 1.  */
  grub_uint64_t last_block;
102 103

  /* Size of one block.  */
104
  grub_uint32_t blocksize;
105 106 107 108 109 110 111

  /* Device-specific data.  */
  void *data;
};
typedef struct grub_scsi *grub_scsi_t;

#endif /* GRUB_SCSI_H */