Ignore:
Timestamp:
Jun 21, 2011, 2:39:30 PM (14 years ago)
Author:
Markus Thielen
Message:

contains CMs changes for unaligned buffers; removed unused stack var; let driver continue boot on unknown command line switch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/os2ahci/libc.c

    r87 r110  
    9696static u8 heap_buf[HEAP_SIZE];
    9797static u8 heap_units[HEAP_UNIT_CNT];
     98static ULONG heap_phys_addr;
    9899
    99100/* ----------------------------- start of code ----------------------------- */
     
    106107  DevHelp_CreateSpinLock(&mem_lock);
    107108  DevHelp_CreateSpinLock(&com_lock);
     109
     110  DevHelp_VirtToPhys(heap_buf, &heap_phys_addr);
    108111}
    109112
     
    347350  va_list va;
    348351  const unsigned char _far *buf = p;
    349   long pos = 0;
    350352  int i;
    351353
     
    378380    printf("\n");
    379381
    380     pos += 16;
    381382    buf += 16;
    382383    len -= 16;
     
    424425  }
    425426  return(0);
     427}
     428
     429/******************************************************************************
     430 * Copy block from S/G list to virtual address or vice versa.
     431 */
     432void 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  }
    426467}
    427468
     
    550591
    551592/******************************************************************************
     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 */
     602ULONG 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/******************************************************************************
    552617 * Calibrate 'mdelay()' loop. This is done by setting up a 1 second timer
    553618 * with a callback that sets 'mdelay_done' to MD_CALIBRATION_END. Then it
     
    681746 * interrupts were already disabled or != 0, if not.
    682747 *
    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 */
    687750int disable(void)
    688751{
     
    699762  return(rc);
    700763}
    701 #endif
    702764
    703765/******************************************************************************
     
    705767 * that the presence of _asm statements will disable compiler optimizations.
    706768 *
    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 */
    711771void enable(void)
    712772{
    713773  _asm sti;
    714774}
    715 #endif
    716775
    717776/******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.