diff mbox series

[3/5] HID: Extract vivaldi hid feature mapping for use in hid-hammer

Message ID 20220204202021.895426-4-swboyd@chromium.org (mailing list archive)
State Superseded
Headers show
Series Input/HID: Consolidate ChromeOS Vivaldi keyboard logic | expand

Commit Message

Stephen Boyd Feb. 4, 2022, 8:20 p.m. UTC
We need to support parsing the HID device in both the vivaldi and the
hammer drivers so that we can properly expose the function row physmap
to userspace when a hammer device uses a vivaldi keyboard layout for the
function row keys. Extract the feature mapping logic from the vivaldi
driver into the vivaldi-keymap library so we can use it from both
HID drivers.

Cc: Jiri Kosina <jikos@kernel.org>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: "Sean O'Brien" <seobrien@chromium.org>
Cc: Douglas Anderson <dianders@chromium.org>
Cc: Zhengqiao Xia <xiazhengqiao@huaqin.corp-partner.google.com>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 drivers/hid/hid-vivaldi.c            | 69 +---------------------
 drivers/input/vivaldi-keymap.c       | 86 ++++++++++++++++++++++++++++
 include/linux/input/vivaldi-keymap.h |  9 +++
 3 files changed, 97 insertions(+), 67 deletions(-)

Comments

kernel test robot Feb. 5, 2022, 12:15 a.m. UTC | #1
Hi Stephen,

I love your patch! Yet something to improve:

[auto build test ERROR on 26291c54e111ff6ba87a164d85d4a4e134b7315c]

