summaryrefslogtreecommitdiff
path: root/bmm_lib.c
diff options
context:
space:
mode:
authorRussell King <rmk@arm.linux.org.uk>2013-06-22 22:34:57 +0100
committerRussell King <rmk@arm.linux.org.uk>2013-06-22 22:40:38 +0100
commit399b0f5486bf1199b74a6eb043b3aed60723d1fe (patch)
tree5791a93f917cd887a7a9f37fb67f28a66b65afac /bmm_lib.c
parent4955e668e477720e371a8f4abcd2931ff359cc48 (diff)
Add method to get kernel driver version
Add a method to allow the userspace library to obtain the API version of the kernel driver. This allows us to automatically adjust to changes in the API and fail cleanly when we detect an incompatibility.
Diffstat (limited to 'bmm_lib.c')
-rw-r--r--bmm_lib.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/bmm_lib.c b/bmm_lib.c
index e6ba3e9..f9d8e69 100644
--- a/bmm_lib.c
+++ b/bmm_lib.c
@@ -30,8 +30,37 @@
#define pr_debug(fmt, arg...) do { } while(0)
#endif
+#define API_FEAT_MIN 0x0000
+#define API_COMP_MAX 0x0000
+#define API_FEAT(x) ((x) >> 16)
+#define API_COMP(x) ((x) & 0xffff)
+
+static unsigned bmm_api;
static int bmm_fd = -1;
+static int bmm_get_api_version(void)
+{
+ ioctl_arg_t io;
+
+ /* Get the BMM API version */
+ io.input = 0;
+ io.arg = 0;
+ io.output = 0;
+ if (ioctl(bmm_fd, BMM_API_VERSION, &io) == 0 &&
+ io.input == 0xdeaddead && io.arg == 0xfacebeef)
+ bmm_api = io.output;
+ else
+ bmm_api = 0;
+
+ pr_debug("BMM API version %08x\n", bmm_api);
+
+ if (API_FEAT(bmm_api) < API_FEAT_MIN ||
+ API_COMP(bmm_api) > API_COMP_MAX)
+ return -1;
+
+ return 0;
+}
+
int bmm_init()
{
/* attempt to open the BMM driver */
@@ -39,9 +68,20 @@ int bmm_init()
bmm_fd = open(BMM_DEVICE_FILE, O_RDWR | O_CLOEXEC);
pr_debug("BMM device fd: %d\n", bmm_fd);
+ if (bmm_fd < 0)
+ goto err_open;
+
+ if (bmm_get_api_version() < 0)
+ goto err_api;
}
return bmm_fd;
+
+ err_api:
+ close(bmm_fd);
+ bmm_fd = -1;
+ err_open:
+ return bmm_fd;
}
void bmm_exit()