harvey.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <acpi.h>
  10. #define MiB (1<<20)
  11. BOOLEAN AcpiGbl_DebugTimeout = FALSE;
  12. static uint32_t rsdp;
  13. static char *name;
  14. /* debug prints for this file. You can set this in gdb or at compile time. */
  15. static int debug;
  16. #if 0
  17. static int
  18. xisprint(int c)
  19. {
  20. return (c >= 32 && c <= 126);
  21. }
  22. static void
  23. hexdump(void *v, int length)
  24. {
  25. int i;
  26. uint8_t *m = v;
  27. uintptr_t memory = (uintptr_t) v;
  28. int all_zero = 0;
  29. if (debug)
  30. fprint(2, "hexdump: %p, %u\n", v, length);
  31. for (i = 0; i < length; i += 16) {
  32. int j;
  33. all_zero++;
  34. for (j = 0; (j < 16) && (i + j < length); j++) {
  35. if (m[i + j] != 0) {
  36. all_zero = 0;
  37. break;
  38. }
  39. }
  40. if (all_zero < 2) {
  41. if (debug)
  42. fprint(2, "%p:", (void *)(memory + i));
  43. for (j = 0; j < 16; j++)
  44. if (debug)
  45. fprint(2, " %02x", m[i + j]);
  46. if (debug)
  47. fprint(2, " ");
  48. for (j = 0; j < 16; j++)
  49. if (debug)
  50. fprint(2, "%c", xisprint(m[i + j]) ? m[i + j] : '.');
  51. if (debug)
  52. fprint(2, "\n");
  53. } else if (all_zero == 2) {
  54. if (debug)
  55. fprint(2, "...\n");
  56. }
  57. }
  58. }
  59. #endif
  60. /* try several variants */
  61. static int
  62. rawfd(void)
  63. {
  64. int fd;
  65. if (name == nil) {
  66. name = "/dev/acpimem";
  67. if (debug)
  68. fprint(2, "Rawfd: open '%s'\n", name);
  69. fd = open(name, OREAD);
  70. if (fd > -1)
  71. return fd;
  72. name = "#P/acpimem";
  73. if (debug)
  74. fprint(2, "Rawfd: open '%s'\n", name);
  75. fd = open(name, OREAD);
  76. if (fd > -1)
  77. return fd;
  78. }
  79. return open(name, OREAD);
  80. }
  81. int iol = -1, iow = -1, iob = -1;
  82. uint32_t
  83. inl(uint16_t addr)
  84. {
  85. uint64_t off = addr;
  86. uint32_t l;
  87. if (pread(iol, &l, 4, off) < 4)
  88. print("inl(0x%x): %r\n", addr);
  89. return l;
  90. }
  91. uint16_t
  92. ins(uint16_t addr)
  93. {
  94. uint64_t off = addr;
  95. uint16_t w;
  96. if (pread(iow, &w, 2, off) < 2)
  97. print("ins(0x%x): %r\n", addr);
  98. return w;
  99. }
  100. uint8_t
  101. inb(uint16_t addr)
  102. {
  103. uint64_t off = addr;
  104. uint16_t b;
  105. if (pread(iob, &b, 1, off) < 1)
  106. print("inb(0x%x): %r\n", addr);
  107. return b;
  108. }
  109. void
  110. outl(uint16_t addr, uint32_t val)
  111. {
  112. uint64_t off = addr;
  113. if (pwrite(iol, &val, 4, off) < 4)
  114. print("outl(0x%x): %r\n", addr);
  115. }
  116. void
  117. outs(uint16_t addr, uint16_t val)
  118. {
  119. uint64_t off = addr;
  120. if (pwrite(iow, &val, 2, off) < 2)
  121. print("outs(0x%x): %r\n", addr);
  122. }
  123. void
  124. outb(uint16_t addr, uint8_t val)
  125. {
  126. uint64_t off = addr;
  127. if (pwrite(iob, &val, 1, off) < 1)
  128. print("outb(0x%x): %r\n", addr);
  129. }
  130. #define MKBUS(t,b,d,f) (((t)<<24)|(((b)&0xFF)<<16)|(((d)&0x1F)<<11)|(((f)&0x07)<<8))
  131. #define BUSFNO(tbdf) (((tbdf)>>8)&0x07)
  132. #define BUSDNO(tbdf) (((tbdf)>>11)&0x1F)
  133. #define BUSBNO(tbdf) (((tbdf)>>16)&0xFF)
  134. #define BUSTYPE(tbdf) ((tbdf)>>24)
  135. #define BUSBDF(tbdf) ((tbdf)&0x00FFFF00)
  136. ACPI_STATUS
  137. AcpiOsReadPciConfiguration(ACPI_PCI_ID * PciId, UINT32 Reg, UINT64 * Value, UINT32 Width)
  138. {
  139. ACPI_STATUS ret = AE_OK;
  140. uint64_t val;
  141. int amt = 0;
  142. static char path[128];
  143. snprint(path, sizeof(path), "/dev/pci/%d.%d.%draw", PciId->Bus,
  144. PciId->Device, PciId->Function);
  145. int fd = open(path, OREAD);
  146. if (fd < 0) {
  147. if (debug)
  148. print("%s: open %s: %r\n", __func__, path);
  149. return AE_IO_ERROR;
  150. }
  151. switch (Width) {
  152. case 32:
  153. case 16:
  154. case 8:
  155. amt = pread(fd, Value, Width / 8, Reg);
  156. if (amt < Width / 8)
  157. ret = AE_IO_ERROR;
  158. break;
  159. default:
  160. sysfatal("Can't read pci: bad width %d\n", Width);
  161. }
  162. close(fd);
  163. if (amt > 0)
  164. memmove(&val, Value, amt);
  165. if (debug)
  166. fprint(2, "pciread 0x%x 0x%x 0x%x 0x%x/%d 0x%x %d\n", PciId->Bus,
  167. PciId->Device, PciId->Function, Reg, Width / 8, *Value, ret);
  168. return ret;
  169. }
  170. ACPI_STATUS
  171. AcpiOsWritePciConfiguration(ACPI_PCI_ID * PciId, UINT32 Reg, UINT64 Value, UINT32 Width)
  172. {
  173. ACPI_STATUS ret = AE_OK;
  174. static char path[128];
  175. snprint(path, sizeof(path), "/dev/pci/%d.%d.%draw", PciId->Bus,
  176. PciId->Device, PciId->Function);
  177. int fd = open(path, ORDWR);
  178. if (fd < 0) {
  179. print("%s: open %s: %r\n", __func__, path);
  180. return AE_IO_ERROR;
  181. }
  182. switch (Width) {
  183. case 32:
  184. case 16:
  185. case 8:
  186. {
  187. int amt = pwrite(fd, &Value, Width / 8, Reg);
  188. if (amt < Width / 8)
  189. ret = AE_IO_ERROR;
  190. break;
  191. }
  192. default:
  193. sysfatal("Can't read pci: bad width %d\n", Width);
  194. }
  195. close(fd);
  196. if (debug)
  197. fprint(2, "pciwrite 0x%x 0x%x 0x%x 0x%x/%d 0x%x %d\n", PciId->Bus,
  198. PciId->Device, PciId->Function, Reg, Width / 8, Value, ret);
  199. return ret;
  200. }
  201. /*
  202. * Miscellaneous
  203. */
  204. BOOLEAN
  205. AcpiOsReadable(void *Pointer, ACPI_SIZE Length)
  206. {
  207. if (debug)
  208. fprint(2, "%s\n", __func__);
  209. sysfatal("%s", __func__);
  210. return AE_OK;
  211. }
  212. BOOLEAN
  213. AcpiOsWritable(void *Pointer, ACPI_SIZE Length)
  214. {
  215. if (debug)
  216. fprint(2, "%s\n", __func__);
  217. sysfatal("%s", __func__);
  218. return AE_OK;
  219. }
  220. UINT64
  221. AcpiOsGetTimer(void)
  222. {
  223. if (debug)
  224. fprint(2, "%s\n", __func__);
  225. sysfatal("%s", __func__);
  226. return AE_OK;
  227. }
  228. ACPI_STATUS
  229. AcpiOsSignal(UINT32 Function, void *Info)
  230. {
  231. if (debug)
  232. fprint(2, "%s\n", __func__);
  233. sysfatal("%s", __func__);
  234. return AE_OK;
  235. }
  236. /* N.B. Only works for single thread! */
  237. void ACPI_INTERNAL_VAR_XFACE
  238. AcpiOsPrintf(const char *Format, ...)
  239. {
  240. static char buf[65536];
  241. va_list args;
  242. va_start(args, Format);
  243. vseprint(buf, &buf[65535], (char *)Format, args);
  244. va_end(args);
  245. if (debug)
  246. fprint(2, buf);
  247. }
  248. void
  249. AcpiOsVprintf(const char *Format, va_list Args)
  250. {
  251. /* This is a leaf function, and this function is required to implement
  252. * the va_list argument. I couldn't find any other way to do this. */
  253. static char buf[1024];
  254. vseprint(buf, &buf[1023], (char *)Format, Args);
  255. if (debug)
  256. fprint(2, buf);
  257. }
  258. void
  259. AcpiOsFree(void *Memory)
  260. {
  261. //fprint(2,"%s\n", __func__);
  262. free(Memory);
  263. }
  264. void *
  265. AcpiOsAllocate(ACPI_SIZE Size)
  266. {
  267. //fprint(2,"%s\n", __func__);
  268. return malloc(Size);
  269. }
  270. void hexdump(void *v, int length);
  271. void *
  272. AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS Where, ACPI_SIZE Length)
  273. {
  274. int fd, amt;
  275. fd = rawfd();
  276. if (debug)
  277. fprint(2, "%s %p %d\n", __func__, (void *)Where, Length);
  278. void *v = malloc(Length);
  279. if (!v) {
  280. sysfatal("%s: %r", __func__);
  281. return nil;
  282. }
  283. fd = rawfd();
  284. if (fd < 0) {
  285. if (debug)
  286. fprint(2, "%s: open %s: %r\n", __func__, name);
  287. return nil;
  288. }
  289. amt = pread(fd, v, Length, Where);
  290. close(fd);
  291. /* If we just do the amt < Length test, it will not work when
  292. * amt is -1. Length is uint64_t. */
  293. if ((amt < 0) || (amt < Length)) {
  294. free(v);
  295. if (debug)
  296. fprint(2, "%s: read %s: %r\n", __func__, name);
  297. return nil;
  298. }
  299. //hexdump(v, Length);
  300. //hexdump(v, 36);
  301. return v;
  302. }
  303. void
  304. AcpiOsUnmapMemory(void *LogicalAddress, ACPI_SIZE Size)
  305. {
  306. free(LogicalAddress);
  307. if (debug)
  308. fprint(2, "%s %p %d \n", __func__, LogicalAddress, Size);
  309. }
  310. ACPI_STATUS
  311. AcpiOsGetPhysicalAddress(void *LogicalAddress,
  312. ACPI_PHYSICAL_ADDRESS * PhysicalAddress)
  313. {
  314. ACPI_PHYSICAL_ADDRESS ret = (uintptr_t) LogicalAddress;
  315. if (debug)
  316. fprint(2, "%s %p = %p", __func__, (void *)ret, LogicalAddress);
  317. *PhysicalAddress = ret;
  318. return AE_OK;
  319. }
  320. /* This is the single threaded version of
  321. * these functions. This is now NetBSD does it. */
  322. ACPI_STATUS
  323. AcpiOsCreateSemaphore(UINT32 MaxUnits,
  324. UINT32 InitialUnits, ACPI_SEMAPHORE * OutHandle)
  325. {
  326. //fprint(2,"%s\n", __func__);
  327. *OutHandle = (ACPI_SEMAPHORE) 1;
  328. return AE_OK;
  329. }
  330. ACPI_STATUS
  331. AcpiOsDeleteSemaphore(ACPI_SEMAPHORE Handle)
  332. {
  333. //fprint(2,"%s\n", __func__);
  334. return AE_OK;
  335. }
  336. ACPI_STATUS
  337. AcpiOsWaitSemaphore(ACPI_SEMAPHORE Handle, UINT32 Units, UINT16 Timeout)
  338. {
  339. //fprint(2,"%s\n", __func__);
  340. return AE_OK;
  341. }
  342. ACPI_STATUS
  343. AcpiOsSignalSemaphore(ACPI_SEMAPHORE Handle, UINT32 Units)
  344. {
  345. //fprint(2,"%s\n", __func__);
  346. return AE_OK;
  347. }
  348. /* this is the single threaded case and as minix shows there is nothing to do. */
  349. ACPI_STATUS
  350. AcpiOsCreateLock(ACPI_SPINLOCK * OutHandle)
  351. {
  352. //fprint(2,"%s\n", __func__);
  353. *OutHandle = nil;
  354. return AE_OK;
  355. }
  356. void
  357. AcpiOsDeleteLock(ACPI_SPINLOCK Handle)
  358. {
  359. //fprint(2,"%s\n", __func__);
  360. }
  361. ACPI_CPU_FLAGS
  362. AcpiOsAcquireLock(ACPI_SPINLOCK Handle)
  363. {
  364. //fprint(2,"%s\n", __func__);
  365. return 0;
  366. }
  367. void
  368. AcpiOsReleaseLock(ACPI_SPINLOCK Handle, ACPI_CPU_FLAGS Flags)
  369. {
  370. //fprint(2,"%s\n", __func__);
  371. }
  372. struct handler {
  373. ACPI_OSD_HANDLER ServiceRoutine;
  374. void *Context;
  375. };
  376. #if 0
  377. /* The ACPI interrupt signature and the Harvey one are not compatible. So, we pass an arg to
  378. * intrenable that can in turn be used to this function to call the ACPI handler. */
  379. static void
  380. acpihandler(void *_, void *arg)
  381. {
  382. struct handler *h = arg;
  383. h->ServiceRoutine(h->Context);
  384. }
  385. #endif
  386. ACPI_STATUS
  387. AcpiOsInstallInterruptHandler(UINT32 InterruptNumber,
  388. ACPI_OSD_HANDLER ServiceRoutine, void *Context)
  389. {
  390. /* minix says "don't do it". So we don't, yet. */
  391. return AE_OK;
  392. struct handler *h = malloc(sizeof(*h));
  393. if (!h)
  394. return AE_NO_MEMORY;
  395. h->ServiceRoutine = ServiceRoutine;
  396. h->Context = Context;
  397. if (debug)
  398. fprint(2, "NOT DOING %s %d %p %p \n", __func__, InterruptNumber,
  399. ServiceRoutine, Context);
  400. /* once enabled, can't be disabled; ignore the return value unless it's nil. */
  401. //intrenable(InterruptNumber, acpihandler, h, 0x5, "ACPI interrupt handler");
  402. return AE_OK;
  403. }
  404. ACPI_STATUS
  405. AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber,
  406. ACPI_OSD_HANDLER ServiceRoutine)
  407. {
  408. if (debug)
  409. fprint(2, "%s\n", __func__);
  410. sysfatal("%s", __func__);
  411. return AE_OK;
  412. }
  413. void
  414. AcpiOsWaitEventsComplete(void)
  415. {
  416. if (debug)
  417. fprint(2, "%s\n", __func__);
  418. sysfatal("%s", __func__);
  419. }
  420. void
  421. AcpiOsSleep(UINT64 Milliseconds)
  422. {
  423. if (debug)
  424. fprint(2, "%s\n", __func__);
  425. sleep(Milliseconds);
  426. }
  427. void
  428. AcpiOsStall(UINT32 Microseconds)
  429. {
  430. if (debug)
  431. fprint(2, "%s\n", __func__);
  432. sleep(Microseconds / 1000 + 1);
  433. }
  434. ACPI_THREAD_ID
  435. AcpiOsGetThreadId(void)
  436. {
  437. static int pid = 2525;
  438. if (pid < 0)
  439. pid = getpid();
  440. return pid;
  441. }
  442. ACPI_STATUS
  443. AcpiOsExecute(ACPI_EXECUTE_TYPE Type,
  444. ACPI_OSD_EXEC_CALLBACK Function, void *Context)
  445. {
  446. ACPI_STATUS ret = AE_OK;
  447. if (debug)
  448. fprint(2, "%s\n", __func__);
  449. Function(Context);
  450. return ret;
  451. }
  452. ACPI_STATUS
  453. AcpiOsReadPort(ACPI_IO_ADDRESS Address, UINT32 * Value, UINT32 Width)
  454. {
  455. switch (Width) {
  456. case 4 * 8:
  457. *Value = inl(Address);
  458. break;
  459. case 2 * 8:
  460. *Value = ins(Address);
  461. break;
  462. case 1 * 8:
  463. *Value = inb(Address);
  464. break;
  465. default:
  466. sysfatal("%s, bad width %d", __func__, Width);
  467. break;
  468. }
  469. if (debug)
  470. fprint(2, "%s 0x%x 0x%x\n", __func__, Address, *Value);
  471. return AE_OK;
  472. }
  473. ACPI_STATUS
  474. AcpiOsWritePort(ACPI_IO_ADDRESS Address, UINT32 Value, UINT32 Width)
  475. {
  476. switch (Width) {
  477. case 4 * 8:
  478. outl(Address, Value);
  479. break;
  480. case 2 * 8:
  481. outs(Address, Value);
  482. break;
  483. case 1 * 8:
  484. outb(Address, Value);
  485. break;
  486. default:
  487. sysfatal("%s, bad width %d", __func__, Width);
  488. break;
  489. }
  490. if (debug)
  491. fprint(2, "%s 0x%x 0x%x\n", __func__, Address, Value);
  492. return AE_OK;
  493. }
  494. /*
  495. * Platform and hardware-independent physical memory interfaces
  496. */
  497. ACPI_STATUS
  498. AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS Address, UINT64 * Value, UINT32 Width)
  499. {
  500. if (debug)
  501. fprint(2, "%s\n", __func__);
  502. sysfatal("%s", __func__);
  503. return AE_OK;
  504. }
  505. ACPI_STATUS
  506. AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS Address, UINT64 Value, UINT32 Width)
  507. {
  508. if (debug)
  509. fprint(2, "%s\n", __func__);
  510. sysfatal("%s", __func__);
  511. return AE_OK;
  512. }
  513. /* Just try to read the rsdp, if that fails, we're screwed anyway. */
  514. ACPI_STATUS
  515. AcpiOsInitialize(void)
  516. {
  517. int fd, amt;
  518. if (debug)
  519. fprint(2, "%s\n", __func__);
  520. fd = rawfd();
  521. if (fd < 0) {
  522. if (debug)
  523. fprint(2, "%s: open %s: %r\n", __func__, name);
  524. return AE_ERROR;
  525. }
  526. amt = read(fd, &rsdp, sizeof(rsdp));
  527. if (amt < sizeof(rsdp)) {
  528. if (debug)
  529. fprint(2, "%s: read %s: %r\n", __func__, name);
  530. return AE_ERROR;
  531. }
  532. close(fd);
  533. iol = open("/dev/iol", ORDWR);
  534. if (iol < 0)
  535. sysfatal("iol: %r");
  536. iow = open("/dev/iow", ORDWR);
  537. if (iow < 0)
  538. sysfatal("iow: %r");
  539. iob = open("/dev/iob", ORDWR);
  540. if (iob < 0)
  541. sysfatal("iob: %r");
  542. return AE_OK;
  543. }
  544. /*
  545. * ACPI Table interfaces
  546. */
  547. __attribute__ ((weak))ACPI_PHYSICAL_ADDRESS
  548. AcpiOsGetRootPointer(void)
  549. {
  550. if (debug)
  551. fprint(2, "%s returns %p\n", __func__, rsdp);
  552. return (ACPI_PHYSICAL_ADDRESS) rsdp;
  553. }
  554. ACPI_STATUS
  555. AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES * InitVal,
  556. ACPI_STRING * NewVal)
  557. {
  558. if (debug)
  559. fprint(2, "%s\n", __func__);
  560. *NewVal = nil;
  561. return AE_OK;
  562. }
  563. ACPI_STATUS
  564. AcpiOsTableOverride(ACPI_TABLE_HEADER * ExistingTable,
  565. ACPI_TABLE_HEADER ** NewTable)
  566. {
  567. if (debug)
  568. fprint(2, "%s\n", __func__);
  569. *NewTable = nil;
  570. return AE_OK;
  571. }
  572. ACPI_STATUS
  573. AcpiOsPhysicalTableOverride(ACPI_TABLE_HEADER * ExistingTable,
  574. ACPI_PHYSICAL_ADDRESS * NewAddress,
  575. UINT32 * NewTableLength)
  576. {
  577. if (debug)
  578. fprint(2, "%s\n", __func__);
  579. *NewAddress = (ACPI_PHYSICAL_ADDRESS) nil;
  580. return AE_OK;
  581. }
  582. /*
  583. * Debug input
  584. */
  585. ACPI_STATUS
  586. AcpiOsGetLine(char *Buffer, UINT32 BufferLength, UINT32 * BytesRead)
  587. {
  588. int amt;
  589. if (debug)
  590. fprint(2, "%s\n", __func__);
  591. amt = read(0, Buffer, BufferLength);
  592. if (BytesRead)
  593. *BytesRead = amt;
  594. return AE_OK;
  595. }
  596. ACPI_STATUS
  597. AcpiOsTerminate(void)
  598. {
  599. sysfatal("%s\n", __func__);
  600. return AE_OK;
  601. }
  602. /* Another acpica failure of vision: code in libraries that depends on functions defined only
  603. * in the compiler or other programs. Really! What to do?
  604. * this is how the acpi tools do it. Save we add a print so we know the function is called, duh! */
  605. typedef void *ACPI_PARSE_OBJECT;
  606. typedef void *AML_RESOURCE;
  607. /* this is from acpiexec. */
  608. /* For AcpiExec only */
  609. __attribute__ ((weak))void
  610. AeDoObjectOverrides(void)
  611. {
  612. if (debug)
  613. fprint(2, "%s\n", __func__);
  614. }
  615. /* Stubs for the disassembler */
  616. __attribute__ ((weak))
  617. void
  618. MpSaveGpioInfo(ACPI_PARSE_OBJECT * Op,
  619. AML_RESOURCE * Resource,
  620. UINT32 PinCount, UINT16 * PinList, char *DeviceName)
  621. {
  622. if (debug)
  623. fprint(2, "%s\n", __func__);
  624. }
  625. __attribute__ ((weak))
  626. void
  627. MpSaveSerialInfo(ACPI_PARSE_OBJECT * Op,
  628. AML_RESOURCE * Resource, char *DeviceName)
  629. {
  630. if (debug)
  631. fprint(2, "%s\n", __func__);
  632. }
  633. int
  634. AcpiOsWriteFile(ACPI_FILE File, void *Buffer, ACPI_SIZE Size, ACPI_SIZE Count)
  635. {
  636. if (debug)
  637. fprint(2, "%s(%p, %p, %d, %d);\n", File, Buffer, Size, Count);
  638. return write(1, Buffer, Size * Count);
  639. }
  640. __attribute__ ((weak))
  641. void hexdump(void *v, int length)
  642. {
  643. int i;
  644. uint8_t *m = v;
  645. uintptr_t memory = (uintptr_t) v;
  646. int all_zero = 0;
  647. print("hexdump: %p, %u\n", v, length);
  648. for (i = 0; i < length; i += 16) {
  649. int j;
  650. all_zero++;
  651. for (j = 0; (j < 16) && (i + j < length); j++) {
  652. if (m[i + j] != 0) {
  653. all_zero = 0;
  654. break;
  655. }
  656. }
  657. if (all_zero < 2) {
  658. print("%p:", (void *)(memory + i));
  659. for (j = 0; j < 16; j++)
  660. print(" %02x", m[i + j]);
  661. print(" ");
  662. for (j = 0; j < 16; j++)
  663. print("%c", isprint(m[i + j]) ? m[i + j] : '.');
  664. print("\n");
  665. } else if (all_zero == 2) {
  666. print("...\n");
  667. }
  668. }
  669. }