Skip to contentSkip to conversation

drivers/staging: Gasket driver framework + Apex driver

PATCH Superseded Simon Que 3 participants 3 messages Jun 30, 2018 Staging

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Simon Que

author
#0 lore raw

PATCH v6 1/1 drivers/staging: Gasket driver framework + Apex driver

The Gasket (Google ASIC Software, Kernel Extensions, and Tools) kernel framework is a generic, flexible system that supports thin kernel drivers. Gasket kernel drivers are expected to handle opening and closing devices, mmap'ing BAR space as requested, a small selection of ioctls, and handling page table translation (covered below). Any other functions should be handled by userspace code.

The Gasket common module is not enough to run a device. In order to customize the Gasket code for a given piece of hardware, a device specific module must be created. At a minimum, this module must define a struct gasket_driver_desc containing the device-specific data for use by the framework; in addition, the module must declare an __init function that calls gasket_register_device with the module's gasket_driver_desc struct. Finally, the driver must define an exit function that calls gasket_unregister_device with the module's gasket_driver_desc struct.

One of the core assumptions of the Gasket framework is that precisely one process is allowed to have an open write handle to the device node at any given time. (That process may, once it has one write handle, open any number of additional write handles.) This is accomplished by tracking open and close data for each driver instance.

---
Patch history:
[PATCH v2]
- Various fixes from John Joseph and Rob Springer
[PATCH v3]
- Removed part about Apex from patch description
- Rearranged order of authors
- 2017 -> 2018
- GPL -> GPL v2
- Deleted README
- Added MAINTAINERS
- Added TODO with all unresolved comments from below
- Added gasket_ioctl.h, which was previously missing
[PATCH v4]
- Deleted unused field "base" in struct gasket_coherent_buffer
- Moved maintainer info to top-level MAINTAINERS file
[PATCH v5]
- Updated drivers/staging/Makefile change to apply to gregkh's staging tree.
[PATCH v6]
- Modified gasket_sysfs.c and gasket_core.c to build against linux-next.

---
 MAINTAINERS                                |    7 +
 drivers/staging/Kconfig                    |    2 +
 drivers/staging/Makefile                   |    1 +
 drivers/staging/gasket/Kconfig             |   23 +
 drivers/staging/gasket/Makefile            |    9 +
 drivers/staging/gasket/TODO                |   17 +
 drivers/staging/gasket/apex.h              |   95 +
 drivers/staging/gasket/apex_driver.c       |  771 +++++++
 drivers/staging/gasket/gasket.h            |  129 ++
 drivers/staging/gasket/gasket_constants.h  |   56 +
 drivers/staging/gasket/gasket_core.c       | 2157 ++++++++++++++++++++
 drivers/staging/gasket/gasket_core.h       |  719 +++++++
 drivers/staging/gasket/gasket_interrupt.c  |  638 ++++++
 drivers/staging/gasket/gasket_interrupt.h  |  172 ++
 drivers/staging/gasket/gasket_ioctl.c      |  449 ++++
 drivers/staging/gasket/gasket_ioctl.h      |   35 +
 drivers/staging/gasket/gasket_logging.h    |   71 +
 drivers/staging/gasket/gasket_page_table.c | 1771 ++++++++++++++++
 drivers/staging/gasket/gasket_page_table.h |  265 +++
 drivers/staging/gasket/gasket_sysfs.c      |  497 +++++
 drivers/staging/gasket/gasket_sysfs.h      |  199 ++
 21 files changed, 8083 insertions(+)
 create mode 100644 drivers/staging/gasket/Kconfig
 create mode 100644 drivers/staging/gasket/Makefile
 create mode 100644 drivers/staging/gasket/TODO
 create mode 100644 drivers/staging/gasket/apex.h
 create mode 100644 drivers/staging/gasket/apex_driver.c
 create mode 100644 drivers/staging/gasket/gasket.h
 create mode 100644 drivers/staging/gasket/gasket_constants.h
 create mode 100644 drivers/staging/gasket/gasket_core.c
 create mode 100644 drivers/staging/gasket/gasket_core.h
 create mode 100644 drivers/staging/gasket/gasket_interrupt.c
 create mode 100644 drivers/staging/gasket/gasket_interrupt.h
 create mode 100644 drivers/staging/gasket/gasket_ioctl.c
 create mode 100644 drivers/staging/gasket/gasket_ioctl.h
 create mode 100644 drivers/staging/gasket/gasket_logging.h
 create mode 100644 drivers/staging/gasket/gasket_page_table.c
 create mode 100644 drivers/staging/gasket/gasket_page_table.h
 create mode 100644 drivers/staging/gasket/gasket_sysfs.c
 create mode 100644 drivers/staging/gasket/gasket_sysfs.h
