Subversion Repositories Kolibri OS

Rev

Rev 1492 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1472 hidnplayr 1
; PCI Bus defines
2
	PCI_HEADER_TYPE 		equ	0x0e  ;8 bit
3
	PCI_BASE_ADDRESS_0		equ	0x10  ;32 bit
4
	PCI_BASE_ADDRESS_5		equ	0x24  ;32 bits
5
	PCI_BASE_ADDRESS_SPACE_IO	equ	0x01
6
	PCI_VENDOR_ID			equ	0x00  ;16 bit
7
	PCI_BASE_ADDRESS_IO_MASK	equ	0xFFFFFFFC
8
 
9
 
10
; PCI programming
11
	PCI_REG_COMMAND 	equ 0x4 ; command register
12
	PCI_REG_STATUS		equ 0x6 ; status register
13
	PCI_REG_LATENCY 	equ 0xd ; latency timer register
14
	PCI_REG_CAP_PTR 	equ 0x34 ; capabilities pointer
15
	PCI_REG_CAPABILITY_ID	equ 0x0 ; capapility ID in pm register block
16
	PCI_REG_PM_STATUS	equ 0x4 ; power management status register
17
	PCI_REG_PM_CTRL 	equ 0x4 ; power management control register
1502 hidnplayr 18
	PCI_BIT_PIO		equ 1 ; bit0: io space control
19
	PCI_BIT_MMIO		equ 2 ; bit1: memory space control
20
	PCI_BIT_MASTER		equ 4 ; bit2: device acts as a PCI master
1472 hidnplayr 21
 
22
 
23
	PAGESIZE		equ	4096
24
 
25
 
26
 
27
	LAST_IO = 0
28
 
29
macro set_io addr {
30
 
31
	if	addr = 0
32
 
33
	mov	edx, [device.io_addr]
34
 
35
	else if addr = LAST_IO
36
 
37
	else
38
 
39
	add	edx, addr - LAST_IO
40
 
41
	end if
42
 
43
	LAST_IO = addr
44
}
45
 
46
 
47
 
48
macro allocate_and_clear dest, size, err {
49
 
50
; We need to allocate at least 8 pages, if we want a continuous memory in ram
51
    if (size < 8*4096) & (size > 4096)
52
	stdcall KernelAlloc, 8*4096
53
    else
54
	stdcall KernelAlloc, size
55
    end if
56
	test	eax, eax
57
	jz	err
58
	mov	dest, eax		; Save the address to it into the device struct
59
	mov	edi, eax		; look at last part of code!
60
 
61
; Release the unused pages (if any)
62
    if (size < 8*4096) & (size > 4096)
63
	add	eax, (size/4096+1)*4096
64
	mov	ecx, 8-(size/4096+1)
65
	call	ReleasePages
66
    end if
67
 
68
; Clear the allocated buffer
69
	mov	ecx, size/4		; divide by 4 because of DWORD
70
	xor	eax, eax
71
	rep	stosd
72
 
73
}
74
 
75
 
76
 
77
macro find_io bus, dev, io {
78
 
79
	local	.check, .inc, .got
80
 
81
	xor	eax, eax
82
	mov	esi, PCI_BASE_ADDRESS_0
83
	movzx	ecx, bus
84
	movzx	edx, dev
85
  .check:
1502 hidnplayr 86
	stdcall PciRead32, ecx ,edx ,esi
1472 hidnplayr 87
 
1502 hidnplayr 88
	test	eax, PCI_BASE_ADDRESS_IO_MASK
1472 hidnplayr 89
	jz	.inc
90
 
1502 hidnplayr 91
	test	eax, PCI_BASE_ADDRESS_SPACE_IO
1472 hidnplayr 92
	jz	.inc
93
 
94
	and	eax, PCI_BASE_ADDRESS_IO_MASK
95
	mov	io , eax
96
	jmp	.got
97
 
98
  .inc:
99
	add	esi, 4
100
	cmp	esi, PCI_BASE_ADDRESS_5
1502 hidnplayr 101
	jle	.check
1472 hidnplayr 102
 
103
  .got:
104
 
105
}
106
 
