summaryrefslogtreecommitdiffstats
path: root/private/ntos/miniport/trantor/source/scsiport.c
blob: 30be5fc840f030169925ac4076c7c94473a81907 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//------------------------------------------------------------------------
//
//  SCSIPORT.C 
//
//  DOS Port Access File
//
//  Contains functions to access I/O and memory ports.  Some of these
//  routines may not be called for some cards.  IO access routines are
//  called for IO mapped cards, Mem access routines are called for Mem
//  mapped cards.
//
//  For DOS these are simple assembly functions.
//
//  Revisions:
//      01-29-93 KJB First.
//      03-03-93 KJB Improved comments.
//      03-22-93 KJB Reorged for stub function library.
//      03-25-93  JAP   Fixed up typedef and prototype inconsistencies
//
//------------------------------------------------------------------------


#include CARDTXXX_H

//
//  ScsiPortReadPortUchar
//
//  Does an "in" instruction from i/o port p.
//  Returns the value.
//

UCHAR ScsiPortReadPortUchar (PUCHAR p)
{
    UCHAR rval;

    _asm {
        mov dx,word ptr p
        in al,dx
        mov rval,al
    }
    return rval;
}

//
//  ScsiPortWritePortUchar
//
//  Does an "out" instruction to i/o port p.
//
VOID ScsiPortWritePortUchar(PUCHAR p,UCHAR b)
{
    _asm {
        mov dx,word ptr p
        mov al,b
        out dx,al
    }
}

//
//  ScsiPortReadPortUshort
//
//  Does an "in" instruction from i/o port p.
//  Returns the value.
//
USHORT ScsiPortReadPortUshort(PUSHORT p)
{
    USHORT rval;

    _asm {
        mov dx,word ptr p
        in ax,dx
        mov rval,ax
    }
    return rval;
}

//
//  ScsiPortWritePortUshort
//
//  Does an "out" instruction to i/o port p.
//
VOID ScsiPortWritePortUshort(PUSHORT p,USHORT w)
{
    _asm {
        mov dx,word ptr p
        mov ax,w
        out dx,ax
    }
}

//
//  ScsiPortWritePortBufferUshort
//
//  Does an "rep outsw" instruction to i/o port p.
//
VOID ScsiPortWritePortBufferUshort(PUSHORT p, PUSHORT buffer, ULONG len)
{
    _asm {
        push ds
        push esi
        mov dx,word ptr p
        mov esi,word ptr buffer
        mov ds,word ptr buffer+2
        mov cx,word ptr len
        rep outsw
        pop esi
        pop ds
    }
}

//
//  ScsiPortReadPortBufferUshort
//
//  Does an rep "insw" instruction from i/o port p.
//
VOID ScsiPortReadPortBufferUshort(PUSHORT p, PUSHORT buffer, ULONG len)
{
    _asm {
        push es
        push edi
        mov dx,word ptr p
        mov di,word ptr buffer
        mov es,word ptr buffer+2
        mov cx,word ptr len
        rep insw
        pop edi
        pop es
    }
}

//
//  ScsiPortReadPortRegisterUchar
//
//  Reads a memory mapped i/o address.
//  Returns the value.
//
UCHAR ScsiPortReadRegisterUchar(PUCHAR p)
{
    UCHAR rval;

    _asm {
        push es
        mov bx,word ptr p
        mov es,word ptr p+2
        mov al,es:[bx]
        mov rval, al
        pop es
    }
    return rval;
}

//
//  ScsiPortWritePortRegisterUchar
//
//  Writes a value to a memory mapped i/o address.
//
VOID ScsiPortWriteRegisterUchar(PUCHAR p,UCHAR b)
{
    _asm {
        push es
        mov bx,word ptr p
        mov es,word ptr p+2
        mov al, b
        mov es:[bx],al
        pop es
    }
}

//
// ScsiPortStallExecution
//
// Stalls executeion for time micro seconds. Should be processor,
// independent, but for now we will do just a loop.
//
VOID ScsiPortStallExecution(ULONG time)
{
    ULONG i;

    if (time>1) {
        for (i=0;i<time;i++);
    }
}