Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1551 art_zh 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
3934 art_zh 3
;; Copyright (C) 2010-13 KolibriOS team.  All rights reserved.  ;;
1551 art_zh 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
1683 art_zh 6
;;  HT.inc                                                      ;;                                                    ;;
1551 art_zh 7
;;                                                              ;;
8
;;  AMD HyperTransport bus control                              ;;
9
;;                                                              ;;
1599 art_zh 10
;;                  art_zh                ;;
1551 art_zh 11
;;                                                              ;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
 
1560 art_zh 14
$Revision: 1554 $
1551 art_zh 15
 
1599 art_zh 16
NB_MISC_INDEX	equ	0xF0000060	; NB Misc indirect access
17
NB_MISC_DATA	equ	0xF0000064
18
PCIEIND_INDEX	equ	0xF00000E0	; PCIe Core indirect config space access
19
HTIU_NB_INDEX	equ	0xF0000094	; HyperTransport indirect config space access
1551 art_zh 20
 
21
;=============================================================================
22
;
23
; This code is a part of Kolibri-A and will only work with AMD RS760+ chipsets
24
;
25
;=============================================================================
1683 art_zh 26
 
27
org $-OS_BASE	; physical addresses needed at initial stage
28
 
1560 art_zh 29
align 4
1551 art_zh 30
 
31
;------------------------------------------
32
;       params:   al = nbconfig register#
33
;       returns: eax = register content
34
;
35
rs7xx_nbconfig_read_pci:
36
	and	eax, 0x0FC		 ; leave register# only
37
	or	eax, 0x80000000 	 ; bdf = 0:0.0
38
	mov	dx,  0x0CF8		 ; write to index reg
39
	out	dx, eax
40
	add	dl, 4
41
	in	eax, dx
42
	ret
1560 art_zh 43
align 4
1551 art_zh 44
 
45
rs7xx_nbconfig_flush_pci:
46
	mov	eax, 0x0B0		; a scratch reg
47
	mov	dx,  0xCF8
48
	out	dx,  eax
49
	ret
50
 
1560 art_zh 51
align 4
1551 art_zh 52
 
1599 art_zh 53
;------------------------------------------
54
;       params:   al = nbconfig register#
55
;                ebx = register content
56
;
1551 art_zh 57
rs7xx_nbconfig_write_pci:
58
	and	eax, 0x0FC		 ; leave register# only
59
	or	eax, 0x80000000 	 ; bdf = 0:0.0
60
	mov	dx,  0x0CF8		 ; write to index reg
61
	out	dx, eax
62
	add	dl, 4
63
	mov	eax, ebx
64
	out	dx, eax
65
	ret
66
 
67
;***************************************************************************
68
;   Function
1599 art_zh 69
;      rs7xx_unlock_bar3:     unlocks the BAR3 register of nbconfig that
70
;                             makes pcie config address space visible
71
;   -----------------------
72
;   in: nothing      out: nothing      destroys:   eax ebx edx
73
;
74
;***************************************************************************
75
align 4
76
rs7xx_unlock_bar3:
77
	mov	eax, NB_MISC_INDEX
1683 art_zh 78
	mov	ebx, 0x080			; NBMISCIND:0x0; write-enable
1599 art_zh 79
	call	rs7xx_nbconfig_write_pci	; set index
80
	mov	eax, NB_MISC_DATA
81
	call	rs7xx_nbconfig_read_pci 	; read data
82
	mov	ebx, eax
83
	and	ebx, 0xFFFFFFF7 		; clear bit3
84
	mov	eax, NB_MISC_DATA
85
	call	rs7xx_nbconfig_write_pci	; write it back
86
	mov	eax, NB_MISC_INDEX
87
	xor	ebx, ebx			; reg#0; write-locked
88
	call	rs7xx_nbconfig_write_pci	; set index
89
	ret
90
 
1683 art_zh 91
 
92
 
93
;***************************************************************************
94
;   Function
3526 art_zh 95
;      fusion_pcie_init:
1683 art_zh 96
;
97
;   Description
3526 art_zh 98
;       PCIe extended  config space detection and mapping
1683 art_zh 99
;
100
;***************************************************************************
101
 
102
align 4
103
 
