aboutsummaryrefslogtreecommitdiff
path: root/pk
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2013-05-23 08:55:29 -0700
committerAndrew Waterman <waterman@cs.berkeley.edu>2013-05-23 08:55:29 -0700
commit17058f071b6bd2e2287c825aaebd390730ec5bdc (patch)
treef3ed7b2565e0cdb86157721570474ae9d5bc4431 /pk
parentf619a02f9fd816f4a438f2c389b6416da9e42cdd (diff)
downloadpk-17058f071b6bd2e2287c825aaebd390730ec5bdc.zip
pk-17058f071b6bd2e2287c825aaebd390730ec5bdc.tar.gz
pk-17058f071b6bd2e2287c825aaebd390730ec5bdc.tar.bz2
add sample device enumeration code
Diffstat (limited to 'pk')
-rw-r--r--pk/device.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/pk/device.c b/pk/device.c
new file mode 100644
index 0000000..e0019f8
--- /dev/null
+++ b/pk/device.c
@@ -0,0 +1,33 @@
+#include "pk.h"
+#include "pcr.h"
+
+static uint64_t tohost_sync(unsigned dev, unsigned cmd, uint64_t payload)
+{
+ uint64_t tohost = (uint64_t)dev << 56 | (uint64_t)cmd << 48 | payload;
+ uint64_t fromhost;
+ __sync_synchronize();
+ while (mtpcr(PCR_TOHOST, tohost));
+ while ((fromhost = mtpcr(PCR_FROMHOST, 0)) == 0);
+ __sync_synchronize();
+ return fromhost;
+}
+
+void enumerate_devices()
+{
+ char buf[64] __attribute__((aligned(64)));
+
+ for (uint64_t dev = 0; dev < 256; dev++)
+ {
+ tohost_sync(dev, 0xFF, (uintptr_t)buf << 8 | 0xFF);
+ if (buf[0])
+ {
+ printk("device %d: %s\n", dev, buf);
+ for (uint64_t cmd = 0; cmd < 255; cmd++)
+ {
+ tohost_sync(dev, 0xFF, (uintptr_t)buf << 8 | cmd);
+ if (buf[0])
+ printk(" command %d: %s\n", cmd, buf);
+ }
+ }
+ }
+}