Subversion Repositories Kolibri OS

Rev

Rev 1521 | 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
 
1514 hidnplayr 26
; network driver types
1472 hidnplayr 27
 
1514 hidnplayr 28
	NET_TYPE_ETH		equ 1
29
	NET_TYPE_SLIP		equ 2
30
 
31
 
32
 
1472 hidnplayr 33
	LAST_IO = 0
34
 
35
macro set_io addr {
36
 
37
	if	addr = 0
38
	mov	edx, [device.io_addr]
39
	else if addr = LAST_IO
40
	else
41
	add	edx, addr - LAST_IO
42
	end if
43
 
44
	LAST_IO = addr
45
}
46
 
47
macro allocate_and_clear dest, size, err {
48
 
49
; We need to allocate at least 8 pages, if we want a continuous memory in ram
1521 hidnplayr 50
	push	edx
1472 hidnplayr 51
    if (size < 8*4096) & (size > 4096)
52
	stdcall KernelAlloc, 8*4096
53
    else
54
	stdcall KernelAlloc, size
55
    end if
1521 hidnplayr 56
	pop	edx
57
 
1472 hidnplayr 58
	test	eax, eax
59
	jz	err
60
	mov	dest, eax		; Save the address to it into the device struct
61
	mov	edi, eax		; look at last part of code!
62
 
63
; Release the unused pages (if any)
64
    if (size < 8*4096) & (size > 4096)
65
	add	eax, (size/4096+1)*4096
66
	mov	ecx, 8-(size/4096+1)
1521 hidnplayr 67
	push	edx
1472 hidnplayr 68
	call	ReleasePages
1521 hidnplayr 69
	pop	edx
1472 hidnplayr 70
    end if
71
 
72
; Clear the allocated buffer
73
	mov	ecx, size/4		; divide by 4 because of DWORD
74
	xor	eax, eax
75
	rep	stosd
76
 
77
}
78
 
79
macro find_io bus, dev, io {
80
 
81
	local	.check, .inc, .got
82
 
83
	xor	eax, eax
84
	mov	esi, PCI_BASE_ADDRESS_0
85
	movzx	ecx, bus
86
	movzx	edx, dev
87
  .check:
1502 hidnplayr 88
	stdcall PciRead32, ecx ,edx ,esi
1472 hidnplayr 89
 
1502 hidnplayr 90
	test	eax, PCI_BASE_ADDRESS_IO_MASK
1472 hidnplayr 91
	jz	.inc
92
 
1502 hidnplayr 93
	test	eax, PCI_BASE_ADDRESS_SPACE_IO
1472 hidnplayr 94
	jz	.inc
95
 
96
	and	eax, PCI_BASE_ADDRESS_IO_MASK
97
	mov	io , eax
98
	jmp	.got
99
 
100
  .inc:
101
	add	esi, 4
102
	cmp	esi, PCI_BASE_ADDRESS_5
1502 hidnplayr 103
	jle	.check
1472 hidnplayr 104
 
105
  .got:
106
 
107
}
108
 
1492 hidnplayr 109
macro find_irq bus, dev, irq {
1472 hidnplayr 110
 
1492 hidnplayr 111
	push	eax edx ecx
112
	movzx	ecx, bus
113
	movzx	edx, dev
114
	stdcall PciRead8, ecx ,edx ,0x3c				; 0x3c is the offset where irq can be found
115
	mov	irq, al
116
	pop	ecx edx eax
1472 hidnplayr 117
 
1492 hidnplayr 118
}
119
 
1502 hidnplayr 120
macro find_rev bus, dev, rev {
1492 hidnplayr 121
 
1502 hidnplayr 122
	push	eax edx ecx
123
	movzx	ecx, bus
124
	movzx	edx, dev
125
	stdcall PciRead8, ecx ,edx ,0x8
126
	mov	rev, al
127
	pop	ecx edx eax
128
 
129
}
130
 
1472 hidnplayr 131
macro make_bus_master bus, dev {
132
 
133
	movzx	ecx, bus
134
	movzx	edx, dev
1492 hidnplayr 135
	stdcall PciRead32, ecx ,edx, PCI_REG_COMMAND
1472 hidnplayr 136
 
1514 hidnplayr 137
	or	al, PCI_BIT_MASTER ;or PCI_BIT_PIO
138
;        and     al, not PCI_BIT_MMIO
1472 hidnplayr 139
	stdcall PciWrite32, ecx, edx, PCI_REG_COMMAND, eax
140
 
1514 hidnplayr 141
;; TODO: try to switch to PIO, and check if PIO works or not..
142
 
1472 hidnplayr 143
}
144
 
145
struc IOCTL {
146
      .handle		dd ?
147
      .io_code		dd ?
148
      .input		dd ?
149
      .inp_size 	dd ?
150
      .output		dd ?
151
      .out_size 	dd ?
152
}
153
 
154
virtual at edx
155
  IOCTL IOCTL
156
end virtual
157
 
158
 
159
if used null_op
160
align 4
161
null_op:
162
	or	eax, -1
163
	ret
164
 
165
end if
166
 
167
 
1529 hidnplayr 168
macro GetRealAddr { ; input is eax
1472 hidnplayr 169
 
170
	push	ax
1529 hidnplayr 171
	call	GetPgAddr
1472 hidnplayr 172
	and	word[esp], PAGESIZE - 1
173
	or	ax, word[esp]
174
	inc	esp
175
	inc	esp
176
 
1492 hidnplayr 177
}
178
 
1514 hidnplayr 179
macro NET_DEVICE {
1519 hidnplayr 180
 
181
	.type		dd ?	; Type field
182
	.mtu		dd ?	; Maximal Transmission Unit
183
	.name		dd ?	; Ptr to 0 terminated string
184
 
185
	.unload 	dd ?	; Ptrs to driver functions
186
	.reset		dd ?	;
187
	.transmit	dd ?	;
188
 
189
	.bytes_tx	dq ?	; Statistics, updated by the driver
190
	.bytes_rx	dq ?	;
191
	.packets_tx	dd ?	;
192
	.packets_rx	dd ?	;
193
 
194
	.end:
1514 hidnplayr 195
}
1492 hidnplayr 196
 
1529 hidnplayr 197
 
1492 hidnplayr 198
macro ETH_DEVICE {
1514 hidnplayr 199
      NET_DEVICE
1519 hidnplayr 200
 
201
	.set_mode	dd ?
202
	.get_mode	dd ?
203
 
204
	.set_MAC	dd ?
205
	.get_MAC	dd ?
206
 
207
	.mode		dd ?
208
	.mac		dp ?
209
			dp ?	; qword alignment
210
 
1492 hidnplayr 211
}
212
 
1502 hidnplayr 213
 
214
 
215
macro SLIP_DEVICE {
1514 hidnplayr 216
	NET_DEVICE
1519 hidnplayr 217
 
1502 hidnplayr 218
	.set_mode	dd ?
219
	.get_mode	dd ?
1519 hidnplayr 220
 
1502 hidnplayr 221
	.mode		dd ?
1519 hidnplayr 222
 
1529 hidnplayr 223
}