cache-utils.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "cache-utils.h"
  2. #if defined(_ARCH_PPC)
  3. struct qemu_cache_conf qemu_cache_conf = {
  4. .dcache_bsize = 16,
  5. .icache_bsize = 16
  6. };
  7. #if defined _AIX
  8. #include <sys/systemcfg.h>
  9. static void ppc_init_cacheline_sizes(void)
  10. {
  11. qemu_cache_conf.icache_bsize = _system_configuration.icache_line;
  12. qemu_cache_conf.dcache_bsize = _system_configuration.dcache_line;
  13. }
  14. #elif defined __linux__
  15. #define QEMU_AT_NULL 0
  16. #define QEMU_AT_DCACHEBSIZE 19
  17. #define QEMU_AT_ICACHEBSIZE 20
  18. static void ppc_init_cacheline_sizes(char **envp)
  19. {
  20. unsigned long *auxv;
  21. while (*envp++);
  22. for (auxv = (unsigned long *) envp; *auxv != QEMU_AT_NULL; auxv += 2) {
  23. switch (*auxv) {
  24. case QEMU_AT_DCACHEBSIZE: qemu_cache_conf.dcache_bsize = auxv[1]; break;
  25. case QEMU_AT_ICACHEBSIZE: qemu_cache_conf.icache_bsize = auxv[1]; break;
  26. default: break;
  27. }
  28. }
  29. }
  30. #elif defined __APPLE__
  31. #include <stdio.h>
  32. #include <sys/types.h>
  33. #include <sys/sysctl.h>
  34. static void ppc_init_cacheline_sizes(void)
  35. {
  36. size_t len;
  37. unsigned cacheline;
  38. int name[2] = { CTL_HW, HW_CACHELINE };
  39. len = sizeof(cacheline);
  40. if (sysctl(name, 2, &cacheline, &len, NULL, 0)) {
  41. perror("sysctl CTL_HW HW_CACHELINE failed");
  42. } else {
  43. qemu_cache_conf.dcache_bsize = cacheline;
  44. qemu_cache_conf.icache_bsize = cacheline;
  45. }
  46. }
  47. #endif
  48. #ifdef __linux__
  49. void qemu_cache_utils_init(char **envp)
  50. {
  51. ppc_init_cacheline_sizes(envp);
  52. }
  53. #else
  54. void qemu_cache_utils_init(char **envp)
  55. {
  56. (void) envp;
  57. ppc_init_cacheline_sizes();
  58. }
  59. #endif
  60. #endif /* _ARCH_PPC */