/* * VasEBoot -- GRand Unified Bootloader * Copyright (C) 2008 Free Software Foundation, Inc. * * VasEBoot 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. * * VasEBoot 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 VasEBoot. If not, see . */ #ifndef VasEBoot_SCSI_H #define VasEBoot_SCSI_H 1 #include typedef struct VasEBoot_scsi_dev *VasEBoot_scsi_dev_t; void VasEBoot_scsi_dev_register (VasEBoot_scsi_dev_t dev); void VasEBoot_scsi_dev_unregister (VasEBoot_scsi_dev_t dev); struct VasEBoot_scsi; enum { VasEBoot_SCSI_SUBSYSTEM_USBMS, VasEBoot_SCSI_SUBSYSTEM_PATA, VasEBoot_SCSI_SUBSYSTEM_AHCI, VasEBoot_SCSI_NUM_SUBSYSTEMS }; extern const char VasEBoot_scsi_names[VasEBoot_SCSI_NUM_SUBSYSTEMS][5]; #define VasEBoot_SCSI_ID_SUBSYSTEM_SHIFT 24 #define VasEBoot_SCSI_ID_BUS_SHIFT 8 #define VasEBoot_SCSI_ID_LUN_SHIFT 0 static inline VasEBoot_uint32_t VasEBoot_make_scsi_id (int subsystem, int bus, int lun) { return (subsystem << VasEBoot_SCSI_ID_SUBSYSTEM_SHIFT) | (bus << VasEBoot_SCSI_ID_BUS_SHIFT) | (lun << VasEBoot_SCSI_ID_LUN_SHIFT); } typedef int (*VasEBoot_scsi_dev_iterate_hook_t) (int id, int bus, int luns, void *data); struct VasEBoot_scsi_dev { /* Call HOOK with each device name, until HOOK returns non-zero. */ int (*iterate) (VasEBoot_scsi_dev_iterate_hook_t hook, void *hook_data, VasEBoot_disk_pull_t pull); /* Open the device named NAME, and set up SCSI. */ VasEBoot_err_t (*open) (int id, int bus, struct VasEBoot_scsi *scsi); /* Close the scsi device SCSI. */ void (*close) (struct VasEBoot_scsi *scsi); /* Read SIZE bytes from the device SCSI into BUF after sending the command CMD of size CMDSIZE. */ VasEBoot_err_t (*read) (struct VasEBoot_scsi *scsi, VasEBoot_size_t cmdsize, char *cmd, VasEBoot_size_t size, char *buf); /* Write SIZE bytes from BUF to the device SCSI after sending the command CMD of size CMDSIZE. */ VasEBoot_err_t (*write) (struct VasEBoot_scsi *scsi, VasEBoot_size_t cmdsize, char *cmd, VasEBoot_size_t size, const char *buf); /* The next scsi device. */ struct VasEBoot_scsi_dev *next; }; struct VasEBoot_scsi { /* The underlying scsi device. */ VasEBoot_scsi_dev_t dev; /* Type of SCSI device. XXX: Make enum. */ VasEBoot_uint8_t devtype; int bus; /* Number of LUNs. */ int luns; /* LUN for this `struct VasEBoot_scsi'. */ int lun; /* Set to 0 when not removable, 1 when removable. */ int removable; /* Size of the device in blocks - 1. */ VasEBoot_uint64_t last_block; /* Size of one block. */ VasEBoot_uint32_t blocksize; /* Device-specific data. */ void *data; }; typedef struct VasEBoot_scsi *VasEBoot_scsi_t; #endif /* VasEBoot_SCSI_H */