MAINTAINERS +7 -0
index eacb99ed25b8..9fa1474bbdce 100644
@@ -5943,6 +5943,13 @@ F:	scripts/gcc-plugin.sh
 F:	scripts/Makefile.gcc-plugins
 F:	Documentation/gcc-plugins.txt
 
+GASKET DRIVER FRAMEWORK
+M:	Rob Springer <[email protected]>
+M:	John Joseph <[email protected]>
+M:	Ben Chan <[email protected]>
+S:	Maintained
+F:	drivers/staging/gasket/
+
 GCOV BASED KERNEL PROFILING
 M:	Peter Oberparleiter <[email protected]>
 S:	Maintained
drivers/staging/Kconfig +2 -0
index 75a480497d22..fca7388e84d9 100644
@@ -126,4 +126,6 @@ source "drivers/staging/mt7621-eth/Kconfig"
 
 source "drivers/staging/mt7621-dts/Kconfig"
 
+source "drivers/staging/gasket/Kconfig"
+
 endif # STAGING
drivers/staging/Makefile +1 -0
index e84959a8a684..1a2fb7ad4287 100644
@@ -54,3 +54,4 @@ obj-$(CONFIG_SOC_MT7621)	+= mt7621-dma/
 obj-$(CONFIG_SOC_MT7621)	+= mt7621-mmc/
 obj-$(CONFIG_SOC_MT7621)	+= mt7621-eth/
 obj-$(CONFIG_SOC_MT7621)	+= mt7621-dts/
+obj-$(CONFIG_STAGING_GASKET_FRAMEWORK)	+= gasket/
drivers/staging/gasket/Kconfig new file +23 -0
new file mode 100644
index 000000000000..3465e8510fc2
@@ -0,0 +1,23 @@
+menu "Gasket devices"
+
+config STAGING_GASKET_FRAMEWORK
+	tristate "Gasket framework"
+	depends on PCI
+	help
+		This framework supports Gasket-compatible devices, such as Apex.
+		It is required for either of those modules.
+
+		To compile this driver as a module, choose M here.  The module
+		will be called "gasket".
+
+config STAGING_APEX_DRIVER
+	tristate "Apex Driver"
+	depends on STAGING_GASKET_FRAMEWORK
+	help
+		This driver supports the Apex device.  Say Y if you want to
+		include this driver in the kernel.
+
+		To compile this driver as a module, choose M here.  The module
+		will be called "apex".
+
+endmenu
drivers/staging/gasket/Makefile new file +9 -0
new file mode 100644
index 000000000000..cec813ece678
@@ -0,0 +1,9 @@
+#
+#  Makefile for Gasket framework and dependent drivers.
+#
+
+obj-$(CONFIG_STAGING_GASKET_FRAMEWORK)	+= gasket.o
+obj-$(CONFIG_STAGING_APEX_DRIVER)	+= apex.o
+
+gasket-objs	:= gasket_core.o gasket_ioctl.o gasket_interrupt.o gasket_page_table.o gasket_sysfs.o
+apex-objs	:= apex_driver.o
drivers/staging/gasket/TODO new file +17 -0
new file mode 100644
index 000000000000..0d8ee9602c80
@@ -0,0 +1,17 @@
+This is a list of things that need to be done to get this driver out of the
+staging directory.
+- Use SPDX tags to show the license of the file, and no more "boiler-plate"
+  license text is needed.
+- Remove static function declarations.
+- Document sysfs files with Documentation/ABI/ entries.
+- Use misc interface instead of major number for driver version description.
+- Add descriptions of module_param's
+- Remove gasket-specific logging functions.
+- apex_get_status() should actually check status.
+- Static functions don't need kernel doc formatting, can be simplified.
+- Fix multi-line alignment formatting to look like:
+      int ret = long_function_name(device, VARIABLE1, VARIABLE2,
+                                   VARIABLE3, VARIABLE4);
+- "drivers" should never be dealing with "raw" sysfs calls or mess around with
+  kobjects at all. The driver core should handle all of this for you
+  automaically. There should not be a need for raw attribute macros.
drivers/staging/gasket/apex.h new file +95 -0

