The "drive" structure is always malloc'ed and therefore always starts off described as a 32-bit "flat" pointer. Instead of switching to/from 16bit pointers, make all the code use the 32bit pointer. This eliminates the confusing 16/32 bit pointer switches.
This patch also removes the "_g" suffixes on local variables in functions that are always called in 32bit mode.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 100 ++++++++++---------- src/block.h | 10 +- src/cdrom.c | 31 +++---- src/disk.c | 257 +++++++++++++++++++++++++-------------------------- src/hw/ahci.c | 28 +++--- src/hw/ata.c | 164 ++++++++++++++++---------------- src/hw/blockcmd.c | 12 +-- src/hw/esp-scsi.c | 15 +-- src/hw/floppy.c | 58 ++++++------ src/hw/lsi-scsi.c | 15 +-- src/hw/megasas.c | 16 ++-- src/hw/pvscsi.c | 19 ++-- src/hw/ramdisk.c | 12 +-- src/hw/usb-msc.c | 42 ++++----- src/hw/usb-uas.c | 18 ++-- src/hw/virtio-blk.c | 50 +++++----- src/hw/virtio-scsi.c | 13 +-- 17 files changed, 429 insertions(+), 431 deletions(-)
diff --git a/src/block.c b/src/block.c index af254ce..7493a5d 100644 --- a/src/block.c +++ b/src/block.c @@ -31,17 +31,15 @@ getDrive(u8 exttype, u8 extdriveoffset) { 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; } @@ -65,12 +63,12 @@ int create_bounce_buf(void) ****************************************************************/
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); @@ -79,10 +77,10 @@ get_translation(struct drive_s *drive_g) }
// 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. @@ -96,15 +94,15 @@ get_translation(struct drive_s *drive_g) }
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) { @@ -161,15 +159,15 @@ setup_translation(struct drive_s *drive_g) 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; }
@@ -179,18 +177,18 @@ setup_translation(struct drive_s *drive_g)
// 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; @@ -224,47 +222,49 @@ fill_fdpt(struct drive_s *drive_g, int hdid)
// 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) { @@ -350,7 +350,7 @@ int 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); @@ -362,15 +362,13 @@ process_op(struct disk_op_s *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); @@ -398,7 +396,7 @@ __send_disk_op(struct disk_op_s *op_far, u16 op_seg) , 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); diff --git a/src/block.h b/src/block.h index 9bffa09..9cb25d0 100644 --- a/src/block.h +++ b/src/block.h @@ -11,7 +11,7 @@ struct disk_op_s { u64 lba; void *buf_fl; - struct drive_s *drive_g; + struct drive_s *drive_gf; u16 count; u8 command; }; @@ -109,10 +109,10 @@ extern struct dpte_s DefaultDPTE; 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 diff --git a/src/cdrom.c b/src/cdrom.c index 836808b..811bef5 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -30,10 +30,9 @@ struct drive_s *cdemu_drive_gf VARFSEG; 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;
@@ -120,17 +119,17 @@ cdrom_prepboot(void) 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) \ @@ -175,14 +174,14 @@ cdemu_134b(struct bregs *regs) ****************************************************************/
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); @@ -231,7 +230,7 @@ cdrom_boot(struct drive_s *drive_g) 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) diff --git a/src/disk.c b/src/disk.c index 80290ce..1011b39 100644 --- a/src/disk.c +++ b/src/disk.c @@ -34,11 +34,10 @@ __disk_stub(struct bregs *regs, int lineno, const char *fname)
// 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 @@ -48,18 +47,18 @@ getLCHS(struct drive_s *drive_g) 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; @@ -74,7 +73,7 @@ basic_access(struct bregs *regs, struct drive_s *drive_g, u16 command) } 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 @@ -99,15 +98,15 @@ basic_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
// 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; @@ -135,10 +134,10 @@ extended_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
// 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); @@ -146,7 +145,7 @@ disk_1300(struct bregs *regs, struct drive_s *drive_g)
// 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) @@ -161,32 +160,32 @@ disk_1301(struct bregs *regs, struct drive_s *drive_g)
// 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; @@ -198,7 +197,7 @@ disk_1305(struct bregs *regs, struct drive_s *drive_g) }
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; @@ -209,10 +208,10 @@ disk_1305(struct bregs *regs, struct drive_s *drive_g)
// 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--; @@ -221,11 +220,10 @@ disk_1308(struct bregs *regs, struct drive_s *drive_g) // 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; @@ -261,33 +259,33 @@ disk_1308(struct bregs *regs, struct drive_s *drive_g)
// 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); @@ -295,21 +293,21 @@ disk_1310(struct bregs *regs, struct drive_s *drive_g)
// 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) { @@ -320,7 +318,7 @@ disk_1315(struct bregs *regs, struct drive_s *drive_g) // 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 @@ -331,7 +329,7 @@ disk_1315(struct bregs *regs, struct drive_s *drive_g) }
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 @@ -343,7 +341,7 @@ disk_1316(struct bregs *regs, struct drive_s *drive_g)
// 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 @@ -353,28 +351,28 @@ disk_1341(struct bregs *regs, struct drive_s *drive_g)
// 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]); @@ -390,7 +388,7 @@ disk_134500(struct bregs *regs, struct drive_s *drive_g)
// 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]); @@ -407,7 +405,7 @@ disk_134501(struct bregs *regs, struct drive_s *drive_g)
// 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]); @@ -416,14 +414,14 @@ disk_134502(struct bregs *regs, struct drive_s *drive_g) }
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 @@ -432,16 +430,16 @@ disk_1345(struct bregs *regs, struct drive_s *drive_g) }
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 @@ -475,14 +473,14 @@ disk_1346(struct bregs *regs, struct drive_s *drive_g)
// 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); @@ -497,12 +495,12 @@ disk_1348(struct bregs *regs, struct drive_s *drive_g)
// 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); @@ -547,10 +545,10 @@ disk_1348(struct bregs *regs, struct drive_s *drive_g) 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); @@ -560,7 +558,7 @@ disk_1348(struct bregs *regs, struct drive_s *drive_g)
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) @@ -594,7 +592,7 @@ disk_1348(struct bregs *regs, struct drive_s *drive_g) 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) { @@ -664,7 +662,7 @@ disk_1348(struct bregs *regs, struct drive_s *drive_g)
// 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 @@ -677,56 +675,56 @@ disk_1349(struct bregs *regs, struct drive_s *drive_g) }
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);
@@ -734,37 +732,37 @@ disk_13(struct bregs *regs, struct drive_s *drive_g) 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) { @@ -777,9 +775,9 @@ floppy_13(struct bregs *regs, struct drive_s *drive_g) 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; } }
@@ -798,21 +796,21 @@ handle_legacy_disk(struct bregs *regs, u8 extdrive) }
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: @@ -843,14 +841,13 @@ handle_13(struct bregs *regs) 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) diff --git a/src/hw/ahci.c b/src/hw/ahci.c index 82a6194..a4ef5c5 100644 --- a/src/hw/ahci.c +++ b/src/hw/ahci.c @@ -102,15 +102,15 @@ static void ahci_port_writel(struct ahci_ctrl_s *ctrl, u32 pnr, u32 reg, u32 val }
// 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 */ @@ -218,9 +218,9 @@ int ahci_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) 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;
@@ -228,7 +228,7 @@ int ahci_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) 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; @@ -239,13 +239,13 @@ int ahci_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) 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); diff --git a/src/hw/ata.c b/src/hw/ata.c index e5ef685..de2a919 100644 --- a/src/hw/ata.c +++ b/src/hw/ata.c @@ -6,7 +6,7 @@ // 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 @@ -80,14 +80,14 @@ ndelay_await_not_bsy(u16 iobase1)
// 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); @@ -120,7 +120,7 @@ ata_reset(struct atadrive_s *adrive_g) }
// 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);
@@ -133,10 +133,10 @@ done:
// 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) @@ -167,10 +167,10 @@ struct ata_pio_command {
// 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 @@ -229,16 +229,16 @@ ata_wait_data(u16 iobase1)
// 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); @@ -270,16 +270,16 @@ fail: ****************************************************************/
// 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; @@ -288,14 +288,14 @@ ata_pio_transfer(struct disk_op_s *op, int iswrite, int blocksize) 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 @@ -364,9 +364,9 @@ ata_try_dma(struct disk_op_s *op, int iswrite, int blocksize) 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; @@ -412,11 +412,11 @@ ata_dma_transfer(struct disk_op_s *op) { 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. @@ -465,16 +465,16 @@ ata_dma_transfer(struct disk_op_s *op) 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); @@ -494,9 +494,9 @@ ata_dma_cmd_data(struct disk_op_s *op, struct ata_pio_command *cmd) { 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); @@ -558,18 +558,18 @@ process_ata_op(struct disk_op_s *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: @@ -594,9 +594,9 @@ atapi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) 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);
@@ -609,7 +609,7 @@ atapi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) // 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); @@ -659,13 +659,13 @@ fail:
// 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); @@ -709,17 +709,17 @@ ata_extract_model(char *model, u32 size, u16 *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. @@ -732,17 +732,17 @@ init_drive_atapi(struct atadrive_s *dummy, u16 *buffer) 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")); @@ -750,13 +750,13 @@ init_drive_atapi(struct atadrive_s *dummy, u16 *buffer)
// 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. @@ -769,22 +769,22 @@ init_drive_ata(struct atadrive_s *dummy, u16 *buffer) 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)) { @@ -794,19 +794,19 @@ init_drive_ata(struct atadrive_s *dummy, u16 *buffer) 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; @@ -883,8 +883,8 @@ ata_detect(void *data)
// 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) @@ -897,8 +897,8 @@ ata_detect(void *data) 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; } diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 7b07ab6..96950f2 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -7,7 +7,7 @@
#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 @@ -27,7 +27,7 @@ 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); @@ -64,7 +64,7 @@ cdb_is_read(u8 *cdbcmd, u16 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", @@ -111,7 +111,7 @@ scsi_drive_setup(struct drive_s *drive, const char *s, int prio) { 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) @@ -268,7 +268,7 @@ cdb_read(struct disk_op_s *op) 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. @@ -280,5 +280,5 @@ cdb_write(struct disk_op_s *op) 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)); } diff --git a/src/hw/esp-scsi.c b/src/hw/esp-scsi.c index 118a1f5..982c1d5 100644 --- a/src/hw/esp-scsi.c +++ b/src/hw/esp-scsi.c @@ -10,7 +10,7 @@ // // 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_* @@ -77,10 +77,10 @@ esp_scsi_dma(u32 iobase, u32 buf, u32 len, int read) }
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;
@@ -150,11 +150,12 @@ esp_scsi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) 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); }
diff --git a/src/hw/floppy.c b/src/hw/floppy.c index 7f63bcc..e73b303 100644 --- a/src/hw/floppy.c +++ b/src/hw/floppy.c @@ -103,33 +103,33 @@ init_floppy(int floppyid, int ftype) 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 @@ -376,10 +376,10 @@ floppy_drive_readid(u8 floppyid, u8 data_rate, u8 head) }
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); @@ -418,9 +418,9 @@ floppy_media_sense(struct drive_s *drive_g) }
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. @@ -432,7 +432,7 @@ check_recal_drive(struct drive_s *drive_g) return ret;
// Sense media. - return floppy_media_sense(drive_g); + return floppy_media_sense(drive_gf); }
@@ -444,7 +444,7 @@ check_recal_drive(struct drive_s *drive_g) 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;
@@ -496,11 +496,11 @@ lba2chs(struct disk_op_s *op) 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; @@ -513,7 +513,7 @@ lba2chs(struct disk_op_s *op) 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); @@ -531,7 +531,7 @@ floppy_read(struct disk_op_s *op) 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 @@ -560,7 +560,7 @@ floppy_write(struct disk_op_s *op) 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 @@ -586,14 +586,14 @@ fail: 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: @@ -608,7 +608,7 @@ floppy_format(struct disk_op_s *op) 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 diff --git a/src/hw/lsi-scsi.c b/src/hw/lsi-scsi.c index 021aa61..b1d6bbf 100644 --- a/src/hw/lsi-scsi.c +++ b/src/hw/lsi-scsi.c @@ -10,7 +10,7 @@ // // 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_* @@ -51,10 +51,10 @@ struct lsi_lun_s { };
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[] = { @@ -128,11 +128,12 @@ lsi_scsi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) 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); }
diff --git a/src/hw/megasas.c b/src/hw/megasas.c index ebc49f9..3ded877 100644 --- a/src/hw/megasas.c +++ b/src/hw/megasas.c @@ -10,7 +10,7 @@ // // 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_* @@ -159,11 +159,11 @@ static int megasas_fire_cmd(u16 pci_id, u32 ioaddr, 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) @@ -172,8 +172,8 @@ megasas_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) 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); @@ -191,7 +191,7 @@ megasas_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) } 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]); diff --git a/src/hw/pvscsi.c b/src/hw/pvscsi.c index 740a74b..6911230 100644 --- a/src/hw/pvscsi.c +++ b/src/hw/pvscsi.c @@ -7,7 +7,7 @@ // // 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_* @@ -234,10 +234,10 @@ pvscsi_get_rsp(struct PVSCSIRingsState *s, }
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); @@ -254,8 +254,8 @@ pvscsi_cmd(struct pvscsi_lun_s *plun, struct disk_op_s *op, 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); @@ -269,11 +269,12 @@ pvscsi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) 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);
} diff --git a/src/hw/ramdisk.c b/src/hw/ramdisk.c index eeddf25..81aed50 100644 --- a/src/hw/ramdisk.c +++ b/src/hw/ramdisk.c @@ -4,7 +4,7 @@ // // 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 @@ -49,19 +49,19 @@ ramdisk_setup(void) 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); diff --git a/src/hw/usb-msc.c b/src/hw/usb-msc.c index 8ee448f..7e2e440 100644 --- a/src/hw/usb-msc.c +++ b/src/hw/usb-msc.c @@ -4,7 +4,7 @@ // // 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 @@ -51,13 +51,13 @@ struct csw_s { } 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); }
@@ -69,9 +69,9 @@ usb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) 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; @@ -82,26 +82,26 @@ usb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) 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;
@@ -142,22 +142,22 @@ usb_msc_lun_setup(struct usb_pipe *inpipe, struct usb_pipe *outpipe, 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; diff --git a/src/hw/usb-uas.c b/src/hw/usb-uas.c index 62b9675..33657ac 100644 --- a/src/hw/usb-uas.c +++ b/src/hw/usb-uas.c @@ -14,7 +14,7 @@ // // 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 @@ -96,16 +96,16 @@ uas_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) 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) { @@ -114,7 +114,7 @@ uas_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) }
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"); @@ -125,7 +125,7 @@ uas_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) 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"); @@ -133,7 +133,7 @@ uas_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) } 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"); @@ -146,7 +146,7 @@ uas_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize) }
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"); diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 2b8e17c..0290d67 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -7,7 +7,7 @@ // // 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 @@ -31,9 +31,9 @@ struct virtiodrive_s { 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, @@ -47,7 +47,7 @@ virtio_blk_op(struct disk_op_s *op, int write) }, { .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), @@ -60,7 +60,7 @@ virtio_blk_op(struct disk_op_s *op, int write) 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)) @@ -72,7 +72,7 @@ virtio_blk_op(struct disk_op_s *op, int write) /* 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; } @@ -105,18 +105,18 @@ init_virtio_blk(struct pci_device *pci) 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; @@ -126,36 +126,36 @@ init_virtio_blk(struct pci_device *pci) 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 diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c index 7cde3bc..4b4ec7b 100644 --- a/src/hw/virtio-scsi.c +++ b/src/hw/virtio-scsi.c @@ -7,7 +7,7 @@ // // 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_* @@ -89,12 +89,13 @@ virtio_scsi_cmd(u16 ioaddr, struct vring_virtqueue *vq, struct disk_op_s *op, 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); }