1 | /* $Id: vds.h 69300 2017-10-25 13:38:41Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Utility routines for calling the Virtual DMA Services.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2016 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 | /* Virtual DMA Services (VDS) */
|
---|
20 |
|
---|
21 | #define VDS_FLAGS_OFS 0x7B /* Offset of VDS flag byte in BDA. */
|
---|
22 | #define VDS_PRESENT 0x20 /* The VDS present bit. */
|
---|
23 |
|
---|
24 | /** The DMA descriptor data structure. */
|
---|
25 | typedef struct
|
---|
26 | {
|
---|
27 | uint32_t region_size; /* Region size in bytes. */
|
---|
28 | uint32_t offset; /* Offset. */
|
---|
29 | uint16_t seg_sel; /* Segment selector. */
|
---|
30 | uint16_t buf_id; /* Buffer ID. */
|
---|
31 | uint32_t phys_addr; /* Physical address. */
|
---|
32 | } vds_dds;
|
---|
33 |
|
---|
34 |
|
---|
35 | /** Scatter/gather descriptor entry. */
|
---|
36 | typedef struct
|
---|
37 | {
|
---|
38 | uint32_t phys_addr; /* Physical address. */
|
---|
39 | uint32_t size; /* Entry size. */
|
---|
40 | } vds_sg;
|
---|
41 |
|
---|
42 | /** The extended DDS for scatter/gather.
|
---|
43 | * Note that the EDDS contains either S/G descriptors or x86-style PTEs.
|
---|
44 | */
|
---|
45 | typedef struct
|
---|
46 | {
|
---|
47 | uint32_t region_size; /* Region size in bytes. */
|
---|
48 | uint32_t offset; /* Offset. */
|
---|
49 | uint16_t seg_sel; /* Segment or selector. */
|
---|
50 | uint16_t resvd; /* Reserved. */
|
---|
51 | uint16_t num_avail; /* Number of entries available. */
|
---|
52 | uint16_t num_used; /* Number of entries used. */
|
---|
53 | union
|
---|
54 | {
|
---|
55 | vds_sg sg[1]; /* S/G entry array. */
|
---|
56 | uint32_t pte[1]; /* Page table entry array. */
|
---|
57 | } u;
|
---|
58 | } vds_edds;
|
---|
59 |
|
---|
60 |
|
---|
61 | /* VDS services */
|
---|
62 |
|
---|
63 | #define VDS_SERVICE 0x81
|
---|
64 |
|
---|
65 | #define VDS_GET_VERSION 0x02 /* Get version */
|
---|
66 | #define VDS_LOCK_BUFFER 0x03 /* Lock DMA buffer region */
|
---|
67 | #define VDS_UNLOCK_BUFFER 0x04 /* Unlock DMA buffer region */
|
---|
68 | #define VDS_SG_LOCK 0x05 /* Scatter/gather lock region */
|
---|
69 | #define VDS_SG_UNLOCK 0x06 /* Scatter/gather unlock region */
|
---|
70 | #define VDS_REQUEST_BUFFER 0x07 /* Request DMA buffer */
|
---|
71 | #define VDS_RELEASE_BUFFER 0x08 /* Release DMA buffer */
|
---|
72 | #define VDS_BUFFER_COPYIN 0x09 /* Copy into DMA buffer */
|
---|
73 | #define VDS_BUFFER_COPYOUT 0x0A /* Copy out of DMA buffer */
|
---|
74 | #define VDS_DISABLE_DMA_XLAT 0x0B /* Disable DMA translation */
|
---|
75 | #define VDS_ENABLE_DMA_XLAT 0x0C /* Enable DMA translation */
|
---|
76 |
|
---|
77 | /* VDS error codes */
|
---|
78 |
|
---|
79 | #define VDS_SUCCESS 0x00 /* No error */
|
---|
80 | #define VDS_ERR_NOT_CONTIG 0x01 /* Region not contiguous */
|
---|
81 | #define VDS_ERR_BOUNDRY_CROSS 0x02 /* Rgn crossed phys align boundary */
|
---|
82 | #define VDS_ERR_CANT_LOCK 0x03 /* Unable to lock pages */
|
---|
83 | #define VDS_ERR_NO_BUF 0x04 /* No buffer available */
|
---|
84 | #define VDS_ERR_RGN_TOO_BIG 0x05 /* Region too large for buffer */
|
---|
85 | #define VDS_ERR_BUF_IN_USE 0x06 /* Buffer currently in use */
|
---|
86 | #define VDS_ERR_RGN_INVALID 0x07 /* Invalid memory region */
|
---|
87 | #define VDS_ERR_RGN_NOT_LOCKED 0x08 /* Region was not locked */
|
---|
88 | #define VDS_ERR_TOO_MANY_PAGES 0x09 /* Num pages greater than table len */
|
---|
89 | #define VDS_ERR_INVALID_ID 0x0A /* Invalid buffer ID */
|
---|
90 | #define VDS_ERR_BNDRY_VIOL 0x0B /* Buffer boundary violated */
|
---|
91 | #define VDS_ERR_INVAL_DMACHN 0x0C /* Invalid DMA channel number */
|
---|
92 | #define VDS_ERR_COUNT_OVRFLO 0x0D /* Disable count overflow */
|
---|
93 | #define VDS_ERR_COUNT_UNDRFLO 0x0E /* Disable count underflow */
|
---|
94 | #define VDS_ERR_UNSUPP_FUNC 0x0F /* Function not supported */
|
---|
95 | #define VDS_ERR_BAD_FLAG 0x10 /* Reserved flag bits set in DX */
|
---|
96 |
|
---|
97 | /* VDS option flags */
|
---|
98 |
|
---|
99 | #define VDSF_AUTOCOPY 0x02 /* Automatic copy to/from buffer */
|
---|
100 | #define VDSF_NOALLOC 0x04 /* Disable auto buffer allocation */
|
---|
101 | #define VDSF_NOREMAP 0x08 /* Disable auto remap feature */
|
---|
102 | #define VDSF_NO64K 0x10 /* Region can't cross 64K boundary */
|
---|
103 | #define VDSF_NO128K 0x20 /* Region can't cross 128K boundary */
|
---|
104 | #define VDSF_COPYTBL 0x40 /* Copy page table for S/G remap */
|
---|
105 | #define VDSF_NPOK 0x80 /* Allow non-present pages for S/G */
|
---|
106 |
|
---|
107 | /* Higher level routines for utilizing VDS. */
|
---|
108 |
|
---|
109 | int vds_build_sg_list( vds_edds __far *edds, void __far *buf, uint32_t len );
|
---|
110 | int vds_free_sg_list( vds_edds __far *edds );
|
---|
111 |
|
---|
112 | /* Helper for translating 16:16 real mode addresses to 32-bit linear. */
|
---|
113 |
|
---|
114 | uint32_t vds_real_to_lin( void __far *ptr );
|
---|
115 |
|
---|