1 | /* $Id: ebda.h 96407 2022-08-22 17:43:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PC BIOS - EBDA (Extended BIOS Data Area) Definition
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2022 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 | #endif
|
---|
89 |
|
---|
90 | #ifdef VBOX_WITH_AHCI
|
---|
91 | /* Four should be enough for now */
|
---|
92 | #define BX_MAX_AHCI_DEVICES 4
|
---|
93 |
|
---|
94 | /* An AHCI device starts always at BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES. */
|
---|
95 | #define VBOX_IS_AHCI_DEVICE(device_id) (device_id >= (BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES))
|
---|
96 | #define VBOX_GET_AHCI_DEVICE(device_id) (device_id - (BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES))
|
---|
97 | #else
|
---|
98 | #define BX_MAX_AHCI_DEVICES 0
|
---|
99 | #endif
|
---|
100 |
|
---|
101 | #ifdef VBOX_WITH_VIRTIO_SCSI
|
---|
102 | /* Four should be enough for now */
|
---|
103 | #define BX_MAX_VIRTIO_SCSI_DEVICES 4
|
---|
104 |
|
---|
105 | /* An AHCI device starts always at BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES. */
|
---|
106 | #define VBOX_IS_VIRTIO_SCSI_DEVICE(device_id) (device_id >= (BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES + BX_MAX_AHCI_DEVICES))
|
---|
107 | #define VBOX_GET_VIRTIO_SCSI_DEVICE(device_id) (device_id - (BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES + BX_MAX_AHCI_DEVICES))
|
---|
108 | #else
|
---|
109 | #define BX_MAX_VIRTIO_SCSI_DEVICES 0
|
---|
110 | #endif
|
---|
111 |
|
---|
112 | #define BX_MAX_STORAGE_DEVICES (BX_MAX_ATA_DEVICES + BX_MAX_SCSI_DEVICES + BX_MAX_AHCI_DEVICES + BX_MAX_VIRTIO_SCSI_DEVICES)
|
---|
113 |
|
---|
114 | /* Generic storage device types. These depend on the controller type and
|
---|
115 | * determine which device access routines should be called.
|
---|
116 | */
|
---|
117 | enum dsk_type_enm {
|
---|
118 | DSK_TYPE_NONE, /* Unknown device. */
|
---|
119 | DSK_TYPE_UNKNOWN, /* Unknown ATA device. */
|
---|
120 | DSK_TYPE_ATA, /* ATA disk. */
|
---|
121 | DSK_TYPE_ATAPI, /* ATAPI device. */
|
---|
122 | DSK_TYPE_SCSI, /* SCSI disk. */
|
---|
123 | DSK_TYPE_AHCI, /* SATA disk via AHCI. */
|
---|
124 | DSKTYP_CNT /* Number of disk types. */
|
---|
125 | };
|
---|
126 |
|
---|
127 | /* Disk device types. */
|
---|
128 | //@todo: Do we really need these?
|
---|
129 | #define DSK_DEVICE_NONE 0x00 /* No device attached. */
|
---|
130 | #define DSK_DEVICE_HD 0xFF /* Device is a hard disk. */
|
---|
131 | #define DSK_DEVICE_CDROM 0x05 /* Device is a CD-ROM. */
|
---|
132 |
|
---|
133 | /* Geometry translation modes. */
|
---|
134 | enum geo_xlat_enm {
|
---|
135 | GEO_TRANSLATION_NONE, /* No geometry translation. */
|
---|
136 | GEO_TRANSLATION_LBA, /* LBA translation. */
|
---|
137 | GEO_TRANSLATION_LARGE, /* Large CHS translation. */
|
---|
138 | GEO_TRANSLATION_RECHS
|
---|
139 | };
|
---|
140 |
|
---|
141 | #if 1 //BX_USE_ATADRV
|
---|
142 |
|
---|
143 | /* Note: The DPTE and FDPT structures are industry standards and
|
---|
144 | * may not be modified. The other disk-related structures are
|
---|
145 | * internal to the BIOS.
|
---|
146 | */
|
---|
147 |
|
---|
148 | /* Translated DPT (Device Parameter Table). */
|
---|
149 | typedef struct {
|
---|
150 | uint16_t iobase1;
|
---|
151 | uint16_t iobase2;
|
---|
152 | uint8_t prefix;
|
---|
153 | uint8_t unused;
|
---|
154 | uint8_t irq;
|
---|
155 | uint8_t blkcount;
|
---|
156 | uint8_t dma;
|
---|
157 | uint8_t pio;
|
---|
158 | uint16_t options;
|
---|
159 | uint16_t reserved;
|
---|
160 | uint8_t revision;
|
---|
161 | uint8_t checksum;
|
---|
162 | } dpte_t;
|
---|
163 |
|
---|
164 | ct_assert(sizeof(dpte_t) == 16); /* Ensure correct size. */
|
---|
165 |
|
---|
166 | #pragma pack(0)
|
---|
167 |
|
---|
168 | /* FDPT - Fixed Disk Parameter Table. PC/AT compatible; note
|
---|
169 | * that this structure is slightly misaligned.
|
---|
170 | */
|
---|
171 | typedef struct {
|
---|
172 | uint16_t lcyl;
|
---|
173 | uint8_t lhead;
|
---|
174 | uint8_t sig;
|
---|
175 | uint8_t spt;
|
---|
176 | uint32_t resvd1;
|
---|
177 | uint16_t cyl;
|
---|
178 | uint8_t head;
|
---|
179 | uint16_t resvd2;
|
---|
180 | uint8_t lspt;
|
---|
181 | uint8_t csum;
|
---|
182 | } fdpt_t;
|
---|
183 |
|
---|
184 | #pragma pack()
|
---|
185 |
|
---|
186 | ct_assert(sizeof(fdpt_t) == 16); /* Ensure correct size. */
|
---|
187 |
|
---|
188 |
|
---|
189 | /* C/H/S geometry information. */
|
---|
190 | typedef struct {
|
---|
191 | uint16_t heads; /* Number of heads. */
|
---|
192 | uint16_t cylinders; /* Number of cylinders. */
|
---|
193 | uint16_t spt; /* Number of sectors per track. */
|
---|
194 | } chs_t;
|
---|
195 |
|
---|
196 | /* IDE/ATA specific device information. */
|
---|
197 | typedef struct {
|
---|
198 | uint8_t iface; /* ISA or PCI. */
|
---|
199 | uint8_t irq; /* IRQ (on the PIC). */
|
---|
200 | uint16_t iobase1; /* I/O base 1. */
|
---|
201 | uint16_t iobase2; /* I/O base 2. */
|
---|
202 | } ata_chan_t;
|
---|
203 |
|
---|
204 | #ifdef VBOX_WITH_SCSI
|
---|
205 |
|
---|
206 | /* SCSI specific device information. */
|
---|
207 | typedef struct {
|
---|
208 | uint16_t hba_seg; /* Segment of HBA driver data block. */
|
---|
209 | uint8_t idx_hba; /* The HBA driver to use. */
|
---|
210 | uint8_t target_id; /* Target ID. */
|
---|
211 | } scsi_dev_t;
|
---|
212 |
|
---|
213 | #endif
|
---|
214 |
|
---|
215 | #ifdef VBOX_WITH_AHCI
|
---|
216 |
|
---|
217 | /* AHCI specific device information. */
|
---|
218 | typedef struct {
|
---|
219 | uint8_t port; /* SATA port. */
|
---|
220 | } ahci_dev_t;
|
---|
221 |
|
---|
222 | #endif
|
---|
223 |
|
---|
224 | /* Generic disk information. */
|
---|
225 | typedef struct {
|
---|
226 | uint8_t type; /* Device type (ATA/ATAPI/SCSI/none/unknown). */
|
---|
227 | uint8_t device; /* Detected type of attached device (HD/CD/none). */
|
---|
228 | uint8_t removable; /* Removable device flag. */
|
---|
229 | uint8_t lock; /* Lock count for removable devices. */
|
---|
230 | //@todo: ATA specific - move?
|
---|
231 | uint8_t mode; /* Transfer mode: PIO 16/32 bits - IRQ - ISADMA - PCIDMA. */
|
---|
232 | uint8_t translation; /* Type of geometry translation. */
|
---|
233 | uint16_t blksize; /* Disk block size. */
|
---|
234 | chs_t lchs; /* Logical CHS geometry. */
|
---|
235 | chs_t pchs; /* Physical CHS geometry. */
|
---|
236 | uint64_t sectors; /* Total sector count. */
|
---|
237 | } disk_dev_t;
|
---|
238 |
|
---|
239 | /* A structure for passing disk request information around. This structure
|
---|
240 | * is designed for saving stack space. As BIOS requests cannot be overlapped,
|
---|
241 | * one such structure is sufficient.
|
---|
242 | */
|
---|
243 | typedef struct {
|
---|
244 | uint64_t lba; /* Starting LBA. */
|
---|
245 | void __far *buffer; /* Read/write data buffer pointer. */
|
---|
246 | uint8_t dev_id; /* Device ID; index into devices array. */
|
---|
247 | uint16_t nsect; /* Number of sectors to be transferred. */
|
---|
248 | uint16_t sect_sz; /* Size of a sector in bytes. */
|
---|
249 | uint16_t cylinder; /* Starting cylinder (CHS only). */
|
---|
250 | uint16_t head; /* Starting head (CHS only). */
|
---|
251 | uint16_t sector; /* Starting sector (CHS only). */
|
---|
252 | uint16_t trsfsectors; /* Actual sectors transferred. */
|
---|
253 | uint32_t trsfbytes; /* Actual bytes transferred. */
|
---|
254 | } disk_req_t;
|
---|
255 |
|
---|
256 | extern uint16_t ahci_cmd_packet(uint16_t device_id, uint8_t cmdlen, char __far *cmdbuf,
|
---|
257 | uint32_t length, uint8_t inout, char __far *buffer);
|
---|
258 | extern uint16_t scsi_cmd_packet(uint16_t device, uint8_t cmdlen, char __far *cmdbuf,
|
---|
259 | uint32_t length, uint8_t inout, char __far *buffer);
|
---|
260 | extern uint16_t ata_cmd_packet(uint16_t device, uint8_t cmdlen, char __far *cmdbuf,
|
---|
261 | uint32_t length, uint8_t inout, char __far *buffer);
|
---|
262 |
|
---|
263 | extern uint16_t ata_soft_reset(uint16_t device);
|
---|
264 |
|
---|
265 | /* All BIOS disk information. Disk-related code in the BIOS should not need
|
---|
266 | * anything outside of this structure.
|
---|
267 | */
|
---|
268 | typedef struct {
|
---|
269 | disk_req_t drqp; /* Disk request packet. */
|
---|
270 |
|
---|
271 | /* Bus-independent disk device information. */
|
---|
272 | disk_dev_t devices[BX_MAX_STORAGE_DEVICES];
|
---|
273 |
|
---|
274 | uint8_t hdcount; /* Total number of BIOS disks. */
|
---|
275 | /* Map between (BIOS disk ID - 0x80) and ATA/SCSI/AHCI disks. */
|
---|
276 | uint8_t hdidmap[BX_MAX_STORAGE_DEVICES];
|
---|
277 |
|
---|
278 | uint8_t cdcount; /* Number of CD-ROMs. */
|
---|
279 | /* Map between (BIOS CD-ROM ID - 0xE0) and ATA/SCSI/AHCI devices. */
|
---|
280 | uint8_t cdidmap[BX_MAX_STORAGE_DEVICES];
|
---|
281 |
|
---|
282 | /* ATA bus-specific device information. */
|
---|
283 | ata_chan_t channels[BX_MAX_ATA_INTERFACES];
|
---|
284 |
|
---|
285 | #ifdef VBOX_WITH_SCSI
|
---|
286 | /* SCSI bus-specific device information. */
|
---|
287 | scsi_dev_t scsidev[BX_MAX_SCSI_DEVICES];
|
---|
288 | uint8_t scsi_devcount; /* Number of SCSI devices. */
|
---|
289 | #endif
|
---|
290 |
|
---|
291 | #ifdef VBOX_WITH_AHCI
|
---|
292 | /* SATA (AHCI) bus-specific device information. */
|
---|
293 | ahci_dev_t ahcidev[BX_MAX_AHCI_DEVICES];
|
---|
294 | uint8_t ahci_devcnt; /* Number of SATA devices. */
|
---|
295 | uint16_t ahci_seg; /* Segment of AHCI data block. */
|
---|
296 | #endif
|
---|
297 |
|
---|
298 | dpte_t dpte; /* Buffer for building a DPTE. */
|
---|
299 | } bio_dsk_t;
|
---|
300 |
|
---|
301 | #if BX_ELTORITO_BOOT
|
---|
302 | /* El Torito device emulation state. */
|
---|
303 | typedef struct {
|
---|
304 | uint8_t active;
|
---|
305 | uint8_t media;
|
---|
306 | uint8_t emulated_drive;
|
---|
307 | uint8_t controller_index;
|
---|
308 | uint16_t device_spec;
|
---|
309 | uint16_t buffer_segment;
|
---|
310 | uint32_t ilba;
|
---|
311 | uint16_t load_segment;
|
---|
312 | uint16_t sector_count;
|
---|
313 | chs_t vdevice; /* Virtual device geometry. */
|
---|
314 | uint8_t __far *ptr_unaligned; /* Bounce buffer for sector unaligned reads. */
|
---|
315 | } cdemu_t;
|
---|
316 | #endif
|
---|
317 |
|
---|
318 | // for access to EBDA area
|
---|
319 | // The EBDA structure should conform to
|
---|
320 | // http://www.frontiernet.net/~fys/rombios.htm document
|
---|
321 | // I made the ata and cdemu structs begin at 0x121 in the EBDA seg
|
---|
322 | /* MS-DOS KEYB.COM may overwrite the word at offset 0x117 in the EBDA
|
---|
323 | * which contains the keyboard ID for PS/2 BIOSes.
|
---|
324 | */
|
---|
325 | typedef struct {
|
---|
326 | uint8_t filler1[0x3D];
|
---|
327 |
|
---|
328 | fdpt_t fdpt0; /* FDPTs for the first two ATA disks. */
|
---|
329 | fdpt_t fdpt1;
|
---|
330 |
|
---|
331 | #ifndef VBOX_WITH_VIRTIO_SCSI /** @todo For development only, need to find a real solution to voercome the 1KB limit. */
|
---|
332 | uint8_t filler2[0xC4];
|
---|
333 | #endif
|
---|
334 |
|
---|
335 | bio_dsk_t bdisk; /* Disk driver data (ATA/SCSI/AHCI). */
|
---|
336 |
|
---|
337 | #if BX_ELTORITO_BOOT
|
---|
338 | cdemu_t cdemu; /* El Torito floppy/HD emulation data. */
|
---|
339 | #endif
|
---|
340 |
|
---|
341 | unsigned char uForceBootDrive;
|
---|
342 | unsigned char uForceBootDevice;
|
---|
343 | } ebda_data_t;
|
---|
344 |
|
---|
345 | ct_assert(sizeof(ebda_data_t) < 0x380); /* Must be under 1K in size. */
|
---|
346 |
|
---|
347 | // the last 16 bytes of the EBDA segment are used for the MPS floating
|
---|
348 | // pointer structure (though only if an I/O APIC is present)
|
---|
349 |
|
---|
350 | #define EbdaData ((ebda_data_t *) 0)
|
---|
351 |
|
---|
352 | // for access to the int13ext structure
|
---|
353 | typedef struct {
|
---|
354 | uint8_t size;
|
---|
355 | uint8_t reserved;
|
---|
356 | uint16_t count;
|
---|
357 | uint16_t offset;
|
---|
358 | uint16_t segment;
|
---|
359 | uint32_t lba1;
|
---|
360 | uint32_t lba2;
|
---|
361 | } int13ext_t;
|
---|
362 |
|
---|
363 | /* Disk Physical Table structure */
|
---|
364 | typedef struct {
|
---|
365 | uint16_t size;
|
---|
366 | uint16_t infos;
|
---|
367 | uint32_t cylinders;
|
---|
368 | uint32_t heads;
|
---|
369 | uint32_t spt;
|
---|
370 | uint32_t sector_count1;
|
---|
371 | uint32_t sector_count2;
|
---|
372 | uint16_t blksize;
|
---|
373 | uint16_t dpte_offset;
|
---|
374 | uint16_t dpte_segment;
|
---|
375 | uint16_t key;
|
---|
376 | uint8_t dpi_length;
|
---|
377 | uint8_t reserved1;
|
---|
378 | uint16_t reserved2;
|
---|
379 | uint8_t host_bus[4];
|
---|
380 | uint8_t iface_type[8];
|
---|
381 | uint8_t iface_path[8];
|
---|
382 | uint8_t device_path[8];
|
---|
383 | uint8_t reserved3;
|
---|
384 | uint8_t checksum;
|
---|
385 | } dpt_t;
|
---|
386 |
|
---|
387 | /* Note: Using fastcall reduces stack usage a little. */
|
---|
388 | int __fastcall ata_read_sectors(bio_dsk_t __far *bios_dsk);
|
---|
389 | int __fastcall ata_write_sectors(bio_dsk_t __far *bios_dsk);
|
---|
390 |
|
---|
391 | int __fastcall scsi_read_sectors(bio_dsk_t __far *bios_dsk);
|
---|
392 | int __fastcall scsi_write_sectors(bio_dsk_t __far *bios_dsk);
|
---|
393 |
|
---|
394 | int __fastcall ahci_read_sectors(bio_dsk_t __far *bios_dsk);
|
---|
395 | int __fastcall ahci_write_sectors(bio_dsk_t __far *bios_dsk);
|
---|
396 |
|
---|
397 | extern void set_geom_lba(chs_t __far *lgeo, uint64_t nsectors);
|
---|
398 | extern int edd_fill_dpt(dpt_t __far *dpt, bio_dsk_t __far *bios_dsk, uint8_t device);
|
---|
399 |
|
---|
400 | // @todo: put this elsewhere (and change/eliminate?)
|
---|
401 | #define SET_DISK_RET_STATUS(status) write_byte(0x0040, 0x0074, status)
|
---|
402 |
|
---|
403 | #endif
|
---|
404 | #endif /* !VBOX_INCLUDED_SRC_PC_BIOS_ebda_h */
|
---|
405 |
|
---|