Changeset 110 for trunk/src/os2ahci/libc.c
- Timestamp:
- Jun 21, 2011, 2:39:30 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/os2ahci/libc.c
r87 r110 96 96 static u8 heap_buf[HEAP_SIZE]; 97 97 static u8 heap_units[HEAP_UNIT_CNT]; 98 static ULONG heap_phys_addr; 98 99 99 100 /* ----------------------------- start of code ----------------------------- */ … … 106 107 DevHelp_CreateSpinLock(&mem_lock); 107 108 DevHelp_CreateSpinLock(&com_lock); 109 110 DevHelp_VirtToPhys(heap_buf, &heap_phys_addr); 108 111 } 109 112 … … 347 350 va_list va; 348 351 const unsigned char _far *buf = p; 349 long pos = 0;350 352 int i; 351 353 … … 378 380 printf("\n"); 379 381 380 pos += 16;381 382 buf += 16; 382 383 len -= 16; … … 424 425 } 425 426 return(0); 427 } 428 429 /****************************************************************************** 430 * Copy block from S/G list to virtual address or vice versa. 431 */ 432 void sg_memcpy(SCATGATENTRY _far *sg_list, USHORT sg_cnt, ULONG sg_off, 433 void _far *buf, USHORT len, SG_MEMCPY_DIRECTION dir) 434 { 435 USHORT mode_flag; 436 USHORT i; 437 USHORT l; 438 ULONG phys_addr; 439 ULONG pos = 0; 440 char _far *p; 441 442 /* walk through S/G list to find the elements involved in the operation */ 443 for (i = 0; i < sg_cnt && len > 0; i++) { 444 if (pos <= sg_off && pos + sg_list[i].XferBufLen > sg_off) { 445 446 /* this S/G element intersects with the block to be copied */ 447 phys_addr = sg_list[i].ppXferBuf + (sg_off - pos); 448 if ((l = sg_list[i].XferBufLen - (sg_off - pos)) > len) { 449 l = len; 450 } 451 452 if (DevHelp_PhysToVirt(phys_addr, l, (PVOID) &p, &mode_flag)) { 453 panic("sg_memcpy(): DevHelp_PhysToVirt() failed"); 454 } 455 if (dir == SG_TO_BUF) { 456 memcpy(buf, p, l); 457 } else { 458 memcpy(p, buf, l); 459 } 460 sg_off += l; 461 buf = (char _far *) buf + l; 462 len -= l; 463 } 464 465 pos += sg_list[i].XferBufLen; 466 } 426 467 } 427 468 … … 550 591 551 592 /****************************************************************************** 593 * Return the physical address of a pointer inside the heap buffer. This is 594 * necessary because DevHelp_VirtToPhys() can't be called at interrupt time 595 * and we need physical addresses for heap objects when requeueing unaligned 596 * IORBs inside ahci_intr -> trigger_engine. 597 * 598 * If the pointer is not a heap pointer, this function falls back to calling 599 * DevHelp_VirtToPhys with all consequences (i.e. a trap when this is done 600 * at interrupt time). 601 */ 602 ULONG virt_to_phys(void _far *ptr) 603 { 604 if (ptr < heap_buf || ptr > heap_buf + sizeof(heap_buf)) { 605 ULONG addr; 606 607 if (DevHelp_VirtToPhys(ptr, &addr) != 0) { 608 panic("virt_to_phys(): invalid pointer or execution mode"); 609 } 610 return(addr); 611 } 612 613 return(heap_phys_addr + ((char _far *) ptr - (char _far *) heap_buf)); 614 } 615 616 /****************************************************************************** 552 617 * Calibrate 'mdelay()' loop. This is done by setting up a 1 second timer 553 618 * with a callback that sets 'mdelay_done' to MD_CALIBRATION_END. Then it … … 681 746 * interrupts were already disabled or != 0, if not. 682 747 * 683 * NOTE: SMP systems must use spinlocks, thus this function will only be 684 * compiled on non-SMP builds. 685 */ 686 #ifndef OS2AHCI_SMP 748 * NOTE: SMP systems should use spinlocks. 749 */ 687 750 int disable(void) 688 751 { … … 699 762 return(rc); 700 763 } 701 #endif702 764 703 765 /****************************************************************************** … … 705 767 * that the presence of _asm statements will disable compiler optimizations. 706 768 * 707 * NOTE: SMP systems must use spinlocks, thus this function will only be 708 * compiled on non-SMP builds. 709 */ 710 #ifndef OS2AHCI_SMP 769 * NOTE: SMP systems should use spinlocks. 770 */ 711 771 void enable(void) 712 772 { 713 773 _asm sti; 714 774 } 715 #endif716 775 717 776 /******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.