diff options
author | Edmond Chung <edmondchung@google.com> | 2022-02-01 20:36:13 -0800 |
---|---|---|
committer | Edmond Chung <edmondchung@google.com> | 2022-05-03 23:42:39 +0000 |
commit | 236b72c5d46c506f28b79523b518569dd182573a (patch) | |
tree | ea32bd5143e8e72c0ff49f192ebd9135b748f338 | |
parent | a76d012ebd7876f17d95a76be9991c318625827a (diff) | |
download | lwis-236b72c5d46c506f28b79523b518569dd182573a.tar.gz |
Add version and feauture flag support
This is to keep track of all the features supported in LWIS and to
ensure that the client code is aligned with this codebase.
Bug: 214104920
Test: cat /dev/lwis-top
Signed-off-by: Edmond Chung <edmondchung@google.com>
Change-Id: Id0fb93c95684abfc8aeafa5e446af651d3760246
-rw-r--r-- | Kbuild | 1 | ||||
-rw-r--r-- | lwis_device.c | 25 | ||||
-rw-r--r-- | lwis_version.c | 34 | ||||
-rw-r--r-- | lwis_version.h | 29 |
4 files changed, 88 insertions, 1 deletions
@@ -21,6 +21,7 @@ lwis-objs += lwis_util.o lwis-objs += lwis_debug.o lwis-objs += lwis_io_entry.o lwis-objs += lwis_allocator.o +lwis-objs += lwis_version.o # Anchorage specific files ifeq ($(CONFIG_SOC_GS101), y) diff --git a/lwis_device.c b/lwis_device.c index 2d113ba..891a8e0 100644 --- a/lwis_device.c +++ b/lwis_device.c @@ -37,6 +37,7 @@ #include "lwis_pinctrl.h" #include "lwis_platform.h" #include "lwis_transaction.h" +#include "lwis_version.h" #ifdef CONFIG_OF #include "lwis_dt.h" @@ -58,6 +59,7 @@ static int lwis_open(struct inode *node, struct file *fp); static int lwis_release(struct inode *node, struct file *fp); static long lwis_ioctl(struct file *fp, unsigned int type, unsigned long param); static unsigned int lwis_poll(struct file *fp, poll_table *wait); +static ssize_t lwis_read(struct file *fp, char __user *user_buf, size_t count, loff_t *pos); static struct file_operations lwis_fops = { .owner = THIS_MODULE, @@ -65,6 +67,7 @@ static struct file_operations lwis_fops = { .release = lwis_release, .unlocked_ioctl = lwis_ioctl, .poll = lwis_poll, + .read = lwis_read, }; /* @@ -84,7 +87,7 @@ static int lwis_open(struct inode *node, struct file *fp) pr_err("No device %d found\n", iminor(node)); return -ENODEV; } - dev_dbg(lwis_dev->dev, "Opening instance %d\n", iminor(node)); + dev_info(lwis_dev->dev, "Opening instance %d\n", iminor(node)); lwis_client = kzalloc(sizeof(struct lwis_client), GFP_KERNEL); if (!lwis_client) { @@ -311,6 +314,26 @@ static unsigned int lwis_poll(struct file *fp, poll_table *wait) return mask; } +static ssize_t lwis_read(struct file *fp, char __user *user_buf, size_t count, loff_t *pos) +{ + int ret = 0; + /* Buffer to store information */ + const size_t buffer_size = 8192; + char *buffer = kzalloc(buffer_size, GFP_KERNEL); + if (!buffer) { + pr_err("Failed to allocate read buffer\n"); + return -ENOMEM; + } + + lwis_get_feature_flags(buffer, buffer_size); + + ret = simple_read_from_buffer(user_buf, count, pos, buffer, strlen(buffer)); + + kfree(buffer); + + return ret; +} + static int lwis_base_setup(struct lwis_device *lwis_dev) { int ret = 0; diff --git a/lwis_version.c b/lwis_version.c new file mode 100644 index 0000000..a284cbb --- /dev/null +++ b/lwis_version.c @@ -0,0 +1,34 @@ +/* + * Google LWIS Versioning File + * + * Copyright (c) 2022 Google, LLC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include <linux/kernel.h> +#include <linux/string.h> + +#include "lwis_version.h" + +void lwis_get_feature_flags(char *buffer, size_t buffer_size) +{ + scnprintf(buffer, buffer_size, + "LWIS (Lightweight Imaging Subsystem) Copyright 2022, Google LLC\n"); + + strlcat(buffer, "features: ", buffer_size); + + /* + * Feature flags start here: + */ + + /* core: + * All features we have shipped with in our initial version of LWIS, the basic fundamental + * functions of LWIS. + */ + strlcat(buffer, "core", buffer_size); + + strlcat(buffer, "\n", buffer_size); +}
\ No newline at end of file diff --git a/lwis_version.h b/lwis_version.h new file mode 100644 index 0000000..7423386 --- /dev/null +++ b/lwis_version.h @@ -0,0 +1,29 @@ +/* + * Google LWIS Feature Versioning File + * + * Copyright (c) 2022 Google, LLC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef LWIS_VERSION_H_ +#define LWIS_VERSION_H_ + +#include <linux/types.h> + +/* + * Get LWIS feature flags + * This is where we specify the features this version of LWIS is supporting. + * + * Special characters: + * ' ' : A space is used to separate different features + * '=' : An equal sign is used to store key-value pairs + * + * Example: + * "features: foo bar=xyz" + */ +void lwis_get_feature_flags(char *buffer, size_t buffer_size); + +#endif /* LWIS_VERSION_H_ */
\ No newline at end of file |