Changeset 178 for trunk/src/os2ahci/trace.c
- Timestamp:
- Nov 29, 2016, 5:30:22 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/os2ahci/trace.c
r176 r178 4 4 * Copyright (c) 2011 thi.guten Software Development 5 5 * Copyright (c) 2011 Mensys B.V. 6 * Copyright (c) 2013-201 5David Azarewicz6 * Copyright (c) 2013-2016 David Azarewicz 7 7 * 8 8 * Authors: Christian Mueller, Markus Thielen … … 36 36 /* ------------------------ global/static variables ------------------------ */ 37 37 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 46 38 /* ----------------------------- start of code ----------------------------- */ 47 48 /******************************************************************************49 * initialize AHCI circular trace buffer50 *51 * NOTE: this func must be called during INIT time since it allocates52 * a GDT selector for the trace ring buffer53 */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 buffer101 *102 * NOTE: this function is here for completeness; the trace buffer should not103 * 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 buffer123 *124 * Note: This func wraps the buffer if necessary, so the caller does not125 * 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 buffer158 * returns the number of bytes written to the caller's buffer159 *160 * NOTE: the caller is expected to call this func repeatedly161 * (up to two times) until it returns 0162 */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 }208 39 209 40 /****************************************************************************** 210 41 * Create adapter/port/device list for user output. 211 42 */ 212 void build_user_info( int check)43 void build_user_info(void) 213 44 { 214 45 int a; … … 216 47 int d; 217 48 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 { 221 51 AD_INFO *ai = ad_infos + a; 222 52 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), 225 56 ai->pci_vendor, ai->pci_device, vendor_from_id(ai->pci_vendor), ai->pci->chipname, 226 57 ai->irq, ai->mmio_phys, 227 58 ai->bios_config[HOST_VERSION / sizeof(u32)]); 228 59 229 for (p = 0; p < ai->hw_ports; p++) { 60 for (p = 0; p < ai->hw_ports; p++) 61 { 230 62 P_INFO *pi = &ai->ports[p]; 231 63 232 ntprintf(" Port %d:\n", p);64 NTPRINTF(" Port %d:\n", p); 233 65 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"); 237 71 } 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, 244 79 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"); 247 82 } /* if */ 248 83 } /* for d */ … … 251 86 } 252 87 88 #ifdef DEBUG 89 void 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.