[PATCH v5 02/10] gna: add GNA DRM device
Maciej Kwapulinski
maciej.kwapulinski at linux.intel.com
Thu Oct 20 17:53:26 UTC 2022
Signed-off-by: Maciej Kwapulinski <maciej.kwapulinski at linux.intel.com>
Tested-by: Mikolaj Grzybowski <mikolajx.grzybowski at intel.com>
---
drivers/gpu/drm/gna/Kconfig | 1 +
drivers/gpu/drm/gna/gna_device.c | 65 ++++++++++++++++++++++++++++++++
drivers/gpu/drm/gna/gna_device.h | 21 +++++++++++
drivers/gpu/drm/gna/gna_hw.h | 17 +++++++++
drivers/gpu/drm/gna/gna_pci.c | 11 ++++++
5 files changed, 115 insertions(+)
create mode 100644 drivers/gpu/drm/gna/gna_hw.h
diff --git a/drivers/gpu/drm/gna/Kconfig b/drivers/gpu/drm/gna/Kconfig
index 467f518db7fa..820dc8424045 100644
--- a/drivers/gpu/drm/gna/Kconfig
+++ b/drivers/gpu/drm/gna/Kconfig
@@ -5,6 +5,7 @@
config DRM_GNA
tristate "Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA)"
depends on X86 && PCI
+ depends on DRM
help
This option enables the Intel(R) Gaussian & Neural Accelerator
(Intel(R) GNA) driver: gna
diff --git a/drivers/gpu/drm/gna/gna_device.c b/drivers/gpu/drm/gna/gna_device.c
index 960b4341c18e..b8620b7da205 100644
--- a/drivers/gpu/drm/gna/gna_device.c
+++ b/drivers/gpu/drm/gna/gna_device.c
@@ -1,8 +1,73 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright(c) 2017-2022 Intel Corporation
+#include <drm/drm_drv.h>
+#include <drm/drm_file.h>
+#include <drm/drm_managed.h>
+
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
#include <linux/module.h>
+#include "gna_device.h"
+
+static void gna_drm_dev_fini(struct drm_device *dev, void *ptr)
+{
+ drm_dev_unregister(dev);
+}
+
+static int gna_drm_dev_init(struct drm_device *dev)
+{
+ int err;
+
+ err = drm_dev_register(dev, 0);
+ if (err)
+ return err;
+
+ return drmm_add_action_or_reset(dev, gna_drm_dev_fini, NULL);
+}
+
+static const struct drm_driver gna_drm_driver = {
+ .driver_features = DRIVER_RENDER,
+
+ .name = DRIVER_NAME,
+ .desc = DRIVER_DESC,
+ .date = DRIVER_DATE,
+ .major = DRIVER_MAJOR,
+ .minor = DRIVER_MINOR,
+ .patchlevel = DRIVER_PATCHLEVEL,
+};
+
+int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase)
+{
+ struct gna_device *gna_priv;
+ struct drm_device *drm_dev;
+ int err;
+
+ gna_priv = devm_drm_dev_alloc(parent, &gna_drm_driver, struct gna_device, drm);
+ if (IS_ERR(gna_priv))
+ return PTR_ERR(gna_priv);
+
+ drm_dev = &gna_priv->drm;
+ gna_priv->iobase = iobase;
+ gna_priv->info = *dev_info;
+
+ if (!(sizeof(dma_addr_t) > 4) ||
+ dma_set_mask(parent, DMA_BIT_MASK(64))) {
+ err = dma_set_mask(parent, DMA_BIT_MASK(32));
+ if (err)
+ return err;
+ }
+
+ dev_set_drvdata(parent, drm_dev);
+
+ err = gna_drm_dev_init(drm_dev);
+ if (err)
+ return err;
+
+ return 0;
+}
+
MODULE_AUTHOR("Intel Corporation");
MODULE_DESCRIPTION("Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA) Driver");
MODULE_LICENSE("GPL");
diff --git a/drivers/gpu/drm/gna/gna_device.h b/drivers/gpu/drm/gna/gna_device.h
index 4cc92f27765a..d269f7da5c5e 100644
--- a/drivers/gpu/drm/gna/gna_device.h
+++ b/drivers/gpu/drm/gna/gna_device.h
@@ -4,6 +4,27 @@
#ifndef __GNA_DEVICE_H__
#define __GNA_DEVICE_H__
+#include <drm/drm_device.h>
+
+#include "gna_hw.h"
+
#define DRIVER_NAME "gna"
+#define DRIVER_DESC "Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA)"
+#define DRIVER_DATE "20211201"
+
+#define DRIVER_MAJOR 1
+#define DRIVER_MINOR 0
+#define DRIVER_PATCHLEVEL 0
+
+struct device;
+
+struct gna_device {
+ struct drm_device drm;
+
+ /* device related resources */
+ void __iomem *iobase;
+ struct gna_dev_info info;
+};
+int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase);
#endif /* __GNA_DEVICE_H__ */
diff --git a/drivers/gpu/drm/gna/gna_hw.h b/drivers/gpu/drm/gna/gna_hw.h
new file mode 100644
index 000000000000..3ca801096fd1
--- /dev/null
+++ b/drivers/gpu/drm/gna/gna_hw.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2017-2022 Intel Corporation */
+
+#ifndef __GNA_HW_H__
+#define __GNA_HW_H__
+
+#include <linux/mm_types.h>
+
+struct gna_dev_info {
+ u32 hwid;
+ u32 num_pagetables;
+ u32 num_page_entries;
+ u32 max_layer_count;
+ u64 max_hw_mem;
+};
+
+#endif // __GNA_HW_H__
diff --git a/drivers/gpu/drm/gna/gna_pci.c b/drivers/gpu/drm/gna/gna_pci.c
index 6bd00c66f3a7..14f8b34e5f5c 100644
--- a/drivers/gpu/drm/gna/gna_pci.c
+++ b/drivers/gpu/drm/gna/gna_pci.c
@@ -5,10 +5,13 @@
#include <linux/pci.h>
#include "gna_device.h"
+#include "gna_hw.h"
#include "gna_pci.h"
int gna_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pci_id)
{
+ struct gna_dev_info *dev_info;
+ void __iomem *iobase;
int err;
err = pcim_enable_device(pcidev);
@@ -19,8 +22,16 @@ int gna_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pci_id)
if (err)
return err;
+ iobase = pcim_iomap_table(pcidev)[0];
+
pci_set_master(pcidev);
+ dev_info = (struct gna_dev_info *)pci_id->driver_data;
+
+ err = gna_probe(&pcidev->dev, dev_info, iobase);
+ if (err)
+ return err;
+
return 0;
}
--
2.25.1
More information about the dri-devel
mailing list