VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/BIOS/vds.c@ 106061

Last change on this file since 106061 was 106061, checked in by vboxsync, 7 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/* $Id: vds.c 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * Utility routines for calling the Virtual DMA Services.
4 */
5
6/*
7 * Copyright (C) 2011-2024 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
29#include <stdint.h>
30#include "biosint.h"
31#include "vds.h"
32
33typedef struct {
34 uint8_t major; /* VDS spec major version number. */
35 uint8_t minor; /* VDS spec minor version number. */
36 uint16_t flags; /* Capabilities/status flags. */
37 uint16_t prod_no; /* Product number. */
38 uint16_t prod_rev; /* Product revision number. */
39 uint32_t max_buf; /* Maximum buffer size supported. */
40} vds_ver;
41
42int vds_is_present( void )
43{
44 uint8_t __far *vds_flags;
45
46 vds_flags = MK_FP( 0x40, VDS_FLAGS_OFS );
47 return( !!(*vds_flags & VDS_PRESENT) );
48}
49
50int vds_lock_sg( vds_edds __far *edds );
51#pragma aux vds_lock_sg = \
52 "mov ax, 8105h" \
53 "mov dx, 0" \
54 "int 4Bh" \
55 "jc error" \
56 "xor al, al" \
57 "error:" \
58 "cbw" \
59 parm [es di] value [ax] modify [dx];
60
61int vds_unlock_sg( vds_edds __far *edds );
62#pragma aux vds_unlock_sg = \
63 "mov ax, 8106h" \
64 "mov dx, 0" \
65 "int 4Bh" \
66 "jc error" \
67 "xor al, al" \
68 "error:" \
69 "cbw" \
70 parm [es di] value [ax] modify [dx];
71
72
73/*
74 * Convert a real mode 16:16 segmented address to a simple 32-bit
75 * linear address.
76 */
77uint32_t vds_real_to_lin( void __far *ptr )
78{
79 return( ((uint32_t)FP_SEG( ptr ) << 4) + FP_OFF( ptr ) );
80}
81
82/*
83 * Build a VDS-style scatter/gather list, regardless of whether VDS is
84 * present or not. This routine either calls VDS to do the work or
85 * trivially creates the list if no remapping is needed.
86 */
87int vds_build_sg_list( vds_edds __far *edds, void __far *buf, uint32_t len )
88{
89 int rc;
90
91 /* NB: The num_avail field in the EDDS must be set correctly! */
92 edds->region_size = len;
93 edds->offset = vds_real_to_lin( buf );
94 edds->seg_sel = 0; /* Indicates a linear address. */
95 if( vds_is_present() ) {
96 /* VDS is present, use it. */
97 rc = vds_lock_sg( edds );
98 } else {
99 /* No VDS, do it ourselves with one S/G entry. */
100 edds->num_used = 1;
101 edds->u.sg[0].phys_addr = edds->offset;
102 edds->u.sg[0].size = len;
103 rc = VDS_SUCCESS;
104 }
105 return( rc );
106}
107
108/*
109 * Free a VDS-style scatter/gather list, regardless of whether VDS
110 * is present or not.
111 */
112int vds_free_sg_list( vds_edds __far *edds )
113{
114 int rc;
115
116 if( vds_is_present() ) {
117 /* VDS is present, use it. */
118 rc = vds_unlock_sg( edds );
119 } else {
120 /* No VDS, not much to do. */
121 /* We could check here if the EDDS had in fact been built by us.
122 * But if VDS really went away, what can we do about it anyway?
123 */
124 rc = VDS_SUCCESS;
125 }
126 edds->num_used = 0;
127 return( rc );
128}
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