104
 
105
 
1928 art_zh 106
; ---- stepping 10h CPUs and Fusion APUs: the configspace is stored in MSR_C001_0058 ----
107
align 4
108
fusion_pcie_init:
2014 art_zh 109
	mov	ecx, 0xC0010058
110
	rdmsr
111
	or	edx, edx
112
	jnz	$				; PCIe is in the upper memory. Stop.
113
	xchg	dl, al
1928 art_zh 114
	mov	dword[mmio_pcie_cfg_addr-OS_BASE], eax	; store the physical address
2014 art_zh 115
	mov	ecx, edx
3934 art_zh 116
 
117
	shr	cl, 2
2014 art_zh 118
	mov	word[PCIe_bus_range-OS_BASE], cx
119
	sub	cl, 2
120
	jae	@f
121
	xor	cl, cl
1928 art_zh 122
@@:
2014 art_zh 123
	shl	edx, cl 			; edx = number of 4M pages to map
124
	mov	word[mmio_pcie_cfg_pdes-OS_BASE], dx
125
	shl	edx, 22
126
	dec	edx
127
	add	edx, eax			; the upper configspace limit
1928 art_zh 128
	mov	dword[mmio_pcie_cfg_lim-OS_BASE], edx
1683 art_zh 129
 
3526 art_zh 130
; ---- large pages mapping  ----
131
; (eax = phys. address of PCIe conf.space)
132
;
133
.map_pcie_pages:
134
	or	eax, (PG_NOCACHE + PG_SHARED + PG_LARGE + PG_UW)  ;  UW is unsafe!
135
	mov	ecx, PCIe_CONFIG_SPACE			; linear address
136
	mov	ebx, ecx
137
	shr	ebx, 20
138
	add	ebx, (sys_pgdir - OS_BASE)		; PgDir entry @
139
	mov	dl, byte[mmio_pcie_cfg_pdes-OS_BASE]	; 1 page = 4M in address space
140
	cmp	dl, 0x34	; =(USER_DMA_BUFFER - PCIe_CONFIG_SPACE) / 4M
141
	jb	@f
142
	mov	dl, 0x33
143
	mov	byte[mmio_pcie_cfg_pdes-OS_BASE], dl
144
@@:
145
	xor	dx,  dx 			; PDEs counter
146
.write_pde:
147
	mov	dword[ebx], eax 		; map 4 buses
148
	add	bx,  4				; new PDE
149
	add	eax, 0x400000			; +4M phys.
150
	add	ecx, 0x400000			; +4M lin.
151
	cmp	dl, byte[mmio_pcie_cfg_pdes-OS_BASE]
152
	jae	.pcie_cfg_mapped
153
	inc	dl
154
	jmp	.write_pde
1928 art_zh 155
 
3526 art_zh 156
.pcie_cfg_mapped:
157
 
3519 art_zh 158
create_mmio_pte:
3531 art_zh 159
	mov	ecx, mmio_pte				; physical address
3934 art_zh 160
	or	ecx, (PG_NOCACHE + PG_SHARED + PG_UW)
3519 art_zh 161
	mov	ebx, FUSION_MMIO			; linear address
162
	shr	ebx, 20
163
	add	ebx, (sys_pgdir - OS_BASE)		; PgDir entry @
3531 art_zh 164
	mov	dword[ebx], ecx 			; Fusion MMIO tables
3519 art_zh 165
 
3934 art_zh 166
; ---- map APIC regs  ----
3526 art_zh 167
.map_apic_mmio:
3531 art_zh 168
	mov	ecx, 0x01B	; APIC BAR
169
	rdmsr
170
	and	eax, 0xFFFFF000 			; physical address
3934 art_zh 171
	or	eax, (PG_NOCACHE + PG_SHARED + PG_UW)
172
	mov	ebx, mmio_pte
173
	mov	[ebx], eax
3519 art_zh 174
 
3934 art_zh 175
; ---- map GPU MMRegs  ----
176
.map_gpu_mmr:
177
	mov	eax, [mmio_pcie_cfg_addr-OS_BASE]	; PCIe space
178
	add	eax, 0x08018				; b:0, d:1, f:0, reg=18
