mirror of https://github.com/torvalds/linux.git
accel/qaic: Add DMA Bridge Channel(DBC) sysfs and uevents
Expose sysfs files for each DBC representing the current state of that DBC. For example, sysfs for DBC ID 0 and accel minor number 0 looks like this, /sys/class/accel/accel0/dbc0_state Following are the states and their corresponding values, DBC_STATE_IDLE (0) DBC_STATE_ASSIGNED (1) DBC_STATE_BEFORE_SHUTDOWN (2) DBC_STATE_AFTER_SHUTDOWN (3) DBC_STATE_BEFORE_POWER_UP (4) DBC_STATE_AFTER_POWER_UP (5) Signed-off-by: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com> Signed-off-by: Youssef Samir <youssef.abdulrahman@oss.qualcomm.com> Signed-off-by: Zack McKevitt <zachary.mckevitt@oss.qualcomm.com> Reviewed-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com> Signed-off-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com> Link: https://patch.msgid.link/20251031174059.2814445-2-zachary.mckevitt@oss.qualcomm.com
This commit is contained in:
parent
1750e652a9
commit
f286066ed9
|
|
@ -0,0 +1,16 @@
|
|||
What: /sys/bus/pci/drivers/qaic/XXXX:XX:XX.X/accel/accel<minor_nr>/dbc<N>_state
|
||||
Date: October 2025
|
||||
KernelVersion: 6.19
|
||||
Contact: Jeff Hugo <jeff.hugo@oss.qualcomm.com>
|
||||
Description: Represents the current state of DMA Bridge channel (DBC). Below are the possible
|
||||
states,
|
||||
IDLE (0) - DBC is free and can be activated
|
||||
ASSIGNED (1) - DBC is activated and a workload is running on device
|
||||
BEFORE_SHUTDOWN (2) - Sub-system associated with this workload has crashed and
|
||||
it will shutdown soon
|
||||
AFTER_SHUTDOWN (3) - Sub-system associated with this workload has crashed and
|
||||
it has shutdown
|
||||
BEFORE_POWER_UP (4) - Sub-system associated with this workload is shutdown and
|
||||
it will be powered up soon
|
||||
AFTER_POWER_UP (5) - Sub-system associated with this workload is now powered up
|
||||
Users: Any userspace application or clients interested in DBC state.
|
||||
|
|
@ -11,6 +11,7 @@ qaic-y := \
|
|||
qaic_data.o \
|
||||
qaic_drv.o \
|
||||
qaic_ras.o \
|
||||
qaic_sysfs.o \
|
||||
qaic_timesync.o \
|
||||
sahara.o
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,22 @@ enum __packed dev_states {
|
|||
QAIC_ONLINE,
|
||||
};
|
||||
|
||||
enum dbc_states {
|
||||
/* DBC is free and can be activated */
|
||||
DBC_STATE_IDLE,
|
||||
/* DBC is activated and a workload is running on device */
|
||||
DBC_STATE_ASSIGNED,
|
||||
/* Sub-system associated with this workload has crashed and it will shutdown soon */
|
||||
DBC_STATE_BEFORE_SHUTDOWN,
|
||||
/* Sub-system associated with this workload has crashed and it has shutdown */
|
||||
DBC_STATE_AFTER_SHUTDOWN,
|
||||
/* Sub-system associated with this workload is shutdown and it will be powered up soon */
|
||||
DBC_STATE_BEFORE_POWER_UP,
|
||||
/* Sub-system associated with this workload is now powered up */
|
||||
DBC_STATE_AFTER_POWER_UP,
|
||||
DBC_STATE_MAX,
|
||||
};
|
||||
|
||||
extern bool datapath_polling;
|
||||
|
||||
struct qaic_user {
|
||||
|
|
@ -114,6 +130,8 @@ struct dma_bridge_chan {
|
|||
unsigned int irq;
|
||||
/* Polling work item to simulate interrupts */
|
||||
struct work_struct poll_work;
|
||||
/* Represents various states of this DBC from enum dbc_states */
|
||||
unsigned int state;
|
||||
};
|
||||
|
||||
struct qaic_device {
|
||||
|
|
@ -197,6 +215,8 @@ struct qaic_drm_device {
|
|||
struct list_head users;
|
||||
/* Synchronizes access to users list */
|
||||
struct mutex users_mutex;
|
||||
/* Pointer to array of DBC sysfs attributes */
|
||||
void *sysfs_attrs;
|
||||
};
|
||||
|
||||
struct qaic_bo {
|
||||
|
|
@ -321,4 +341,9 @@ int qaic_perf_stats_bo_ioctl(struct drm_device *dev, void *data, struct drm_file
|
|||
int qaic_detach_slice_bo_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);
|
||||
void irq_polling_work(struct work_struct *work);
|
||||
|
||||
/* qaic_sysfs.c */
|
||||
int qaic_sysfs_init(struct qaic_drm_device *qddev);
|
||||
void qaic_sysfs_remove(struct qaic_drm_device *qddev);
|
||||
void set_dbc_state(struct qaic_device *qdev, u32 dbc_id, unsigned int state);
|
||||
|
||||
#endif /* _QAIC_H_ */
|
||||
|
|
|
|||
|
|
@ -310,6 +310,7 @@ static void save_dbc_buf(struct qaic_device *qdev, struct ioctl_resources *resou
|
|||
enable_dbc(qdev, dbc_id, usr);
|
||||
qdev->dbc[dbc_id].in_use = true;
|
||||
resources->buf = NULL;
|
||||
set_dbc_state(qdev, dbc_id, DBC_STATE_ASSIGNED);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -923,6 +924,7 @@ static int decode_deactivate(struct qaic_device *qdev, void *trans, u32 *msg_len
|
|||
}
|
||||
|
||||
release_dbc(qdev, dbc_id);
|
||||
set_dbc_state(qdev, dbc_id, DBC_STATE_IDLE);
|
||||
*msg_len += sizeof(*in_trans);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -270,6 +270,13 @@ static int qaic_create_drm_device(struct qaic_device *qdev, s32 partition_id)
|
|||
return ret;
|
||||
}
|
||||
|
||||
ret = qaic_sysfs_init(qddev);
|
||||
if (ret) {
|
||||
drm_dev_unregister(drm);
|
||||
pci_dbg(qdev->pdev, "qaic_sysfs_init failed %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
qaic_debugfs_init(qddev);
|
||||
|
||||
return ret;
|
||||
|
|
@ -281,6 +288,7 @@ static void qaic_destroy_drm_device(struct qaic_device *qdev, s32 partition_id)
|
|||
struct drm_device *drm = to_drm(qddev);
|
||||
struct qaic_user *usr;
|
||||
|
||||
qaic_sysfs_remove(qddev);
|
||||
drm_dev_unregister(drm);
|
||||
qddev->partition_id = 0;
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,109 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
/* Copyright (c) 2020-2025, The Linux Foundation. All rights reserved. */
|
||||
|
||||
#include <drm/drm_file.h>
|
||||
#include <drm/drm_managed.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/kobject.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/sysfs.h>
|
||||
|
||||
#include "qaic.h"
|
||||
|
||||
#define NAME_LEN 14
|
||||
|
||||
struct dbc_attribute {
|
||||
struct device_attribute dev_attr;
|
||||
u32 dbc_id;
|
||||
char name[NAME_LEN];
|
||||
};
|
||||
|
||||
static ssize_t dbc_state_show(struct device *dev, struct device_attribute *a, char *buf)
|
||||
{
|
||||
struct dbc_attribute *dbc_attr = container_of(a, struct dbc_attribute, dev_attr);
|
||||
struct drm_minor *minor = dev_get_drvdata(dev);
|
||||
struct qaic_device *qdev;
|
||||
|
||||
qdev = to_qaic_device(minor->dev);
|
||||
return sysfs_emit(buf, "%d\n", qdev->dbc[dbc_attr->dbc_id].state);
|
||||
}
|
||||
|
||||
void set_dbc_state(struct qaic_device *qdev, u32 dbc_id, unsigned int state)
|
||||
{
|
||||
struct device *kdev = to_accel_kdev(qdev->qddev);
|
||||
char *envp[3] = {};
|
||||
char state_str[16];
|
||||
char id_str[12];
|
||||
|
||||
envp[0] = id_str;
|
||||
envp[1] = state_str;
|
||||
|
||||
if (state >= DBC_STATE_MAX)
|
||||
return;
|
||||
if (dbc_id >= qdev->num_dbc)
|
||||
return;
|
||||
if (state == qdev->dbc[dbc_id].state)
|
||||
return;
|
||||
|
||||
scnprintf(id_str, ARRAY_SIZE(id_str), "DBC_ID=%d", dbc_id);
|
||||
scnprintf(state_str, ARRAY_SIZE(state_str), "DBC_STATE=%d", state);
|
||||
|
||||
qdev->dbc[dbc_id].state = state;
|
||||
kobject_uevent_env(&kdev->kobj, KOBJ_CHANGE, envp);
|
||||
}
|
||||
|
||||
int qaic_sysfs_init(struct qaic_drm_device *qddev)
|
||||
{
|
||||
struct device *kdev = to_accel_kdev(qddev);
|
||||
struct drm_device *drm = to_drm(qddev);
|
||||
u32 num_dbc = qddev->qdev->num_dbc;
|
||||
struct dbc_attribute *dbc_attrs;
|
||||
int i, ret;
|
||||
|
||||
dbc_attrs = drmm_kcalloc(drm, num_dbc, sizeof(*dbc_attrs), GFP_KERNEL);
|
||||
if (!dbc_attrs)
|
||||
return -ENOMEM;
|
||||
|
||||
for (i = 0; i < num_dbc; ++i) {
|
||||
struct dbc_attribute *dbc_attr = &dbc_attrs[i];
|
||||
|
||||
sysfs_attr_init(&dbc_attr->dev_attr.attr);
|
||||
dbc_attr->dbc_id = i;
|
||||
scnprintf(dbc_attr->name, NAME_LEN, "dbc%d_state", i);
|
||||
dbc_attr->dev_attr.attr.name = dbc_attr->name;
|
||||
dbc_attr->dev_attr.attr.mode = 0444;
|
||||
dbc_attr->dev_attr.show = dbc_state_show;
|
||||
ret = sysfs_create_file(&kdev->kobj, &dbc_attr->dev_attr.attr);
|
||||
if (ret) {
|
||||
int j;
|
||||
|
||||
for (j = 0; j < i; ++j) {
|
||||
dbc_attr = &dbc_attrs[j];
|
||||
sysfs_remove_file(&kdev->kobj, &dbc_attr->dev_attr.attr);
|
||||
}
|
||||
drmm_kfree(drm, dbc_attrs);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
qddev->sysfs_attrs = dbc_attrs;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void qaic_sysfs_remove(struct qaic_drm_device *qddev)
|
||||
{
|
||||
struct dbc_attribute *dbc_attrs = qddev->sysfs_attrs;
|
||||
struct device *kdev = to_accel_kdev(qddev);
|
||||
u32 num_dbc = qddev->qdev->num_dbc;
|
||||
int i;
|
||||
|
||||
if (!dbc_attrs)
|
||||
return;
|
||||
|
||||
qddev->sysfs_attrs = NULL;
|
||||
for (i = 0; i < num_dbc; ++i)
|
||||
sysfs_remove_file(&kdev->kobj, &dbc_attrs[i].dev_attr.attr);
|
||||
drmm_kfree(to_drm(qddev), dbc_attrs);
|
||||
}
|
||||
Loading…
Reference in New Issue