95 lines not on this page · raw message

drivers/staging/gasket/apex_driver.c new file +771 -0

771 lines not on this page · raw message

drivers/staging/gasket/gasket.h new file +129 -0

129 lines not on this page · raw message

drivers/staging/gasket/gasket_constants.h new file +56 -0

56 lines not on this page · raw message

drivers/staging/gasket/gasket_core.c new file +2157 -0

1,877 lines not on this page · raw message

drivers/staging/gasket/gasket_core.h new file +719 -0

719 lines not on this page · raw message

drivers/staging/gasket/gasket_interrupt.c new file +638 -0

638 lines not on this page · raw message

drivers/staging/gasket/gasket_interrupt.h new file +172 -0

172 lines not on this page · raw message

drivers/staging/gasket/gasket_ioctl.c new file +449 -0

449 lines not on this page · raw message

drivers/staging/gasket/gasket_ioctl.h new file +35 -0
new file mode 100644
index 000000000000..df868000c803

Lines of this file are not shown. View the raw message.

drivers/staging/gasket/gasket_logging.h new file +71 -0

71 lines not on this page · raw message

drivers/staging/gasket/gasket_page_table.c new file +1771 -0

1,771 lines not on this page · raw message

drivers/staging/gasket/gasket_page_table.h new file +265 -0

265 lines not on this page · raw message

drivers/staging/gasket/gasket_sysfs.c new file +497 -0

497 lines not on this page · raw message

drivers/staging/gasket/gasket_sysfs.h new file +199 -0

199 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.18.0.399.gad0ab374a1-goog

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 6 lines · Simon Que
drivers/staging/gasket/Kconfig new file +0 -0
new file mode 100644
index 000000000000..3465e8510fc2

drivers/staging/gasket/Kconfig line 8

Quoted 8 lines
drivers/staging/gasket/Kconfig new file +8 -0
@@ -0,0 +1,23 @@
+menu "Gasket devices"
+
+config STAGING_GASKET_FRAMEWORK
+	tristate "Gasket framework"
+	depends on PCI
+	help
+		This framework supports Gasket-compatible devices, such as Apex.
+		It is required for either of those modules.

Either of what modules?
Maybe "for any of those modules." ?

Also, Kconfig help text indentation is (from Documentation/process/coding-style.rst):

Lines under a ``config`` definition are indented with one tab, while help text is indented an additional two spaces.

so one tab + 2 spaces, please, above and below here.

Quoted 15 lines
drivers/staging/gasket/Kconfig new file +15 -0
+
+		To compile this driver as a module, choose M here.  The module
+		will be called "gasket".
+
+config STAGING_APEX_DRIVER
+	tristate "Apex Driver"
+	depends on STAGING_GASKET_FRAMEWORK
+	help
+		This driver supports the Apex device.  Say Y if you want to
+		include this driver in the kernel.
+
+		To compile this driver as a module, choose M here.  The module
+		will be called "apex".
+
+endmenu
Signature · 1 line
~Randy
#2 lore raw
In reply to Simon Que
Thank you for the patch! Yet something to improve:

Hi Simon,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on staging/staging-testing]
[also build test ERROR on v4.18-rc2 next-20180629]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Simon-Que/drivers-staging-Gasket-driver-framework-Apex-driver/20180630-080504
config: i386-allmodconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

In file included from drivers/staging/gasket/gasket_core.c:16:0:
drivers/staging/gasket/gasket_core.h: In function 'gasket_dev_read_64':

>> drivers/staging/gasket/gasket_core.h:658:9: error: implicit declaration of function 'readq'; did you mean 'readl'? [-Werror=implicit-function-declaration]
     return readq(&gasket_dev->bar_data[bar].virt_base[location]);
            ^~~~~
            readl
   drivers/staging/gasket/gasket_core.h: In function 'gasket_dev_write_64':
   drivers/staging/gasket/gasket_core.h:664:2: error: implicit declaration of function 'writeq'; did you mean 'writel'? [-Werror=implicit-function-declaration]
     writeq(value, &dev->bar_data[bar].virt_base[location]);
     ^~~~~~
     writel