url:    https://github.com/0day-ci/linux/commits/Stephen-Boyd/Input-HID-Consolidate-ChromeOS-Vivaldi-keyboard-logic/20220205-042211
base:   26291c54e111ff6ba87a164d85d4a4e134b7315c
config: x86_64-randconfig-a004-20220131 (https://download.01.org/0day-ci/archive/20220205/202202050807.BvUyitVE-lkp@intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/83759eb892fd16fd0bb7ff4bb0c4baa4e7a0283e
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Stephen-Boyd/Input-HID-Consolidate-ChromeOS-Vivaldi-keyboard-logic/20220205-042211
        git checkout 83759eb892fd16fd0bb7ff4bb0c4baa4e7a0283e
        # save the config file to linux build tree
        mkdir build_dir
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   vmlinux.o: warning: objtool: mce_start()+0x4e: call to clear_bit() leaves .noinstr.text section
   vmlinux.o: warning: objtool: mce_read_aux()+0x41: call to mca_msr_reg() leaves .noinstr.text section
   vmlinux.o: warning: objtool: do_machine_check()+0x39d: call to test_bit() leaves .noinstr.text section
   vmlinux.o: warning: objtool: enter_from_user_mode()+0x4e: call to on_thread_stack() leaves .noinstr.text section
   vmlinux.o: warning: objtool: syscall_enter_from_user_mode()+0x53: call to on_thread_stack() leaves .noinstr.text section
   vmlinux.o: warning: objtool: syscall_enter_from_user_mode_prepare()+0x4e: call to on_thread_stack() leaves .noinstr.text section
   vmlinux.o: warning: objtool: irqentry_enter_from_user_mode()+0x4e: call to on_thread_stack() leaves .noinstr.text section
   ld: drivers/input/vivaldi-keymap.o: in function `vivaldi_hid_feature_mapping':
>> drivers/input/vivaldi-keymap.c:73: undefined reference to `hid_alloc_report_buf'
>> ld: drivers/input/vivaldi-keymap.c:90: undefined reference to `hid_hw_raw_request'
>> ld: drivers/input/vivaldi-keymap.c:108: undefined reference to `hid_report_raw_event'


vim +73 drivers/input/vivaldi-keymap.c

    44	
    45	/**
    46	 * vivaldi_hid_feature_mapping - Fill out vivaldi keymap data exposed via HID
    47	 * @data: The vivaldi function keymap
    48	 * @hdev: HID device to parse
    49	 * @field: HID field to parse
    50	 * @usage: HID usage to parse
    51	 */
    52	void vivaldi_hid_feature_mapping(struct vivaldi_data *data,
    53					 struct hid_device *hdev,
    54					 struct hid_field *field,
    55					 struct hid_usage *usage)
    56	{
    57		struct hid_report *report = field->report;
    58		int fn_key;
    59		int ret;
    60		u32 report_len;
    61		u8 *report_data, *buf;
    62	
    63		if (field->logical != HID_USAGE_FN_ROW_PHYSMAP ||
    64		    (usage->hid & HID_USAGE_PAGE) != HID_UP_ORDINAL)
    65			return;
    66	
    67		fn_key = (usage->hid & HID_USAGE);
    68		if (fn_key < VIVALDI_MIN_FN_ROW_KEY || fn_key > VIVALDI_MAX_FN_ROW_KEY)
    69			return;
    70		if (fn_key > data->num_function_row_keys)
    71			data->num_function_row_keys = fn_key;
    72	
  > 73		report_data = buf = hid_alloc_report_buf(report, GFP_KERNEL);
    74		if (!report_data)
    75			return;
    76	
    77		report_len = hid_report_len(report);
    78		if (!report->id) {
    79			/*
    80			 * hid_hw_raw_request() will stuff report ID (which will be 0)
    81			 * into the first byte of the buffer even for unnumbered
    82			 * reports, so we need to account for this to avoid getting
    83			 * -EOVERFLOW in return.
    84			 * Note that hid_alloc_report_buf() adds 7 bytes to the size
    85			 * so we can safely say that we have space for an extra byte.
    86			 */
    87			report_len++;
    88		}
    89	
  > 90		ret = hid_hw_raw_request(hdev, report->id, report_data,
    91					 report_len, HID_FEATURE_REPORT,
    92					 HID_REQ_GET_REPORT);
    93		if (ret < 0) {
    94			dev_warn(&hdev->dev, "failed to fetch feature %d\n",
    95				 field->report->id);
    96			goto out;
    97		}
    98	
    99		if (!report->id) {
   100			/*
   101			 * Undo the damage from hid_hw_raw_request() for unnumbered
   102			 * reports.
   103			 */
   104			report_data++;
   105			report_len--;
   106		}
   107	
 > 108		ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, report_data,
   109					   report_len, 0);
   110		if (ret) {
   111			dev_warn(&hdev->dev, "failed to report feature %d\n",
   112				 field->report->id);
   113			goto out;
   114		}
   115	
   116		data->function_row_physmap[fn_key - VIVALDI_MIN_FN_ROW_KEY] =
   117		    field->value[usage->usage_index];
   118	
   119	out:
   120		kfree(buf);
   121	}
   122	EXPORT_SYMBOL_GPL(vivaldi_hid_feature_mapping);
   123	#endif /* CONFIG_HID */
   124	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Stephen Boyd Feb. 5, 2022, 2:19 a.m. UTC | #2
