Skip to contentSkip to conversation

drivers/staging: Gasket driver framework + Apex driver

PATCH In review Simon Que 3 participants 3 messages Jun 30, 2018 Staging

lore
Share & tools
lore

Simon Que

author
#0 lore raw

PATCH v7 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. [PATCH v7]
- Added Kconfig dependency on X86_64.
- Updated Kconfig help text indentation to tab + 2 spaces.

---
 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..c836389c1402
@@ -0,0 +1,23 @@
+menu "Gasket devices"
+
+config STAGING_GASKET_FRAMEWORK
+	tristate "Gasket framework"
+	depends on PCI && X86_64
+	help
+	  This framework supports Gasket-compatible devices, such as Apex.
+	  It is required for any of the following module(s).
+
+	  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

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.

[]

Quoted 6 lines

[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.

Why delete all the logging by adding if (false} tests and then not mention it?

#2 lore raw
In reply to Simon Que
Quoted 6 lines

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.

So it seems to me that we shouldn't have one random layer for Google ASIC, another chunk of code for FPGA and so on. This all really ought to be unified including where possible making things meaningfully self describe.

You also don't seem to consider partitioning of an ASIC, eg if it implements a serial port abstraction for debug that ought to routed to the kernel, nor how to handle an ASIC that provides services to multiple consumers ?

Quoted 3 lines

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

Why ? That's a very un-Linuxlike and un-Unixlike model. It's more like Windows and with all the problems we know that model causes.

Quoted 2 lines

any number of additional write handles.) This is accomplished by tracking open and close data for each driver instance.

What if I want to have multiple threads not sharing an mm, or pass an ASIC by handle to another instance - eg if I have a master process assigning resources wanting to pass a handle into a container ?

And what about fd passing ?

It seems completely weird to try and do this given I can (given permissions) equally just ptrace the person with it open and use ptrace as a multiplexor ???

Also how about pointers to a real world use case example and user space ?

Alan