{
if (extdriveoffset >= ARRAY_SIZE(IDMap[0]))
return NULL;
- struct drive_s *drive_gf = GET_GLOBAL(IDMap[exttype][extdriveoffset]);
- if (!drive_gf)
- return NULL;
- return GLOBALFLAT2GLOBAL(drive_gf);
+ return GET_GLOBAL(IDMap[exttype][extdriveoffset]);
}
-int getDriveId(u8 exttype, struct drive_s *drive_g)
+int getDriveId(u8 exttype, struct drive_s *drive)
{
+ ASSERT32FLAT();
int i;
for (i = 0; i < ARRAY_SIZE(IDMap[0]); i++)
- if (getDrive(exttype, i) == drive_g)
+ if (getDrive(exttype, i) == drive)
return i;
return -1;
}
****************************************************************/
static u8
-get_translation(struct drive_s *drive_g)
+get_translation(struct drive_s *drive)
{
- u8 type = GET_GLOBAL(drive_g->type);
+ u8 type = drive->type;
if (CONFIG_QEMU && type == DTYPE_ATA) {
// Emulators pass in the translation info via nvram.
- u8 ataid = GET_GLOBAL(drive_g->cntl_id);
+ u8 ataid = drive->cntl_id;
u8 channel = ataid / 2;
u8 translation = rtc_read(CMOS_BIOS_DISKTRANSFLAG + channel/2);
translation >>= 2 * (ataid % 4);
}
// Otherwise use a heuristic to determine translation type.
- u16 heads = GET_GLOBAL(drive_g->pchs.head);
- u16 cylinders = GET_GLOBAL(drive_g->pchs.cylinder);
- u16 spt = GET_GLOBAL(drive_g->pchs.sector);
- u64 sectors = GET_GLOBAL(drive_g->sectors);
+ u16 heads = drive->pchs.head;
+ u16 cylinders = drive->pchs.cylinder;
+ u16 spt = drive->pchs.sector;
+ u64 sectors = drive->sectors;
u64 psectors = (u64)heads * cylinders * spt;
if (!heads || !cylinders || !spt || psectors > sectors)
// pchs doesn't look valid - use LBA.
}
static void
-setup_translation(struct drive_s *drive_g)
+setup_translation(struct drive_s *drive)
{
- u8 translation = get_translation(drive_g);
- SET_GLOBAL(drive_g->translation, translation);
+ u8 translation = get_translation(drive);
+ drive->translation = translation;
- u16 heads = GET_GLOBAL(drive_g->pchs.head);
- u16 cylinders = GET_GLOBAL(drive_g->pchs.cylinder);
- u16 spt = GET_GLOBAL(drive_g->pchs.sector);
- u64 sectors = GET_GLOBAL(drive_g->sectors);
+ u16 heads = drive->pchs.head ;
+ u16 cylinders = drive->pchs.cylinder;
+ u16 spt = drive->pchs.sector;
+ u64 sectors = drive->sectors;
const char *desc = NULL;
switch (translation) {
if (cylinders > 1024)
cylinders = 1024;
dprintf(1, "drive %p: PCHS=%u/%d/%d translation=%s LCHS=%d/%d/%d s=%d\n"
- , drive_g
- , drive_g->pchs.cylinder, drive_g->pchs.head, drive_g->pchs.sector
+ , drive
+ , drive->pchs.cylinder, drive->pchs.head, drive->pchs.sector
, desc
, cylinders, heads, spt
, (u32)sectors);
- SET_GLOBAL(drive_g->lchs.head, heads);
- SET_GLOBAL(drive_g->lchs.cylinder, cylinders);
- SET_GLOBAL(drive_g->lchs.sector, spt);
+ drive->lchs.head = heads;
+ drive->lchs.cylinder = cylinders;
+ drive->lchs.sector = spt;
}
// Fill in Fixed Disk Parameter Table (located in ebda).
static void
-fill_fdpt(struct drive_s *drive_g, int hdid)
+fill_fdpt(struct drive_s *drive, int hdid)
{
if (hdid > 1)
return;
- u16 nlc = GET_GLOBAL(drive_g->lchs.cylinder);
- u16 nlh = GET_GLOBAL(drive_g->lchs.head);
- u16 nls = GET_GLOBAL(drive_g->lchs.sector);
+ u16 nlc = drive->lchs.cylinder;
+ u16 nlh = drive->lchs.head;
+ u16 nls = drive->lchs.sector;
- u16 npc = GET_GLOBAL(drive_g->pchs.cylinder);
- u16 nph = GET_GLOBAL(drive_g->pchs.head);
- u16 nps = GET_GLOBAL(drive_g->pchs.sector);
+ u16 npc = drive->pchs.cylinder;
+ u16 nph = drive->pchs.head;
+ u16 nps = drive->pchs.sector;
struct fdpt_s *fdpt = &get_ebda_ptr()->fdpt[hdid];
fdpt->precompensation = 0xffff;
// Find spot to add a drive
static void
-add_drive(struct drive_s **idmap, u8 *count, struct drive_s *drive_g)
+add_drive(struct drive_s **idmap, u8 *count, struct drive_s *drive)
{
if (*count >= ARRAY_SIZE(IDMap[0])) {
warn_noalloc();
return;
}
- idmap[*count] = drive_g;
+ idmap[*count] = drive;
*count = *count + 1;
}
// Map a hard drive
void
-map_hd_drive(struct drive_s *drive_g)
+map_hd_drive(struct drive_s *drive)
{
ASSERT32FLAT();
struct bios_data_area_s *bda = MAKE_FLATPTR(SEG_BDA, 0);
int hdid = bda->hdcount;
- dprintf(3, "Mapping hd drive %p to %d\n", drive_g, hdid);
- add_drive(IDMap[EXTTYPE_HD], &bda->hdcount, drive_g);
+ dprintf(3, "Mapping hd drive %p to %d\n", drive, hdid);
+ add_drive(IDMap[EXTTYPE_HD], &bda->hdcount, drive);
// Setup disk geometry translation.
- setup_translation(drive_g);
+ setup_translation(drive);
// Fill "fdpt" structure.
- fill_fdpt(drive_g, hdid);
+ fill_fdpt(drive, hdid);
}
// Map a cd
void
-map_cd_drive(struct drive_s *drive_g)
+map_cd_drive(struct drive_s *drive)
{
- dprintf(3, "Mapping cd drive %p\n", drive_g);
- add_drive(IDMap[EXTTYPE_CD], &CDCount, drive_g);
+ ASSERT32FLAT();
+ dprintf(3, "Mapping cd drive %p\n", drive);
+ add_drive(IDMap[EXTTYPE_CD], &CDCount, drive);
}
// Map a floppy
void
-map_floppy_drive(struct drive_s *drive_g)
+map_floppy_drive(struct drive_s *drive)
{
- dprintf(3, "Mapping floppy drive %p\n", drive_g);
- add_drive(IDMap[EXTTYPE_FLOPPY], &FloppyCount, drive_g);
+ ASSERT32FLAT();
+ dprintf(3, "Mapping floppy drive %p\n", drive);
+ add_drive(IDMap[EXTTYPE_FLOPPY], &FloppyCount, drive);
// Update equipment word bits for floppy
if (FloppyCount == 1) {
process_op(struct disk_op_s *op)
{
ASSERT16();
- u8 type = GET_GLOBAL(op->drive_g->type);
+ u8 type = GET_GLOBALFLAT(op->drive_gf->type);
switch (type) {
case DTYPE_FLOPPY:
return process_floppy_op(op);
return process_cdemu_op(op);
case DTYPE_VIRTIO_BLK:
return process_virtio_blk_op(op);
- case DTYPE_AHCI:
- op->drive_g = (void*)op->drive_g + BUILD_BIOS_ADDR;
+ case DTYPE_AHCI: ;
extern void _cfunc32flat_process_ahci_op(void);
return call32(_cfunc32flat_process_ahci_op
, (u32)MAKE_FLATPTR(GET_SEG(SS), op), DISK_RET_EPARAM);
case DTYPE_ATA_ATAPI:
return process_atapi_op(op);
- case DTYPE_AHCI_ATAPI:
- op->drive_g = (void*)op->drive_g + BUILD_BIOS_ADDR;
+ case DTYPE_AHCI_ATAPI: ;
extern void _cfunc32flat_process_atapi_op(void);
return call32(_cfunc32flat_process_atapi_op
, (u32)MAKE_FLATPTR(GET_SEG(SS), op), DISK_RET_EPARAM);
, sizeof(dop));
dprintf(DEBUG_HDL_13, "disk_op d=%p lba=%d buf=%p count=%d cmd=%d\n"
- , dop.drive_g, (u32)dop.lba, dop.buf_fl
+ , dop.drive_gf, (u32)dop.lba, dop.buf_fl
, dop.count, dop.command);
int status = process_op(&dop);
struct disk_op_s {
u64 lba;
void *buf_fl;
- struct drive_s *drive_g;
+ struct drive_s *drive_gf;
u16 count;
u8 command;
};
extern u8 FloppyCount, CDCount;
extern u8 *bounce_buf_fl;
struct drive_s *getDrive(u8 exttype, u8 extdriveoffset);
-int getDriveId(u8 exttype, struct drive_s *drive_g);
-void map_floppy_drive(struct drive_s *drive_g);
-void map_hd_drive(struct drive_s *drive_g);
-void map_cd_drive(struct drive_s *drive_g);
+int getDriveId(u8 exttype, struct drive_s *drive);
+void map_floppy_drive(struct drive_s *drive);
+void map_hd_drive(struct drive_s *drive);
+void map_cd_drive(struct drive_s *drive);
struct bregs;
void __disk_ret(struct bregs *regs, u32 linecode, const char *fname);
void __disk_ret_unimplemented(struct bregs *regs, u32 linecode
static int
cdemu_read(struct disk_op_s *op)
{
- struct drive_s *drive_g;
- drive_g = GLOBALFLAT2GLOBAL(GET_LOW(CDEmu.emulated_drive_gf));
+ struct drive_s *drive_gf = GET_LOW(CDEmu.emulated_drive_gf);
struct disk_op_s dop;
- dop.drive_g = drive_g;
+ dop.drive_gf = drive_gf;
dop.command = op->command;
dop.lba = GET_LOW(CDEmu.ilba) + op->lba / 4;
if (create_bounce_buf() < 0)
return;
- struct drive_s *drive_g = malloc_fseg(sizeof(*drive_g));
- if (!drive_g) {
+ struct drive_s *drive = malloc_fseg(sizeof(*drive));
+ if (!drive) {
warn_noalloc();
- free(drive_g);
+ free(drive);
return;
}
- cdemu_drive_gf = drive_g;
- memset(drive_g, 0, sizeof(*drive_g));
- drive_g->type = DTYPE_CDEMU;
- drive_g->blksize = DISK_SECTOR_SIZE;
- drive_g->sectors = (u64)-1;
+ cdemu_drive_gf = drive;
+ memset(drive, 0, sizeof(*drive));
+ drive->type = DTYPE_CDEMU;
+ drive->blksize = DISK_SECTOR_SIZE;
+ drive->sectors = (u64)-1;
}
#define SET_INT13ET(regs,var,val) \
****************************************************************/
int
-cdrom_boot(struct drive_s *drive_g)
+cdrom_boot(struct drive_s *drive)
{
ASSERT32FLAT();
struct disk_op_s dop;
- int cdid = getDriveId(EXTTYPE_CD, drive_g);
+ int cdid = getDriveId(EXTTYPE_CD, drive);
memset(&dop, 0, sizeof(dop));
- dop.drive_g = drive_g;
- if (!dop.drive_g || cdid < 0)
+ dop.drive_gf = drive;
+ if (!dop.drive_gf || cdid < 0)
return 1;
int ret = scsi_is_ready(&dop);
u8 media = buffer[0x21];
CDEmu.media = media;
- CDEmu.emulated_drive_gf = dop.drive_g;
+ CDEmu.emulated_drive_gf = dop.drive_gf;
u16 boot_segment = *(u16*)&buffer[0x22];
if (!boot_segment)
// Get the cylinders/heads/sectors for the given drive.
static struct chs_s
-getLCHS(struct drive_s *drive_g)
+getLCHS(struct drive_s *drive_gf)
{
struct chs_s res = { };
- if (CONFIG_CDROM_EMU
- && drive_g == GLOBALFLAT2GLOBAL(GET_GLOBAL(cdemu_drive_gf))) {
+ if (CONFIG_CDROM_EMU && drive_gf == GET_GLOBAL(cdemu_drive_gf)) {
// Emulated drive - get info from CDEmu. (It's not possible to
// populate the geometry directly in the driveid because the
// geometry is only known after the bios segment is made
res.sector = GET_LOW(CDEmu.lchs.sector);
return res;
}
- res.cylinder = GET_GLOBAL(drive_g->lchs.cylinder);
- res.head = GET_GLOBAL(drive_g->lchs.head);
- res.sector = GET_GLOBAL(drive_g->lchs.sector);
+ res.cylinder = GET_GLOBALFLAT(drive_gf->lchs.cylinder);
+ res.head = GET_GLOBALFLAT(drive_gf->lchs.head);
+ res.sector = GET_GLOBALFLAT(drive_gf->lchs.sector);
return res;
}
// Perform read/write/verify using old-style chs accesses
static void noinline
-basic_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
+basic_access(struct bregs *regs, struct drive_s *drive_gf, u16 command)
{
struct disk_op_s dop;
- dop.drive_g = drive_g;
+ dop.drive_gf = drive_gf;
dop.command = command;
u8 count = regs->al;
}
dop.count = count;
- struct chs_s chs = getLCHS(drive_g);
+ struct chs_s chs = getLCHS(drive_gf);
u16 nlc=chs.cylinder, nlh=chs.head, nls=chs.sector;
// sanity check on cyl heads, sec
// Perform read/write/verify using new-style "int13ext" accesses.
static void noinline
-extended_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
+extended_access(struct bregs *regs, struct drive_s *drive_gf, u16 command)
{
struct disk_op_s dop;
struct int13ext_s *param_far = (struct int13ext_s*)(regs->si+0);
// Get lba and check.
dop.lba = GET_FARVAR(regs->ds, param_far->lba);
dop.command = command;
- dop.drive_g = drive_g;
- if (dop.lba >= GET_GLOBAL(drive_g->sectors)) {
+ dop.drive_gf = drive_gf;
+ if (dop.lba >= GET_GLOBALFLAT(drive_gf->sectors)) {
warn_invalid(regs);
disk_ret(regs, DISK_RET_EPARAM);
return;
// disk controller reset
static void
-disk_1300(struct bregs *regs, struct drive_s *drive_g)
+disk_1300(struct bregs *regs, struct drive_s *drive_gf)
{
struct disk_op_s dop;
- dop.drive_g = drive_g;
+ dop.drive_gf = drive_gf;
dop.command = CMD_RESET;
int status = send_disk_op(&dop);
disk_ret(regs, status);
// read disk status
static void
-disk_1301(struct bregs *regs, struct drive_s *drive_g)
+disk_1301(struct bregs *regs, struct drive_s *drive_gf)
{
u8 v;
if (regs->dl < EXTSTART_HD)
// read disk sectors
static void
-disk_1302(struct bregs *regs, struct drive_s *drive_g)
+disk_1302(struct bregs *regs, struct drive_s *drive_gf)
{
- basic_access(regs, drive_g, CMD_READ);
+ basic_access(regs, drive_gf, CMD_READ);
}
// write disk sectors
static void
-disk_1303(struct bregs *regs, struct drive_s *drive_g)
+disk_1303(struct bregs *regs, struct drive_s *drive_gf)
{
- basic_access(regs, drive_g, CMD_WRITE);
+ basic_access(regs, drive_gf, CMD_WRITE);
}
// verify disk sectors
static void
-disk_1304(struct bregs *regs, struct drive_s *drive_g)
+disk_1304(struct bregs *regs, struct drive_s *drive_gf)
{
- basic_access(regs, drive_g, CMD_VERIFY);
+ basic_access(regs, drive_gf, CMD_VERIFY);
}
// format disk track
static void noinline
-disk_1305(struct bregs *regs, struct drive_s *drive_g)
+disk_1305(struct bregs *regs, struct drive_s *drive_gf)
{
debug_stub(regs);
- struct chs_s chs = getLCHS(drive_g);
+ struct chs_s chs = getLCHS(drive_gf);
u16 nlh=chs.head, nls=chs.sector;
u8 num_sectors = regs->al;
}
struct disk_op_s dop;
- dop.drive_g = drive_g;
+ dop.drive_gf = drive_gf;
dop.command = CMD_FORMAT;
dop.lba = head;
dop.count = num_sectors;
// read disk drive parameters
static void noinline
-disk_1308(struct bregs *regs, struct drive_s *drive_g)
+disk_1308(struct bregs *regs, struct drive_s *drive_gf)
{
// Get logical geometry from table
- struct chs_s chs = getLCHS(drive_g);
+ struct chs_s chs = getLCHS(drive_gf);
u16 nlc=chs.cylinder, nlh=chs.head, nls=chs.sector;
nlc--;
nlh--;
// Floppy
count = GET_GLOBAL(FloppyCount);
- if (CONFIG_CDROM_EMU
- && drive_g == GLOBALFLAT2GLOBAL(GET_GLOBAL(cdemu_drive_gf)))
+ if (CONFIG_CDROM_EMU && drive_gf == GET_GLOBAL(cdemu_drive_gf))
regs->bx = GET_LOW(CDEmu.media) * 2;
else
- regs->bx = GET_GLOBAL(drive_g->floppy_type);
+ regs->bx = GET_GLOBALFLAT(drive_gf->floppy_type);
// set es & di to point to 11 byte diskette param table in ROM
regs->es = SEG_BIOS;
// initialize drive parameters
static void
-disk_1309(struct bregs *regs, struct drive_s *drive_g)
+disk_1309(struct bregs *regs, struct drive_s *drive_gf)
{
DISK_STUB(regs);
}
// seek to specified cylinder
static void
-disk_130c(struct bregs *regs, struct drive_s *drive_g)
+disk_130c(struct bregs *regs, struct drive_s *drive_gf)
{
DISK_STUB(regs);
}
// alternate disk reset
static void
-disk_130d(struct bregs *regs, struct drive_s *drive_g)
+disk_130d(struct bregs *regs, struct drive_s *drive_gf)
{
DISK_STUB(regs);
}
// check drive ready
static void
-disk_1310(struct bregs *regs, struct drive_s *drive_g)
+disk_1310(struct bregs *regs, struct drive_s *drive_gf)
{
// should look at 40:8E also???
struct disk_op_s dop;
- dop.drive_g = drive_g;
+ dop.drive_gf = drive_gf;
dop.command = CMD_ISREADY;
int status = send_disk_op(&dop);
disk_ret(regs, status);
// recalibrate
static void
-disk_1311(struct bregs *regs, struct drive_s *drive_g)
+disk_1311(struct bregs *regs, struct drive_s *drive_gf)
{
DISK_STUB(regs);
}
// controller internal diagnostic
static void
-disk_1314(struct bregs *regs, struct drive_s *drive_g)
+disk_1314(struct bregs *regs, struct drive_s *drive_gf)
{
DISK_STUB(regs);
}
// read disk drive size
static void noinline
-disk_1315(struct bregs *regs, struct drive_s *drive_g)
+disk_1315(struct bregs *regs, struct drive_s *drive_gf)
{
disk_ret(regs, DISK_RET_SUCCESS);
if (regs->dl < EXTSTART_HD || regs->dl >= EXTSTART_CD) {
// Hard drive
// Get logical geometry from table
- struct chs_s chs = getLCHS(drive_g);
+ struct chs_s chs = getLCHS(drive_gf);
u16 nlc=chs.cylinder, nlh=chs.head, nls=chs.sector;
// Compute sector count seen by int13
}
static void
-disk_1316(struct bregs *regs, struct drive_s *drive_g)
+disk_1316(struct bregs *regs, struct drive_s *drive_gf)
{
if (regs->dl >= EXTSTART_HD) {
// Hard drive
// IBM/MS installation check
static void
-disk_1341(struct bregs *regs, struct drive_s *drive_g)
+disk_1341(struct bregs *regs, struct drive_s *drive_gf)
{
regs->bx = 0xaa55; // install check
regs->cx = 0x0007; // ext disk access and edd, removable supported
// IBM/MS extended read
static void
-disk_1342(struct bregs *regs, struct drive_s *drive_g)
+disk_1342(struct bregs *regs, struct drive_s *drive_gf)
{
- extended_access(regs, drive_g, CMD_READ);
+ extended_access(regs, drive_gf, CMD_READ);
}
// IBM/MS extended write
static void
-disk_1343(struct bregs *regs, struct drive_s *drive_g)
+disk_1343(struct bregs *regs, struct drive_s *drive_gf)
{
- extended_access(regs, drive_g, CMD_WRITE);
+ extended_access(regs, drive_gf, CMD_WRITE);
}
// IBM/MS verify
static void
-disk_1344(struct bregs *regs, struct drive_s *drive_g)
+disk_1344(struct bregs *regs, struct drive_s *drive_gf)
{
- extended_access(regs, drive_g, CMD_VERIFY);
+ extended_access(regs, drive_gf, CMD_VERIFY);
}
// lock
static void
-disk_134500(struct bregs *regs, struct drive_s *drive_g)
+disk_134500(struct bregs *regs, struct drive_s *drive_gf)
{
int cdid = regs->dl - EXTSTART_CD;
u8 locks = GET_LOW(CDRom_locks[cdid]);
// unlock
static void
-disk_134501(struct bregs *regs, struct drive_s *drive_g)
+disk_134501(struct bregs *regs, struct drive_s *drive_gf)
{
int cdid = regs->dl - EXTSTART_CD;
u8 locks = GET_LOW(CDRom_locks[cdid]);
// status
static void
-disk_134502(struct bregs *regs, struct drive_s *drive_g)
+disk_134502(struct bregs *regs, struct drive_s *drive_gf)
{
int cdid = regs->dl - EXTSTART_CD;
u8 locks = GET_LOW(CDRom_locks[cdid]);
}
static void
-disk_1345XX(struct bregs *regs, struct drive_s *drive_g)
+disk_1345XX(struct bregs *regs, struct drive_s *drive_gf)
{
disk_ret_unimplemented(regs, DISK_RET_EPARAM);
}
// IBM/MS lock/unlock drive
static void
-disk_1345(struct bregs *regs, struct drive_s *drive_g)
+disk_1345(struct bregs *regs, struct drive_s *drive_gf)
{
if (regs->dl < EXTSTART_CD) {
// Always success for HD
}
switch (regs->al) {
- case 0x00: disk_134500(regs, drive_g); break;
- case 0x01: disk_134501(regs, drive_g); break;
- case 0x02: disk_134502(regs, drive_g); break;
- default: disk_1345XX(regs, drive_g); break;
+ case 0x00: disk_134500(regs, drive_gf); break;
+ case 0x01: disk_134501(regs, drive_gf); break;
+ case 0x02: disk_134502(regs, drive_gf); break;
+ default: disk_1345XX(regs, drive_gf); break;
}
}
// IBM/MS eject media
static void noinline
-disk_1346(struct bregs *regs, struct drive_s *drive_g)
+disk_1346(struct bregs *regs, struct drive_s *drive_gf)
{
if (regs->dl < EXTSTART_CD) {
// Volume Not Removable
// IBM/MS extended seek
static void
-disk_1347(struct bregs *regs, struct drive_s *drive_g)
+disk_1347(struct bregs *regs, struct drive_s *drive_gf)
{
- extended_access(regs, drive_g, CMD_SEEK);
+ extended_access(regs, drive_gf, CMD_SEEK);
}
// IBM/MS get drive parameters
static void noinline
-disk_1348(struct bregs *regs, struct drive_s *drive_g)
+disk_1348(struct bregs *regs, struct drive_s *drive_gf)
{
u16 seg = regs->ds;
struct int13dpt_s *param_far = (struct int13dpt_s*)(regs->si+0);
// EDD 1.x
- u8 type = GET_GLOBAL(drive_g->type);
- u16 npc = GET_GLOBAL(drive_g->pchs.cylinder);
- u16 nph = GET_GLOBAL(drive_g->pchs.head);
- u16 nps = GET_GLOBAL(drive_g->pchs.sector);
- u64 lba = GET_GLOBAL(drive_g->sectors);
- u16 blksize = GET_GLOBAL(drive_g->blksize);
+ u8 type = GET_GLOBALFLAT(drive_gf->type);
+ u16 npc = GET_GLOBALFLAT(drive_gf->pchs.cylinder);
+ u16 nph = GET_GLOBALFLAT(drive_gf->pchs.head);
+ u16 nps = GET_GLOBALFLAT(drive_gf->pchs.sector);
+ u64 lba = GET_GLOBALFLAT(drive_gf->sectors);
+ u16 blksize = GET_GLOBALFLAT(drive_gf->blksize);
dprintf(DEBUG_HDL_13, "disk_1348 size=%d t=%d chs=%d,%d,%d lba=%d bs=%d\n"
, size, type, npc, nph, nps, (u32)lba, blksize);
SET_FARVAR(seg, param_far->dpte, SEGOFF(SEG_LOW, (u32)&DefaultDPTE));
// Fill in dpte
- struct atadrive_s *adrive_g = container_of(
- drive_g, struct atadrive_s, drive);
- struct ata_channel_s *chan_gf = GET_GLOBAL(adrive_g->chan_gf);
- u8 slave = GET_GLOBAL(adrive_g->slave);
+ struct atadrive_s *adrive_gf = container_of(
+ drive_gf, struct atadrive_s, drive);
+ struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
+ u8 slave = GET_GLOBALFLAT(adrive_gf->slave);
u16 iobase2 = GET_GLOBALFLAT(chan_gf->iobase2);
u8 irq = GET_GLOBALFLAT(chan_gf->irq);
iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
u16 options = 0;
if (type == DTYPE_ATA) {
- u8 translation = GET_GLOBAL(drive_g->translation);
+ u8 translation = GET_GLOBALFLAT(drive_gf->translation);
if (translation != TRANSLATION_NONE) {
options |= 1<<3; // CHS translation
if (translation == TRANSLATION_LBA)
SET_LOW(DefaultDPTE.checksum, -sum);
} else {
SET_FARVAR(seg, param_far->dpte.segoff, 0xffffffff);
- bdf = GET_GLOBAL(drive_g->cntl_id);
+ bdf = GET_GLOBALFLAT(drive_gf->cntl_id);
}
if (size < 66) {
// IBM/MS extended media change
static void
-disk_1349(struct bregs *regs, struct drive_s *drive_g)
+disk_1349(struct bregs *regs, struct drive_s *drive_gf)
{
if (regs->dl < EXTSTART_CD) {
// Always success for HD
}
static void
-disk_134e01(struct bregs *regs, struct drive_s *drive_g)
+disk_134e01(struct bregs *regs, struct drive_s *drive_gf)
{
disk_ret(regs, DISK_RET_SUCCESS);
}
static void
-disk_134e03(struct bregs *regs, struct drive_s *drive_g)
+disk_134e03(struct bregs *regs, struct drive_s *drive_gf)
{
disk_ret(regs, DISK_RET_SUCCESS);
}
static void
-disk_134e04(struct bregs *regs, struct drive_s *drive_g)
+disk_134e04(struct bregs *regs, struct drive_s *drive_gf)
{
disk_ret(regs, DISK_RET_SUCCESS);
}
static void
-disk_134e06(struct bregs *regs, struct drive_s *drive_g)
+disk_134e06(struct bregs *regs, struct drive_s *drive_gf)
{
disk_ret(regs, DISK_RET_SUCCESS);
}
static void
-disk_134eXX(struct bregs *regs, struct drive_s *drive_g)
+disk_134eXX(struct bregs *regs, struct drive_s *drive_gf)
{
disk_ret(regs, DISK_RET_EPARAM);
}
// IBM/MS set hardware configuration
static void
-disk_134e(struct bregs *regs, struct drive_s *drive_g)
+disk_134e(struct bregs *regs, struct drive_s *drive_gf)
{
switch (regs->al) {
- case 0x01: disk_134e01(regs, drive_g); break;
- case 0x03: disk_134e03(regs, drive_g); break;
- case 0x04: disk_134e04(regs, drive_g); break;
- case 0x06: disk_134e06(regs, drive_g); break;
- default: disk_134eXX(regs, drive_g); break;
+ case 0x01: disk_134e01(regs, drive_gf); break;
+ case 0x03: disk_134e03(regs, drive_gf); break;
+ case 0x04: disk_134e04(regs, drive_gf); break;
+ case 0x06: disk_134e06(regs, drive_gf); break;
+ default: disk_134eXX(regs, drive_gf); break;
}
}
static void
-disk_13XX(struct bregs *regs, struct drive_s *drive_g)
+disk_13XX(struct bregs *regs, struct drive_s *drive_gf)
{
disk_ret_unimplemented(regs, DISK_RET_EPARAM);
}
static void
-disk_13(struct bregs *regs, struct drive_s *drive_g)
+disk_13(struct bregs *regs, struct drive_s *drive_gf)
{
//debug_stub(regs);
SET_BDA(disk_interrupt_flag, 0);
switch (regs->ah) {
- case 0x00: disk_1300(regs, drive_g); break;
- case 0x01: disk_1301(regs, drive_g); break;
- case 0x02: disk_1302(regs, drive_g); break;
- case 0x03: disk_1303(regs, drive_g); break;
- case 0x04: disk_1304(regs, drive_g); break;
- case 0x05: disk_1305(regs, drive_g); break;
- case 0x08: disk_1308(regs, drive_g); break;
- case 0x09: disk_1309(regs, drive_g); break;
- case 0x0c: disk_130c(regs, drive_g); break;
- case 0x0d: disk_130d(regs, drive_g); break;
- case 0x10: disk_1310(regs, drive_g); break;
- case 0x11: disk_1311(regs, drive_g); break;
- case 0x14: disk_1314(regs, drive_g); break;
- case 0x15: disk_1315(regs, drive_g); break;
- case 0x16: disk_1316(regs, drive_g); break;
- case 0x41: disk_1341(regs, drive_g); break;
- case 0x42: disk_1342(regs, drive_g); break;
- case 0x43: disk_1343(regs, drive_g); break;
- case 0x44: disk_1344(regs, drive_g); break;
- case 0x45: disk_1345(regs, drive_g); break;
- case 0x46: disk_1346(regs, drive_g); break;
- case 0x47: disk_1347(regs, drive_g); break;
- case 0x48: disk_1348(regs, drive_g); break;
- case 0x49: disk_1349(regs, drive_g); break;
- case 0x4e: disk_134e(regs, drive_g); break;
- default: disk_13XX(regs, drive_g); break;
- }
-}
-
-static void
-floppy_13(struct bregs *regs, struct drive_s *drive_g)
+ case 0x00: disk_1300(regs, drive_gf); break;
+ case 0x01: disk_1301(regs, drive_gf); break;
+ case 0x02: disk_1302(regs, drive_gf); break;
+ case 0x03: disk_1303(regs, drive_gf); break;
+ case 0x04: disk_1304(regs, drive_gf); break;
+ case 0x05: disk_1305(regs, drive_gf); break;
+ case 0x08: disk_1308(regs, drive_gf); break;
+ case 0x09: disk_1309(regs, drive_gf); break;
+ case 0x0c: disk_130c(regs, drive_gf); break;
+ case 0x0d: disk_130d(regs, drive_gf); break;
+ case 0x10: disk_1310(regs, drive_gf); break;
+ case 0x11: disk_1311(regs, drive_gf); break;
+ case 0x14: disk_1314(regs, drive_gf); break;
+ case 0x15: disk_1315(regs, drive_gf); break;
+ case 0x16: disk_1316(regs, drive_gf); break;
+ case 0x41: disk_1341(regs, drive_gf); break;
+ case 0x42: disk_1342(regs, drive_gf); break;
+ case 0x43: disk_1343(regs, drive_gf); break;
+ case 0x44: disk_1344(regs, drive_gf); break;
+ case 0x45: disk_1345(regs, drive_gf); break;
+ case 0x46: disk_1346(regs, drive_gf); break;
+ case 0x47: disk_1347(regs, drive_gf); break;
+ case 0x48: disk_1348(regs, drive_gf); break;
+ case 0x49: disk_1349(regs, drive_gf); break;
+ case 0x4e: disk_134e(regs, drive_gf); break;
+ default: disk_13XX(regs, drive_gf); break;
+ }
+}
+
+static void
+floppy_13(struct bregs *regs, struct drive_s *drive_gf)
{
// Only limited commands are supported on floppies.
switch (regs->ah) {
case 0x08:
case 0x15:
case 0x16:
- disk_13(regs, drive_g);
+ disk_13(regs, drive_gf);
break;
- default: disk_13XX(regs, drive_g); break;
+ default: disk_13XX(regs, drive_gf); break;
}
}
}
if (extdrive < EXTSTART_HD) {
- struct drive_s *drive_g = getDrive(EXTTYPE_FLOPPY, extdrive);
- if (!drive_g)
+ struct drive_s *drive_gf = getDrive(EXTTYPE_FLOPPY, extdrive);
+ if (!drive_gf)
goto fail;
- floppy_13(regs, drive_g);
+ floppy_13(regs, drive_gf);
return;
}
- struct drive_s *drive_g;
+ struct drive_s *drive_gf;
if (extdrive >= EXTSTART_CD)
- drive_g = getDrive(EXTTYPE_CD, extdrive - EXTSTART_CD);
+ drive_gf = getDrive(EXTTYPE_CD, extdrive - EXTSTART_CD);
else
- drive_g = getDrive(EXTTYPE_HD, extdrive - EXTSTART_HD);
- if (!drive_g)
+ drive_gf = getDrive(EXTTYPE_HD, extdrive - EXTSTART_HD);
+ if (!drive_gf)
goto fail;
- disk_13(regs, drive_g);
+ disk_13(regs, drive_gf);
return;
fail:
u8 emudrive = GET_LOW(CDEmu.emulated_extdrive);
if (extdrive == emudrive) {
// Access to an emulated drive.
- struct drive_s *cdemu_g;
- cdemu_g = GLOBALFLAT2GLOBAL(GET_GLOBAL(cdemu_drive_gf));
+ struct drive_s *cdemu_gf = GET_GLOBAL(cdemu_drive_gf);
if (regs->ah > 0x16) {
// Only old-style commands supported.
- disk_13XX(regs, cdemu_g);
+ disk_13XX(regs, cdemu_gf);
return;
}
- disk_13(regs, cdemu_g);
+ disk_13(regs, cdemu_gf);
return;
}
if (extdrive < EXTSTART_CD && ((emudrive ^ extdrive) & 0x80) == 0)
}
// submit ahci command + wait for result
-static int ahci_command(struct ahci_port_s *port, int iswrite, int isatapi,
+static int ahci_command(struct ahci_port_s *port_gf, int iswrite, int isatapi,
void *buffer, u32 bsize)
{
u32 val, status, success, flags, intbits, error;
- struct ahci_ctrl_s *ctrl = GET_GLOBAL(port->ctrl);
- struct ahci_cmd_s *cmd = GET_GLOBAL(port->cmd);
- struct ahci_fis_s *fis = GET_GLOBAL(port->fis);
- struct ahci_list_s *list = GET_GLOBAL(port->list);
- u32 pnr = GET_GLOBAL(port->pnr);
+ struct ahci_ctrl_s *ctrl = GET_GLOBALFLAT(port_gf->ctrl);
+ struct ahci_cmd_s *cmd = GET_GLOBALFLAT(port_gf->cmd);
+ struct ahci_fis_s *fis = GET_GLOBALFLAT(port_gf->fis);
+ struct ahci_list_s *list = GET_GLOBALFLAT(port_gf->list);
+ u32 pnr = GET_GLOBALFLAT(port_gf->pnr);
SET_LOWFLAT(cmd->fis.reg, 0x27);
SET_LOWFLAT(cmd->fis.pmp_type, (1 << 7)); /* cmd fis */
if (! CONFIG_AHCI)
return 0;
- struct ahci_port_s *port = container_of(
- op->drive_g, struct ahci_port_s, drive);
- struct ahci_cmd_s *cmd = GET_GLOBAL(port->cmd);
+ struct ahci_port_s *port_gf = container_of(
+ op->drive_gf, struct ahci_port_s, drive);
+ struct ahci_cmd_s *cmd = GET_GLOBALFLAT(port_gf->cmd);
u8 *atapi = cdbcmd;
int i, rc;
for (i = 0; i < CDROM_CDB_SIZE; i++) {
SET_LOWFLAT(cmd->atapi[i], atapi[i]);
}
- rc = ahci_command(port, 0, 1, op->buf_fl,
+ rc = ahci_command(port_gf, 0, 1, op->buf_fl,
op->count * blocksize);
if (rc < 0)
return DISK_RET_EBADTRACK;
static int
ahci_disk_readwrite_aligned(struct disk_op_s *op, int iswrite)
{
- struct ahci_port_s *port = container_of(
- op->drive_g, struct ahci_port_s, drive);
- struct ahci_cmd_s *cmd = GET_GLOBAL(port->cmd);
+ struct ahci_port_s *port_gf = container_of(
+ op->drive_gf, struct ahci_port_s, drive);
+ struct ahci_cmd_s *cmd = GET_GLOBALFLAT(port_gf->cmd);
int rc;
sata_prep_readwrite(&cmd->fis, op, iswrite);
- rc = ahci_command(port, iswrite, 0, op->buf_fl,
+ rc = ahci_command(port_gf, iswrite, 0, op->buf_fl,
op->count * DISK_SECTOR_SIZE);
dprintf(8, "ahci disk %s, lba %6x, count %3x, buf %p, rc %d\n",
iswrite ? "write" : "read", (u32)op->lba, op->count, op->buf_fl, rc);
// This file may be distributed under the terms of the GNU LGPLv3 license.
#include "ata.h" // ATA_CB_STAT
-#include "biosvar.h" // GET_GLOBAL
+#include "biosvar.h" // GET_GLOBALFLAT
#include "block.h" // struct drive_s
#include "blockcmd.h" // CDB_CMD_READ_10
#include "byteorder.h" // be16_to_cpu
// Reset a drive
static void
-ata_reset(struct atadrive_s *adrive_g)
+ata_reset(struct atadrive_s *adrive_gf)
{
- struct ata_channel_s *chan_gf = GET_GLOBAL(adrive_g->chan_gf);
- u8 slave = GET_GLOBAL(adrive_g->slave);
+ struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
+ u8 slave = GET_GLOBALFLAT(adrive_gf->slave);
u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
u16 iobase2 = GET_GLOBALFLAT(chan_gf->iobase2);
- dprintf(6, "ata_reset drive=%p\n", &adrive_g->drive);
+ dprintf(6, "ata_reset drive=%p\n", &adrive_gf->drive);
// Pulse SRST
outb(ATA_CB_DC_HD15 | ATA_CB_DC_NIEN | ATA_CB_DC_SRST, iobase2+ATA_CB_DC);
udelay(5);
}
// On a user-reset request, wait for RDY if it is an ATA device.
- u8 type=GET_GLOBAL(adrive_g->drive.type);
+ u8 type=GET_GLOBALFLAT(adrive_gf->drive.type);
if (type == DTYPE_ATA)
status = await_rdy(iobase1);
// Check for drive RDY for 16bit interface command.
static int
-isready(struct atadrive_s *adrive_g)
+isready(struct atadrive_s *adrive_gf)
{
// Read the status from controller
- struct ata_channel_s *chan_gf = GET_GLOBAL(adrive_g->chan_gf);
+ struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
u8 status = inb(iobase1 + ATA_CB_STAT);
if ((status & (ATA_CB_STAT_BSY|ATA_CB_STAT_RDY)) == ATA_CB_STAT_RDY)
// Send an ata command to the drive.
static int
-send_cmd(struct atadrive_s *adrive_g, struct ata_pio_command *cmd)
+send_cmd(struct atadrive_s *adrive_gf, struct ata_pio_command *cmd)
{
- struct ata_channel_s *chan_gf = GET_GLOBAL(adrive_g->chan_gf);
- u8 slave = GET_GLOBAL(adrive_g->slave);
+ struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
+ u8 slave = GET_GLOBALFLAT(adrive_gf->slave);
u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
// Select device
// Send an ata command that does not transfer any further data.
int
-ata_cmd_nondata(struct atadrive_s *adrive_g, struct ata_pio_command *cmd)
+ata_cmd_nondata(struct atadrive_s *adrive_gf, struct ata_pio_command *cmd)
{
- struct ata_channel_s *chan_gf = GET_GLOBAL(adrive_g->chan_gf);
+ struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
u16 iobase2 = GET_GLOBALFLAT(chan_gf->iobase2);
// Disable interrupts
outb(ATA_CB_DC_HD15 | ATA_CB_DC_NIEN, iobase2 + ATA_CB_DC);
- int ret = send_cmd(adrive_g, cmd);
+ int ret = send_cmd(adrive_gf, cmd);
if (ret)
goto fail;
ret = ndelay_await_not_bsy(iobase1);
****************************************************************/
// Transfer 'op->count' blocks (of 'blocksize' bytes) to/from drive
-// 'op->drive_g'.
+// 'op->drive_gf'.
static int
ata_pio_transfer(struct disk_op_s *op, int iswrite, int blocksize)
{
dprintf(16, "ata_pio_transfer id=%p write=%d count=%d bs=%d buf=%p\n"
- , op->drive_g, iswrite, op->count, blocksize, op->buf_fl);
+ , op->drive_gf, iswrite, op->count, blocksize, op->buf_fl);
- struct atadrive_s *adrive_g = container_of(
- op->drive_g, struct atadrive_s, drive);
- struct ata_channel_s *chan_gf = GET_GLOBAL(adrive_g->chan_gf);
+ struct atadrive_s *adrive_gf = container_of(
+ op->drive_gf, struct atadrive_s, drive);
+ struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
u16 iobase2 = GET_GLOBALFLAT(chan_gf->iobase2);
int count = op->count;
for (;;) {
if (iswrite) {
// Write data to controller
- dprintf(16, "Write sector id=%p dest=%p\n", op->drive_g, buf_fl);
+ dprintf(16, "Write sector id=%p dest=%p\n", op->drive_gf, buf_fl);
if (CONFIG_ATA_PIO32)
outsl_fl(iobase1, buf_fl, blocksize / 4);
else
outsw_fl(iobase1, buf_fl, blocksize / 2);
} else {
// Read data from controller
- dprintf(16, "Read sector id=%p dest=%p\n", op->drive_g, buf_fl);
+ dprintf(16, "Read sector id=%p dest=%p\n", op->drive_gf, buf_fl);
if (CONFIG_ATA_PIO32)
insl_fl(iobase1, buf_fl, blocksize / 4);
else
if (dest & 1)
// Need minimum alignment of 1.
return -1;
- struct atadrive_s *adrive_g = container_of(
- op->drive_g, struct atadrive_s, drive);
- struct ata_channel_s *chan_gf = GET_GLOBAL(adrive_g->chan_gf);
+ struct atadrive_s *adrive_gf = container_of(
+ op->drive_gf, struct atadrive_s, drive);
+ struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
u16 iomaster = GET_GLOBALFLAT(chan_gf->iomaster);
if (! iomaster)
return -1;
{
if (! CONFIG_ATA_DMA)
return -1;
- dprintf(16, "ata_dma_transfer id=%p buf=%p\n", op->drive_g, op->buf_fl);
+ dprintf(16, "ata_dma_transfer id=%p buf=%p\n", op->drive_gf, op->buf_fl);
- struct atadrive_s *adrive_g = container_of(
- op->drive_g, struct atadrive_s, drive);
- struct ata_channel_s *chan_gf = GET_GLOBAL(adrive_g->chan_gf);
+ struct atadrive_s *adrive_gf = container_of(
+ op->drive_gf, struct atadrive_s, drive);
+ struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
u16 iomaster = GET_GLOBALFLAT(chan_gf->iomaster);
// Start bus-master controller.
static int
ata_pio_cmd_data(struct disk_op_s *op, int iswrite, struct ata_pio_command *cmd)
{
- struct atadrive_s *adrive_g = container_of(
- op->drive_g, struct atadrive_s, drive);
- struct ata_channel_s *chan_gf = GET_GLOBAL(adrive_g->chan_gf);
+ struct atadrive_s *adrive_gf = container_of(
+ op->drive_gf, struct atadrive_s, drive);
+ struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
u16 iobase2 = GET_GLOBALFLAT(chan_gf->iobase2);
// Disable interrupts
outb(ATA_CB_DC_HD15 | ATA_CB_DC_NIEN, iobase2 + ATA_CB_DC);
- int ret = send_cmd(adrive_g, cmd);
+ int ret = send_cmd(adrive_gf, cmd);
if (ret)
goto fail;
ret = ata_wait_data(iobase1);
{
if (! CONFIG_ATA_DMA)
return -1;
- struct atadrive_s *adrive_g = container_of(
- op->drive_g, struct atadrive_s, drive);
- int ret = send_cmd(adrive_g, cmd);
+ struct atadrive_s *adrive_gf = container_of(
+ op->drive_gf, struct atadrive_s, drive);
+ int ret = send_cmd(adrive_gf, cmd);
if (ret)
return ret;
return ata_dma_transfer(op);
if (!CONFIG_ATA)
return 0;
- struct atadrive_s *adrive_g = container_of(
- op->drive_g, struct atadrive_s, drive);
+ struct atadrive_s *adrive_gf = container_of(
+ op->drive_gf, struct atadrive_s, drive);
switch (op->command) {
case CMD_READ:
return ata_readwrite(op, 0);
case CMD_WRITE:
return ata_readwrite(op, 1);
case CMD_RESET:
- ata_reset(adrive_g);
+ ata_reset(adrive_gf);
return DISK_RET_SUCCESS;
case CMD_ISREADY:
- return isready(adrive_g);
+ return isready(adrive_gf);
case CMD_FORMAT:
case CMD_VERIFY:
case CMD_SEEK:
if (! CONFIG_ATA)
return 0;
- struct atadrive_s *adrive_g = container_of(
- op->drive_g, struct atadrive_s, drive);
- struct ata_channel_s *chan_gf = GET_GLOBAL(adrive_g->chan_gf);
+ struct atadrive_s *adrive_gf = container_of(
+ op->drive_gf, struct atadrive_s, drive);
+ struct ata_channel_s *chan_gf = GET_GLOBALFLAT(adrive_gf->chan_gf);
u16 iobase1 = GET_GLOBALFLAT(chan_gf->iobase1);
u16 iobase2 = GET_GLOBALFLAT(chan_gf->iobase2);
// Disable interrupts
outb(ATA_CB_DC_HD15 | ATA_CB_DC_NIEN, iobase2 + ATA_CB_DC);
- int ret = send_cmd(adrive_g, &cmd);
+ int ret = send_cmd(adrive_gf, &cmd);
if (ret)
goto fail;
ret = ata_wait_data(iobase1);
// Send an identify device or identify device packet command.
static int
-send_ata_identity(struct atadrive_s *adrive_g, u16 *buffer, int command)
+send_ata_identity(struct atadrive_s *adrive, u16 *buffer, int command)
{
memset(buffer, 0, DISK_SECTOR_SIZE);
struct disk_op_s dop;
memset(&dop, 0, sizeof(dop));
- dop.drive_g = &adrive_g->drive;
+ dop.drive_gf = &adrive->drive;
dop.count = 1;
dop.lba = 1;
dop.buf_fl = MAKE_FLATPTR(GET_SEG(SS), buffer);
static struct atadrive_s *
init_atadrive(struct atadrive_s *dummy, u16 *buffer)
{
- struct atadrive_s *adrive_g = malloc_fseg(sizeof(*adrive_g));
- if (!adrive_g) {
+ struct atadrive_s *adrive = malloc_fseg(sizeof(*adrive));
+ if (!adrive) {
warn_noalloc();
return NULL;
}
- memset(adrive_g, 0, sizeof(*adrive_g));
- adrive_g->chan_gf = dummy->chan_gf;
- adrive_g->slave = dummy->slave;
- adrive_g->drive.cntl_id = adrive_g->chan_gf->chanid * 2 + dummy->slave;
- adrive_g->drive.removable = (buffer[0] & 0x80) ? 1 : 0;
- return adrive_g;
+ memset(adrive, 0, sizeof(*adrive));
+ adrive->chan_gf = dummy->chan_gf;
+ adrive->slave = dummy->slave;
+ adrive->drive.cntl_id = adrive->chan_gf->chanid * 2 + dummy->slave;
+ adrive->drive.removable = (buffer[0] & 0x80) ? 1 : 0;
+ return adrive;
}
// Detect if the given drive is an atapi - initialize it if so.
return NULL;
// Success - setup as ATAPI.
- struct atadrive_s *adrive_g = init_atadrive(dummy, buffer);
- if (!adrive_g)
+ struct atadrive_s *adrive = init_atadrive(dummy, buffer);
+ if (!adrive)
return NULL;
- adrive_g->drive.type = DTYPE_ATA_ATAPI;
- adrive_g->drive.blksize = CDROM_SECTOR_SIZE;
- adrive_g->drive.sectors = (u64)-1;
+ adrive->drive.type = DTYPE_ATA_ATAPI;
+ adrive->drive.blksize = CDROM_SECTOR_SIZE;
+ adrive->drive.sectors = (u64)-1;
u8 iscd = ((buffer[0] >> 8) & 0x1f) == 0x05;
char model[MAXMODEL+1];
char *desc = znprintf(MAXDESCSIZE
, "DVD/CD [ata%d-%d: %s ATAPI-%d %s]"
- , adrive_g->chan_gf->chanid, adrive_g->slave
+ , adrive->chan_gf->chanid, adrive->slave
, ata_extract_model(model, MAXMODEL, buffer)
, ata_extract_version(buffer)
, (iscd ? "DVD/CD" : "Device"));
// fill cdidmap
if (iscd) {
- int prio = bootprio_find_ata_device(adrive_g->chan_gf->pci_tmp,
- adrive_g->chan_gf->chanid,
- adrive_g->slave);
- boot_add_cd(&adrive_g->drive, desc, prio);
+ int prio = bootprio_find_ata_device(adrive->chan_gf->pci_tmp,
+ adrive->chan_gf->chanid,
+ adrive->slave);
+ boot_add_cd(&adrive->drive, desc, prio);
}
- return adrive_g;
+ return adrive;
}
// Detect if the given drive is a regular ata drive - initialize it if so.
return NULL;
// Success - setup as ATA.
- struct atadrive_s *adrive_g = init_atadrive(dummy, buffer);
- if (!adrive_g)
+ struct atadrive_s *adrive = init_atadrive(dummy, buffer);
+ if (!adrive)
return NULL;
- adrive_g->drive.type = DTYPE_ATA;
- adrive_g->drive.blksize = DISK_SECTOR_SIZE;
+ adrive->drive.type = DTYPE_ATA;
+ adrive->drive.blksize = DISK_SECTOR_SIZE;
- adrive_g->drive.pchs.cylinder = buffer[1];
- adrive_g->drive.pchs.head = buffer[3];
- adrive_g->drive.pchs.sector = buffer[6];
+ adrive->drive.pchs.cylinder = buffer[1];
+ adrive->drive.pchs.head = buffer[3];
+ adrive->drive.pchs.sector = buffer[6];
u64 sectors;
if (buffer[83] & (1 << 10)) // word 83 - lba48 support
sectors = *(u64*)&buffer[100]; // word 100-103
else
sectors = *(u32*)&buffer[60]; // word 60 and word 61
- adrive_g->drive.sectors = sectors;
+ adrive->drive.sectors = sectors;
u64 adjsize = sectors >> 11;
char adjprefix = 'M';
if (adjsize >= (1 << 16)) {
char model[MAXMODEL+1];
char *desc = znprintf(MAXDESCSIZE
, "ata%d-%d: %s ATA-%d Hard-Disk (%u %ciBytes)"
- , adrive_g->chan_gf->chanid, adrive_g->slave
+ , adrive->chan_gf->chanid, adrive->slave
, ata_extract_model(model, MAXMODEL, buffer)
, ata_extract_version(buffer)
, (u32)adjsize, adjprefix);
dprintf(1, "%s\n", desc);
- int prio = bootprio_find_ata_device(adrive_g->chan_gf->pci_tmp,
- adrive_g->chan_gf->chanid,
- adrive_g->slave);
+ int prio = bootprio_find_ata_device(adrive->chan_gf->pci_tmp,
+ adrive->chan_gf->chanid,
+ adrive->slave);
// Register with bcv system.
- boot_add_hd(&adrive_g->drive, desc, prio);
+ boot_add_hd(&adrive->drive, desc, prio);
- return adrive_g;
+ return adrive;
}
static u32 SpinupEnd;
// check for ATAPI
u16 buffer[256];
- struct atadrive_s *adrive_g = init_drive_atapi(&dummy, buffer);
- if (!adrive_g) {
+ struct atadrive_s *adrive = init_drive_atapi(&dummy, buffer);
+ if (!adrive) {
// Didn't find an ATAPI drive - look for ATA drive.
u8 st = inb(iobase1+ATA_CB_STAT);
if (!st)
continue;
// check for ATA.
- adrive_g = init_drive_ata(&dummy, buffer);
- if (!adrive_g)
+ adrive = init_drive_ata(&dummy, buffer);
+ if (!adrive)
// No ATA drive found
continue;
}
#include "ahci.h" // atapi_cmd_data
#include "ata.h" // atapi_cmd_data
-#include "biosvar.h" // GET_GLOBAL
+#include "biosvar.h" // GET_GLOBALFLAT
#include "block.h" // struct disk_op_s
#include "blockcmd.h" // struct cdb_request_sense
#include "byteorder.h" // be32_to_cpu
static int
cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize)
{
- u8 type = GET_GLOBAL(op->drive_g->type);
+ u8 type = GET_GLOBALFLAT(op->drive_gf->type);
switch (type) {
case DTYPE_ATA_ATAPI:
return atapi_cmd_data(op, cdbcmd, blocksize);
int
scsi_is_ready(struct disk_op_s *op)
{
- dprintf(6, "scsi_is_ready (drive=%p)\n", op->drive_g);
+ dprintf(6, "scsi_is_ready (drive=%p)\n", op->drive_gf);
/* Retry TEST UNIT READY for 5 seconds unless MEDIUM NOT PRESENT is
* reported by the device. If the device reports "IN PROGRESS",
{
struct disk_op_s dop;
memset(&dop, 0, sizeof(dop));
- dop.drive_g = drive;
+ dop.drive_gf = drive;
struct cdbres_inquiry data;
int ret = cdb_get_inquiry(&dop, &data);
if (ret)
cmd.command = CDB_CMD_READ_10;
cmd.lba = cpu_to_be32(op->lba);
cmd.count = cpu_to_be16(op->count);
- return cdb_cmd_data(op, &cmd, GET_GLOBAL(op->drive_g->blksize));
+ return cdb_cmd_data(op, &cmd, GET_GLOBALFLAT(op->drive_gf->blksize));
}
// Write sectors.
cmd.command = CDB_CMD_WRITE_10;
cmd.lba = cpu_to_be32(op->lba);
cmd.count = cpu_to_be16(op->count);
- return cdb_cmd_data(op, &cmd, GET_GLOBAL(op->drive_g->blksize));
+ return cdb_cmd_data(op, &cmd, GET_GLOBALFLAT(op->drive_gf->blksize));
}
//
// This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "biosvar.h" // GET_GLOBAL
+#include "biosvar.h" // GET_GLOBALFLAT
#include "block.h" // struct drive_s
#include "blockcmd.h" // scsi_drive_setup
#include "config.h" // CONFIG_*
}
static int
-esp_scsi_cmd(struct esp_lun_s *llun, struct disk_op_s *op,
+esp_scsi_cmd(struct esp_lun_s *llun_gf, struct disk_op_s *op,
u8 *cdbcmd, u16 target, u16 lun, u16 blocksize)
{
- u32 iobase = GET_GLOBAL(llun->iobase);
+ u32 iobase = GET_GLOBALFLAT(llun_gf->iobase);
int i, state;
u8 status;
if (!CONFIG_ESP_SCSI)
return DISK_RET_EBADTRACK;
- struct esp_lun_s *llun =
- container_of(op->drive_g, struct esp_lun_s, drive);
+ struct esp_lun_s *llun_gf =
+ container_of(op->drive_gf, struct esp_lun_s, drive);
- return esp_scsi_cmd(llun, op, cdbcmd,
- GET_GLOBAL(llun->target), GET_GLOBAL(llun->lun),
+ return esp_scsi_cmd(llun_gf, op, cdbcmd,
+ GET_GLOBALFLAT(llun_gf->target),
+ GET_GLOBALFLAT(llun_gf->lun),
blocksize);
}
return NULL;
}
- struct drive_s *drive_g = malloc_fseg(sizeof(*drive_g));
- if (!drive_g) {
+ struct drive_s *drive = malloc_fseg(sizeof(*drive));
+ if (!drive) {
warn_noalloc();
return NULL;
}
- memset(drive_g, 0, sizeof(*drive_g));
- drive_g->cntl_id = floppyid;
- drive_g->type = DTYPE_FLOPPY;
- drive_g->blksize = DISK_SECTOR_SIZE;
- drive_g->floppy_type = ftype;
- drive_g->sectors = (u64)-1;
-
- memcpy(&drive_g->lchs, &FloppyInfo[ftype].chs
+ memset(drive, 0, sizeof(*drive));
+ drive->cntl_id = floppyid;
+ drive->type = DTYPE_FLOPPY;
+ drive->blksize = DISK_SECTOR_SIZE;
+ drive->floppy_type = ftype;
+ drive->sectors = (u64)-1;
+
+ memcpy(&drive->lchs, &FloppyInfo[ftype].chs
, sizeof(FloppyInfo[ftype].chs));
- return drive_g;
+ return drive;
}
static void
addFloppy(int floppyid, int ftype)
{
- struct drive_s *drive_g = init_floppy(floppyid, ftype);
- if (!drive_g)
+ struct drive_s *drive = init_floppy(floppyid, ftype);
+ if (!drive)
return;
char *desc = znprintf(MAXDESCSIZE, "Floppy [drive %c]", 'A' + floppyid);
struct pci_device *pci = pci_find_class(PCI_CLASS_BRIDGE_ISA); /* isa-to-pci bridge */
int prio = bootprio_find_fdc_device(pci, PORT_FD_BASE, floppyid);
- boot_add_floppy(drive_g, desc, prio);
+ boot_add_floppy(drive, desc, prio);
}
void
}
static int
-floppy_media_sense(struct drive_s *drive_g)
+floppy_media_sense(struct drive_s *drive_gf)
{
- u8 ftype = GET_GLOBAL(drive_g->floppy_type), stype = ftype;
- u8 floppyid = GET_GLOBAL(drive_g->cntl_id);
+ u8 ftype = GET_GLOBALFLAT(drive_gf->floppy_type), stype = ftype;
+ u8 floppyid = GET_GLOBALFLAT(drive_gf->cntl_id);
u8 data_rate = GET_GLOBAL(FloppyInfo[stype].data_rate);
int ret = floppy_drive_readid(floppyid, data_rate, 0);
}
static int
-check_recal_drive(struct drive_s *drive_g)
+check_recal_drive(struct drive_s *drive_gf)
{
- u8 floppyid = GET_GLOBAL(drive_g->cntl_id);
+ u8 floppyid = GET_GLOBALFLAT(drive_gf->cntl_id);
if ((GET_BDA(floppy_recalibration_status) & (1<<floppyid))
&& (GET_BDA(floppy_media_state[floppyid]) & FMS_MEDIA_DRIVE_ESTABLISHED))
// Media is known.
return ret;
// Sense media.
- return floppy_media_sense(drive_g);
+ return floppy_media_sense(drive_gf);
}
static int
floppy_cmd(struct disk_op_s *op, int blocksize, struct floppy_pio_s *pio)
{
- int ret = check_recal_drive(op->drive_g);
+ int ret = check_recal_drive(op->drive_gf);
if (ret)
return ret;
u32 lba = op->lba;
u32 tmp = lba + 1;
- u16 nls = GET_GLOBAL(op->drive_g->lchs.sector);
+ u16 nls = GET_GLOBALFLAT(op->drive_gf->lchs.sector);
res.sector = tmp % nls;
tmp /= nls;
- u16 nlh = GET_GLOBAL(op->drive_g->lchs.head);
+ u16 nlh = GET_GLOBALFLAT(op->drive_gf->lchs.head);
res.head = tmp % nlh;
tmp /= nlh;
static int
floppy_reset(struct disk_op_s *op)
{
- u8 floppyid = GET_GLOBAL(op->drive_g->cntl_id);
+ u8 floppyid = GET_GLOBALFLAT(op->drive_gf->cntl_id);
SET_BDA(floppy_recalibration_status, 0);
SET_BDA(floppy_media_state[0], 0);
SET_BDA(floppy_media_state[1], 0);
struct chs_s chs = lba2chs(op);
// send read-normal-data command (9 bytes) to controller
- u8 floppyid = GET_GLOBAL(op->drive_g->cntl_id);
+ u8 floppyid = GET_GLOBALFLAT(op->drive_gf->cntl_id);
struct floppy_pio_s pio;
pio.cmdlen = 9;
pio.data[0] = 0xe6; // e6: read normal data
struct chs_s chs = lba2chs(op);
// send write-normal-data command (9 bytes) to controller
- u8 floppyid = GET_GLOBAL(op->drive_g->cntl_id);
+ u8 floppyid = GET_GLOBALFLAT(op->drive_gf->cntl_id);
struct floppy_pio_s pio;
pio.cmdlen = 9;
pio.data[0] = 0xc5; // c5: write normal data
static int
floppy_verify(struct disk_op_s *op)
{
- int res = check_recal_drive(op->drive_g);
+ int res = check_recal_drive(op->drive_gf);
if (res)
goto fail;
struct chs_s chs = lba2chs(op);
// ??? should track be new val from return_status[3] ?
- u8 floppyid = GET_GLOBAL(op->drive_g->cntl_id);
+ u8 floppyid = GET_GLOBALFLAT(op->drive_gf->cntl_id);
set_diskette_current_cyl(floppyid, chs.cylinder);
return DISK_RET_SUCCESS;
fail:
u8 head = op->lba;
// send format-track command (6 bytes) to controller
- u8 floppyid = GET_GLOBAL(op->drive_g->cntl_id);
+ u8 floppyid = GET_GLOBALFLAT(op->drive_gf->cntl_id);
struct floppy_pio_s pio;
pio.cmdlen = 6;
pio.data[0] = 0x4d; // 4d: format track
//
// This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "biosvar.h" // GET_GLOBAL
+#include "biosvar.h" // GET_GLOBALFLAT
#include "block.h" // struct drive_s
#include "blockcmd.h" // scsi_drive_setup
#include "config.h" // CONFIG_*
};
static int
-lsi_scsi_cmd(struct lsi_lun_s *llun, struct disk_op_s *op,
+lsi_scsi_cmd(struct lsi_lun_s *llun_gf, struct disk_op_s *op,
void *cdbcmd, u16 target, u16 lun, u16 blocksize)
{
- u32 iobase = GET_GLOBAL(llun->iobase);
+ u32 iobase = GET_GLOBALFLAT(llun_gf->iobase);
u32 dma = ((cdb_is_read(cdbcmd, blocksize) ? 0x01000000 : 0x00000000) |
(op->count * blocksize));
u8 msgout[] = {
if (!CONFIG_LSI_SCSI)
return DISK_RET_EBADTRACK;
- struct lsi_lun_s *llun =
- container_of(op->drive_g, struct lsi_lun_s, drive);
+ struct lsi_lun_s *llun_gf =
+ container_of(op->drive_gf, struct lsi_lun_s, drive);
- return lsi_scsi_cmd(llun, op, cdbcmd,
- GET_GLOBAL(llun->target), GET_GLOBAL(llun->lun),
+ return lsi_scsi_cmd(llun_gf, op, cdbcmd,
+ GET_GLOBALFLAT(llun_gf->target),
+ GET_GLOBALFLAT(llun_gf->lun),
blocksize);
}
//
// This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "biosvar.h" // GET_GLOBAL
+#include "biosvar.h" // GET_GLOBALFLAT
#include "block.h" // struct drive_s
#include "blockcmd.h" // scsi_drive_setup
#include "config.h" // CONFIG_*
int
megasas_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize)
{
- struct megasas_lun_s *mlun =
- container_of(op->drive_g, struct megasas_lun_s, drive);
+ struct megasas_lun_s *mlun_gf =
+ container_of(op->drive_gf, struct megasas_lun_s, drive);
u8 *cdb = cdbcmd;
- struct megasas_cmd_frame *frame = GET_GLOBAL(mlun->frame);
- u16 pci_id = GET_GLOBAL(mlun->pci->device);
+ struct megasas_cmd_frame *frame = GET_GLOBALFLAT(mlun_gf->frame);
+ u16 pci_id = GET_GLOBALFLAT(mlun_gf->pci->device);
int i;
if (!CONFIG_MEGASAS)
memset_fl(frame, 0, sizeof(*frame));
SET_LOWFLAT(frame->cmd, MFI_CMD_LD_SCSI_IO);
SET_LOWFLAT(frame->cmd_status, 0xFF);
- SET_LOWFLAT(frame->target_id, GET_GLOBAL(mlun->target));
- SET_LOWFLAT(frame->lun, GET_GLOBAL(mlun->lun));
+ SET_LOWFLAT(frame->target_id, GET_GLOBALFLAT(mlun_gf->target));
+ SET_LOWFLAT(frame->lun, GET_GLOBALFLAT(mlun_gf->lun));
SET_LOWFLAT(frame->flags, 0x0001);
SET_LOWFLAT(frame->data_xfer_len, op->count * blocksize);
SET_LOWFLAT(frame->cdb_len, 16);
}
SET_LOWFLAT(frame->context, (u32)frame);
- if (megasas_fire_cmd(pci_id, GET_GLOBAL(mlun->iobase), frame) == 0)
+ if (megasas_fire_cmd(pci_id, GET_GLOBALFLAT(mlun_gf->iobase), frame) == 0)
return DISK_RET_SUCCESS;
dprintf(2, "pthru cmd 0x%x failed\n", cdb[0]);
//
// This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "biosvar.h" // GET_GLOBAL
+#include "biosvar.h" // GET_GLOBALFLAT
#include "block.h" // struct drive_s
#include "blockcmd.h" // scsi_drive_setup
#include "config.h" // CONFIG_*
}
static int
-pvscsi_cmd(struct pvscsi_lun_s *plun, struct disk_op_s *op,
+pvscsi_cmd(struct pvscsi_lun_s *plun_gf, struct disk_op_s *op,
void *cdbcmd, u16 target, u16 lun, u16 blocksize)
{
- struct pvscsi_ring_dsc_s *ring_dsc = GET_GLOBAL(plun->ring_dsc);
+ struct pvscsi_ring_dsc_s *ring_dsc = GET_GLOBALFLAT(plun_gf->ring_dsc);
struct PVSCSIRingsState *s = GET_LOWFLAT(ring_dsc->ring_state);
u32 req_entries = GET_LOWFLAT(s->reqNumEntriesLog2);
u32 cmp_entries = GET_LOWFLAT(s->cmpNumEntriesLog2);
req = GET_LOWFLAT(ring_dsc->ring_reqs) + (GET_LOWFLAT(s->reqProdIdx) & MASK(req_entries));
pvscsi_fill_req(s, req, target, lun, cdbcmd, blocksize, op);
- pvscsi_kick_rw_io(GET_GLOBAL(plun->iobase));
- pvscsi_wait_intr_cmpl(GET_GLOBAL(plun->iobase));
+ pvscsi_kick_rw_io(GET_GLOBALFLAT(plun_gf->iobase));
+ pvscsi_wait_intr_cmpl(GET_GLOBALFLAT(plun_gf->iobase));
rsp = GET_LOWFLAT(ring_dsc->ring_cmps) + (GET_LOWFLAT(s->cmpConsIdx) & MASK(cmp_entries));
status = pvscsi_get_rsp(s, rsp);
if (!CONFIG_PVSCSI)
return DISK_RET_EBADTRACK;
- struct pvscsi_lun_s *plun =
- container_of(op->drive_g, struct pvscsi_lun_s, drive);
+ struct pvscsi_lun_s *plun_gf =
+ container_of(op->drive_gf, struct pvscsi_lun_s, drive);
- return pvscsi_cmd(plun, op, cdbcmd,
- GET_GLOBAL(plun->target), GET_GLOBAL(plun->lun),
+ return pvscsi_cmd(plun_gf, op, cdbcmd,
+ GET_GLOBALFLAT(plun_gf->target),
+ GET_GLOBALFLAT(plun_gf->lun),
blocksize);
}
//
// This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "biosvar.h" // GET_GLOBAL
+#include "biosvar.h" // GET_GLOBALFLAT
#include "block.h" // struct drive_s
#include "bregs.h" // struct bregs
#include "malloc.h" // malloc_fseg
return;
// Setup driver.
- struct drive_s *drive_g = init_floppy((u32)pos, ftype);
- if (!drive_g)
+ struct drive_s *drive = init_floppy((u32)pos, ftype);
+ if (!drive)
return;
- drive_g->type = DTYPE_RAMDISK;
+ drive->type = DTYPE_RAMDISK;
dprintf(1, "Mapping CBFS floppy %s to addr %p\n", filename, pos);
char *desc = znprintf(MAXDESCSIZE, "Ramdisk [%s]", &filename[10]);
- boot_add_floppy(drive_g, desc, bootprio_find_named_rom(filename, 0));
+ boot_add_floppy(drive, desc, bootprio_find_named_rom(filename, 0));
}
static int
ramdisk_copy(struct disk_op_s *op, int iswrite)
{
- u32 offset = GET_GLOBAL(op->drive_g->cntl_id);
+ u32 offset = GET_GLOBALFLAT(op->drive_gf->cntl_id);
offset += (u32)op->lba * DISK_SECTOR_SIZE;
u64 opd = GDT_DATA | GDT_LIMIT(0xfffff) | GDT_BASE((u32)op->buf_fl);
u64 ramd = GDT_DATA | GDT_LIMIT(0xfffff) | GDT_BASE(offset);
//
// This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "biosvar.h" // GET_GLOBAL
+#include "biosvar.h" // GET_GLOBALFLAT
#include "block.h" // DTYPE_USB
#include "blockcmd.h" // cdb_read
#include "config.h" // CONFIG_USB_MSC
} PACKED;
static int
-usb_msc_send(struct usbdrive_s *udrive_g, int dir, void *buf, u32 bytes)
+usb_msc_send(struct usbdrive_s *udrive_gf, int dir, void *buf, u32 bytes)
{
struct usb_pipe *pipe;
if (dir == USB_DIR_OUT)
- pipe = GET_GLOBAL(udrive_g->bulkout);
+ pipe = GET_GLOBALFLAT(udrive_gf->bulkout);
else
- pipe = GET_GLOBAL(udrive_g->bulkin);
+ pipe = GET_GLOBALFLAT(udrive_gf->bulkin);
return usb_send_bulk(pipe, dir, buf, bytes);
}
return 0;
dprintf(16, "usb_cmd_data id=%p write=%d count=%d bs=%d buf=%p\n"
- , op->drive_g, 0, op->count, blocksize, op->buf_fl);
- struct usbdrive_s *udrive_g = container_of(
- op->drive_g, struct usbdrive_s, drive);
+ , op->drive_gf, 0, op->count, blocksize, op->buf_fl);
+ struct usbdrive_s *udrive_gf = container_of(
+ op->drive_gf, struct usbdrive_s, drive);
// Setup command block wrapper.
u32 bytes = blocksize * op->count;
cbw.dCBWTag = 999; // XXX
cbw.dCBWDataTransferLength = bytes;
cbw.bmCBWFlags = cdb_is_read(cdbcmd, blocksize) ? USB_DIR_IN : USB_DIR_OUT;
- cbw.bCBWLUN = GET_GLOBAL(udrive_g->lun);
+ cbw.bCBWLUN = GET_GLOBALFLAT(udrive_gf->lun);
cbw.bCBWCBLength = USB_CDB_SIZE;
// Transfer cbw to device.
- int ret = usb_msc_send(udrive_g, USB_DIR_OUT
+ int ret = usb_msc_send(udrive_gf, USB_DIR_OUT
, MAKE_FLATPTR(GET_SEG(SS), &cbw), sizeof(cbw));
if (ret)
goto fail;
// Transfer data to/from device.
if (bytes) {
- ret = usb_msc_send(udrive_g, cbw.bmCBWFlags, op->buf_fl, bytes);
+ ret = usb_msc_send(udrive_gf, cbw.bmCBWFlags, op->buf_fl, bytes);
if (ret)
goto fail;
}
// Transfer csw info.
struct csw_s csw;
- ret = usb_msc_send(udrive_g, USB_DIR_IN
- , MAKE_FLATPTR(GET_SEG(SS), &csw), sizeof(csw));
+ ret = usb_msc_send(udrive_gf, USB_DIR_IN
+ , MAKE_FLATPTR(GET_SEG(SS), &csw), sizeof(csw));
if (ret)
goto fail;
struct usbdevice_s *usbdev, int lun)
{
// Allocate drive structure.
- struct usbdrive_s *udrive_g = malloc_fseg(sizeof(*udrive_g));
- if (!udrive_g) {
+ struct usbdrive_s *drive = malloc_fseg(sizeof(*drive));
+ if (!drive) {
warn_noalloc();
return -1;
}
- memset(udrive_g, 0, sizeof(*udrive_g));
- udrive_g->drive.type = DTYPE_USB;
- udrive_g->bulkin = inpipe;
- udrive_g->bulkout = outpipe;
- udrive_g->lun = lun;
+ memset(drive, 0, sizeof(*drive));
+ drive->drive.type = DTYPE_USB;
+ drive->bulkin = inpipe;
+ drive->bulkout = outpipe;
+ drive->lun = lun;
int prio = bootprio_find_usb(usbdev, lun);
- int ret = scsi_drive_setup(&udrive_g->drive, "USB MSC", prio);
+ int ret = scsi_drive_setup(&drive->drive, "USB MSC", prio);
if (ret) {
dprintf(1, "Unable to configure USB MSC drive.\n");
- free(udrive_g);
+ free(drive);
return -1;
}
return 0;
//
// This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "biosvar.h" // GET_GLOBAL
+#include "biosvar.h" // GET_GLOBALFLAT
#include "block.h" // DTYPE_USB
#include "blockcmd.h" // cdb_read
#include "config.h" // CONFIG_USB_UAS
if (!CONFIG_USB_UAS)
return DISK_RET_EBADTRACK;
- struct uasdrive_s *drive = container_of(
- op->drive_g, struct uasdrive_s, drive);
+ struct uasdrive_s *drive_gf = container_of(
+ op->drive_gf, struct uasdrive_s, drive);
uas_ui ui;
memset(&ui, 0, sizeof(ui));
ui.hdr.id = UAS_UI_COMMAND;
ui.hdr.tag = 0xdead;
- ui.command.lun[1] = drive->lun;
+ ui.command.lun[1] = GET_GLOBALFLAT(drive_gf->lun);
memcpy(ui.command.cdb, cdbcmd, sizeof(ui.command.cdb));
- int ret = usb_send_bulk(GET_GLOBAL(drive->command),
+ int ret = usb_send_bulk(GET_GLOBALFLAT(drive_gf->command),
USB_DIR_OUT, MAKE_FLATPTR(GET_SEG(SS), &ui),
sizeof(ui.hdr) + sizeof(ui.command));
if (ret) {
}
memset(&ui, 0xff, sizeof(ui));
- ret = usb_send_bulk(GET_GLOBAL(drive->status),
+ ret = usb_send_bulk(GET_GLOBALFLAT(drive_gf->status),
USB_DIR_IN, MAKE_FLATPTR(GET_SEG(SS), &ui), sizeof(ui));
if (ret) {
dprintf(1, "uas: status recv fail");
case UAS_UI_SENSE:
goto have_sense;
case UAS_UI_READ_READY:
- ret = usb_send_bulk(GET_GLOBAL(drive->data_in),
+ ret = usb_send_bulk(GET_GLOBALFLAT(drive_gf->data_in),
USB_DIR_IN, op->buf_fl, op->count * blocksize);
if (ret) {
dprintf(1, "uas: data read fail");
}
break;
case UAS_UI_WRITE_READY:
- ret = usb_send_bulk(GET_GLOBAL(drive->data_out),
+ ret = usb_send_bulk(GET_GLOBALFLAT(drive_gf->data_out),
USB_DIR_OUT, op->buf_fl, op->count * blocksize);
if (ret) {
dprintf(1, "uas: data write fail");
}
memset(&ui, 0xff, sizeof(ui));
- ret = usb_send_bulk(GET_GLOBAL(drive->status),
+ ret = usb_send_bulk(GET_GLOBALFLAT(drive_gf->status),
USB_DIR_IN, MAKE_FLATPTR(GET_SEG(SS), &ui), sizeof(ui));
if (ret) {
dprintf(1, "uas: status recv fail");
//
// This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "biosvar.h" // GET_GLOBAL
+#include "biosvar.h" // GET_GLOBALFLAT
#include "config.h" // CONFIG_*
#include "block.h" // struct drive_s
#include "malloc.h" // free
static int
virtio_blk_op(struct disk_op_s *op, int write)
{
- struct virtiodrive_s *vdrive_g =
- container_of(op->drive_g, struct virtiodrive_s, drive);
- struct vring_virtqueue *vq = GET_GLOBAL(vdrive_g->vq);
+ struct virtiodrive_s *vdrive_gf =
+ container_of(op->drive_gf, struct virtiodrive_s, drive);
+ struct vring_virtqueue *vq = GET_GLOBALFLAT(vdrive_gf->vq);
struct virtio_blk_outhdr hdr = {
.type = write ? VIRTIO_BLK_T_OUT : VIRTIO_BLK_T_IN,
.ioprio = 0,
},
{
.addr = op->buf_fl,
- .length = GET_GLOBAL(vdrive_g->drive.blksize) * op->count,
+ .length = GET_GLOBALFLAT(vdrive_gf->drive.blksize) * op->count,
},
{
.addr = MAKE_FLATPTR(GET_SEG(SS), &status),
vring_add_buf(vq, sg, 2, 1, 0, 0);
else
vring_add_buf(vq, sg, 1, 2, 0, 0);
- vring_kick(GET_GLOBAL(vdrive_g->ioaddr), vq, 1);
+ vring_kick(GET_GLOBALFLAT(vdrive_gf->ioaddr), vq, 1);
/* Wait for reply */
while (!vring_more_used(vq))
/* Clear interrupt status register. Avoid leaving interrupts stuck if
* VRING_AVAIL_F_NO_INTERRUPT was ignored and interrupts were raised.
*/
- vp_get_isr(GET_GLOBAL(vdrive_g->ioaddr));
+ vp_get_isr(GET_GLOBALFLAT(vdrive_gf->ioaddr));
return status == VIRTIO_BLK_S_OK ? DISK_RET_SUCCESS : DISK_RET_EBADTRACK;
}
u16 bdf = pci->bdf;
dprintf(1, "found virtio-blk at %x:%x\n", pci_bdf_to_bus(bdf),
pci_bdf_to_dev(bdf));
- struct virtiodrive_s *vdrive_g = malloc_fseg(sizeof(*vdrive_g));
- if (!vdrive_g) {
+ struct virtiodrive_s *vdrive = malloc_fseg(sizeof(*vdrive));
+ if (!vdrive) {
warn_noalloc();
return;
}
- memset(vdrive_g, 0, sizeof(*vdrive_g));
- vdrive_g->drive.type = DTYPE_VIRTIO_BLK;
- vdrive_g->drive.cntl_id = bdf;
+ memset(vdrive, 0, sizeof(*vdrive));
+ vdrive->drive.type = DTYPE_VIRTIO_BLK;
+ vdrive->drive.cntl_id = bdf;
u16 ioaddr = vp_init_simple(bdf);
- vdrive_g->ioaddr = ioaddr;
- if (vp_find_vq(ioaddr, 0, &vdrive_g->vq) < 0 ) {
+ vdrive->ioaddr = ioaddr;
+ if (vp_find_vq(ioaddr, 0, &vdrive->vq) < 0 ) {
dprintf(1, "fail to find vq for virtio-blk %x:%x\n",
pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf));
goto fail;
vp_get(ioaddr, 0, &cfg, sizeof(cfg));
u32 f = vp_get_features(ioaddr);
- vdrive_g->drive.blksize = (f & (1 << VIRTIO_BLK_F_BLK_SIZE)) ?
+ vdrive->drive.blksize = (f & (1 << VIRTIO_BLK_F_BLK_SIZE)) ?
cfg.blk_size : DISK_SECTOR_SIZE;
- vdrive_g->drive.sectors = cfg.capacity;
+ vdrive->drive.sectors = cfg.capacity;
dprintf(3, "virtio-blk %x:%x blksize=%d sectors=%u\n",
pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf),
- vdrive_g->drive.blksize, (u32)vdrive_g->drive.sectors);
+ vdrive->drive.blksize, (u32)vdrive->drive.sectors);
- if (vdrive_g->drive.blksize != DISK_SECTOR_SIZE) {
+ if (vdrive->drive.blksize != DISK_SECTOR_SIZE) {
dprintf(1, "virtio-blk %x:%x block size %d is unsupported\n",
pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf),
- vdrive_g->drive.blksize);
+ vdrive->drive.blksize);
goto fail;
}
- vdrive_g->drive.pchs.cylinder = cfg.cylinders;
- vdrive_g->drive.pchs.head = cfg.heads;
- vdrive_g->drive.pchs.sector = cfg.sectors;
+ vdrive->drive.pchs.cylinder = cfg.cylinders;
+ vdrive->drive.pchs.head = cfg.heads;
+ vdrive->drive.pchs.sector = cfg.sectors;
char *desc = znprintf(MAXDESCSIZE, "Virtio disk PCI:%x:%x",
pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf));
- boot_add_hd(&vdrive_g->drive, desc, bootprio_find_pci_device(pci));
+ boot_add_hd(&vdrive->drive, desc, bootprio_find_pci_device(pci));
vp_set_status(ioaddr, VIRTIO_CONFIG_S_ACKNOWLEDGE |
VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_DRIVER_OK);
return;
fail:
- free(vdrive_g->vq);
- free(vdrive_g);
+ free(vdrive->vq);
+ free(vdrive);
}
void
//
// This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "biosvar.h" // GET_GLOBAL
+#include "biosvar.h" // GET_GLOBALFLAT
#include "block.h" // struct drive_s
#include "blockcmd.h" // scsi_drive_setup
#include "config.h" // CONFIG_*
int
virtio_scsi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize)
{
- struct virtio_lun_s *vlun =
- container_of(op->drive_g, struct virtio_lun_s, drive);
+ struct virtio_lun_s *vlun_gf =
+ container_of(op->drive_gf, struct virtio_lun_s, drive);
- return virtio_scsi_cmd(GET_GLOBAL(vlun->ioaddr),
- GET_GLOBAL(vlun->vq), op, cdbcmd,
- GET_GLOBAL(vlun->target), GET_GLOBAL(vlun->lun),
+ return virtio_scsi_cmd(GET_GLOBALFLAT(vlun_gf->ioaddr),
+ GET_GLOBALFLAT(vlun_gf->vq), op, cdbcmd,
+ GET_GLOBALFLAT(vlun_gf->target),
+ GET_GLOBALFLAT(vlun_gf->lun),
blocksize);
}