1492 hidnplayr 107
macro find_irq bus, dev, irq {
1472 hidnplayr 108
 
1492 hidnplayr 109
	push	eax edx ecx
110
	movzx	ecx, bus
111
	movzx	edx, dev
112
	stdcall PciRead8, ecx ,edx ,0x3c				; 0x3c is the offset where irq can be found
113
	mov	irq, al
114
	pop	ecx edx eax
1472 hidnplayr 115
 
1492 hidnplayr 116
}
117
 
118
 
1502 hidnplayr 119
macro find_rev bus, dev, rev {
1492 hidnplayr 120
 
1502 hidnplayr 121
	push	eax edx ecx
122
	movzx	ecx, bus
123
	movzx	edx, dev
124
	stdcall PciRead8, ecx ,edx ,0x8
125
	mov	rev, al
126
	pop	ecx edx eax
127
 
128
}
129
 
130
 
131
 
1472 hidnplayr 132
macro make_bus_master bus, dev {
133
 
134
	movzx	ecx, bus
135
	movzx	edx, dev
1492 hidnplayr 136
	stdcall PciRead32, ecx ,edx, PCI_REG_COMMAND
1472 hidnplayr 137
 
1502 hidnplayr 138
	or	al, PCI_BIT_MASTER or PCI_BIT_PIO
139
	and	al, not PCI_BIT_MMIO
1472 hidnplayr 140
	stdcall PciWrite32, ecx, edx, PCI_REG_COMMAND, eax
141
 
142
}
143
 
144
struc IOCTL {
145
      .handle		dd ?
146
      .io_code		dd ?
147
      .input		dd ?
148
      .inp_size 	dd ?
149
      .output		dd ?
150
      .out_size 	dd ?
151
}
152
 
153
virtual at edx
154
  IOCTL IOCTL
155
end virtual
156
 
157
 
158
 
159
 
160
if used null_op
161
 
162
align 4
163
null_op:
164
	or	eax, -1
165
	ret
166
 
167
end if
168
 
169
 
170
macro virt_to_dma { ; input is eax
171
 
172
	push	ax
173
	and	word[esp], PAGESIZE - 1
174
	call	GetPgAddr
175
	or	ax, word[esp]
176
	inc	esp
177
	inc	esp
178
 
1492 hidnplayr 179
}
180
 
181
 
182
;struc ETH_DEVICE {
183
macro ETH_DEVICE {
184
; pointers to procedures
185
      .unload		dd ?
186
      .reset		dd ?
187
      .transmit 	dd ?
188
      .set_MAC		dd ?
189
      .get_MAC		dd ?
190
      .set_mode 	dd ?
191
      .get_mode 	dd ?
192
; status
193
      .bytes_tx 	dq ?
194
      .bytes_rx 	dq ?
195
      .packets_tx	dd ?
196
      .packets_rx	dd ?
197
      .mode		dd ?
198
      .name		dd ?
199
      .mac		dp ?
200
}
201
 
1502 hidnplayr 202
 
203
 
204
macro SLIP_DEVICE {
205
; pointers to procedures
206
	.unload 	dd ?
207
	.reset		dd ?
208
	.transmit	dd ?
209
	.set_mode	dd ?
210
	.get_mode	dd ?
211
; status
212
	.bytes_tx	dq ?
213
	.bytes_rx	dq ?
214
	.packets_tx	dd ?
215
	.packets_rx	dd ?
216
	.mode		dd ?
217
	.name		dd ?
218
}
219
 
220
macro GetRealAddr {
221
 
222
	push	eax
223
	call	GetPgAddr
224
	and	dword [esp], (PAGESIZE - 1)
225
	add	eax, dword [esp]
226
	add	esp, 4
227
 
228
}
229