VirtualBox

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

Last change on this file since 87766 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette