Ignore:
Timestamp:
Nov 29, 2016, 5:30:22 AM (9 years ago)
Author:
David Azarewicz
Message:

Major reorganization

File:
1 edited

Legend:

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

    r176 r178  
    44 * Copyright (c) 2011 thi.guten Software Development
    55 * Copyright (c) 2011 Mensys B.V.
    6  * Copyright (c) 2013-2015 David Azarewicz
     6 * Copyright (c) 2013-2016 David Azarewicz
    77 *
    88 * Authors: Christian Mueller, Markus Thielen
     
    3636/* ------------------------ global/static variables ------------------------ */
    3737
    38 struct {
    39   u32 phys_addr;   /* physical address of allocated buffer */
    40   u8 _far *tbuf;   /* mapped address of trace buffer */
    41   u16 writep;      /* current write offset in buffer */
    42   u16 readp;       /* current read offset in buffer */
    43   u16 mask;        /* The mask for wrapping the buffer pointers */
    44 } ahci_trace_buf;
    45 
    4638/* ----------------------------- start of code ----------------------------- */
    47 
    48 /******************************************************************************
    49  * initialize AHCI circular trace buffer
    50  *
    51  * NOTE: this func must be called during INIT time since it allocates
    52  *       a GDT selector for the trace ring buffer
    53  */
    54 void trace_init(u32 ulBufSize)
    55 {
    56   SEL sel = 0;
    57 
    58   if (ahci_trace_buf.phys_addr) return;
    59 
    60   /* initialize ring buffer logic */
    61   ahci_trace_buf.writep = 0;
    62   ahci_trace_buf.readp = 0;
    63   ahci_trace_buf.mask = ulBufSize - 1;
    64 
    65   if (ahci_trace_buf.phys_addr == 0) {
    66     /* allocate buffer */
    67     if (DevHelp_AllocPhys(ulBufSize, MEMTYPE_ABOVE_1M,
    68                          &(ahci_trace_buf.phys_addr))) {
    69       /* failed above 1MB, try below */
    70       if (DevHelp_AllocPhys(ulBufSize, MEMTYPE_BELOW_1M,
    71                             &(ahci_trace_buf.phys_addr))) {
    72         /* failed, too. Give up */
    73         ahci_trace_buf.phys_addr = 0;
    74         cprintf("%s warning: failed to allocate %dk trace buffer\n",
    75                 drv_name, ulBufSize / 1024);
    76         return;
    77       }
    78     }
    79 
    80     /* allocate GDT selector and map our physical trace buffer to it */
    81     if (DevHelp_AllocGDTSelector(&sel, 1) ||
    82         DevHelp_PhysToGDTSelector(ahci_trace_buf.phys_addr,
    83                                   ulBufSize, sel)) {
    84       /* failed; free GDT selector and physical memory we allocated before */
    85       if (sel) {
    86         DevHelp_FreeGDTSelector(sel);
    87         sel = 0;
    88       }
    89       DevHelp_FreePhys(ahci_trace_buf.phys_addr);
    90       ahci_trace_buf.phys_addr = 0;
    91       return;
    92     }
    93 
    94     /* create ring buffer address */
    95     ahci_trace_buf.tbuf = (u8 _far *) ((u32) sel << 16);
    96   }
    97 }
    98 
    99 /******************************************************************************
    100  * cleanup trace buffer
    101  *
    102  * NOTE: this function is here for completeness; the trace buffer should not
    103  *       be deallocated and then reallocated.
    104  */
    105 void trace_exit(void)
    106 {
    107   /* free physical address */
    108   if (ahci_trace_buf.phys_addr) {
    109     DevHelp_FreePhys(ahci_trace_buf.phys_addr);
    110     ahci_trace_buf.phys_addr = 0;
    111   }
    112 
    113   /* free GDT selector */
    114   if (ahci_trace_buf.tbuf) {
    115     DevHelp_FreeGDTSelector((SEL) ((u32) (ahci_trace_buf.tbuf) >> 16));
    116     ahci_trace_buf.tbuf = NULL;
    117   }
    118 }
    119 
    120 
    121 /******************************************************************************
    122  * write a string to the circular trace buffer
    123  *
    124  * Note: This func wraps the buffer if necessary, so the caller does not
    125  *       need to call repeatedly until everything is written.
    126  *
    127  */
    128 void trace_write(u8 _far *s, int len)
    129 {
    130   //NOT USED USHORT awake_cnt;
    131 
    132   if (ahci_trace_buf.phys_addr == 0) {
    133     /* tracing not active */
    134     return;
    135   }
    136 
    137   while (len) {
    138     if ( !wrap_trace_buffer && (((ahci_trace_buf.writep+1) & ahci_trace_buf.mask) == ahci_trace_buf.readp) ) break; /* buffer is full */
    139 
    140     ahci_trace_buf.tbuf[ahci_trace_buf.writep] = *s++;
    141     ahci_trace_buf.writep++;
    142     ahci_trace_buf.writep &= ahci_trace_buf.mask;
    143 
    144     /* keep the latest full buffer of information */
    145     if (ahci_trace_buf.writep == ahci_trace_buf.readp)
    146       ahci_trace_buf.readp = (ahci_trace_buf.readp+1) & ahci_trace_buf.mask;
    147 
    148     len--;
    149   }
    150 
    151   /* wake up processes waiting for data from trace buffer */
    152   //NOT_USED DevHelp_ProcRun(ahci_trace_buf.phys_addr, &awake_cnt);
    153 
    154 }
    155 
    156 /******************************************************************************
    157  * read data from circular trace buffer
    158  * returns the number of bytes written to the caller's buffer
    159  *
    160  * NOTE: the caller is expected to call this func repeatedly
    161  *       (up to two times) until it returns 0
    162  */
    163 u16 trace_read(u8 _far *buf, u16 cb_buf)
    164 {
    165   u16 cb_read;
    166 
    167   if (ahci_trace_buf.phys_addr == NULL) return 0;
    168 
    169   for (cb_read = 0; cb_read < cb_buf && ( ahci_trace_buf.readp != ahci_trace_buf.writep ); cb_read++)
    170   {
    171     *buf++ = ahci_trace_buf.tbuf[ahci_trace_buf.readp];
    172     ahci_trace_buf.readp++;
    173     ahci_trace_buf.readp &= ahci_trace_buf.mask;
    174   }
    175 
    176   return cb_read;
    177 }
    178 
    179 /******************************************************************************
    180  * copy trace buffer content to character device reader (request block buffer)
    181  */
    182 u16 trace_char_dev(RP_RWV _far *rwrb)
    183 {
    184   u8 _far *to_buf;
    185   u16 cb_read = 0;
    186   u16 cb;
    187   USHORT mode = 0;
    188 
    189   spin_lock(com_lock);
    190 
    191   /* get pointer to caller's buffer */
    192   if (DevHelp_PhysToVirt(rwrb->XferAddr, rwrb->NumSectors, &to_buf, &mode)) {
    193     spin_unlock(com_lock);
    194     return (STATUS_DONE | STERR);
    195   }
    196 
    197   /* loop until caller's buffer is full or no more data in trace buffer */
    198   do {
    199     cb = trace_read(to_buf + cb_read, rwrb->NumSectors - cb_read);
    200     cb_read += cb;
    201   } while (cb > 0 && cb_read < rwrb->NumSectors);
    202 
    203   spin_unlock(com_lock);
    204   rwrb->NumSectors = cb_read;
    205 
    206   return(STDON);
    207 }
    20839
    20940/******************************************************************************
    21041 * Create adapter/port/device list for user output.
    21142 */
    212 void build_user_info(int check)
     43void build_user_info(void)
    21344{
    21445  int a;
     
    21647  int d;
    21748
    218   if ( check && (ahci_trace_buf.readp != ahci_trace_buf.writep)) return;
    219 
    220   for (a = 0; a < ad_info_cnt; a++) {
     49  for (a = 0; a < ad_info_cnt; a++)
     50  {
    22151    AD_INFO *ai = ad_infos + a;
    22252
    223     ntprintf("Adapter %d: PCI=%d:%d:%d ID=%04x:%04x %s %s irq=%d addr=0x%lx version=%lx\n", a,
    224       ai->bus, ai->dev_func>>3, ai->dev_func&7,
     53    NTPRINTF("Adapter %d: PCI=%d:%d:%d ID=%04x:%04x %s %s irq=%d addr=0x%x version=%x\n", a,
     54      PCI_BUS_FROM_BDF(ai->bus_dev_func), PCI_DEV_FROM_BDF(ai->bus_dev_func),
     55      PCI_FUNC_FROM_BDF(ai->bus_dev_func),
    22556      ai->pci_vendor, ai->pci_device, vendor_from_id(ai->pci_vendor), ai->pci->chipname,
    22657      ai->irq, ai->mmio_phys,
    22758      ai->bios_config[HOST_VERSION / sizeof(u32)]);
    22859
    229     for (p = 0; p < ai->hw_ports; p++) {
     60    for (p = 0; p < ai->hw_ports; p++)
     61    {
    23062      P_INFO *pi = &ai->ports[p];
    23163
    232       ntprintf("  Port %d:\n", p);
     64      NTPRINTF("  Port %d:\n", p);
    23365
    234       for (d = 0; d <= pi->dev_max; d++) {
    235         if (!pi->devs[d].present) {
    236           ntprintf("    No drive present\n");
     66      for (d = 0; d <= pi->dev_max; d++)
     67      {
     68        if (!pi->devs[d].present)
     69        {
     70          NTPRINTF("    No drive present\n");
    23771        } else {
    238           ntprintf("    Drive %d:", d);
    239           if (pi->devs[d].atapi) ntprintf(" atapi");
    240           if (pi->devs[d].removable) ntprintf(" removable");
    241           if (pi->devs[d].dev_info.Method != NULL) {
    242             ntprintf(" %ld cylinders, %d heads, %d sectors per track (%ldMB) (%s)",
    243               (u32)pi->devs[d].dev_info.Cylinders, pi->devs[d].dev_info.HeadsPerCylinder, pi->devs[d].dev_info.SectorsPerTrack,
     72          NTPRINTF("    Drive %d:", d);
     73          if (pi->devs[d].atapi) NTPRINTF(" atapi");
     74          if (pi->devs[d].removable) NTPRINTF(" removable");
     75          if (pi->devs[d].dev_info.Method != NULL)
     76          {
     77            NTPRINTF(" %d cylinders, %d heads, %d sectors per track (%dMB) (%s)",
     78              pi->devs[d].dev_info.Cylinders, pi->devs[d].dev_info.HeadsPerCylinder, pi->devs[d].dev_info.SectorsPerTrack,
    24479              pi->devs[d].dev_info.TotalSectors/2048, pi->devs[d].dev_info.Method);
    245           } else ntprintf(" Drive present but no information available. Not queried by OS.");
    246           ntprintf("\n");
     80          } else NTPRINTF(" Drive present but no information available.");
     81          NTPRINTF("\n");
    24782        } /* if */
    24883      } /* for d */
     
    25186}
    25287
     88#ifdef DEBUG
     89void DumpIorb(IORBH *pIorb)
     90{
     91  DPRINTF(2,"IORB %x: Size=%x Len=%x Handle=%x CmdCode=%x\n",
     92      pIorb, sizeof(IORBH), pIorb->Length, pIorb->UnitHandle, pIorb->CommandCode);
     93  DPRINTF(2,"  CmdMod=%x ReqCtrl=%x Status=%x ErrorCode=%x\n",
     94      pIorb->CommandModifier, pIorb->RequestControl, pIorb->Status, pIorb->ErrorCode);
     95  DPRINTF(2,"  Timeout=%x StatusBlkLen=%x pStatusBlk=%x Res=%x pNxtIORB=%x\n",
     96      pIorb->Timeout, pIorb->StatusBlockLen, pIorb->pStatusBlock, pIorb->Reserved_1,
     97      pIorb->pNxtIORB);
     98}
     99#endif
     100
Note: See TracChangeset for help on using the changeset viewer.