VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/BIOS/ebda.h@ 104142

Last change on this file since 104142 was 104142, checked in by vboxsync, 6 weeks ago

BIOS: Removed VBOX_IS_VIRTIO_SCSI_DEVICE and associated cruft. It's no longer used, virtio-scsi is treated the same as other SCSI HBAs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.2 KB
Line 
1/* $Id: ebda.h 104142 2024-04-03 15:49:45Z vboxsync $ */
2/** @file
3 * PC BIOS - EBDA (Extended BIOS Data Area) Definition
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 * --------------------------------------------------------------------
27 *
28 * This code is based on:
29 *
30 * ROM BIOS for use with Bochs/Plex86/QEMU emulation environment
31 *
32 * Copyright (C) 2002 MandrakeSoft S.A.
33 *
34 * MandrakeSoft S.A.
35 * 43, rue d'Aboukir
36 * 75002 Paris - France
37 * http://www.linux-mandrake.com/
38 * http://www.mandrakesoft.com/
39 *
40 * This library is free software; you can redistribute it and/or
41 * modify it under the terms of the GNU Lesser General Public
42 * License as published by the Free Software Foundation; either
43 * version 2 of the License, or (at your option) any later version.
44 *
45 * This library is distributed in the hope that it will be useful,
46 * but WITHOUT ANY WARRANTY; without even the implied warranty of
47 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
48 * Lesser General Public License for more details.
49 *
50 * You should have received a copy of the GNU Lesser General Public
51 * License along with this library; if not, write to the Free Software
52 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
53 *
54 */
55
56/*
57 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
58 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
59 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
60 * a choice of LGPL license versions is made available with the language indicating
61 * that LGPLv2 or any later version may be used, or where a choice of which version
62 * of the LGPL is applied is otherwise unspecified.
63 */
64
65#ifndef VBOX_INCLUDED_SRC_PC_BIOS_ebda_h
66#define VBOX_INCLUDED_SRC_PC_BIOS_ebda_h
67#ifndef RT_WITHOUT_PRAGMA_ONCE
68# pragma once
69#endif
70
71#include <stdint.h>
72
73/* Must be defined here (EBDA structures depend on these). */
74#define BX_MAX_ATA_INTERFACES 4
75#define BX_MAX_ATA_DEVICES (BX_MAX_ATA_INTERFACES*2)
76
77#define BX_USE_ATADRV 1
78#define BX_ELTORITO_BOOT 1
79
80#ifdef VBOX_WITH_SCSI
81 /* Enough for now */
82 #define BX_MAX_SCSI_DEVICES 4
83 /* A SCSI device starts always at BX_MAX_ATA_DEVICES. */
84 #define VBOX_IS_SCSI_DEVICE(device_id) (device_id >= BX_MAX_ATA_DEVICES)
85 #define VBOX_GET_SCSI_DEVICE(device_id) (device_id - BX_MAX_ATA_DEVICES)
86#else
87 #define BX_MAX_SCSI_DEVICES 0
88 #define VBOX_IS_SCSI_DEVICE(device_id) (1 == 0)
89#endif
90
91#ifdef VBOX_WITH_AHCI
92 /* Four should be enough for now */
93 #define BX_MAX_AHCI_DEVICES 4
94
95 /* An AHCI device starts always at BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES. */
96 #define VBOX_IS_AHCI_DEVICE(device_id) (device_id >= (BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES))
97 #define VBOX_GET_AHCI_DEVICE(device_id) (device_id - (BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES))
98#else
99 #define BX_MAX_AHCI_DEVICES 0
100#endif
101
102#define BX_MAX_STORAGE_DEVICES (BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES + BX_MAX_AHCI_DEVICES)
103
104/* Generic storage device types. These depend on the controller type and
105 * determine which device access routines should be called.
106 */
107enum dsk_type_enm {
108 DSK_TYPE_NONE, /* Unknown device. */
109 DSK_TYPE_UNKNOWN, /* Unknown ATA device. */
110 DSK_TYPE_ATA, /* ATA disk. */
111 DSK_TYPE_ATAPI, /* ATAPI device. */
112 DSK_TYPE_SCSI, /* SCSI disk. */
113 DSK_TYPE_AHCI, /* SATA disk via AHCI. */
114 DSKTYP_CNT /* Number of disk types. */
115};
116
117/* Disk device types. */
118//@todo: Do we really need these?
119#define DSK_DEVICE_NONE 0x00 /* No device attached. */
120#define DSK_DEVICE_HD 0xFF /* Device is a hard disk. */
121#define DSK_DEVICE_CDROM 0x05 /* Device is a CD-ROM. */
122
123/* Geometry translation modes. */
124enum geo_xlat_enm {
125 GEO_TRANSLATION_NONE, /* No geometry translation. */
126 GEO_TRANSLATION_LBA, /* LBA translation. */
127 GEO_TRANSLATION_LARGE, /* Large CHS translation. */
128 GEO_TRANSLATION_RECHS
129};
130
131#if 1 //BX_USE_ATADRV
132
133/* Note: The DPTE and FDPT structures are industry standards and
134 * may not be modified. The other disk-related structures are
135 * internal to the BIOS.
136 */
137
138/* Translated DPT (Device Parameter Table). */
139typedef struct {
140 uint16_t iobase1;
141 uint16_t iobase2;
142 uint8_t prefix;
143 uint8_t unused;
144 uint8_t irq;
145 uint8_t blkcount;
146 uint8_t dma;
147 uint8_t pio;
148 uint16_t options;
149 uint16_t reserved;
150 uint8_t revision;
151 uint8_t checksum;
152} dpte_t;
153
154ct_assert(sizeof(dpte_t) == 16); /* Ensure correct size. */
155
156#pragma pack(0)
157
158/* FDPT - Fixed Disk Parameter Table. PC/AT compatible; note
159 * that this structure is slightly misaligned.
160 */
161typedef struct {
162 uint16_t lcyl;
163 uint8_t lhead;
164 uint8_t sig;
165 uint8_t spt;
166 uint32_t resvd1;
167 uint16_t cyl;
168 uint8_t head;
169 uint16_t resvd2;
170 uint8_t lspt;
171 uint8_t csum;
172} fdpt_t;
173
174#pragma pack()
175
176ct_assert(sizeof(fdpt_t) == 16); /* Ensure correct size. */
177
178
179/* C/H/S geometry information. */
180typedef struct {
181 uint16_t heads; /* Number of heads. */
182 uint16_t cylinders; /* Number of cylinders. */
183 uint16_t spt; /* Number of sectors per track. */
184} chs_t;
185
186/* IDE/ATA specific device information. */
187typedef struct {
188 uint8_t iface; /* ISA or PCI. */
189 uint8_t irq; /* IRQ (on the PIC). */
190 uint16_t iobase1; /* I/O base 1. */
191 uint16_t iobase2; /* I/O base 2. */
192} ata_chan_t;
193
194#ifdef VBOX_WITH_SCSI
195
196/* SCSI specific device information. */
197typedef struct {
198 uint16_t hba_seg; /* Segment of HBA driver data block. */
199 uint8_t idx_hba; /* The HBA driver to use. */
200 uint8_t target_id; /* Target ID. */
201} scsi_dev_t;
202
203#endif
204
205#ifdef VBOX_WITH_AHCI
206
207/* AHCI specific device information. */
208typedef struct {
209 uint8_t port; /* SATA port. */
210} ahci_dev_t;
211
212#endif
213
214/* Generic disk information. */
215typedef struct {
216 uint8_t type; /* Device type (ATA/ATAPI/SCSI/none/unknown). */
217 uint8_t device; /* Detected type of attached device (HD/CD/none). */
218 uint8_t removable; /* Removable device flag. */
219 uint8_t lock; /* Lock count for removable devices. */
220 //@todo: ATA specific - move?
221 uint8_t mode; /* Transfer mode: PIO 16/32 bits - IRQ - ISADMA - PCIDMA. */
222 uint8_t translation; /* Type of geometry translation. */
223 uint16_t blksize; /* Disk block size. */
224 chs_t lchs; /* Logical CHS geometry. */
225 chs_t pchs; /* Physical CHS geometry. */
226 uint64_t sectors; /* Total sector count. */
227} disk_dev_t;
228
229/* A structure for passing disk request information around. This structure
230 * is designed for saving stack space. As BIOS requests cannot be overlapped,
231 * one such structure is sufficient.
232 */
233typedef struct {
234 uint64_t lba; /* Starting LBA. */
235 void __far *buffer; /* Read/write data buffer pointer. */
236 uint8_t dev_id; /* Device ID; index into devices array. */
237 uint16_t nsect; /* Number of sectors to be transferred. */
238 uint16_t sect_sz; /* Size of a sector in bytes. */
239 uint16_t cylinder; /* Starting cylinder (CHS only). */
240 uint16_t head; /* Starting head (CHS only). */
241 uint16_t sector; /* Starting sector (CHS only). */
242 uint16_t trsfsectors; /* Actual sectors transferred. */
243 uint32_t trsfbytes; /* Actual bytes transferred. */
244} disk_req_t;
245
246extern uint16_t ahci_cmd_packet(uint16_t device_id, uint8_t cmdlen, char __far *cmdbuf,
247 uint32_t length, uint8_t inout, char __far *buffer);
248extern uint16_t scsi_cmd_packet(uint16_t device, uint8_t cmdlen, char __far *cmdbuf,
249 uint32_t length, uint8_t inout, char __far *buffer);
250extern uint16_t ata_cmd_packet(uint16_t device, uint8_t cmdlen, char __far *cmdbuf,
251 uint32_t length, uint8_t inout, char __far *buffer);
252
253extern uint16_t ata_soft_reset(uint16_t device);
254
255/* All BIOS disk information. Disk-related code in the BIOS should not need
256 * anything outside of this structure.
257 */
258typedef struct {
259 disk_req_t drqp; /* Disk request packet. */
260
261 /* Bus-independent disk device information. */
262 disk_dev_t devices[BX_MAX_STORAGE_DEVICES];
263
264 uint8_t hdcount; /* Total number of BIOS disks. */
265 /* Map between (BIOS disk ID - 0x80) and ATA/SCSI/AHCI disks. */
266 uint8_t hdidmap[BX_MAX_STORAGE_DEVICES];
267
268 uint8_t cdcount; /* Number of CD-ROMs. */
269 /* Map between (BIOS CD-ROM ID - 0xE0) and ATA/SCSI/AHCI devices. */
270 uint8_t cdidmap[BX_MAX_STORAGE_DEVICES];
271
272 /* ATA bus-specific device information. */
273 ata_chan_t channels[BX_MAX_ATA_INTERFACES];
274
275#ifdef VBOX_WITH_SCSI
276 /* SCSI bus-specific device information. */
277 scsi_dev_t scsidev[BX_MAX_SCSI_DEVICES];
278 uint8_t scsi_devcount; /* Number of SCSI devices. */
279#endif
280
281#ifdef VBOX_WITH_AHCI
282 /* SATA (AHCI) bus-specific device information. */
283 ahci_dev_t ahcidev[BX_MAX_AHCI_DEVICES];
284 uint8_t ahci_devcnt; /* Number of SATA devices. */
285 uint16_t ahci_seg; /* Segment of AHCI data block. */
286#endif
287
288 dpte_t dpte; /* Buffer for building a DPTE. */
289} bio_dsk_t;
290
291#if BX_ELTORITO_BOOT
292/* El Torito device emulation state. */
293typedef struct {
294 uint8_t active;
295 uint8_t media;
296 uint8_t emulated_drive;
297 uint8_t controller_index;
298 uint16_t device_spec;
299 uint16_t buffer_segment;
300 uint32_t ilba;
301 uint16_t load_segment;
302 uint16_t sector_count;
303 chs_t vdevice; /* Virtual device geometry. */
304 uint8_t __far *ptr_unaligned; /* Bounce buffer for sector unaligned reads. */
305} cdemu_t;
306#endif
307
308// for access to EBDA area
309// The EBDA structure should conform to
310// http://www.frontiernet.net/~fys/rombios.htm document
311// I made the ata and cdemu structs begin at 0x121 in the EBDA seg
312/* MS-DOS KEYB.COM may overwrite the word at offset 0x117 in the EBDA
313 * which contains the keyboard ID for PS/2 BIOSes.
314 */
315typedef struct {
316 uint8_t filler1[0x3D];
317
318 fdpt_t fdpt0; /* FDPTs for the first two ATA disks. */
319 fdpt_t fdpt1;
320
321 bio_dsk_t bdisk; /* Disk driver data (ATA/SCSI/AHCI). */
322
323#if BX_ELTORITO_BOOT
324 cdemu_t cdemu; /* El Torito floppy/HD emulation data. */
325#endif
326
327 unsigned char uForceBootDrive;
328 unsigned char uForceBootDevice;
329} ebda_data_t;
330
331ct_assert(sizeof(ebda_data_t) < 0x380); /* Must be under 1K in size. */
332
333// the last 16 bytes of the EBDA segment are used for the MPS floating
334// pointer structure (though only if an I/O APIC is present)
335
336#define EbdaData ((ebda_data_t *) 0)
337
338// for access to the int13ext structure
339typedef struct {
340 uint8_t size;
341 uint8_t reserved;
342 uint16_t count;
343 uint16_t offset;
344 uint16_t segment;
345 uint32_t lba1;
346 uint32_t lba2;
347} int13ext_t;
348
349/* Disk Physical Table structure */
350typedef struct {
351 uint16_t size;
352 uint16_t infos;
353 uint32_t cylinders;
354 uint32_t heads;
355 uint32_t spt;
356 uint32_t sector_count1;
357 uint32_t sector_count2;
358 uint16_t blksize;
359 uint16_t dpte_offset;
360 uint16_t dpte_segment;
361 uint16_t key;
362 uint8_t dpi_length;
363 uint8_t reserved1;
364 uint16_t reserved2;
365 uint8_t host_bus[4];
366 uint8_t iface_type[8];
367 uint8_t iface_path[8];
368 uint8_t device_path[8];
369 uint8_t reserved3;
370 uint8_t checksum;
371} dpt_t;
372
373/* Note: Using fastcall reduces stack usage a little. */
374int __fastcall ata_read_sectors(bio_dsk_t __far *bios_dsk);
375int __fastcall ata_write_sectors(bio_dsk_t __far *bios_dsk);
376
377int __fastcall scsi_read_sectors(bio_dsk_t __far *bios_dsk);
378int __fastcall scsi_write_sectors(bio_dsk_t __far *bios_dsk);
379
380int __fastcall ahci_read_sectors(bio_dsk_t __far *bios_dsk);
381int __fastcall ahci_write_sectors(bio_dsk_t __far *bios_dsk);
382
383extern void set_geom_lba(chs_t __far *lgeo, uint64_t nsectors);
384extern int edd_fill_dpt(dpt_t __far *dpt, bio_dsk_t __far *bios_dsk, uint8_t device);
385
386// @todo: put this elsewhere (and change/eliminate?)
387#define SET_DISK_RET_STATUS(status) write_byte(0x0040, 0x0074, status)
388
389#endif
390#endif /* !VBOX_INCLUDED_SRC_PC_BIOS_ebda_h */
391
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use