Quoting kernel test robot (2022-02-04 16:15:59)
> Hi Stephen,
>
> I love your patch! Yet something to improve:
>
> [auto build test ERROR on 26291c54e111ff6ba87a164d85d4a4e134b7315c]
>
> url:    https://github.com/0day-ci/linux/commits/Stephen-Boyd/Input-HID-Consolidate-ChromeOS-Vivaldi-keyboard-logic/20220205-042211
> base:   26291c54e111ff6ba87a164d85d4a4e134b7315c
> config: x86_64-randconfig-a004-20220131 (https://download.01.org/0day-ci/archive/20220205/202202050807.BvUyitVE-lkp@intel.com/config)
> compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
> reproduce (this is a W=1 build):
>         # https://github.com/0day-ci/linux/commit/83759eb892fd16fd0bb7ff4bb0c4baa4e7a0283e
>         git remote add linux-review https://github.com/0day-ci/linux
>         git fetch --no-tags linux-review Stephen-Boyd/Input-HID-Consolidate-ChromeOS-Vivaldi-keyboard-logic/20220205-042211
>         git checkout 83759eb892fd16fd0bb7ff4bb0c4baa4e7a0283e
>         # save the config file to linux build tree
>         mkdir build_dir
>         make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
>
> All errors (new ones prefixed by >>):
>
>    vmlinux.o: warning: objtool: mce_start()+0x4e: call to clear_bit() leaves .noinstr.text section
>    vmlinux.o: warning: objtool: mce_read_aux()+0x41: call to mca_msr_reg() leaves .noinstr.text section
>    vmlinux.o: warning: objtool: do_machine_check()+0x39d: call to test_bit() leaves .noinstr.text section
>    vmlinux.o: warning: objtool: enter_from_user_mode()+0x4e: call to on_thread_stack() leaves .noinstr.text section
>    vmlinux.o: warning: objtool: syscall_enter_from_user_mode()+0x53: call to on_thread_stack() leaves .noinstr.text section
>    vmlinux.o: warning: objtool: syscall_enter_from_user_mode_prepare()+0x4e: call to on_thread_stack() leaves .noinstr.text section
>    vmlinux.o: warning: objtool: irqentry_enter_from_user_mode()+0x4e: call to on_thread_stack() leaves .noinstr.text section
>    ld: drivers/input/vivaldi-keymap.o: in function `vivaldi_hid_feature_mapping':
> >> drivers/input/vivaldi-keymap.c:73: undefined reference to `hid_alloc_report_buf'
> >> ld: drivers/input/vivaldi-keymap.c:90: undefined reference to `hid_hw_raw_request'
> >> ld: drivers/input/vivaldi-keymap.c:108: undefined reference to `hid_report_raw_event'
>

Ah I see. CONFIG_HID=m but CONFIG_VIVALDIFMAP=y so we need to make the
whole file into a module when CONFIG_HID is a module, but then that
means the atkbd driver would need to be a module too. Probably best to
move this hid part to yet another file in drivers/hid/ to keep things
tidy.
kernel test robot Feb. 5, 2022, 3:19 a.m. UTC | #3
Hi Stephen,

I love your patch! Yet something to improve:

[auto build test ERROR on 26291c54e111ff6ba87a164d85d4a4e134b7315c]

url:    https://github.com/0day-ci/linux/commits/Stephen-Boyd/Input-HID-Consolidate-ChromeOS-Vivaldi-keyboard-logic/20220205-042211
base:   26291c54e111ff6ba87a164d85d4a4e134b7315c
config: s390-randconfig-r014-20220130 (https://download.01.org/0day-ci/archive/20220205/202202051134.yIxi48BD-lkp@intel.com/config)
compiler: s390-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/83759eb892fd16fd0bb7ff4bb0c4baa4e7a0283e
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Stephen-Boyd/Input-HID-Consolidate-ChromeOS-Vivaldi-keyboard-logic/20220205-042211
        git checkout 83759eb892fd16fd0bb7ff4bb0c4baa4e7a0283e
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=s390 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   s390-linux-ld: drivers/dma/idma64.o: in function `idma64_platform_probe':
   idma64.c:(.text+0x1336): undefined reference to `devm_ioremap_resource'
   s390-linux-ld: drivers/input/vivaldi-keymap.o: in function `vivaldi_hid_feature_mapping':
>> (.text+0x13e): undefined reference to `hid_alloc_report_buf'
>> s390-linux-ld: (.text+0x18c): undefined reference to `hid_hw_raw_request'
>> s390-linux-ld: (.text+0x1e8): undefined reference to `hid_report_raw_event'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/hid/hid-vivaldi.c b/drivers/hid/hid-vivaldi.c
index 78ae3725bc89..361ba6200387 100644
--- a/drivers/hid/hid-vivaldi.c
+++ b/drivers/hid/hid-vivaldi.c
@@ -13,9 +13,6 @@ 
 #include <linux/module.h>
 #include <linux/sysfs.h>
 
-#define HID_VD_FN_ROW_PHYSMAP 0x00000001
-#define HID_USAGE_FN_ROW_PHYSMAP (HID_UP_GOOGLEVENDOR | HID_VD_FN_ROW_PHYSMAP)
-
 static ssize_t function_row_physmap_show(struct device *dev,
 					 struct device_attribute *attr,
 					 char *buf)
@@ -60,70 +57,8 @@  static void vivaldi_feature_mapping(struct hid_device *hdev,
 				    struct hid_usage *usage)
 {
 	struct vivaldi_data *drvdata = hid_get_drvdata(hdev);
-	struct hid_report *report = field->report;
-	int fn_key;
-	int ret;
-	u32 report_len;
-	u8 *report_data, *buf;
-
-	if (field->logical != HID_USAGE_FN_ROW_PHYSMAP ||
-	    (usage->hid & HID_USAGE_PAGE) != HID_UP_ORDINAL)
-		return;
-
-	fn_key = (usage->hid & HID_USAGE);
-	if (fn_key < VIVALDI_MIN_FN_ROW_KEY || fn_key > VIVALDI_MAX_FN_ROW_KEY)
-		return;
-	if (fn_key > drvdata->num_function_row_keys)
-		drvdata->num_function_row_keys = fn_key;
-
-	report_data = buf = hid_alloc_report_buf(report, GFP_KERNEL);
-	if (!report_data)
-		return;
-
-	report_len = hid_report_len(report);
-	if (!report->id) {
-		/*
-		 * hid_hw_raw_request() will stuff report ID (which will be 0)
-		 * into the first byte of the buffer even for unnumbered
-		 * reports, so we need to account for this to avoid getting
-		 * -EOVERFLOW in return.
-		 * Note that hid_alloc_report_buf() adds 7 bytes to the size
-		 * so we can safely say that we have space for an extra byte.
-		 */
-		report_len++;
-	}
-
-	ret = hid_hw_raw_request(hdev, report->id, report_data,
-				 report_len, HID_FEATURE_REPORT,
-				 HID_REQ_GET_REPORT);
-	if (ret < 0) {
-		dev_warn(&hdev->dev, "failed to fetch feature %d\n",
-			 field->report->id);
-		goto out;
-	}
-
-	if (!report->id) {
-		/*
-		 * Undo the damage from hid_hw_raw_request() for unnumbered
-		 * reports.
-		 */
-		report_data++;
-		report_len--;
-	}
-
-	ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, report_data,
-				   report_len, 0);
-	if (ret) {
-		dev_warn(&hdev->dev, "failed to report feature %d\n",
-			 field->report->id);
-		goto out;
-	}
-
-	drvdata->function_row_physmap[fn_key - VIVALDI_MIN_FN_ROW_KEY] =
-	    field->value[usage->usage_index];
-
-out:
-	kfree(buf);
+
+	vivaldi_hid_feature_mapping(drvdata, hdev, field, usage);
 }
 
 static int vivaldi_input_configured(struct hid_device *hdev,
diff --git a/drivers/input/vivaldi-keymap.c b/drivers/input/vivaldi-keymap.c
index da6dc4070216..7d472b8126b2 100644
--- a/drivers/input/vivaldi-keymap.c
+++ b/drivers/input/vivaldi-keymap.c
@@ -6,6 +6,7 @@ 
  */
 
 #include <linux/export.h>
+#include <linux/hid.h>
 #include <linux/input/vivaldi-keymap.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -36,4 +37,89 @@  ssize_t vivaldi_function_row_physmap_show(const struct vivaldi_data *data,
 }
 EXPORT_SYMBOL_GPL(vivaldi_function_row_physmap_show);
 
+#if IS_ENABLED(CONFIG_HID)
+
+#define HID_VD_FN_ROW_PHYSMAP 0x00000001
+#define HID_USAGE_FN_ROW_PHYSMAP (HID_UP_GOOGLEVENDOR | HID_VD_FN_ROW_PHYSMAP)
+
+/**
+ * vivaldi_hid_feature_mapping - Fill out vivaldi keymap data exposed via HID
+ * @data: The vivaldi function keymap
+ * @hdev: HID device to parse
+ * @field: HID field to parse
+ * @usage: HID usage to parse
+ */
+void vivaldi_hid_feature_mapping(struct vivaldi_data *data,
+				 struct hid_device *hdev,
+				 struct hid_field *field,
+				 struct hid_usage *usage)
+{
+	struct hid_report *report = field->report;
+	int fn_key;
+	int ret;
+	u32 report_len;
+	u8 *report_data, *buf;
+
+	if (field->logical != HID_USAGE_FN_ROW_PHYSMAP ||
+	    (usage->hid & HID_USAGE_PAGE) != HID_UP_ORDINAL)
+		return;
+
+	fn_key = (usage->hid & HID_USAGE);
+	if (fn_key < VIVALDI_MIN_FN_ROW_KEY || fn_key > VIVALDI_MAX_FN_ROW_KEY)
+		return;
+	if (fn_key > data->num_function_row_keys)
+		data->num_function_row_keys = fn_key;
+
+	report_data = buf = hid_alloc_report_buf(report, GFP_KERNEL);
+	if (!report_data)
+		return;
+
+	report_len = hid_report_len(report);
+	if (!report->id) {
+		/*
+		 * hid_hw_raw_request() will stuff report ID (which will be 0)
+		 * into the first byte of the buffer even for unnumbered
+		 * reports, so we need to account for this to avoid getting
+		 * -EOVERFLOW in return.
+		 * Note that hid_alloc_report_buf() adds 7 bytes to the size
+		 * so we can safely say that we have space for an extra byte.
+		 */
+		report_len++;
+	}
+
+	ret = hid_hw_raw_request(hdev, report->id, report_data,
+				 report_len, HID_FEATURE_REPORT,
+				 HID_REQ_GET_REPORT);
+	if (ret < 0) {
+		dev_warn(&hdev->dev, "failed to fetch feature %d\n",
+			 field->report->id);
+		goto out;
+	}
+
+	if (!report->id) {
+		/*
+		 * Undo the damage from hid_hw_raw_request() for unnumbered
+		 * reports.
+		 */
+		report_data++;
+		report_len--;
+	}
+
+	ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, report_data,
+				   report_len, 0);
+	if (ret) {
+		dev_warn(&hdev->dev, "failed to report feature %d\n",
+			 field->report->id);
+		goto out;
+	}
+
+	data->function_row_physmap[fn_key - VIVALDI_MIN_FN_ROW_KEY] =
+	    field->value[usage->usage_index];
+
+out:
+	kfree(buf);
+}
+EXPORT_SYMBOL_GPL(vivaldi_hid_feature_mapping);
+#endif /* CONFIG_HID */
+
 MODULE_LICENSE("GPL");
diff --git a/include/linux/input/vivaldi-keymap.h b/include/linux/input/vivaldi-keymap.h
index 4023b65e1649..7cf5bc650fed 100644
--- a/include/linux/input/vivaldi-keymap.h
+++ b/include/linux/input/vivaldi-keymap.h
@@ -4,6 +4,10 @@ 
 
 #include <linux/types.h>
 
+struct hid_device;
+struct hid_field;
+struct hid_usage;
+
 #define VIVALDI_MIN_FN_ROW_KEY	1
 #define VIVALDI_MAX_FN_ROW_KEY	24
 
@@ -25,4 +29,9 @@  struct vivaldi_data {
 ssize_t vivaldi_function_row_physmap_show(const struct vivaldi_data *data,
 					  char *buf);
 
+void vivaldi_hid_feature_mapping(struct vivaldi_data *data,
+				 struct hid_device *hdev,
+				 struct hid_field *field,
+				 struct hid_usage *usage);
+
 #endif /* _VIVALDI_KEYMAP_H */