staging: gasket: remove it from the kernel
[email protected]
maintainerPATCH 1/1 staging: gasket: remove it from the kernel
From: Greg Kroah-Hartman <[email protected]>
As none of the proposed things that need to be changed in the gasket drivers have ever been done, and there has not been any forward progress to get this out of staging, it seems totally abandonded so remove the code entirely so that people do not spend their time doing tiny cleanups for code that will never get out of staging.
If this code is actually being used, it can be reverted simply and then cleaned up properly, but as it is abandoned, let's just get rid of it.
--- MAINTAINERS | 8 - drivers/staging/Kconfig | 2 - drivers/staging/Makefile | 1 - drivers/staging/gasket/Kconfig | 25 - drivers/staging/gasket/Makefile | 10 - drivers/staging/gasket/TODO | 22 - drivers/staging/gasket/apex.h | 30 - drivers/staging/gasket/apex_driver.c | 726 -------- drivers/staging/gasket/gasket.h | 122 -- drivers/staging/gasket/gasket_constants.h | 44 - drivers/staging/gasket/gasket_core.c | 1815 -------------------- drivers/staging/gasket/gasket_core.h | 638 ------- drivers/staging/gasket/gasket_interrupt.c | 515 ------ drivers/staging/gasket/gasket_interrupt.h | 95 - drivers/staging/gasket/gasket_ioctl.c | 388 ----- drivers/staging/gasket/gasket_ioctl.h | 28 - drivers/staging/gasket/gasket_page_table.c | 1357 --------------- drivers/staging/gasket/gasket_page_table.h | 249 --- drivers/staging/gasket/gasket_sysfs.c | 398 ----- drivers/staging/gasket/gasket_sysfs.h | 175 -- 20 files changed, 6648 deletions(-) delete mode 100644 drivers/staging/gasket/Kconfig delete mode 100644 drivers/staging/gasket/Makefile delete mode 100644 drivers/staging/gasket/TODO delete mode 100644 drivers/staging/gasket/apex.h delete mode 100644 drivers/staging/gasket/apex_driver.c delete mode 100644 drivers/staging/gasket/gasket.h delete mode 100644 drivers/staging/gasket/gasket_constants.h delete mode 100644 drivers/staging/gasket/gasket_core.c delete mode 100644 drivers/staging/gasket/gasket_core.h delete mode 100644 drivers/staging/gasket/gasket_interrupt.c delete mode 100644 drivers/staging/gasket/gasket_interrupt.h delete mode 100644 drivers/staging/gasket/gasket_ioctl.c delete mode 100644 drivers/staging/gasket/gasket_ioctl.h delete mode 100644 drivers/staging/gasket/gasket_page_table.c delete mode 100644 drivers/staging/gasket/gasket_page_table.h delete mode 100644 drivers/staging/gasket/gasket_sysfs.c delete mode 100644 drivers/staging/gasket/gasket_sysfs.h
MAINTAINERS +0 -8
@@ -7385,14 +7385,6 @@ F: Documentation/hwmon/gsc-hwmon.rst F: drivers/hwmon/gsc-hwmon.c F: include/linux/platform_data/gsc_hwmon.h -GASKET DRIVER FRAMEWORK -M: Rob Springer <[email protected]> -M: Todd Poynor <[email protected]> -M: Ben Chan <[email protected]> -M: Richard Yeh <[email protected]> -S: Maintained -F: drivers/staging/gasket/ - GCC PLUGINS M: Kees Cook <[email protected]> L: [email protected]
drivers/staging/Kconfig +0 -2
@@ -98,8 +98,6 @@ source "drivers/staging/ralink-gdma/Kconfig" source "drivers/staging/mt7621-dts/Kconfig" -source "drivers/staging/gasket/Kconfig" - source "drivers/staging/axis-fifo/Kconfig" source "drivers/staging/fieldbus/Kconfig"
drivers/staging/Makefile +0 -1
@@ -39,7 +39,6 @@ obj-$(CONFIG_PCI_MT7621) += mt7621-pci/ obj-$(CONFIG_SOC_MT7621) += mt7621-dma/ obj-$(CONFIG_DMA_RALINK) += ralink-gdma/ obj-$(CONFIG_SOC_MT7621) += mt7621-dts/ -obj-$(CONFIG_STAGING_GASKET_FRAMEWORK) += gasket/ obj-$(CONFIG_XIL_AXIS_FIFO) += axis-fifo/ obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/ obj-$(CONFIG_KPC2000) += kpc2000/
drivers/staging/gasket/Kconfig deleted +0 -25
@@ -1,25 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -menu "Gasket devices" - -config STAGING_GASKET_FRAMEWORK - tristate "Gasket framework" - depends on PCI && (X86_64 || ARM64) - 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 Edge TPU device. See - https://cloud.google.com/edge-tpu/ for more information. - 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 deleted +0 -10
@@ -1,10 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# 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 deleted +0 -22
@@ -1,22 +0,0 @@ -This is a list of things that need to be done to get this driver out of the -staging directory. - -- Implement the gasket framework's functionality through UIO instead of - introducing a new user-space drivers framework that is quite similar. - - UIO provides the necessary bits to implement user-space drivers. Meanwhile - the gasket APIs adds some extra conveniences like PCI BAR mapping, and - MSI interrupts. Add these features to the UIO subsystem, then re-implement - the Apex driver as a basic UIO driver instead (include/linux/uio_driver.h) - -- Document sysfs files with Documentation/ABI/ entries. - -- Use misc interface instead of major number for driver version description. - -- Add descriptions of module_param's - -- apex_get_status() should actually check status. - -- "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 deleted +0 -30
@@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* Apex kernel-userspace interface definitions. -* -* Copyright (C) 2018 Google, Inc. -*/ -#ifndef __APEX_H__ -#define __APEX_H__ - -#include <linux/ioctl.h> - -/* Clock Gating ioctl. */ -struct apex_gate_clock_ioctl { -/* Enter or leave clock gated state. */ -u64 enable; - -/* If set, enter clock gating state, regardless of custom block's -* internal idle state -*/ -u64 force_idle; -}; - -/* Base number for all Apex-common IOCTLs */ -#define APEX_IOCTL_BASE 0x7F - -/* Enable/Disable clock gating. */ -#define APEX_IOCTL_GATE_CLOCK \ - _IOW(APEX_IOCTL_BASE, 0, struct apex_gate_clock_ioctl) - -#endif /* __APEX_H__ */
drivers/staging/gasket/apex_driver.c deleted +0 -726
726 lines not on this page · raw message
drivers/staging/gasket/gasket.h deleted +0 -122
122 lines not on this page · raw message
drivers/staging/gasket/gasket_constants.h deleted +0 -44
44 lines not on this page · raw message
drivers/staging/gasket/gasket_core.c deleted +0 -1815
1,815 lines not on this page · raw message
drivers/staging/gasket/gasket_core.h deleted +0 -638
177 lines not on this page · raw message
drivers/staging/gasket/gasket_interrupt.c deleted +0 -515
515 lines not on this page · raw message
drivers/staging/gasket/gasket_interrupt.h deleted +0 -95
95 lines not on this page · raw message
drivers/staging/gasket/gasket_ioctl.c deleted +0 -388
388 lines not on this page · raw message
drivers/staging/gasket/gasket_ioctl.h deleted +0 -28
Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_page_table.c deleted +0 -1357
1,357 lines not on this page · raw message
drivers/staging/gasket/gasket_page_table.h deleted +0 -249
249 lines not on this page · raw message
drivers/staging/gasket/gasket_sysfs.c deleted +0 -398
398 lines not on this page · raw message
drivers/staging/gasket/gasket_sysfs.h deleted +0 -175
175 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.30.2
Part of the diff is not shown here. View the raw message.
Quoted 7,370 lines · On Mon, Mar 15, 2021 at 8:44 AM <[email protected]> wrote:
From: Greg Kroah-Hartman <[email protected]>
As none of the proposed things that need to be changed in the gasket drivers have ever been done, and there has not been any forward progress to get this out of staging, it seems totally abandonded so remove the code entirely so that people do not spend their time doing tiny cleanups for code that will never get out of staging.
If this code is actually being used, it can be reverted simply and then cleaned up properly, but as it is abandoned, let's just get rid of it.
Cc Rob Springer <[email protected]>Cc Todd Poynor <[email protected]>Cc Ben Chan <[email protected]>Cc Richard Yeh <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- MAINTAINERS | 8 - drivers/staging/Kconfig | 2 - drivers/staging/Makefile | 1 - drivers/staging/gasket/Kconfig | 25 - drivers/staging/gasket/Makefile | 10 - drivers/staging/gasket/TODO | 22 - drivers/staging/gasket/apex.h | 30 - drivers/staging/gasket/apex_driver.c | 726 -------- drivers/staging/gasket/gasket.h | 122 -- drivers/staging/gasket/gasket_constants.h | 44 - drivers/staging/gasket/gasket_core.c | 1815 -------------------- drivers/staging/gasket/gasket_core.h | 638 ------- drivers/staging/gasket/gasket_interrupt.c | 515 ------ drivers/staging/gasket/gasket_interrupt.h | 95 - drivers/staging/gasket/gasket_ioctl.c | 388 ----- drivers/staging/gasket/gasket_ioctl.h | 28 - drivers/staging/gasket/gasket_page_table.c | 1357 --------------- drivers/staging/gasket/gasket_page_table.h | 249 --- drivers/staging/gasket/gasket_sysfs.c | 398 ----- drivers/staging/gasket/gasket_sysfs.h | 175 -- 20 files changed, 6648 deletions(-) delete mode 100644 drivers/staging/gasket/Kconfig delete mode 100644 drivers/staging/gasket/Makefile delete mode 100644 drivers/staging/gasket/TODO delete mode 100644 drivers/staging/gasket/apex.h delete mode 100644 drivers/staging/gasket/apex_driver.c delete mode 100644 drivers/staging/gasket/gasket.h delete mode 100644 drivers/staging/gasket/gasket_constants.h delete mode 100644 drivers/staging/gasket/gasket_core.c delete mode 100644 drivers/staging/gasket/gasket_core.h delete mode 100644 drivers/staging/gasket/gasket_interrupt.c delete mode 100644 drivers/staging/gasket/gasket_interrupt.h delete mode 100644 drivers/staging/gasket/gasket_ioctl.c delete mode 100644 drivers/staging/gasket/gasket_ioctl.h delete mode 100644 drivers/staging/gasket/gasket_page_table.c delete mode 100644 drivers/staging/gasket/gasket_page_table.h delete mode 100644 drivers/staging/gasket/gasket_sysfs.c delete mode 100644 drivers/staging/gasket/gasket_sysfs.hMAINTAINERS +0
-8@@ -7385,14 +7385,6 @@ F: Documentation/hwmon/gsc-hwmon.rst F: drivers/hwmon/gsc-hwmon.c F: include/linux/platform_data/gsc_hwmon.h -GASKET DRIVER FRAMEWORK -M: Rob Springer <[email protected]> -M: Todd Poynor <[email protected]> -M: Ben Chan <[email protected]> -M: Richard Yeh <[email protected]> -S: Maintained -F: drivers/staging/gasket/ - GCC PLUGINS M: Kees Cook <[email protected]> L: [email protected]drivers/staging/Kconfig +0
-2@@ -98,8 +98,6 @@ source "drivers/staging/ralink-gdma/Kconfig" source "drivers/staging/mt7621-dts/Kconfig" -source "drivers/staging/gasket/Kconfig" - source "drivers/staging/axis-fifo/Kconfig" source "drivers/staging/fieldbus/Kconfig"drivers/staging/Makefile +0
-1@@ -39,7 +39,6 @@ obj-$(CONFIG_PCI_MT7621) += mt7621-pci/ obj-$(CONFIG_SOC_MT7621) += mt7621-dma/ obj-$(CONFIG_DMA_RALINK) += ralink-gdma/ obj-$(CONFIG_SOC_MT7621) += mt7621-dts/ -obj-$(CONFIG_STAGING_GASKET_FRAMEWORK) += gasket/ obj-$(CONFIG_XIL_AXIS_FIFO) += axis-fifo/ obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/ obj-$(CONFIG_KPC2000) += kpc2000/drivers/staging/gasket/Kconfig deleted +0
-25@@ -1,25 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -menu "Gasket devices" - -config STAGING_GASKET_FRAMEWORK - tristate "Gasket framework" - depends on PCI && (X86_64 || ARM64) - 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 Edge TPU device. See - https://cloud.google.com/edge-tpu/ for more information. - 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". - -endmenudrivers/staging/gasket/Makefile deleted +0
-9@@ -1,10 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# 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.ogasket_page_table.o gasket_sysfs.o
drivers/staging/gasket/Makefile deleted +0
-1-apex-objs := apex_driver.odrivers/staging/gasket/TODO deleted +0
-1@@ -1,22 +0,0 @@ -This is a list of things that need to be done to get this driver out ofthe
drivers/staging/gasket/TODO deleted +0
-6-staging directory. - -- Implement the gasket framework's functionality through UIO instead of - introducing a new user-space drivers framework that is quite similar. - - UIO provides the necessary bits to implement user-space drivers.Meanwhile
drivers/staging/gasket/TODO deleted +0
-2- the gasket APIs adds some extra conveniences like PCI BAR mapping, and - MSI interrupts. Add these features to the UIO subsystem, thenre-implement
- the Apex driver as a basic UIO driver instead
(include/linux/uio_driver.h)drivers/staging/gasket/TODO deleted +0
-4- -- Document sysfs files with Documentation/ABI/ entries. - -- Use misc interface instead of major number for driver versiondescription.
drivers/staging/gasket/TODO deleted +0
-6- -- Add descriptions of module_param's - -- apex_get_status() should actually check status. - -- "drivers" should never be dealing with "raw" sysfs calls or mess aroundwith
drivers/staging/gasket/TODO deleted +0
-2- 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 deleted +0
-30@@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* Apex kernel-userspace interface definitions. -* -* Copyright (C) 2018 Google, Inc. -*/ -#ifndef __APEX_H__ -#define __APEX_H__ - -#include <linux/ioctl.h> - -/* Clock Gating ioctl. */ -struct apex_gate_clock_ioctl { -/* Enter or leave clock gated state. */ -u64 enable; - -/* If set, enter clock gating state, regardless of custom block's -* internal idle state -*/ -u64 force_idle; -}; - -/* Base number for all Apex-common IOCTLs */ -#define APEX_IOCTL_BASE 0x7F - -/* Enable/Disable clock gating. */ -#define APEX_IOCTL_GATE_CLOCK \ - _IOW(APEX_IOCTL_BASE, 0, struct apex_gate_clock_ioctl) - -#endif /* __APEX_H__ */ drivers/staging/gasket/apex_driver.c deleted +0
-53@@ -1,726 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* Driver for the Apex chip. -* -* Copyright (C) 2018 Google, Inc. -*/ - -#include <linux/compiler.h> -#include <linux/delay.h> -#include <linux/device.h> -#include <linux/fs.h> -#include <linux/init.h> -#include <linux/mm.h> -#include <linux/module.h> -#include <linux/moduleparam.h> -#include <linux/pci.h> -#include <linux/printk.h> -#include <linux/sched.h> -#include <linux/uaccess.h> - -#include "apex.h" - -#include "gasket_core.h" -#include "gasket_interrupt.h" -#include "gasket_page_table.h" -#include "gasket_sysfs.h" - -/* Constants */ -#define APEX_DEVICE_NAME "Apex" -#define APEX_DRIVER_VERSION "1.0" - -/* CSRs are in BAR 2. */ -#define APEX_BAR_INDEX 2 - -#define APEX_PCI_VENDOR_ID 0x1ac1 -#define APEX_PCI_DEVICE_ID 0x089a - -/* Bar Offsets. */ -#define APEX_BAR_OFFSET 0 -#define APEX_CM_OFFSET 0x1000000 - -/* The sizes of each Apex BAR 2. */ -#define APEX_BAR_BYTES 0x100000 -#define APEX_CH_MEM_BYTES (PAGE_SIZE * MAX_NUM_COHERENT_PAGES) - -/* The number of user-mappable memory ranges in BAR2 of a Apex chip. */ -#define NUM_REGIONS 3 - -/* The number of nodes in a Apex chip. */ -#define NUM_NODES 1 - -/* -* The total number of entries in the page table. Should match the value read
- * from the registerAPEX_BAR2_REG_KERNEL_HIB_PAGE_TABLE_SIZE.
- */drivers/staging/gasket/apex_driver.c deleted +0
-68-#define APEX_PAGE_TABLE_TOTAL_ENTRIES 8192 - -#define APEX_EXTENDED_SHIFT 63/* Extended address bit position. */ - -/* Check reset 120 times */ -#define APEX_RESET_RETRY 120 -/* Wait 100 ms between checks. Total 12 sec wait maximum. */ -#define APEX_RESET_DELAY 100 - -/* Enumeration of the supported sysfs entries. */ -enum sysfs_attribute_type { -ATTR_KERNEL_HIB_PAGE_TABLE_SIZE , -ATTR_KERNEL_HIB_SIMPLE_PAGE_TABLE_SIZE , -ATTR_KERNEL_HIB_NUM_ACTIVE_PAGES , -}; - -/* -* Register offsets into BAR2 memory. -* Only values necessary for driver implementation are defined. -*/ -enum apex_bar2_regs { -APEX_BAR2_REG_SCU_BASE =0x1A300 , -APEX_BAR2_REG_KERNEL_HIB_PAGE_TABLE_SIZE =0x46000 , -APEX_BAR2_REG_KERNEL_HIB_EXTENDED_TABLE =0x46008 , -APEX_BAR2_REG_KERNEL_HIB_TRANSLATION_ENABLE =0x46010 , -APEX_BAR2_REG_KERNEL_HIB_INSTR_QUEUE_INTVECCTL =0x46018 , -APEX_BAR2_REG_KERNEL_HIB_INPUT_ACTV_QUEUE_INTVECCTL =0x46020 , -APEX_BAR2_REG_KERNEL_HIB_PARAM_QUEUE_INTVECCTL =0x46028 , -APEX_BAR2_REG_KERNEL_HIB_OUTPUT_ACTV_QUEUE_INTVECCTL =0x46030 , -APEX_BAR2_REG_KERNEL_HIB_SC_HOST_INTVECCTL =0x46038 , -APEX_BAR2_REG_KERNEL_HIB_TOP_LEVEL_INTVECCTL =0x46040 , -APEX_BAR2_REG_KERNEL_HIB_FATAL_ERR_INTVECCTL =0x46048 , -APEX_BAR2_REG_KERNEL_HIB_DMA_PAUSE =0x46050 , -APEX_BAR2_REG_KERNEL_HIB_DMA_PAUSE_MASK =0x46058 , -APEX_BAR2_REG_KERNEL_HIB_STATUS_BLOCK_DELAY =0x46060 , -APEX_BAR2_REG_KERNEL_HIB_MSIX_PENDING_BIT_ARRAY0 =0x46068 , -APEX_BAR2_REG_KERNEL_HIB_MSIX_PENDING_BIT_ARRAY1 =0x46070 , -APEX_BAR2_REG_KERNEL_HIB_PAGE_TABLE_INIT =0x46078 , -APEX_BAR2_REG_KERNEL_HIB_MSIX_TABLE_INIT =0x46080 , -APEX_BAR2_REG_KERNEL_WIRE_INT_PENDING_BIT_ARRAY =0x48778 , -APEX_BAR2_REG_KERNEL_WIRE_INT_MASK_ARRAY =0x48780 , -APEX_BAR2_REG_USER_HIB_DMA_PAUSE =0x486D8 , -APEX_BAR2_REG_USER_HIB_DMA_PAUSED =0x486E0 , -APEX_BAR2_REG_IDLEGENERATOR_IDLEGEN_IDLEREGISTER =0x4A000 , -APEX_BAR2_REG_KERNEL_HIB_PAGE_TABLE =0x50000 , - -/* Error registers - Used mostly for debug */ -APEX_BAR2_REG_USER_HIB_ERROR_STATUS =0x86f0 , -APEX_BAR2_REG_SCALAR_CORE_ERROR_STATUS =0x41a0 , -}; - -/* Addresses for packed registers. */ -#define APEX_BAR2_REG_AXI_QUIESCE (APEX_BAR2_REG_SCU_BASE + 0x2C) -#define APEX_BAR2_REG_GCB_CLOCK_GATE (APEX_BAR2_REG_SCU_BASE + 0x14) -#define APEX_BAR2_REG_SCU_0 (APEX_BAR2_REG_SCU_BASE + 0xc) -#define APEX_BAR2_REG_SCU_1 (APEX_BAR2_REG_SCU_BASE + 0x10) -#define APEX_BAR2_REG_SCU_2 (APEX_BAR2_REG_SCU_BASE + 0x14) -#define APEX_BAR2_REG_SCU_3 (APEX_BAR2_REG_SCU_BASE + 0x18) -#define APEX_BAR2_REG_SCU_4 (APEX_BAR2_REG_SCU_BASE + 0x1c) -#define APEX_BAR2_REG_SCU_5 (APEX_BAR2_REG_SCU_BASE + 0x20) - -#define SCU3_RG_PWR_STATE_OVR_BIT_OFFSET 26 -#define SCU3_RG_PWR_STATE_OVR_MASK_WIDTH 2 -#define SCU3_CUR_RST_GCB_BIT_MASK 0x10 -#define SCU2_RG_RST_GCB_BIT_MASK 0xc - -/* Configuration for page table. */ -static struct gasket_page_table_config apex_page_table_configs[NUM_NODES ]= {
drivers/staging/gasket/apex_driver.c deleted +0
-12- { - .id = 0, - .mode = GASKET_PAGE_TABLE_MODE_NORMAL, - .total_entries = APEX_PAGE_TABLE_TOTAL_ENTRIES, - .base_reg = APEX_BAR2_REG_KERNEL_HIB_PAGE_TABLE, - .extended_reg = APEX_BAR2_REG_KERNEL_HIB_EXTENDED_TABLE, - .extended_bit = APEX_EXTENDED_SHIFT, - }, -}; - -/* The regions in the BAR2 space that can be mapped into user space. */ -static const struct gasket_mappable_region mappable_regions[NUM_REGIONS ]= {
drivers/staging/gasket/apex_driver.c deleted +0
-111- { 0x40000, 0x1000 }, - { 0x44000, 0x1000 }, - { 0x48000, 0x1000 }, -}; - -/* Gasket device interrupts enums must be dense (i.e., no empty slots). */ -enum apex_interrupt { -APEX_INTERRUPT_INSTR_QUEUE =0 , -APEX_INTERRUPT_INPUT_ACTV_QUEUE =1 , -APEX_INTERRUPT_PARAM_QUEUE =2 , -APEX_INTERRUPT_OUTPUT_ACTV_QUEUE =3 , -APEX_INTERRUPT_SC_HOST_0 =4 , -APEX_INTERRUPT_SC_HOST_1 =5 , -APEX_INTERRUPT_SC_HOST_2 =6 , -APEX_INTERRUPT_SC_HOST_3 =7 , -APEX_INTERRUPT_TOP_LEVEL_0 =8 , -APEX_INTERRUPT_TOP_LEVEL_1 =9 , -APEX_INTERRUPT_TOP_LEVEL_2 =10 , -APEX_INTERRUPT_TOP_LEVEL_3 =11 , -APEX_INTERRUPT_FATAL_ERR =12 , -APEX_INTERRUPT_COUNT =13 , -}; - -/* Interrupt descriptors for Apex */ -static struct gasket_interrupt_desc apex_interrupts[] = { - { -APEX_INTERRUPT_INSTR_QUEUE , -APEX_BAR2_REG_KERNEL_HIB_INSTR_QUEUE_INTVECCTL , -UNPACKED , - }, - { -APEX_INTERRUPT_INPUT_ACTV_QUEUE , -APEX_BAR2_REG_KERNEL_HIB_INPUT_ACTV_QUEUE_INTVECCTL , -UNPACKED - }, - { -APEX_INTERRUPT_PARAM_QUEUE , -APEX_BAR2_REG_KERNEL_HIB_PARAM_QUEUE_INTVECCTL , -UNPACKED - }, - { -APEX_INTERRUPT_OUTPUT_ACTV_QUEUE , -APEX_BAR2_REG_KERNEL_HIB_OUTPUT_ACTV_QUEUE_INTVECCTL , -UNPACKED - }, - { -APEX_INTERRUPT_SC_HOST_0 , -APEX_BAR2_REG_KERNEL_HIB_SC_HOST_INTVECCTL , -PACK_0 - }, - { -APEX_INTERRUPT_SC_HOST_1 , -APEX_BAR2_REG_KERNEL_HIB_SC_HOST_INTVECCTL , -PACK_1 - }, - { -APEX_INTERRUPT_SC_HOST_2 , -APEX_BAR2_REG_KERNEL_HIB_SC_HOST_INTVECCTL , -PACK_2 - }, - { -APEX_INTERRUPT_SC_HOST_3 , -APEX_BAR2_REG_KERNEL_HIB_SC_HOST_INTVECCTL , -PACK_3 - }, - { -APEX_INTERRUPT_TOP_LEVEL_0 , -APEX_BAR2_REG_KERNEL_HIB_TOP_LEVEL_INTVECCTL , -PACK_0 - }, - { -APEX_INTERRUPT_TOP_LEVEL_1 , -APEX_BAR2_REG_KERNEL_HIB_TOP_LEVEL_INTVECCTL , -PACK_1 - }, - { -APEX_INTERRUPT_TOP_LEVEL_2 , -APEX_BAR2_REG_KERNEL_HIB_TOP_LEVEL_INTVECCTL , -PACK_2 - }, - { -APEX_INTERRUPT_TOP_LEVEL_3 , -APEX_BAR2_REG_KERNEL_HIB_TOP_LEVEL_INTVECCTL , -PACK_3 - }, - { -APEX_INTERRUPT_FATAL_ERR , -APEX_BAR2_REG_KERNEL_HIB_FATAL_ERR_INTVECCTL , -UNPACKED - }, -}; - -/* Allows device to enter power save upon driver close(). */ -static int allow_power_save =1 ; - -/* Allows SW based clock gating. */ -static int allow_sw_clock_gating; - -/* Allows HW based clock gating. */ -/* Note: this is not mutual exclusive with SW clock gating. */ -static int allow_hw_clock_gating =1 ; - -/* Act as if only GCB is instantiated. */ -static int bypass_top_level; - -module_param (allow_power_save, int,0644 ); -module_param (allow_sw_clock_gating, int,0644 ); -module_param (allow_hw_clock_gating, int,0644 ); -module_param (bypass_top_level, int,0644 ); - -/* Check the device status registers and return device status ALIVE or DEAD. */
drivers/staging/gasket/apex_driver.c deleted +0
-29-static int apex_get_status (struct gasket_dev *gasket_dev) -{ -/* TODO: Check device status. */ -return GASKET_STATUS_ALIVE ; -} - -/* Enter GCB reset state. */ -static int apex_enter_reset (struct gasket_dev *gasket_dev) -{ -if (bypass_top_level) -return 0 ; - -/* -* Software reset: -* Enable sleep mode -* - Software force GCB idle -* - Enable GCB idle -*/ -gasket_read_modify_write_64 (gasket_dev,APEX_BAR_INDEX , - APEX_BAR2_REG_IDLEGENERATOR_IDLEGEN_IDLEREGISTER, -0x0 ,1 ,32 ); - -/* - Initiate DMA pause */ -gasket_dev_write_64 (gasket_dev,1 ,APEX_BAR_INDEX , -APEX_BAR2_REG_USER_HIB_DMA_PAUSE ); - -/* - Wait for DMA pause complete. */ - if (gasket_wait_with_reschedule(gasket_dev, APEX_BAR_INDEX, - APEX_BAR2_REG_USER_HIB_DMA_PAUSED,1, 1,
-APEX_RESET_DELAY,APEX_RESET_RETRY)) {drivers/staging/gasket/apex_driver.c deleted +0
-21-dev_err (gasket_dev->dev, -"DMAs did not quiesce within timeout (%d ms)\n" , -APEX_RESET_RETRY *APEX_RESET_DELAY ); -return -ETIMEDOUT ; - } - -/* - Enable GCB reset (0x1 to rg_rst_gcb) */ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_2 ,0x1 ,2 ,2 ); - -/* - Enable GCB clock Gate (0x1 to rg_gated_gcb) */ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_2 ,0x1 ,2 ,18 ); - -/* - Enable GCB memory shut down (0x3 to rg_force_ram_sd) */ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ,0x3 ,2 ,14 ); - -/* - Wait for RAM shutdown. */ - if (gasket_wait_with_reschedule(gasket_dev, APEX_BAR_INDEX, - APEX_BAR2_REG_SCU_3, BIT(6),BIT(6),
-APEX_RESET_DELAY,APEX_RESET_RETRY)) {drivers/staging/gasket/apex_driver.c deleted +0
-46-dev_err (gasket_dev->dev, -"RAM did not shut down within timeout (%d ms)\n" , -APEX_RESET_RETRY *APEX_RESET_DELAY ); -return -ETIMEDOUT ; - } - -return 0 ; -} - -/* Quit GCB reset state. */ -static int apex_quit_reset (struct gasket_dev *gasket_dev) -{ -u32 val0, val1; - -if (bypass_top_level) -return 0 ; - -/* -* Disable sleep mode: -* - Disable GCB memory shut down: -* - b00: Not forced (HW controlled) -* - b1x: Force disable -*/ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ,0x0 ,2 ,14 ); - -/* -* - Disable software clock gate: -* - b00: Not forced (HW controlled) -* - b1x: Force disable -*/ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_2 ,0x0 ,2 ,18 ); - -/* -* - Disable GCB reset (rg_rst_gcb): -* - b00: Not forced (HW controlled) -* - b1x: Force disable = Force not Reset -*/ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_2 ,0x2 ,2 ,2 ); - -/* - Wait for RAM enable. */ - if (gasket_wait_with_reschedule(gasket_dev, APEX_BAR_INDEX, - APEX_BAR2_REG_SCU_3, BIT(6), 0, - APEX_RESET_DELAY,
APEX_RESET_RETRY)) {drivers/staging/gasket/apex_driver.c deleted +0
-11-dev_err (gasket_dev->dev, -"RAM did not enable within timeout (%d ms)\n" , -APEX_RESET_RETRY *APEX_RESET_DELAY ); -return -ETIMEDOUT ; - } - -/* - Wait for Reset complete. */ - if (gasket_wait_with_reschedule(gasket_dev, APEX_BAR_INDEX, - APEX_BAR2_REG_SCU_3, - SCU3_CUR_RST_GCB_BIT_MASK, 0, - APEX_RESET_DELAY,
APEX_RESET_RETRY)) {drivers/staging/gasket/apex_driver.c deleted +0
-19-dev_err (gasket_dev->dev, -"GCB did not leave reset within timeout (%d ms)\n" , -APEX_RESET_RETRY *APEX_RESET_DELAY ); -return -ETIMEDOUT ; - } - -if (!allow_hw_clock_gating) { - val0 =gasket_dev_read_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ); -/* Inactive and Sleep mode are disabled. */ -gasket_read_modify_write_32 (gasket_dev, -APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ,0x3 , -SCU3_RG_PWR_STATE_OVR_MASK_WIDTH , - SCU3_RG_PWR_STATE_OVR_BIT_OFFSET); - val1 =gasket_dev_read_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ); - dev_dbg(gasket_dev->dev, - "Disallow HW clock gating 0x%x -> 0x%x\n", val0,val1);
drivers/staging/gasket/apex_driver.c deleted +0
-11- }else { - val0 =gasket_dev_read_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ); -/* Inactive mode enabled - Sleep mode disabled. */ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ,2 , -SCU3_RG_PWR_STATE_OVR_MASK_WIDTH , - SCU3_RG_PWR_STATE_OVR_BIT_OFFSET); - val1 =gasket_dev_read_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ); - dev_dbg(gasket_dev->dev, "Allow HW clock gating 0x%x ->0x%x\n",
drivers/staging/gasket/apex_driver.c deleted +0
-15- val0, val1); - } - -return 0 ; -} - -/* Reset the Apex hardware. Called on final close via device_close_cb. */ -static int apex_device_cleanup (struct gasket_dev *gasket_dev) -{ -u64 scalar_error; -u64 hib_error; -int ret =0 ; - - hib_error = gasket_dev_read_64(gasket_dev, APEX_BAR_INDEX, -
APEX_BAR2_REG_USER_HIB_ERROR_STATUS);drivers/staging/gasket/apex_driver.c deleted +0
-33- scalar_error =gasket_dev_read_64 (gasket_dev,APEX_BAR_INDEX , - APEX_BAR2_REG_SCALAR_CORE_ERROR_STATUS); - -dev_dbg (gasket_dev->dev, -"%s 0x%p hib_error 0x%llx scalar_error 0x%llx\n" , - __func__, gasket_dev, hib_error, scalar_error); - -if (allow_power_save) - ret =apex_enter_reset (gasket_dev); - -return ret; -} - -/* Determine if GCB is in reset state. */ -static bool is_gcb_in_reset (struct gasket_dev *gasket_dev) -{ -u32 val =gasket_dev_read_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ); - -/* Masks rg_rst_gcb bit of SCU_CTRL_2 */ -return (val &SCU3_CUR_RST_GCB_BIT_MASK ); -} - -/* Reset the hardware, then quit reset. Called on device open. */ -static int apex_reset (struct gasket_dev *gasket_dev) -{ -int ret; - -if (bypass_top_level) -return 0 ; - -if (!is_gcb_in_reset (gasket_dev)) { -/* We are not in reset - toggle the reset bit so as to force
drivers/staging/gasket/apex_driver.c deleted +0
-14-* re-init of custom block -*/ -dev_dbg (gasket_dev->dev,"%s: toggle reset\n" , __func__); - - ret =apex_enter_reset (gasket_dev); -if (ret) -return ret; - } -return apex_quit_reset (gasket_dev); -} - -/* -* Check permissions for Apex ioctls. -* Returns true if the current user may execute this ioctl, and false otherwise.
- */drivers/staging/gasket/apex_driver.c deleted +0
-23-static bool apex_ioctl_check_permissions (struct file *filp,uint cmd) -{ -return !!(filp->f_mode &FMODE_WRITE ); -} - -/* Gates or un-gates Apex clock. */ -static long apex_clock_gating (struct gasket_dev *gasket_dev, -struct apex_gate_clock_ioctl __user *argp) -{ -struct apex_gate_clock_ioctl ibuf; - -if (bypass_top_level || !allow_sw_clock_gating) -return 0 ; - -if (copy_from_user (&ibuf, argp,sizeof (ibuf))) -return -EFAULT ; - -dev_dbg (gasket_dev->dev,"%s %llu\n" , __func__, ibuf.enable); - -if (ibuf.enable) { -/* Quiesce AXI, gate GCB clock. */ - gasket_read_modify_write_32(gasket_dev, APEX_BAR_INDEX, - APEX_BAR2_REG_AXI_QUIESCE,
0x1, 1,drivers/staging/gasket/apex_driver.c deleted +0
-3- 16); - gasket_read_modify_write_32(gasket_dev, APEX_BAR_INDEX, - APEX_BAR2_REG_GCB_CLOCK_GATE,
0x1,drivers/staging/gasket/apex_driver.c deleted +0
-5- 2, 18); - }else { -/* Un-gate GCB clock, un-quiesce AXI. */ - gasket_read_modify_write_32(gasket_dev, APEX_BAR_INDEX, - APEX_BAR2_REG_GCB_CLOCK_GATE,
0x0,drivers/staging/gasket/apex_driver.c deleted +0
-3- 2, 18); - gasket_read_modify_write_32(gasket_dev, APEX_BAR_INDEX, - APEX_BAR2_REG_AXI_QUIESCE,
0x0, 1,drivers/staging/gasket/apex_driver.c deleted +0
-23- 16); - } -return 0 ; -} - -/* Apex-specific ioctl handler. */ -static long apex_ioctl (struct file *filp,uint cmd,void __user *argp) -{ -struct gasket_dev *gasket_dev = filp->private_data; - -if (!apex_ioctl_check_permissions (filp, cmd)) -return -EPERM ; - -switch (cmd) { -case APEX_IOCTL_GATE_CLOCK : -return apex_clock_gating (gasket_dev, argp); -default : -return -ENOTTY ;/* unknown command */ - } -} - -/* Display driver sysfs entries. */ -static ssize_t sysfs_show(struct device *device, struct device_attribute*attr,
drivers/staging/gasket/apex_driver.c deleted +0
-97- char *buf) -{ -int ret; -struct gasket_dev *gasket_dev; -struct gasket_sysfs_attribute *gasket_attr; -enum sysfs_attribute_type type; -struct gasket_page_table *gpt; -uint val; - - gasket_dev =gasket_sysfs_get_device_data (device); -if (!gasket_dev) { -dev_err (device,"No Apex device sysfs mapping found\n" ); -return -ENODEV ; - } - - gasket_attr =gasket_sysfs_get_attr (device, attr); -if (!gasket_attr) { -dev_err (device,"No Apex device sysfs attr data found\n" ); -gasket_sysfs_put_device_data (device, gasket_dev); -return -ENODEV ; - } - - type = (enum sysfs_attribute_type )gasket_attr->data.attr_type; - gpt = gasket_dev->page_table[0 ]; -switch (type) { -case ATTR_KERNEL_HIB_PAGE_TABLE_SIZE : - val =gasket_page_table_num_entries (gpt); -break ; -case ATTR_KERNEL_HIB_SIMPLE_PAGE_TABLE_SIZE : - val =gasket_page_table_num_simple_entries (gpt); -break ; -case ATTR_KERNEL_HIB_NUM_ACTIVE_PAGES : - val =gasket_page_table_num_active_pages (gpt); -break ; -default : -dev_dbg (gasket_dev->dev,"Unknown attribute: %s\n" , - attr->attr.name); - ret =0 ; - goto exit; - } - ret =scnprintf (buf,PAGE_SIZE ,"%u\n" , val); -exit: -gasket_sysfs_put_attr (device, gasket_attr); -gasket_sysfs_put_device_data (device, gasket_dev); -return ret; -} - -static struct gasket_sysfs_attribute apex_sysfs_attrs[] = { -GASKET_SYSFS_RO (node_0_page_table_entries, sysfs_show, -ATTR_KERNEL_HIB_PAGE_TABLE_SIZE ), -GASKET_SYSFS_RO (node_0_simple_page_table_entries, sysfs_show, -ATTR_KERNEL_HIB_SIMPLE_PAGE_TABLE_SIZE ), -GASKET_SYSFS_RO (node_0_num_mapped_pages, sysfs_show, -ATTR_KERNEL_HIB_NUM_ACTIVE_PAGES ), -GASKET_END_OF_ATTR_ARRAY -}; - -/* On device open, perform a core reinit reset. */ -static int apex_device_open_cb (struct gasket_dev *gasket_dev) -{ -return gasket_reset_nolock (gasket_dev); -} - -static const struct pci_device_id apex_pci_ids[] = { - {PCI_DEVICE (APEX_PCI_VENDOR_ID ,APEX_PCI_DEVICE_ID ) }, {0 } -}; - -static int apex_pci_probe (struct pci_dev *pci_dev, -const struct pci_device_id *id) -{ -int ret; -ulong page_table_ready, msix_table_ready; -int retries =0 ; -struct gasket_dev *gasket_dev; - - ret =pci_enable_device (pci_dev); -if (ret) { -dev_err (&pci_dev->dev,"error enabling PCI device\n" ); -return ret; - } - -pci_set_master (pci_dev); - - ret =gasket_pci_add_device (pci_dev, &gasket_dev); -if (ret) { -dev_err (&pci_dev->dev,"error adding gasket device\n" ); -pci_disable_device (pci_dev); -return ret; - } - -pci_set_drvdata (pci_dev, gasket_dev); -apex_reset (gasket_dev); - -while (retries <APEX_RESET_RETRY ) { - page_table_ready = - gasket_dev_read_64(gasket_dev, APEX_BAR_INDEX, -
APEX_BAR2_REG_KERNEL_HIB_PAGE_TABLE_INIT);drivers/staging/gasket/apex_driver.c deleted +0
-3- msix_table_ready = - gasket_dev_read_64(gasket_dev, APEX_BAR_INDEX, -
APEX_BAR2_REG_KERNEL_HIB_MSIX_TABLE_INIT);drivers/staging/gasket/apex_driver.c deleted +0
-9-if (page_table_ready && msix_table_ready) -break ; -schedule_timeout (msecs_to_jiffies (APEX_RESET_DELAY )); - retries++; - } - -if (retries ==APEX_RESET_RETRY ) { -if (!page_table_ready) - dev_err(gasket_dev->dev, "Page table init timedout\n");
drivers/staging/gasket/apex_driver.c deleted +0
-2-if (!msix_table_ready) - dev_err(gasket_dev->dev, "MSI-X table init timedout\n");
drivers/staging/gasket/apex_driver.c deleted +0
-8- ret = -ETIMEDOUT ; - goto remove_device; - } - - ret =gasket_sysfs_create_entries (gasket_dev->dev_info.device, - apex_sysfs_attrs); -if (ret) - dev_err(&pci_dev->dev, "error creating device sysfsentries\n");
drivers/staging/gasket/apex_driver.c deleted +0
-102- - ret =gasket_enable_device (gasket_dev); -if (ret) { -dev_err (&pci_dev->dev,"error enabling gasket device\n" ); - goto remove_device; - } - -/* Place device in low power mode until opened */ -if (allow_power_save) -apex_enter_reset (gasket_dev); - -return 0 ; - -remove_device: -gasket_pci_remove_device (pci_dev); -pci_disable_device (pci_dev); -return ret; -} - -static void apex_pci_remove (struct pci_dev *pci_dev) -{ -struct gasket_dev *gasket_dev =pci_get_drvdata (pci_dev); - -gasket_disable_device (gasket_dev); -gasket_pci_remove_device (pci_dev); -pci_disable_device (pci_dev); -} - -static const struct gasket_driver_desc apex_desc = { - .name ="apex" , - .driver_version =APEX_DRIVER_VERSION , - .major =120 , - .minor =0 , - .module =THIS_MODULE , - .pci_id_table = apex_pci_ids, - - .num_page_tables =NUM_NODES , - .page_table_bar_index =APEX_BAR_INDEX , - .page_table_configs = apex_page_table_configs, - .page_table_extended_bit =APEX_EXTENDED_SHIFT , - - .bar_descriptions = { -GASKET_UNUSED_BAR , -GASKET_UNUSED_BAR , - {APEX_BAR_BYTES , (VM_WRITE |VM_READ ),APEX_BAR_OFFSET , -NUM_REGIONS , mappable_regions,PCI_BAR }, -GASKET_UNUSED_BAR , -GASKET_UNUSED_BAR , -GASKET_UNUSED_BAR , - }, - .coherent_buffer_description = { -APEX_CH_MEM_BYTES , - (VM_WRITE |VM_READ ), -APEX_CM_OFFSET , - }, - .interrupt_type =PCI_MSIX , - .interrupt_bar_index =APEX_BAR_INDEX , - .num_interrupts =APEX_INTERRUPT_COUNT , - .interrupts = apex_interrupts, - .interrupt_pack_width =7 , - - .device_open_cb = apex_device_open_cb, - .device_close_cb = apex_device_cleanup, - - .ioctl_handler_cb = apex_ioctl, - .device_status_cb = apex_get_status, - .hardware_revision_cb =NULL , - .device_reset_cb = apex_reset, -}; - -static struct pci_driver apex_pci_driver = { - .name ="apex" , - .probe = apex_pci_probe, - .remove = apex_pci_remove, - .id_table = apex_pci_ids, -}; - -static int __init apex_init (void ) -{ -int ret; - - ret =gasket_register_device (&apex_desc); -if (ret) -return ret; - ret =pci_register_driver (&apex_pci_driver); -if (ret) -gasket_unregister_device (&apex_desc); -return ret; -} - -static void apex_exit (void ) -{ -pci_unregister_driver (&apex_pci_driver); -gasket_unregister_device (&apex_desc); -} -MODULE_DESCRIPTION ("Google Apex driver" ); -MODULE_VERSION (APEX_DRIVER_VERSION ); -MODULE_LICENSE ("GPL v2" ); -MODULE_AUTHOR ("John Joseph <[email protected]>" ); -MODULE_DEVICE_TABLE (pci, apex_pci_ids); -module_init (apex_init); -module_exit (apex_exit);drivers/staging/gasket/gasket.h deleted +0
-21@@ -1,122 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* Common Gasket device kernel and user space declarations. -* -* Copyright (C) 2018 Google, Inc. -*/ -#ifndef __GASKET_H__ -#define __GASKET_H__ - -#include <linux/ioctl.h> -#include <linux/types.h> - -/* ioctl structure declarations */ - -/* Ioctl structures are padded to a multiple of 64 bits */ -/* and padded to put 64 bit values on 64 bit boundaries. */ -/* Unsigned 64 bit integers are used to hold pointers. */ -/* This helps compatibility between 32 and 64 bits. */ - -/* -* Common structure for ioctls associating an eventfd with a device interrupt,
- * when using the Gasket interrupt module.
- */drivers/staging/gasket/gasket.h deleted +0
-7-struct gasket_interrupt_eventfd { -u64 interrupt; -u64 event_fd; -}; - -/* -* Common structure for ioctls mapping and unmapping buffers when using the
- * Gasketpage_tablemodule.
- */drivers/staging/gasket/gasket.h deleted +0
-9-struct gasket_page_table_ioctl { -u64 page_table_index; -u64 size; -u64 host_address; -u64 device_address; -}; - -/* -* Common structure for ioctls mapping and unmapping buffers when using the
- * Gasketpage_tablemodule.
- *dma_address: phys addr start of coherent memory, allocated by kernel
- */drivers/staging/gasket/gasket.h deleted +0
-22-struct gasket_coherent_alloc_config_ioctl { -u64 page_table_index; -u64 enable; -u64 size; -u64 dma_address; -}; - -/* Base number for all Gasket-common IOCTLs */ -#define GASKET_IOCTL_BASE 0xDC - -/* Reset the device. */ -#define GASKET_IOCTL_RESET _IO(GASKET_IOCTL_BASE, 0) - -/* Associate the specified [event]fd with the specified interrupt. */ -#define GASKET_IOCTL_SET_EVENTFD \ - _IOW(GASKET_IOCTL_BASE, 1, struct gasket_interrupt_eventfd) - -/* -* Clears any eventfd associated with the specified interrupt. The (ulong) -* argument is the interrupt number to clear. - */ -#define GASKET_IOCTL_CLEAR_EVENTFD _IOW(GASKET_IOCTL_BASE, 2, unsignedlong)
drivers/staging/gasket/gasket.h deleted +0
-4- -/* -* [Loopbacks only] Requests that the loopback device send the specified -* interrupt to the host. The (ulong) argument is the number of the interrupt to
- * send.
- */drivers/staging/gasket/gasket.h deleted +0
-4-#define GASKET_IOCTL_LOOPBACK_INTERRUPT \ - _IOW(GASKET_IOCTL_BASE, 3, unsigned long) - -/* Queries the kernel for the number of page tables supported by the device. */
drivers/staging/gasket/gasket.h deleted +0
-4-#define GASKET_IOCTL_NUMBER_PAGE_TABLES _IOR(GASKET_IOCTL_BASE, 4, u64) - -/* -* Queries the kernel for the maximum size of the page table. Only the size and
- *page_table_indexfields are used from the structgasket_page_table_ioctl.
- */drivers/staging/gasket/gasket.h deleted +0
-5-#define GASKET_IOCTL_PAGE_TABLE_SIZE \ - _IOWR(GASKET_IOCTL_BASE, 5, struct gasket_page_table_ioctl) - -/* -* Queries the kernel for the current simple page table size. Only the size and
- *page_table_indexfields are used from the structgasket_page_table_ioctl.
- */drivers/staging/gasket/gasket.h deleted +0
-6-#define GASKET_IOCTL_SIMPLE_PAGE_TABLE_SIZE \ - _IOWR(GASKET_IOCTL_BASE, 6, struct gasket_page_table_ioctl) - -/* -* Tells the kernel to change the split between the number of simple and -* extended entries in the given page table. Only the size and
page_table_index
- * fields are used from the structgasket_page_table_ioctl.
- */drivers/staging/gasket/gasket.h deleted +0
-12-#define GASKET_IOCTL_PARTITION_PAGE_TABLE \ - _IOW(GASKET_IOCTL_BASE, 7, struct gasket_page_table_ioctl) - -/* -* Tells the kernel to map size bytes at host_address to device_address in -* page_table_index page table. - */ -#define GASKET_IOCTL_MAP_BUFFER \ - _IOW(GASKET_IOCTL_BASE, 8, struct gasket_page_table_ioctl) - -/* -* Tells the kernel to unmap size bytes at host_address from
device_addressin
- *page_table_indexpage table.
- */drivers/staging/gasket/gasket.h deleted +0
-9-#define GASKET_IOCTL_UNMAP_BUFFER \ - _IOW(GASKET_IOCTL_BASE, 9, struct gasket_page_table_ioctl) - -/* Clear the interrupt counts stored for this device. */ -#define GASKET_IOCTL_CLEAR_INTERRUPT_COUNTS _IO(GASKET_IOCTL_BASE, 10) - -/* Enable/Disable and configure the coherent allocator. */ -#define GASKET_IOCTL_CONFIG_COHERENT_ALLOCATOR \ - _IOWR(GASKET_IOCTL_BASE, 11, struct
gasket_coherent_alloc_config_ioctl)drivers/staging/gasket/gasket.h deleted +0
-2- -#endif /* __GASKET_H__ */ drivers/staging/gasket/gasket_constants.h deleted +0
-9@@ -1,44 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright (C) 2018 Google, Inc. */ -#ifndef __GASKET_CONSTANTS_H__ -#define __GASKET_CONSTANTS_H__ - -#define GASKET_FRAMEWORK_VERSION "1.1.2" - -/* -* The maximum number of simultaneous device types supported by the framework.
- */drivers/staging/gasket/gasket_constants.h deleted +0
-9-#define GASKET_FRAMEWORK_DESC_MAX 2 - -/* The maximum devices per each type. */ -#define GASKET_DEV_MAX 256 - -/* The number of supported Gasket page tables per device. */ -#define GASKET_MAX_NUM_PAGE_TABLES 1 - -/* Maximum length of device names (driver name + minor number suffix + NULL). */
drivers/staging/gasket/gasket_constants.h deleted +0
-6-#define GASKET_NAME_MAX 32 - -/* Device status enumeration. */ -enum gasket_status { -/* -* A device is DEAD if it has not been initialized or has had an error.
drivers/staging/gasket/gasket_constants.h deleted +0
-13-*/ -GASKET_STATUS_DEAD =0 , -/* -* A device is LAMED if the hardware is healthy but the kernel was -* unable to enable some functionality (e.g. interrupts). -*/ -GASKET_STATUS_LAMED , - -/* A device is ALIVE if it is ready for operation. */ - GASKET_STATUS_ALIVE, - -/* -* This status is set when the driver is exiting and waiting for all
drivers/staging/gasket/gasket_constants.h deleted +0
-6-* handles to be closed. -*/ - GASKET_STATUS_DRIVER_EXIT, -}; - -#endif drivers/staging/gasket/gasket_core.c deleted +0
-4@@ -1,1815 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* Gasket generic driver framework. This file contains the implementation -* for the Gasket generic driver framework - the functionality that is common
- * across Gasket devices.
- *
- * Copyright (C) 2018 Google, Inc.
- */drivers/staging/gasket/gasket_core.c deleted +0
-33- -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt - -#include "gasket_core.h" - -#include "gasket_interrupt.h" -#include "gasket_ioctl.h" -#include "gasket_page_table.h" -#include "gasket_sysfs.h" - -#include <linux/capability.h> -#include <linux/compiler.h> -#include <linux/delay.h> -#include <linux/device.h> -#include <linux/fs.h> -#include <linux/init.h> -#include <linux/of.h> -#include <linux/pid_namespace.h> -#include <linux/printk.h> -#include <linux/sched.h> - -#ifdef GASKET_KERNEL_TRACE_SUPPORT -#define CREATE_TRACE_POINTS -#include <trace/events/gasket_mmap.h> -#else -#define trace_gasket_mmap_exit (x) -#define trace_gasket_mmap_entry (x, ...) -#endif - -/* -* "Private" members of gasket_driver_desc. -* -* Contains internal per-device type tracking data, i.e., data not appropriate
- * as part of the public interface for the generic framework.
- */drivers/staging/gasket/gasket_core.c deleted +0
-23-struct gasket_internal_desc { -/* Device-specific-driver-provided configuration information. */ -const struct gasket_driver_desc *driver_desc; - -/* Protects access to per-driver data (i.e. this structure). */ -struct mutex mutex; - -/* Kernel-internal device class. */ -struct class *class; - -/* Instantiated / present devices of this type. */ -struct gasket_dev *devs[GASKET_DEV_MAX ]; -}; - -/* do_map_region() needs be able to return more than just true/false. */ -enum do_map_region_status { -/* The region was successfully mapped. */ -DO_MAP_REGION_SUCCESS , - -/* Attempted to map region and failed. */ -DO_MAP_REGION_FAILURE , - -/* The requested region to map was not part of a mappable region. */
drivers/staging/gasket/gasket_core.c deleted +0
-13- DO_MAP_REGION_INVALID, -}; - -/* Global data definitions. */ -/* Mutex - only for framework-wide data. Other data should be protected by -* finer-grained locks. -*/ -static DEFINE_MUTEX (g_mutex); - -/* List of all registered device descriptions & their supporting data. */ -static struct gasket_internal_desc g_descs[GASKET_FRAMEWORK_DESC_MAX ]; - -/* Mapping of statuses to human-readable strings. Must end with {0,NULL}. */
drivers/staging/gasket/gasket_core.c deleted +0
-41-static const struct gasket_num_name gasket_status_name_table[] = { - {GASKET_STATUS_DEAD ,"DEAD" }, - {GASKET_STATUS_ALIVE ,"ALIVE" }, - {GASKET_STATUS_LAMED ,"LAMED" }, - {GASKET_STATUS_DRIVER_EXIT ,"DRIVER_EXITING" }, - {0 ,NULL }, -}; - -/* Enumeration of the automatic Gasket framework sysfs nodes. */ -enum gasket_sysfs_attribute_type { -ATTR_BAR_OFFSETS , -ATTR_BAR_SIZES , -ATTR_DRIVER_VERSION , -ATTR_FRAMEWORK_VERSION , -ATTR_DEVICE_TYPE , -ATTR_HARDWARE_REVISION , -ATTR_PCI_ADDRESS , -ATTR_STATUS , -ATTR_IS_DEVICE_OWNED , -ATTR_DEVICE_OWNER , -ATTR_WRITE_OPEN_COUNT , -ATTR_RESET_COUNT , -ATTR_USER_MEM_RANGES -}; - -/* Perform a standard Gasket callback. */ -static inline int -check_and_invoke_callback (struct gasket_dev *gasket_dev, -int (*cb_function)(struct gasket_dev *)) -{ -int ret =0 ; - -if (cb_function) { -mutex_lock (&gasket_dev->mutex); - ret =cb_function (gasket_dev); -mutex_unlock (&gasket_dev->mutex); - } -return ret; -} - -/* Perform a standard Gasket callback without grabbing gasket_dev->mutex. */
drivers/staging/gasket/gasket_core.c deleted +0
-3-static inline int -gasket_check_and_invoke_callback_nolock(struct gasket_dev *gasket_dev, - int (*cb_function)(struct
gasket_dev*))drivers/staging/gasket/gasket_core.c deleted +0
-10-{ -int ret =0 ; - -if (cb_function) - ret =cb_function (gasket_dev); -return ret; -} - -/* -* Return nonzero if the gasket_cdev_info is owned by the current thread group
- * ID.
- */drivers/staging/gasket/gasket_core.c deleted +0
-10-static int gasket_owned_by_current_tgid (struct gasket_cdev_info *info) -{ -return (info->ownership.is_owned && - (info->ownership.owner == current->tgid)); -} - -/* -* Find the next free gasket_internal_dev slot. -* -* Returns the located slot number on success or a negative number on failure.
- */
-static int gasket_find_dev_slot(structgasket_internal_desc*internal_desc,drivers/staging/gasket/gasket_core.c deleted +0
-10- const char *kobj_name) -{ -int i; - -mutex_lock (&internal_desc->mutex); - -/* Search for a previous instance of this device. */ -for (i =0 ; i <GASKET_DEV_MAX ; i++) { -if (internal_desc->devs[i] && - strcmp(internal_desc->devs[i]->kobj_name, kobj_name)== 0) {
drivers/staging/gasket/gasket_core.c deleted +0
-14-pr_err ("Duplicate device %s\n" , kobj_name); -mutex_unlock (&internal_desc->mutex); -return -EBUSY ; - } - } - -/* Find a free device slot. */ -for (i =0 ; i <GASKET_DEV_MAX ; i++) { -if (!internal_desc->devs[i]) -break ; - } - -if (i ==GASKET_DEV_MAX ) { - pr_err("Too many registered devices; max %d\n",
GASKET_DEV_MAX);drivers/staging/gasket/gasket_core.c deleted +0
-10-mutex_unlock (&internal_desc->mutex); -return -EBUSY ; - } - -mutex_unlock (&internal_desc->mutex); -return i; -} - -/* -* Allocate and initialize a Gasket device structure, add the device to the
- * device list.
- *
- * Returns 0 if successful, a negative error code otherwise.
- */drivers/staging/gasket/gasket_core.c deleted +0
-2-static int gasket_alloc_dev (struct gasket_internal_desc *internal_desc, - struct device *parent, struct gasket_dev**pdev)
drivers/staging/gasket/gasket_core.c deleted +0
-28-{ -int dev_idx; -const struct gasket_driver_desc *driver_desc = - internal_desc->driver_desc; -struct gasket_dev *gasket_dev; -struct gasket_cdev_info *dev_info; -const char *parent_name =dev_name (parent); - -pr_debug ("Allocating a Gasket device, parent %s.\n" , parent_name); - - *pdev =NULL ; - - dev_idx =gasket_find_dev_slot (internal_desc, parent_name); -if (dev_idx <0 ) -return dev_idx; - - gasket_dev = *pdev =kzalloc (sizeof (*gasket_dev),GFP_KERNEL ); -if (!gasket_dev) { -pr_err ("no memory for device, parent %s\n" , parent_name); -return -ENOMEM ; - } - internal_desc->devs[dev_idx] = gasket_dev; - -mutex_init (&gasket_dev->mutex); - - gasket_dev->internal_desc = internal_desc; - gasket_dev->dev_idx = dev_idx; - snprintf(gasket_dev->kobj_name, GASKET_NAME_MAX, "%s",
parent_name);drivers/staging/gasket/gasket_core.c deleted +0
-9- gasket_dev->dev =get_device (parent); -/* gasket_bar_data is uninitialized. */ - gasket_dev->num_page_tables = driver_desc->num_page_tables; -/* max_page_table_size and *page table are uninit'ed */ -/* interrupt_data is not initialized. */ -/* status is 0, or GASKET_STATUS_DEAD */ - - dev_info = &gasket_dev->dev_info; - snprintf(dev_info->name, GASKET_NAME_MAX, "%s_%u",
driver_desc->name,drivers/staging/gasket/gasket_core.c deleted +0
-19- gasket_dev->dev_idx); - dev_info->devt = -MKDEV (driver_desc->major, driver_desc->minor + - gasket_dev->dev_idx); - dev_info->device = -device_create (internal_desc->class, parent, dev_info->devt, - gasket_dev, dev_info->name); - -/* cdev has not yet been added; cdev_added is 0 */ - dev_info->gasket_dev_ptr = gasket_dev; -/* ownership is all 0, indicating no owner or opens. */ - -return 0 ; -} - -/* Free a Gasket device. */ -static void gasket_free_dev (struct gasket_dev *gasket_dev) -{ - struct gasket_internal_desc *internal_desc =
gasket_dev->internal_desc;drivers/staging/gasket/gasket_core.c deleted +0
-17- -mutex_lock (&internal_desc->mutex); - internal_desc->devs[gasket_dev->dev_idx] =NULL ; -mutex_unlock (&internal_desc->mutex); -put_device (gasket_dev->dev); -kfree (gasket_dev); -} - -/* -* Maps the specified bar into kernel space. -* -* Returns 0 on success, a negative error code otherwise. -* A zero-sized BAR will not be mapped, but is not an error. -*/ -static int gasket_map_pci_bar (struct gasket_dev *gasket_dev,int bar_num) -{ - struct gasket_internal_desc *internal_desc =
gasket_dev->internal_desc;drivers/staging/gasket/gasket_core.c deleted +0
-18-const struct gasket_driver_desc *driver_desc = - internal_desc->driver_desc; -ulong desc_bytes = driver_desc->bar_descriptions[bar_num].size; -struct gasket_bar_data *data; -int ret; - -if (desc_bytes ==0 ) -return 0 ; - -if (driver_desc->bar_descriptions[bar_num].type !=PCI_BAR ) { -/* not PCI: skip this entry */ -return 0 ; - } - - data = &gasket_dev->bar_data[bar_num]; - -/* -* pci_resource_start and pci_resource_len return a "
resource_size_t",drivers/staging/gasket/gasket_core.c deleted +0
-16-* which is safely castable to ulong (which itself is the arg to -* request_mem_region). -*/ - data->phys_base = - (ulong )pci_resource_start (gasket_dev->pci_dev, bar_num); -if (!data->phys_base) { -dev_err (gasket_dev->dev,"Cannot get BAR%u base address\n" , - bar_num); -return -EINVAL ; - } - - data->length_bytes = - (ulong )pci_resource_len (gasket_dev->pci_dev, bar_num); -if (data->length_bytes < desc_bytes) { - dev_err(gasket_dev->dev, - "PCI BAR %u space is too small: %lu; expected >=%lu\n",
drivers/staging/gasket/gasket_core.c deleted +0
-36- bar_num, data->length_bytes, desc_bytes); -return -ENOMEM ; - } - -if (!request_mem_region (data->phys_base, data->length_bytes, - gasket_dev->dev_info.name)) { -dev_err (gasket_dev->dev, -"Cannot get BAR %d memory region %p\n" , - bar_num, &gasket_dev->pci_dev->resource[bar_num]); -return -EINVAL ; - } - - data->virt_base =ioremap (data->phys_base, data->length_bytes); -if (!data->virt_base) { -dev_err (gasket_dev->dev, -"Cannot remap BAR %d memory region %p\n" , - bar_num, &gasket_dev->pci_dev->resource[bar_num]); - ret = -ENOMEM ; - goto fail; - } - -dma_set_mask (&gasket_dev->pci_dev->dev,DMA_BIT_MASK (64 )); -dma_set_coherent_mask (&gasket_dev->pci_dev->dev,DMA_BIT_MASK (64 )); - -return 0 ; - -fail: -iounmap (data->virt_base); -release_mem_region (data->phys_base, data->length_bytes); -return ret; -} - -/* -* Releases PCI BAR mapping. -* -* A zero-sized or not-mapped BAR will not be unmapped, but is not an error.
- */drivers/staging/gasket/gasket_core.c deleted +0
-32-static void gasket_unmap_pci_bar (struct gasket_dev *dev,int bar_num) -{ -ulong base, bytes; -struct gasket_internal_desc *internal_desc = dev->internal_desc; -const struct gasket_driver_desc *driver_desc = - internal_desc->driver_desc; - -if (driver_desc->bar_descriptions[bar_num].size ==0 || - !dev->bar_data[bar_num].virt_base) -return ; - -if (driver_desc->bar_descriptions[bar_num].type !=PCI_BAR ) -return ; - -iounmap (dev->bar_data[bar_num].virt_base); - dev->bar_data[bar_num].virt_base =NULL ; - - base =pci_resource_start (dev->pci_dev, bar_num); -if (!base) { -dev_err (dev->dev,"cannot get PCI BAR%u base address\n" , - bar_num); -return ; - } - - bytes =pci_resource_len (dev->pci_dev, bar_num); -release_mem_region (base, bytes); -} - -/* -* Setup PCI memory mapping for the specified device. -* -* Reads the BAR registers and sets up pointers to the device's memory mapped
- * IO space.
- *
- * Returns 0 on success and a negative value otherwise.
- */drivers/staging/gasket/gasket_core.c deleted +0
-41-static int gasket_setup_pci (struct pci_dev *pci_dev, -struct gasket_dev *gasket_dev) -{ -int i, mapped_bars, ret; - -for (i =0 ; i <PCI_STD_NUM_BARS ; i++) { - ret =gasket_map_pci_bar (gasket_dev, i); -if (ret) { - mapped_bars = i; - goto fail; - } - } - -return 0 ; - -fail: -for (i =0 ; i < mapped_bars; i++) -gasket_unmap_pci_bar (gasket_dev, i); - -return -ENOMEM ; -} - -/* Unmaps memory for the specified device. */ -static void gasket_cleanup_pci (struct gasket_dev *gasket_dev) -{ -int i; - -for (i =0 ; i <PCI_STD_NUM_BARS ; i++) -gasket_unmap_pci_bar (gasket_dev, i); -} - -/* Determine the health of the Gasket device. */ -static int gasket_get_hw_status (struct gasket_dev *gasket_dev) -{ -int status; -int i; -const struct gasket_driver_desc *driver_desc = - gasket_dev->internal_desc->driver_desc; - - status = gasket_check_and_invoke_callback_nolock(gasket_dev, -
driver_desc->device_status_cb);drivers/staging/gasket/gasket_core.c deleted +0
-15-if (status !=GASKET_STATUS_ALIVE ) { -dev_dbg (gasket_dev->dev,"Hardware reported status %d.\n" , - status); -return status; - } - - status =gasket_interrupt_system_status (gasket_dev); -if (status !=GASKET_STATUS_ALIVE ) { -dev_dbg (gasket_dev->dev, -"Interrupt system reported status %d.\n" , status); -return status; - } - -for (i =0 ; i < driver_desc->num_page_tables; ++i) { - status =
gasket_page_table_system_status(gasket_dev->page_table[i]);drivers/staging/gasket/gasket_core.c deleted +0
-27-if (status !=GASKET_STATUS_ALIVE ) { -dev_dbg (gasket_dev->dev, -"Page table %d reported status %d.\n" , - i, status); -return status; - } - } - -return GASKET_STATUS_ALIVE ; -} - -static ssize_t -gasket_write_mappable_regions(char *buf, - const struct gasket_driver_desc *driver_desc, - int bar_index) -{ - int i; - ssize_t written; - ssize_t total_written = 0; - ulong min_addr, max_addr; - struct gasket_bar_desc bar_desc = - driver_desc->bar_descriptions[bar_index]; - - if (bar_desc.permissions == GASKET_NOMAP) - return 0; - for (i = 0; - i < bar_desc.num_mappable_regions && total_written <
PAGE_SIZE;drivers/staging/gasket/gasket_core.c deleted +0
-8- i++) { - min_addr = bar_desc.mappable_regions[i].start - - driver_desc->legacy_mmap_address_offset; - max_addr = bar_desc.mappable_regions[i].start - - driver_desc->legacy_mmap_address_offset + - bar_desc.mappable_regions[i].length_bytes; - written = scnprintf(buf, PAGE_SIZE - total_written, - "0x%08lx-0x%08lx\n", min_addr,
max_addr);drivers/staging/gasket/gasket_core.c deleted +0
-8- total_written += written; - buf += written; - } -return total_written; -} - -static ssize_t gasket_sysfs_data_show (struct device *device, - struct device_attribute *attr, char*buf)
drivers/staging/gasket/gasket_core.c deleted +0
-26-{ -int i, ret =0 ; -ssize_t current_written =0 ; -const struct gasket_driver_desc *driver_desc; -struct gasket_dev *gasket_dev; -struct gasket_sysfs_attribute *gasket_attr; -const struct gasket_bar_desc *bar_desc; -enum gasket_sysfs_attribute_type sysfs_type; - - gasket_dev =gasket_sysfs_get_device_data (device); -if (!gasket_dev) { -dev_err (device,"No sysfs mapping found for device\n" ); -return 0 ; - } - - gasket_attr =gasket_sysfs_get_attr (device, attr); -if (!gasket_attr) { -dev_err (device,"No sysfs attr found for device\n" ); -gasket_sysfs_put_device_data (device, gasket_dev); -return 0 ; - } - - driver_desc = gasket_dev->internal_desc->driver_desc; - - sysfs_type = - (enumgasket_sysfs_attribute_type)gasket_attr->data.attr_type;
drivers/staging/gasket/gasket_core.c deleted +0
-8-switch (sysfs_type) { -case ATTR_BAR_OFFSETS : -for (i =0 ; i <PCI_STD_NUM_BARS ; i++) { - bar_desc = &driver_desc->bar_descriptions[i]; -if (bar_desc->size ==0 ) -continue ; - current_written = - snprintf(buf, PAGE_SIZE - ret, "%d:0x%lx\n", i,
drivers/staging/gasket/gasket_core.c deleted +0
-12- (ulong)bar_desc->base); - buf += current_written; - ret += current_written; - } -break ; -case ATTR_BAR_SIZES : -for (i =0 ; i <PCI_STD_NUM_BARS ; i++) { - bar_desc = &driver_desc->bar_descriptions[i]; -if (bar_desc->size ==0 ) -continue ; - current_written = - snprintf(buf, PAGE_SIZE - ret, "%d:0x%lx\n", i,
drivers/staging/gasket/gasket_core.c deleted +0
-8- (ulong)bar_desc->size); - buf += current_written; - ret += current_written; - } -break ; -case ATTR_DRIVER_VERSION : - ret = snprintf(buf, PAGE_SIZE, "%s\n", -
gasket_dev->internal_desc->driver_desc->driver_version);drivers/staging/gasket/gasket_core.c deleted +0
-8-break ; -case ATTR_FRAMEWORK_VERSION : - ret =snprintf (buf,PAGE_SIZE ,"%s\n" , -GASKET_FRAMEWORK_VERSION ); -break ; -case ATTR_DEVICE_TYPE : - ret = snprintf(buf, PAGE_SIZE, "%s\n", -
gasket_dev->internal_desc->driver_desc->name);drivers/staging/gasket/gasket_core.c deleted +0
-7-break ; -case ATTR_HARDWARE_REVISION : - ret =snprintf (buf,PAGE_SIZE ,"%d\n" , - gasket_dev->hardware_revision); -break ; -case ATTR_PCI_ADDRESS : - ret = snprintf(buf, PAGE_SIZE, "%s\n",
gasket_dev->kobj_name);drivers/staging/gasket/gasket_core.c deleted +0
-17-break ; -case ATTR_STATUS : - ret =snprintf (buf,PAGE_SIZE ,"%s\n" , -gasket_num_name_lookup (gasket_dev->status, - gasket_status_name_table)); -break ; -case ATTR_IS_DEVICE_OWNED : - ret =snprintf (buf,PAGE_SIZE ,"%d\n" , - gasket_dev->dev_info.ownership.is_owned); -break ; -case ATTR_DEVICE_OWNER : - ret =snprintf (buf,PAGE_SIZE ,"%d\n" , - gasket_dev->dev_info.ownership.owner); -break ; -case ATTR_WRITE_OPEN_COUNT : - ret = snprintf(buf, PAGE_SIZE, "%d\n", -
gasket_dev->dev_info.ownership.write_open_count);drivers/staging/gasket/gasket_core.c deleted +0
-3-break ; -case ATTR_RESET_COUNT : - ret = snprintf(buf, PAGE_SIZE, "%d\n",
gasket_dev->reset_count);drivers/staging/gasket/gasket_core.c deleted +0
-5-break ; -case ATTR_USER_MEM_RANGES : -for (i =0 ; i <PCI_STD_NUM_BARS ; ++i) { - current_written = - gasket_write_mappable_regions(buf,
driver_desc,drivers/staging/gasket/gasket_core.c deleted +0
-19- i); - buf += current_written; - ret += current_written; - } -break ; -default : -dev_dbg (gasket_dev->dev,"Unknown attribute: %s\n" , - attr->attr.name); - ret =0 ; -break ; - } - -gasket_sysfs_put_attr (device, gasket_attr); -gasket_sysfs_put_device_data (device, gasket_dev); -return ret; -} - -/* These attributes apply to all Gasket driver instances. */ -static const struct gasket_sysfs_attribute gasket_sysfs_generic_attrs[] ={
- GASKET_SYSFS_RO(bar_offsets,gasket_sysfs_data_show,ATTR_BAR_OFFSETS),drivers/staging/gasket/gasket_core.c deleted +0
-6-GASKET_SYSFS_RO (bar_sizes, gasket_sysfs_data_show,ATTR_BAR_SIZES ), -GASKET_SYSFS_RO (driver_version, gasket_sysfs_data_show, -ATTR_DRIVER_VERSION ), -GASKET_SYSFS_RO (framework_version, gasket_sysfs_data_show, -ATTR_FRAMEWORK_VERSION ), - GASKET_SYSFS_RO(device_type, gasket_sysfs_data_show,
ATTR_DEVICE_TYPE),drivers/staging/gasket/gasket_core.c deleted +0
-3-GASKET_SYSFS_RO (revision, gasket_sysfs_data_show, -ATTR_HARDWARE_REVISION ), - GASKET_SYSFS_RO(pci_address, gasket_sysfs_data_show,
ATTR_PCI_ADDRESS),drivers/staging/gasket/gasket_core.c deleted +0
-8-GASKET_SYSFS_RO (status, gasket_sysfs_data_show,ATTR_STATUS ), -GASKET_SYSFS_RO (is_device_owned, gasket_sysfs_data_show, -ATTR_IS_DEVICE_OWNED ), -GASKET_SYSFS_RO (device_owner, gasket_sysfs_data_show, -ATTR_DEVICE_OWNER ), -GASKET_SYSFS_RO (write_open_count, gasket_sysfs_data_show, -ATTR_WRITE_OPEN_COUNT ), - GASKET_SYSFS_RO(reset_count, gasket_sysfs_data_show,
ATTR_RESET_COUNT),drivers/staging/gasket/gasket_core.c deleted +0
-65- GASKET_SYSFS_RO(user_mem_ranges, gasket_sysfs_data_show, - ATTR_USER_MEM_RANGES), - GASKET_END_OF_ATTR_ARRAY -}; - -/* Add a char device and related info. */ -static int gasket_add_cdev(struct gasket_cdev_info *dev_info, - const struct file_operations *file_ops, - struct module *owner) -{ - int ret; - - cdev_init(&dev_info->cdev, file_ops); - dev_info->cdev.owner = owner; - ret = cdev_add(&dev_info->cdev, dev_info->devt, 1); - if (ret) { - dev_err(dev_info->gasket_dev_ptr->dev, - "cannot add char device [ret=%d]\n", ret); - return ret; - } - dev_info->cdev_added = 1; - - return 0; -} - -/* Disable device operations. */ -void gasket_disable_device(struct gasket_dev *gasket_dev) -{ - const struct gasket_driver_desc *driver_desc = - gasket_dev->internal_desc->driver_desc; - int i; - - /* Only delete the device if it has been successfully added. */ - if (gasket_dev->dev_info.cdev_added) - cdev_del(&gasket_dev->dev_info.cdev); - - gasket_dev->status = GASKET_STATUS_DEAD; - - gasket_interrupt_cleanup(gasket_dev); - - for (i = 0; i < driver_desc->num_page_tables; ++i) { - if (gasket_dev->page_table[i]) { - gasket_page_table_reset(gasket_dev->page_table[i]); -gasket_page_table_cleanup (gasket_dev->page_table[i]); - } - } -} -EXPORT_SYMBOL(gasket_disable_device); - -/* - * Registered driver descriptor lookup for PCI devices. - * - * Precondition: Called with g_mutex held (to avoid a race on return). - * Returns NULL if no matching device was found. - */ -static struct gasket_internal_desc * -lookup_pci_internal_desc(struct pci_dev *pci_dev) -{ - int i; - - __must_hold(&g_mutex); - for (i = 0; i < GASKET_FRAMEWORK_DESC_MAX; i++) { - if (g_descs[i].driver_desc && - g_descs[i].driver_desc->pci_id_table && - pci_match_id(g_descs[i].driver_desc->pci_id_table,
pci_dev))drivers/staging/gasket/gasket_core.c deleted +0
-8-return &g_descs[i]; - } - -return NULL ; -} - -/* -* Verifies that the user has permissions to perform the requested mapping and
- * that the provided descriptor/range is of adequate size to hold the range to
- * be mapped.
- */drivers/staging/gasket/gasket_core.c deleted +0
-21-static bool gasket_mmap_has_permissions (struct gasket_dev *gasket_dev, -struct vm_area_struct *vma, -int bar_permissions) -{ -int requested_permissions; -/* Always allow sysadmin to access. */ -if (capable (CAP_SYS_ADMIN )) -return true; - -/* Never allow non-sysadmins to access to a dead device. */ -if (gasket_dev->status !=GASKET_STATUS_ALIVE ) { -dev_dbg (gasket_dev->dev,"Device is dead.\n" ); -return false; - } - -/* Make sure that no wrong flags are set. */ - requested_permissions = - (vma->vm_flags &VM_ACCESS_FLAGS ); -if (requested_permissions & ~(bar_permissions)) { - dev_dbg(gasket_dev->dev, - "Attempting to map a region with requestedpermissions 0x%x, but region has permissions 0x%x.\n",
drivers/staging/gasket/gasket_core.c deleted +0
-9- requested_permissions, bar_permissions); -return false; - } - -/* Do not allow a non-owner to write. */ -if ((vma->vm_flags &VM_WRITE ) && - !gasket_owned_by_current_tgid (&gasket_dev->dev_info)) { - dev_dbg(gasket_dev->dev, - "Attempting to mmap a region for write withoutowning device.\n");
drivers/staging/gasket/gasket_core.c deleted +0
-8-return false; - } - -return true; -} - -/* -* Verifies that the input address is within the region allocated to coherent
- * buffer.
- */drivers/staging/gasket/gasket_core.c deleted +0
-42-static bool -gasket_is_coherent_region (const struct gasket_driver_desc *driver_desc, -ulong address) -{ -struct gasket_coherent_buffer_desc coh_buff_desc = - driver_desc->coherent_buffer_description; - -if (coh_buff_desc.permissions !=GASKET_NOMAP ) { -if ((address >= coh_buff_desc.base) && - (address < coh_buff_desc.base + coh_buff_desc.size)) { -return true; - } - } -return false; -} - -static int gasket_get_bar_index (const struct gasket_dev *gasket_dev, -ulong phys_addr) -{ -int i; -const struct gasket_driver_desc *driver_desc; - - driver_desc = gasket_dev->internal_desc->driver_desc; -for (i =0 ; i <PCI_STD_NUM_BARS ; ++i) { -struct gasket_bar_desc bar_desc = - driver_desc->bar_descriptions[i]; - -if (bar_desc.permissions !=GASKET_NOMAP ) { -if (phys_addr >= bar_desc.base && - phys_addr < (bar_desc.base + bar_desc.size)) { -return i; - } - } - } -/* If we haven't found the address by now, it is invalid. */ -return -EINVAL ; -} - -/* -* Sets the actual bounds to map, given the device's mappable region. -* -* Given the device's mappable region, along with the user-requested mapping
- * start offset and length of the user region, determine how much of this
- * mappable region can be mapped into the user's region (start/end offsets),
- * and the physical offset (phys_offset) into the BAR where the mapping should
- * begin (either the VMA's or region lower bound).
- *
- * In other words, this calculates the overlap between the VMA
- * (bar_offset,requested_length) and the givengasket_mappable_region.
- *
- * Returns true if there's anything to map, and false otherwise.
- */drivers/staging/gasket/gasket_core.c deleted +0
-121-static bool -gasket_mm_get_mapping_addrs (const struct gasket_mappable_region *region, -ulong bar_offset,ulong requested_length, -struct gasket_mappable_region *mappable_region, -ulong *virt_offset) -{ -ulong range_start = region->start; -ulong range_length = region->length_bytes; -ulong range_end = range_start + range_length; - - *virt_offset =0 ; -if (bar_offset + requested_length < range_start) { -/* -* If the requested region is completely below the range, -* there is nothing to map. -*/ -return false; - }else if (bar_offset <= range_start) { -/* If the bar offset is below this range's start -* but the requested length continues into it: -* 1) Only map starting from the beginning of this -* range's phys. offset, so we don't map unmappable -* memory. -* 2) The length of the virtual memory to not map is the -* delta between the bar offset and the -* mappable start (and since the mappable start is -* bigger, start - req.) -* 3) The map length is the minimum of the mappable -* requested length (requested_length - virt_offset) -* and the actual mappable length of the range. -*/ - mappable_region->start = range_start; - *virt_offset = range_start - bar_offset; - mappable_region->length_bytes = -min (requested_length - *virt_offset, range_length); -return true; - }else if (bar_offset > range_start && - bar_offset < range_end) { -/* -* If the bar offset is within this range: -* 1) Map starting from the bar offset. -* 2) Because there is no forbidden memory between the -* bar offset and the range start, -* virt_offset is 0. -* 3) The map length is the minimum of the requested -* length and the remaining length in the buffer -* (range_end - bar_offset) -*/ - mappable_region->start = bar_offset; - *virt_offset =0 ; - mappable_region->length_bytes = -min (requested_length, range_end - bar_offset); -return true; - } - -/* -* If the requested [start] offset is above range_end, -* there's nothing to map. -*/ -return false; -} - -/* -* Calculates the offset where the VMA range begins in its containing BAR. -* The offset is written into bar_offset on success. -* Returns zero on success, anything else on error. -*/ -static int gasket_mm_vma_bar_offset (const struct gasket_dev *gasket_dev, -const struct vm_area_struct *vma, -ulong *bar_offset) -{ -ulong raw_offset; -int bar_index; -const struct gasket_driver_desc *driver_desc = - gasket_dev->internal_desc->driver_desc; - - raw_offset = (vma->vm_pgoff <<PAGE_SHIFT ) + - driver_desc->legacy_mmap_address_offset; - bar_index =gasket_get_bar_index (gasket_dev, raw_offset); -if (bar_index <0 ) { -dev_err (gasket_dev->dev, -"Unable to find matching bar for address 0x%lx\n" , - raw_offset); -trace_gasket_mmap_exit (bar_index); -return bar_index; - } - *bar_offset = - raw_offset - driver_desc->bar_descriptions[bar_index].base; - -return 0 ; -} - -int gasket_mm_unmap_region (const struct gasket_dev *gasket_dev, -struct vm_area_struct *vma, -const struct gasket_mappable_region *map_region) -{ -ulong bar_offset; -ulong virt_offset; -struct gasket_mappable_region mappable_region; -int ret; - -if (map_region->length_bytes ==0 ) -return 0 ; - - ret =gasket_mm_vma_bar_offset (gasket_dev, vma, &bar_offset); -if (ret) -return ret; - -if (!gasket_mm_get_mapping_addrs (map_region, bar_offset, - vma->vm_end - vma->vm_start, - &mappable_region, &virt_offset)) -return 1 ; - -/* -* The length passed to zap_vma_ptes MUST BE A MULTIPLE OF -* PAGE_SIZE! Trust me. I have the scars. -* -* Next multiple of y: ceil_div(x, y) * y -*/ -zap_vma_ptes (vma, vma->vm_start + virt_offset, - DIV_ROUND_UP(mappable_region.length_bytes, PAGE_SIZE)*
drivers/staging/gasket/gasket_core.c deleted +0
-8- PAGE_SIZE); -return 0 ; -} -EXPORT_SYMBOL (gasket_mm_unmap_region); - -/* Maps a virtual address + range to a physical offset of a BAR. */ -static enum do_map_region_status -do_map_region(const struct gasket_dev *gasket_dev, struct vm_area_struct*vma,
drivers/staging/gasket/gasket_core.c deleted +0
-32- struct gasket_mappable_region *mappable_region) -{ -/* Maximum size of a single call to io_remap_pfn_range. */ -/* I pulled this number out of thin air. */ -const ulong max_chunk_size =64 *1024 *1024 ; -ulong chunk_size, mapped_bytes =0 ; - -const struct gasket_driver_desc *driver_desc = - gasket_dev->internal_desc->driver_desc; - -ulong bar_offset, virt_offset; -struct gasket_mappable_region region_to_map; -ulong phys_offset, map_length; -ulong virt_base, phys_base; -int bar_index, ret; - - ret =gasket_mm_vma_bar_offset (gasket_dev, vma, &bar_offset); -if (ret) -return DO_MAP_REGION_INVALID ; - -if (!gasket_mm_get_mapping_addrs (mappable_region, bar_offset, - vma->vm_end - vma->vm_start, - ®ion_to_map, &virt_offset)) -return DO_MAP_REGION_INVALID ; - phys_offset = region_to_map.start; - map_length = region_to_map.length_bytes; - - virt_base = vma->vm_start + virt_offset; - bar_index = - gasket_get_bar_index(gasket_dev, - (vma->vm_pgoff << PAGE_SHIFT) + -
driver_desc->legacy_mmap_address_offset);drivers/staging/gasket/gasket_core.c deleted +0
-5- -if (bar_index <0 ) -return DO_MAP_REGION_INVALID ; - - phys_base = gasket_dev->bar_data[bar_index].phys_base +
phys_offset;drivers/staging/gasket/gasket_core.c deleted +0
-6-while (mapped_bytes < map_length) { -/* -* io_remap_pfn_range can take a while, so we chunk its -* calls and call cond_resched between each. -*/ - chunk_size = min(max_chunk_size, map_length -
mapped_bytes);drivers/staging/gasket/gasket_core.c deleted +0
-22- -cond_resched (); - ret =io_remap_pfn_range (vma, virt_base + mapped_bytes, - (phys_base + mapped_bytes) >> -PAGE_SHIFT , chunk_size, - vma->vm_page_prot); -if (ret) { -dev_err (gasket_dev->dev, -"Error remapping PFN range.\n" ); - goto fail; - } - mapped_bytes += chunk_size; - } - -return DO_MAP_REGION_SUCCESS ; - -fail: -/* Unmap the partial chunk we mapped. */ - mappable_region->length_bytes = mapped_bytes; -if (gasket_mm_unmap_region (gasket_dev, vma, mappable_region)) - dev_err(gasket_dev->dev, - "Error unmapping partial region 0x%lx (0x%lxbytes)\n",
drivers/staging/gasket/gasket_core.c deleted +0
-34- (ulong )virt_offset, - (ulong)mapped_bytes); - -return DO_MAP_REGION_FAILURE ; -} - -/* Map a region of coherent memory. */ -static int gasket_mmap_coherent (struct gasket_dev *gasket_dev, -struct vm_area_struct *vma) -{ -const struct gasket_driver_desc *driver_desc = - gasket_dev->internal_desc->driver_desc; -const ulong requested_length = vma->vm_end - vma->vm_start; -int ret; -ulong permissions; - -if (requested_length ==0 || requested_length > - gasket_dev->coherent_buffer.length_bytes) { -trace_gasket_mmap_exit (-EINVAL ); -return -EINVAL ; - } - - permissions = driver_desc->coherent_buffer_description.permissions; -if (!gasket_mmap_has_permissions (gasket_dev, vma, permissions)) { -dev_err (gasket_dev->dev,"Permission checking failed.\n" ); -trace_gasket_mmap_exit (-EPERM ); -return -EPERM ; - } - - vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); - - ret = remap_pfn_range(vma, vma->vm_start, - (gasket_dev->coherent_buffer.phys_base) >> - PAGE_SHIFT, requested_length,
vma->vm_page_prot);drivers/staging/gasket/gasket_core.c deleted +0
-2-if (ret) { - dev_err(gasket_dev->dev, "Error remapping PFN rangeerr=%d.\n",
drivers/staging/gasket/gasket_core.c deleted +0
-25- ret); -trace_gasket_mmap_exit (ret); -return ret; - } - -/* Record the user virtual to dma_address mapping that was -* created by the kernel. -*/ -gasket_set_user_virt (gasket_dev, requested_length, - gasket_dev->coherent_buffer.phys_base, - vma->vm_start); -return 0 ; -} - -/* Map a device's BARs into user space. */ -static int gasket_mmap (struct file *filp,struct vm_area_struct *vma) -{ -int i, ret; -int bar_index; -int has_mapped_anything =0 ; -ulong permissions; -ulong raw_offset, vma_size; -bool is_coherent_region; -const struct gasket_driver_desc *driver_desc; - struct gasket_dev *gasket_dev = (struct gasket_dev*)filp->private_data;
drivers/staging/gasket/gasket_core.c deleted +0
-24-const struct gasket_bar_desc *bar_desc; -struct gasket_mappable_region *map_regions =NULL ; -int num_map_regions =0 ; -enum do_map_region_status map_status; - - driver_desc = gasket_dev->internal_desc->driver_desc; - -if (vma->vm_start & ~PAGE_MASK ) { -dev_err (gasket_dev->dev, -"Base address not page-aligned: 0x%lx\n" , - vma->vm_start); -trace_gasket_mmap_exit (-EINVAL ); -return -EINVAL ; - } - -/* Calculate the offset of this range into physical mem. */ - raw_offset = (vma->vm_pgoff <<PAGE_SHIFT ) + - driver_desc->legacy_mmap_address_offset; - vma_size = vma->vm_end - vma->vm_start; -trace_gasket_mmap_entry (gasket_dev->dev_info.name, raw_offset, - vma_size); - -/* -* Check if the raw offset is within a bar region. If not, check if it
drivers/staging/gasket/gasket_core.c deleted +0
-4-* is a coherent region. -*/ - bar_index =gasket_get_bar_index (gasket_dev, raw_offset); - is_coherent_region = gasket_is_coherent_region(driver_desc,
raw_offset);drivers/staging/gasket/gasket_core.c deleted +0
-10-if (bar_index <0 && !is_coherent_region) { -dev_err (gasket_dev->dev, -"Unable to find matching bar for address 0x%lx\n" , - raw_offset); -trace_gasket_mmap_exit (bar_index); -return bar_index; - } -if (bar_index >0 && is_coherent_region) { - dev_err(gasket_dev->dev, - "double matching bar and coherent buffers foraddress 0x%lx\n",
drivers/staging/gasket/gasket_core.c deleted +0
-11- raw_offset); -trace_gasket_mmap_exit (bar_index); -return -EINVAL ; - } - - vma->vm_private_data = gasket_dev; - -if (is_coherent_region) -return gasket_mmap_coherent (gasket_dev, vma); - -/* Everything in the rest of this function is for normal BAR mapping. */
drivers/staging/gasket/gasket_core.c deleted +0
-18- -/* -* Subtract the base of the bar from the raw offset to get the -* memory location within the bar to map. -*/ - bar_desc = &driver_desc->bar_descriptions[bar_index]; - permissions = bar_desc->permissions; -if (!gasket_mmap_has_permissions (gasket_dev, vma, permissions)) { -dev_err (gasket_dev->dev,"Permission checking failed.\n" ); -trace_gasket_mmap_exit (-EPERM ); -return -EPERM ; - } - -if (driver_desc->get_mappable_regions_cb) { - ret = driver_desc->get_mappable_regions_cb(gasket_dev, - bar_index, - &map_regions, -
&num_map_regions);drivers/staging/gasket/gasket_core.c deleted +0
-23-if (ret) -return ret; - }else { -if (!gasket_mmap_has_permissions (gasket_dev, vma, - bar_desc->permissions)) { -dev_err (gasket_dev->dev, -"Permission checking failed.\n" ); -trace_gasket_mmap_exit (-EPERM ); -return -EPERM ; - } - num_map_regions = bar_desc->num_mappable_regions; - map_regions =kcalloc (num_map_regions, -sizeof (*bar_desc->mappable_regions), -GFP_KERNEL ); -if (map_regions) { -memcpy (map_regions, bar_desc->mappable_regions, - num_map_regions * - sizeof(*bar_desc->mappable_regions)); - } - } - -if (!map_regions || num_map_regions ==0 ) { - dev_err(gasket_dev->dev, "No mappable regionsreturned!\n");
drivers/staging/gasket/gasket_core.c deleted +0
-7-return -EINVAL ; - } - -/* Marks the VMA's pages as uncacheable. */ - vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); -for (i =0 ; i < num_map_regions; i++) { - map_status = do_map_region(gasket_dev, vma,&map_regions[i]);
drivers/staging/gasket/gasket_core.c deleted +0
-31-/* Try the next region if this one was not mappable. */ -if (map_status ==DO_MAP_REGION_INVALID ) -continue ; -if (map_status ==DO_MAP_REGION_FAILURE ) { - ret = -ENOMEM ; - goto fail; - } - - has_mapped_anything =1 ; - } - -kfree (map_regions); - -/* If we could not map any memory, the request was invalid. */ -if (!has_mapped_anything) { -dev_err (gasket_dev->dev, -"Map request did not contain a valid region.\n" ); -trace_gasket_mmap_exit (-EINVAL ); -return -EINVAL ; - } - -trace_gasket_mmap_exit (0 ); -return 0 ; - -fail: -/* Need to unmap any mapped ranges. */ - num_map_regions = i; -for (i =0 ; i < num_map_regions; i++) -if (gasket_mm_unmap_region (gasket_dev, vma, - &bar_desc->mappable_regions[i])) - dev_err(gasket_dev->dev, "Error unmapping range%d.\n",
drivers/staging/gasket/gasket_core.c deleted +0
-10- i); -kfree (map_regions); - -return ret; -} - -/* -* Open the char device file. -* -* If the open is for writing, and the device is not owned, this process becomes
- * the owner. If the open is for writing and the device is already owned by
- * some other process, it is an error. If this process is the owner, increment
- * the open count.
- *
- * Returns 0 if successful, a negative error number otherwise.
- */drivers/staging/gasket/gasket_core.c deleted +0
-21-static int gasket_open (struct inode *inode,struct file *filp) -{ -int ret; -struct gasket_dev *gasket_dev; -const struct gasket_driver_desc *driver_desc; -struct gasket_ownership *ownership; -char task_name[TASK_COMM_LEN ]; -struct gasket_cdev_info *dev_info = - container_of(inode->i_cdev, struct gasket_cdev_info, cdev); -struct pid_namespace *pid_ns =task_active_pid_ns (current); -bool is_root =ns_capable (pid_ns->user_ns,CAP_SYS_ADMIN ); - - gasket_dev = dev_info->gasket_dev_ptr; - driver_desc = gasket_dev->internal_desc->driver_desc; - ownership = &dev_info->ownership; -get_task_comm (task_name, current); - filp->private_data = gasket_dev; - inode->i_size =0 ; - - dev_dbg(gasket_dev->dev, - "Attempting to open with tgid %u (%s) (f_mode: 0%03o,
fmode_write: %dis_root: %u)\n",drivers/staging/gasket/gasket_core.c deleted +0
-16- current->tgid, task_name, filp->f_mode, - (filp->f_mode & FMODE_WRITE), is_root); - -/* Always allow non-writing accesses. */ -if (!(filp->f_mode &FMODE_WRITE )) { -dev_dbg (gasket_dev->dev,"Allowing read-only opening.\n" ); -return 0 ; - } - -mutex_lock (&gasket_dev->mutex); - -dev_dbg (gasket_dev->dev, -"Current owner open count (owning tgid %u): %d.\n" , - ownership->owner, ownership->write_open_count); - -/* Opening a node owned by another TGID is an error (unless root) */
drivers/staging/gasket/gasket_core.c deleted +0
-37-if (ownership->is_owned && ownership->owner != current->tgid && - !is_root) { -dev_err (gasket_dev->dev, -"Process %u is opening a node held by %u.\n" , - current->tgid, ownership->owner); -mutex_unlock (&gasket_dev->mutex); -return -EPERM ; - } - -/* If the node is not owned, assign it to the current TGID. */ -if (!ownership->is_owned) { - ret =gasket_check_and_invoke_callback_nolock (gasket_dev, - driver_desc->device_open_cb); -if (ret) { -dev_err (gasket_dev->dev, -"Error in device open cb: %d\n" , ret); -mutex_unlock (&gasket_dev->mutex); -return ret; - } - ownership->is_owned =1 ; - ownership->owner = current->tgid; -dev_dbg (gasket_dev->dev,"Device owner is now tgid %u\n" , - ownership->owner); - } - - ownership->write_open_count++; - -dev_dbg (gasket_dev->dev,"New open count (owning tgid %u): %d\n" , - ownership->owner, ownership->write_open_count); - -mutex_unlock (&gasket_dev->mutex); -return 0 ; -} - -/* -* Called on a close of the device file. If this process is the owner, -* decrement the open count. On last close by the owner, free up buffers and
- * eventfd contexts, and release ownership.
- *
- * Returns 0 if successful, a negative error number otherwise.
- */drivers/staging/gasket/gasket_core.c deleted +0
-20-static int gasket_release (struct inode *inode,struct file *file) -{ -int i; -struct gasket_dev *gasket_dev; -struct gasket_ownership *ownership; -const struct gasket_driver_desc *driver_desc; -char task_name[TASK_COMM_LEN ]; -struct gasket_cdev_info *dev_info = - container_of(inode->i_cdev, struct gasket_cdev_info, cdev); -struct pid_namespace *pid_ns =task_active_pid_ns (current); -bool is_root =ns_capable (pid_ns->user_ns,CAP_SYS_ADMIN ); - - gasket_dev = dev_info->gasket_dev_ptr; - driver_desc = gasket_dev->internal_desc->driver_desc; - ownership = &dev_info->ownership; -get_task_comm (task_name, current); -mutex_lock (&gasket_dev->mutex); - - dev_dbg(gasket_dev->dev, - "Releasing device node. Call origin: tgid %u (%s) (f_mode:0%03o,
fmode_write: %d,is_root: %u)\n",drivers/staging/gasket/gasket_core.c deleted +0
-3- current->tgid, task_name, file->f_mode, - (file->f_mode & FMODE_WRITE), is_root); - dev_dbg(gasket_dev->dev, "Current open count (owning tgid %u):%d\n",
drivers/staging/gasket/gasket_core.c deleted +0
-10- ownership->owner, ownership->write_open_count); - -if (file->f_mode &FMODE_WRITE ) { - ownership->write_open_count--; -if (ownership->write_open_count ==0 ) { -dev_dbg (gasket_dev->dev,"Device is now free\n" ); - ownership->is_owned =0 ; - ownership->owner =0 ; - -/* Forces chip reset before we unmap the page tables. */
drivers/staging/gasket/gasket_core.c deleted +0
-3- driver_desc->device_reset_cb (gasket_dev); - -for (i =0 ; i < driver_desc->num_page_tables; ++i){
drivers/staging/gasket/gasket_core.c deleted +0
-43-gasket_page_table_unmap_all (gasket_dev->page_table[i]); -gasket_page_table_garbage_collect (gasket_dev->page_table[i]); -gasket_free_coherent_memory_all (gasket_dev, i); - } - -/* Closes device, enters power save. */ -gasket_check_and_invoke_callback_nolock (gasket_dev, - driver_desc->device_close_cb); - } - } - -dev_dbg (gasket_dev->dev,"New open count (owning tgid %u): %d\n" , - ownership->owner, ownership->write_open_count); -mutex_unlock (&gasket_dev->mutex); -return 0 ; -} - -/* -* Gasket ioctl dispatch function. -* -* Check if the ioctl is a generic ioctl. If not, pass the ioctl to the -* ioctl_handler_cb registered in the driver description. -* If the ioctl is a generic ioctl, pass it to gasket_ioctl_handler. -*/ -static long gasket_ioctl (struct file *filp,uint cmd,ulong arg) -{ -struct gasket_dev *gasket_dev; -const struct gasket_driver_desc *driver_desc; -void __user *argp = (void __user *)arg; -char path[256 ]; - - gasket_dev = (struct gasket_dev *)filp->private_data; - driver_desc = gasket_dev->internal_desc->driver_desc; -if (!driver_desc) { -dev_dbg (gasket_dev->dev, -"Unable to find device descriptor for file %s\n" , -d_path (&filp->f_path, path,256 )); -return -ENODEV ; - } - -if (!gasket_is_supported_ioctl (cmd)) { -/* -* The ioctl handler is not a standard Gasket callback, since
drivers/staging/gasket/gasket_core.c deleted +0
-5-* it requires different arguments. This means we can't use -* check_and_invoke_callback. -*/ -if (driver_desc->ioctl_handler_cb) - return driver_desc->ioctl_handler_cb(filp, cmd,argp);
drivers/staging/gasket/gasket_core.c deleted +0
-2- - dev_dbg(gasket_dev->dev, "Received unknown ioctl 0x%x\n",cmd);
drivers/staging/gasket/gasket_core.c deleted +0
-28-return -EINVAL ; - } - -return gasket_handle_ioctl (filp, cmd, argp); -} - -/* File operations for all Gasket devices. */ -static const struct file_operations gasket_file_ops = { - .owner =THIS_MODULE , - .llseek = no_llseek, - .mmap = gasket_mmap, - .open = gasket_open, - .release = gasket_release, - .unlocked_ioctl = gasket_ioctl, -}; - -/* Perform final init and marks the device as active. */ -int gasket_enable_device (struct gasket_dev *gasket_dev) -{ -int tbl_idx; -int ret; -const struct gasket_driver_desc *driver_desc = - gasket_dev->internal_desc->driver_desc; - - ret =gasket_interrupt_init (gasket_dev); -if (ret) { - dev_err(gasket_dev->dev, - "Critical failure to allocate interrupts: %d\n",ret);
drivers/staging/gasket/gasket_core.c deleted +0
-5-gasket_interrupt_cleanup (gasket_dev); -return ret; - } - - for (tbl_idx = 0; tbl_idx < driver_desc->num_page_tables;tbl_idx++) {
drivers/staging/gasket/gasket_core.c deleted +0
-3-dev_dbg (gasket_dev->dev,"Initializing page table %d.\n" , - tbl_idx); - ret =gasket_page_table_init(&gasket_dev->page_table[tbl_idx], - &gasket_dev->bar_data[driver_desc->page_table_bar_index], -
&driver_desc->page_table_configs[tbl_idx],drivers/staging/gasket/gasket_core.c deleted +0
-32- gasket_dev->dev, - gasket_dev->pci_dev); -if (ret) { -dev_err (gasket_dev->dev, -"Couldn't init page table %d: %d\n" , - tbl_idx, ret); -return ret; - } -/* -* Make sure that the page table is clear and set to simple -* addresses. -*/ -gasket_page_table_reset (gasket_dev->page_table[tbl_idx]); - } - -/* -* hardware_revision_cb returns a positive integer (the rev) if -* successful.) -*/ - ret =check_and_invoke_callback (gasket_dev, - driver_desc->hardware_revision_cb); -if (ret <0 ) { -dev_err (gasket_dev->dev, -"Error getting hardware revision: %d\n" , ret); -return ret; - } - gasket_dev->hardware_revision = ret; - -/* device_status_cb returns a device status, not an error code. */ - gasket_dev->status =gasket_get_hw_status (gasket_dev); -if (gasket_dev->status ==GASKET_STATUS_DEAD ) - dev_err(gasket_dev->dev, "Device reported asunhealthy.\n");
drivers/staging/gasket/gasket_core.c deleted +0
-24- - ret =gasket_add_cdev (&gasket_dev->dev_info, &gasket_file_ops, - driver_desc->module); -if (ret) -return ret; - -return 0 ; -} -EXPORT_SYMBOL (gasket_enable_device); - -static int __gasket_add_device (struct device *parent_dev, -struct gasket_internal_desc *internal_desc, -struct gasket_dev **gasket_devp) -{ -int ret; -struct gasket_dev *gasket_dev; -const struct gasket_driver_desc *driver_desc = - internal_desc->driver_desc; - - ret =gasket_alloc_dev (internal_desc, parent_dev, &gasket_dev); -if (ret) -return ret; -if (IS_ERR (gasket_dev->dev_info.device)) { - dev_err(parent_dev, "Cannot create %s device %s [ret =%ld]\n",
drivers/staging/gasket/gasket_core.c deleted +0
-29- driver_desc->name, gasket_dev->dev_info.name, - PTR_ERR(gasket_dev->dev_info.device)); - ret = -ENODEV ; - goto free_gasket_dev; - } - - ret =gasket_sysfs_create_mapping (gasket_dev->dev_info.device, - gasket_dev); -if (ret) - goto remove_device; - - ret =gasket_sysfs_create_entries (gasket_dev->dev_info.device, - gasket_sysfs_generic_attrs); -if (ret) - goto remove_sysfs_mapping; - - *gasket_devp = gasket_dev; -return 0 ; - -remove_sysfs_mapping: -gasket_sysfs_remove_mapping (gasket_dev->dev_info.device); -remove_device: -device_destroy (internal_desc->class, gasket_dev->dev_info.devt); -free_gasket_dev: -gasket_free_dev (gasket_dev); -return ret; -} - -static void __gasket_remove_device(struct gasket_internal_desc
*internal_desc,drivers/staging/gasket/gasket_core.c deleted +0
-12- struct gasket_dev *gasket_dev) -{ -gasket_sysfs_remove_mapping (gasket_dev->dev_info.device); -device_destroy (internal_desc->class, gasket_dev->dev_info.devt); -gasket_free_dev (gasket_dev); -} - -/* -* Add PCI gasket device. -* -* Called by Gasket device probe function. -* Allocates device metadata and maps device memory. The device driver must
- * callgasket_enable_deviceafter driver init is complete to place the device
- * in active use.
- */drivers/staging/gasket/gasket_core.c deleted +0
-31-int gasket_pci_add_device (struct pci_dev *pci_dev, -struct gasket_dev **gasket_devp) -{ -int ret; -struct gasket_internal_desc *internal_desc; -struct gasket_dev *gasket_dev; -struct device *parent; - -dev_dbg (&pci_dev->dev,"add PCI gasket device\n" ); - -mutex_lock (&g_mutex); - internal_desc =lookup_pci_internal_desc (pci_dev); -mutex_unlock (&g_mutex); -if (!internal_desc) { -dev_err (&pci_dev->dev, -"PCI add device called for unknown driver type\n" ); -return -ENODEV ; - } - - parent = &pci_dev->dev; - ret =__gasket_add_device (parent, internal_desc, &gasket_dev); -if (ret) -return ret; - - gasket_dev->pci_dev = pci_dev; - ret =gasket_setup_pci (pci_dev, gasket_dev); -if (ret) - goto cleanup_pci; - -/* -* Once we've created the mapping structures successfully, attempt to
drivers/staging/gasket/gasket_core.c deleted +0
-4-* create a symlink to the pci directory of this object. -*/ - ret = sysfs_create_link(&gasket_dev->dev_info.device->kobj, - &pci_dev->dev.kobj,
dev_name(&pci_dev->dev));drivers/staging/gasket/gasket_core.c deleted +0
-114-if (ret) { -dev_err (gasket_dev->dev, -"Cannot create sysfs pci link: %d\n" , ret); - goto cleanup_pci; - } - - *gasket_devp = gasket_dev; -return 0 ; - -cleanup_pci: -gasket_cleanup_pci (gasket_dev); -__gasket_remove_device (internal_desc, gasket_dev); -return ret; -} -EXPORT_SYMBOL (gasket_pci_add_device); - -/* Remove a PCI gasket device. */ -void gasket_pci_remove_device (struct pci_dev *pci_dev) -{ -int i; -struct gasket_internal_desc *internal_desc; -struct gasket_dev *gasket_dev =NULL ; -/* Find the device desc. */ -mutex_lock (&g_mutex); - internal_desc =lookup_pci_internal_desc (pci_dev); -if (!internal_desc) { -mutex_unlock (&g_mutex); -return ; - } -mutex_unlock (&g_mutex); - -/* Now find the specific device */ -mutex_lock (&internal_desc->mutex); -for (i =0 ; i <GASKET_DEV_MAX ; i++) { -if (internal_desc->devs[i] && - internal_desc->devs[i]->pci_dev == pci_dev) { - gasket_dev = internal_desc->devs[i]; -break ; - } - } -mutex_unlock (&internal_desc->mutex); - -if (!gasket_dev) -return ; - -dev_dbg (gasket_dev->dev,"remove %s PCI gasket device\n" , - internal_desc->driver_desc->name); - -gasket_cleanup_pci (gasket_dev); -__gasket_remove_device (internal_desc, gasket_dev); -} -EXPORT_SYMBOL (gasket_pci_remove_device); - -/** -* Lookup a name by number in a num_name table. -* @num: Number to lookup. -* @table: Array of num_name structures, the table for the lookup. -* -* Description: Searches for num in the table. If found, the -* corresponding name is returned; otherwise NULL -* is returned. -* -* The table must have a NULL name pointer at the end. -*/ -const char *gasket_num_name_lookup (uint num, -const struct gasket_num_name *table) -{ -uint i =0 ; - -while (table[i].snn_name) { -if (num == table[i].snn_num) -break ; - ++i; - } - -return table[i].snn_name; -} -EXPORT_SYMBOL (gasket_num_name_lookup); - -int gasket_reset (struct gasket_dev *gasket_dev) -{ -int ret; - -mutex_lock (&gasket_dev->mutex); - ret =gasket_reset_nolock (gasket_dev); -mutex_unlock (&gasket_dev->mutex); -return ret; -} -EXPORT_SYMBOL (gasket_reset); - -int gasket_reset_nolock (struct gasket_dev *gasket_dev) -{ -int ret; -int i; -const struct gasket_driver_desc *driver_desc; - - driver_desc = gasket_dev->internal_desc->driver_desc; -if (!driver_desc->device_reset_cb) -return 0 ; - - ret = driver_desc->device_reset_cb (gasket_dev); -if (ret) { -dev_dbg (gasket_dev->dev,"Device reset cb returned %d.\n" , - ret); -return ret; - } - -/* Reinitialize the page tables and interrupt framework. */ -for (i =0 ; i < driver_desc->num_page_tables; ++i) -gasket_page_table_reset (gasket_dev->page_table[i]); - - ret =gasket_interrupt_reinit (gasket_dev); -if (ret) { - dev_dbg(gasket_dev->dev, "Unable to reinit interrupts:%d.\n",
drivers/staging/gasket/gasket_core.c deleted +0
-19- ret); -return ret; - } - -/* Get current device health. */ - gasket_dev->status =gasket_get_hw_status (gasket_dev); -if (gasket_dev->status ==GASKET_STATUS_DEAD ) { -dev_dbg (gasket_dev->dev,"Device reported as dead.\n" ); -return -EINVAL ; - } - -return 0 ; -} -EXPORT_SYMBOL (gasket_reset_nolock); - -gasket_ioctl_permissions_cb_t -gasket_get_ioctl_permissions_cb (struct gasket_dev *gasket_dev) -{ -return
gasket_dev->internal_desc->driver_desc->ioctl_permissions_cb;drivers/staging/gasket/gasket_core.c deleted +0
-7-} -EXPORT_SYMBOL (gasket_get_ioctl_permissions_cb); - -/* Get the driver structure for a given gasket_dev. -* @dev: pointer to gasket_dev, implementing the requested driver. -*/ -const struct gasket_driver_desc *gasket_get_driver_desc(struct gasket_dev*dev)
drivers/staging/gasket/gasket_core.c deleted +0
-23-{ -return dev->internal_desc->driver_desc; -} - -/* Get the device structure for a given gasket_dev. -* @dev: pointer to gasket_dev, implementing the requested driver. -*/ -struct device *gasket_get_device (struct gasket_dev *dev) -{ -return dev->dev; -} - -/** -* Asynchronously waits on device. -* @gasket_dev: Device struct. -* @bar: Bar -* @offset: Register offset -* @mask: Register mask -* @val: Expected value -* @max_retries: number of sleep periods -* @delay_ms: Timeout in milliseconds -* -* Description: Busy waits for a specific combination of bits to be set on a
- * Gasket register.
- **/drivers/staging/gasket/gasket_core.c deleted +0
-15-int gasket_wait_with_reschedule (struct gasket_dev *gasket_dev,int bar, -u64 offset,u64 mask,u64 val, -uint max_retries,u64 delay_ms) -{ -uint retries =0 ; -u64 tmp; - -while (retries < max_retries) { - tmp =gasket_dev_read_64 (gasket_dev, bar, offset); -if ((tmp & mask) == val) -return 0 ; -msleep (delay_ms); - retries++; - } - dev_dbg(gasket_dev->dev, "%s timeout: reg %llx timeout (%llums)\n",
drivers/staging/gasket/gasket_core.c deleted +0
-27- __func__, offset, max_retries * delay_ms); -return -ETIMEDOUT ; -} -EXPORT_SYMBOL (gasket_wait_with_reschedule); - -/* See gasket_core.h for description. */ -int gasket_register_device (const struct gasket_driver_desc *driver_desc) -{ -int i, ret; -int desc_idx =-1 ; -struct gasket_internal_desc *internal; - -pr_debug ("Loading %s driver version %s\n" , driver_desc->name, - driver_desc->driver_version); -/* Check for duplicates and find a free slot. */ -mutex_lock (&g_mutex); - -for (i =0 ; i <GASKET_FRAMEWORK_DESC_MAX ; i++) { -if (g_descs[i].driver_desc == driver_desc) { -pr_err ("%s driver already loaded/registered\n" , - driver_desc->name); -mutex_unlock (&g_mutex); -return -EBUSY ; - } - } - -/* This and the above loop could be combined, but this reads easier. */
drivers/staging/gasket/gasket_core.c deleted +0
-18-for (i =0 ; i <GASKET_FRAMEWORK_DESC_MAX ; i++) { -if (!g_descs[i].driver_desc) { - g_descs[i].driver_desc = driver_desc; - desc_idx = i; -break ; - } - } -mutex_unlock (&g_mutex); - -if (desc_idx ==-1 ) { -pr_err ("too many drivers loaded, max %d\n" , -GASKET_FRAMEWORK_DESC_MAX ); -return -EBUSY ; - } - - internal = &g_descs[desc_idx]; -mutex_init (&internal->mutex); - memset(internal->devs, 0, sizeof(struct gasket_dev *) *
GASKET_DEV_MAX);drivers/staging/gasket/gasket_core.c deleted +0
-12- internal->class = -class_create (driver_desc->module, driver_desc->name); - -if (IS_ERR (internal->class)) { -pr_err ("Cannot register %s class [ret=%ld]\n" , - driver_desc->name,PTR_ERR (internal->class)); - ret =PTR_ERR (internal->class); - goto unregister_gasket_driver; - } - - ret = register_chrdev_region(MKDEV(driver_desc->major, - driver_desc->minor),
GASKET_DEV_MAX,drivers/staging/gasket/gasket_core.c deleted +0
-22- driver_desc->name); -if (ret) { -pr_err ("cannot register %s char driver [ret=%d]\n" , - driver_desc->name, ret); - goto destroy_class; - } - -return 0 ; - -destroy_class: -class_destroy (internal->class); - -unregister_gasket_driver: -mutex_lock (&g_mutex); - g_descs[desc_idx].driver_desc =NULL ; -mutex_unlock (&g_mutex); -return ret; -} -EXPORT_SYMBOL (gasket_register_device); - -/* See gasket_core.h for description. */ -void gasket_unregister_device(const struct gasket_driver_desc
*driver_desc)drivers/staging/gasket/gasket_core.c deleted +0
-22-{ -int i, desc_idx; -struct gasket_internal_desc *internal_desc =NULL ; - -mutex_lock (&g_mutex); -for (i =0 ; i <GASKET_FRAMEWORK_DESC_MAX ; i++) { -if (g_descs[i].driver_desc == driver_desc) { - internal_desc = &g_descs[i]; - desc_idx = i; -break ; - } - } - -if (!internal_desc) { -mutex_unlock (&g_mutex); -pr_err ("request to unregister unknown desc: %s, %d:%d\n" , - driver_desc->name, driver_desc->major, - driver_desc->minor); -return ; - } - - unregister_chrdev_region(MKDEV(driver_desc->major,
driver_desc->minor),drivers/staging/gasket/gasket_core.c deleted +0
-33- GASKET_DEV_MAX); - -class_destroy (internal_desc->class); - -/* Finally, effectively "remove" the driver. */ - g_descs[desc_idx].driver_desc =NULL ; -mutex_unlock (&g_mutex); - -pr_debug ("removed %s driver\n" , driver_desc->name); -} -EXPORT_SYMBOL (gasket_unregister_device); - -static int __init gasket_init (void ) -{ -int i; - -mutex_lock (&g_mutex); -for (i =0 ; i <GASKET_FRAMEWORK_DESC_MAX ; i++) { - g_descs[i].driver_desc =NULL ; -mutex_init (&g_descs[i].mutex); - } - -gasket_sysfs_init (); - -mutex_unlock (&g_mutex); -return 0 ; -} - -MODULE_DESCRIPTION ("Google Gasket driver framework" ); -MODULE_VERSION (GASKET_FRAMEWORK_VERSION ); -MODULE_LICENSE ("GPL v2" ); -MODULE_AUTHOR ("Rob Springer <[email protected]>" ); -module_init (gasket_init);drivers/staging/gasket/gasket_core.h deleted +0
-3@@ -1,638 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* Gasket generic driver. Defines the set of data types and functions necessary
- * to define a driver using the Gasket generic driver framework.
- *
- * Copyright (C) 2018 Google, Inc.
- */drivers/staging/gasket/gasket_core.h deleted +0
-20-#ifndef __GASKET_CORE_H__ -#define __GASKET_CORE_H__ - -#include <linux/cdev.h> -#include <linux/compiler.h> -#include <linux/device.h> -#include <linux/init.h> -#include <linux/module.h> -#include <linux/pci.h> -#include <linux/sched.h> -#include <linux/slab.h> - -#include "gasket_constants.h" - -/** -* struct gasket_num_name - Map numbers to names. -* @ein_num: Number. -* @ein_name: Name associated with the number, a char pointer. -* -* This structure maps numbers to names. It is used to provide printable enum
- * names, e.g {0, "DEAD"} or {1, "ALIVE"}.
- */drivers/staging/gasket/gasket_core.h deleted +0
-9-struct gasket_num_name { -uint snn_num; -const char *snn_name; -}; - -/* -* Register location for packed interrupts. -* Each value indicates the location of an interrupt field (in units of -* gasket_driver_desc->interrupt_pack_width) within the containing register.
- * In other words, this indicates the shift to use when creating a mask to
- * extract/set bits within a register for a given interrupt.
- */drivers/staging/gasket/gasket_core.h deleted +0
-15-enum gasket_interrupt_packing { -PACK_0 =0 , -PACK_1 =1 , -PACK_2 =2 , -PACK_3 =3 , -UNPACKED =4 , -}; - -/* Type of the interrupt supported by the device. */ -enum gasket_interrupt_type { -PCI_MSIX =0 , -}; - -/* -* Used to describe a Gasket interrupt. Contains an interrupt index, a register,
- * and packing data for that interrupt. The register and packing data
- * fields are relevant only forPCI_MSIXinterrupt type and can be
- * set to 0 for everything else.
- */drivers/staging/gasket/gasket_core.h deleted +0
-6-struct gasket_interrupt_desc { -/* Device-wide interrupt index/number. */ -int index; -/* The register offset controlling this interrupt. */ -u64 reg; -/* The location of this interrupt inside register reg, if packed. */
drivers/staging/gasket/gasket_core.h deleted +0
-16-int packing; -}; - -/* -* This enum is used to identify memory regions being part of the physical -* memory that belongs to a device. -*/ -enum mappable_area_type { -PCI_BAR =0 ,/* Default */ -BUS_REGION ,/* For SYSBUS devices, i.e. AXI etc... */ -COHERENT_MEMORY -}; - -/* -* Metadata for each BAR mapping. -* This struct is used so as to track PCI memory, I/O space, AXI and coherent
- * memory area... i.e. memory objects which can be referenced in the device's
- * mmap function.
- */drivers/staging/gasket/gasket_core.h deleted +0
-29-struct gasket_bar_data { -/* Virtual base address. */ -u8 __iomem *virt_base; - -/* Physical base address. */ -ulong phys_base; - -/* Length of the mapping. */ -ulong length_bytes; - -/* Type of mappable area */ -enum mappable_area_type type; -}; - -/* Maintains device open ownership data. */ -struct gasket_ownership { -/* 1 if the device is owned, 0 otherwise. */ -int is_owned; - -/* TGID of the owner. */ -pid_t owner; - -/* Count of current device opens in write mode. */ -int write_open_count; -}; - -/* Page table modes of operation. */ -enum gasket_page_table_mode { -/* The page table is partitionable as normal, all simple by default. */
drivers/staging/gasket/gasket_core.h deleted +0
-25-GASKET_PAGE_TABLE_MODE_NORMAL , - -/* All entries are always simple. */ -GASKET_PAGE_TABLE_MODE_SIMPLE , - -/* All entries are always extended. No extended bit is used. */ - GASKET_PAGE_TABLE_MODE_EXTENDED, -}; - -/* Page table configuration. One per table. */ -struct gasket_page_table_config { -/* The identifier/index of this page table. */ -int id; - -/* The operation mode of this page table. */ -enum gasket_page_table_mode mode; - -/* Total (first-level) entries in this page table. */ -ulong total_entries; - -/* Base register for the page table. */ -int base_reg; - -/* -* Register containing the extended page table. This value is unused in
- *GASKET_PAGE_TABLE_MODE_SIMPLEandGASKET_PAGE_TABLE_MODE_EXTENDEDdrivers/staging/gasket/gasket_core.h deleted +0
-42-* modes. -*/ -int extended_reg; - -/* The bit index indicating whether a PT entry is extended. */ -int extended_bit; -}; - -/* Maintains information about a device node. */ -struct gasket_cdev_info { -/* The internal name of this device. */ -char name[GASKET_NAME_MAX ]; - -/* Device number. */ -dev_t devt; - -/* Kernel-internal device structure. */ -struct device *device; - -/* Character device for real. */ -struct cdev cdev; - -/* Flag indicating if cdev_add has been called for the devices. */ -int cdev_added; - -/* Pointer to the overall gasket_dev struct for this device. */ -struct gasket_dev *gasket_dev_ptr; - -/* Ownership data for the device in question. */ -struct gasket_ownership ownership; -}; - -/* Describes the offset and length of mmapable device BAR regions. */ -struct gasket_mappable_region { -u64 start; -u64 length_bytes; -}; - -/* Describe the offset, size, and permissions for a device bar. */ -struct gasket_bar_desc { -/* -* The size of each PCI BAR range, in bytes. If a value is 0, that BAR
drivers/staging/gasket/gasket_core.h deleted +0
-2-* will not be mapped into kernel space at all. -* For devices with 64 bit BARs, only elements 0, 2, and 4 should be
drivers/staging/gasket/gasket_core.h deleted +0
-2-* populated, and 1, 3, and 5 should be set to 0. -* For example, for a device mapping 1M in each of the first two 64-bit
- * BARs, this field would be set as {0x100000, 0,0x100000, 0, 0,
0 }drivers/staging/gasket/gasket_core.h deleted +0
-4-* (one number per bar_desc struct.) -*/ -u64 size; -/* The permissions for this bar. (Should be VM_WRITE/VM_READ/VM_EXEC,
drivers/staging/gasket/gasket_core.h deleted +0
-5-* and can be or'd.) If set to GASKET_NOMAP, the bar will -* not be used for mmapping. -*/ -ulong permissions; -/* The memory address corresponding to the base of this bar, if used. */
drivers/staging/gasket/gasket_core.h deleted +0
-17-u64 base; -/* The number of mappable regions in this bar. */ -int num_mappable_regions; - -/* The mappable subregions of this bar. */ -const struct gasket_mappable_region *mappable_regions; - -/* Type of mappable area */ -enum mappable_area_type type; -}; - -/* Describes the offset, size, and permissions for a coherent buffer. */ -struct gasket_coherent_buffer_desc { -/* The size of the coherent buffer. */ -u64 size; - -/* The permissions for this bar. (Should be VM_WRITE/VM_READ/VM_EXEC,
drivers/staging/gasket/gasket_core.h deleted +0
-31-* and can be or'd.) If set to GASKET_NOMAP, the bar will -* not be used for mmaping. -*/ -ulong permissions; - -/* device side address. */ -u64 base; -}; - -/* Coherent buffer structure. */ -struct gasket_coherent_buffer { -/* Virtual base address. */ -u8 *virt_base; - -/* Physical base address. */ -ulong phys_base; - -/* Length of the mapping. */ -ulong length_bytes; -}; - -/* Description of Gasket-specific permissions in the mmap field. */ -enum gasket_mapping_options {GASKET_NOMAP =0 }; - -/* This struct represents an undefined bar that should never be mapped. */ -#define GASKET_UNUSED_BAR \ - { \ - 0, GASKET_NOMAP, 0, 0, NULL, 0 \ - } - -/* Internal data for a Gasket device. See gasket_core.c for more information. */
drivers/staging/gasket/gasket_core.h deleted +0
-35-struct gasket_internal_desc ;Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
implementation. */
drivers/staging/gasket/gasket_core.h deleted +0
-37Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
address a
- * type of device to be administered via the Gasket generic driver.
- *
- * Device IDs are per-driver. In other words, two drivers using the Gasket
- * framework will each have a distinct device 0 (for example).
- */drivers/staging/gasket/gasket_core.h deleted +0
-43Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
be 0
drivers/staging/gasket/gasket_core.h deleted +0
-18Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*/
drivers/staging/gasket/gasket_core.h deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
bit
- * width is supported for each interrupt mapping
(unpacked/"full-width"
- * interrupts are always supported). This value specifies that
width. Ifdrivers/staging/gasket/gasket_core.h deleted +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
write
drivers/staging/gasket/gasket_core.h deleted +0
-22Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
the
drivers/staging/gasket/gasket_core.h deleted +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
closed.
drivers/staging/gasket/gasket_core.h deleted +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
opposed
- * to per-fd cleanup (which should be handled bydevice_release_cb).drivers/staging/gasket/gasket_core.h deleted +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
memory.
drivers/staging/gasket/gasket_core.h deleted +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
on the
drivers/staging/gasket/gasket_core.h deleted +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mappable_regions.drivers/staging/gasket/gasket_core.h deleted +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
which
- * regions of device memory may be mapped by the current process.
Thisdrivers/staging/gasket/gasket_core.h deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
**mappable_regions,
drivers/staging/gasket/gasket_core.h deleted +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
session.
drivers/staging/gasket/gasket_core.h deleted +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
callback
- * isn't specified a default routine will be used, that only
allows the
- * original device opener (i.e, the "owner") to execute
state-affectingdrivers/staging/gasket/gasket_core.h deleted +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
session.
drivers/staging/gasket/gasket_core.h deleted +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
ioctls
drivers/staging/gasket/gasket_core.h deleted +0
-10Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
return
drivers/staging/gasket/gasket_core.h deleted +0
-30Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
must
- * exist until the matching call togasket_unregister_device.
- * This function should be called from your driver'smodule_initfunction.
- */drivers/staging/gasket/gasket_core.h deleted +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
been
- * passed togasket_register_devicein a previous call.
- *
- * This function should be called from your driver'smodule_exitfunction.
- */drivers/staging/gasket/gasket_core.h deleted +0
-19Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
othewrise.
- *gasket_reset_nolockwill not lock the mutex,gasket_resetwill.
- *
- */drivers/staging/gasket/gasket_core.h deleted +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
own
- * file in the future.
- */drivers/staging/gasket/gasket_core.h deleted +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*map_region);drivers/staging/gasket/gasket_core.h deleted +0
-19Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
bar,
drivers/staging/gasket/gasket_core.h deleted +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
readq_relaxed(&gasket_dev->bar_data[bar].virt_base[location]);drivers/staging/gasket/gasket_core.h deleted +0
-21Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
int bar,
drivers/staging/gasket/gasket_core.h deleted +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mask_shift)drivers/staging/gasket/gasket_core.h deleted +0
-10Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
int bar,
drivers/staging/gasket/gasket_core.h deleted +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mask_shift)drivers/staging/gasket/gasket_core.h deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*dev);
drivers/staging/gasket/gasket_core.h deleted +0
-10Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_interrupt.c deleted +0
-18Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*/
drivers/staging/gasket/gasket_interrupt.c deleted +0
-14Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*/
drivers/staging/gasket/gasket_interrupt.c deleted +0
-12Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*/
drivers/staging/gasket/gasket_interrupt.c deleted +0
-41Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
initialized\n");
drivers/staging/gasket/gasket_interrupt.c deleted +0
-10Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
into
- * the register directly. If not, we need to deal with a
read-drivers/staging/gasket/gasket_interrupt.c deleted +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
and packing %d\n",
drivers/staging/gasket/gasket_interrupt.c deleted +0
-15Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
interrupt_data->pack_width;drivers/staging/gasket/gasket_interrupt.c deleted +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
interrupt_data->pack_width;drivers/staging/gasket/gasket_interrupt.c deleted +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
unknown enum %d\n",
drivers/staging/gasket/gasket_interrupt.c deleted +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
interrupt_data->interrupt_bar_index,
-
interrupt_data->interrupts[i].reg);drivers/staging/gasket/gasket_interrupt.c deleted +0
-17Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
interrupt_index);drivers/staging/gasket/gasket_interrupt.c deleted +0
-14Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*/
drivers/staging/gasket/gasket_interrupt.c deleted +0
-33Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*/
drivers/staging/gasket/gasket_interrupt.c deleted +0
-17Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
%d; "
drivers/staging/gasket/gasket_interrupt.c deleted +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
ret);
drivers/staging/gasket/gasket_interrupt.c deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
interrupt
- * setup code with MSIX vectors masked. This is wrong because nothing else in
- * the driver will normally touch the MSIX vectors.
- *
- * As a temporary hack, force unmasking there.
- *
- * TODO: Figure out why QCM kernel doesn't unmask the MSIX vectors, after
- *gasket_interrupt_msix_init(), and remove this code.
- */drivers/staging/gasket/gasket_interrupt.c deleted +0
-10Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
MSIX_VECTOR_SIZE;drivers/staging/gasket/gasket_interrupt.c deleted +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gasket_dev->interrupt_data->interrupt_bar_index,drivers/staging/gasket/gasket_interrupt.c deleted +0
-15Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*buf)
drivers/staging/gasket/gasket_interrupt.c deleted +0
-71Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
driver_desc->interrupt_bar_index;drivers/staging/gasket/gasket_interrupt.c deleted +0
-14Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
GFP_KERNEL);drivers/staging/gasket/gasket_interrupt.c deleted +0
-20Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
report
drivers/staging/gasket/gasket_interrupt.c deleted +0
-16Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*interrupt_data)drivers/staging/gasket/gasket_interrupt.c deleted +0
-21Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
data\n");
drivers/staging/gasket/gasket_interrupt.c deleted +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gasket_interrupt_msix_init(gasket_dev->interrupt_data);drivers/staging/gasket/gasket_interrupt.c deleted +0
-14Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
%d\n",
drivers/staging/gasket/gasket_interrupt.c deleted +0
-64Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*interrupt_data,drivers/staging/gasket/gasket_interrupt.c deleted +0
-17Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*interrupt_data,drivers/staging/gasket/gasket_interrupt.c deleted +0
-11Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_interrupt.h deleted +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
process.
- *
- * Copyright (C) 2018 Google, Inc.
- */drivers/staging/gasket/gasket_interrupt.h deleted +0
-9Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
set,
- * numbered from 0 - (num_interrupts- 1). Should this have to change, these
- * APIs will have to be updated.
- */drivers/staging/gasket/gasket_interrupt.h deleted +0
-23Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
not
- * free the underlying data structures. Returns 0 on success and an error code
- * on error.
- */drivers/staging/gasket/gasket_interrupt.h deleted +0
-17Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
associating
- *event_fdwith interrupt. Upon receipt of a device interrupt,event_fdwill be
- * signaled, after successful configuration.
- *
- * Returns 0 on success, a negative error code otherwise.
- */
-int gasket_interrupt_set_eventfd(structgasket_interrupt_data*interrupt_data,drivers/staging/gasket/gasket_interrupt.h deleted +0
-10Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*interrupt_data,drivers/staging/gasket/gasket_interrupt.h deleted +0
-17Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_ioctl.c deleted +0
-28Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*argp)
drivers/staging/gasket/gasket_ioctl.c deleted +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gasket_interrupt_eventfd)))drivers/staging/gasket/gasket_ioctl.c deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
__user*argp)drivers/staging/gasket/gasket_ioctl.c deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gasket_page_table_ioctl)))drivers/staging/gasket/gasket_ioctl.c deleted +0
-9Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
ibuf.size,
drivers/staging/gasket/gasket_ioctl.c deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*gasket_dev,
- structgasket_page_table_ioctl__user*argp)drivers/staging/gasket/gasket_ioctl.c deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gasket_page_table_ioctl)))drivers/staging/gasket/gasket_ioctl.c deleted +0
-9Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
ibuf.size,
drivers/staging/gasket/gasket_ioctl.c deleted +0
-12Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
__user*argp)drivers/staging/gasket/gasket_ioctl.c deleted +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gasket_page_table_ioctl)))drivers/staging/gasket/gasket_ioctl.c deleted +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
ibuf.size,
drivers/staging/gasket/gasket_ioctl.c deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
0x%x\n",
drivers/staging/gasket/gasket_ioctl.c deleted +0
-20Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gasket_page_table_ioctl)))drivers/staging/gasket/gasket_ioctl.c deleted +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
ibuf.size,
drivers/staging/gasket/gasket_ioctl.c deleted +0
-9Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
ibuf.size))
drivers/staging/gasket/gasket_ioctl.c deleted +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
ibuf.device_address,
drivers/staging/gasket/gasket_ioctl.c deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*argp)
drivers/staging/gasket/gasket_ioctl.c deleted +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gasket_page_table_ioctl)))drivers/staging/gasket/gasket_ioctl.c deleted +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
ibuf.size,
drivers/staging/gasket/gasket_ioctl.c deleted +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
ibuf.size))
drivers/staging/gasket/gasket_ioctl.c deleted +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
PAGE_SIZE);drivers/staging/gasket/gasket_ioctl.c deleted +0
-10Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gasket_coherent_alloc_config_ioctl__user*argp)drivers/staging/gasket/gasket_ioctl.c deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gasket_coherent_alloc_config_ioctl)))drivers/staging/gasket/gasket_ioctl.c deleted +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
ibuf.size,
drivers/staging/gasket/gasket_ioctl.c deleted +0
-31Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*)filp->private_data;
drivers/staging/gasket/gasket_ioctl.c deleted +0
-104Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
argp);
drivers/staging/gasket/gasket_ioctl.c deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
argp);
drivers/staging/gasket/gasket_ioctl.c deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
trace
drivers/staging/gasket/gasket_ioctl.c deleted +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gasket_is_supported_ioctl\n",
drivers/staging/gasket/gasket_ioctl.c deleted +0
-34Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_ioctl.h deleted +0
-28Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_page_table.c deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
necessary.
- *
- * There is a configurable number of page table entries, as well as a
- * configurable bit index for the extended address flag. Both of these are
- * specified ingasket_page_table_initthrough thepage_table_configparameter.
- *
- * The following example assumes:
- *page_table_config->total_entries= 8192
- *page_table_config->extended_bit= 63
- *
- * Address format:
- * Simple addresses - those whose containing pages are directly placed in the
- * device's address translation registers - are laid out as:- * [ 63 - 25: 0 | 24 - 12: page index | 11 - 0: page offset ] - * page index: The index of the containing page in the device's address - * translation registers.- * page offset: The index of the address into the containing page.
- *
- * Extended address - those whose containing pages are contained in a second-
- * level page table whose address is present in the device's address translation
- * registers - are laid out as:
- * [ 63: flag | 62 - 34: 0 | 33 - 21: dev/level 0 index |
- * 20 - 12: host/level 1 index | 11 - 0: page offset ]
- * flag: Marker indicating that this is an extended address.
Always 1.- * dev index: The index of the first-level page in the device's extended - * address translation registers. - * host index: The index of the containing page in the [host-resident]second-
- * level page table.
- * page offset: The index of the address into the containing [second-level]
- * page.
- */drivers/staging/gasket/gasket_page_table.c deleted +0
-16Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
table. */
drivers/staging/gasket/gasket_page_table.c deleted +0
-22Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
log2(PAGES_PER_SUBTABLE)
- * or, = 13 + 9 + 12
- */drivers/staging/gasket/gasket_page_table.c deleted +0
-19Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
PTEs).
- * Where device vs. host entries are differentiated, device-side or -visible
- * entries are called "slots". A slot may be either an entry in the device's
- * address translation table registers or an entry in a second-level page
- * table ("subtable").
- *
- * The full data in this structure is visible on the host [of course]. Only
- * the address contained indma_addris communicated to the device; that points
- * to the actual page mapped and described by this structure.
- */drivers/staging/gasket/gasket_page_table.c deleted +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
address may
- * not be page-aligned. Offset is the index into the containing
page ofdrivers/staging/gasket/gasket_page_table.c deleted +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
addresses
drivers/staging/gasket/gasket_page_table.c deleted +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*/
drivers/staging/gasket/gasket_page_table.c deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
is
- * allocated by this module for a given device.
- * Note that coherent pages mappings virt mapping cannot be tracked by the
- * Linux kernel, and coherent pages don't have a struct page associated,
- * hence Linux kernel cannot perform aget_user_page_xx()on a phys address
- * that was allocated coherent.
- * This structure trivially implements this mechanism.
- */drivers/staging/gasket/gasket_page_table.c deleted +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
subsystem */
drivers/staging/gasket/gasket_page_table.c deleted +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
virtual
drivers/staging/gasket/gasket_page_table.c deleted +0
-16Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*/
drivers/staging/gasket/gasket_page_table.c deleted +0
-16Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
table.
drivers/staging/gasket/gasket_page_table.c deleted +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
logging. */
drivers/staging/gasket/gasket_page_table.c deleted +0
-19Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
track
- * of the user coherent pages (pfn pages), and virt to coherent
pagedrivers/staging/gasket/gasket_page_table.c deleted +0
-15Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*page_table_config,drivers/staging/gasket/gasket_page_table.c deleted +0
-13Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
table with size 0\n");
drivers/staging/gasket/gasket_page_table.c deleted +0
-31Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
sizeof(*page_table_config));drivers/staging/gasket/gasket_page_table.c deleted +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
page_table_config->extended_bit;drivers/staging/gasket/gasket_page_table.c deleted +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*)&bar_data->virt_base[page_table_config->base_reg];
drivers/staging/gasket/gasket_page_table.c deleted +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*)&bar_data->virt_base[page_table_config->extended_reg];
drivers/staging/gasket/gasket_page_table.c deleted +0
-30Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*pg_tbl,
- structgasket_page_table_entry
*pte,drivers/staging/gasket/gasket_page_table.c deleted +0
-40Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
GASKET_PAGES_PER_SUBTABLE))drivers/staging/gasket/gasket_page_table.c deleted +0
-48Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
i);
drivers/staging/gasket/gasket_page_table.c deleted +0
-19Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
to one
- * contiguous virtual memory range. Check if thehost_addris within that range.
- */drivers/staging/gasket/gasket_page_table.c deleted +0
-31Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
is a
- * simple mapping, these will be address translation registers. If this is
- * an extended mapping, these will be within a second-level page table
- * allocated by the host and so must have their__iomemattribute casted away.
- */drivers/staging/gasket/gasket_page_table.c deleted +1
-30Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
addr=0x%lx, offset=0x%lx [ret=%d]\n",
drivers/staging/gasket/gasket_page_table.c deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
PAGE_SIZE,drivers/staging/gasket/gasket_page_table.c deleted +0
-9Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gasket_page_table_entry));drivers/staging/gasket/gasket_page_table.c deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
GASKET_VALID_SLOT_FLAG;drivers/staging/gasket/gasket_page_table.c deleted +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
updated.
drivers/staging/gasket/gasket_page_table.c deleted +0
-26Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*pg_tbl,drivers/staging/gasket/gasket_page_table.c deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*pg_tbl,drivers/staging/gasket/gasket_page_table.c deleted +0
-15Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
dev_addr),drivers/staging/gasket/gasket_page_table.c deleted +0
-18Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
device's
drivers/staging/gasket/gasket_page_table.c deleted +0
-9Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*/
drivers/staging/gasket/gasket_page_table.c deleted +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
ptes[i].dma_addr,
-PAGE_SIZE,DMA_BIDIRECTIONAL);drivers/staging/gasket/gasket_page_table.c deleted +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gasket_page_table_entry));drivers/staging/gasket/gasket_page_table.c deleted +0
-38Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*)(page_address(pte->page) +
drivers/staging/gasket/gasket_page_table.c deleted +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
len, 0);
drivers/staging/gasket/gasket_page_table.c deleted +0
-28Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*pg_tbl,
- intis_simple, uintpage_index,drivers/staging/gasket/gasket_page_table.c deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
offset)
- * and that the requested page range starts and ends within the set of
- * currently-partitioned simple pages.
- */
-static bool gasket_is_simple_dev_addr_bad(structgasket_page_table*pg_tbl,drivers/staging/gasket/gasket_page_table.c deleted +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
1);
drivers/staging/gasket/gasket_page_table.c deleted +0
-19Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
pg_tbl->num_simple_entries);drivers/staging/gasket/gasket_page_table.c deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
set of
- * currently-partitioned extended pages.
- */
-static bool gasket_is_extended_dev_addr_bad(structgasket_page_table*pg_tbl,drivers/staging/gasket/gasket_page_table.c deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
GASKET_EXTENDED_LVL0_SHIFT)) {
- dev_err(pg_tbl->device, "device address out of bounds:
0x%lx\n",drivers/staging/gasket/gasket_page_table.c deleted +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*/
drivers/staging/gasket/gasket_page_table.c deleted +0
-9Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
GASKET_PAGES_PER_SUBTABLE);drivers/staging/gasket/gasket_page_table.c deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
< %u\n",
drivers/staging/gasket/gasket_page_table.c deleted +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
{
drivers/staging/gasket/gasket_page_table.c deleted +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
<= %u\n",
drivers/staging/gasket/gasket_page_table.c deleted +0
-13Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*pg_tbl,drivers/staging/gasket/gasket_page_table.c deleted +0
-26Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
available\n",
drivers/staging/gasket/gasket_page_table.c deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
host_addr,drivers/staging/gasket/gasket_page_table.c deleted +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
num_pages);
- dev_err(pg_tbl->device, "gasket_perform_mapping%d\n",
ret);drivers/staging/gasket/gasket_page_table.c deleted +0
-9Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*pg_tbl,
- structgasket_page_table_entry
*pte,drivers/staging/gasket/gasket_page_table.c deleted +0
-10Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
kernel
drivers/staging/gasket/gasket_page_table.c deleted +0
-18Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
PAGE_SIZE,drivers/staging/gasket/gasket_page_table.c deleted +0
-19Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
page
- * table slots are available. If necessary, memory is allocated for second level
- * page tables.
- *
- * Note that memory for second level page tables is allocated as needed, but
- * that memory is only freed on the final close of the device
file, when the
- * page tables are repartitioned, or the device is removed. If there is an
- * error or if the full range of slots is not available, any memory
- * allocated for second level page tables remains allocated until final close,
- * repartition, or device removal.
- *
- * The page table mutex must be held by the caller.
- */drivers/staging/gasket/gasket_page_table.c deleted +0
-10Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
dev_addr);drivers/staging/gasket/gasket_page_table.c deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
slot);
drivers/staging/gasket/gasket_page_table.c deleted +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
subtable\n");
drivers/staging/gasket/gasket_page_table.c deleted +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
len))
drivers/staging/gasket/gasket_page_table.c deleted +0
-31Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
are not available\n",
drivers/staging/gasket/gasket_page_table.c deleted +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
dev_addr_end),
- gasket_extended_lvl1_page_idx(pg_tbl,dev_addr_end));drivers/staging/gasket/gasket_page_table.c deleted +0
-13Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
pte->offset);
- ret = gasket_perform_mapping(pg_tbl,pte->sublevel+slot_idx,
-slot_base+slot_idx,host_addr,drivers/staging/gasket/gasket_page_table.c deleted +0
-25Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
host_addr,drivers/staging/gasket/gasket_page_table.c deleted +0
-14Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
dev_addr,drivers/staging/gasket/gasket_page_table.c deleted +0
-18Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
dev_addr,drivers/staging/gasket/gasket_page_table.c deleted +0
-12Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*pg_tbl)drivers/staging/gasket/gasket_page_table.c deleted +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
1, 0,
drivers/staging/gasket/gasket_page_table.c deleted +0
-51Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
page_num;drivers/staging/gasket/gasket_page_table.c deleted +0
-30Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
aligned\n",
drivers/staging/gasket/gasket_page_table.c deleted +0
-17Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
bytes);
drivers/staging/gasket/gasket_page_table.c deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
%lu\n",
drivers/staging/gasket/gasket_page_table.c deleted +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
num_pages);drivers/staging/gasket/gasket_page_table.c deleted +0
-23Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*pg_tbl)drivers/staging/gasket/gasket_page_table.c deleted +0
-41Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
multiple
drivers/staging/gasket/gasket_page_table.c deleted +0
-34Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
GFP_KERNEL);drivers/staging/gasket/gasket_page_table.c deleted +0
-76Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
index)
drivers/staging/gasket/gasket_page_table.c deleted +0
-14Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_page_table.h deleted +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
framework.
- * As much as possible, internal details are hidden to simplify use -
- * all calls are thread-safe (protected by an internal mutex) except where
- * indicated otherwise.
- *
- * Copyright (C) 2018 Google, Inc.
- */drivers/staging/gasket/gasket_page_table.h deleted +0
-12Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
details are
- * internal to the implementation.
- */drivers/staging/gasket/gasket_page_table.h deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
address
- * translation table.
- * @extended_offset_reg: [Mapped] pointer to the device's register containing
- * the starting index of the extended translation
table.
- * @extended_bit_location: The index of the bit indicating whether an address
- * is extended.
- * @total_entries: The total number of entries in the device's address
- * translation table.
- * @device: Device structure for the underlying device. Only used for logging.
- * @pci_dev: PCI system descriptor for the underlying device.
- * whether the driver will supply its own.
- *
- * Description: Allocates and initializes data to track address translation -
- * simple and extended page table metadata. Initially, the page table is
- * partitioned such that all addresses are "simple" (single-level lookup).
- *gasket_partition_page_tablecan be called to change this paritioning.
- *
- * Returns 0 on success, a negative error code otherwise.
- */drivers/staging/gasket/gasket_page_table.h deleted +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*page_table_config,drivers/staging/gasket/gasket_page_table.h deleted +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
contained
- * elements.
- *
- * Because this call destroys the page table, it cannot be
- * thread-safe (mutex-protected)!
- */drivers/staging/gasket/gasket_page_table.h deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
entries).
- *
- * Description:gasket_partition_page_tablechecks to see if the simple page- * size can be changed (i.e., if there are no active extended - * mappings in the new simple size range), and, if so, - * sets the new simple and extended page table sizes.- *
- * Returns 0 if successful, or non-zero if the page table
entries
- * are not free.
- */drivers/staging/gasket/gasket_page_table.h deleted +0
-14Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
ranges.
- *
- * Returns 0 if successful or a non-zero error number
otherwise.
- * If there is an error, no pages are mapped.
- */
-int gasket_page_table_map(structgasket_page_table*page_table, ulonghost_addr,drivers/staging/gasket/gasket_page_table.h deleted +0
-9Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
device.
- */drivers/staging/gasket/gasket_page_table.h deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
simple
- * addressing.
- * @page_table: Gasket page table pointer.
- */drivers/staging/gasket/gasket_page_table.h deleted +0
-10Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*page_table);drivers/staging/gasket/gasket_page_table.h deleted +0
-10Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
an
- * offset because the host page may be larger than the
Gasket chip
- * page it contains.)
- *
- * Returns 0 if successful, -1 for an error. The page
pointer
- * and offset are returned through the pointers, if
successful.
- */drivers/staging/gasket/gasket_page_table.h deleted +0
-12Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
ranges
- * specified by both addresses and the size are valid for mapping pages into
- * device memory.
- *
- * Returns true if the mapping is bad, false otherwise.
- */drivers/staging/gasket/gasket_page_table.h deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
range
- * specified by the device address and the size is valid for mapping pages into
- * device memory.
- *
- * Returns true if the address is bad, false otherwise.
- */
-bool gasket_page_table_is_dev_addr_bad(structgasket_page_table*page_table,drivers/staging/gasket/gasket_page_table.h deleted +0
-19Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*page_table);drivers/staging/gasket/gasket_page_table.h deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*page_table);drivers/staging/gasket/gasket_page_table.h deleted +0
-18Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
size,
drivers/staging/gasket/gasket_page_table.h deleted +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
size,
drivers/staging/gasket/gasket_page_table.h deleted +0
-22Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_sysfs.c deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
sysfs
- * "show" functions to return user data.
- */drivers/staging/gasket/gasket_sysfs.c deleted +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mapping
drivers/staging/gasket/gasket_sysfs.c deleted +0
-23Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
dynamically
- * allocated.
- */drivers/staging/gasket/gasket_sysfs.c deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
dev_mappings[GASKET_SYSFS_NUM_MAPPINGS];
drivers/staging/gasket/gasket_sysfs.c deleted +0
-43Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mapping\n");
drivers/staging/gasket/gasket_sysfs.c deleted +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
since
drivers/staging/gasket/gasket_sysfs.c deleted +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
on
- * the mapping mutex, resulting in deadlock. To fix this,
thedrivers/staging/gasket/gasket_sysfs.c deleted +0
-34Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
function
- * will need to release a mapping 2x - once for the refcount taken in the
- * release function itself, and once for the count taken in the acquire call.
- */drivers/staging/gasket/gasket_sysfs.c deleted +0
-26Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
device
drivers/staging/gasket/gasket_sysfs.c deleted +0
-12Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
device\n");
drivers/staging/gasket/gasket_sysfs.c deleted +0
-29Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
array\n");
drivers/staging/gasket/gasket_sysfs.c deleted +0
-13Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
alive! */
drivers/staging/gasket/gasket_sysfs.c deleted +0
-13Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
initializing mapping\n");
drivers/staging/gasket/gasket_sysfs.c deleted +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
device\n");
drivers/staging/gasket/gasket_sysfs.c deleted +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
entries\n");
drivers/staging/gasket/gasket_sysfs.c deleted +0
-22Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
device\n");
drivers/staging/gasket/gasket_sysfs.c deleted +0
-20Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gasket_dev*dev)drivers/staging/gasket/gasket_sysfs.c deleted +0
-13Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*attr)
drivers/staging/gasket/gasket_sysfs.c deleted +0
-60Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
value>\"\n");
drivers/staging/gasket/gasket_sysfs.c deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
buf);
drivers/staging/gasket/gasket_sysfs.c deleted +0
-35Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_sysfs.h deleted +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
in the
- * Gasket driver framework to manage their own set of sysfs entries, instead of
- * centralizing all that work in one file.
- *
- * The goal of these utilities is to allow for sysfs entries to be easily
- * created without causing a proliferation of sysfs "show" functions. This
- * requires O(N) string lookups during show function execution, but as reading
- * sysfs entries is rarely performance-critical, this is likely acceptible.
- */drivers/staging/gasket/gasket_sysfs.h deleted +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
GASKET_DEV_MAX)drivers/staging/gasket/gasket_sysfs.h deleted +0
-21Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
data. */
drivers/staging/gasket/gasket_sysfs.h deleted +0
-13Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
attribute is
- * written (if so configured). The arguments are to the Gasket
device
- * pointer, the enclosinggasket_attrstructure, and the value
written.
- * The callback should perform any logging necessary, as errors
cannotdrivers/staging/gasket/gasket_sysfs.h deleted +0
-16Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
usage
- * at [Gasket] module load time.
- */drivers/staging/gasket/gasket_sysfs.h deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
@device.
- *
- * Description: This function maps a gasket_dev* to a device*. This mapping can
- * be used insysfs_showfunctions to get a handle to thegasket_devstruct
- * controlling the device node.
- *
- * If this function is not called beforegasket_sysfs_create_entries, a warning
- * will be logged.
- */drivers/staging/gasket/gasket_sysfs.h deleted +0
-9Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
called
- * multiple times for a given @device. If thegasket_devspecified in
- *gasket_sysfs_create_mappinghad a legacy device, the entries will be created
- * for it, as well.
- */drivers/staging/gasket/gasket_sysfs.h deleted +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*attrs);
drivers/staging/gasket/gasket_sysfs.h deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
internal
- * table.
- */drivers/staging/gasket/gasket_sysfs.h deleted +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
call
- * togasket_sysfs_create_entries. Returns NULL if no mapping can be found.
- * Upon success, this call take a reference to internal sysfs data that must be
- * released withgasket_sysfs_put_device_data. While this reference is held, the
- * underlying device sysfs information/structure will remain valid/will not be
- * deleted.
- */drivers/staging/gasket/gasket_sysfs.h deleted +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gasket_sysfs_get_device_data).
- */drivers/staging/gasket/gasket_sysfs.h deleted +0
-10Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
take a
- * reference to internal sysfs data that must be released with a call to
- *gasket_sysfs_put_attr. While this reference is held, the underlying device
- * sysfs information/structure will remain valid/will not be deleted.
- */drivers/staging/gasket/gasket_sysfs.h deleted +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*attr);
drivers/staging/gasket/gasket_sysfs.h deleted +0
-21Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
2.30.2
Part of the diff is not shown here. View the raw message.
Quoted 6,843 lines · On Mon, Mar 15, 2021 at 8:44 AM <[email protected]> wrote:
From: Greg Kroah-Hartman <[email protected]>
As none of the proposed things that need to be changed in the gasket drivers have ever been done, and there has not been any forward progress to get this out of staging, it seems totally abandonded so remove the code entirely so that people do not spend their time doing tiny cleanups for code that will never get out of staging.
If this code is actually being used, it can be reverted simply and then cleaned up properly, but as it is abandoned, let's just get rid of it.
Cc Rob Springer <[email protected]>Cc Todd Poynor <[email protected]>Cc Ben Chan <[email protected]>Cc Richard Yeh <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- MAINTAINERS | 8 - drivers/staging/Kconfig | 2 - drivers/staging/Makefile | 1 - drivers/staging/gasket/Kconfig | 25 - drivers/staging/gasket/Makefile | 10 - drivers/staging/gasket/TODO | 22 - drivers/staging/gasket/apex.h | 30 - drivers/staging/gasket/apex_driver.c | 726 -------- drivers/staging/gasket/gasket.h | 122 -- drivers/staging/gasket/gasket_constants.h | 44 - drivers/staging/gasket/gasket_core.c | 1815 -------------------- drivers/staging/gasket/gasket_core.h | 638 ------- drivers/staging/gasket/gasket_interrupt.c | 515 ------ drivers/staging/gasket/gasket_interrupt.h | 95 - drivers/staging/gasket/gasket_ioctl.c | 388 ----- drivers/staging/gasket/gasket_ioctl.h | 28 - drivers/staging/gasket/gasket_page_table.c | 1357 --------------- drivers/staging/gasket/gasket_page_table.h | 249 --- drivers/staging/gasket/gasket_sysfs.c | 398 ----- drivers/staging/gasket/gasket_sysfs.h | 175 -- 20 files changed, 6648 deletions(-) delete mode 100644 drivers/staging/gasket/Kconfig delete mode 100644 drivers/staging/gasket/Makefile delete mode 100644 drivers/staging/gasket/TODO delete mode 100644 drivers/staging/gasket/apex.h delete mode 100644 drivers/staging/gasket/apex_driver.c delete mode 100644 drivers/staging/gasket/gasket.h delete mode 100644 drivers/staging/gasket/gasket_constants.h delete mode 100644 drivers/staging/gasket/gasket_core.c delete mode 100644 drivers/staging/gasket/gasket_core.h delete mode 100644 drivers/staging/gasket/gasket_interrupt.c delete mode 100644 drivers/staging/gasket/gasket_interrupt.h delete mode 100644 drivers/staging/gasket/gasket_ioctl.c delete mode 100644 drivers/staging/gasket/gasket_ioctl.h delete mode 100644 drivers/staging/gasket/gasket_page_table.c delete mode 100644 drivers/staging/gasket/gasket_page_table.h delete mode 100644 drivers/staging/gasket/gasket_sysfs.c delete mode 100644 drivers/staging/gasket/gasket_sysfs.hMAINTAINERS +0
-8@@ -7385,14 +7385,6 @@ F: Documentation/hwmon/gsc-hwmon.rst F: drivers/hwmon/gsc-hwmon.c F: include/linux/platform_data/gsc_hwmon.h -GASKET DRIVER FRAMEWORK -M: Rob Springer <[email protected]> -M: Todd Poynor <[email protected]> -M: Ben Chan <[email protected]> -M: Richard Yeh <[email protected]> -S: Maintained -F: drivers/staging/gasket/ - GCC PLUGINS M: Kees Cook <[email protected]> L: [email protected]drivers/staging/Kconfig +0
-2@@ -98,8 +98,6 @@ source "drivers/staging/ralink-gdma/Kconfig" source "drivers/staging/mt7621-dts/Kconfig" -source "drivers/staging/gasket/Kconfig" - source "drivers/staging/axis-fifo/Kconfig" source "drivers/staging/fieldbus/Kconfig"drivers/staging/Makefile +0
-1@@ -39,7 +39,6 @@ obj-$(CONFIG_PCI_MT7621) += mt7621-pci/ obj-$(CONFIG_SOC_MT7621) += mt7621-dma/ obj-$(CONFIG_DMA_RALINK) += ralink-gdma/ obj-$(CONFIG_SOC_MT7621) += mt7621-dts/ -obj-$(CONFIG_STAGING_GASKET_FRAMEWORK) += gasket/ obj-$(CONFIG_XIL_AXIS_FIFO) += axis-fifo/ obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/ obj-$(CONFIG_KPC2000) += kpc2000/drivers/staging/gasket/Kconfig deleted +0
-25@@ -1,25 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -menu "Gasket devices" - -config STAGING_GASKET_FRAMEWORK - tristate "Gasket framework" - depends on PCI && (X86_64 || ARM64) - 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 Edge TPU device. See - https://cloud.google.com/edge-tpu/ for more information. - 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". - -endmenudrivers/staging/gasket/Makefile deleted +0
-10@@ -1,10 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# 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.odrivers/staging/gasket/TODO deleted +0
-22@@ -1,22 +0,0 @@ -This is a list of things that need to be done to get this driver out of the -staging directory. - -- Implement the gasket framework's functionality through UIO instead of - introducing a new user-space drivers framework that is quite similar. - - UIO provides the necessary bits to implement user-space drivers. Meanwhile - the gasket APIs adds some extra conveniences like PCI BAR mapping, and - MSI interrupts. Add these features to the UIO subsystem, then re-implement - the Apex driver as a basic UIO driver instead (include/linux/uio_driver.h) - -- Document sysfs files with Documentation/ABI/ entries. - -- Use misc interface instead of major number for driver version description. - -- Add descriptions of module_param's - -- apex_get_status() should actually check status. - -- "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 deleted +0
-30@@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* Apex kernel-userspace interface definitions. -* -* Copyright (C) 2018 Google, Inc. -*/ -#ifndef __APEX_H__ -#define __APEX_H__ - -#include <linux/ioctl.h> - -/* Clock Gating ioctl. */ -struct apex_gate_clock_ioctl { -/* Enter or leave clock gated state. */ -u64 enable; - -/* If set, enter clock gating state, regardless of custom block's -* internal idle state -*/ -u64 force_idle; -}; - -/* Base number for all Apex-common IOCTLs */ -#define APEX_IOCTL_BASE 0x7F - -/* Enable/Disable clock gating. */ -#define APEX_IOCTL_GATE_CLOCK \ - _IOW(APEX_IOCTL_BASE, 0, struct apex_gate_clock_ioctl) - -#endif /* __APEX_H__ */ drivers/staging/gasket/apex_driver.c deleted +0
-726@@ -1,726 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* Driver for the Apex chip. -* -* Copyright (C) 2018 Google, Inc. -*/ - -#include <linux/compiler.h> -#include <linux/delay.h> -#include <linux/device.h> -#include <linux/fs.h> -#include <linux/init.h> -#include <linux/mm.h> -#include <linux/module.h> -#include <linux/moduleparam.h> -#include <linux/pci.h> -#include <linux/printk.h> -#include <linux/sched.h> -#include <linux/uaccess.h> - -#include "apex.h" - -#include "gasket_core.h" -#include "gasket_interrupt.h" -#include "gasket_page_table.h" -#include "gasket_sysfs.h" - -/* Constants */ -#define APEX_DEVICE_NAME "Apex" -#define APEX_DRIVER_VERSION "1.0" - -/* CSRs are in BAR 2. */ -#define APEX_BAR_INDEX 2 - -#define APEX_PCI_VENDOR_ID 0x1ac1 -#define APEX_PCI_DEVICE_ID 0x089a - -/* Bar Offsets. */ -#define APEX_BAR_OFFSET 0 -#define APEX_CM_OFFSET 0x1000000 - -/* The sizes of each Apex BAR 2. */ -#define APEX_BAR_BYTES 0x100000 -#define APEX_CH_MEM_BYTES (PAGE_SIZE * MAX_NUM_COHERENT_PAGES) - -/* The number of user-mappable memory ranges in BAR2 of a Apex chip. */ -#define NUM_REGIONS 3 - -/* The number of nodes in a Apex chip. */ -#define NUM_NODES 1 - -/* -* The total number of entries in the page table. Should match the value read -* from the register APEX_BAR2_REG_KERNEL_HIB_PAGE_TABLE_SIZE. -*/ -#define APEX_PAGE_TABLE_TOTAL_ENTRIES 8192 - -#define APEX_EXTENDED_SHIFT 63/* Extended address bit position. */ - -/* Check reset 120 times */ -#define APEX_RESET_RETRY 120 -/* Wait 100 ms between checks. Total 12 sec wait maximum. */ -#define APEX_RESET_DELAY 100 - -/* Enumeration of the supported sysfs entries. */ -enum sysfs_attribute_type { -ATTR_KERNEL_HIB_PAGE_TABLE_SIZE , -ATTR_KERNEL_HIB_SIMPLE_PAGE_TABLE_SIZE , -ATTR_KERNEL_HIB_NUM_ACTIVE_PAGES , -}; - -/* -* Register offsets into BAR2 memory. -* Only values necessary for driver implementation are defined. -*/ -enum apex_bar2_regs { -APEX_BAR2_REG_SCU_BASE =0x1A300 , -APEX_BAR2_REG_KERNEL_HIB_PAGE_TABLE_SIZE =0x46000 , -APEX_BAR2_REG_KERNEL_HIB_EXTENDED_TABLE =0x46008 , -APEX_BAR2_REG_KERNEL_HIB_TRANSLATION_ENABLE =0x46010 , -APEX_BAR2_REG_KERNEL_HIB_INSTR_QUEUE_INTVECCTL =0x46018 , -APEX_BAR2_REG_KERNEL_HIB_INPUT_ACTV_QUEUE_INTVECCTL =0x46020 , -APEX_BAR2_REG_KERNEL_HIB_PARAM_QUEUE_INTVECCTL =0x46028 , -APEX_BAR2_REG_KERNEL_HIB_OUTPUT_ACTV_QUEUE_INTVECCTL =0x46030 , -APEX_BAR2_REG_KERNEL_HIB_SC_HOST_INTVECCTL =0x46038 , -APEX_BAR2_REG_KERNEL_HIB_TOP_LEVEL_INTVECCTL =0x46040 , -APEX_BAR2_REG_KERNEL_HIB_FATAL_ERR_INTVECCTL =0x46048 , -APEX_BAR2_REG_KERNEL_HIB_DMA_PAUSE =0x46050 , -APEX_BAR2_REG_KERNEL_HIB_DMA_PAUSE_MASK =0x46058 , -APEX_BAR2_REG_KERNEL_HIB_STATUS_BLOCK_DELAY =0x46060 , -APEX_BAR2_REG_KERNEL_HIB_MSIX_PENDING_BIT_ARRAY0 =0x46068 , -APEX_BAR2_REG_KERNEL_HIB_MSIX_PENDING_BIT_ARRAY1 =0x46070 , -APEX_BAR2_REG_KERNEL_HIB_PAGE_TABLE_INIT =0x46078 , -APEX_BAR2_REG_KERNEL_HIB_MSIX_TABLE_INIT =0x46080 , -APEX_BAR2_REG_KERNEL_WIRE_INT_PENDING_BIT_ARRAY =0x48778 , -APEX_BAR2_REG_KERNEL_WIRE_INT_MASK_ARRAY =0x48780 , -APEX_BAR2_REG_USER_HIB_DMA_PAUSE =0x486D8 , -APEX_BAR2_REG_USER_HIB_DMA_PAUSED =0x486E0 , -APEX_BAR2_REG_IDLEGENERATOR_IDLEGEN_IDLEREGISTER =0x4A000 , -APEX_BAR2_REG_KERNEL_HIB_PAGE_TABLE =0x50000 , - -/* Error registers - Used mostly for debug */ -APEX_BAR2_REG_USER_HIB_ERROR_STATUS =0x86f0 , -APEX_BAR2_REG_SCALAR_CORE_ERROR_STATUS =0x41a0 , -}; - -/* Addresses for packed registers. */ -#define APEX_BAR2_REG_AXI_QUIESCE (APEX_BAR2_REG_SCU_BASE + 0x2C) -#define APEX_BAR2_REG_GCB_CLOCK_GATE (APEX_BAR2_REG_SCU_BASE + 0x14) -#define APEX_BAR2_REG_SCU_0 (APEX_BAR2_REG_SCU_BASE + 0xc) -#define APEX_BAR2_REG_SCU_1 (APEX_BAR2_REG_SCU_BASE + 0x10) -#define APEX_BAR2_REG_SCU_2 (APEX_BAR2_REG_SCU_BASE + 0x14) -#define APEX_BAR2_REG_SCU_3 (APEX_BAR2_REG_SCU_BASE + 0x18) -#define APEX_BAR2_REG_SCU_4 (APEX_BAR2_REG_SCU_BASE + 0x1c) -#define APEX_BAR2_REG_SCU_5 (APEX_BAR2_REG_SCU_BASE + 0x20) - -#define SCU3_RG_PWR_STATE_OVR_BIT_OFFSET 26 -#define SCU3_RG_PWR_STATE_OVR_MASK_WIDTH 2 -#define SCU3_CUR_RST_GCB_BIT_MASK 0x10 -#define SCU2_RG_RST_GCB_BIT_MASK 0xc - -/* Configuration for page table. */ -static struct gasket_page_table_config apex_page_table_configs[NUM_NODES ] = { - { - .id =0 , - .mode =GASKET_PAGE_TABLE_MODE_NORMAL , - .total_entries =APEX_PAGE_TABLE_TOTAL_ENTRIES , - .base_reg =APEX_BAR2_REG_KERNEL_HIB_PAGE_TABLE , - .extended_reg =APEX_BAR2_REG_KERNEL_HIB_EXTENDED_TABLE , - .extended_bit =APEX_EXTENDED_SHIFT , - }, -}; - -/* The regions in the BAR2 space that can be mapped into user space. */ -static const struct gasket_mappable_region mappable_regions[NUM_REGIONS ] = { - {0x40000 ,0x1000 }, - {0x44000 ,0x1000 }, - {0x48000 ,0x1000 }, -}; - -/* Gasket device interrupts enums must be dense (i.e., no empty slots). */ -enum apex_interrupt { -APEX_INTERRUPT_INSTR_QUEUE =0 , -APEX_INTERRUPT_INPUT_ACTV_QUEUE =1 , -APEX_INTERRUPT_PARAM_QUEUE =2 , -APEX_INTERRUPT_OUTPUT_ACTV_QUEUE =3 , -APEX_INTERRUPT_SC_HOST_0 =4 , -APEX_INTERRUPT_SC_HOST_1 =5 , -APEX_INTERRUPT_SC_HOST_2 =6 , -APEX_INTERRUPT_SC_HOST_3 =7 , -APEX_INTERRUPT_TOP_LEVEL_0 =8 , -APEX_INTERRUPT_TOP_LEVEL_1 =9 , -APEX_INTERRUPT_TOP_LEVEL_2 =10 , -APEX_INTERRUPT_TOP_LEVEL_3 =11 , -APEX_INTERRUPT_FATAL_ERR =12 , -APEX_INTERRUPT_COUNT =13 , -}; - -/* Interrupt descriptors for Apex */ -static struct gasket_interrupt_desc apex_interrupts[] = { - { -APEX_INTERRUPT_INSTR_QUEUE , -APEX_BAR2_REG_KERNEL_HIB_INSTR_QUEUE_INTVECCTL , -UNPACKED , - }, - { -APEX_INTERRUPT_INPUT_ACTV_QUEUE , -APEX_BAR2_REG_KERNEL_HIB_INPUT_ACTV_QUEUE_INTVECCTL , -UNPACKED - }, - { -APEX_INTERRUPT_PARAM_QUEUE , -APEX_BAR2_REG_KERNEL_HIB_PARAM_QUEUE_INTVECCTL , -UNPACKED - }, - { -APEX_INTERRUPT_OUTPUT_ACTV_QUEUE , -APEX_BAR2_REG_KERNEL_HIB_OUTPUT_ACTV_QUEUE_INTVECCTL , -UNPACKED - }, - { -APEX_INTERRUPT_SC_HOST_0 , -APEX_BAR2_REG_KERNEL_HIB_SC_HOST_INTVECCTL , -PACK_0 - }, - { -APEX_INTERRUPT_SC_HOST_1 , -APEX_BAR2_REG_KERNEL_HIB_SC_HOST_INTVECCTL , -PACK_1 - }, - { -APEX_INTERRUPT_SC_HOST_2 , -APEX_BAR2_REG_KERNEL_HIB_SC_HOST_INTVECCTL , -PACK_2 - }, - { -APEX_INTERRUPT_SC_HOST_3 , -APEX_BAR2_REG_KERNEL_HIB_SC_HOST_INTVECCTL , -PACK_3 - }, - { -APEX_INTERRUPT_TOP_LEVEL_0 , -APEX_BAR2_REG_KERNEL_HIB_TOP_LEVEL_INTVECCTL , -PACK_0 - }, - { -APEX_INTERRUPT_TOP_LEVEL_1 , -APEX_BAR2_REG_KERNEL_HIB_TOP_LEVEL_INTVECCTL , -PACK_1 - }, - { -APEX_INTERRUPT_TOP_LEVEL_2 , -APEX_BAR2_REG_KERNEL_HIB_TOP_LEVEL_INTVECCTL , -PACK_2 - }, - { -APEX_INTERRUPT_TOP_LEVEL_3 , -APEX_BAR2_REG_KERNEL_HIB_TOP_LEVEL_INTVECCTL , -PACK_3 - }, - { -APEX_INTERRUPT_FATAL_ERR , -APEX_BAR2_REG_KERNEL_HIB_FATAL_ERR_INTVECCTL , -UNPACKED - }, -}; - -/* Allows device to enter power save upon driver close(). */ -static int allow_power_save =1 ; - -/* Allows SW based clock gating. */ -static int allow_sw_clock_gating; - -/* Allows HW based clock gating. */ -/* Note: this is not mutual exclusive with SW clock gating. */ -static int allow_hw_clock_gating =1 ; - -/* Act as if only GCB is instantiated. */ -static int bypass_top_level; - -module_param (allow_power_save, int,0644 ); -module_param (allow_sw_clock_gating, int,0644 ); -module_param (allow_hw_clock_gating, int,0644 ); -module_param (bypass_top_level, int,0644 ); - -/* Check the device status registers and return device status ALIVE or DEAD. */ -static int apex_get_status (struct gasket_dev *gasket_dev) -{ -/* TODO: Check device status. */ -return GASKET_STATUS_ALIVE ; -} - -/* Enter GCB reset state. */ -static int apex_enter_reset (struct gasket_dev *gasket_dev) -{ -if (bypass_top_level) -return 0 ; - -/* -* Software reset: -* Enable sleep mode -* - Software force GCB idle -* - Enable GCB idle -*/ -gasket_read_modify_write_64 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_IDLEGENERATOR_IDLEGEN_IDLEREGISTER , -0x0 ,1 ,32 ); - -/* - Initiate DMA pause */ -gasket_dev_write_64 (gasket_dev,1 ,APEX_BAR_INDEX , -APEX_BAR2_REG_USER_HIB_DMA_PAUSE ); - -/* - Wait for DMA pause complete. */ -if (gasket_wait_with_reschedule (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_USER_HIB_DMA_PAUSED ,1 ,1 , -APEX_RESET_DELAY ,APEX_RESET_RETRY )) { -dev_err (gasket_dev->dev, -"DMAs did not quiesce within timeout (%d ms)\n" , -APEX_RESET_RETRY *APEX_RESET_DELAY ); -return -ETIMEDOUT ; - } - -/* - Enable GCB reset (0x1 to rg_rst_gcb) */ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_2 ,0x1 ,2 ,2 ); - -/* - Enable GCB clock Gate (0x1 to rg_gated_gcb) */ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_2 ,0x1 ,2 ,18 ); - -/* - Enable GCB memory shut down (0x3 to rg_force_ram_sd) */ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ,0x3 ,2 ,14 ); - -/* - Wait for RAM shutdown. */ -if (gasket_wait_with_reschedule (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ,BIT (6 ),BIT (6 ), -APEX_RESET_DELAY ,APEX_RESET_RETRY )) { -dev_err (gasket_dev->dev, -"RAM did not shut down within timeout (%d ms)\n" , -APEX_RESET_RETRY *APEX_RESET_DELAY ); -return -ETIMEDOUT ; - } - -return 0 ; -} - -/* Quit GCB reset state. */ -static int apex_quit_reset (struct gasket_dev *gasket_dev) -{ -u32 val0, val1; - -if (bypass_top_level) -return 0 ; - -/* -* Disable sleep mode: -* - Disable GCB memory shut down: -* - b00: Not forced (HW controlled) -* - b1x: Force disable -*/ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ,0x0 ,2 ,14 ); - -/* -* - Disable software clock gate: -* - b00: Not forced (HW controlled) -* - b1x: Force disable -*/ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_2 ,0x0 ,2 ,18 ); - -/* -* - Disable GCB reset (rg_rst_gcb): -* - b00: Not forced (HW controlled) -* - b1x: Force disable = Force not Reset -*/ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_2 ,0x2 ,2 ,2 ); - -/* - Wait for RAM enable. */ -if (gasket_wait_with_reschedule (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ,BIT (6 ),0 , -APEX_RESET_DELAY ,APEX_RESET_RETRY )) { -dev_err (gasket_dev->dev, -"RAM did not enable within timeout (%d ms)\n" , -APEX_RESET_RETRY *APEX_RESET_DELAY ); -return -ETIMEDOUT ; - } - -/* - Wait for Reset complete. */ -if (gasket_wait_with_reschedule (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 , -SCU3_CUR_RST_GCB_BIT_MASK ,0 , -APEX_RESET_DELAY ,APEX_RESET_RETRY )) { -dev_err (gasket_dev->dev, -"GCB did not leave reset within timeout (%d ms)\n" , -APEX_RESET_RETRY *APEX_RESET_DELAY ); -return -ETIMEDOUT ; - } - -if (!allow_hw_clock_gating) { - val0 =gasket_dev_read_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ); -/* Inactive and Sleep mode are disabled. */ -gasket_read_modify_write_32 (gasket_dev, -APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ,0x3 , -SCU3_RG_PWR_STATE_OVR_MASK_WIDTH , -SCU3_RG_PWR_STATE_OVR_BIT_OFFSET ); - val1 =gasket_dev_read_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ); -dev_dbg (gasket_dev->dev, -"Disallow HW clock gating 0x%x -> 0x%x\n" , val0, val1); - }else { - val0 =gasket_dev_read_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ); -/* Inactive mode enabled - Sleep mode disabled. */ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ,2 , -SCU3_RG_PWR_STATE_OVR_MASK_WIDTH , -SCU3_RG_PWR_STATE_OVR_BIT_OFFSET ); - val1 =gasket_dev_read_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ); -dev_dbg (gasket_dev->dev,"Allow HW clock gating 0x%x -> 0x%x\n" , - val0, val1); - } - -return 0 ; -} - -/* Reset the Apex hardware. Called on final close via device_close_cb. */ -static int apex_device_cleanup (struct gasket_dev *gasket_dev) -{ -u64 scalar_error; -u64 hib_error; -int ret =0 ; - - hib_error =gasket_dev_read_64 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_USER_HIB_ERROR_STATUS ); - scalar_error =gasket_dev_read_64 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCALAR_CORE_ERROR_STATUS ); - -dev_dbg (gasket_dev->dev, -"%s 0x%p hib_error 0x%llx scalar_error 0x%llx\n" , - __func__, gasket_dev, hib_error, scalar_error); - -if (allow_power_save) - ret =apex_enter_reset (gasket_dev); - -return ret; -} - -/* Determine if GCB is in reset state. */ -static bool is_gcb_in_reset (struct gasket_dev *gasket_dev) -{ -u32 val =gasket_dev_read_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_SCU_3 ); - -/* Masks rg_rst_gcb bit of SCU_CTRL_2 */ -return (val &SCU3_CUR_RST_GCB_BIT_MASK ); -} - -/* Reset the hardware, then quit reset. Called on device open. */ -static int apex_reset (struct gasket_dev *gasket_dev) -{ -int ret; - -if (bypass_top_level) -return 0 ; - -if (!is_gcb_in_reset (gasket_dev)) { -/* We are not in reset - toggle the reset bit so as to force -* re-init of custom block -*/ -dev_dbg (gasket_dev->dev,"%s: toggle reset\n" , __func__); - - ret =apex_enter_reset (gasket_dev); -if (ret) -return ret; - } -return apex_quit_reset (gasket_dev); -} - -/* -* Check permissions for Apex ioctls. -* Returns true if the current user may execute this ioctl, and false otherwise. -*/ -static bool apex_ioctl_check_permissions (struct file *filp,uint cmd) -{ -return !!(filp->f_mode &FMODE_WRITE ); -} - -/* Gates or un-gates Apex clock. */ -static long apex_clock_gating (struct gasket_dev *gasket_dev, -struct apex_gate_clock_ioctl __user *argp) -{ -struct apex_gate_clock_ioctl ibuf; - -if (bypass_top_level || !allow_sw_clock_gating) -return 0 ; - -if (copy_from_user (&ibuf, argp,sizeof (ibuf))) -return -EFAULT ; - -dev_dbg (gasket_dev->dev,"%s %llu\n" , __func__, ibuf.enable); - -if (ibuf.enable) { -/* Quiesce AXI, gate GCB clock. */ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_AXI_QUIESCE ,0x1 ,1 , -16 ); -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_GCB_CLOCK_GATE ,0x1 , -2 ,18 ); - }else { -/* Un-gate GCB clock, un-quiesce AXI. */ -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_GCB_CLOCK_GATE ,0x0 , -2 ,18 ); -gasket_read_modify_write_32 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_AXI_QUIESCE ,0x0 ,1 , -16 ); - } -return 0 ; -} - -/* Apex-specific ioctl handler. */ -static long apex_ioctl (struct file *filp,uint cmd,void __user *argp) -{ -struct gasket_dev *gasket_dev = filp->private_data; - -if (!apex_ioctl_check_permissions (filp, cmd)) -return -EPERM ; - -switch (cmd) { -case APEX_IOCTL_GATE_CLOCK : -return apex_clock_gating (gasket_dev, argp); -default : -return -ENOTTY ;/* unknown command */ - } -} - -/* Display driver sysfs entries. */ -static ssize_t sysfs_show (struct device *device,struct device_attribute *attr, -char *buf) -{ -int ret; -struct gasket_dev *gasket_dev; -struct gasket_sysfs_attribute *gasket_attr; -enum sysfs_attribute_type type; -struct gasket_page_table *gpt; -uint val; - - gasket_dev =gasket_sysfs_get_device_data (device); -if (!gasket_dev) { -dev_err (device,"No Apex device sysfs mapping found\n" ); -return -ENODEV ; - } - - gasket_attr =gasket_sysfs_get_attr (device, attr); -if (!gasket_attr) { -dev_err (device,"No Apex device sysfs attr data found\n" ); -gasket_sysfs_put_device_data (device, gasket_dev); -return -ENODEV ; - } - - type = (enum sysfs_attribute_type )gasket_attr->data.attr_type; - gpt = gasket_dev->page_table[0 ]; -switch (type) { -case ATTR_KERNEL_HIB_PAGE_TABLE_SIZE : - val =gasket_page_table_num_entries (gpt); -break ; -case ATTR_KERNEL_HIB_SIMPLE_PAGE_TABLE_SIZE : - val =gasket_page_table_num_simple_entries (gpt); -break ; -case ATTR_KERNEL_HIB_NUM_ACTIVE_PAGES : - val =gasket_page_table_num_active_pages (gpt); -break ; -default : -dev_dbg (gasket_dev->dev,"Unknown attribute: %s\n" , - attr->attr.name); - ret =0 ; - goto exit; - } - ret =scnprintf (buf,PAGE_SIZE ,"%u\n" , val); -exit: -gasket_sysfs_put_attr (device, gasket_attr); -gasket_sysfs_put_device_data (device, gasket_dev); -return ret; -} - -static struct gasket_sysfs_attribute apex_sysfs_attrs[] = { -GASKET_SYSFS_RO (node_0_page_table_entries, sysfs_show, -ATTR_KERNEL_HIB_PAGE_TABLE_SIZE ), -GASKET_SYSFS_RO (node_0_simple_page_table_entries, sysfs_show, -ATTR_KERNEL_HIB_SIMPLE_PAGE_TABLE_SIZE ), -GASKET_SYSFS_RO (node_0_num_mapped_pages, sysfs_show, -ATTR_KERNEL_HIB_NUM_ACTIVE_PAGES ), -GASKET_END_OF_ATTR_ARRAY -}; - -/* On device open, perform a core reinit reset. */ -static int apex_device_open_cb (struct gasket_dev *gasket_dev) -{ -return gasket_reset_nolock (gasket_dev); -} - -static const struct pci_device_id apex_pci_ids[] = { - {PCI_DEVICE (APEX_PCI_VENDOR_ID ,APEX_PCI_DEVICE_ID ) }, {0 } -}; - -static int apex_pci_probe (struct pci_dev *pci_dev, -const struct pci_device_id *id) -{ -int ret; -ulong page_table_ready, msix_table_ready; -int retries =0 ; -struct gasket_dev *gasket_dev; - - ret =pci_enable_device (pci_dev); -if (ret) { -dev_err (&pci_dev->dev,"error enabling PCI device\n" ); -return ret; - } - -pci_set_master (pci_dev); - - ret =gasket_pci_add_device (pci_dev, &gasket_dev); -if (ret) { -dev_err (&pci_dev->dev,"error adding gasket device\n" ); -pci_disable_device (pci_dev); -return ret; - } - -pci_set_drvdata (pci_dev, gasket_dev); -apex_reset (gasket_dev); - -while (retries <APEX_RESET_RETRY ) { - page_table_ready = -gasket_dev_read_64 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_KERNEL_HIB_PAGE_TABLE_INIT ); - msix_table_ready = -gasket_dev_read_64 (gasket_dev,APEX_BAR_INDEX , -APEX_BAR2_REG_KERNEL_HIB_MSIX_TABLE_INIT ); -if (page_table_ready && msix_table_ready) -break ; -schedule_timeout (msecs_to_jiffies (APEX_RESET_DELAY )); - retries++; - } - -if (retries ==APEX_RESET_RETRY ) { -if (!page_table_ready) -dev_err (gasket_dev->dev,"Page table init timed out\n" ); -if (!msix_table_ready) -dev_err (gasket_dev->dev,"MSI-X table init timed out\n" ); - ret = -ETIMEDOUT ; - goto remove_device; - } - - ret =gasket_sysfs_create_entries (gasket_dev->dev_info.device, - apex_sysfs_attrs); -if (ret) -dev_err (&pci_dev->dev,"error creating device sysfs entries\n" ); - - ret =gasket_enable_device (gasket_dev); -if (ret) { -dev_err (&pci_dev->dev,"error enabling gasket device\n" ); - goto remove_device; - } - -/* Place device in low power mode until opened */ -if (allow_power_save) -apex_enter_reset (gasket_dev); - -return 0 ; - -remove_device: -gasket_pci_remove_device (pci_dev); -pci_disable_device (pci_dev); -return ret; -} - -static void apex_pci_remove (struct pci_dev *pci_dev) -{ -struct gasket_dev *gasket_dev =pci_get_drvdata (pci_dev); - -gasket_disable_device (gasket_dev); -gasket_pci_remove_device (pci_dev); -pci_disable_device (pci_dev); -} - -static const struct gasket_driver_desc apex_desc = { - .name ="apex" , - .driver_version =APEX_DRIVER_VERSION , - .major =120 , - .minor =0 , - .module =THIS_MODULE , - .pci_id_table = apex_pci_ids, - - .num_page_tables =NUM_NODES , - .page_table_bar_index =APEX_BAR_INDEX , - .page_table_configs = apex_page_table_configs, - .page_table_extended_bit =APEX_EXTENDED_SHIFT , - - .bar_descriptions = { -GASKET_UNUSED_BAR , -GASKET_UNUSED_BAR , - {APEX_BAR_BYTES , (VM_WRITE |VM_READ ),APEX_BAR_OFFSET , -NUM_REGIONS , mappable_regions,PCI_BAR }, -GASKET_UNUSED_BAR , -GASKET_UNUSED_BAR , -GASKET_UNUSED_BAR , - }, - .coherent_buffer_description = { -APEX_CH_MEM_BYTES , - (VM_WRITE |VM_READ ), -APEX_CM_OFFSET , - }, - .interrupt_type =PCI_MSIX , - .interrupt_bar_index =APEX_BAR_INDEX , - .num_interrupts =APEX_INTERRUPT_COUNT , - .interrupts = apex_interrupts, - .interrupt_pack_width =7 , - - .device_open_cb = apex_device_open_cb, - .device_close_cb = apex_device_cleanup, - - .ioctl_handler_cb = apex_ioctl, - .device_status_cb = apex_get_status, - .hardware_revision_cb =NULL , - .device_reset_cb = apex_reset, -}; - -static struct pci_driver apex_pci_driver = { - .name ="apex" , - .probe = apex_pci_probe, - .remove = apex_pci_remove, - .id_table = apex_pci_ids, -}; - -static int __init apex_init (void ) -{ -int ret; - - ret =gasket_register_device (&apex_desc); -if (ret) -return ret; - ret =pci_register_driver (&apex_pci_driver); -if (ret) -gasket_unregister_device (&apex_desc); -return ret; -} - -static void apex_exit (void ) -{ -pci_unregister_driver (&apex_pci_driver); -gasket_unregister_device (&apex_desc); -} -MODULE_DESCRIPTION ("Google Apex driver" ); -MODULE_VERSION (APEX_DRIVER_VERSION ); -MODULE_LICENSE ("GPL v2" ); -MODULE_AUTHOR ("John Joseph <[email protected]>" ); -MODULE_DEVICE_TABLE (pci, apex_pci_ids); -module_init (apex_init); -module_exit (apex_exit);drivers/staging/gasket/gasket.h deleted +0
-122@@ -1,122 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* Common Gasket device kernel and user space declarations. -* -* Copyright (C) 2018 Google, Inc. -*/ -#ifndef __GASKET_H__ -#define __GASKET_H__ - -#include <linux/ioctl.h> -#include <linux/types.h> - -/* ioctl structure declarations */ - -/* Ioctl structures are padded to a multiple of 64 bits */ -/* and padded to put 64 bit values on 64 bit boundaries. */ -/* Unsigned 64 bit integers are used to hold pointers. */ -/* This helps compatibility between 32 and 64 bits. */ - -/* -* Common structure for ioctls associating an eventfd with a device interrupt, -* when using the Gasket interrupt module. -*/ -struct gasket_interrupt_eventfd { -u64 interrupt; -u64 event_fd; -}; - -/* -* Common structure for ioctls mapping and unmapping buffers when using the -* Gasket page_table module. -*/ -struct gasket_page_table_ioctl { -u64 page_table_index; -u64 size; -u64 host_address; -u64 device_address; -}; - -/* -* Common structure for ioctls mapping and unmapping buffers when using the -* Gasket page_table module. -* dma_address: phys addr start of coherent memory, allocated by kernel -*/ -struct gasket_coherent_alloc_config_ioctl { -u64 page_table_index; -u64 enable; -u64 size; -u64 dma_address; -}; - -/* Base number for all Gasket-common IOCTLs */ -#define GASKET_IOCTL_BASE 0xDC - -/* Reset the device. */ -#define GASKET_IOCTL_RESET _IO(GASKET_IOCTL_BASE, 0) - -/* Associate the specified [event]fd with the specified interrupt. */ -#define GASKET_IOCTL_SET_EVENTFD \ - _IOW(GASKET_IOCTL_BASE, 1, struct gasket_interrupt_eventfd) - -/* -* Clears any eventfd associated with the specified interrupt. The (ulong) -* argument is the interrupt number to clear. -*/ -#define GASKET_IOCTL_CLEAR_EVENTFD _IOW(GASKET_IOCTL_BASE, 2, unsigned long) - -/* -* [Loopbacks only] Requests that the loopback device send the specified -* interrupt to the host. The (ulong) argument is the number of the interrupt to -* send. -*/ -#define GASKET_IOCTL_LOOPBACK_INTERRUPT \ - _IOW(GASKET_IOCTL_BASE, 3, unsigned long) - -/* Queries the kernel for the number of page tables supported by the device. */ -#define GASKET_IOCTL_NUMBER_PAGE_TABLES _IOR(GASKET_IOCTL_BASE, 4, u64) - -/* -* Queries the kernel for the maximum size of the page table. Only the size and -* page_table_index fields are used from the struct gasket_page_table_ioctl. -*/ -#define GASKET_IOCTL_PAGE_TABLE_SIZE \ - _IOWR(GASKET_IOCTL_BASE, 5, struct gasket_page_table_ioctl) - -/* -* Queries the kernel for the current simple page table size. Only the size and -* page_table_index fields are used from the struct gasket_page_table_ioctl. -*/ -#define GASKET_IOCTL_SIMPLE_PAGE_TABLE_SIZE \ - _IOWR(GASKET_IOCTL_BASE, 6, struct gasket_page_table_ioctl) - -/* -* Tells the kernel to change the split between the number of simple and -* extended entries in the given page table. Only the size and page_table_index -* fields are used from the struct gasket_page_table_ioctl. -*/ -#define GASKET_IOCTL_PARTITION_PAGE_TABLE \ - _IOW(GASKET_IOCTL_BASE, 7, struct gasket_page_table_ioctl) - -/* -* Tells the kernel to map size bytes at host_address to device_address in -* page_table_index page table. -*/ -#define GASKET_IOCTL_MAP_BUFFER \ - _IOW(GASKET_IOCTL_BASE, 8, struct gasket_page_table_ioctl) - -/* -* Tells the kernel to unmap size bytes at host_address from device_address in -* page_table_index page table. -*/ -#define GASKET_IOCTL_UNMAP_BUFFER \ - _IOW(GASKET_IOCTL_BASE, 9, struct gasket_page_table_ioctl) - -/* Clear the interrupt counts stored for this device. */ -#define GASKET_IOCTL_CLEAR_INTERRUPT_COUNTS _IO(GASKET_IOCTL_BASE, 10) - -/* Enable/Disable and configure the coherent allocator. */ -#define GASKET_IOCTL_CONFIG_COHERENT_ALLOCATOR \ - _IOWR(GASKET_IOCTL_BASE, 11, struct gasket_coherent_alloc_config_ioctl) - -#endif /* __GASKET_H__ */ drivers/staging/gasket/gasket_constants.h deleted +0
-44@@ -1,44 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright (C) 2018 Google, Inc. */ -#ifndef __GASKET_CONSTANTS_H__ -#define __GASKET_CONSTANTS_H__ - -#define GASKET_FRAMEWORK_VERSION "1.1.2" - -/* -* The maximum number of simultaneous device types supported by the framework. -*/ -#define GASKET_FRAMEWORK_DESC_MAX 2 - -/* The maximum devices per each type. */ -#define GASKET_DEV_MAX 256 - -/* The number of supported Gasket page tables per device. */ -#define GASKET_MAX_NUM_PAGE_TABLES 1 - -/* Maximum length of device names (driver name + minor number suffix + NULL). */ -#define GASKET_NAME_MAX 32 - -/* Device status enumeration. */ -enum gasket_status { -/* -* A device is DEAD if it has not been initialized or has had an error. -*/ -GASKET_STATUS_DEAD =0 , -/* -* A device is LAMED if the hardware is healthy but the kernel was -* unable to enable some functionality (e.g. interrupts). -*/ -GASKET_STATUS_LAMED , - -/* A device is ALIVE if it is ready for operation. */ -GASKET_STATUS_ALIVE , - -/* -* This status is set when the driver is exiting and waiting for all -* handles to be closed. -*/ -GASKET_STATUS_DRIVER_EXIT , -}; - -#endif drivers/staging/gasket/gasket_core.c deleted +0
-1815@@ -1,1815 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* Gasket generic driver framework. This file contains the implementation -* for the Gasket generic driver framework - the functionality that is common -* across Gasket devices. -* -* Copyright (C) 2018 Google, Inc. -*/ - -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt - -#include "gasket_core.h" - -#include "gasket_interrupt.h" -#include "gasket_ioctl.h" -#include "gasket_page_table.h" -#include "gasket_sysfs.h" - -#include <linux/capability.h> -#include <linux/compiler.h> -#include <linux/delay.h> -#include <linux/device.h> -#include <linux/fs.h> -#include <linux/init.h> -#include <linux/of.h> -#include <linux/pid_namespace.h> -#include <linux/printk.h> -#include <linux/sched.h> - -#ifdef GASKET_KERNEL_TRACE_SUPPORT -#define CREATE_TRACE_POINTS -#include <trace/events/gasket_mmap.h> -#else -#define trace_gasket_mmap_exit (x) -#define trace_gasket_mmap_entry (x, ...) -#endif - -/* -* "Private" members of gasket_driver_desc. -* -* Contains internal per-device type tracking data, i.e., data not appropriate -* as part of the public interface for the generic framework. -*/ -struct gasket_internal_desc { -/* Device-specific-driver-provided configuration information. */ -const struct gasket_driver_desc *driver_desc; - -/* Protects access to per-driver data (i.e. this structure). */ -struct mutex mutex; - -/* Kernel-internal device class. */ -struct class *class; - -/* Instantiated / present devices of this type. */ -struct gasket_dev *devs[GASKET_DEV_MAX ]; -}; - -/* do_map_region() needs be able to return more than just true/false. */ -enum do_map_region_status { -/* The region was successfully mapped. */ -DO_MAP_REGION_SUCCESS , - -/* Attempted to map region and failed. */ -DO_MAP_REGION_FAILURE , - -/* The requested region to map was not part of a mappable region. */ -DO_MAP_REGION_INVALID , -}; - -/* Global data definitions. */ -/* Mutex - only for framework-wide data. Other data should be protected by -* finer-grained locks. -*/ -static DEFINE_MUTEX (g_mutex); - -/* List of all registered device descriptions & their supporting data. */ -static struct gasket_internal_desc g_descs[GASKET_FRAMEWORK_DESC_MAX ]; - -/* Mapping of statuses to human-readable strings. Must end with {0,NULL}. */ -static const struct gasket_num_name gasket_status_name_table[] = { - {GASKET_STATUS_DEAD ,"DEAD" }, - {GASKET_STATUS_ALIVE ,"ALIVE" }, - {GASKET_STATUS_LAMED ,"LAMED" }, - {GASKET_STATUS_DRIVER_EXIT ,"DRIVER_EXITING" }, - {0 ,NULL }, -}; - -/* Enumeration of the automatic Gasket framework sysfs nodes. */ -enum gasket_sysfs_attribute_type { -ATTR_BAR_OFFSETS , -ATTR_BAR_SIZES , -ATTR_DRIVER_VERSION , -ATTR_FRAMEWORK_VERSION , -ATTR_DEVICE_TYPE , -ATTR_HARDWARE_REVISION , -ATTR_PCI_ADDRESS , -ATTR_STATUS , -ATTR_IS_DEVICE_OWNED , -ATTR_DEVICE_OWNER , -ATTR_WRITE_OPEN_COUNT , -ATTR_RESET_COUNT , -ATTR_USER_MEM_RANGES -}; - -/* Perform a standard Gasket callback. */ -static inline int -check_and_invoke_callback (struct gasket_dev *gasket_dev, -int (*cb_function)(struct gasket_dev *)) -{ -int ret =0 ; - -if (cb_function) { -mutex_lock (&gasket_dev->mutex); - ret =cb_function (gasket_dev); -mutex_unlock (&gasket_dev->mutex); - } -return ret; -} - -/* Perform a standard Gasket callback without grabbing gasket_dev->mutex. */ -static inline int -gasket_check_and_invoke_callback_nolock (struct gasket_dev *gasket_dev, -int (*cb_function)(struct gasket_dev *)) -{ -int ret =0 ; - -if (cb_function) - ret =cb_function (gasket_dev); -return ret; -} - -/* -* Return nonzero if the gasket_cdev_info is owned by the current thread group -* ID. -*/ -static int gasket_owned_by_current_tgid (struct gasket_cdev_info *info) -{ -return (info->ownership.is_owned && - (info->ownership.owner == current->tgid)); -} - -/* -* Find the next free gasket_internal_dev slot. -* -* Returns the located slot number on success or a negative number on failure. -*/ -static int gasket_find_dev_slot (struct gasket_internal_desc *internal_desc, -const char *kobj_name) -{ -int i; - -mutex_lock (&internal_desc->mutex); - -/* Search for a previous instance of this device. */ -for (i =0 ; i <GASKET_DEV_MAX ; i++) { -if (internal_desc->devs[i] && -strcmp (internal_desc->devs[i]->kobj_name, kobj_name) ==0 ) { -pr_err ("Duplicate device %s\n" , kobj_name); -mutex_unlock (&internal_desc->mutex); -return -EBUSY ; - } - } - -/* Find a free device slot. */ -for (i =0 ; i <GASKET_DEV_MAX ; i++) { -if (!internal_desc->devs[i]) -break ; - } - -if (i ==GASKET_DEV_MAX ) { -pr_err ("Too many registered devices; max %d\n" ,GASKET_DEV_MAX ); -mutex_unlock (&internal_desc->mutex); -return -EBUSY ; - } - -mutex_unlock (&internal_desc->mutex); -return i; -} - -/* -* Allocate and initialize a Gasket device structure, add the device to the -* device list. -* -* Returns 0 if successful, a negative error code otherwise. -*/ -static int gasket_alloc_dev (struct gasket_internal_desc *internal_desc, -struct device *parent,struct gasket_dev **pdev) -{ -int dev_idx; -const struct gasket_driver_desc *driver_desc = - internal_desc->driver_desc; -struct gasket_dev *gasket_dev; -struct gasket_cdev_info *dev_info; -const char *parent_name =dev_name (parent); - -pr_debug ("Allocating a Gasket device, parent %s.\n" , parent_name); - - *pdev =NULL ; - - dev_idx =gasket_find_dev_slot (internal_desc, parent_name); -if (dev_idx <0 ) -return dev_idx; - - gasket_dev = *pdev =kzalloc (sizeof (*gasket_dev),GFP_KERNEL ); -if (!gasket_dev) { -pr_err ("no memory for device, parent %s\n" , parent_name); -return -ENOMEM ; - } - internal_desc->devs[dev_idx] = gasket_dev; - -mutex_init (&gasket_dev->mutex); - - gasket_dev->internal_desc = internal_desc; - gasket_dev->dev_idx = dev_idx; -snprintf (gasket_dev->kobj_name,GASKET_NAME_MAX ,"%s" , parent_name); - gasket_dev->dev =get_device (parent); -/* gasket_bar_data is uninitialized. */ - gasket_dev->num_page_tables = driver_desc->num_page_tables; -/* max_page_table_size and *page table are uninit'ed */ -/* interrupt_data is not initialized. */ -/* status is 0, or GASKET_STATUS_DEAD */ - - dev_info = &gasket_dev->dev_info; -snprintf (dev_info->name,GASKET_NAME_MAX ,"%s_%u" , driver_desc->name, - gasket_dev->dev_idx); - dev_info->devt = -MKDEV (driver_desc->major, driver_desc->minor + - gasket_dev->dev_idx); - dev_info->device = -device_create (internal_desc->class, parent, dev_info->devt, - gasket_dev, dev_info->name); - -/* cdev has not yet been added; cdev_added is 0 */ - dev_info->gasket_dev_ptr = gasket_dev; -/* ownership is all 0, indicating no owner or opens. */ - -return 0 ; -} - -/* Free a Gasket device. */ -static void gasket_free_dev (struct gasket_dev *gasket_dev) -{ -struct gasket_internal_desc *internal_desc = gasket_dev->internal_desc; - -mutex_lock (&internal_desc->mutex); - internal_desc->devs[gasket_dev->dev_idx] =NULL ; -mutex_unlock (&internal_desc->mutex); -put_device (gasket_dev->dev); -kfree (gasket_dev); -} - -/* -* Maps the specified bar into kernel space. -* -* Returns 0 on success, a negative error code otherwise. -* A zero-sized BAR will not be mapped, but is not an error. -*/ -static int gasket_map_pci_bar (struct gasket_dev *gasket_dev,int bar_num) -{ -struct gasket_internal_desc *internal_desc = gasket_dev->internal_desc; -const struct gasket_driver_desc *driver_desc = - internal_desc->driver_desc; -ulong desc_bytes = driver_desc->bar_descriptions[bar_num].size; -struct gasket_bar_data *data; -int ret; - -if (desc_bytes ==0 ) -return 0 ; - -if (driver_desc->bar_descriptions[bar_num].type !=PCI_BAR ) { -/* not PCI: skip this entry */ -return 0 ; - } - - data = &gasket_dev->bar_data[bar_num]; - -/* -* pci_resource_start and pci_resource_len return a "resource_size_t", -* which is safely castable to ulong (which itself is the arg to -* request_mem_region). -*/ - data->phys_base = - (ulong )pci_resource_start (gasket_dev->pci_dev, bar_num); -if (!data->phys_base) { -dev_err (gasket_dev->dev,"Cannot get BAR%u base address\n" , - bar_num); -return -EINVAL ; - } - - data->length_bytes = - (ulong )pci_resource_len (gasket_dev->pci_dev, bar_num); -if (data->length_bytes < desc_bytes) { -dev_err (gasket_dev->dev, -"PCI BAR %u space is too small: %lu; expected >= %lu\n" , - bar_num, data->length_bytes, desc_bytes); -return -ENOMEM ; - } - -if (!request_mem_region (data->phys_base, data->length_bytes, - gasket_dev->dev_info.name)) { -dev_err (gasket_dev->dev, -"Cannot get BAR %d memory region %p\n" , - bar_num, &gasket_dev->pci_dev->resource[bar_num]); -return -EINVAL ; - } - - data->virt_base =ioremap (data->phys_base, data->length_bytes); -if (!data->virt_base) { -dev_err (gasket_dev->dev, -"Cannot remap BAR %d memory region %p\n" , - bar_num, &gasket_dev->pci_dev->resource[bar_num]); - ret = -ENOMEM ; - goto fail; - } - -dma_set_mask (&gasket_dev->pci_dev->dev,DMA_BIT_MASK (64 )); -dma_set_coherent_mask (&gasket_dev->pci_dev->dev,DMA_BIT_MASK (64 )); - -return 0 ; - -fail: -iounmap (data->virt_base); -release_mem_region (data->phys_base, data->length_bytes); -return ret; -} - -/* -* Releases PCI BAR mapping. -* -* A zero-sized or not-mapped BAR will not be unmapped, but is not an error. -*/ -static void gasket_unmap_pci_bar (struct gasket_dev *dev,int bar_num) -{ -ulong base, bytes; -struct gasket_internal_desc *internal_desc = dev->internal_desc; -const struct gasket_driver_desc *driver_desc = - internal_desc->driver_desc; - -if (driver_desc->bar_descriptions[bar_num].size ==0 || - !dev->bar_data[bar_num].virt_base) -return ; - -if (driver_desc->bar_descriptions[bar_num].type !=PCI_BAR ) -return ; - -iounmap (dev->bar_data[bar_num].virt_base); - dev->bar_data[bar_num].virt_base =NULL ; - - base =pci_resource_start (dev->pci_dev, bar_num); -if (!base) { -dev_err (dev->dev,"cannot get PCI BAR%u base address\n" , - bar_num); -return ; - } - - bytes =pci_resource_len (dev->pci_dev, bar_num); -release_mem_region (base, bytes); -} - -/* -* Setup PCI memory mapping for the specified device. -* -* Reads the BAR registers and sets up pointers to the device's memory mapped -* IO space. -* -* Returns 0 on success and a negative value otherwise. -*/ -static int gasket_setup_pci (struct pci_dev *pci_dev, -struct gasket_dev *gasket_dev) -{ -int i, mapped_bars, ret; - -for (i =0 ; i <PCI_STD_NUM_BARS ; i++) { - ret =gasket_map_pci_bar (gasket_dev, i); -if (ret) { - mapped_bars = i; - goto fail; - } - } - -return 0 ; - -fail: -for (i =0 ; i < mapped_bars; i++) -gasket_unmap_pci_bar (gasket_dev, i); - -return -ENOMEM ; -} - -/* Unmaps memory for the specified device. */ -static void gasket_cleanup_pci (struct gasket_dev *gasket_dev) -{ -int i; - -for (i =0 ; i <PCI_STD_NUM_BARS ; i++) -gasket_unmap_pci_bar (gasket_dev, i); -} - -/* Determine the health of the Gasket device. */ -static int gasket_get_hw_status (struct gasket_dev *gasket_dev) -{ -int status; -int i; -const struct gasket_driver_desc *driver_desc = - gasket_dev->internal_desc->driver_desc; - - status =gasket_check_and_invoke_callback_nolock (gasket_dev, - driver_desc->device_status_cb); -if (status !=GASKET_STATUS_ALIVE ) { -dev_dbg (gasket_dev->dev,"Hardware reported status %d.\n" , - status); -return status; - } - - status =gasket_interrupt_system_status (gasket_dev); -if (status !=GASKET_STATUS_ALIVE ) { -dev_dbg (gasket_dev->dev, -"Interrupt system reported status %d.\n" , status); -return status; - } - -for (i =0 ; i < driver_desc->num_page_tables; ++i) { - status =gasket_page_table_system_status (gasket_dev->page_table[i]); -if (status !=GASKET_STATUS_ALIVE ) { -dev_dbg (gasket_dev->dev, -"Page table %d reported status %d.\n" , - i, status); -return status; - } - } - -return GASKET_STATUS_ALIVE ; -} - -static ssize_t -gasket_write_mappable_regions (char *buf, -const struct gasket_driver_desc *driver_desc, -int bar_index) -{ -int i; -ssize_t written; -ssize_t total_written =0 ; -ulong min_addr, max_addr; -struct gasket_bar_desc bar_desc = - driver_desc->bar_descriptions[bar_index]; - -if (bar_desc.permissions ==GASKET_NOMAP ) -return 0 ; -for (i =0 ; - i < bar_desc.num_mappable_regions && total_written <PAGE_SIZE ; - i++) { - min_addr = bar_desc.mappable_regions[i].start - - driver_desc->legacy_mmap_address_offset; - max_addr = bar_desc.mappable_regions[i].start - - driver_desc->legacy_mmap_address_offset + - bar_desc.mappable_regions[i].length_bytes; - written =scnprintf (buf,PAGE_SIZE - total_written, -"0x%08lx-0x%08lx\n" , min_addr, max_addr); - total_written += written; - buf += written; - } -return total_written; -} - -static ssize_t gasket_sysfs_data_show (struct device *device, -struct device_attribute *attr,char *buf) -{ -int i, ret =0 ; -ssize_t current_written =0 ; -const struct gasket_driver_desc *driver_desc; -struct gasket_dev *gasket_dev; -struct gasket_sysfs_attribute *gasket_attr; -const struct gasket_bar_desc *bar_desc; -enum gasket_sysfs_attribute_type sysfs_type; - - gasket_dev =gasket_sysfs_get_device_data (device); -if (!gasket_dev) { -dev_err (device,"No sysfs mapping found for device\n" ); -return 0 ; - } - - gasket_attr =gasket_sysfs_get_attr (device, attr); -if (!gasket_attr) { -dev_err (device,"No sysfs attr found for device\n" ); -gasket_sysfs_put_device_data (device, gasket_dev); -return 0 ; - } - - driver_desc = gasket_dev->internal_desc->driver_desc; - - sysfs_type = - (enum gasket_sysfs_attribute_type )gasket_attr->data.attr_type; -switch (sysfs_type) { -case ATTR_BAR_OFFSETS : -for (i =0 ; i <PCI_STD_NUM_BARS ; i++) { - bar_desc = &driver_desc->bar_descriptions[i]; -if (bar_desc->size ==0 ) -continue ; - current_written = -snprintf (buf,PAGE_SIZE - ret,"%d: 0x%lx\n" , i, - (ulong )bar_desc->base); - buf += current_written; - ret += current_written; - } -break ; -case ATTR_BAR_SIZES : -for (i =0 ; i <PCI_STD_NUM_BARS ; i++) { - bar_desc = &driver_desc->bar_descriptions[i]; -if (bar_desc->size ==0 ) -continue ; - current_written = -snprintf (buf,PAGE_SIZE - ret,"%d: 0x%lx\n" , i, - (ulong )bar_desc->size); - buf += current_written; - ret += current_written; - } -break ; -case ATTR_DRIVER_VERSION : - ret =snprintf (buf,PAGE_SIZE ,"%s\n" , - gasket_dev->internal_desc->driver_desc->driver_version); -break ; -case ATTR_FRAMEWORK_VERSION : - ret =snprintf (buf,PAGE_SIZE ,"%s\n" , -GASKET_FRAMEWORK_VERSION ); -break ; -case ATTR_DEVICE_TYPE : - ret =snprintf (buf,PAGE_SIZE ,"%s\n" , - gasket_dev->internal_desc->driver_desc->name); -break ; -case ATTR_HARDWARE_REVISION : - ret =snprintf (buf,PAGE_SIZE ,"%d\n" , - gasket_dev->hardware_revision); -break ; -case ATTR_PCI_ADDRESS : - ret =snprintf (buf,PAGE_SIZE ,"%s\n" , gasket_dev->kobj_name); -break ; -case ATTR_STATUS : - ret =snprintf (buf,PAGE_SIZE ,"%s\n" , -gasket_num_name_lookup (gasket_dev->status, - gasket_status_name_table)); -break ; -case ATTR_IS_DEVICE_OWNED : - ret =snprintf (buf,PAGE_SIZE ,"%d\n" , - gasket_dev->dev_info.ownership.is_owned); -break ; -case ATTR_DEVICE_OWNER : - ret =snprintf (buf,PAGE_SIZE ,"%d\n" , - gasket_dev->dev_info.ownership.owner); -break ; -case ATTR_WRITE_OPEN_COUNT : - ret =snprintf (buf,PAGE_SIZE ,"%d\n" , - gasket_dev->dev_info.ownership.write_open_count); -break ; -case ATTR_RESET_COUNT : - ret =snprintf (buf,PAGE_SIZE ,"%d\n" , gasket_dev->reset_count); -break ; -case ATTR_USER_MEM_RANGES : -for (i =0 ; i <PCI_STD_NUM_BARS ; ++i) { - current_written = -gasket_write_mappable_regions (buf, driver_desc, - i); - buf += current_written; - ret += current_written; - } -break ; -default : -dev_dbg (gasket_dev->dev,"Unknown attribute: %s\n" , - attr->attr.name); - ret =0 ; -break ; - } - -gasket_sysfs_put_attr (device, gasket_attr); -gasket_sysfs_put_device_data (device, gasket_dev); -return ret; -} - -/* These attributes apply to all Gasket driver instances. */ -static const struct gasket_sysfs_attribute gasket_sysfs_generic_attrs[] = { -GASKET_SYSFS_RO (bar_offsets, gasket_sysfs_data_show,ATTR_BAR_OFFSETS ), -GASKET_SYSFS_RO (bar_sizes, gasket_sysfs_data_show,ATTR_BAR_SIZES ), -GASKET_SYSFS_RO (driver_version, gasket_sysfs_data_show, -ATTR_DRIVER_VERSION ), -GASKET_SYSFS_RO (framework_version, gasket_sysfs_data_show, -ATTR_FRAMEWORK_VERSION ), -GASKET_SYSFS_RO (device_type, gasket_sysfs_data_show,ATTR_DEVICE_TYPE ), -GASKET_SYSFS_RO (revision, gasket_sysfs_data_show, -ATTR_HARDWARE_REVISION ), -GASKET_SYSFS_RO (pci_address, gasket_sysfs_data_show,ATTR_PCI_ADDRESS ), -GASKET_SYSFS_RO (status, gasket_sysfs_data_show,ATTR_STATUS ), -GASKET_SYSFS_RO (is_device_owned, gasket_sysfs_data_show, -ATTR_IS_DEVICE_OWNED ), -GASKET_SYSFS_RO (device_owner, gasket_sysfs_data_show, -ATTR_DEVICE_OWNER ), -GASKET_SYSFS_RO (write_open_count, gasket_sysfs_data_show, -ATTR_WRITE_OPEN_COUNT ), -GASKET_SYSFS_RO (reset_count, gasket_sysfs_data_show,ATTR_RESET_COUNT ), -GASKET_SYSFS_RO (user_mem_ranges, gasket_sysfs_data_show, -ATTR_USER_MEM_RANGES ), -GASKET_END_OF_ATTR_ARRAY -}; - -/* Add a char device and related info. */ -static int gasket_add_cdev (struct gasket_cdev_info *dev_info, -const struct file_operations *file_ops, -struct module *owner) -{ -int ret; - -cdev_init (&dev_info->cdev, file_ops); - dev_info->cdev.owner = owner; - ret =cdev_add (&dev_info->cdev, dev_info->devt,1 ); -if (ret) { -dev_err (dev_info->gasket_dev_ptr->dev, -"cannot add char device [ret=%d]\n" , ret); -return ret; - } - dev_info->cdev_added =1 ; - -return 0 ; -} - -/* Disable device operations. */ -void gasket_disable_device (struct gasket_dev *gasket_dev) -{ -const struct gasket_driver_desc *driver_desc = - gasket_dev->internal_desc->driver_desc; -int i; - -/* Only delete the device if it has been successfully added. */ -if (gasket_dev->dev_info.cdev_added) -cdev_del (&gasket_dev->dev_info.cdev); - - gasket_dev->status =GASKET_STATUS_DEAD ; - -gasket_interrupt_cleanup (gasket_dev); - -for (i =0 ; i < driver_desc->num_page_tables; ++i) { -if (gasket_dev->page_table[i]) { -gasket_page_table_reset (gasket_dev->page_table[i]); -gasket_page_table_cleanup (gasket_dev->page_table[i]); - } - } -} -EXPORT_SYMBOL (gasket_disable_device); - -/* -* Registered driver descriptor lookup for PCI devices. -* -* Precondition: Called with g_mutex held (to avoid a race on return). -* Returns NULL if no matching device was found. -*/ -static struct gasket_internal_desc * -lookup_pci_internal_desc (struct pci_dev *pci_dev) -{ -int i; - -__must_hold (&g_mutex); -for (i =0 ; i <GASKET_FRAMEWORK_DESC_MAX ; i++) { -if (g_descs[i].driver_desc && - g_descs[i].driver_desc->pci_id_table && -pci_match_id (g_descs[i].driver_desc->pci_id_table, pci_dev)) -return &g_descs[i]; - } - -return NULL ; -} - -/* -* Verifies that the user has permissions to perform the requested mapping and -* that the provided descriptor/range is of adequate size to hold the range to -* be mapped. -*/ -static bool gasket_mmap_has_permissions (struct gasket_dev *gasket_dev, -struct vm_area_struct *vma, -int bar_permissions) -{ -int requested_permissions; -/* Always allow sysadmin to access. */ -if (capable (CAP_SYS_ADMIN )) -return true; - -/* Never allow non-sysadmins to access to a dead device. */ -if (gasket_dev->status !=GASKET_STATUS_ALIVE ) { -dev_dbg (gasket_dev->dev,"Device is dead.\n" ); -return false; - } - -/* Make sure that no wrong flags are set. */ - requested_permissions = - (vma->vm_flags &VM_ACCESS_FLAGS ); -if (requested_permissions & ~(bar_permissions)) { -dev_dbg (gasket_dev->dev, -"Attempting to map a region with requested permissions 0x%x, but region has permissions 0x%x.\n" , - requested_permissions, bar_permissions); -return false; - } - -/* Do not allow a non-owner to write. */ -if ((vma->vm_flags &VM_WRITE ) && - !gasket_owned_by_current_tgid (&gasket_dev->dev_info)) { -dev_dbg (gasket_dev->dev, -"Attempting to mmap a region for write without owning device.\n" ); -return false; - } - -return true; -} - -/* -* Verifies that the input address is within the region allocated to coherent -* buffer. -*/ -static bool -gasket_is_coherent_region (const struct gasket_driver_desc *driver_desc, -ulong address) -{ -struct gasket_coherent_buffer_desc coh_buff_desc = - driver_desc->coherent_buffer_description; - -if (coh_buff_desc.permissions !=GASKET_NOMAP ) { -if ((address >= coh_buff_desc.base) && - (address < coh_buff_desc.base + coh_buff_desc.size)) { -return true; - } - } -return false; -} - -static int gasket_get_bar_index (const struct gasket_dev *gasket_dev, -ulong phys_addr) -{ -int i; -const struct gasket_driver_desc *driver_desc; - - driver_desc = gasket_dev->internal_desc->driver_desc; -for (i =0 ; i <PCI_STD_NUM_BARS ; ++i) { -struct gasket_bar_desc bar_desc = - driver_desc->bar_descriptions[i]; - -if (bar_desc.permissions !=GASKET_NOMAP ) { -if (phys_addr >= bar_desc.base && - phys_addr < (bar_desc.base + bar_desc.size)) { -return i; - } - } - } -/* If we haven't found the address by now, it is invalid. */ -return -EINVAL ; -} - -/* -* Sets the actual bounds to map, given the device's mappable region. -* -* Given the device's mappable region, along with the user-requested mapping -* start offset and length of the user region, determine how much of this -* mappable region can be mapped into the user's region (start/end offsets), -* and the physical offset (phys_offset) into the BAR where the mapping should -* begin (either the VMA's or region lower bound). -* -* In other words, this calculates the overlap between the VMA -* (bar_offset, requested_length) and the given gasket_mappable_region. -* -* Returns true if there's anything to map, and false otherwise. -*/ -static bool -gasket_mm_get_mapping_addrs (const struct gasket_mappable_region *region, -ulong bar_offset,ulong requested_length, -struct gasket_mappable_region *mappable_region, -ulong *virt_offset) -{ -ulong range_start = region->start; -ulong range_length = region->length_bytes; -ulong range_end = range_start + range_length; - - *virt_offset =0 ; -if (bar_offset + requested_length < range_start) { -/* -* If the requested region is completely below the range, -* there is nothing to map. -*/ -return false; - }else if (bar_offset <= range_start) { -/* If the bar offset is below this range's start -* but the requested length continues into it: -* 1) Only map starting from the beginning of this -* range's phys. offset, so we don't map unmappable -* memory. -* 2) The length of the virtual memory to not map is the -* delta between the bar offset and the -* mappable start (and since the mappable start is -* bigger, start - req.) -* 3) The map length is the minimum of the mappable -* requested length (requested_length - virt_offset) -* and the actual mappable length of the range. -*/ - mappable_region->start = range_start; - *virt_offset = range_start - bar_offset; - mappable_region->length_bytes = -min (requested_length - *virt_offset, range_length); -return true; - }else if (bar_offset > range_start && - bar_offset < range_end) { -/* -* If the bar offset is within this range: -* 1) Map starting from the bar offset. -* 2) Because there is no forbidden memory between the -* bar offset and the range start, -* virt_offset is 0. -* 3) The map length is the minimum of the requested -* length and the remaining length in the buffer -* (range_end - bar_offset) -*/ - mappable_region->start = bar_offset; - *virt_offset =0 ; - mappable_region->length_bytes = -min (requested_length, range_end - bar_offset); -return true; - } - -/* -* If the requested [start] offset is above range_end, -* there's nothing to map. -*/ -return false; -} - -/* -* Calculates the offset where the VMA range begins in its containing BAR. -* The offset is written into bar_offset on success. -* Returns zero on success, anything else on error. -*/ -static int gasket_mm_vma_bar_offset (const struct gasket_dev *gasket_dev, -const struct vm_area_struct *vma, -ulong *bar_offset) -{ -ulong raw_offset; -int bar_index; -const struct gasket_driver_desc *driver_desc = - gasket_dev->internal_desc->driver_desc; - - raw_offset = (vma->vm_pgoff <<PAGE_SHIFT ) + - driver_desc->legacy_mmap_address_offset; - bar_index =gasket_get_bar_index (gasket_dev, raw_offset); -if (bar_index <0 ) { -dev_err (gasket_dev->dev, -"Unable to find matching bar for address 0x%lx\n" , - raw_offset); -trace_gasket_mmap_exit (bar_index); -return bar_index; - } - *bar_offset = - raw_offset - driver_desc->bar_descriptions[bar_index].base; - -return 0 ; -} - -int gasket_mm_unmap_region (const struct gasket_dev *gasket_dev, -struct vm_area_struct *vma, -const struct gasket_mappable_region *map_region) -{ -ulong bar_offset; -ulong virt_offset; -struct gasket_mappable_region mappable_region; -int ret; - -if (map_region->length_bytes ==0 ) -return 0 ; - - ret =gasket_mm_vma_bar_offset (gasket_dev, vma, &bar_offset); -if (ret) -return ret; - -if (!gasket_mm_get_mapping_addrs (map_region, bar_offset, - vma->vm_end - vma->vm_start, - &mappable_region, &virt_offset)) -return 1 ; - -/* -* The length passed to zap_vma_ptes MUST BE A MULTIPLE OF -* PAGE_SIZE! Trust me. I have the scars. -* -* Next multiple of y: ceil_div(x, y) * y -*/ -zap_vma_ptes (vma, vma->vm_start + virt_offset, -DIV_ROUND_UP (mappable_region.length_bytes,PAGE_SIZE ) * -PAGE_SIZE ); -return 0 ; -} -EXPORT_SYMBOL (gasket_mm_unmap_region); - -/* Maps a virtual address + range to a physical offset of a BAR. */ -static enum do_map_region_status -do_map_region (const struct gasket_dev *gasket_dev,struct vm_area_struct *vma, -struct gasket_mappable_region *mappable_region) -{ -/* Maximum size of a single call to io_remap_pfn_range. */ -/* I pulled this number out of thin air. */ -const ulong max_chunk_size =64 *1024 *1024 ; -ulong chunk_size, mapped_bytes =0 ; - -const struct gasket_driver_desc *driver_desc = - gasket_dev->internal_desc->driver_desc; - -ulong bar_offset, virt_offset; -struct gasket_mappable_region region_to_map; -ulong phys_offset, map_length; -ulong virt_base, phys_base; -int bar_index, ret; - - ret =gasket_mm_vma_bar_offset (gasket_dev, vma, &bar_offset); -if (ret) -return DO_MAP_REGION_INVALID ; - -if (!gasket_mm_get_mapping_addrs (mappable_region, bar_offset, - vma->vm_end - vma->vm_start, - ®ion_to_map, &virt_offset)) -return DO_MAP_REGION_INVALID ; - phys_offset = region_to_map.start; - map_length = region_to_map.length_bytes; - - virt_base = vma->vm_start + virt_offset; - bar_index = -gasket_get_bar_index (gasket_dev, - (vma->vm_pgoff <<PAGE_SHIFT ) + - driver_desc->legacy_mmap_address_offset); - -if (bar_index <0 ) -return DO_MAP_REGION_INVALID ; - - phys_base = gasket_dev->bar_data[bar_index].phys_base + phys_offset; -while (mapped_bytes < map_length) { -/* -* io_remap_pfn_range can take a while, so we chunk its -* calls and call cond_resched between each. -*/ - chunk_size =min (max_chunk_size, map_length - mapped_bytes); - -cond_resched (); - ret =io_remap_pfn_range (vma, virt_base + mapped_bytes, - (phys_base + mapped_bytes) >> -PAGE_SHIFT , chunk_size, - vma->vm_page_prot); -if (ret) { -dev_err (gasket_dev->dev, -"Error remapping PFN range.\n" ); - goto fail; - } - mapped_bytes += chunk_size; - } - -return DO_MAP_REGION_SUCCESS ; - -fail: -/* Unmap the partial chunk we mapped. */ - mappable_region->length_bytes = mapped_bytes; -if (gasket_mm_unmap_region (gasket_dev, vma, mappable_region)) -dev_err (gasket_dev->dev, -"Error unmapping partial region 0x%lx (0x%lx bytes)\n" , - (ulong )virt_offset, - (ulong )mapped_bytes); - -return DO_MAP_REGION_FAILURE ; -} - -/* Map a region of coherent memory. */ -static int gasket_mmap_coherent (struct gasket_dev *gasket_dev, -struct vm_area_struct *vma) -{ -const struct gasket_driver_desc *driver_desc = - gasket_dev->internal_desc->driver_desc; -const ulong requested_length = vma->vm_end - vma->vm_start; -int ret; -ulong permissions; - -if (requested_length ==0 || requested_length > - gasket_dev->coherent_buffer.length_bytes) { -trace_gasket_mmap_exit (-EINVAL ); -return -EINVAL ; - } - - permissions = driver_desc->coherent_buffer_description.permissions; -if (!gasket_mmap_has_permissions (gasket_dev, vma, permissions)) { -dev_err (gasket_dev->dev,"Permission checking failed.\n" ); -trace_gasket_mmap_exit (-EPERM ); -return -EPERM ; - } - - vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); - - ret =remap_pfn_range (vma, vma->vm_start, - (gasket_dev->coherent_buffer.phys_base) >> -PAGE_SHIFT , requested_length, vma->vm_page_prot); -if (ret) { -dev_err (gasket_dev->dev,"Error remapping PFN range err=%d.\n" , - ret); -trace_gasket_mmap_exit (ret); -return ret; - } - -/* Record the user virtual to dma_address mapping that was -* created by the kernel. -*/ -gasket_set_user_virt (gasket_dev, requested_length, - gasket_dev->coherent_buffer.phys_base, - vma->vm_start); -return 0 ; -} - -/* Map a device's BARs into user space. */ -static int gasket_mmap (struct file *filp,struct vm_area_struct *vma) -{ -int i, ret; -int bar_index; -int has_mapped_anything =0 ; -ulong permissions; -ulong raw_offset, vma_size; -bool is_coherent_region; -const struct gasket_driver_desc *driver_desc; -struct gasket_dev *gasket_dev = (struct gasket_dev *)filp->private_data; -const struct gasket_bar_desc *bar_desc; -struct gasket_mappable_region *map_regions =NULL ; -int num_map_regions =0 ; -enum do_map_region_status map_status; - - driver_desc = gasket_dev->internal_desc->driver_desc; - -if (vma->vm_start & ~PAGE_MASK ) { -dev_err (gasket_dev->dev, -"Base address not page-aligned: 0x%lx\n" , - vma->vm_start); -trace_gasket_mmap_exit (-EINVAL ); -return -EINVAL ; - } - -/* Calculate the offset of this range into physical mem. */ - raw_offset = (vma->vm_pgoff <<PAGE_SHIFT ) + - driver_desc->legacy_mmap_address_offset; - vma_size = vma->vm_end - vma->vm_start; -trace_gasket_mmap_entry (gasket_dev->dev_info.name, raw_offset, - vma_size); - -/* -* Check if the raw offset is within a bar region. If not, check if it -* is a coherent region. -*/ - bar_index =gasket_get_bar_index (gasket_dev, raw_offset); - is_coherent_region =gasket_is_coherent_region (driver_desc, raw_offset); -if (bar_index <0 && !is_coherent_region) { -dev_err (gasket_dev->dev, -"Unable to find matching bar for address 0x%lx\n" , - raw_offset); -trace_gasket_mmap_exit (bar_index); -return bar_index; - } -if (bar_index >0 && is_coherent_region) { -dev_err (gasket_dev->dev, -"double matching bar and coherent buffers for address 0x%lx\n" , - raw_offset); -trace_gasket_mmap_exit (bar_index); -return -EINVAL ; - } - - vma->vm_private_data = gasket_dev; - -if (is_coherent_region) -return gasket_mmap_coherent (gasket_dev, vma); - -/* Everything in the rest of this function is for normal BAR mapping. */ - -/* -* Subtract the base of the bar from the raw offset to get the -* memory location within the bar to map. -*/ - bar_desc = &driver_desc->bar_descriptions[bar_index]; - permissions = bar_desc->permissions; -if (!gasket_mmap_has_permissions (gasket_dev, vma, permissions)) { -dev_err (gasket_dev->dev,"Permission checking failed.\n" ); -trace_gasket_mmap_exit (-EPERM ); -return -EPERM ; - } - -if (driver_desc->get_mappable_regions_cb) { - ret = driver_desc->get_mappable_regions_cb (gasket_dev, - bar_index, - &map_regions, - &num_map_regions); -if (ret) -return ret; - }else { -if (!gasket_mmap_has_permissions (gasket_dev, vma, - bar_desc->permissions)) { -dev_err (gasket_dev->dev, -"Permission checking failed.\n" ); -trace_gasket_mmap_exit (-EPERM ); -return -EPERM ; - } - num_map_regions = bar_desc->num_mappable_regions; - map_regions =kcalloc (num_map_regions, -sizeof (*bar_desc->mappable_regions), -GFP_KERNEL ); -if (map_regions) { -memcpy (map_regions, bar_desc->mappable_regions, - num_map_regions * -sizeof (*bar_desc->mappable_regions)); - } - } - -if (!map_regions || num_map_regions ==0 ) { -dev_err (gasket_dev->dev,"No mappable regions returned!\n" ); -return -EINVAL ; - } - -/* Marks the VMA's pages as uncacheable. */ - vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); -for (i =0 ; i < num_map_regions; i++) { - map_status =do_map_region (gasket_dev, vma, &map_regions[i]); -/* Try the next region if this one was not mappable. */ -if (map_status ==DO_MAP_REGION_INVALID ) -continue ; -if (map_status ==DO_MAP_REGION_FAILURE ) { - ret = -ENOMEM ; - goto fail; - } - - has_mapped_anything =1 ; - } - -kfree (map_regions); - -/* If we could not map any memory, the request was invalid. */ -if (!has_mapped_anything) { -dev_err (gasket_dev->dev, -"Map request did not contain a valid region.\n" ); -trace_gasket_mmap_exit (-EINVAL ); -return -EINVAL ; - } - -trace_gasket_mmap_exit (0 ); -return 0 ; - -fail: -/* Need to unmap any mapped ranges. */ - num_map_regions = i; -for (i =0 ; i < num_map_regions; i++) -if (gasket_mm_unmap_region (gasket_dev, vma, - &bar_desc->mappable_regions[i])) -dev_err (gasket_dev->dev,"Error unmapping range %d.\n" , - i); -kfree (map_regions); - -return ret; -} - -/* -* Open the char device file. -* -* If the open is for writing, and the device is not owned, this process becomes -* the owner. If the open is for writing and the device is already owned by -* some other process, it is an error. If this process is the owner, increment -* the open count. -* -* Returns 0 if successful, a negative error number otherwise. -*/ -static int gasket_open (struct inode *inode,struct file *filp) -{ -int ret; -struct gasket_dev *gasket_dev; -const struct gasket_driver_desc *driver_desc; -struct gasket_ownership *ownership; -char task_name[TASK_COMM_LEN ]; -struct gasket_cdev_info *dev_info = - container_of(inode->i_cdev, struct gasket_cdev_info, cdev); -struct pid_namespace *pid_ns =task_active_pid_ns (current); -bool is_root =ns_capable (pid_ns->user_ns,CAP_SYS_ADMIN ); - - gasket_dev = dev_info->gasket_dev_ptr; - driver_desc = gasket_dev->internal_desc->driver_desc; - ownership = &dev_info->ownership; -get_task_comm (task_name, current); - filp->private_data = gasket_dev; - inode->i_size =0 ; - -dev_dbg (gasket_dev->dev, -"Attempting to open with tgid %u (%s) (f_mode: 0%03o, fmode_write: %d is_root: %u)\n" , - current->tgid, task_name, filp->f_mode, - (filp->f_mode &FMODE_WRITE ), is_root); - -/* Always allow non-writing accesses. */ -if (!(filp->f_mode &FMODE_WRITE )) { -dev_dbg (gasket_dev->dev,"Allowing read-only opening.\n" ); -return 0 ; - } - -mutex_lock (&gasket_dev->mutex); - -dev_dbg (gasket_dev->dev, -"Current owner open count (owning tgid %u): %d.\n" , - ownership->owner, ownership->write_open_count); - -/* Opening a node owned by another TGID is an error (unless root) */ -if (ownership->is_owned && ownership->owner != current->tgid && - !is_root) { -dev_err (gasket_dev->dev, -"Process %u is opening a node held by %u.\n" , - current->tgid, ownership->owner); -mutex_unlock (&gasket_dev->mutex); -return -EPERM ; - } - -/* If the node is not owned, assign it to the current TGID. */ -if (!ownership->is_owned) { - ret =gasket_check_and_invoke_callback_nolock (gasket_dev, - driver_desc->device_open_cb); -if (ret) { -dev_err (gasket_dev->dev, -"Error in device open cb: %d\n" , ret); -mutex_unlock (&gasket_dev->mutex); -return ret; - } - ownership->is_owned =1 ; - ownership->owner = current->tgid; -dev_dbg (gasket_dev->dev,"Device owner is now tgid %u\n" , - ownership->owner); - } - - ownership->write_open_count++; - -dev_dbg (gasket_dev->dev,"New open count (owning tgid %u): %d\n" , - ownership->owner, ownership->write_open_count); - -mutex_unlock (&gasket_dev->mutex); -return 0 ; -} - -/* -* Called on a close of the device file. If this process is the owner, -* decrement the open count. On last close by the owner, free up buffers and -* eventfd contexts, and release ownership. -* -* Returns 0 if successful, a negative error number otherwise. -*/ -static int gasket_release (struct inode *inode,struct file *file) -{ -int i; -struct gasket_dev *gasket_dev; -struct gasket_ownership *ownership; -const struct gasket_driver_desc *driver_desc; -char task_name[TASK_COMM_LEN ]; -struct gasket_cdev_info *dev_info = - container_of(inode->i_cdev, struct gasket_cdev_info, cdev); -struct pid_namespace *pid_ns =task_active_pid_ns (current); -bool is_root =ns_capable (pid_ns->user_ns,CAP_SYS_ADMIN ); - - gasket_dev = dev_info->gasket_dev_ptr; - driver_desc = gasket_dev->internal_desc->driver_desc; - ownership = &dev_info->ownership; -get_task_comm (task_name, current); -mutex_lock (&gasket_dev->mutex); - -dev_dbg (gasket_dev->dev, -"Releasing device node. Call origin: tgid %u (%s) (f_mode: 0%03o, fmode_write: %d, is_root: %u)\n" , - current->tgid, task_name, file->f_mode, - (file->f_mode &FMODE_WRITE ), is_root); -dev_dbg (gasket_dev->dev,"Current open count (owning tgid %u): %d\n" , - ownership->owner, ownership->write_open_count); - -if (file->f_mode &FMODE_WRITE ) { - ownership->write_open_count--; -if (ownership->write_open_count ==0 ) { -dev_dbg (gasket_dev->dev,"Device is now free\n" ); - ownership->is_owned =0 ; - ownership->owner =0 ; - -/* Forces chip reset before we unmap the page tables. */ - driver_desc->device_reset_cb (gasket_dev); - -for (i =0 ; i < driver_desc->num_page_tables; ++i) { -gasket_page_table_unmap_all (gasket_dev->page_table[i]); -gasket_page_table_garbage_collect (gasket_dev->page_table[i]); -gasket_free_coherent_memory_all (gasket_dev, i); - } - -/* Closes device, enters power save. */ -gasket_check_and_invoke_callback_nolock (gasket_dev, - driver_desc->device_close_cb); - } - } - -dev_dbg (gasket_dev->dev,"New open count (owning tgid %u): %d\n" , - ownership->owner, ownership->write_open_count); -mutex_unlock (&gasket_dev->mutex); -return 0 ; -} - -/* -* Gasket ioctl dispatch function. -* -* Check if the ioctl is a generic ioctl. If not, pass the ioctl to the -* ioctl_handler_cb registered in the driver description. -* If the ioctl is a generic ioctl, pass it to gasket_ioctl_handler. -*/ -static long gasket_ioctl (struct file *filp,uint cmd,ulong arg) -{ -struct gasket_dev *gasket_dev; -const struct gasket_driver_desc *driver_desc; -void __user *argp = (void __user *)arg; -char path[256 ]; - - gasket_dev = (struct gasket_dev *)filp->private_data; - driver_desc = gasket_dev->internal_desc->driver_desc; -if (!driver_desc) { -dev_dbg (gasket_dev->dev, -"Unable to find device descriptor for file %s\n" , -d_path (&filp->f_path, path,256 )); -return -ENODEV ; - } - -if (!gasket_is_supported_ioctl (cmd)) { -/* -* The ioctl handler is not a standard Gasket callback, since -* it requires different arguments. This means we can't use -* check_and_invoke_callback. -*/ -if (driver_desc->ioctl_handler_cb) -return driver_desc->ioctl_handler_cb (filp, cmd, argp); - -dev_dbg (gasket_dev->dev,"Received unknown ioctl 0x%x\n" , cmd); -return -EINVAL ; - } - -return gasket_handle_ioctl (filp, cmd, argp); -} - -/* File operations for all Gasket devices. */ -static const struct file_operations gasket_file_ops = { - .owner =THIS_MODULE , - .llseek = no_llseek, - .mmap = gasket_mmap, - .open = gasket_open, - .release = gasket_release, - .unlocked_ioctl = gasket_ioctl, -}; - -/* Perform final init and marks the device as active. */ -int gasket_enable_device (struct gasket_dev *gasket_dev) -{ -int tbl_idx; -int ret; -const struct gasket_driver_desc *driver_desc = - gasket_dev->internal_desc->driver_desc; - - ret =gasket_interrupt_init (gasket_dev); -if (ret) { -dev_err (gasket_dev->dev, -"Critical failure to allocate interrupts: %d\n" , ret); -gasket_interrupt_cleanup (gasket_dev); -return ret; - } - -for (tbl_idx =0 ; tbl_idx < driver_desc->num_page_tables; tbl_idx++) { -dev_dbg (gasket_dev->dev,"Initializing page table %d.\n" , - tbl_idx); - ret =gasket_page_table_init (&gasket_dev->page_table[tbl_idx], - &gasket_dev->bar_data[driver_desc->page_table_bar_index], - &driver_desc->page_table_configs[tbl_idx], - gasket_dev->dev, - gasket_dev->pci_dev); -if (ret) { -dev_err (gasket_dev->dev, -"Couldn't init page table %d: %d\n" , - tbl_idx, ret); -return ret; - } -/* -* Make sure that the page table is clear and set to simple -* addresses. -*/ -gasket_page_table_reset (gasket_dev->page_table[tbl_idx]); - } - -/* -* hardware_revision_cb returns a positive integer (the rev) if -* successful.) -*/ - ret =check_and_invoke_callback (gasket_dev, - driver_desc->hardware_revision_cb); -if (ret <0 ) { -dev_err (gasket_dev->dev, -"Error getting hardware revision: %d\n" , ret); -return ret; - } - gasket_dev->hardware_revision = ret; - -/* device_status_cb returns a device status, not an error code. */ - gasket_dev->status =gasket_get_hw_status (gasket_dev); -if (gasket_dev->status ==GASKET_STATUS_DEAD ) -dev_err (gasket_dev->dev,"Device reported as unhealthy.\n" ); - - ret =gasket_add_cdev (&gasket_dev->dev_info, &gasket_file_ops, - driver_desc->module); -if (ret) -return ret; - -return 0 ; -} -EXPORT_SYMBOL (gasket_enable_device); - -static int __gasket_add_device (struct device *parent_dev, -struct gasket_internal_desc *internal_desc, -struct gasket_dev **gasket_devp) -{ -int ret; -struct gasket_dev *gasket_dev; -const struct gasket_driver_desc *driver_desc = - internal_desc->driver_desc; - - ret =gasket_alloc_dev (internal_desc, parent_dev, &gasket_dev); -if (ret) -return ret; -if (IS_ERR (gasket_dev->dev_info.device)) { -dev_err (parent_dev,"Cannot create %s device %s [ret = %ld]\n" , - driver_desc->name, gasket_dev->dev_info.name, -PTR_ERR (gasket_dev->dev_info.device)); - ret = -ENODEV ; - goto free_gasket_dev; - } - - ret =gasket_sysfs_create_mapping (gasket_dev->dev_info.device, - gasket_dev); -if (ret) - goto remove_device; - - ret =gasket_sysfs_create_entries (gasket_dev->dev_info.device, - gasket_sysfs_generic_attrs); -if (ret) - goto remove_sysfs_mapping; - - *gasket_devp = gasket_dev; -return 0 ; - -remove_sysfs_mapping: -gasket_sysfs_remove_mapping (gasket_dev->dev_info.device); -remove_device: -device_destroy (internal_desc->class, gasket_dev->dev_info.devt); -free_gasket_dev: -gasket_free_dev (gasket_dev); -return ret; -} - -static void __gasket_remove_device (struct gasket_internal_desc *internal_desc, -struct gasket_dev *gasket_dev) -{ -gasket_sysfs_remove_mapping (gasket_dev->dev_info.device); -device_destroy (internal_desc->class, gasket_dev->dev_info.devt); -gasket_free_dev (gasket_dev); -} - -/* -* Add PCI gasket device. -* -* Called by Gasket device probe function. -* Allocates device metadata and maps device memory. The device driver must -* call gasket_enable_device after driver init is complete to place the device -* in active use. -*/ -int gasket_pci_add_device (struct pci_dev *pci_dev, -struct gasket_dev **gasket_devp) -{ -int ret; -struct gasket_internal_desc *internal_desc; -struct gasket_dev *gasket_dev; -struct device *parent; - -dev_dbg (&pci_dev->dev,"add PCI gasket device\n" ); - -mutex_lock (&g_mutex); - internal_desc =lookup_pci_internal_desc (pci_dev); -mutex_unlock (&g_mutex); -if (!internal_desc) { -dev_err (&pci_dev->dev, -"PCI add device called for unknown driver type\n" ); -return -ENODEV ; - } - - parent = &pci_dev->dev; - ret =__gasket_add_device (parent, internal_desc, &gasket_dev); -if (ret) -return ret; - - gasket_dev->pci_dev = pci_dev; - ret =gasket_setup_pci (pci_dev, gasket_dev); -if (ret) - goto cleanup_pci; - -/* -* Once we've created the mapping structures successfully, attempt to -* create a symlink to the pci directory of this object. -*/ - ret =sysfs_create_link (&gasket_dev->dev_info.device->kobj, - &pci_dev->dev.kobj,dev_name (&pci_dev->dev)); -if (ret) { -dev_err (gasket_dev->dev, -"Cannot create sysfs pci link: %d\n" , ret); - goto cleanup_pci; - } - - *gasket_devp = gasket_dev; -return 0 ; - -cleanup_pci: -gasket_cleanup_pci (gasket_dev); -__gasket_remove_device (internal_desc, gasket_dev); -return ret; -} -EXPORT_SYMBOL (gasket_pci_add_device); - -/* Remove a PCI gasket device. */ -void gasket_pci_remove_device (struct pci_dev *pci_dev) -{ -int i; -struct gasket_internal_desc *internal_desc; -struct gasket_dev *gasket_dev =NULL ; -/* Find the device desc. */ -mutex_lock (&g_mutex); - internal_desc =lookup_pci_internal_desc (pci_dev); -if (!internal_desc) { -mutex_unlock (&g_mutex); -return ; - } -mutex_unlock (&g_mutex); - -/* Now find the specific device */ -mutex_lock (&internal_desc->mutex); -for (i =0 ; i <GASKET_DEV_MAX ; i++) { -if (internal_desc->devs[i] && - internal_desc->devs[i]->pci_dev == pci_dev) { - gasket_dev = internal_desc->devs[i]; -break ; - } - } -mutex_unlock (&internal_desc->mutex); - -if (!gasket_dev) -return ; - -dev_dbg (gasket_dev->dev,"remove %s PCI gasket device\n" , - internal_desc->driver_desc->name); - -gasket_cleanup_pci (gasket_dev); -__gasket_remove_device (internal_desc, gasket_dev); -} -EXPORT_SYMBOL (gasket_pci_remove_device); - -/** -* Lookup a name by number in a num_name table. -* @num: Number to lookup. -* @table: Array of num_name structures, the table for the lookup. -* -* Description: Searches for num in the table. If found, the -* corresponding name is returned; otherwise NULL -* is returned. -* -* The table must have a NULL name pointer at the end. -*/ -const char *gasket_num_name_lookup (uint num, -const struct gasket_num_name *table) -{ -uint i =0 ; - -while (table[i].snn_name) { -if (num == table[i].snn_num) -break ; - ++i; - } - -return table[i].snn_name; -} -EXPORT_SYMBOL (gasket_num_name_lookup); - -int gasket_reset (struct gasket_dev *gasket_dev) -{ -int ret; - -mutex_lock (&gasket_dev->mutex); - ret =gasket_reset_nolock (gasket_dev); -mutex_unlock (&gasket_dev->mutex); -return ret; -} -EXPORT_SYMBOL (gasket_reset); - -int gasket_reset_nolock (struct gasket_dev *gasket_dev) -{ -int ret; -int i; -const struct gasket_driver_desc *driver_desc; - - driver_desc = gasket_dev->internal_desc->driver_desc; -if (!driver_desc->device_reset_cb) -return 0 ; - - ret = driver_desc->device_reset_cb (gasket_dev); -if (ret) { -dev_dbg (gasket_dev->dev,"Device reset cb returned %d.\n" , - ret); -return ret; - } - -/* Reinitialize the page tables and interrupt framework. */ -for (i =0 ; i < driver_desc->num_page_tables; ++i) -gasket_page_table_reset (gasket_dev->page_table[i]); - - ret =gasket_interrupt_reinit (gasket_dev); -if (ret) { -dev_dbg (gasket_dev->dev,"Unable to reinit interrupts: %d.\n" , - ret); -return ret; - } - -/* Get current device health. */ - gasket_dev->status =gasket_get_hw_status (gasket_dev); -if (gasket_dev->status ==GASKET_STATUS_DEAD ) { -dev_dbg (gasket_dev->dev,"Device reported as dead.\n" ); -return -EINVAL ; - } - -return 0 ; -} -EXPORT_SYMBOL (gasket_reset_nolock); - -gasket_ioctl_permissions_cb_t -gasket_get_ioctl_permissions_cb (struct gasket_dev *gasket_dev) -{ -return gasket_dev->internal_desc->driver_desc->ioctl_permissions_cb; -} -EXPORT_SYMBOL (gasket_get_ioctl_permissions_cb); - -/* Get the driver structure for a given gasket_dev. -* @dev: pointer to gasket_dev, implementing the requested driver. -*/ -const struct gasket_driver_desc *gasket_get_driver_desc (struct gasket_dev *dev) -{ -return dev->internal_desc->driver_desc; -} - -/* Get the device structure for a given gasket_dev. -* @dev: pointer to gasket_dev, implementing the requested driver. -*/ -struct device *gasket_get_device (struct gasket_dev *dev) -{ -return dev->dev; -} - -/** -* Asynchronously waits on device. -* @gasket_dev: Device struct. -* @bar: Bar -* @offset: Register offset -* @mask: Register mask -* @val: Expected value -* @max_retries: number of sleep periods -* @delay_ms: Timeout in milliseconds -* -* Description: Busy waits for a specific combination of bits to be set on a -* Gasket register. -**/ -int gasket_wait_with_reschedule (struct gasket_dev *gasket_dev,int bar, -u64 offset,u64 mask,u64 val, -uint max_retries,u64 delay_ms) -{ -uint retries =0 ; -u64 tmp; - -while (retries < max_retries) { - tmp =gasket_dev_read_64 (gasket_dev, bar, offset); -if ((tmp & mask) == val) -return 0 ; -msleep (delay_ms); - retries++; - } -dev_dbg (gasket_dev->dev,"%s timeout: reg %llx timeout (%llu ms)\n" , - __func__, offset, max_retries * delay_ms); -return -ETIMEDOUT ; -} -EXPORT_SYMBOL (gasket_wait_with_reschedule); - -/* See gasket_core.h for description. */ -int gasket_register_device (const struct gasket_driver_desc *driver_desc) -{ -int i, ret; -int desc_idx =-1 ; -struct gasket_internal_desc *internal; - -pr_debug ("Loading %s driver version %s\n" , driver_desc->name, - driver_desc->driver_version); -/* Check for duplicates and find a free slot. */ -mutex_lock (&g_mutex); - -for (i =0 ; i <GASKET_FRAMEWORK_DESC_MAX ; i++) { -if (g_descs[i].driver_desc == driver_desc) { -pr_err ("%s driver already loaded/registered\n" , - driver_desc->name); -mutex_unlock (&g_mutex); -return -EBUSY ; - } - } - -/* This and the above loop could be combined, but this reads easier. */ -for (i =0 ; i <GASKET_FRAMEWORK_DESC_MAX ; i++) { -if (!g_descs[i].driver_desc) { - g_descs[i].driver_desc = driver_desc; - desc_idx = i; -break ; - } - } -mutex_unlock (&g_mutex); - -if (desc_idx ==-1 ) { -pr_err ("too many drivers loaded, max %d\n" , -GASKET_FRAMEWORK_DESC_MAX ); -return -EBUSY ; - } - - internal = &g_descs[desc_idx]; -mutex_init (&internal->mutex); -memset (internal->devs,0 ,sizeof (struct gasket_dev *) *GASKET_DEV_MAX ); - internal->class = -class_create (driver_desc->module, driver_desc->name); - -if (IS_ERR (internal->class)) { -pr_err ("Cannot register %s class [ret=%ld]\n" , - driver_desc->name,PTR_ERR (internal->class)); - ret =PTR_ERR (internal->class); - goto unregister_gasket_driver; - } - - ret =register_chrdev_region (MKDEV (driver_desc->major, - driver_desc->minor),GASKET_DEV_MAX , - driver_desc->name); -if (ret) { -pr_err ("cannot register %s char driver [ret=%d]\n" , - driver_desc->name, ret); - goto destroy_class; - } - -return 0 ; - -destroy_class: -class_destroy (internal->class); - -unregister_gasket_driver: -mutex_lock (&g_mutex); - g_descs[desc_idx].driver_desc =NULL ; -mutex_unlock (&g_mutex); -return ret; -} -EXPORT_SYMBOL (gasket_register_device); - -/* See gasket_core.h for description. */ -void gasket_unregister_device (const struct gasket_driver_desc *driver_desc) -{ -int i, desc_idx; -struct gasket_internal_desc *internal_desc =NULL ; - -mutex_lock (&g_mutex); -for (i =0 ; i <GASKET_FRAMEWORK_DESC_MAX ; i++) { -if (g_descs[i].driver_desc == driver_desc) { - internal_desc = &g_descs[i]; - desc_idx = i; -break ; - } - } - -if (!internal_desc) { -mutex_unlock (&g_mutex); -pr_err ("request to unregister unknown desc: %s, %d:%d\n" , - driver_desc->name, driver_desc->major, - driver_desc->minor); -return ; - } - -unregister_chrdev_region (MKDEV (driver_desc->major, driver_desc->minor), -GASKET_DEV_MAX ); - -class_destroy (internal_desc->class); - -/* Finally, effectively "remove" the driver. */ - g_descs[desc_idx].driver_desc =NULL ; -mutex_unlock (&g_mutex); - -pr_debug ("removed %s driver\n" , driver_desc->name); -} -EXPORT_SYMBOL (gasket_unregister_device); - -static int __init gasket_init (void ) -{ -int i; - -mutex_lock (&g_mutex); -for (i =0 ; i <GASKET_FRAMEWORK_DESC_MAX ; i++) { - g_descs[i].driver_desc =NULL ; -mutex_init (&g_descs[i].mutex); - } - -gasket_sysfs_init (); - -mutex_unlock (&g_mutex); -return 0 ; -} - -MODULE_DESCRIPTION ("Google Gasket driver framework" ); -MODULE_VERSION (GASKET_FRAMEWORK_VERSION ); -MODULE_LICENSE ("GPL v2" ); -MODULE_AUTHOR ("Rob Springer <[email protected]>" ); -module_init (gasket_init);drivers/staging/gasket/gasket_core.h deleted +0
-638@@ -1,638 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* Gasket generic driver. Defines the set of data types and functions necessary -* to define a driver using the Gasket generic driver framework. -* -* Copyright (C) 2018 Google, Inc. -*/ -#ifndef __GASKET_CORE_H__ -#define __GASKET_CORE_H__ - -#include <linux/cdev.h> -#include <linux/compiler.h> -#include <linux/device.h> -#include <linux/init.h> -#include <linux/module.h> -#include <linux/pci.h> -#include <linux/sched.h> -#include <linux/slab.h> - -#include "gasket_constants.h" - -/** -* struct gasket_num_name - Map numbers to names. -* @ein_num: Number. -* @ein_name: Name associated with the number, a char pointer. -* -* This structure maps numbers to names. It is used to provide printable enum -* names, e.g {0, "DEAD"} or {1, "ALIVE"}. -*/ -struct gasket_num_name { -uint snn_num; -const char *snn_name; -}; - -/* -* Register location for packed interrupts. -* Each value indicates the location of an interrupt field (in units of -* gasket_driver_desc->interrupt_pack_width) within the containing register. -* In other words, this indicates the shift to use when creating a mask to -* extract/set bits within a register for a given interrupt. -*/ -enum gasket_interrupt_packing { -PACK_0 =0 , -PACK_1 =1 , -PACK_2 =2 , -PACK_3 =3 , -UNPACKED =4 , -}; - -/* Type of the interrupt supported by the device. */ -enum gasket_interrupt_type { -PCI_MSIX =0 , -}; - -/* -* Used to describe a Gasket interrupt. Contains an interrupt index, a register, -* and packing data for that interrupt. The register and packing data -* fields are relevant only for PCI_MSIX interrupt type and can be -* set to 0 for everything else. -*/ -struct gasket_interrupt_desc { -/* Device-wide interrupt index/number. */ -int index; -/* The register offset controlling this interrupt. */ -u64 reg; -/* The location of this interrupt inside register reg, if packed. */ -int packing; -}; - -/* -* This enum is used to identify memory regions being part of the physical -* memory that belongs to a device. -*/ -enum mappable_area_type { -PCI_BAR =0 ,/* Default */ -BUS_REGION ,/* For SYSBUS devices, i.e. AXI etc... */ -COHERENT_MEMORY -}; - -/* -* Metadata for each BAR mapping. -* This struct is used so as to track PCI memory, I/O space, AXI and coherent -* memory area... i.e. memory objects which can be referenced in the device's -* mmap function. -*/ -struct gasket_bar_data { -/* Virtual base address. */ -u8 __iomem *virt_base; - -/* Physical base address. */ -ulong phys_base; - -/* Length of the mapping. */ -ulong length_bytes; - -/* Type of mappable area */ -enum mappable_area_type type; -}; - -/* Maintains device open ownership data. */ -struct gasket_ownership { -/* 1 if the device is owned, 0 otherwise. */ -int is_owned; - -/* TGID of the owner. */ -pid_t owner; - -/* Count of current device opens in write mode. */ -int write_open_count; -}; - -/* Page table modes of operation. */ -enum gasket_page_table_mode { -/* The page table is partitionable as normal, all simple by default. */ -GASKET_PAGE_TABLE_MODE_NORMAL , - -/* All entries are always simple. */ -GASKET_PAGE_TABLE_MODE_SIMPLE , - -/* All entries are always extended. No extended bit is used. */ -GASKET_PAGE_TABLE_MODE_EXTENDED , -}; - -/* Page table configuration. One per table. */ -struct gasket_page_table_config { -/* The identifier/index of this page table. */ -int id; - -/* The operation mode of this page table. */ -enum gasket_page_table_mode mode; - -/* Total (first-level) entries in this page table. */ -ulong total_entries; - -/* Base register for the page table. */ -int base_reg; - -/* -* Register containing the extended page table. This value is unused in -* GASKET_PAGE_TABLE_MODE_SIMPLE and GASKET_PAGE_TABLE_MODE_EXTENDED -* modes. -*/ -int extended_reg; - -/* The bit index indicating whether a PT entry is extended. */ -int extended_bit; -}; - -/* Maintains information about a device node. */ -struct gasket_cdev_info { -/* The internal name of this device. */ -char name[GASKET_NAME_MAX ]; - -/* Device number. */ -dev_t devt; - -/* Kernel-internal device structure. */ -struct device *device; - -/* Character device for real. */ -struct cdev cdev; - -/* Flag indicating if cdev_add has been called for the devices. */ -int cdev_added; - -/* Pointer to the overall gasket_dev struct for this device. */ -struct gasket_dev *gasket_dev_ptr; - -/* Ownership data for the device in question. */ -struct gasket_ownership ownership; -}; - -/* Describes the offset and length of mmapable device BAR regions. */ -struct gasket_mappable_region { -u64 start; -u64 length_bytes; -};Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_interrupt.c deleted +0
-515Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_interrupt.h deleted +0
-95Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_ioctl.c deleted +0
-388Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_ioctl.h deleted +0
-28Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_page_table.c deleted +0
-1357Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_page_table.h deleted +0
-249Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_sysfs.c deleted +0
-398Lines of this file are not shown. View the raw message.
drivers/staging/gasket/gasket_sysfs.h deleted +0
-176Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
2.30.2
Part of the diff is not shown here. View the raw message.
Quoted 21 lines · Rob Springer
Acked-by Rob Springer <[email protected]>Quoted 17 lines · On Mon, Mar 15, 2021 at 8:44 AM <[email protected]> wrote:
From: Greg Kroah-Hartman <[email protected]>
As none of the proposed things that need to be changed in the gasket drivers have ever been done, and there has not been any forward progress to get this out of staging, it seems totally abandonded so remove the code entirely so that people do not spend their time doing tiny cleanups for code that will never get out of staging.
If this code is actually being used, it can be reverted simply and then cleaned up properly, but as it is abandoned, let's just get rid of it.
Cc Rob Springer <[email protected]>Cc Todd Poynor <[email protected]>Cc Ben Chan <[email protected]>Cc Richard Yeh <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
OK, so is there a plan of the HW vendor to improve the user experience for this hardware? Is there a different software architecture in sight which will not need a kernel driver?
Just wondering loudly while fiddling with dkms packages and starring at the code diffs between what was removed here and what I still have to install manually from remote sources.
Thanks,
Jan
Signature · 2 lines
Siemens AG, T RDA IOT Corporate Competence Center Embedded Linux
Greg KH
maintainerQuoted 23 lines · Jan Kiszka
Quoted 21 lines · Rob Springer
Acked-by Rob Springer <[email protected]>Quoted 17 lines · On Mon, Mar 15, 2021 at 8:44 AM <[email protected]> wrote:
From: Greg Kroah-Hartman <[email protected]>
As none of the proposed things that need to be changed in the gasket drivers have ever been done, and there has not been any forward progress to get this out of staging, it seems totally abandonded so remove the code entirely so that people do not spend their time doing tiny cleanups for code that will never get out of staging.
If this code is actually being used, it can be reverted simply and then cleaned up properly, but as it is abandoned, let's just get rid of it.
Cc Rob Springer <[email protected]>Cc Todd Poynor <[email protected]>Cc Ben Chan <[email protected]>Cc Richard Yeh <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 3 lines
OK, so is there a plan of the HW vendor to improve the user experience for this hardware? Is there a different software architecture in sight which will not need a kernel driver?
What hardware vendor makes this thing? What systems require it? And why can't you use UIO instead?
Quoted 3 lines
Just wondering loudly while fiddling with dkms packages and starring at the code diffs between what was removed here and what I still have to install manually from remote sources.
Where are the remote sources for this thing and why didn't they ever get synced into the kernel tree?
thanks,
greg k-h
Quoted 31 lines · Greg KH
Quoted 23 lines · Jan Kiszka
Quoted 21 lines · Rob Springer
Acked-by Rob Springer <[email protected]>Quoted 17 lines · On Mon, Mar 15, 2021 at 8:44 AM <[email protected]> wrote:
From: Greg Kroah-Hartman <[email protected]>
As none of the proposed things that need to be changed in the gasket drivers have ever been done, and there has not been any forward progress to get this out of staging, it seems totally abandonded so remove the code entirely so that people do not spend their time doing tiny cleanups for code that will never get out of staging.
If this code is actually being used, it can be reverted simply and then cleaned up properly, but as it is abandoned, let's just get rid of it.
Cc Rob Springer <[email protected]>Cc Todd Poynor <[email protected]>Cc Ben Chan <[email protected]>Cc Richard Yeh <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>Quoted 3 lines
OK, so is there a plan of the HW vendor to improve the user experience for this hardware? Is there a different software architecture in sight which will not need a kernel driver?
What hardware vendor makes this thing? What systems require it? And why can't you use UIO instead?
Quoted 7 lines
Quoted 3 lines
Just wondering loudly while fiddling with dkms packages and starring at the code diffs between what was removed here and what I still have to install manually from remote sources.
Where are the remote sources for this thing and why didn't they ever get synced into the kernel tree?
Very good questions, and I'm curious to learn if someone in CC can answer them.
I was just starting to play with this thing, using Google's binary Debian repo. But that is not... optimal. Even more when thinking beyond a try-out stage.
Jan
Signature · 2 lines
Siemens AG, T RDA IOT Corporate Competence Center Embedded Linux