cc1: some warnings being treated as errors
--
In file included from drivers/staging/gasket/gasket_ioctl.h:15:0,
from drivers/staging/gasket/gasket_ioctl.c:13:
drivers/staging/gasket/gasket_core.h: In function 'gasket_dev_read_64':

>> drivers/staging/gasket/gasket_core.h:658:9: error: implicit declaration of function 'readq'; did you mean 'readl'? [-Werror=implicit-function-declaration]
     return readq(&gasket_dev->bar_data[bar].virt_base[location]);
            ^~~~~
            readl
   drivers/staging/gasket/gasket_core.h: In function 'gasket_dev_write_64':
   drivers/staging/gasket/gasket_core.h:664:2: error: implicit declaration of function 'writeq'; did you mean 'writel'? [-Werror=implicit-function-declaration]
     writeq(value, &dev->bar_data[bar].virt_base[location]);
     ^~~~~~
     writel

drivers/staging/gasket/gasket_ioctl.c: In function 'gasket_config_coherent_allocator':
drivers/staging/gasket/gasket_ioctl.c:442:27: error: passing argument 3 of 'gasket_alloc_coherent_memory' from incompatible pointer type [-Werror=incompatible-pointer-types]
gasket_dev, ibuf.size, &ibuf.dma_address,
^
In file included from drivers/staging/gasket/gasket_ioctl.c:18:0:
drivers/staging/gasket/gasket_page_table.h:240:5: note: expected 'dma_addr_t * {aka unsigned int *}' but argument is of type 'u64 * {aka long long unsigned int *}'
int gasket_alloc_coherent_memory(struct gasket_dev *gasket_dev, uint64_t size,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
--
In file included from drivers/staging/gasket/gasket_page_table.h:26:0,
from drivers/staging/gasket/gasket_page_table.c:41:
drivers/staging/gasket/gasket_core.h: In function 'gasket_dev_read_64':

>> drivers/staging/gasket/gasket_core.h:658:9: error: implicit declaration of function 'readq'; did you mean 'readl'? [-Werror=implicit-function-declaration]
     return readq(&gasket_dev->bar_data[bar].virt_base[location]);
            ^~~~~
            readl
   drivers/staging/gasket/gasket_core.h: In function 'gasket_dev_write_64':
   drivers/staging/gasket/gasket_core.h:664:2: error: implicit declaration of function 'writeq'; did you mean 'writel'? [-Werror=implicit-function-declaration]
     writeq(value, &dev->bar_data[bar].virt_base[location]);
     ^~~~~~
     writel
   drivers/staging/gasket/gasket_page_table.c: In function 'gasket_is_extended_dev_addr_bad':
   drivers/staging/gasket/gasket_page_table.c:1388:11: warning: right shift count >= width of type [-Wshift-count-overflow]
     if (addr >> (GASKET_EXTENDED_LVL0_WIDTH + GASKET_EXTENDED_LVL0_SHIFT)) {
              ^~
   drivers/staging/gasket/gasket_page_table.c: In function 'gasket_alloc_coherent_memory':
   drivers/staging/gasket/gasket_page_table.c:1694:4: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
       (u64)mem + j * PAGE_SIZE;
       ^

cc1: some warnings being treated as errors

vim +658 drivers/staging/gasket/gasket_core.h

627
628 /*
629 * Memory management functions. These will likely be spun off into their own
630 * file in the future.
631 */
632
633 /* Unmaps the specified mappable region from a VMA. */
634 int gasket_mm_unmap_region(
635 const struct gasket_dev *gasket_dev, struct vm_area_struct *vma,
636 const struct gasket_mappable_region *map_region);
637
638 /*
639 * Get the ioctl permissions callback.
640 * @gasket_dev: Gasket device structure.
641 */
642 gasket_ioctl_permissions_cb_t gasket_get_ioctl_permissions_cb(
643 struct gasket_dev *gasket_dev);
644
645 /**
646 * Lookup a name by number in a num_name table.
647 * @num: Number to lookup.
648 * @table: Array of num_name structures, the table for the lookup.
649 *
650 */
651 const char *gasket_num_name_lookup(
652 uint num, const struct gasket_num_name *table);
653
654 /* Handy inlines */
655 static inline ulong gasket_dev_read_64(
656 struct gasket_dev *gasket_dev, int bar, ulong location)
657 {

 > 658		return readq(&gasket_dev->bar_data[bar].virt_base[location]);

659 }
660

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation