]> git.proxmox.com Git - qemu.git/blobdiff - cache-utils.c
ide: Turn properties any IDE device must have into bus properties
[qemu.git] / cache-utils.c
index 0b4a5acb82f12fdda225bd602be6d0ae000125e8..2db5af2db14d025a5b24c606191c020028480a36 100644 (file)
@@ -1,6 +1,6 @@
 #include "cache-utils.h"
 
-#ifdef __powerpc__
+#if defined(_ARCH_PPC)
 struct qemu_cache_conf qemu_cache_conf = {
     .dcache_bsize = 16,
     .icache_bsize = 16
@@ -16,7 +16,10 @@ static void ppc_init_cacheline_sizes(void)
 }
 
 #elif defined __linux__
-#include <linux/auxvec.h>
+
+#define QEMU_AT_NULL        0
+#define QEMU_AT_DCACHEBSIZE 19
+#define QEMU_AT_ICACHEBSIZE 20
 
 static void ppc_init_cacheline_sizes(char **envp)
 {
@@ -24,16 +27,17 @@ static void ppc_init_cacheline_sizes(char **envp)
 
     while (*envp++);
 
-    for (auxv = (unsigned long *) envp; *auxv != AT_NULL; auxv += 2) {
+    for (auxv = (unsigned long *) envp; *auxv != QEMU_AT_NULL; auxv += 2) {
         switch (*auxv) {
-        case AT_DCACHEBSIZE: qemu_cache_conf.dcache_bsize = auxv[1]; break;
-        case AT_ICACHEBSIZE: qemu_cache_conf.icache_bsize = auxv[1]; break;
+        case QEMU_AT_DCACHEBSIZE: qemu_cache_conf.dcache_bsize = auxv[1]; break;
+        case QEMU_AT_ICACHEBSIZE: qemu_cache_conf.icache_bsize = auxv[1]; break;
         default: break;
         }
     }
 }
 
 #elif defined __APPLE__
+#include <stdio.h>
 #include <sys/types.h>
 #include <sys/sysctl.h>
 
@@ -43,6 +47,7 @@ static void ppc_init_cacheline_sizes(void)
     unsigned cacheline;
     int name[2] = { CTL_HW, HW_CACHELINE };
 
+    len = sizeof(cacheline);
     if (sysctl(name, 2, &cacheline, &len, NULL, 0)) {
         perror("sysctl CTL_HW HW_CACHELINE failed");
     } else {
@@ -52,6 +57,30 @@ static void ppc_init_cacheline_sizes(void)
 }
 #endif
 
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+static void ppc_init_cacheline_sizes(void)
+{
+    size_t len = 4;
+    unsigned cacheline;
+
+    if (sysctlbyname ("machdep.cacheline_size", &cacheline, &len, NULL, 0)) {
+        fprintf(stderr, "sysctlbyname machdep.cacheline_size failed: %s\n",
+                strerror(errno));
+        exit(1);
+    }
+
+    qemu_cache_conf.dcache_bsize = cacheline;
+    qemu_cache_conf.icache_bsize = cacheline;
+}
+#endif
+
 #ifdef __linux__
 void qemu_cache_utils_init(char **envp)
 {
@@ -65,4 +94,4 @@ void qemu_cache_utils_init(char **envp)
 }
 #endif
 
-#endif /* __powerpc__ */
+#endif /* _ARCH_PPC */