/*
* Copyright © 2008 Intel Corporation
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
#include <sys/mman.h>
#ifdef HAVE_STRUCT_SYSINFO_TOTALRAM
#include <sys/sysinfo.h>
+#elif defined(HAVE_SWAPCTL) /* Solaris */
+#include <sys/swap.h>
#endif
#include "intel_gpu_tools.h"
pagesize = sysconf(_SC_PAGESIZE);
npages = sysconf(_SC_PHYS_PAGES);
- retval = pagesize * npages;
+ retval = (uint64_t) pagesize * npages;
#else
#error "Unknown how to get RAM size for this OS"
#endif
retval = sysinf.totalswap;
retval *= sysinf.mem_unit;
+#elif defined(HAVE_SWAPCTL) /* Solaris */
+ long pagesize = sysconf(_SC_PAGESIZE);
+ uint64_t totalpages = 0;
+ swaptbl_t *swt;
+ char *buf;
+ int n, i;
+
+ if ((n = swapctl(SC_GETNSWP, NULL)) == -1) {
+ perror("swapctl: GETNSWP");
+ return 0;
+ }
+ if (n == 0) {
+ /* no error, but no swap devices either */
+ return 0;
+ }
+
+ swt = malloc(sizeof(struct swaptable) + (n * sizeof(swapent_t)));
+ buf = malloc(n * MAXPATHLEN);
+ if (!swt || !buf) {
+ perror("malloc");
+ } else {
+ swt->swt_n = n;
+ for (i = 0 ; i < n; i++) {
+ swt->swt_ent[i].ste_path = buf + (i * MAXPATHLEN);
+ }
+
+ if ((n = swapctl(SC_LIST, swt)) == -1) {
+ perror("swapctl: LIST");
+ } else {
+ for (i = 0; i < swt->swt_n; i++) {
+ totalpages += swt->swt_ent[i].ste_pages;
+ }
+ }
+ }
+ free(swt);
+ free(buf);
+
+ retval = (uint64_t) pagesize * totalpages;
#else
#error "Unknown how to get swap size for this OS"
#endif
return retval / (1024*1024);
}
+
+
+/*
+ * When testing a port to a new platform, create a standalone test binary
+ * by running:
+ * cc -o porttest intel_drm.c -I.. -DSTANDALONE_TEST `pkg-config --cflags libdrm`
+ * and then running the resulting porttest program.
+ */
+#ifdef STANDALONE_TEST
+void *mmio;
+
+int main(int argc, char **argv)
+{
+ printf("Total RAM: %" PRIu64 " Mb\n", intel_get_total_ram_mb());
+ printf("Total Swap: %" PRIu64 " Mb\n", intel_get_total_swap_mb());
+
+ return 0;
+}
+#endif /* STANDALONE_TEST */