179
	mov	eax, [eax]
180
 
181
	xor	al, al					; physical address
182
	or	eax, (PG_NOCACHE + PG_SHARED + PG_UW)
183
@@:
184
	add   bl, 4
185
	mov	[ebx], eax
186
	add   eax, 0x01000
187
	cmp   bl, 16*4	  ; map 15 pages
188
	jb    @b
189
 
3519 art_zh 190
	ret	; <<< OK >>>
191
 
1683 art_zh 192
; ================================================================================
193
 
194
org OS_BASE+$	; back to the linear address space
195
 
1599 art_zh 196
;--------------------------------------------------------------
197
align 4
198
rs780_read_misc:
199
;  in: eax(al) - reg#           out: eax = NBMISCIND data
200
	push	edx
201
	mov	edx, NB_MISC_INDEX
202
	and	eax, 0x07F
203
	mov	[edx], eax
204
	add	dl, 4
205
	mov	eax, [edx]
206
	pop	edx
207
	ret
208
 
209
;-------------------------------------------
210
align 4
211
rs780_write_misc:
212
;  in: eax(al) - reg#     ebx = NBMISCIND data
213
	push	edx
214
	mov	edx, NB_MISC_INDEX
215
	and	eax, 0x07F
216
	or	eax, 0x080		; set WE
217
	mov	[edx], eax
218
	add	dl, 4
219
	mov	[edx], ebx
220
	sub	dl, 4
221
	xor	eax,   eax
222
	mov	[edx], eax		; safety last
223
	pop	edx
224
	ret
225
 
226
;-------------------------------------------------------------
227
align 4
228
rs780_read_pcieind:
229
;  in: ah = bridge#, al = reg#           out: eax = PCIEIND data
230
	push	edx
231
	xor	edx, edx
232
	mov	ah,  dl 		; bridge# :     0 = Core+GFX;   0x10 = Core+SB
233
	and	dl,  15 		;            0x20 = Core+GPP;  2..12 = a PortBridge
234
	shl	edx, 15 		; device#
235
	add	edx, PCIEIND_INDEX	; full bdf-address
236
	and	eax, 0x30FF
237
	or	al,  al
238
	jnz	@f
239
	shl	eax, 4			; set bits 17..16 for a Core bridge
240
@@:
241
	mov	[edx], eax
242
	add	dl,  4
243
	mov	eax, [edx]
244
	pop	edx
245
	ret
246
 
247
;-------------------------------------------
248
align 4
249
rs780_write_pcieind:
250
;  in: ah = bridge#, al = reg#,  ebx = PCIEIND data
251
	push	edx
252
	xor	edx, edx
253
	mov	ah,  dl 		; bridge# :     0 = Core+GFX;   0x10 = Core+SB
254
	and	dl,  15 		;            0x20 = Core+GPP;  2..12 = a PortBridge
255
	shl	edx, 15 		; device#
256
	add	edx, PCIEIND_INDEX	; full bdf-address
257
	and	eax, 0x30FF
258
	or	al,  al
259
	jnz	@f
260
	shl	eax, 4			; set bits 17..16 for a Core bridge
261
@@:
262
	mov	[edx], eax
263
	add	dl,  4
264
	mov	[edx], ebx
265
	sub	dl,  4
266
	xor	eax,   eax
267
	mov	[edx], eax		; safety last
268
	pop	edx
269
	ret
270
 
271
;------------------------------------------------
272
align 4
273
rs780_read_htiu:
274
; in:  al = reg#  |  out: eax = HTIU data
275
;------------------------------------------------
276
	push	edx
277
	mov	edx,  HTIU_NB_INDEX
278
	and	eax, 0x07F
279
	mov	[edx], eax
280
	add	dl,  4
281
	mov	eax, [edx]
282
	pop	edx
283
	ret
284
;------------------------------------------------
285
align 4
286
rs780_write_htiu:
287
; in:  al = reg#; ebx = data
288
;------------------------------------------------
289
	push	edx
290
	mov	edx,  HTIU_NB_INDEX
291
	and	eax, 0x07F
292
	or	eax, 0x100
293
	mov	[edx], eax
294
	add	dl,  4
295
	mov	[edx], ebx
296
	sub	dl,  4
297
	xor	eax,   eax
298
	mov	[edx], eax
299
	pop	edx
300
	ret
301
 
1928 art_zh 302
;------------------------------------------------
303
align 4
304
sys_rdmsr:
305
;  in: [esp+8] = MSR#
306
; out: [esp+8] = MSR[63:32]
307
;        [eax] = MSR[31: 0]
308
;------------------------------------------------
2014 art_zh 309
	push	ecx edx
310
	mov	ecx, [esp+16]
311
	rdmsr
312
	mov	[esp+16], edx
313
	pop	edx ecx
314
	ret
1599 art_zh 315
 
3573 art_zh 316
;------------------------------------------------
317
uglobal
318
 
319
align 4
320
diff16 "apic_data : ", 0, $
321
apic_data:
322
 
323
    .counter dd ?
324
    .ticks   dd ?
325
    .t_freq  dd ?
3934 art_zh 326
    .gpu_r6998 dd ?
3573 art_zh 327
endg
328
 
3531 art_zh 329
apic_timer_reset:
3573 art_zh 330
	mov	eax, [pll_frequency.osc]
331
	shr	eax, 1					; default prescaler - fix it !!
332
	mov	[apic_data.t_freq], eax
333
	shr	eax, 4					; 16 per second
334
	mov	[apic_data.ticks], eax
335
 
3531 art_zh 336
	mov	ebx, LAPIC_BAR+ 0x320
3573 art_zh 337
	mov	edx, [ebx]
338
	and	edx, 0xFFFEFF00
339
	or	edx, 0x0002003F 			; int vector + restart
3934 art_zh 340
;--     mov     [ebx], edx
3573 art_zh 341
	mov	dword [LAPIC_BAR + 0x380], eax		; load APICTIC
3934 art_zh 342
 
343
; ret
344
 
345
init_hw_cursor:
346
	call	alloc_page			 ; eax = phys. addr
347
	push	eax
348
	or	eax, (PG_NOCACHE + PG_SHARED + PG_UW)	 ; i like dirty hacks
349
	mov	[mmio_pte + OS_BASE + 15*4], eax ; mapped to the end of GPU MMRegs
350
	mov	edi, GPU_CURSOR 		 ; lin. addr
351
	invlpg	[edi]
352
	xor	ecx, ecx
353
.fill64pix:
354
	xor	ebx, ebx
355
	mov	eax, 0x80000000 		; black, non-transparent
356
.check_pix:
357
	cmp	ebx, ecx
358
	jbe	@f
359
	xor	eax, eax			; transparent
360
@@:
361
	mov	[edi + ebx*4], eax
362
	inc	ebx
363
	cmp	bl, 64
364
	jb	.check_pix
365
	inc	ecx
366
	cmp	ecx, 16
367
	je	@f
368
	add	edi, 64*4			; new line
369
	jmp	.fill64pix
370
@@:
371
	pop	eax
372
	mov	dword[GPU_MMR + 0x0699C], eax	     ; cur_surface_addr
373
	mov	dword[GPU_MMR + 0x069A0], 0x000F000F ; cur_size    = 16x16
374
	mov	dword[GPU_MMR + 0x069A4], 0	     ; cur_adr_hi
375
	mov	dword[GPU_MMR + 0x069A8], 0x02000100 ; cur_pos     = 512,256
376
	mov	dword[GPU_MMR + 0x069AC], 0	     ; cur_hotspot = 0,0
377
 
378
	mov	dword[GPU_MMR + 0x06998], 0x00000301 ; set it!
379
 
380
 
381
 
3531 art_zh 382
	ret
1599 art_zh 383
 
3531 art_zh 384
 
385
apic_timer_int:
386
	push	eax
3573 art_zh 387
	inc	dword [apic_data.counter]
388
;        mov     eax,  [apic_data.ticks]
389
;        mov     dword [LAPIC_BAR + 0x380], eax          ; reload APICTIC
390
	mov	dword [LAPIC_BAR + 0x0B0], 0		; end of interrupt
391
;        mov     dword [LAPIC_BAR + 0x420], 0x3F            ; end of interrupt
3531 art_zh 392
	pop	eax
393
	iretd
394