Rev 750 | Rev 1353 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 750 | Rev 1348 | ||
---|---|---|---|
Line 19... | Line 19... | ||
19 | ;; ;; |
19 | ;; ;; |
20 | ;; See file COPYING for details ;; |
20 | ;; See file COPYING for details ;; |
21 | ;; ;; |
21 | ;; ;; |
22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 23... | Line 23... | ||
23 | 23 | ||
Line 24... | Line 24... | ||
24 | $Revision: 750 $ |
24 | $Revision: 1348 $ |
25 | 25 | ||
26 | ;*************************************************************************** |
26 | ;*************************************************************************** |
27 | ; Function |
27 | ; Function |
Line 72... | Line 72... | ||
72 | cmp al,9 |
72 | cmp al,9 |
73 | jz pci_write_reg ;word |
73 | jz pci_write_reg ;word |
74 | cmp al,10 |
74 | cmp al,10 |
75 | jz pci_write_reg ;dword |
75 | jz pci_write_reg ;dword |
Line -... | Line 76... | ||
- | 76 | ||
- | 77 | cmp al,11 ; <<< user-level MMIO functions <<< NEW! |
|
- | 78 | jz pci_mmio_init |
|
- | 79 | cmp al,12 |
|
- | 80 | jz pci_mmio_map |
|
- | 81 | cmp al,13 |
|
- | 82 | jz pci_mmio_unmap |
|
- | 83 | ||
76 | 84 | ||
Line 77... | Line 85... | ||
77 | no_pci_access_for_applications: |
85 | no_pci_access_for_applications: |
Line 78... | Line 86... | ||
78 | 86 | ||
Line 364... | Line 372... | ||
364 | pci_write_reg_err: |
372 | pci_write_reg_err: |
365 | xor eax,eax |
373 | xor eax,eax |
366 | dec eax |
374 | dec eax |
367 | ret |
375 | ret |
Line -... | Line 376... | ||
- | 376 | ||
- | 377 | ;*************************************************************************** |
|
- | 378 | ; Function |
|
- | 379 | ; pci_mmio_init ; NEW! |
|
- | 380 | ; |
|
- | 381 | ; Description |
|
- | 382 | ; IN: bx = device's PCI bus address (bbbbbbbbdddddfff) |
|
- | 383 | ; returns ax = user heap space available (bytes) |
|
- | 384 | ; Error codes |
|
- | 385 | ; eax = -1 : PCI user access blocked, |
|
- | 386 | ; eax = -2 : device not registered for uMMIO service |
|
- | 387 | ; eax = -3 : user heap initialization failure |
|
- | 388 | ;*************************************************************************** |
|
- | 389 | align 4 |
|
- | 390 | pci_mmio_init: |
|
- | 391 | cmp bx, word [mmio_pci_addr] ; must be set in kernel/data32.inc |
|
- | 392 | jz @f |
|
- | 393 | mov eax,-2 |
|
- | 394 | ret |
|
- | 395 | @@: |
|
- | 396 | call init_heap ; (if not initialized yet) |
|
- | 397 | or eax,eax |
|
- | 398 | jz @f |
|
- | 399 | ret |
|
- | 400 | @@: |
|
- | 401 | mov eax,-3 |
|
- | 402 | ret |
|
- | 403 | ||
- | 404 | ||
- | 405 | ;*************************************************************************** |
|
- | 406 | ; Function |
|
- | 407 | ; pci_mmio_map ; NEW! |
|
- | 408 | ; |
|
- | 409 | ; Description |
|
- | 410 | ; maps a block of PCI memory to user-accessible linear address |
|
- | 411 | ; |
|
- | 412 | ; WARNING! This VERY EXPERIMENTAL service is for one chosen PCI device only! |
|
- | 413 | ; The target device address should be set in kernel var mmio_pci_addr |
|
- | 414 | ; |
|
- | 415 | ; IN: ah = BAR#; |
|
- | 416 | ; IN: ebx = block size (bytes); |
|
- | 417 | ; IN: ecx = offset in MMIO block (in 4K-pages, to avoid misaligned pages); |
|
- | 418 | ; |
|
- | 419 | ; Returns eax = MMIO block's linear address in the userspace (if no error) |
|
- | 420 | ; |
|
- | 421 | ; |
|
- | 422 | ; Error codes |
|
- | 423 | ; eax = -1 : user access to PCI blocked, |
|
- | 424 | ; eax = -2 : an invalid BAR register referred |
|
- | 425 | ; eax = -3 : no i/o space on that BAR |
|
- | 426 | ; eax = -4 : a port i/o BAR register referred |
|
- | 427 | ; eax = -5 : dynamic userspace allocation problem |
|
- | 428 | ;*************************************************************************** |
|
- | 429 | ||
- | 430 | align 4 |
|
- | 431 | pci_mmio_map: |
|
- | 432 | and edx,0x0ffff |
|
- | 433 | cmp ah,6 |
|
- | 434 | jc @f |
|
- | 435 | mov eax,-2 |
|
- | 436 | ret |
|
- | 437 | @@: |
|
- | 438 | push ecx |
|
- | 439 | add ebx, 4095 |
|
- | 440 | and ebx,-4096 |
|
- | 441 | push ebx |
|
- | 442 | mov bl, ah ; bl = BAR# (0..5) |
|
- | 443 | shl bl, 1 |
|
- | 444 | shl bl, 1 |
|
- | 445 | add bl, 0x10 ; bl = BARs offset in PCI config. space |
|
- | 446 | mov ax,word [mmio_pci_addr] |
|
- | 447 | mov bh, al ; bh = dddddfff |
|
- | 448 | mov al, 2 ; al : DW to read |
|
- | 449 | call pci_read_reg |
|
- | 450 | or eax, eax |
|
- | 451 | jnz @f |
|
- | 452 | mov eax,-3 ; empty I/O space |
|
- | 453 | jmp mmio_ret_fail |
|
- | 454 | @@: |
|
- | 455 | test eax, 1 |
|
- | 456 | jz @f |
|
- | 457 | mov eax,-4 ; damned ports (not MMIO space) |
|
- | 458 | jmp mmio_ret_fail |
|
- | 459 | @@: |
|
- | 460 | pop ecx ; ecx = block size, bytes (expanded to whole page) |
|
- | 461 | mov ebx, ecx ; user_alloc destroys eax, ecx, edx, but saves ebx |
|
- | 462 | push eax ; store MMIO physical address + keep 2DWords in the stack |
|
- | 463 | stdcall user_alloc, ecx |
|
- | 464 | or eax, eax |
|
- | 465 | jnz mmio_map_over |
|
- | 466 | mov eax,-5 ; problem with page allocation |
|
- | 467 | ||
- | 468 | mmio_ret_fail: |
|
- | 469 | pop ecx |
|
- | 470 | pop edx |
|
- | 471 | ret |
|
- | 472 | ||
- | 473 | mmio_map_over: |
|
- | 474 | mov ecx, ebx ; ecx = size (bytes, expanded to whole page) |
|
- | 475 | shr ecx, 12 ; ecx = number of pages |
|
- | 476 | mov ebx, eax ; ebx = linear address |
|
- | 477 | pop eax ; eax = MMIO start |
|
- | 478 | pop edx ; edx = MMIO shift (pages) |
|
- | 479 | shl edx, 12 ; edx = MMIO shift (bytes) |
|
- | 480 | add eax, edx ; eax = uMMIO physical address |
|
- | 481 | or eax, PG_SHARED |
|
- | 482 | or eax, PG_UW |
|
- | 483 | or eax, PG_NOCACHE |
|
- | 484 | mov edi, ebx |
|
- | 485 | call commit_pages |
|
- | 486 | mov eax, edi |
|
- | 487 | ret |
|
- | 488 | ||
- | 489 | ;*************************************************************************** |
|
- | 490 | ; Function |
|
- | 491 | ; pci_mmio_unmap_page ; NEW! |
|
- | 492 | ; |
|
- | 493 | ; Description |
|
- | 494 | ; unmaps the linear space previously tied to a PCI memory block |
|
- | 495 | ; |
|
- | 496 | ; IN: ebx = linear address of space previously allocated by pci_mmio_map |
|
- | 497 | ; returns eax = 1 if successfully unmapped |
|
- | 498 | ; |
|
- | 499 | ; Error codes |
|
- | 500 | ; eax = -1 if no user PCI access allowed, |
|
- | 501 | ; eax = 0 if unmapping failed |
|
- | 502 | ;*************************************************************************** |
|
- | 503 | ||
- | 504 | align 4 |
|
- | 505 | pci_mmio_unmap: |
|
- | 506 | stdcall user_free, ebx |
|
- | 507 | ret |
|
- | 508 | ||
368 | 509 | ||
Line 369... | Line 510... | ||
369 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
510 | ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
370 | 511 |