Commit ea097ffa authored by Pranjal Ramajor Asha Kanojiya's avatar Pranjal Ramajor Asha Kanojiya Committed by Jeffrey Hugo

accel/qaic: Use devm_drm_dev_alloc() instead of drm_dev_alloc()

Since drm_dev_alloc() is deprecated it is recommended to use
devm_drm_dev_alloc() instead. Update the driver to start using
devm_drm_dev_alloc().
Signed-off-by: default avatarPranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
Reviewed-by: default avatarCarl Vanderlip <quic_carlv@quicinc.com>
Reviewed-by: default avatarJeffrey Hugo <quic_jhugo@quicinc.com>
Signed-off-by: default avatarJeffrey Hugo <quic_jhugo@quicinc.com>
Reviewed-by: default avatarStanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230901161236.8371-1-quic_jhugo@quicinc.com
parent 1006d674
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
#define QAIC_DBC_OFF(i) ((i) * QAIC_DBC_SIZE + QAIC_DBC_BASE) #define QAIC_DBC_OFF(i) ((i) * QAIC_DBC_SIZE + QAIC_DBC_BASE)
#define to_qaic_bo(obj) container_of(obj, struct qaic_bo, base) #define to_qaic_bo(obj) container_of(obj, struct qaic_bo, base)
#define to_qaic_drm_device(dev) container_of(dev, struct qaic_drm_device, drm)
#define to_drm(qddev) (&(qddev)->drm)
#define to_accel_kdev(qddev) (to_drm(qddev)->accel->kdev) /* Return Linux device of accel node */
extern bool datapath_polling; extern bool datapath_polling;
...@@ -137,6 +140,8 @@ struct qaic_device { ...@@ -137,6 +140,8 @@ struct qaic_device {
}; };
struct qaic_drm_device { struct qaic_drm_device {
/* The drm device struct of this drm device */
struct drm_device drm;
/* Pointer to the root device struct driven by this driver */ /* Pointer to the root device struct driven by this driver */
struct qaic_device *qdev; struct qaic_device *qdev;
/* /*
...@@ -146,8 +151,6 @@ struct qaic_drm_device { ...@@ -146,8 +151,6 @@ struct qaic_drm_device {
* device is the actual physical device * device is the actual physical device
*/ */
s32 partition_id; s32 partition_id;
/* Pointer to the drm device struct of this drm device */
struct drm_device *ddev;
/* Head in list of users who have opened this drm device */ /* Head in list of users who have opened this drm device */
struct list_head users; struct list_head users;
/* Synchronizes access to users list */ /* Synchronizes access to users list */
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <drm/drm_file.h> #include <drm/drm_file.h>
#include <drm/drm_gem.h> #include <drm/drm_gem.h>
#include <drm/drm_ioctl.h> #include <drm/drm_ioctl.h>
#include <drm/drm_managed.h>
#include <uapi/drm/qaic_accel.h> #include <uapi/drm/qaic_accel.h>
#include "mhi_controller.h" #include "mhi_controller.h"
...@@ -55,7 +56,7 @@ static void free_usr(struct kref *kref) ...@@ -55,7 +56,7 @@ static void free_usr(struct kref *kref)
static int qaic_open(struct drm_device *dev, struct drm_file *file) static int qaic_open(struct drm_device *dev, struct drm_file *file)
{ {
struct qaic_drm_device *qddev = dev->dev_private; struct qaic_drm_device *qddev = to_qaic_drm_device(dev);
struct qaic_device *qdev = qddev->qdev; struct qaic_device *qdev = qddev->qdev;
struct qaic_user *usr; struct qaic_user *usr;
int rcu_id; int rcu_id;
...@@ -170,64 +171,39 @@ static const struct drm_driver qaic_accel_driver = { ...@@ -170,64 +171,39 @@ static const struct drm_driver qaic_accel_driver = {
static int qaic_create_drm_device(struct qaic_device *qdev, s32 partition_id) static int qaic_create_drm_device(struct qaic_device *qdev, s32 partition_id)
{ {
struct qaic_drm_device *qddev; struct qaic_drm_device *qddev = qdev->qddev;
struct drm_device *ddev; struct drm_device *drm = to_drm(qddev);
struct device *pdev;
int ret; int ret;
/* Hold off implementing partitions until the uapi is determined */ /* Hold off implementing partitions until the uapi is determined */
if (partition_id != QAIC_NO_PARTITION) if (partition_id != QAIC_NO_PARTITION)
return -EINVAL; return -EINVAL;
pdev = &qdev->pdev->dev;
qddev = kzalloc(sizeof(*qddev), GFP_KERNEL);
if (!qddev)
return -ENOMEM;
ddev = drm_dev_alloc(&qaic_accel_driver, pdev);
if (IS_ERR(ddev)) {
ret = PTR_ERR(ddev);
goto ddev_fail;
}
ddev->dev_private = qddev;
qddev->ddev = ddev;
qddev->qdev = qdev;
qddev->partition_id = partition_id; qddev->partition_id = partition_id;
INIT_LIST_HEAD(&qddev->users);
mutex_init(&qddev->users_mutex);
qdev->qddev = qddev;
ret = drm_dev_register(ddev, 0);
if (ret) {
pci_dbg(qdev->pdev, "%s: drm_dev_register failed %d\n", __func__, ret);
goto drm_reg_fail;
}
return 0; /*
* drm_dev_unregister() sets the driver data to NULL and
* drm_dev_register() does not update the driver data. During a SOC
* reset drm dev is unregistered and registered again leaving the
* driver data to NULL.
*/
dev_set_drvdata(to_accel_kdev(qddev), drm->accel);
ret = drm_dev_register(drm, 0);
if (ret)
pci_dbg(qdev->pdev, "drm_dev_register failed %d\n", ret);
drm_reg_fail:
mutex_destroy(&qddev->users_mutex);
qdev->qddev = NULL;
drm_dev_put(ddev);
ddev_fail:
kfree(qddev);
return ret; return ret;
} }
static void qaic_destroy_drm_device(struct qaic_device *qdev, s32 partition_id) static void qaic_destroy_drm_device(struct qaic_device *qdev, s32 partition_id)
{ {
struct qaic_drm_device *qddev; struct qaic_drm_device *qddev = qdev->qddev;
struct drm_device *drm = to_drm(qddev);
struct qaic_user *usr; struct qaic_user *usr;
qddev = qdev->qddev; drm_dev_get(drm);
qdev->qddev = NULL; drm_dev_unregister(drm);
if (!qddev) qddev->partition_id = 0;
return;
/* /*
* Existing users get unresolvable errors till they close FDs. * Existing users get unresolvable errors till they close FDs.
* Need to sync carefully with users calling close(). The * Need to sync carefully with users calling close(). The
...@@ -254,13 +230,7 @@ static void qaic_destroy_drm_device(struct qaic_device *qdev, s32 partition_id) ...@@ -254,13 +230,7 @@ static void qaic_destroy_drm_device(struct qaic_device *qdev, s32 partition_id)
mutex_lock(&qddev->users_mutex); mutex_lock(&qddev->users_mutex);
} }
mutex_unlock(&qddev->users_mutex); mutex_unlock(&qddev->users_mutex);
drm_dev_put(drm);
if (qddev->ddev) {
drm_dev_unregister(qddev->ddev);
drm_dev_put(qddev->ddev);
}
kfree(qddev);
} }
static int qaic_mhi_probe(struct mhi_device *mhi_dev, const struct mhi_device_id *id) static int qaic_mhi_probe(struct mhi_device *mhi_dev, const struct mhi_device_id *id)
...@@ -344,8 +314,20 @@ void qaic_dev_reset_clean_local_state(struct qaic_device *qdev, bool exit_reset) ...@@ -344,8 +314,20 @@ void qaic_dev_reset_clean_local_state(struct qaic_device *qdev, bool exit_reset)
qdev->in_reset = false; qdev->in_reset = false;
} }
static void cleanup_qdev(struct qaic_device *qdev)
{
int i;
for (i = 0; i < qdev->num_dbc; ++i)
cleanup_srcu_struct(&qdev->dbc[i].ch_lock);
cleanup_srcu_struct(&qdev->dev_lock);
pci_set_drvdata(qdev->pdev, NULL);
destroy_workqueue(qdev->cntl_wq);
}
static struct qaic_device *create_qdev(struct pci_dev *pdev, const struct pci_device_id *id) static struct qaic_device *create_qdev(struct pci_dev *pdev, const struct pci_device_id *id)
{ {
struct qaic_drm_device *qddev;
struct qaic_device *qdev; struct qaic_device *qdev;
int i; int i;
...@@ -381,18 +363,18 @@ static struct qaic_device *create_qdev(struct pci_dev *pdev, const struct pci_de ...@@ -381,18 +363,18 @@ static struct qaic_device *create_qdev(struct pci_dev *pdev, const struct pci_de
INIT_LIST_HEAD(&qdev->dbc[i].bo_lists); INIT_LIST_HEAD(&qdev->dbc[i].bo_lists);
} }
return qdev; qddev = devm_drm_dev_alloc(&pdev->dev, &qaic_accel_driver, struct qaic_drm_device, drm);
} if (IS_ERR(qddev)) {
cleanup_qdev(qdev);
return NULL;
}
static void cleanup_qdev(struct qaic_device *qdev) drmm_mutex_init(to_drm(qddev), &qddev->users_mutex);
{ INIT_LIST_HEAD(&qddev->users);
int i; qddev->qdev = qdev;
qdev->qddev = qddev;
for (i = 0; i < qdev->num_dbc; ++i) return qdev;
cleanup_srcu_struct(&qdev->dbc[i].ch_lock);
cleanup_srcu_struct(&qdev->dev_lock);
pci_set_drvdata(qdev->pdev, NULL);
destroy_workqueue(qdev->cntl_wq);
} }
static int init_pci(struct qaic_device *qdev, struct pci_dev *pdev) static int init_pci(struct qaic_device *qdev, struct pci_dev *pdev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment