* [PATCH v6 00/12] spi: add driver for Intel discrete graphics
@ 2024-09-16 13:49 Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 01/12] spi: add driver for intel graphics on-die spi device Alexander Usyskin
` (12 more replies)
0 siblings, 13 replies; 34+ messages in thread
From: Alexander Usyskin @ 2024-09-16 13:49 UTC (permalink / raw)
To: Mark Brown, Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin
Cc: Tomas Winkler, Alexander Usyskin, Vitaly Lubart, intel-xe,
dri-devel, linux-spi, intel-gfx
Add driver for access to Intel discrete graphics card
internal SPI device.
Expose device on auxiliary bus by i915 and Xe drivers and
provide spi driver to register this device with MTD framework.
This is a rewrite of "drm/i915/spi: spi access for discrete graphics"
series with connection to the Xe driver and splitting
the spi driver part to separate module in spi subsystem.
This series intended to be pushed through drm-xe-next.
V6: rebase over latest drm-xe-next, update to change in Xe APIs
V5: depend solely on AUXILIARY_BUS, not on COMPILE_TEST
disable spi driver on virtual function in Xe, no spi device there
V4: fix white-spaces
add check for discrete graphics missed in i915 intel_spi_fini
V3: rebase over drm-xe-next to enable CI run
V2: fix review comments
fix signatures order
depend spi presence in Xe on special flag,
as not all new discrete cards have such spi
Alexander Usyskin (6):
spi: add driver for intel graphics on-die spi device
spi: intel-dg: align 64bit read and write
spi: intel-dg: wake card on operations
drm/i915/spi: add support for access mode
drm/xe/spi: add on-die spi device
drm/xe/spi: add support for access mode
Tomas Winkler (6):
spi: intel-dg: implement region enumeration
spi: intel-dg: implement spi access functions
spi: intel-dg: spi register with mtd
spi: intel-dg: implement mtd access handlers
drm/i915/spi: add spi device for discrete graphics
drm/i915/spi: add intel_spi_region map
MAINTAINERS | 7 +
drivers/gpu/drm/i915/Makefile | 4 +
drivers/gpu/drm/i915/i915_driver.c | 6 +
drivers/gpu/drm/i915/i915_drv.h | 4 +
drivers/gpu/drm/i915/i915_reg.h | 1 +
drivers/gpu/drm/i915/spi/intel_spi.c | 101 +++
drivers/gpu/drm/i915/spi/intel_spi.h | 15 +
drivers/gpu/drm/xe/Makefile | 1 +
drivers/gpu/drm/xe/regs/xe_gsc_regs.h | 4 +
drivers/gpu/drm/xe/xe_device.c | 3 +
drivers/gpu/drm/xe/xe_device_types.h | 8 +
drivers/gpu/drm/xe/xe_heci_gsc.c | 5 +-
drivers/gpu/drm/xe/xe_pci.c | 5 +
drivers/gpu/drm/xe/xe_spi.c | 113 ++++
drivers/gpu/drm/xe/xe_spi.h | 15 +
drivers/spi/Kconfig | 11 +
drivers/spi/Makefile | 1 +
drivers/spi/spi-intel-dg.c | 863 ++++++++++++++++++++++++++
include/linux/intel_dg_spi_aux.h | 27 +
19 files changed, 1190 insertions(+), 4 deletions(-)
create mode 100644 drivers/gpu/drm/i915/spi/intel_spi.c
create mode 100644 drivers/gpu/drm/i915/spi/intel_spi.h
create mode 100644 drivers/gpu/drm/xe/xe_spi.c
create mode 100644 drivers/gpu/drm/xe/xe_spi.h
create mode 100644 drivers/spi/spi-intel-dg.c
create mode 100644 include/linux/intel_dg_spi_aux.h
--
2.34.1
^ permalink raw reply [flat|nested] 34+ messages in thread
* [PATCH v6 01/12] spi: add driver for intel graphics on-die spi device
2024-09-16 13:49 [PATCH v6 00/12] spi: add driver for Intel discrete graphics Alexander Usyskin
@ 2024-09-16 13:49 ` Alexander Usyskin
2024-09-18 13:33 ` Mark Brown
2024-09-16 13:49 ` [PATCH v6 02/12] spi: intel-dg: implement region enumeration Alexander Usyskin
` (11 subsequent siblings)
12 siblings, 1 reply; 34+ messages in thread
From: Alexander Usyskin @ 2024-09-16 13:49 UTC (permalink / raw)
To: Mark Brown, Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin
Cc: Tomas Winkler, Alexander Usyskin, Vitaly Lubart, intel-xe,
dri-devel, linux-spi, intel-gfx
Add auxiliary driver for intel discrete graphics
on-die spi device.
CC: Rodrigo Vivi <rodrigo.vivi@intel.com>
CC: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
---
MAINTAINERS | 7 ++
drivers/spi/Kconfig | 11 +++
drivers/spi/Makefile | 1 +
drivers/spi/spi-intel-dg.c | 142 +++++++++++++++++++++++++++++++
include/linux/intel_dg_spi_aux.h | 27 ++++++
5 files changed, 188 insertions(+)
create mode 100644 drivers/spi/spi-intel-dg.c
create mode 100644 include/linux/intel_dg_spi_aux.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 333ed0718175..b2c1aa743bc6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11214,6 +11214,13 @@ L: linux-kernel@vger.kernel.org
S: Supported
F: arch/x86/include/asm/intel-family.h
+INTEL DISCRETE GRAPHIC SPI FLASH DRIVER
+M: Alexander Usyskin <alexander.usyskin@intel.com>
+L: linux-spi@vger.kernel.org
+S: Supported
+F: drivers/spi/spi-intel-dg.c
+F: include/linux/intel_dg_spi_aux.h
+
INTEL DRM DISPLAY FOR XE AND I915 DRIVERS
M: Jani Nikula <jani.nikula@linux.intel.com>
M: Rodrigo Vivi <rodrigo.vivi@intel.com>
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index ec1550c698d5..95d6667dc127 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -524,6 +524,17 @@ config SPI_INTEL_PLATFORM
To compile this driver as a module, choose M here: the module
will be called spi-intel-platform.
+config SPI_INTEL_DG
+ tristate "Intel Discrete Graphic SPI flash driver"
+ depends on AUXILIARY_BUS
+ depends on MTD
+ help
+ This enables support for Intel Discrete Graphic SPI
+ auxiliary device.
+
+ To compile this driver as a module, choose M here: the module
+ will be called spi-intel-dg.
+
config SPI_JCORE
tristate "J-Core SPI Master"
depends on OF && (SUPERH || COMPILE_TEST)
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index a9b1bc259b68..ae8398930f3b 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_SPI_INGENIC) += spi-ingenic.o
obj-$(CONFIG_SPI_INTEL) += spi-intel.o
obj-$(CONFIG_SPI_INTEL_PCI) += spi-intel-pci.o
obj-$(CONFIG_SPI_INTEL_PLATFORM) += spi-intel-platform.o
+obj-$(CONFIG_SPI_INTEL_DG) += spi-intel-dg.o
obj-$(CONFIG_SPI_LANTIQ_SSC) += spi-lantiq-ssc.o
obj-$(CONFIG_SPI_JCORE) += spi-jcore.o
obj-$(CONFIG_SPI_LJCA) += spi-ljca.o
diff --git a/drivers/spi/spi-intel-dg.c b/drivers/spi/spi-intel-dg.c
new file mode 100644
index 000000000000..4e302957f077
--- /dev/null
+++ b/drivers/spi/spi-intel-dg.c
@@ -0,0 +1,142 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright(c) 2019-2024, Intel Corporation. All rights reserved.
+ */
+
+#include <linux/device.h>
+#include <linux/intel_dg_spi_aux.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+
+struct intel_dg_spi {
+ struct kref refcnt;
+ void __iomem *base;
+ size_t size;
+ unsigned int nregions;
+ struct {
+ const char *name;
+ u8 id;
+ u64 offset;
+ u64 size;
+ } regions[];
+};
+
+static void intel_dg_spi_release(struct kref *kref)
+{
+ struct intel_dg_spi *spi = container_of(kref, struct intel_dg_spi, refcnt);
+ int i;
+
+ pr_debug("freeing spi memory\n");
+ for (i = 0; i < spi->nregions; i++)
+ kfree(spi->regions[i].name);
+ kfree(spi);
+}
+
+static int intel_dg_spi_probe(struct auxiliary_device *aux_dev,
+ const struct auxiliary_device_id *aux_dev_id)
+{
+ struct intel_dg_spi_dev *ispi = auxiliary_dev_to_intel_dg_spi_dev(aux_dev);
+ struct device *device;
+ struct intel_dg_spi *spi;
+ unsigned int nregions;
+ unsigned int i, n;
+ size_t size;
+ char *name;
+ size_t name_size;
+ int ret;
+
+ device = &aux_dev->dev;
+
+ /* count available regions */
+ for (nregions = 0, i = 0; i < INTEL_DG_SPI_REGIONS; i++) {
+ if (ispi->regions[i].name)
+ nregions++;
+ }
+
+ if (!nregions) {
+ dev_err(device, "no regions defined\n");
+ return -ENODEV;
+ }
+
+ size = sizeof(*spi) + sizeof(spi->regions[0]) * nregions;
+ spi = kzalloc(size, GFP_KERNEL);
+ if (!spi)
+ return -ENOMEM;
+
+ kref_init(&spi->refcnt);
+
+ spi->nregions = nregions;
+ for (n = 0, i = 0; i < INTEL_DG_SPI_REGIONS; i++) {
+ if (ispi->regions[i].name) {
+ name_size = strlen(dev_name(&aux_dev->dev)) +
+ strlen(ispi->regions[i].name) + 2; /* for point */
+ name = kzalloc(name_size, GFP_KERNEL);
+ if (!name)
+ continue;
+ snprintf(name, name_size, "%s.%s",
+ dev_name(&aux_dev->dev), ispi->regions[i].name);
+ spi->regions[n].name = name;
+ spi->regions[n].id = i;
+ n++;
+ }
+ }
+
+ spi->base = devm_ioremap_resource(device, &ispi->bar);
+ if (IS_ERR(spi->base)) {
+ dev_err(device, "mmio not mapped\n");
+ ret = PTR_ERR(spi->base);
+ goto err;
+ }
+
+ dev_set_drvdata(&aux_dev->dev, spi);
+
+ return 0;
+
+err:
+ kref_put(&spi->refcnt, intel_dg_spi_release);
+ return ret;
+}
+
+static void intel_dg_spi_remove(struct auxiliary_device *aux_dev)
+{
+ struct intel_dg_spi *spi = dev_get_drvdata(&aux_dev->dev);
+
+ if (!spi)
+ return;
+
+ dev_set_drvdata(&aux_dev->dev, NULL);
+
+ kref_put(&spi->refcnt, intel_dg_spi_release);
+}
+
+static const struct auxiliary_device_id intel_dg_spi_id_table[] = {
+ {
+ .name = "i915.spi",
+ },
+ {
+ .name = "xe.spi",
+ },
+ {
+ /* sentinel */
+ }
+};
+MODULE_DEVICE_TABLE(auxiliary, intel_dg_spi_id_table);
+
+static struct auxiliary_driver intel_dg_spi_driver = {
+ .probe = intel_dg_spi_probe,
+ .remove = intel_dg_spi_remove,
+ .driver = {
+ /* auxiliary_driver_register() sets .name to be the modname */
+ },
+ .id_table = intel_dg_spi_id_table
+};
+
+module_auxiliary_driver(intel_dg_spi_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Intel Corporation");
+MODULE_DESCRIPTION("Intel DGFX SPI driver");
diff --git a/include/linux/intel_dg_spi_aux.h b/include/linux/intel_dg_spi_aux.h
new file mode 100644
index 000000000000..d4c3830d56d6
--- /dev/null
+++ b/include/linux/intel_dg_spi_aux.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright(c) 2019-2024, Intel Corporation. All rights reserved.
+ */
+
+#ifndef __INTEL_DG_SPI_AUX_H__
+#define __INTEL_DG_SPI_AUX_H__
+
+#include <linux/auxiliary_bus.h>
+
+#define INTEL_DG_SPI_REGIONS 13
+
+struct intel_dg_spi_region {
+ const char *name;
+};
+
+struct intel_dg_spi_dev {
+ struct auxiliary_device aux_dev;
+ bool writeable_override;
+ struct resource bar;
+ const struct intel_dg_spi_region *regions;
+};
+
+#define auxiliary_dev_to_intel_dg_spi_dev(auxiliary_dev) \
+ container_of(auxiliary_dev, struct intel_dg_spi_dev, aux_dev)
+
+#endif /* __INTEL_DG_SPI_AUX_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v6 02/12] spi: intel-dg: implement region enumeration
2024-09-16 13:49 [PATCH v6 00/12] spi: add driver for Intel discrete graphics Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 01/12] spi: add driver for intel graphics on-die spi device Alexander Usyskin
@ 2024-09-16 13:49 ` Alexander Usyskin
2024-09-18 13:35 ` Mark Brown
2024-09-16 13:49 ` [PATCH v6 03/12] spi: intel-dg: implement spi access functions Alexander Usyskin
` (10 subsequent siblings)
12 siblings, 1 reply; 34+ messages in thread
From: Alexander Usyskin @ 2024-09-16 13:49 UTC (permalink / raw)
To: Mark Brown, Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin
Cc: Tomas Winkler, Alexander Usyskin, Vitaly Lubart, intel-xe,
dri-devel, linux-spi, intel-gfx
From: Tomas Winkler <tomas.winkler@intel.com>
In intel-dg spi, there is no access to the spi controller,
the information is extracted from the descriptor region.
CC: Rodrigo Vivi <rodrigo.vivi@intel.com>
CC: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
---
drivers/spi/spi-intel-dg.c | 190 +++++++++++++++++++++++++++++++++++++
1 file changed, 190 insertions(+)
diff --git a/drivers/spi/spi-intel-dg.c b/drivers/spi/spi-intel-dg.c
index 4e302957f077..661e5189fa58 100644
--- a/drivers/spi/spi-intel-dg.c
+++ b/drivers/spi/spi-intel-dg.c
@@ -17,14 +17,197 @@ struct intel_dg_spi {
void __iomem *base;
size_t size;
unsigned int nregions;
+ u32 access_map;
struct {
const char *name;
u8 id;
u64 offset;
u64 size;
+ unsigned int is_readable:1;
+ unsigned int is_writable:1;
} regions[];
};
+#define SPI_TRIGGER_REG 0x00000000
+#define SPI_VALSIG_REG 0x00000010
+#define SPI_ADDRESS_REG 0x00000040
+#define SPI_REGION_ID_REG 0x00000044
+/*
+ * [15:0]-Erase size = 0x0010 4K 0x0080 32K 0x0100 64K
+ * [23:16]-Reserved
+ * [31:24]-Erase SPI RegionID
+ */
+#define SPI_ERASE_REG 0x00000048
+#define SPI_ACCESS_ERROR_REG 0x00000070
+#define SPI_ADDRESS_ERROR_REG 0x00000074
+
+/* Flash Valid Signature */
+#define SPI_FLVALSIG 0x0FF0A55A
+
+#define SPI_MAP_ADDR_MASK 0x000000FF
+#define SPI_MAP_ADDR_SHIFT 0x00000004
+
+#define REGION_ID_DESCRIPTOR 0
+/* Flash Region Base Address */
+#define FRBA 0x40
+/* Flash Region __n - Flash Descriptor Record */
+#define FLREG(__n) (FRBA + ((__n) * 4))
+/* Flash Map 1 Register */
+#define FLMAP1_REG 0x18
+#define FLMSTR4_OFFSET 0x00C
+
+#define SPI_ACCESS_ERROR_PCIE_MASK 0x7
+
+static inline void spi_set_region_id(struct intel_dg_spi *spi, u8 region)
+{
+ iowrite32((u32)region, spi->base + SPI_REGION_ID_REG);
+}
+
+static inline u32 spi_error(struct intel_dg_spi *spi)
+{
+ u32 reg = ioread32(spi->base + SPI_ACCESS_ERROR_REG) &
+ SPI_ACCESS_ERROR_PCIE_MASK;
+
+ /* reset error bits */
+ if (reg)
+ iowrite32(reg, spi->base + SPI_ACCESS_ERROR_REG);
+
+ return reg;
+}
+
+static inline u32 spi_read32(struct intel_dg_spi *spi, u32 address)
+{
+ void __iomem *base = spi->base;
+
+ iowrite32(address, base + SPI_ADDRESS_REG);
+
+ return ioread32(base + SPI_TRIGGER_REG);
+}
+
+static int spi_get_access_map(struct intel_dg_spi *spi)
+{
+ u32 flmap1;
+ u32 fmba;
+ u32 fmstr4;
+ u32 fmstr4_addr;
+
+ spi_set_region_id(spi, REGION_ID_DESCRIPTOR);
+
+ flmap1 = spi_read32(spi, FLMAP1_REG);
+ if (spi_error(spi))
+ return -EIO;
+ /* Get Flash Master Baser Address (FMBA) */
+ fmba = ((flmap1 & SPI_MAP_ADDR_MASK) << SPI_MAP_ADDR_SHIFT);
+ fmstr4_addr = fmba + FLMSTR4_OFFSET;
+
+ fmstr4 = spi_read32(spi, fmstr4_addr);
+ if (spi_error(spi))
+ return -EIO;
+
+ spi->access_map = fmstr4;
+ return 0;
+}
+
+static bool spi_region_readable(struct intel_dg_spi *spi, u8 region)
+{
+ if (region < 12)
+ return spi->access_map & (1 << (region + 8)); /* [19:8] */
+ else
+ return spi->access_map & (1 << (region - 12)); /* [3:0] */
+}
+
+static bool spi_region_writeable(struct intel_dg_spi *spi, u8 region)
+{
+ if (region < 12)
+ return spi->access_map & (1 << (region + 20)); /* [31:20] */
+ else
+ return spi->access_map & (1 << (region - 8)); /* [7:4] */
+}
+
+static int intel_dg_spi_is_valid(struct intel_dg_spi *spi)
+{
+ u32 is_valid;
+
+ spi_set_region_id(spi, REGION_ID_DESCRIPTOR);
+
+ is_valid = spi_read32(spi, SPI_VALSIG_REG);
+ if (spi_error(spi))
+ return -EIO;
+
+ if (is_valid != SPI_FLVALSIG)
+ return -ENODEV;
+
+ return 0;
+}
+
+static int intel_dg_spi_init(struct intel_dg_spi *spi, struct device *device)
+{
+ int ret;
+ unsigned int i, n;
+
+ /* clean error register, previous errors are ignored */
+ spi_error(spi);
+
+ ret = intel_dg_spi_is_valid(spi);
+ if (ret) {
+ dev_err(device, "The SPI is not valid %d\n", ret);
+ return ret;
+ }
+
+ if (spi_get_access_map(spi))
+ return -EIO;
+
+ for (i = 0, n = 0; i < spi->nregions; i++) {
+ u32 address, base, limit, region;
+ u8 id = spi->regions[i].id;
+
+ address = FLREG(id);
+ region = spi_read32(spi, address);
+
+ base = (region & 0x0000FFFF) << 12;
+ limit = (((region & 0xFFFF0000) >> 16) << 12) | 0xFFF;
+
+ dev_dbg(device, "[%d] %s: region: 0x%08X base: 0x%08x limit: 0x%08x\n",
+ id, spi->regions[i].name, region, base, limit);
+
+ if (base >= limit || (i > 0 && limit == 0)) {
+ dev_dbg(device, "[%d] %s: disabled\n",
+ id, spi->regions[i].name);
+ spi->regions[i].is_readable = 0;
+ continue;
+ }
+
+ if (spi->size < limit)
+ spi->size = limit;
+
+ spi->regions[i].offset = base;
+ spi->regions[i].size = limit - base + 1;
+ /* No write access to descriptor; mask it out*/
+ spi->regions[i].is_writable = spi_region_writeable(spi, id);
+
+ spi->regions[i].is_readable = spi_region_readable(spi, id);
+ dev_dbg(device, "Registered, %s id=%d offset=%lld size=%lld rd=%d wr=%d\n",
+ spi->regions[i].name,
+ spi->regions[i].id,
+ spi->regions[i].offset,
+ spi->regions[i].size,
+ spi->regions[i].is_readable,
+ spi->regions[i].is_writable);
+
+ if (spi->regions[i].is_readable)
+ n++;
+ }
+
+ dev_dbg(device, "Registered %d regions\n", n);
+
+ /* Need to add 1 to the amount of memory
+ * so it is reported as an even block
+ */
+ spi->size += 1;
+
+ return n;
+}
+
static void intel_dg_spi_release(struct kref *kref)
{
struct intel_dg_spi *spi = container_of(kref, struct intel_dg_spi, refcnt);
@@ -92,6 +275,13 @@ static int intel_dg_spi_probe(struct auxiliary_device *aux_dev,
goto err;
}
+ ret = intel_dg_spi_init(spi, device);
+ if (ret < 0) {
+ dev_err(device, "cannot initialize spi\n");
+ ret = -ENODEV;
+ goto err;
+ }
+
dev_set_drvdata(&aux_dev->dev, spi);
return 0;
--
2.34.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v6 03/12] spi: intel-dg: implement spi access functions
2024-09-16 13:49 [PATCH v6 00/12] spi: add driver for Intel discrete graphics Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 01/12] spi: add driver for intel graphics on-die spi device Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 02/12] spi: intel-dg: implement region enumeration Alexander Usyskin
@ 2024-09-16 13:49 ` Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 04/12] spi: intel-dg: spi register with mtd Alexander Usyskin
` (9 subsequent siblings)
12 siblings, 0 replies; 34+ messages in thread
From: Alexander Usyskin @ 2024-09-16 13:49 UTC (permalink / raw)
To: Mark Brown, Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin
Cc: Tomas Winkler, Alexander Usyskin, Vitaly Lubart, intel-xe,
dri-devel, linux-spi, intel-gfx
From: Tomas Winkler <tomas.winkler@intel.com>
Implement spi_read(), spi_erase() and spi_write() functions.
CC: Lucas De Marchi <lucas.demarchi@intel.com>
CC: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Vitaly Lubart <vitaly.lubart@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
---
drivers/spi/spi-intel-dg.c | 199 +++++++++++++++++++++++++++++++++++++
1 file changed, 199 insertions(+)
diff --git a/drivers/spi/spi-intel-dg.c b/drivers/spi/spi-intel-dg.c
index 661e5189fa58..863898c8739c 100644
--- a/drivers/spi/spi-intel-dg.c
+++ b/drivers/spi/spi-intel-dg.c
@@ -3,13 +3,16 @@
* Copyright(c) 2019-2024, Intel Corporation. All rights reserved.
*/
+#include <linux/delay.h>
#include <linux/device.h>
#include <linux/intel_dg_spi_aux.h>
#include <linux/io.h>
+#include <linux/io-64-nonatomic-lo-hi.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/slab.h>
+#include <linux/sizes.h>
#include <linux/types.h>
struct intel_dg_spi {
@@ -84,6 +87,33 @@ static inline u32 spi_read32(struct intel_dg_spi *spi, u32 address)
return ioread32(base + SPI_TRIGGER_REG);
}
+static inline u64 spi_read64(struct intel_dg_spi *spi, u32 address)
+{
+ void __iomem *base = spi->base;
+
+ iowrite32(address, base + SPI_ADDRESS_REG);
+
+ return readq(base + SPI_TRIGGER_REG);
+}
+
+static void spi_write32(struct intel_dg_spi *spi, u32 address, u32 data)
+{
+ void __iomem *base = spi->base;
+
+ iowrite32(address, base + SPI_ADDRESS_REG);
+
+ iowrite32(data, base + SPI_TRIGGER_REG);
+}
+
+static void spi_write64(struct intel_dg_spi *spi, u32 address, u64 data)
+{
+ void __iomem *base = spi->base;
+
+ iowrite32(address, base + SPI_ADDRESS_REG);
+
+ writeq(data, base + SPI_TRIGGER_REG);
+}
+
static int spi_get_access_map(struct intel_dg_spi *spi)
{
u32 flmap1;
@@ -140,6 +170,175 @@ static int intel_dg_spi_is_valid(struct intel_dg_spi *spi)
return 0;
}
+__maybe_unused
+static unsigned int spi_get_region(const struct intel_dg_spi *spi, loff_t from)
+{
+ unsigned int i;
+
+ for (i = 0; i < spi->nregions; i++) {
+ if ((spi->regions[i].offset + spi->regions[i].size - 1) > from &&
+ spi->regions[i].offset <= from &&
+ spi->regions[i].size != 0)
+ break;
+ }
+
+ return i;
+}
+
+static ssize_t spi_rewrite_partial(struct intel_dg_spi *spi, loff_t to,
+ loff_t offset, size_t len, const u32 *newdata)
+{
+ u32 data = spi_read32(spi, to);
+
+ if (spi_error(spi))
+ return -EIO;
+
+ memcpy((u8 *)&data + offset, newdata, len);
+
+ spi_write32(spi, to, data);
+ if (spi_error(spi))
+ return -EIO;
+
+ return len;
+}
+
+__maybe_unused
+static ssize_t spi_write(struct intel_dg_spi *spi, u8 region,
+ loff_t to, size_t len, const unsigned char *buf)
+{
+ size_t i;
+ size_t len8;
+ size_t len4;
+ size_t to4;
+ size_t to_shift;
+ size_t len_s = len;
+ ssize_t ret;
+
+ spi_set_region_id(spi, region);
+
+ to4 = ALIGN_DOWN(to, sizeof(u32));
+ to_shift = min(sizeof(u32) - ((size_t)to - to4), len);
+ if (to - to4) {
+ ret = spi_rewrite_partial(spi, to4, to - to4, to_shift,
+ (uint32_t *)&buf[0]);
+ if (ret < 0)
+ return ret;
+
+ buf += to_shift;
+ to += to_shift;
+ len_s -= to_shift;
+ }
+
+ len8 = ALIGN_DOWN(len_s, sizeof(u64));
+ for (i = 0; i < len8; i += sizeof(u64)) {
+ u64 data;
+
+ memcpy(&data, &buf[i], sizeof(u64));
+ spi_write64(spi, to + i, data);
+ if (spi_error(spi))
+ return -EIO;
+ }
+
+ len4 = len_s - len8;
+ if (len4 >= sizeof(u32)) {
+ u32 data;
+
+ memcpy(&data, &buf[i], sizeof(u32));
+ spi_write32(spi, to + i, data);
+ if (spi_error(spi))
+ return -EIO;
+ i += sizeof(u32);
+ len4 -= sizeof(u32);
+ }
+
+ if (len4 > 0) {
+ ret = spi_rewrite_partial(spi, to + i, 0, len4,
+ (uint32_t *)&buf[i]);
+ if (ret < 0)
+ return ret;
+ }
+
+ return len;
+}
+
+__maybe_unused
+static ssize_t spi_read(struct intel_dg_spi *spi, u8 region,
+ loff_t from, size_t len, unsigned char *buf)
+{
+ size_t i;
+ size_t len8;
+ size_t len4;
+ size_t from4;
+ size_t from_shift;
+ size_t len_s = len;
+
+ spi_set_region_id(spi, region);
+
+ from4 = ALIGN_DOWN(from, sizeof(u32));
+ from_shift = min(sizeof(u32) - ((size_t)from - from4), len);
+
+ if (from - from4) {
+ u32 data = spi_read32(spi, from4);
+
+ if (spi_error(spi))
+ return -EIO;
+ memcpy(&buf[0], (u8 *)&data + (from - from4), from_shift);
+ len_s -= from_shift;
+ buf += from_shift;
+ from += from_shift;
+ }
+
+ len8 = ALIGN_DOWN(len_s, sizeof(u64));
+ for (i = 0; i < len8; i += sizeof(u64)) {
+ u64 data = spi_read64(spi, from + i);
+
+ if (spi_error(spi))
+ return -EIO;
+
+ memcpy(&buf[i], &data, sizeof(data));
+ }
+
+ len4 = len_s - len8;
+ if (len4 >= sizeof(u32)) {
+ u32 data = spi_read32(spi, from + i);
+
+ if (spi_error(spi))
+ return -EIO;
+ memcpy(&buf[i], &data, sizeof(data));
+ i += sizeof(u32);
+ len4 -= sizeof(u32);
+ }
+
+ if (len4 > 0) {
+ u32 data = spi_read32(spi, from + i);
+
+ if (spi_error(spi))
+ return -EIO;
+ memcpy(&buf[i], &data, len4);
+ }
+
+ return len;
+}
+
+__maybe_unused
+static ssize_t
+spi_erase(struct intel_dg_spi *spi, u8 region, loff_t from, u64 len, u64 *fail_addr)
+{
+ u64 i;
+ const u32 block = 0x10;
+ void __iomem *base = spi->base;
+
+ for (i = 0; i < len; i += SZ_4K) {
+ iowrite32(from + i, base + SPI_ADDRESS_REG);
+ iowrite32(region << 24 | block, base + SPI_ERASE_REG);
+ /* Since the writes are via sguint
+ * we cannot do back to back erases.
+ */
+ msleep(50);
+ }
+ return len;
+}
+
static int intel_dg_spi_init(struct intel_dg_spi *spi, struct device *device)
{
int ret;
--
2.34.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v6 04/12] spi: intel-dg: spi register with mtd
2024-09-16 13:49 [PATCH v6 00/12] spi: add driver for Intel discrete graphics Alexander Usyskin
` (2 preceding siblings ...)
2024-09-16 13:49 ` [PATCH v6 03/12] spi: intel-dg: implement spi access functions Alexander Usyskin
@ 2024-09-16 13:49 ` Alexander Usyskin
2024-09-18 13:38 ` Mark Brown
2024-09-16 13:49 ` [PATCH v6 05/12] spi: intel-dg: implement mtd access handlers Alexander Usyskin
` (8 subsequent siblings)
12 siblings, 1 reply; 34+ messages in thread
From: Alexander Usyskin @ 2024-09-16 13:49 UTC (permalink / raw)
To: Mark Brown, Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin
Cc: Tomas Winkler, Alexander Usyskin, Vitaly Lubart, intel-xe,
dri-devel, linux-spi, intel-gfx
From: Tomas Winkler <tomas.winkler@intel.com>
Register the on-die spi device with the mtd subsystem.
Refcount spi object on _get and _put mtd callbacks.
CC: Rodrigo Vivi <rodrigo.vivi@intel.com>
CC: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
---
drivers/spi/spi-intel-dg.c | 111 +++++++++++++++++++++++++++++++++++++
1 file changed, 111 insertions(+)
diff --git a/drivers/spi/spi-intel-dg.c b/drivers/spi/spi-intel-dg.c
index 863898c8739c..a936014f1a76 100644
--- a/drivers/spi/spi-intel-dg.c
+++ b/drivers/spi/spi-intel-dg.c
@@ -10,6 +10,8 @@
#include <linux/io-64-nonatomic-lo-hi.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/sizes.h>
@@ -17,6 +19,8 @@
struct intel_dg_spi {
struct kref refcnt;
+ struct mtd_info mtd;
+ struct mutex lock; /* region access lock */
void __iomem *base;
size_t size;
unsigned int nregions;
@@ -407,6 +411,23 @@ static int intel_dg_spi_init(struct intel_dg_spi *spi, struct device *device)
return n;
}
+static int intel_dg_spi_erase(struct mtd_info *mtd, struct erase_info *info)
+{
+ return 0;
+}
+
+static int intel_dg_spi_read(struct mtd_info *mtd, loff_t from, size_t len,
+ size_t *retlen, u_char *buf)
+{
+ return 0;
+}
+
+static int intel_dg_spi_write(struct mtd_info *mtd, loff_t to, size_t len,
+ size_t *retlen, const u_char *buf)
+{
+ return 0;
+}
+
static void intel_dg_spi_release(struct kref *kref)
{
struct intel_dg_spi *spi = container_of(kref, struct intel_dg_spi, refcnt);
@@ -415,9 +436,90 @@ static void intel_dg_spi_release(struct kref *kref)
pr_debug("freeing spi memory\n");
for (i = 0; i < spi->nregions; i++)
kfree(spi->regions[i].name);
+ mutex_destroy(&spi->lock);
kfree(spi);
}
+static int intel_dg_spi_get_device(struct mtd_info *mtd)
+{
+ struct mtd_info *master;
+ struct intel_dg_spi *spi;
+
+ if (!mtd)
+ return -ENODEV;
+
+ master = mtd_get_master(mtd);
+ spi = master->priv;
+ if (WARN_ON(!spi))
+ return -EINVAL;
+ pr_debug("get spi %s %d\n", mtd->name, kref_read(&spi->refcnt));
+ kref_get(&spi->refcnt);
+
+ return 0;
+}
+
+static void intel_dg_spi_put_device(struct mtd_info *mtd)
+{
+ struct mtd_info *master;
+ struct intel_dg_spi *spi;
+
+ if (!mtd)
+ return;
+
+ master = mtd_get_master(mtd);
+ spi = master->priv;
+ if (WARN_ON(!spi))
+ return;
+ pr_debug("put spi %s %d\n", mtd->name, kref_read(&spi->refcnt));
+ kref_put(&spi->refcnt, intel_dg_spi_release);
+}
+
+static int intel_dg_spi_init_mtd(struct intel_dg_spi *spi, struct device *device,
+ unsigned int nparts, bool writeable_override)
+{
+ unsigned int i;
+ unsigned int n;
+ struct mtd_partition *parts = NULL;
+ int ret;
+
+ dev_dbg(device, "registering with mtd\n");
+
+ spi->mtd.owner = THIS_MODULE;
+ spi->mtd.dev.parent = device;
+ spi->mtd.flags = MTD_CAP_NORFLASH | MTD_WRITEABLE;
+ spi->mtd.type = MTD_DATAFLASH;
+ spi->mtd.priv = spi;
+ spi->mtd._write = intel_dg_spi_write;
+ spi->mtd._read = intel_dg_spi_read;
+ spi->mtd._erase = intel_dg_spi_erase;
+ spi->mtd._get_device = intel_dg_spi_get_device;
+ spi->mtd._put_device = intel_dg_spi_put_device;
+ spi->mtd.writesize = SZ_1; /* 1 byte granularity */
+ spi->mtd.erasesize = SZ_4K; /* 4K bytes granularity */
+ spi->mtd.size = spi->size;
+
+ parts = kcalloc(spi->nregions, sizeof(*parts), GFP_KERNEL);
+ if (!parts)
+ return -ENOMEM;
+
+ for (i = 0, n = 0; i < spi->nregions && n < nparts; i++) {
+ if (!spi->regions[i].is_readable)
+ continue;
+ parts[n].name = spi->regions[i].name;
+ parts[n].offset = spi->regions[i].offset;
+ parts[n].size = spi->regions[i].size;
+ if (!spi->regions[i].is_writable && !writeable_override)
+ parts[n].mask_flags = MTD_WRITEABLE;
+ n++;
+ }
+
+ ret = mtd_device_register(&spi->mtd, parts, n);
+
+ kfree(parts);
+
+ return ret;
+}
+
static int intel_dg_spi_probe(struct auxiliary_device *aux_dev,
const struct auxiliary_device_id *aux_dev_id)
{
@@ -449,6 +551,7 @@ static int intel_dg_spi_probe(struct auxiliary_device *aux_dev,
if (!spi)
return -ENOMEM;
+ mutex_init(&spi->lock);
kref_init(&spi->refcnt);
spi->nregions = nregions;
@@ -481,6 +584,12 @@ static int intel_dg_spi_probe(struct auxiliary_device *aux_dev,
goto err;
}
+ ret = intel_dg_spi_init_mtd(spi, device, ret, ispi->writeable_override);
+ if (ret) {
+ dev_err(device, "failed init mtd %d\n", ret);
+ goto err;
+ }
+
dev_set_drvdata(&aux_dev->dev, spi);
return 0;
@@ -497,6 +606,8 @@ static void intel_dg_spi_remove(struct auxiliary_device *aux_dev)
if (!spi)
return;
+ mtd_device_unregister(&spi->mtd);
+
dev_set_drvdata(&aux_dev->dev, NULL);
kref_put(&spi->refcnt, intel_dg_spi_release);
--
2.34.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v6 05/12] spi: intel-dg: implement mtd access handlers
2024-09-16 13:49 [PATCH v6 00/12] spi: add driver for Intel discrete graphics Alexander Usyskin
` (3 preceding siblings ...)
2024-09-16 13:49 ` [PATCH v6 04/12] spi: intel-dg: spi register with mtd Alexander Usyskin
@ 2024-09-16 13:49 ` Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 06/12] spi: intel-dg: align 64bit read and write Alexander Usyskin
` (7 subsequent siblings)
12 siblings, 0 replies; 34+ messages in thread
From: Alexander Usyskin @ 2024-09-16 13:49 UTC (permalink / raw)
To: Mark Brown, Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin
Cc: Tomas Winkler, Alexander Usyskin, Vitaly Lubart, intel-xe,
dri-devel, linux-spi, intel-gfx
From: Tomas Winkler <tomas.winkler@intel.com>
Implement mtd read, erase, and write handlers.
For erase operation address and size should be 4K aligned.
For write operation address and size has to be 4bytes aligned.
CC: Rodrigo Vivi <rodrigo.vivi@intel.com>
CC: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Vitaly Lubart <vitaly.lubart@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
---
drivers/spi/spi-intel-dg.c | 152 +++++++++++++++++++++++++++++++++++--
1 file changed, 147 insertions(+), 5 deletions(-)
diff --git a/drivers/spi/spi-intel-dg.c b/drivers/spi/spi-intel-dg.c
index a936014f1a76..dfb457c43a5d 100644
--- a/drivers/spi/spi-intel-dg.c
+++ b/drivers/spi/spi-intel-dg.c
@@ -174,7 +174,6 @@ static int intel_dg_spi_is_valid(struct intel_dg_spi *spi)
return 0;
}
-__maybe_unused
static unsigned int spi_get_region(const struct intel_dg_spi *spi, loff_t from)
{
unsigned int i;
@@ -206,7 +205,6 @@ static ssize_t spi_rewrite_partial(struct intel_dg_spi *spi, loff_t to,
return len;
}
-__maybe_unused
static ssize_t spi_write(struct intel_dg_spi *spi, u8 region,
loff_t to, size_t len, const unsigned char *buf)
{
@@ -265,7 +263,6 @@ static ssize_t spi_write(struct intel_dg_spi *spi, u8 region,
return len;
}
-__maybe_unused
static ssize_t spi_read(struct intel_dg_spi *spi, u8 region,
loff_t from, size_t len, unsigned char *buf)
{
@@ -324,7 +321,6 @@ static ssize_t spi_read(struct intel_dg_spi *spi, u8 region,
return len;
}
-__maybe_unused
static ssize_t
spi_erase(struct intel_dg_spi *spi, u8 region, loff_t from, u64 len, u64 *fail_addr)
{
@@ -413,18 +409,164 @@ static int intel_dg_spi_init(struct intel_dg_spi *spi, struct device *device)
static int intel_dg_spi_erase(struct mtd_info *mtd, struct erase_info *info)
{
- return 0;
+ struct intel_dg_spi *spi;
+ unsigned int idx;
+ u8 region;
+ u64 addr;
+ ssize_t bytes;
+ loff_t from;
+ size_t len;
+ size_t total_len;
+ int ret = 0;
+
+ if (!mtd || !info)
+ return -EINVAL;
+
+ spi = mtd->priv;
+ if (WARN_ON(!spi))
+ return -EINVAL;
+
+ if (!IS_ALIGNED(info->addr, SZ_4K) || !IS_ALIGNED(info->len, SZ_4K)) {
+ dev_err(&mtd->dev, "unaligned erase %llx %llx\n",
+ info->addr, info->len);
+ info->fail_addr = MTD_FAIL_ADDR_UNKNOWN;
+ return -EINVAL;
+ }
+
+ total_len = info->len;
+ addr = info->addr;
+
+ mutex_lock(&spi->lock);
+
+ while (total_len > 0) {
+ if (!IS_ALIGNED(addr, SZ_4K) || !IS_ALIGNED(total_len, SZ_4K)) {
+ dev_err(&mtd->dev, "unaligned erase %llx %zx\n", addr, total_len);
+ info->fail_addr = addr;
+ ret = -ERANGE;
+ goto out;
+ }
+
+ idx = spi_get_region(spi, addr);
+ if (idx >= spi->nregions) {
+ dev_err(&mtd->dev, "out of range");
+ info->fail_addr = MTD_FAIL_ADDR_UNKNOWN;
+ ret = -ERANGE;
+ goto out;
+ }
+
+ from = addr - spi->regions[idx].offset;
+ region = spi->regions[idx].id;
+ len = total_len;
+ if (len > spi->regions[idx].size - from)
+ len = spi->regions[idx].size - from;
+
+ dev_dbg(&mtd->dev, "erasing region[%d] %s from %llx len %zx\n",
+ region, spi->regions[idx].name, from, len);
+
+ bytes = spi_erase(spi, region, from, len, &info->fail_addr);
+ if (bytes < 0) {
+ dev_dbg(&mtd->dev, "erase failed with %zd\n", bytes);
+ info->fail_addr += spi->regions[idx].offset;
+ ret = bytes;
+ goto out;
+ }
+
+ addr += len;
+ total_len -= len;
+ }
+
+out:
+ mutex_unlock(&spi->lock);
+ return ret;
}
static int intel_dg_spi_read(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, u_char *buf)
{
+ struct intel_dg_spi *spi;
+ ssize_t ret;
+ unsigned int idx;
+ u8 region;
+
+ if (!mtd)
+ return -EINVAL;
+
+ spi = mtd->priv;
+ if (WARN_ON(!spi))
+ return -EINVAL;
+
+ idx = spi_get_region(spi, from);
+
+ dev_dbg(&mtd->dev, "reading region[%d] %s from %lld len %zd\n",
+ spi->regions[idx].id, spi->regions[idx].name, from, len);
+
+ if (idx >= spi->nregions) {
+ dev_err(&mtd->dev, "out of ragnge");
+ return -ERANGE;
+ }
+
+ from -= spi->regions[idx].offset;
+ region = spi->regions[idx].id;
+ if (len > spi->regions[idx].size - from)
+ len = spi->regions[idx].size - from;
+
+ mutex_lock(&spi->lock);
+
+ ret = spi_read(spi, region, from, len, buf);
+ if (ret < 0) {
+ dev_dbg(&mtd->dev, "read failed with %zd\n", ret);
+ mutex_unlock(&spi->lock);
+ return ret;
+ }
+
+ *retlen = ret;
+
+ mutex_unlock(&spi->lock);
return 0;
}
static int intel_dg_spi_write(struct mtd_info *mtd, loff_t to, size_t len,
size_t *retlen, const u_char *buf)
{
+ struct intel_dg_spi *spi;
+ ssize_t ret;
+ unsigned int idx;
+ u8 region;
+
+ if (!mtd)
+ return -EINVAL;
+
+ spi = mtd->priv;
+ if (WARN_ON(!spi))
+ return -EINVAL;
+
+ idx = spi_get_region(spi, to);
+
+ dev_dbg(&mtd->dev, "writing region[%d] %s to %lld len %zd\n",
+ spi->regions[idx].id, spi->regions[idx].name, to, len);
+
+ if (idx >= spi->nregions) {
+ dev_err(&mtd->dev, "out of range");
+ return -ERANGE;
+ }
+
+ to -= spi->regions[idx].offset;
+ region = spi->regions[idx].id;
+ if (len > spi->regions[idx].size - to)
+ len = spi->regions[idx].size - to;
+
+ mutex_lock(&spi->lock);
+
+ ret = spi_write(spi, region, to, len, buf);
+ if (ret < 0) {
+ dev_dbg(&mtd->dev, "write failed with %zd\n", ret);
+ mutex_unlock(&spi->lock);
+ return ret;
+ }
+
+ *retlen = ret;
+
+ mutex_unlock(&spi->lock);
return 0;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v6 06/12] spi: intel-dg: align 64bit read and write
2024-09-16 13:49 [PATCH v6 00/12] spi: add driver for Intel discrete graphics Alexander Usyskin
` (4 preceding siblings ...)
2024-09-16 13:49 ` [PATCH v6 05/12] spi: intel-dg: implement mtd access handlers Alexander Usyskin
@ 2024-09-16 13:49 ` Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 07/12] spi: intel-dg: wake card on operations Alexander Usyskin
` (6 subsequent siblings)
12 siblings, 0 replies; 34+ messages in thread
From: Alexander Usyskin @ 2024-09-16 13:49 UTC (permalink / raw)
To: Mark Brown, Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin
Cc: Tomas Winkler, Alexander Usyskin, Vitaly Lubart, intel-xe,
dri-devel, linux-spi, intel-gfx
GSC SPI HW errors on quad access overlapping 1K border.
Align 64bit read and write to avoid readq/writeq over 1K border.
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
---
drivers/spi/spi-intel-dg.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/drivers/spi/spi-intel-dg.c b/drivers/spi/spi-intel-dg.c
index dfb457c43a5d..c76b0a70f8d8 100644
--- a/drivers/spi/spi-intel-dg.c
+++ b/drivers/spi/spi-intel-dg.c
@@ -231,6 +231,24 @@ static ssize_t spi_write(struct intel_dg_spi *spi, u8 region,
len_s -= to_shift;
}
+ if (!IS_ALIGNED(to, sizeof(u64)) &&
+ ((to ^ (to + len_s)) & GENMASK(31, 10))) {
+ /*
+ * Workaround reads/writes across 1k-aligned addresses
+ * (start u32 before 1k, end u32 after)
+ * as this fails on hardware.
+ */
+ u32 data;
+
+ memcpy(&data, &buf[0], sizeof(u32));
+ spi_write32(spi, to, data);
+ if (spi_error(spi))
+ return -EIO;
+ buf += sizeof(u32);
+ to += sizeof(u32);
+ len_s -= sizeof(u32);
+ }
+
len8 = ALIGN_DOWN(len_s, sizeof(u64));
for (i = 0; i < len8; i += sizeof(u64)) {
u64 data;
@@ -289,6 +307,23 @@ static ssize_t spi_read(struct intel_dg_spi *spi, u8 region,
from += from_shift;
}
+ if (!IS_ALIGNED(from, sizeof(u64)) &&
+ ((from ^ (from + len_s)) & GENMASK(31, 10))) {
+ /*
+ * Workaround reads/writes across 1k-aligned addresses
+ * (start u32 before 1k, end u32 after)
+ * as this fails on hardware.
+ */
+ u32 data = spi_read32(spi, from);
+
+ if (spi_error(spi))
+ return -EIO;
+ memcpy(&buf[0], &data, sizeof(data));
+ len_s -= sizeof(u32);
+ buf += sizeof(u32);
+ from += sizeof(u32);
+ }
+
len8 = ALIGN_DOWN(len_s, sizeof(u64));
for (i = 0; i < len8; i += sizeof(u64)) {
u64 data = spi_read64(spi, from + i);
--
2.34.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v6 07/12] spi: intel-dg: wake card on operations
2024-09-16 13:49 [PATCH v6 00/12] spi: add driver for Intel discrete graphics Alexander Usyskin
` (5 preceding siblings ...)
2024-09-16 13:49 ` [PATCH v6 06/12] spi: intel-dg: align 64bit read and write Alexander Usyskin
@ 2024-09-16 13:49 ` Alexander Usyskin
2024-09-16 18:00 ` Rodrigo Vivi
2024-09-16 13:49 ` [PATCH v6 08/12] drm/i915/spi: add spi device for discrete graphics Alexander Usyskin
` (5 subsequent siblings)
12 siblings, 1 reply; 34+ messages in thread
From: Alexander Usyskin @ 2024-09-16 13:49 UTC (permalink / raw)
To: Mark Brown, Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin
Cc: Tomas Winkler, Alexander Usyskin, Vitaly Lubart, intel-xe,
dri-devel, linux-spi, intel-gfx
Enable runtime PM in spi driver to notify graphics driver that
whole card should be kept awake while spi operations are
performed through this driver.
CC: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
---
drivers/spi/spi-intel-dg.c | 44 ++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/drivers/spi/spi-intel-dg.c b/drivers/spi/spi-intel-dg.c
index c76b0a70f8d8..a14fc3190520 100644
--- a/drivers/spi/spi-intel-dg.c
+++ b/drivers/spi/spi-intel-dg.c
@@ -12,11 +12,14 @@
#include <linux/module.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
+#include <linux/pm_runtime.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/sizes.h>
#include <linux/types.h>
+#define INTEL_DG_SPI_RPM_TIMEOUT 500
+
struct intel_dg_spi {
struct kref refcnt;
struct mtd_info mtd;
@@ -471,6 +474,12 @@ static int intel_dg_spi_erase(struct mtd_info *mtd, struct erase_info *info)
total_len = info->len;
addr = info->addr;
+ ret = pm_runtime_resume_and_get(mtd->dev.parent);
+ if (ret < 0) {
+ dev_err(&mtd->dev, "rpm: get failed %d\n", ret);
+ return ret;
+ }
+
mutex_lock(&spi->lock);
while (total_len > 0) {
@@ -512,6 +521,8 @@ static int intel_dg_spi_erase(struct mtd_info *mtd, struct erase_info *info)
out:
mutex_unlock(&spi->lock);
+ pm_runtime_mark_last_busy(mtd->dev.parent);
+ pm_runtime_put_autosuspend(mtd->dev.parent);
return ret;
}
@@ -545,6 +556,12 @@ static int intel_dg_spi_read(struct mtd_info *mtd, loff_t from, size_t len,
if (len > spi->regions[idx].size - from)
len = spi->regions[idx].size - from;
+ ret = pm_runtime_resume_and_get(mtd->dev.parent);
+ if (ret < 0) {
+ dev_err(&mtd->dev, "rpm: get failed %zd\n", ret);
+ return ret;
+ }
+
mutex_lock(&spi->lock);
ret = spi_read(spi, region, from, len, buf);
@@ -557,6 +574,8 @@ static int intel_dg_spi_read(struct mtd_info *mtd, loff_t from, size_t len,
*retlen = ret;
mutex_unlock(&spi->lock);
+ pm_runtime_mark_last_busy(mtd->dev.parent);
+ pm_runtime_put_autosuspend(mtd->dev.parent);
return 0;
}
@@ -590,6 +609,12 @@ static int intel_dg_spi_write(struct mtd_info *mtd, loff_t to, size_t len,
if (len > spi->regions[idx].size - to)
len = spi->regions[idx].size - to;
+ ret = pm_runtime_resume_and_get(mtd->dev.parent);
+ if (ret < 0) {
+ dev_err(&mtd->dev, "rpm: get failed %zd\n", ret);
+ return ret;
+ }
+
mutex_lock(&spi->lock);
ret = spi_write(spi, region, to, len, buf);
@@ -602,6 +627,8 @@ static int intel_dg_spi_write(struct mtd_info *mtd, loff_t to, size_t len,
*retlen = ret;
mutex_unlock(&spi->lock);
+ pm_runtime_mark_last_busy(mtd->dev.parent);
+ pm_runtime_put_autosuspend(mtd->dev.parent);
return 0;
}
@@ -747,6 +774,17 @@ static int intel_dg_spi_probe(struct auxiliary_device *aux_dev,
}
}
+ pm_runtime_enable(device);
+
+ pm_runtime_set_autosuspend_delay(device, INTEL_DG_SPI_RPM_TIMEOUT);
+ pm_runtime_use_autosuspend(device);
+
+ ret = pm_runtime_resume_and_get(device);
+ if (ret < 0) {
+ dev_err(device, "rpm: get failed %d\n", ret);
+ goto err_norpm;
+ }
+
spi->base = devm_ioremap_resource(device, &ispi->bar);
if (IS_ERR(spi->base)) {
dev_err(device, "mmio not mapped\n");
@@ -769,9 +807,13 @@ static int intel_dg_spi_probe(struct auxiliary_device *aux_dev,
dev_set_drvdata(&aux_dev->dev, spi);
+ pm_runtime_put(device);
return 0;
err:
+ pm_runtime_put(device);
+err_norpm:
+ pm_runtime_disable(device);
kref_put(&spi->refcnt, intel_dg_spi_release);
return ret;
}
@@ -783,6 +825,8 @@ static void intel_dg_spi_remove(struct auxiliary_device *aux_dev)
if (!spi)
return;
+ pm_runtime_disable(&aux_dev->dev);
+
mtd_device_unregister(&spi->mtd);
dev_set_drvdata(&aux_dev->dev, NULL);
--
2.34.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v6 08/12] drm/i915/spi: add spi device for discrete graphics
2024-09-16 13:49 [PATCH v6 00/12] spi: add driver for Intel discrete graphics Alexander Usyskin
` (6 preceding siblings ...)
2024-09-16 13:49 ` [PATCH v6 07/12] spi: intel-dg: wake card on operations Alexander Usyskin
@ 2024-09-16 13:49 ` Alexander Usyskin
2024-09-23 8:31 ` Jani Nikula
2024-09-16 13:49 ` [PATCH v6 09/12] drm/i915/spi: add intel_spi_region map Alexander Usyskin
` (4 subsequent siblings)
12 siblings, 1 reply; 34+ messages in thread
From: Alexander Usyskin @ 2024-09-16 13:49 UTC (permalink / raw)
To: Mark Brown, Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin
Cc: Tomas Winkler, Alexander Usyskin, Vitaly Lubart, intel-xe,
dri-devel, linux-spi, intel-gfx
From: Tomas Winkler <tomas.winkler@intel.com>
Enable access to internal spi on DGFX devices via a child device.
The spi child device is exposed via auxiliary bus.
CC: Rodrigo Vivi <rodrigo.vivi@intel.com>
CC: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
---
drivers/gpu/drm/i915/Makefile | 4 ++
drivers/gpu/drm/i915/i915_driver.c | 6 +++
drivers/gpu/drm/i915/i915_drv.h | 4 ++
drivers/gpu/drm/i915/i915_reg.h | 1 +
drivers/gpu/drm/i915/spi/intel_spi.c | 68 ++++++++++++++++++++++++++++
drivers/gpu/drm/i915/spi/intel_spi.h | 15 ++++++
6 files changed, 98 insertions(+)
create mode 100644 drivers/gpu/drm/i915/spi/intel_spi.c
create mode 100644 drivers/gpu/drm/i915/spi/intel_spi.h
diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index c63fa2133ccb..02a9faf049a7 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -211,6 +211,10 @@ i915-y += \
i915-y += \
gt/intel_gsc.o
+# graphics spi device (DGFX) support
+i915-y += \
+ spi/intel_spi.o
+
# graphics hardware monitoring (HWMON) support
i915-$(CONFIG_HWMON) += \
i915_hwmon.o
diff --git a/drivers/gpu/drm/i915/i915_driver.c b/drivers/gpu/drm/i915/i915_driver.c
index fe905d65ddf7..80330571a2f5 100644
--- a/drivers/gpu/drm/i915/i915_driver.c
+++ b/drivers/gpu/drm/i915/i915_driver.c
@@ -80,6 +80,8 @@
#include "soc/intel_dram.h"
#include "soc/intel_gmch.h"
+#include "spi/intel_spi.h"
+
#include "i915_debugfs.h"
#include "i915_driver.h"
#include "i915_drm_client.h"
@@ -620,6 +622,8 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
/* Depends on sysfs having been initialized */
i915_perf_register(dev_priv);
+ intel_spi_init(dev_priv);
+
for_each_gt(gt, dev_priv, i)
intel_gt_driver_register(gt);
@@ -663,6 +667,8 @@ static void i915_driver_unregister(struct drm_i915_private *dev_priv)
i915_hwmon_unregister(dev_priv);
+ intel_spi_fini(dev_priv);
+
i915_perf_unregister(dev_priv);
i915_pmu_unregister(dev_priv);
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 39f6614a0a99..b9d4f9be5355 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -34,6 +34,8 @@
#include <linux/pm_qos.h>
+#include <linux/intel_dg_spi_aux.h>
+
#include <drm/ttm/ttm_device.h>
#include "display/intel_display_limits.h"
@@ -315,6 +317,8 @@ struct drm_i915_private {
struct i915_perf perf;
+ struct intel_dg_spi_dev spi;
+
struct i915_hwmon *hwmon;
struct intel_gt *gt[I915_MAX_GT];
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 41f4350a7c6c..af5d0497b95c 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -323,6 +323,7 @@
#define DG2_GSC_HECI2_BASE 0x00374000
#define MTL_GSC_HECI1_BASE 0x00116000
#define MTL_GSC_HECI2_BASE 0x00117000
+#define GEN12_GUNIT_SPI_BASE 0x00102040
#define HECI_H_CSR(base) _MMIO((base) + 0x4)
#define HECI_H_CSR_IE REG_BIT(0)
diff --git a/drivers/gpu/drm/i915/spi/intel_spi.c b/drivers/gpu/drm/i915/spi/intel_spi.c
new file mode 100644
index 000000000000..4b90e42b0f86
--- /dev/null
+++ b/drivers/gpu/drm/i915/spi/intel_spi.c
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright(c) 2019-2024, Intel Corporation. All rights reserved.
+ */
+
+#include <linux/intel_dg_spi_aux.h>
+#include <linux/irq.h>
+#include "i915_reg.h"
+#include "i915_drv.h"
+#include "spi/intel_spi.h"
+
+#define GEN12_GUNIT_SPI_SIZE 0x80
+
+static void i915_spi_release_dev(struct device *dev)
+{
+}
+
+void intel_spi_init(struct drm_i915_private *dev_priv)
+{
+ struct intel_dg_spi_dev *spi = &dev_priv->spi;
+ struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
+ struct auxiliary_device *aux_dev = &spi->aux_dev;
+ int ret;
+
+ /* Only the DGFX devices have internal SPI */
+ if (!IS_DGFX(dev_priv))
+ return;
+
+ spi->bar.parent = &pdev->resource[0];
+ spi->bar.start = GEN12_GUNIT_SPI_BASE + pdev->resource[0].start;
+ spi->bar.end = spi->bar.start + GEN12_GUNIT_SPI_SIZE - 1;
+ spi->bar.flags = IORESOURCE_MEM;
+ spi->bar.desc = IORES_DESC_NONE;
+
+ aux_dev->name = "spi";
+ aux_dev->id = (pci_domain_nr(pdev->bus) << 16) |
+ PCI_DEVID(pdev->bus->number, pdev->devfn);
+ aux_dev->dev.parent = &pdev->dev;
+ aux_dev->dev.release = i915_spi_release_dev;
+
+ ret = auxiliary_device_init(aux_dev);
+ if (ret) {
+ dev_err(&pdev->dev, "i915-spi aux init failed %d\n", ret);
+ return;
+ }
+
+ ret = auxiliary_device_add(aux_dev);
+ if (ret) {
+ dev_err(&pdev->dev, "i915-spi aux add failed %d\n", ret);
+ auxiliary_device_uninit(aux_dev);
+ return;
+ }
+}
+
+void intel_spi_fini(struct drm_i915_private *dev_priv)
+{
+ struct intel_dg_spi_dev *spi = &dev_priv->spi;
+ struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
+
+ /* Only the DGFX devices have internal SPI */
+ if (!IS_DGFX(dev_priv))
+ return;
+
+ dev_dbg(&pdev->dev, "removing i915-spi cell\n");
+
+ auxiliary_device_delete(&spi->aux_dev);
+ auxiliary_device_uninit(&spi->aux_dev);
+}
diff --git a/drivers/gpu/drm/i915/spi/intel_spi.h b/drivers/gpu/drm/i915/spi/intel_spi.h
new file mode 100644
index 000000000000..ed4153401f5d
--- /dev/null
+++ b/drivers/gpu/drm/i915/spi/intel_spi.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright(c) 2019-2024 Intel Corporation. All rights reserved.
+ */
+
+#ifndef __INTEL_SPI_H__
+#define __INTEL_SPI_H__
+
+struct drm_i915_private;
+
+void intel_spi_init(struct drm_i915_private *i915);
+
+void intel_spi_fini(struct drm_i915_private *i915);
+
+#endif /* __INTEL_SPI_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v6 09/12] drm/i915/spi: add intel_spi_region map
2024-09-16 13:49 [PATCH v6 00/12] spi: add driver for Intel discrete graphics Alexander Usyskin
` (7 preceding siblings ...)
2024-09-16 13:49 ` [PATCH v6 08/12] drm/i915/spi: add spi device for discrete graphics Alexander Usyskin
@ 2024-09-16 13:49 ` Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 10/12] drm/i915/spi: add support for access mode Alexander Usyskin
` (3 subsequent siblings)
12 siblings, 0 replies; 34+ messages in thread
From: Alexander Usyskin @ 2024-09-16 13:49 UTC (permalink / raw)
To: Mark Brown, Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin
Cc: Tomas Winkler, Alexander Usyskin, Vitaly Lubart, intel-xe,
dri-devel, linux-spi, intel-gfx
From: Tomas Winkler <tomas.winkler@intel.com>
Add the dGFX spi region map and convey it via auxiliary device
to the spi child device.
CC: Rodrigo Vivi <rodrigo.vivi@intel.com>
CC: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
---
drivers/gpu/drm/i915/spi/intel_spi.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/gpu/drm/i915/spi/intel_spi.c b/drivers/gpu/drm/i915/spi/intel_spi.c
index 4b90e42b0f86..200139531d26 100644
--- a/drivers/gpu/drm/i915/spi/intel_spi.c
+++ b/drivers/gpu/drm/i915/spi/intel_spi.c
@@ -11,6 +11,13 @@
#define GEN12_GUNIT_SPI_SIZE 0x80
+static const struct intel_dg_spi_region regions[INTEL_DG_SPI_REGIONS] = {
+ [0] = { .name = "DESCRIPTOR", },
+ [2] = { .name = "GSC", },
+ [11] = { .name = "OptionROM", },
+ [12] = { .name = "DAM", },
+};
+
static void i915_spi_release_dev(struct device *dev)
{
}
@@ -31,6 +38,7 @@ void intel_spi_init(struct drm_i915_private *dev_priv)
spi->bar.end = spi->bar.start + GEN12_GUNIT_SPI_SIZE - 1;
spi->bar.flags = IORESOURCE_MEM;
spi->bar.desc = IORES_DESC_NONE;
+ spi->regions = regions;
aux_dev->name = "spi";
aux_dev->id = (pci_domain_nr(pdev->bus) << 16) |
--
2.34.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v6 10/12] drm/i915/spi: add support for access mode
2024-09-16 13:49 [PATCH v6 00/12] spi: add driver for Intel discrete graphics Alexander Usyskin
` (8 preceding siblings ...)
2024-09-16 13:49 ` [PATCH v6 09/12] drm/i915/spi: add intel_spi_region map Alexander Usyskin
@ 2024-09-16 13:49 ` Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 11/12] drm/xe/spi: add on-die spi device Alexander Usyskin
` (2 subsequent siblings)
12 siblings, 0 replies; 34+ messages in thread
From: Alexander Usyskin @ 2024-09-16 13:49 UTC (permalink / raw)
To: Mark Brown, Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin
Cc: Tomas Winkler, Alexander Usyskin, Vitaly Lubart, intel-xe,
dri-devel, linux-spi, intel-gfx
Check SPI access mode from GSC FW status registers
and overwrite access status read from SPI descriptor, if needed.
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
---
drivers/gpu/drm/i915/spi/intel_spi.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/gpu/drm/i915/spi/intel_spi.c b/drivers/gpu/drm/i915/spi/intel_spi.c
index 200139531d26..e2b76e5cbc0c 100644
--- a/drivers/gpu/drm/i915/spi/intel_spi.c
+++ b/drivers/gpu/drm/i915/spi/intel_spi.c
@@ -10,6 +10,7 @@
#include "spi/intel_spi.h"
#define GEN12_GUNIT_SPI_SIZE 0x80
+#define HECI_FW_STATUS_2_SPI_ACCESS_MODE BIT(3)
static const struct intel_dg_spi_region regions[INTEL_DG_SPI_REGIONS] = {
[0] = { .name = "DESCRIPTOR", },
@@ -22,6 +23,29 @@ static void i915_spi_release_dev(struct device *dev)
{
}
+static bool i915_spi_writeable_override(struct drm_i915_private *dev_priv)
+{
+ struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
+ resource_size_t base;
+ bool writeable_override;
+
+ if (IS_DG1(dev_priv)) {
+ base = DG1_GSC_HECI2_BASE;
+ } else if (IS_DG2(dev_priv)) {
+ base = DG2_GSC_HECI2_BASE;
+ } else {
+ dev_err(&pdev->dev, "Unknown platform\n");
+ return true;
+ }
+
+ writeable_override =
+ !(intel_uncore_read(&dev_priv->uncore, HECI_FWSTS(base, 2)) &
+ HECI_FW_STATUS_2_SPI_ACCESS_MODE);
+ if (writeable_override)
+ dev_info(&pdev->dev, "SPI access overridden by jumper\n");
+ return writeable_override;
+}
+
void intel_spi_init(struct drm_i915_private *dev_priv)
{
struct intel_dg_spi_dev *spi = &dev_priv->spi;
@@ -33,6 +57,7 @@ void intel_spi_init(struct drm_i915_private *dev_priv)
if (!IS_DGFX(dev_priv))
return;
+ spi->writeable_override = i915_spi_writeable_override(dev_priv);
spi->bar.parent = &pdev->resource[0];
spi->bar.start = GEN12_GUNIT_SPI_BASE + pdev->resource[0].start;
spi->bar.end = spi->bar.start + GEN12_GUNIT_SPI_SIZE - 1;
--
2.34.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v6 11/12] drm/xe/spi: add on-die spi device
2024-09-16 13:49 [PATCH v6 00/12] spi: add driver for Intel discrete graphics Alexander Usyskin
` (9 preceding siblings ...)
2024-09-16 13:49 ` [PATCH v6 10/12] drm/i915/spi: add support for access mode Alexander Usyskin
@ 2024-09-16 13:49 ` Alexander Usyskin
2024-09-16 18:04 ` Rodrigo Vivi
2024-09-16 13:49 ` [PATCH v6 12/12] drm/xe/spi: add support for access mode Alexander Usyskin
2024-09-18 13:45 ` [PATCH v6 00/12] spi: add driver for Intel discrete graphics Mark Brown
12 siblings, 1 reply; 34+ messages in thread
From: Alexander Usyskin @ 2024-09-16 13:49 UTC (permalink / raw)
To: Mark Brown, Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin
Cc: Tomas Winkler, Alexander Usyskin, Vitaly Lubart, intel-xe,
dri-devel, linux-spi, intel-gfx
Enable access to internal spi on DGFX with GSC/CSC devices
via a child device.
The spi child device is exposed via auxiliary bus.
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
---
drivers/gpu/drm/xe/Makefile | 1 +
drivers/gpu/drm/xe/xe_device.c | 3 +
drivers/gpu/drm/xe/xe_device_types.h | 8 +++
drivers/gpu/drm/xe/xe_pci.c | 5 ++
drivers/gpu/drm/xe/xe_spi.c | 82 ++++++++++++++++++++++++++++
drivers/gpu/drm/xe/xe_spi.h | 15 +++++
6 files changed, 114 insertions(+)
create mode 100644 drivers/gpu/drm/xe/xe_spi.c
create mode 100644 drivers/gpu/drm/xe/xe_spi.h
diff --git a/drivers/gpu/drm/xe/Makefile b/drivers/gpu/drm/xe/Makefile
index edfd812e0f41..90f995b04479 100644
--- a/drivers/gpu/drm/xe/Makefile
+++ b/drivers/gpu/drm/xe/Makefile
@@ -93,6 +93,7 @@ xe-y += xe_bb.o \
xe_ring_ops.o \
xe_sa.o \
xe_sched_job.o \
+ xe_spi.o \
xe_step.o \
xe_sync.o \
xe_tile.o \
diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index 4d3c794f134c..25ca0b53c5c1 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -48,6 +48,7 @@
#include "xe_pcode.h"
#include "xe_pm.h"
#include "xe_query.h"
+#include "xe_spi.h"
#include "xe_sriov.h"
#include "xe_tile.h"
#include "xe_ttm_stolen_mgr.h"
@@ -734,6 +735,7 @@ int xe_device_probe(struct xe_device *xe)
goto err_fini_gt;
}
+ xe_spi_init(xe);
xe_heci_gsc_init(xe);
err = xe_oa_init(xe);
@@ -802,6 +804,7 @@ void xe_device_remove(struct xe_device *xe)
xe_oa_fini(xe);
xe_heci_gsc_fini(xe);
+ xe_spi_fini(xe);
for_each_gt(gt, xe, id)
xe_gt_remove(gt);
diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
index c92df0a2423f..dfc0183cabe0 100644
--- a/drivers/gpu/drm/xe/xe_device_types.h
+++ b/drivers/gpu/drm/xe/xe_device_types.h
@@ -12,6 +12,8 @@
#include <drm/drm_file.h>
#include <drm/ttm/ttm_device.h>
+#include <linux/intel_dg_spi_aux.h>
+
#include "xe_devcoredump_types.h"
#include "xe_heci_gsc.h"
#include "xe_lmtt_types.h"
@@ -44,6 +46,7 @@ struct xe_pat_ops;
#define IS_DGFX(xe) ((xe)->info.is_dgfx)
#define HAS_HECI_GSCFI(xe) ((xe)->info.has_heci_gscfi)
#define HAS_HECI_CSCFI(xe) ((xe)->info.has_heci_cscfi)
+#define HAS_GSC_SPI(xe) ((xe)->info.has_gsc_spi)
#define XE_VRAM_FLAGS_NEED64K BIT(0)
@@ -331,6 +334,8 @@ struct xe_device {
u8 has_heci_gscfi:1;
/** @info.has_heci_cscfi: device has heci cscfi */
u8 has_heci_cscfi:1;
+ /** @info.has_gsc_spi: device has gsc spi */
+ u8 has_gsc_spi:1;
/** @info.skip_guc_pc: Skip GuC based PM feature init */
u8 skip_guc_pc:1;
/** @info.has_atomic_enable_pte_bit: Device has atomic enable PTE bit */
@@ -499,6 +504,9 @@ struct xe_device {
/** @heci_gsc: graphics security controller */
struct xe_heci_gsc heci_gsc;
+ /** @spi: discrete graphics spi */
+ struct intel_dg_spi_dev spi;
+
/** @oa: oa observation subsystem */
struct xe_oa oa;
diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c
index a1d08e20cd34..45be73ccf274 100644
--- a/drivers/gpu/drm/xe/xe_pci.c
+++ b/drivers/gpu/drm/xe/xe_pci.c
@@ -60,6 +60,7 @@ struct xe_device_desc {
u8 has_display:1;
u8 has_heci_gscfi:1;
u8 has_heci_cscfi:1;
+ u8 has_gsc_spi:1;
u8 has_llc:1;
u8 has_mmio_ext:1;
u8 has_sriov:1;
@@ -282,6 +283,7 @@ static const struct xe_device_desc dg1_desc = {
PLATFORM(DG1),
.has_display = true,
.has_heci_gscfi = 1,
+ .has_gsc_spi = 1,
.require_force_probe = true,
};
@@ -293,6 +295,7 @@ static const u16 dg2_g12_ids[] = { XE_DG2_G12_IDS(NOP), 0 };
DGFX_FEATURES, \
PLATFORM(DG2), \
.has_heci_gscfi = 1, \
+ .has_gsc_spi = 1, \
.subplatforms = (const struct xe_subplatform_desc[]) { \
{ XE_SUBPLATFORM_DG2_G10, "G10", dg2_g10_ids }, \
{ XE_SUBPLATFORM_DG2_G11, "G11", dg2_g11_ids }, \
@@ -324,6 +327,7 @@ static const __maybe_unused struct xe_device_desc pvc_desc = {
PLATFORM(PVC),
.has_display = false,
.has_heci_gscfi = 1,
+ .has_gsc_spi = 1,
.require_force_probe = true,
};
@@ -613,6 +617,7 @@ static int xe_info_init_early(struct xe_device *xe,
xe->info.is_dgfx = desc->is_dgfx;
xe->info.has_heci_gscfi = desc->has_heci_gscfi;
xe->info.has_heci_cscfi = desc->has_heci_cscfi;
+ xe->info.has_gsc_spi = desc->has_gsc_spi;
xe->info.has_llc = desc->has_llc;
xe->info.has_mmio_ext = desc->has_mmio_ext;
xe->info.has_sriov = desc->has_sriov;
diff --git a/drivers/gpu/drm/xe/xe_spi.c b/drivers/gpu/drm/xe/xe_spi.c
new file mode 100644
index 000000000000..37080b82e9ae
--- /dev/null
+++ b/drivers/gpu/drm/xe/xe_spi.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright(c) 2019-2024, Intel Corporation. All rights reserved.
+ */
+
+#include <linux/intel_dg_spi_aux.h>
+#include <linux/pci.h>
+#include "xe_device_types.h"
+#include "xe_spi.h"
+#include "xe_sriov.h"
+
+#define GEN12_GUNIT_SPI_BASE 0x00102040
+#define GEN12_GUNIT_SPI_SIZE 0x80
+#define HECI_FW_STATUS_2_SPI_ACCESS_MODE BIT(3)
+
+static const struct intel_dg_spi_region regions[INTEL_DG_SPI_REGIONS] = {
+ [0] = { .name = "DESCRIPTOR", },
+ [2] = { .name = "GSC", },
+ [11] = { .name = "OptionROM", },
+ [12] = { .name = "DAM", },
+};
+
+static void xe_spi_release_dev(struct device *dev)
+{
+}
+
+void xe_spi_init(struct xe_device *xe)
+{
+ struct intel_dg_spi_dev *spi = &xe->spi;
+ struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
+ struct auxiliary_device *aux_dev = &spi->aux_dev;
+ int ret;
+
+ if (!HAS_GSC_SPI(xe))
+ return;
+
+ /* No access to internal SPI from VFs */
+ if (IS_SRIOV_VF(xe))
+ return;
+
+ spi->writeable_override = false;
+ spi->bar.parent = &pdev->resource[0];
+ spi->bar.start = GEN12_GUNIT_SPI_BASE + pdev->resource[0].start;
+ spi->bar.end = spi->bar.start + GEN12_GUNIT_SPI_SIZE - 1;
+ spi->bar.flags = IORESOURCE_MEM;
+ spi->bar.desc = IORES_DESC_NONE;
+ spi->regions = regions;
+
+ aux_dev->name = "spi";
+ aux_dev->id = (pci_domain_nr(pdev->bus) << 16) |
+ PCI_DEVID(pdev->bus->number, pdev->devfn);
+ aux_dev->dev.parent = &pdev->dev;
+ aux_dev->dev.release = xe_spi_release_dev;
+
+ ret = auxiliary_device_init(aux_dev);
+ if (ret) {
+ dev_err(&pdev->dev, "xe-spi aux init failed %d\n", ret);
+ return;
+ }
+
+ ret = auxiliary_device_add(aux_dev);
+ if (ret) {
+ dev_err(&pdev->dev, "xe-spi aux add failed %d\n", ret);
+ auxiliary_device_uninit(aux_dev);
+ return;
+ }
+}
+
+void xe_spi_fini(struct xe_device *xe)
+{
+ struct intel_dg_spi_dev *spi = &xe->spi;
+
+ if (!HAS_GSC_SPI(xe))
+ return;
+
+ /* No access to internal SPI from VFs */
+ if (IS_SRIOV_VF(xe))
+ return;
+
+ auxiliary_device_delete(&spi->aux_dev);
+ auxiliary_device_uninit(&spi->aux_dev);
+}
diff --git a/drivers/gpu/drm/xe/xe_spi.h b/drivers/gpu/drm/xe/xe_spi.h
new file mode 100644
index 000000000000..aef79893a864
--- /dev/null
+++ b/drivers/gpu/drm/xe/xe_spi.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright(c) 2019-2024 Intel Corporation. All rights reserved.
+ */
+
+#ifndef __XE_SPI_H__
+#define __XE_SPI_H__
+
+struct xe_device;
+
+void xe_spi_init(struct xe_device *xe);
+
+void xe_spi_fini(struct xe_device *xe);
+
+#endif /* __XE_SPI_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* [PATCH v6 12/12] drm/xe/spi: add support for access mode
2024-09-16 13:49 [PATCH v6 00/12] spi: add driver for Intel discrete graphics Alexander Usyskin
` (10 preceding siblings ...)
2024-09-16 13:49 ` [PATCH v6 11/12] drm/xe/spi: add on-die spi device Alexander Usyskin
@ 2024-09-16 13:49 ` Alexander Usyskin
2024-09-18 13:45 ` [PATCH v6 00/12] spi: add driver for Intel discrete graphics Mark Brown
12 siblings, 0 replies; 34+ messages in thread
From: Alexander Usyskin @ 2024-09-16 13:49 UTC (permalink / raw)
To: Mark Brown, Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin
Cc: Tomas Winkler, Alexander Usyskin, Vitaly Lubart, intel-xe,
dri-devel, linux-spi, intel-gfx
Check SPI access mode from GSC FW status registers
and overwrite access status read from SPI descriptor, if needed.
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
---
drivers/gpu/drm/xe/regs/xe_gsc_regs.h | 4 ++++
drivers/gpu/drm/xe/xe_heci_gsc.c | 5 +---
drivers/gpu/drm/xe/xe_spi.c | 33 ++++++++++++++++++++++++++-
3 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/xe/regs/xe_gsc_regs.h b/drivers/gpu/drm/xe/regs/xe_gsc_regs.h
index 7702364b65f1..9b66cc972a63 100644
--- a/drivers/gpu/drm/xe/regs/xe_gsc_regs.h
+++ b/drivers/gpu/drm/xe/regs/xe_gsc_regs.h
@@ -16,6 +16,10 @@
#define MTL_GSC_HECI1_BASE 0x00116000
#define MTL_GSC_HECI2_BASE 0x00117000
+#define DG1_GSC_HECI2_BASE 0x00259000
+#define PVC_GSC_HECI2_BASE 0x00285000
+#define DG2_GSC_HECI2_BASE 0x00374000
+
#define HECI_H_CSR(base) XE_REG((base) + 0x4)
#define HECI_H_CSR_IE REG_BIT(0)
#define HECI_H_CSR_IS REG_BIT(1)
diff --git a/drivers/gpu/drm/xe/xe_heci_gsc.c b/drivers/gpu/drm/xe/xe_heci_gsc.c
index 65b2e147c4b9..27734085164e 100644
--- a/drivers/gpu/drm/xe/xe_heci_gsc.c
+++ b/drivers/gpu/drm/xe/xe_heci_gsc.c
@@ -11,14 +11,11 @@
#include "xe_device_types.h"
#include "xe_drv.h"
#include "xe_heci_gsc.h"
+#include "regs/xe_gsc_regs.h"
#include "xe_platform_types.h"
#define GSC_BAR_LENGTH 0x00000FFC
-#define DG1_GSC_HECI2_BASE 0x259000
-#define PVC_GSC_HECI2_BASE 0x285000
-#define DG2_GSC_HECI2_BASE 0x374000
-
static void heci_gsc_irq_mask(struct irq_data *d)
{
/* generic irq handling */
diff --git a/drivers/gpu/drm/xe/xe_spi.c b/drivers/gpu/drm/xe/xe_spi.c
index 37080b82e9ae..8ac6376f663e 100644
--- a/drivers/gpu/drm/xe/xe_spi.c
+++ b/drivers/gpu/drm/xe/xe_spi.c
@@ -5,7 +5,10 @@
#include <linux/intel_dg_spi_aux.h>
#include <linux/pci.h>
+#include "xe_device.h"
#include "xe_device_types.h"
+#include "xe_mmio.h"
+#include "regs/xe_gsc_regs.h"
#include "xe_spi.h"
#include "xe_sriov.h"
@@ -24,6 +27,34 @@ static void xe_spi_release_dev(struct device *dev)
{
}
+static bool xe_spi_writeable_override(struct xe_device *xe)
+{
+ struct xe_gt *gt = xe_root_mmio_gt(xe);
+ struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
+ resource_size_t base;
+ bool writeable_override;
+
+ if (xe->info.platform == XE_BATTLEMAGE) {
+ base = DG2_GSC_HECI2_BASE;
+ } else if (xe->info.platform == XE_PVC) {
+ base = PVC_GSC_HECI2_BASE;
+ } else if (xe->info.platform == XE_DG2) {
+ base = DG2_GSC_HECI2_BASE;
+ } else if (xe->info.platform == XE_DG1) {
+ base = DG1_GSC_HECI2_BASE;
+ } else {
+ dev_err(&pdev->dev, "Unknown platform\n");
+ return true;
+ }
+
+ writeable_override =
+ !(xe_mmio_read32(>->mmio, HECI_H_GS1(base)) &
+ HECI_FW_STATUS_2_SPI_ACCESS_MODE);
+ if (writeable_override)
+ dev_info(&pdev->dev, "SPI access overridden by jumper\n");
+ return writeable_override;
+}
+
void xe_spi_init(struct xe_device *xe)
{
struct intel_dg_spi_dev *spi = &xe->spi;
@@ -38,7 +69,7 @@ void xe_spi_init(struct xe_device *xe)
if (IS_SRIOV_VF(xe))
return;
- spi->writeable_override = false;
+ spi->writeable_override = xe_spi_writeable_override(xe);
spi->bar.parent = &pdev->resource[0];
spi->bar.start = GEN12_GUNIT_SPI_BASE + pdev->resource[0].start;
spi->bar.end = spi->bar.start + GEN12_GUNIT_SPI_SIZE - 1;
--
2.34.1
^ permalink raw reply related [flat|nested] 34+ messages in thread
* Re: [PATCH v6 07/12] spi: intel-dg: wake card on operations
2024-09-16 13:49 ` [PATCH v6 07/12] spi: intel-dg: wake card on operations Alexander Usyskin
@ 2024-09-16 18:00 ` Rodrigo Vivi
0 siblings, 0 replies; 34+ messages in thread
From: Rodrigo Vivi @ 2024-09-16 18:00 UTC (permalink / raw)
To: Alexander Usyskin
Cc: Mark Brown, Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Tvrtko Ursulin,
Tomas Winkler, Vitaly Lubart, intel-xe, dri-devel, linux-spi,
intel-gfx
On Mon, Sep 16, 2024 at 04:49:23PM +0300, Alexander Usyskin wrote:
> Enable runtime PM in spi driver to notify graphics driver that
> whole card should be kept awake while spi operations are
> performed through this driver.
>
> CC: Lucas De Marchi <lucas.demarchi@intel.com>
> Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
> ---
> drivers/spi/spi-intel-dg.c | 44 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 44 insertions(+)
>
> diff --git a/drivers/spi/spi-intel-dg.c b/drivers/spi/spi-intel-dg.c
> index c76b0a70f8d8..a14fc3190520 100644
> --- a/drivers/spi/spi-intel-dg.c
> +++ b/drivers/spi/spi-intel-dg.c
> @@ -12,11 +12,14 @@
> #include <linux/module.h>
> #include <linux/mtd/mtd.h>
> #include <linux/mtd/partitions.h>
> +#include <linux/pm_runtime.h>
> #include <linux/string.h>
> #include <linux/slab.h>
> #include <linux/sizes.h>
> #include <linux/types.h>
>
> +#define INTEL_DG_SPI_RPM_TIMEOUT 500
> +
> struct intel_dg_spi {
> struct kref refcnt;
> struct mtd_info mtd;
> @@ -471,6 +474,12 @@ static int intel_dg_spi_erase(struct mtd_info *mtd, struct erase_info *info)
> total_len = info->len;
> addr = info->addr;
>
> + ret = pm_runtime_resume_and_get(mtd->dev.parent);
> + if (ret < 0) {
> + dev_err(&mtd->dev, "rpm: get failed %d\n", ret);
If I understood correctly,
this is the device = &aux_dev->dev;
which is the drm->pdev.dev
?
This is to ensure that the graphics driver is not going to runtime suspend,
right?
> + return ret;
> + }
> +
> mutex_lock(&spi->lock);
>
> while (total_len > 0) {
> @@ -512,6 +521,8 @@ static int intel_dg_spi_erase(struct mtd_info *mtd, struct erase_info *info)
>
> out:
> mutex_unlock(&spi->lock);
> + pm_runtime_mark_last_busy(mtd->dev.parent);
> + pm_runtime_put_autosuspend(mtd->dev.parent);
> return ret;
> }
>
> @@ -545,6 +556,12 @@ static int intel_dg_spi_read(struct mtd_info *mtd, loff_t from, size_t len,
> if (len > spi->regions[idx].size - from)
> len = spi->regions[idx].size - from;
>
> + ret = pm_runtime_resume_and_get(mtd->dev.parent);
> + if (ret < 0) {
> + dev_err(&mtd->dev, "rpm: get failed %zd\n", ret);
> + return ret;
> + }
> +
> mutex_lock(&spi->lock);
>
> ret = spi_read(spi, region, from, len, buf);
> @@ -557,6 +574,8 @@ static int intel_dg_spi_read(struct mtd_info *mtd, loff_t from, size_t len,
> *retlen = ret;
>
> mutex_unlock(&spi->lock);
> + pm_runtime_mark_last_busy(mtd->dev.parent);
> + pm_runtime_put_autosuspend(mtd->dev.parent);
> return 0;
> }
>
> @@ -590,6 +609,12 @@ static int intel_dg_spi_write(struct mtd_info *mtd, loff_t to, size_t len,
> if (len > spi->regions[idx].size - to)
> len = spi->regions[idx].size - to;
>
> + ret = pm_runtime_resume_and_get(mtd->dev.parent);
> + if (ret < 0) {
> + dev_err(&mtd->dev, "rpm: get failed %zd\n", ret);
> + return ret;
> + }
> +
> mutex_lock(&spi->lock);
>
> ret = spi_write(spi, region, to, len, buf);
> @@ -602,6 +627,8 @@ static int intel_dg_spi_write(struct mtd_info *mtd, loff_t to, size_t len,
> *retlen = ret;
>
> mutex_unlock(&spi->lock);
> + pm_runtime_mark_last_busy(mtd->dev.parent);
> + pm_runtime_put_autosuspend(mtd->dev.parent);
> return 0;
> }
>
> @@ -747,6 +774,17 @@ static int intel_dg_spi_probe(struct auxiliary_device *aux_dev,
> }
> }
>
> + pm_runtime_enable(device);
> +
> + pm_runtime_set_autosuspend_delay(device, INTEL_DG_SPI_RPM_TIMEOUT);
> + pm_runtime_use_autosuspend(device);
If the above assumption is right, then I don't believe you
should change the device settings in here.
But if you tell me that this 'device' is the spi one, and not
the graphics dgfx, then I believe this code would be missing
the runtime pm suspend/resume functions.
> +
> + ret = pm_runtime_resume_and_get(device);
> + if (ret < 0) {
> + dev_err(device, "rpm: get failed %d\n", ret);
> + goto err_norpm;
> + }
> +
> spi->base = devm_ioremap_resource(device, &ispi->bar);
> if (IS_ERR(spi->base)) {
> dev_err(device, "mmio not mapped\n");
> @@ -769,9 +807,13 @@ static int intel_dg_spi_probe(struct auxiliary_device *aux_dev,
>
> dev_set_drvdata(&aux_dev->dev, spi);
>
> + pm_runtime_put(device);
> return 0;
>
> err:
> + pm_runtime_put(device);
> +err_norpm:
> + pm_runtime_disable(device);
> kref_put(&spi->refcnt, intel_dg_spi_release);
> return ret;
> }
> @@ -783,6 +825,8 @@ static void intel_dg_spi_remove(struct auxiliary_device *aux_dev)
> if (!spi)
> return;
>
> + pm_runtime_disable(&aux_dev->dev);
> +
> mtd_device_unregister(&spi->mtd);
>
> dev_set_drvdata(&aux_dev->dev, NULL);
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH v6 11/12] drm/xe/spi: add on-die spi device
2024-09-16 13:49 ` [PATCH v6 11/12] drm/xe/spi: add on-die spi device Alexander Usyskin
@ 2024-09-16 18:04 ` Rodrigo Vivi
0 siblings, 0 replies; 34+ messages in thread
From: Rodrigo Vivi @ 2024-09-16 18:04 UTC (permalink / raw)
To: Alexander Usyskin
Cc: Mark Brown, Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Tvrtko Ursulin,
Tomas Winkler, Vitaly Lubart, intel-xe, dri-devel, linux-spi,
intel-gfx
On Mon, Sep 16, 2024 at 04:49:27PM +0300, Alexander Usyskin wrote:
> Enable access to internal spi on DGFX with GSC/CSC devices
> via a child device.
> The spi child device is exposed via auxiliary bus.
>
> Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
> ---
> drivers/gpu/drm/xe/Makefile | 1 +
> drivers/gpu/drm/xe/xe_device.c | 3 +
> drivers/gpu/drm/xe/xe_device_types.h | 8 +++
> drivers/gpu/drm/xe/xe_pci.c | 5 ++
> drivers/gpu/drm/xe/xe_spi.c | 82 ++++++++++++++++++++++++++++
> drivers/gpu/drm/xe/xe_spi.h | 15 +++++
> 6 files changed, 114 insertions(+)
> create mode 100644 drivers/gpu/drm/xe/xe_spi.c
> create mode 100644 drivers/gpu/drm/xe/xe_spi.h
>
> diff --git a/drivers/gpu/drm/xe/Makefile b/drivers/gpu/drm/xe/Makefile
> index edfd812e0f41..90f995b04479 100644
> --- a/drivers/gpu/drm/xe/Makefile
> +++ b/drivers/gpu/drm/xe/Makefile
> @@ -93,6 +93,7 @@ xe-y += xe_bb.o \
> xe_ring_ops.o \
> xe_sa.o \
> xe_sched_job.o \
> + xe_spi.o \
> xe_step.o \
> xe_sync.o \
> xe_tile.o \
> diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
> index 4d3c794f134c..25ca0b53c5c1 100644
> --- a/drivers/gpu/drm/xe/xe_device.c
> +++ b/drivers/gpu/drm/xe/xe_device.c
> @@ -48,6 +48,7 @@
> #include "xe_pcode.h"
> #include "xe_pm.h"
> #include "xe_query.h"
> +#include "xe_spi.h"
> #include "xe_sriov.h"
> #include "xe_tile.h"
> #include "xe_ttm_stolen_mgr.h"
> @@ -734,6 +735,7 @@ int xe_device_probe(struct xe_device *xe)
> goto err_fini_gt;
> }
>
> + xe_spi_init(xe);
> xe_heci_gsc_init(xe);
>
> err = xe_oa_init(xe);
> @@ -802,6 +804,7 @@ void xe_device_remove(struct xe_device *xe)
> xe_oa_fini(xe);
>
> xe_heci_gsc_fini(xe);
> + xe_spi_fini(xe);
>
> for_each_gt(gt, xe, id)
> xe_gt_remove(gt);
> diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
> index c92df0a2423f..dfc0183cabe0 100644
> --- a/drivers/gpu/drm/xe/xe_device_types.h
> +++ b/drivers/gpu/drm/xe/xe_device_types.h
> @@ -12,6 +12,8 @@
> #include <drm/drm_file.h>
> #include <drm/ttm/ttm_device.h>
>
> +#include <linux/intel_dg_spi_aux.h>
> +
> #include "xe_devcoredump_types.h"
> #include "xe_heci_gsc.h"
> #include "xe_lmtt_types.h"
> @@ -44,6 +46,7 @@ struct xe_pat_ops;
> #define IS_DGFX(xe) ((xe)->info.is_dgfx)
> #define HAS_HECI_GSCFI(xe) ((xe)->info.has_heci_gscfi)
> #define HAS_HECI_CSCFI(xe) ((xe)->info.has_heci_cscfi)
> +#define HAS_GSC_SPI(xe) ((xe)->info.has_gsc_spi)
>
> #define XE_VRAM_FLAGS_NEED64K BIT(0)
>
> @@ -331,6 +334,8 @@ struct xe_device {
> u8 has_heci_gscfi:1;
> /** @info.has_heci_cscfi: device has heci cscfi */
> u8 has_heci_cscfi:1;
> + /** @info.has_gsc_spi: device has gsc spi */
> + u8 has_gsc_spi:1;
> /** @info.skip_guc_pc: Skip GuC based PM feature init */
> u8 skip_guc_pc:1;
> /** @info.has_atomic_enable_pte_bit: Device has atomic enable PTE bit */
> @@ -499,6 +504,9 @@ struct xe_device {
> /** @heci_gsc: graphics security controller */
> struct xe_heci_gsc heci_gsc;
>
> + /** @spi: discrete graphics spi */
> + struct intel_dg_spi_dev spi;
> +
> /** @oa: oa observation subsystem */
> struct xe_oa oa;
>
> diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c
> index a1d08e20cd34..45be73ccf274 100644
> --- a/drivers/gpu/drm/xe/xe_pci.c
> +++ b/drivers/gpu/drm/xe/xe_pci.c
> @@ -60,6 +60,7 @@ struct xe_device_desc {
> u8 has_display:1;
> u8 has_heci_gscfi:1;
> u8 has_heci_cscfi:1;
> + u8 has_gsc_spi:1;
> u8 has_llc:1;
> u8 has_mmio_ext:1;
> u8 has_sriov:1;
> @@ -282,6 +283,7 @@ static const struct xe_device_desc dg1_desc = {
> PLATFORM(DG1),
> .has_display = true,
> .has_heci_gscfi = 1,
> + .has_gsc_spi = 1,
> .require_force_probe = true,
> };
>
> @@ -293,6 +295,7 @@ static const u16 dg2_g12_ids[] = { XE_DG2_G12_IDS(NOP), 0 };
> DGFX_FEATURES, \
> PLATFORM(DG2), \
> .has_heci_gscfi = 1, \
> + .has_gsc_spi = 1, \
> .subplatforms = (const struct xe_subplatform_desc[]) { \
> { XE_SUBPLATFORM_DG2_G10, "G10", dg2_g10_ids }, \
> { XE_SUBPLATFORM_DG2_G11, "G11", dg2_g11_ids }, \
> @@ -324,6 +327,7 @@ static const __maybe_unused struct xe_device_desc pvc_desc = {
> PLATFORM(PVC),
> .has_display = false,
> .has_heci_gscfi = 1,
> + .has_gsc_spi = 1,
> .require_force_probe = true,
> };
>
> @@ -613,6 +617,7 @@ static int xe_info_init_early(struct xe_device *xe,
> xe->info.is_dgfx = desc->is_dgfx;
> xe->info.has_heci_gscfi = desc->has_heci_gscfi;
> xe->info.has_heci_cscfi = desc->has_heci_cscfi;
> + xe->info.has_gsc_spi = desc->has_gsc_spi;
> xe->info.has_llc = desc->has_llc;
> xe->info.has_mmio_ext = desc->has_mmio_ext;
> xe->info.has_sriov = desc->has_sriov;
> diff --git a/drivers/gpu/drm/xe/xe_spi.c b/drivers/gpu/drm/xe/xe_spi.c
> new file mode 100644
> index 000000000000..37080b82e9ae
> --- /dev/null
> +++ b/drivers/gpu/drm/xe/xe_spi.c
> @@ -0,0 +1,82 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright(c) 2019-2024, Intel Corporation. All rights reserved.
only 2024 on the new headers should be enough.
> + */
> +
> +#include <linux/intel_dg_spi_aux.h>
> +#include <linux/pci.h>
> +#include "xe_device_types.h"
> +#include "xe_spi.h"
> +#include "xe_sriov.h"
> +
> +#define GEN12_GUNIT_SPI_BASE 0x00102040
> +#define GEN12_GUNIT_SPI_SIZE 0x80
> +#define HECI_FW_STATUS_2_SPI_ACCESS_MODE BIT(3)
> +
> +static const struct intel_dg_spi_region regions[INTEL_DG_SPI_REGIONS] = {
> + [0] = { .name = "DESCRIPTOR", },
> + [2] = { .name = "GSC", },
> + [11] = { .name = "OptionROM", },
> + [12] = { .name = "DAM", },
> +};
> +
> +static void xe_spi_release_dev(struct device *dev)
> +{
> +}
> +
> +void xe_spi_init(struct xe_device *xe)
> +{
> + struct intel_dg_spi_dev *spi = &xe->spi;
> + struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
> + struct auxiliary_device *aux_dev = &spi->aux_dev;
> + int ret;
> +
> + if (!HAS_GSC_SPI(xe))
> + return;
> +
> + /* No access to internal SPI from VFs */
> + if (IS_SRIOV_VF(xe))
> + return;
> +
> + spi->writeable_override = false;
> + spi->bar.parent = &pdev->resource[0];
> + spi->bar.start = GEN12_GUNIT_SPI_BASE + pdev->resource[0].start;
> + spi->bar.end = spi->bar.start + GEN12_GUNIT_SPI_SIZE - 1;
> + spi->bar.flags = IORESOURCE_MEM;
> + spi->bar.desc = IORES_DESC_NONE;
> + spi->regions = regions;
> +
> + aux_dev->name = "spi";
> + aux_dev->id = (pci_domain_nr(pdev->bus) << 16) |
> + PCI_DEVID(pdev->bus->number, pdev->devfn);
> + aux_dev->dev.parent = &pdev->dev;
> + aux_dev->dev.release = xe_spi_release_dev;
> +
> + ret = auxiliary_device_init(aux_dev);
> + if (ret) {
> + dev_err(&pdev->dev, "xe-spi aux init failed %d\n", ret);
for both, this and i915 one. We have 'drm' pointer here,
so we should prefer the drm_err
> + return;
> + }
> +
> + ret = auxiliary_device_add(aux_dev);
> + if (ret) {
> + dev_err(&pdev->dev, "xe-spi aux add failed %d\n", ret);
> + auxiliary_device_uninit(aux_dev);
> + return;
> + }
> +}
> +
> +void xe_spi_fini(struct xe_device *xe)
> +{
> + struct intel_dg_spi_dev *spi = &xe->spi;
> +
> + if (!HAS_GSC_SPI(xe))
> + return;
> +
> + /* No access to internal SPI from VFs */
> + if (IS_SRIOV_VF(xe))
> + return;
> +
> + auxiliary_device_delete(&spi->aux_dev);
> + auxiliary_device_uninit(&spi->aux_dev);
> +}
> diff --git a/drivers/gpu/drm/xe/xe_spi.h b/drivers/gpu/drm/xe/xe_spi.h
> new file mode 100644
> index 000000000000..aef79893a864
> --- /dev/null
> +++ b/drivers/gpu/drm/xe/xe_spi.h
> @@ -0,0 +1,15 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright(c) 2019-2024 Intel Corporation. All rights reserved.
> + */
> +
> +#ifndef __XE_SPI_H__
> +#define __XE_SPI_H__
> +
> +struct xe_device;
> +
> +void xe_spi_init(struct xe_device *xe);
> +
> +void xe_spi_fini(struct xe_device *xe);
> +
> +#endif /* __XE_SPI_H__ */
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH v6 01/12] spi: add driver for intel graphics on-die spi device
2024-09-16 13:49 ` [PATCH v6 01/12] spi: add driver for intel graphics on-die spi device Alexander Usyskin
@ 2024-09-18 13:33 ` Mark Brown
2024-09-19 9:54 ` Winkler, Tomas
0 siblings, 1 reply; 34+ messages in thread
From: Mark Brown @ 2024-09-18 13:33 UTC (permalink / raw)
To: Alexander Usyskin
Cc: Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin, Tomas Winkler, Vitaly Lubart, intel-xe, dri-devel,
linux-spi, intel-gfx
[-- Attachment #1: Type: text/plain, Size: 1993 bytes --]
On Mon, Sep 16, 2024 at 04:49:17PM +0300, Alexander Usyskin wrote:
> Add auxiliary driver for intel discrete graphics
> on-die spi device.
This doesn't actually do anything AFAICT? It doesn't register with any
subsystem or anything. Please don't submit empty boilerplate like this,
submit a driver that is at least minimally useful - assuming some other
patches in the series add functionality squash at least a basic set of
functionality into this. This makes review and test easier.
> +++ b/drivers/spi/spi-intel-dg.c
> @@ -0,0 +1,142 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright(c) 2019-2024, Intel Corporation. All rights reserved.
> + */
Please make the entire comment a C++ one so things look more
intentional.
> +struct intel_dg_spi {
> + struct kref refcnt;
> + void __iomem *base;
> + size_t size;
> + unsigned int nregions;
> + struct {
> + const char *name;
> + u8 id;
> + u64 offset;
> + u64 size;
> + } regions[];
Use __counted_by() for the benefit of the static checkers.
> + size = sizeof(*spi) + sizeof(spi->regions[0]) * nregions;
> + spi = kzalloc(size, GFP_KERNEL);
Use at least array_size().
> + kref_init(&spi->refcnt);
This refcount feels more complex than just freeing in the error and
release paths, it's not a common pattern for drivers.
> + spi->nregions = nregions;
> + for (n = 0, i = 0; i < INTEL_DG_SPI_REGIONS; i++) {
> + if (ispi->regions[i].name) {
> + name_size = strlen(dev_name(&aux_dev->dev)) +
> + strlen(ispi->regions[i].name) + 2; /* for point */
> + name = kzalloc(name_size, GFP_KERNEL);
> + if (!name)
> + continue;
> + snprintf(name, name_size, "%s.%s",
> + dev_name(&aux_dev->dev), ispi->regions[i].name);
kasprintf().
> +static void intel_dg_spi_remove(struct auxiliary_device *aux_dev)
> +{
> + struct intel_dg_spi *spi = dev_get_drvdata(&aux_dev->dev);
> +
> + if (!spi)
> + return;
> +
> + dev_set_drvdata(&aux_dev->dev, NULL);
If the above is doing anything there's a problem...
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH v6 02/12] spi: intel-dg: implement region enumeration
2024-09-16 13:49 ` [PATCH v6 02/12] spi: intel-dg: implement region enumeration Alexander Usyskin
@ 2024-09-18 13:35 ` Mark Brown
2024-09-19 9:55 ` Winkler, Tomas
0 siblings, 1 reply; 34+ messages in thread
From: Mark Brown @ 2024-09-18 13:35 UTC (permalink / raw)
To: Alexander Usyskin
Cc: Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin, Tomas Winkler, Vitaly Lubart, intel-xe, dri-devel,
linux-spi, intel-gfx
[-- Attachment #1: Type: text/plain, Size: 527 bytes --]
On Mon, Sep 16, 2024 at 04:49:18PM +0300, Alexander Usyskin wrote:
> In intel-dg spi, there is no access to the spi controller,
> the information is extracted from the descriptor region.
Which information? I can't tell what this patch is supposed to do; as
with the first patch this shouldn't be standalone.
> +static inline u32 spi_error(struct intel_dg_spi *spi)
> +{
> +static inline u32 spi_read32(struct intel_dg_spi *spi, u32 address)
> +{
At least these names are too generic, please use driver specific
prefixes.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH v6 04/12] spi: intel-dg: spi register with mtd
2024-09-16 13:49 ` [PATCH v6 04/12] spi: intel-dg: spi register with mtd Alexander Usyskin
@ 2024-09-18 13:38 ` Mark Brown
2024-09-19 10:01 ` Winkler, Tomas
0 siblings, 1 reply; 34+ messages in thread
From: Mark Brown @ 2024-09-18 13:38 UTC (permalink / raw)
To: Alexander Usyskin
Cc: Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin, Tomas Winkler, Vitaly Lubart, intel-xe, dri-devel,
linux-spi, intel-gfx
[-- Attachment #1: Type: text/plain, Size: 784 bytes --]
On Mon, Sep 16, 2024 at 04:49:20PM +0300, Alexander Usyskin wrote:
> From: Tomas Winkler <tomas.winkler@intel.com>
>
> Register the on-die spi device with the mtd subsystem.
> Refcount spi object on _get and _put mtd callbacks.
This is a MTD driver, it should be in drivers/mtd.
> +static int intel_dg_spi_erase(struct mtd_info *mtd, struct erase_info *info)
> +{
> + return 0;
> +}
> +
> +static int intel_dg_spi_read(struct mtd_info *mtd, loff_t from, size_t len,
> + size_t *retlen, u_char *buf)
> +{
> + return 0;
> +}
> +
> +static int intel_dg_spi_write(struct mtd_info *mtd, loff_t to, size_t len,
> + size_t *retlen, const u_char *buf)
> +{
> + return 0;
> +}
If these functions can legitimately be empty they should be removed.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH v6 00/12] spi: add driver for Intel discrete graphics
2024-09-16 13:49 [PATCH v6 00/12] spi: add driver for Intel discrete graphics Alexander Usyskin
` (11 preceding siblings ...)
2024-09-16 13:49 ` [PATCH v6 12/12] drm/xe/spi: add support for access mode Alexander Usyskin
@ 2024-09-18 13:45 ` Mark Brown
2024-09-19 6:56 ` Usyskin, Alexander
12 siblings, 1 reply; 34+ messages in thread
From: Mark Brown @ 2024-09-18 13:45 UTC (permalink / raw)
To: Alexander Usyskin
Cc: Lucas De Marchi, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
Tvrtko Ursulin, Tomas Winkler, Vitaly Lubart, intel-xe, dri-devel,
linux-spi, intel-gfx
[-- Attachment #1: Type: text/plain, Size: 831 bytes --]
On Mon, Sep 16, 2024 at 04:49:16PM +0300, Alexander Usyskin wrote:
> Add driver for access to Intel discrete graphics card
> internal SPI device.
> Expose device on auxiliary bus by i915 and Xe drivers and
> provide spi driver to register this device with MTD framework.
As far as I can tell this does not actually provide a SPI driver, there
is no call to any SPI API that I've noticed here. The SPI framework
does have support for SPI controllers with specific flash support via
spi_controller_mem_ops but this does not appear to use them. Either it
should do that or it should just be a MTD driver.
The series is also split up into too many patches with minimal
explanation, making it hard to follow what's going on. I would
recommend making the first patch be a minimal functional driver and then
building on top of that.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 34+ messages in thread
* RE: [PATCH v6 00/12] spi: add driver for Intel discrete graphics
2024-09-18 13:45 ` [PATCH v6 00/12] spi: add driver for Intel discrete graphics Mark Brown
@ 2024-09-19 6:56 ` Usyskin, Alexander
2024-09-19 8:31 ` Mark Brown
0 siblings, 1 reply; 34+ messages in thread
From: Usyskin, Alexander @ 2024-09-19 6:56 UTC (permalink / raw)
To: Mark Brown, Miquel Raynal
Cc: De Marchi, Lucas, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Vivi, Rodrigo,
Tvrtko Ursulin, Winkler, Tomas, Lubart, Vitaly,
intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-spi@vger.kernel.org, intel-gfx@lists.freedesktop.org
> On Mon, Sep 16, 2024 at 04:49:16PM +0300, Alexander Usyskin wrote:
> > Add driver for access to Intel discrete graphics card
> > internal SPI device.
> > Expose device on auxiliary bus by i915 and Xe drivers and
> > provide spi driver to register this device with MTD framework.
>
> As far as I can tell this does not actually provide a SPI driver, there
> is no call to any SPI API that I've noticed here. The SPI framework
> does have support for SPI controllers with specific flash support via
> spi_controller_mem_ops but this does not appear to use them. Either it
> should do that or it should just be a MTD driver.
>
I have had some talks with Miquel on this and he was not sure where this driver belongs.
Miquel - can this driver be put in drivers/mtd, as spi cleanly do not want it?
> The series is also split up into too many patches with minimal
> explanation, making it hard to follow what's going on. I would
> recommend making the first patch be a minimal functional driver and then
> building on top of that.
As I understand, better to have small amount of big patches
than big list of smaller patches?
I'll try, according to your comments in other patches,
but we have there three big parts (changes in i915, changes in Xe
and actual spi/mtd driver) and they should come together as
there is no point in any of them alone.
- -
Thanks,
Sasha
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH v6 00/12] spi: add driver for Intel discrete graphics
2024-09-19 6:56 ` Usyskin, Alexander
@ 2024-09-19 8:31 ` Mark Brown
0 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2024-09-19 8:31 UTC (permalink / raw)
To: Usyskin, Alexander
Cc: Miquel Raynal, De Marchi, Lucas, Oded Gabbay,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Daniel Vetter, Jani Nikula,
Joonas Lahtinen, Vivi, Rodrigo, Tvrtko Ursulin, Winkler, Tomas,
Lubart, Vitaly, intel-xe@lists.freedesktop.org,
dri-devel@lists.freedesktop.org, linux-spi@vger.kernel.org,
intel-gfx@lists.freedesktop.org
[-- Attachment #1: Type: text/plain, Size: 1547 bytes --]
On Thu, Sep 19, 2024 at 06:56:39AM +0000, Usyskin, Alexander wrote:
> > On Mon, Sep 16, 2024 at 04:49:16PM +0300, Alexander Usyskin wrote:
> > As far as I can tell this does not actually provide a SPI driver, there
> > is no call to any SPI API that I've noticed here. The SPI framework
> > does have support for SPI controllers with specific flash support via
> > spi_controller_mem_ops but this does not appear to use them. Either it
> > should do that or it should just be a MTD driver.
> I have had some talks with Miquel on this and he was not sure where this driver belongs.
> Miquel - can this driver be put in drivers/mtd, as spi cleanly do not want it?
To be clear, it's not that this hardware shouldn't be supported in the
SPI subsystem it's that if the driver is in the SPI subsystem it should
be written in terms of the relevant APIs. Simply taking a MTD driver
and dropping it in a random other directory with no further updates
is clearly not the way forwards.
> > The series is also split up into too many patches with minimal
> > explanation, making it hard to follow what's going on. I would
> > recommend making the first patch be a minimal functional driver and then
> > building on top of that.
> As I understand, better to have small amount of big patches
> than big list of smaller patches?
The patches should be individually standalone and useful, the problem
here is that it's difficult to review any of the patches by themselves
because they've not been split up with a clear goal.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 34+ messages in thread
* RE: [PATCH v6 01/12] spi: add driver for intel graphics on-die spi device
2024-09-18 13:33 ` Mark Brown
@ 2024-09-19 9:54 ` Winkler, Tomas
2024-09-19 10:32 ` Mark Brown
0 siblings, 1 reply; 34+ messages in thread
From: Winkler, Tomas @ 2024-09-19 9:54 UTC (permalink / raw)
To: Mark Brown, Usyskin, Alexander
Cc: De Marchi, Lucas, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Vivi, Rodrigo,
Tvrtko Ursulin, Lubart, Vitaly, intel-xe@lists.freedesktop.org,
dri-devel@lists.freedesktop.org, linux-spi@vger.kernel.org,
intel-gfx@lists.freedesktop.org
>
> On Mon, Sep 16, 2024 at 04:49:17PM +0300, Alexander Usyskin wrote:
>
> > Add auxiliary driver for intel discrete graphics on-die spi device.
>
> This doesn't actually do anything AFAICT? It doesn't register with any
> subsystem or anything. Please don't submit empty boilerplate like this,
> submit a driver that is at least minimally useful - assuming some other
> patches in the series add functionality squash at least a basic set of
> functionality into this. This makes review and test easier.
>
> > +++ b/drivers/spi/spi-intel-dg.c
> > @@ -0,0 +1,142 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright(c) 2019-2024, Intel Corporation. All rights reserved.
> > + */
>
> Please make the entire comment a C++ one so things look more intentional.
This is how it is required by Linux spdx checker,
>
> > +struct intel_dg_spi {
> > + struct kref refcnt;
> > + void __iomem *base;
> > + size_t size;
> > + unsigned int nregions;
> > + struct {
> > + const char *name;
> > + u8 id;
> > + u64 offset;
> > + u64 size;
> > + } regions[];
>
> Use __counted_by() for the benefit of the static checkers.
Good point, it's a new C feature.
>
> > + size = sizeof(*spi) + sizeof(spi->regions[0]) * nregions;
> > + spi = kzalloc(size, GFP_KERNEL);
>
> Use at least array_size().
Regions is not fixed size array, it will not work.
>
> > + kref_init(&spi->refcnt);
>
> This refcount feels more complex than just freeing in the error and release
> paths, it's not a common pattern for drivers.
What are you suggesting
>
> > + spi->nregions = nregions;
> > + for (n = 0, i = 0; i < INTEL_DG_SPI_REGIONS; i++) {
> > + if (ispi->regions[i].name) {
> > + name_size = strlen(dev_name(&aux_dev->dev)) +
> > + strlen(ispi->regions[i].name) + 2; /* for
> point */
> > + name = kzalloc(name_size, GFP_KERNEL);
> > + if (!name)
> > + continue;
> > + snprintf(name, name_size, "%s.%s",
> > + dev_name(&aux_dev->dev), ispi-
> >regions[i].name);
>
> kasprintf().
As I understand kasprintf allocates memory, this is not required here.
>
> > +static void intel_dg_spi_remove(struct auxiliary_device *aux_dev) {
> > + struct intel_dg_spi *spi = dev_get_drvdata(&aux_dev->dev);
> > +
> > + if (!spi)
> > + return;
> > +
> > + dev_set_drvdata(&aux_dev->dev, NULL);
>
> If the above is doing anything there's a problem...
It makes sure the data is set to NULL.
^ permalink raw reply [flat|nested] 34+ messages in thread
* RE: [PATCH v6 02/12] spi: intel-dg: implement region enumeration
2024-09-18 13:35 ` Mark Brown
@ 2024-09-19 9:55 ` Winkler, Tomas
2024-09-19 10:34 ` Mark Brown
0 siblings, 1 reply; 34+ messages in thread
From: Winkler, Tomas @ 2024-09-19 9:55 UTC (permalink / raw)
To: Mark Brown, Usyskin, Alexander
Cc: De Marchi, Lucas, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Vivi, Rodrigo,
Tvrtko Ursulin, Lubart, Vitaly, intel-xe@lists.freedesktop.org,
dri-devel@lists.freedesktop.org, linux-spi@vger.kernel.org,
intel-gfx@lists.freedesktop.org
>
> On Mon, Sep 16, 2024 at 04:49:18PM +0300, Alexander Usyskin wrote:
>
> > In intel-dg spi, there is no access to the spi controller, the
> > information is extracted from the descriptor region.
>
> Which information? I can't tell what this patch is supposed to do; as with the
> first patch this shouldn't be standalone.
The patch series was built for review, it adds functionality on top of each other.
>
> > +static inline u32 spi_error(struct intel_dg_spi *spi) {
>
> > +static inline u32 spi_read32(struct intel_dg_spi *spi, u32 address) {
>
> At least these names are too generic, please use driver specific prefixes.
Can be done but those functions are local to the driver not part of the API.
^ permalink raw reply [flat|nested] 34+ messages in thread
* RE: [PATCH v6 04/12] spi: intel-dg: spi register with mtd
2024-09-18 13:38 ` Mark Brown
@ 2024-09-19 10:01 ` Winkler, Tomas
2024-09-19 10:43 ` Mark Brown
0 siblings, 1 reply; 34+ messages in thread
From: Winkler, Tomas @ 2024-09-19 10:01 UTC (permalink / raw)
To: Mark Brown, Usyskin, Alexander
Cc: De Marchi, Lucas, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Vivi, Rodrigo,
Tvrtko Ursulin, Lubart, Vitaly, intel-xe@lists.freedesktop.org,
dri-devel@lists.freedesktop.org, linux-spi@vger.kernel.org,
intel-gfx@lists.freedesktop.org
>
> On Mon, Sep 16, 2024 at 04:49:20PM +0300, Alexander Usyskin wrote:
>
> > From: Tomas Winkler <tomas.winkler@intel.com>
> >
> > Register the on-die spi device with the mtd subsystem.
> > Refcount spi object on _get and _put mtd callbacks.
>
> This is a MTD driver, it should be in drivers/mtd.
Okay.
>
> > +static int intel_dg_spi_erase(struct mtd_info *mtd, struct erase_info
> > +*info) {
> > + return 0;
> > +}
> > +
> > +static int intel_dg_spi_read(struct mtd_info *mtd, loff_t from, size_t len,
> > + size_t *retlen, u_char *buf)
> > +{
> > + return 0;
> > +}
> > +
> > +static int intel_dg_spi_write(struct mtd_info *mtd, loff_t to, size_t len,
> > + size_t *retlen, const u_char *buf) {
> > + return 0;
> > +}
>
> If these functions can legitimately be empty they should be removed.
Those are place holder so the code will compile and implemented in following patches, this is compromise on not making too big changes.
It use dot be acceptable compromise in past.
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH v6 01/12] spi: add driver for intel graphics on-die spi device
2024-09-19 9:54 ` Winkler, Tomas
@ 2024-09-19 10:32 ` Mark Brown
2024-09-21 13:00 ` Winkler, Tomas
0 siblings, 1 reply; 34+ messages in thread
From: Mark Brown @ 2024-09-19 10:32 UTC (permalink / raw)
To: Winkler, Tomas
Cc: Usyskin, Alexander, De Marchi, Lucas, Oded Gabbay,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Daniel Vetter, Jani Nikula,
Joonas Lahtinen, Vivi, Rodrigo, Tvrtko Ursulin, Lubart, Vitaly,
intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-spi@vger.kernel.org, intel-gfx@lists.freedesktop.org
[-- Attachment #1: Type: text/plain, Size: 1992 bytes --]
On Thu, Sep 19, 2024 at 09:54:24AM +0000, Winkler, Tomas wrote:
> > On Mon, Sep 16, 2024 at 04:49:17PM +0300, Alexander Usyskin wrote:
> > > @@ -0,0 +1,142 @@
> > > +// SPDX-License-Identifier: GPL-2.0
> > > +/*
> > > + * Copyright(c) 2019-2024, Intel Corporation. All rights reserved.
> > > + */
> > Please make the entire comment a C++ one so things look more intentional.
> This is how it is required by Linux spdx checker,
There is no incompatibility between SPDX and what I'm asking for...
> > > + size = sizeof(*spi) + sizeof(spi->regions[0]) * nregions;
> > > + spi = kzalloc(size, GFP_KERNEL);
> > Use at least array_size().
> Regions is not fixed size array, it will not work.
Yes, that's the wrong helper - there is a relevent one though which I'm
not remembering right now.
> > > + kref_init(&spi->refcnt);
> > This refcount feels more complex than just freeing in the error and release
> > paths, it's not a common pattern for drivers.
> What are you suggesting
Just do normal open coded allocations, the reference counting is just
obscure.
> > > + if (ispi->regions[i].name) {
> > > + name_size = strlen(dev_name(&aux_dev->dev)) +
> > > + strlen(ispi->regions[i].name) + 2; /* for
> > point */
> > > + name = kzalloc(name_size, GFP_KERNEL);
> > > + if (!name)
> > > + continue;
> > > + snprintf(name, name_size, "%s.%s",
> > > + dev_name(&aux_dev->dev), ispi-
> > >regions[i].name);
> > kasprintf().
> As I understand kasprintf allocates memory, this is not required here.
There is a kzalloc() in the above code block?
> > > +static void intel_dg_spi_remove(struct auxiliary_device *aux_dev) {
> > > + struct intel_dg_spi *spi = dev_get_drvdata(&aux_dev->dev);
> > > + if (!spi)
> > > + return;
> > > + dev_set_drvdata(&aux_dev->dev, NULL);
> > If the above is doing anything there's a problem...
o
> It makes sure the data is set to NULL.
Which is needed because...?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH v6 02/12] spi: intel-dg: implement region enumeration
2024-09-19 9:55 ` Winkler, Tomas
@ 2024-09-19 10:34 ` Mark Brown
0 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2024-09-19 10:34 UTC (permalink / raw)
To: Winkler, Tomas
Cc: Usyskin, Alexander, De Marchi, Lucas, Oded Gabbay,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Daniel Vetter, Jani Nikula,
Joonas Lahtinen, Vivi, Rodrigo, Tvrtko Ursulin, Lubart, Vitaly,
intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-spi@vger.kernel.org, intel-gfx@lists.freedesktop.org
[-- Attachment #1: Type: text/plain, Size: 1097 bytes --]
On Thu, Sep 19, 2024 at 09:55:54AM +0000, Winkler, Tomas wrote:
> > On Mon, Sep 16, 2024 at 04:49:18PM +0300, Alexander Usyskin wrote:
> > > In intel-dg spi, there is no access to the spi controller, the
> > > information is extracted from the descriptor region.
> > Which information? I can't tell what this patch is supposed to do; as with the
> > first patch this shouldn't be standalone.
> The patch series was built for review, it adds functionality on top of each other.
That's not worked out well here - like I say I can't tell what the patch
is supposed to be doing. What information is supposed to be read here,
why?
> > > +static inline u32 spi_error(struct intel_dg_spi *spi) {
> > > +static inline u32 spi_read32(struct intel_dg_spi *spi, u32 address) {
> > At least these names are too generic, please use driver specific prefixes.
> Can be done but those functions are local to the driver not part of the API.
Sure, the issue is that a core API with the same name could reasonably
be added at which point it'll collide with the driver internals.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH v6 04/12] spi: intel-dg: spi register with mtd
2024-09-19 10:01 ` Winkler, Tomas
@ 2024-09-19 10:43 ` Mark Brown
0 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2024-09-19 10:43 UTC (permalink / raw)
To: Winkler, Tomas
Cc: Usyskin, Alexander, De Marchi, Lucas, Oded Gabbay,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Daniel Vetter, Jani Nikula,
Joonas Lahtinen, Vivi, Rodrigo, Tvrtko Ursulin, Lubart, Vitaly,
intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-spi@vger.kernel.org, intel-gfx@lists.freedesktop.org
[-- Attachment #1: Type: text/plain, Size: 1001 bytes --]
On Thu, Sep 19, 2024 at 10:01:06AM +0000, Winkler, Tomas wrote:
> > On Mon, Sep 16, 2024 at 04:49:20PM +0300, Alexander Usyskin wrote:
> > > +static int intel_dg_spi_write(struct mtd_info *mtd, loff_t to, size_t len,
> > > + size_t *retlen, const u_char *buf) {
> > > + return 0;
> > > +}
> > If these functions can legitimately be empty they should be removed.
> Those are place holder so the code will compile and implemented in following patches, this is compromise on not making too big changes.
> It use dot be acceptable compromise in past.
If you omit the functions you should obviously entirely omit them
entirely, including putting them in relevant ops struct. As things
stand this just makes the code look buggy which doesn't help review,
you're adding functions which obviously don't work properly and not even
noting that in the changelog or code. Just add the assignment of the
ops when you add the implementation of the ops, that way there's no
partially implemented step.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 34+ messages in thread
* RE: [PATCH v6 01/12] spi: add driver for intel graphics on-die spi device
2024-09-19 10:32 ` Mark Brown
@ 2024-09-21 13:00 ` Winkler, Tomas
2024-09-23 8:02 ` Tvrtko Ursulin
2024-09-23 12:49 ` Mark Brown
0 siblings, 2 replies; 34+ messages in thread
From: Winkler, Tomas @ 2024-09-21 13:00 UTC (permalink / raw)
To: Mark Brown
Cc: Usyskin, Alexander, De Marchi, Lucas, Oded Gabbay,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Daniel Vetter, Jani Nikula,
Joonas Lahtinen, Vivi, Rodrigo, Tvrtko Ursulin, Lubart, Vitaly,
intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-spi@vger.kernel.org, intel-gfx@lists.freedesktop.org
>
> On Thu, Sep 19, 2024 at 09:54:24AM +0000, Winkler, Tomas wrote:
> > > On Mon, Sep 16, 2024 at 04:49:17PM +0300, Alexander Usyskin wrote:
>
> > > > @@ -0,0 +1,142 @@
> > > > +// SPDX-License-Identifier: GPL-2.0
> > > > +/*
> > > > + * Copyright(c) 2019-2024, Intel Corporation. All rights reserved.
> > > > + */
>
> > > Please make the entire comment a C++ one so things look more
> intentional.
>
> > This is how it is required by Linux spdx checker,
>
> There is no incompatibility between SPDX and what I'm asking for...
>
> > > > + size = sizeof(*spi) + sizeof(spi->regions[0]) * nregions;
> > > > + spi = kzalloc(size, GFP_KERNEL);
>
> > > Use at least array_size().
>
> > Regions is not fixed size array, it will not work.
>
> Yes, that's the wrong helper - there is a relevent one though which I'm not
> remembering right now.
I don't think there is one, you can allocate arrays but this is not the case here.
>
> > > > + kref_init(&spi->refcnt);
>
> > > This refcount feels more complex than just freeing in the error and
> > > release paths, it's not a common pattern for drivers.
>
> > What are you suggesting
>
> Just do normal open coded allocations, the reference counting is just
> obscure.
The kref here is for reason so we don't need to hunt the close open, I frankly don't understand
what is wrong with it,
> > > > + if (ispi->regions[i].name) {
> > > > + name_size = strlen(dev_name(&aux_dev->dev)) +
> > > > + strlen(ispi->regions[i].name) + 2; /* for
> > > point */
> > > > + name = kzalloc(name_size, GFP_KERNEL);
> > > > + if (!name)
> > > > + continue;
> > > > + snprintf(name, name_size, "%s.%s",
> > > > + dev_name(&aux_dev->dev), ispi-
> > > >regions[i].name);
>
> > > kasprintf().
>
> > As I understand kasprintf allocates memory, this is not required here.
>
> There is a kzalloc() in the above code block?
Sorry you are right.
>
> > > > +static void intel_dg_spi_remove(struct auxiliary_device *aux_dev) {
> > > > + struct intel_dg_spi *spi = dev_get_drvdata(&aux_dev->dev);
>
> > > > + if (!spi)
> > > > + return;
>
> > > > + dev_set_drvdata(&aux_dev->dev, NULL);
>
> > > If the above is doing anything there's a problem...
> o
> > It makes sure the data is set to NULL.
>
> Which is needed because...?
This is a boilerplate part, the content is consequent patches.
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH v6 01/12] spi: add driver for intel graphics on-die spi device
2024-09-21 13:00 ` Winkler, Tomas
@ 2024-09-23 8:02 ` Tvrtko Ursulin
2024-09-23 12:49 ` Mark Brown
1 sibling, 0 replies; 34+ messages in thread
From: Tvrtko Ursulin @ 2024-09-23 8:02 UTC (permalink / raw)
To: Winkler, Tomas, Mark Brown
Cc: Usyskin, Alexander, De Marchi, Lucas, Oded Gabbay,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Daniel Vetter, Jani Nikula,
Joonas Lahtinen, Vivi, Rodrigo, Lubart, Vitaly,
intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-spi@vger.kernel.org, intel-gfx@lists.freedesktop.org
On 21/09/2024 14:00, Winkler, Tomas wrote:
>
>
>>
>> On Thu, Sep 19, 2024 at 09:54:24AM +0000, Winkler, Tomas wrote:
>>>> On Mon, Sep 16, 2024 at 04:49:17PM +0300, Alexander Usyskin wrote:
>>
>>>>> @@ -0,0 +1,142 @@
>>>>> +// SPDX-License-Identifier: GPL-2.0
>>>>> +/*
>>>>> + * Copyright(c) 2019-2024, Intel Corporation. All rights reserved.
>>>>> + */
>>
>>>> Please make the entire comment a C++ one so things look more
>> intentional.
>>
>>> This is how it is required by Linux spdx checker,
>>
>> There is no incompatibility between SPDX and what I'm asking for...
>>
>>>>> + size = sizeof(*spi) + sizeof(spi->regions[0]) * nregions;
>>>>> + spi = kzalloc(size, GFP_KERNEL);
>>
>>>> Use at least array_size().
>>
>>> Regions is not fixed size array, it will not work.
>>
>> Yes, that's the wrong helper - there is a relevent one though which I'm not
>> remembering right now.
>
>
> I don't think there is one, you can allocate arrays but this is not the case here.
struct_size() probably.
Regards,
Tvrtko
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH v6 08/12] drm/i915/spi: add spi device for discrete graphics
2024-09-16 13:49 ` [PATCH v6 08/12] drm/i915/spi: add spi device for discrete graphics Alexander Usyskin
@ 2024-09-23 8:31 ` Jani Nikula
2024-09-23 11:33 ` Usyskin, Alexander
0 siblings, 1 reply; 34+ messages in thread
From: Jani Nikula @ 2024-09-23 8:31 UTC (permalink / raw)
To: Alexander Usyskin, Mark Brown, Lucas De Marchi, Oded Gabbay,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Daniel Vetter, Joonas Lahtinen,
Rodrigo Vivi, Tvrtko Ursulin
Cc: Tomas Winkler, Alexander Usyskin, Vitaly Lubart, intel-xe,
dri-devel, linux-spi, intel-gfx
On Mon, 16 Sep 2024, Alexander Usyskin <alexander.usyskin@intel.com> wrote:
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index 39f6614a0a99..b9d4f9be5355 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -34,6 +34,8 @@
>
> #include <linux/pm_qos.h>
>
> +#include <linux/intel_dg_spi_aux.h>
> +
> #include <drm/ttm/ttm_device.h>
>
> #include "display/intel_display_limits.h"
> @@ -315,6 +317,8 @@ struct drm_i915_private {
>
> struct i915_perf perf;
>
> + struct intel_dg_spi_dev spi;
> +
Sorry, late to the party.
Can we make that struct intel_dg_spi_dev *spi, drop the include and use
a forward declaration for the type, and allocate dynamically please?
Ditto for xe driver.
struct drm_i915_private is huge, i915_drv.h gets included everywhere,
and there's no reason everyone should be able to look at the guts of of
that member.
BR,
Jani.
--
Jani Nikula, Intel
^ permalink raw reply [flat|nested] 34+ messages in thread
* RE: [PATCH v6 08/12] drm/i915/spi: add spi device for discrete graphics
2024-09-23 8:31 ` Jani Nikula
@ 2024-09-23 11:33 ` Usyskin, Alexander
0 siblings, 0 replies; 34+ messages in thread
From: Usyskin, Alexander @ 2024-09-23 11:33 UTC (permalink / raw)
To: Jani Nikula, Mark Brown, De Marchi, Lucas, Oded Gabbay,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Daniel Vetter, Joonas Lahtinen,
Vivi, Rodrigo, Tvrtko Ursulin
Cc: Winkler, Tomas, Lubart, Vitaly, intel-xe@lists.freedesktop.org,
dri-devel@lists.freedesktop.org, linux-spi@vger.kernel.org,
intel-gfx@lists.freedesktop.org
> Subject: Re: [PATCH v6 08/12] drm/i915/spi: add spi device for discrete
> graphics
>
> On Mon, 16 Sep 2024, Alexander Usyskin <alexander.usyskin@intel.com>
> wrote:
> > diff --git a/drivers/gpu/drm/i915/i915_drv.h
> b/drivers/gpu/drm/i915/i915_drv.h
> > index 39f6614a0a99..b9d4f9be5355 100644
> > --- a/drivers/gpu/drm/i915/i915_drv.h
> > +++ b/drivers/gpu/drm/i915/i915_drv.h
> > @@ -34,6 +34,8 @@
> >
> > #include <linux/pm_qos.h>
> >
> > +#include <linux/intel_dg_spi_aux.h>
> > +
> > #include <drm/ttm/ttm_device.h>
> >
> > #include "display/intel_display_limits.h"
> > @@ -315,6 +317,8 @@ struct drm_i915_private {
> >
> > struct i915_perf perf;
> >
> > + struct intel_dg_spi_dev spi;
> > +
>
> Sorry, late to the party.
>
> Can we make that struct intel_dg_spi_dev *spi, drop the include and use
> a forward declaration for the type, and allocate dynamically please?
>
> Ditto for xe driver.
>
> struct drm_i915_private is huge, i915_drv.h gets included everywhere,
> and there's no reason everyone should be able to look at the guts of of
> that member.
>
Thanks for review!
Yes, seem reasonable to move the struct out, I'll look how to do it and
update in the next revision.
Any other comments about Xe/i915 code?
It should be unaffected by changes in spi/mtd part.
- -
Thanks,
Sasha
>
> BR,
> Jani.
>
>
> --
> Jani Nikula, Intel
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH v6 01/12] spi: add driver for intel graphics on-die spi device
2024-09-21 13:00 ` Winkler, Tomas
2024-09-23 8:02 ` Tvrtko Ursulin
@ 2024-09-23 12:49 ` Mark Brown
2024-09-25 12:31 ` Usyskin, Alexander
1 sibling, 1 reply; 34+ messages in thread
From: Mark Brown @ 2024-09-23 12:49 UTC (permalink / raw)
To: Winkler, Tomas
Cc: Usyskin, Alexander, De Marchi, Lucas, Oded Gabbay,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Daniel Vetter, Jani Nikula,
Joonas Lahtinen, Vivi, Rodrigo, Tvrtko Ursulin, Lubart, Vitaly,
intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-spi@vger.kernel.org, intel-gfx@lists.freedesktop.org
[-- Attachment #1: Type: text/plain, Size: 2128 bytes --]
On Sat, Sep 21, 2024 at 01:00:52PM +0000, Winkler, Tomas wrote:
> > On Thu, Sep 19, 2024 at 09:54:24AM +0000, Winkler, Tomas wrote:
> > > > On Mon, Sep 16, 2024 at 04:49:17PM +0300, Alexander Usyskin wrote:
> > Just do normal open coded allocations, the reference counting is just
> > obscure.
> The kref here is for reason so we don't need to hunt the close open, I frankly don't understand
> what is wrong with it,
It's locking/refcounting stuff that looks nothing like any other SPI
controller driver. Even if it works it's obviously fragile since the
driver does surprising things which break assumptions that will be made
by people not looking at this specific driver, and causes people to have
to spend more effort figuring out what you're doing. If there is any
benefit to doing this then open coding it in one specific driver is
clearly not the right place to do it.
> > > > > +static void intel_dg_spi_remove(struct auxiliary_device *aux_dev) {
> > > > > + struct intel_dg_spi *spi = dev_get_drvdata(&aux_dev->dev);
> > > > > + if (!spi)
> > > > > + return;
> > > > > + dev_set_drvdata(&aux_dev->dev, NULL);
> > > > If the above is doing anything there's a problem...
> > o
> > > It makes sure the data is set to NULL.
> > Which is needed because...?
> This is a boilerplate part, the content is consequent patches.
Which would come back to the issues created by the random splitting of
the series were it not for the fact that if anything tries to look at
the driver data of a removed device it's buggy, the reference is gone
and the device may have been deallocated and it's certainly freed from
the perspective of this user. Notice how other drivers don't do this.
The driver core will also overwrite the driver data of released
devices...
At a high level a lot of the issues with this series is that both in
terms of how it's been sent and what it's doing there's a bunch of
things that look nothing like how we normally handle things. At best
this means that problems are being solved at the wrong level, but it's
hard to see that this is the case.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 34+ messages in thread
* RE: [PATCH v6 01/12] spi: add driver for intel graphics on-die spi device
2024-09-23 12:49 ` Mark Brown
@ 2024-09-25 12:31 ` Usyskin, Alexander
2024-09-25 13:12 ` Mark Brown
0 siblings, 1 reply; 34+ messages in thread
From: Usyskin, Alexander @ 2024-09-25 12:31 UTC (permalink / raw)
To: Mark Brown, Winkler, Tomas
Cc: De Marchi, Lucas, Oded Gabbay, Thomas Hellström,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Daniel Vetter, Jani Nikula, Joonas Lahtinen, Vivi, Rodrigo,
Tvrtko Ursulin, Lubart, Vitaly, intel-xe@lists.freedesktop.org,
dri-devel@lists.freedesktop.org, linux-spi@vger.kernel.org,
intel-gfx@lists.freedesktop.org
> On Sat, Sep 21, 2024 at 01:00:52PM +0000, Winkler, Tomas wrote:
> > > On Thu, Sep 19, 2024 at 09:54:24AM +0000, Winkler, Tomas wrote:
> > > > > On Mon, Sep 16, 2024 at 04:49:17PM +0300, Alexander Usyskin
> wrote:
>
> > > Just do normal open coded allocations, the reference counting is just
> > > obscure.
>
> > The kref here is for reason so we don't need to hunt the close open, I frankly
> don't understand
> > what is wrong with it,
>
> It's locking/refcounting stuff that looks nothing like any other SPI
> controller driver. Even if it works it's obviously fragile since the
> driver does surprising things which break assumptions that will be made
> by people not looking at this specific driver, and causes people to have
> to spend more effort figuring out what you're doing. If there is any
> benefit to doing this then open coding it in one specific driver is
> clearly not the right place to do it.
>
The reason for all this refcounting that the device itself is discrete card and
the SPI memory backend can disappear at any moment leaving open connections dangling.
Refcount ensures that object behind the MTD device will be freed only
when the last user-space is disconnected.
Is there any other model that can keep the object alive in this situation?
- -
Thanks,
Sasha
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: [PATCH v6 01/12] spi: add driver for intel graphics on-die spi device
2024-09-25 12:31 ` Usyskin, Alexander
@ 2024-09-25 13:12 ` Mark Brown
0 siblings, 0 replies; 34+ messages in thread
From: Mark Brown @ 2024-09-25 13:12 UTC (permalink / raw)
To: Usyskin, Alexander
Cc: Winkler, Tomas, De Marchi, Lucas, Oded Gabbay,
Thomas Hellström, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Daniel Vetter, Jani Nikula,
Joonas Lahtinen, Vivi, Rodrigo, Tvrtko Ursulin, Lubart, Vitaly,
intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-spi@vger.kernel.org, intel-gfx@lists.freedesktop.org
[-- Attachment #1: Type: text/plain, Size: 1286 bytes --]
On Wed, Sep 25, 2024 at 12:31:34PM +0000, Usyskin, Alexander wrote:
> > It's locking/refcounting stuff that looks nothing like any other SPI
> > controller driver. Even if it works it's obviously fragile since the
> > driver does surprising things which break assumptions that will be made
> > by people not looking at this specific driver, and causes people to have
> > to spend more effort figuring out what you're doing. If there is any
> > benefit to doing this then open coding it in one specific driver is
> > clearly not the right place to do it.
> The reason for all this refcounting that the device itself is discrete card and
> the SPI memory backend can disappear at any moment leaving open connections dangling.
> Refcount ensures that object behind the MTD device will be freed only
> when the last user-space is disconnected.
> Is there any other model that can keep the object alive in this situation?
If devices connected to the SPI controller can be hotplugged then those
devices should be registered and unregistered like any other spi_device
would be, the driver core and relevant subsystems will deal with the
lifetime issues. This is all invisible to the SPI controllers, the fact
that things are being open coded in the driver should be a big warning
sign.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 34+ messages in thread
end of thread, other threads:[~2024-09-25 13:12 UTC | newest]
Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-16 13:49 [PATCH v6 00/12] spi: add driver for Intel discrete graphics Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 01/12] spi: add driver for intel graphics on-die spi device Alexander Usyskin
2024-09-18 13:33 ` Mark Brown
2024-09-19 9:54 ` Winkler, Tomas
2024-09-19 10:32 ` Mark Brown
2024-09-21 13:00 ` Winkler, Tomas
2024-09-23 8:02 ` Tvrtko Ursulin
2024-09-23 12:49 ` Mark Brown
2024-09-25 12:31 ` Usyskin, Alexander
2024-09-25 13:12 ` Mark Brown
2024-09-16 13:49 ` [PATCH v6 02/12] spi: intel-dg: implement region enumeration Alexander Usyskin
2024-09-18 13:35 ` Mark Brown
2024-09-19 9:55 ` Winkler, Tomas
2024-09-19 10:34 ` Mark Brown
2024-09-16 13:49 ` [PATCH v6 03/12] spi: intel-dg: implement spi access functions Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 04/12] spi: intel-dg: spi register with mtd Alexander Usyskin
2024-09-18 13:38 ` Mark Brown
2024-09-19 10:01 ` Winkler, Tomas
2024-09-19 10:43 ` Mark Brown
2024-09-16 13:49 ` [PATCH v6 05/12] spi: intel-dg: implement mtd access handlers Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 06/12] spi: intel-dg: align 64bit read and write Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 07/12] spi: intel-dg: wake card on operations Alexander Usyskin
2024-09-16 18:00 ` Rodrigo Vivi
2024-09-16 13:49 ` [PATCH v6 08/12] drm/i915/spi: add spi device for discrete graphics Alexander Usyskin
2024-09-23 8:31 ` Jani Nikula
2024-09-23 11:33 ` Usyskin, Alexander
2024-09-16 13:49 ` [PATCH v6 09/12] drm/i915/spi: add intel_spi_region map Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 10/12] drm/i915/spi: add support for access mode Alexander Usyskin
2024-09-16 13:49 ` [PATCH v6 11/12] drm/xe/spi: add on-die spi device Alexander Usyskin
2024-09-16 18:04 ` Rodrigo Vivi
2024-09-16 13:49 ` [PATCH v6 12/12] drm/xe/spi: add support for access mode Alexander Usyskin
2024-09-18 13:45 ` [PATCH v6 00/12] spi: add driver for Intel discrete graphics Mark Brown
2024-09-19 6:56 ` Usyskin, Alexander
2024-09-19 8:31 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).