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