Skip to content

Commit cb850f6

Browse files
Pranjal Ramajor Asha Kanojiyaquic-jhugo
authored andcommitted
accel/qaic: Remove ->size field from struct qaic_bo
->size field in struct qaic_bo stores user requested buffer size for allocate path or size of the dmabuf(PRIME). Now for allocate path driver allocates a BO of size which is PAGE_SIZE aligned, this size is already stored in base BO structure (struct drm_gem_object). So difference is ->size of struct qaic_bo stores the raw value coming from user and ->size in struct drm_gem_object stores the PAGE_SZIE aligned size. Do not use ->size from struct qaic_bo for any validation or operation instead use ->size from struct drm_gem_object since we already have allocated that much memory then why not use it. Only validate if user is trying to use more then the BO size. This make the driver more flexible. After this change ->size field of struct qaic_bo becomes redundant. Remove it. Signed-off-by: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com> Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com> Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com> Reviewed-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20230901172247.11410-2-quic_jhugo@quicinc.com
1 parent a08e062 commit cb850f6

3 files changed

Lines changed: 9 additions & 15 deletions

File tree

drivers/accel/qaic/qaic.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ struct qaic_bo {
161161
struct drm_gem_object base;
162162
/* Scatter/gather table for allocate/imported BO */
163163
struct sg_table *sgt;
164-
/* BO size requested by user. GEM object might be bigger in size. */
165-
u64 size;
166164
/* Head in list of slices of this BO */
167165
struct list_head slices;
168166
/* Total nents, for all slices of this BO */

drivers/accel/qaic/qaic_data.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ static void qaic_gem_print_info(struct drm_printer *p, unsigned int indent,
579579
{
580580
struct qaic_bo *bo = to_qaic_bo(obj);
581581

582-
drm_printf_indent(p, indent, "user requested size=%llu\n", bo->size);
582+
drm_printf_indent(p, indent, "BO DMA direction %d\n", bo->dir);
583583
}
584584

585585
static const struct vm_operations_struct drm_vm_ops = {
@@ -695,8 +695,6 @@ int qaic_create_bo_ioctl(struct drm_device *dev, void *data, struct drm_file *fi
695695
if (ret)
696696
goto free_bo;
697697

698-
bo->size = args->size;
699-
700698
ret = drm_gem_handle_create(file_priv, obj, &args->handle);
701699
if (ret)
702700
goto free_sgt;
@@ -828,7 +826,6 @@ static int qaic_prepare_import_bo(struct qaic_bo *bo, struct qaic_attach_slice_h
828826
}
829827

830828
bo->sgt = sgt;
831-
bo->size = hdr->size;
832829

833830
return 0;
834831
}
@@ -838,7 +835,7 @@ static int qaic_prepare_export_bo(struct qaic_device *qdev, struct qaic_bo *bo,
838835
{
839836
int ret;
840837

841-
if (bo->size != hdr->size)
838+
if (bo->base.size < hdr->size)
842839
return -EINVAL;
843840

844841
ret = dma_map_sgtable(&qdev->pdev->dev, bo->sgt, hdr->dir, 0);
@@ -868,7 +865,6 @@ static void qaic_unprepare_import_bo(struct qaic_bo *bo)
868865
{
869866
dma_buf_unmap_attachment(bo->base.import_attach, bo->sgt, bo->dir);
870867
bo->sgt = NULL;
871-
bo->size = 0;
872868
}
873869

874870
static void qaic_unprepare_export_bo(struct qaic_device *qdev, struct qaic_bo *bo)
@@ -1190,7 +1186,7 @@ static int send_bo_list_to_device(struct qaic_device *qdev, struct drm_file *fil
11901186
goto failed_to_send_bo;
11911187
}
11921188

1193-
if (is_partial && pexec[i].resize > bo->size) {
1189+
if (is_partial && pexec[i].resize > bo->base.size) {
11941190
ret = -EINVAL;
11951191
goto failed_to_send_bo;
11961192
}

include/uapi/drm/qaic_accel.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ struct qaic_attach_slice_entry {
242242
* @dbc_id: In. Associate the sliced BO with this DBC.
243243
* @handle: In. GEM handle of the BO to slice.
244244
* @dir: In. Direction of data flow. 1 = DMA_TO_DEVICE, 2 = DMA_FROM_DEVICE
245-
* @size: In. Total length of the BO.
246-
* If BO is imported (DMABUF/PRIME) then this size
247-
* should not exceed the size of DMABUF provided.
248-
* If BO is allocated using DRM_IOCTL_QAIC_CREATE_BO
249-
* then this size should be exactly same as the size
250-
* provided during DRM_IOCTL_QAIC_CREATE_BO.
245+
* @size: In. Total length of BO being used. This should not exceed base
246+
* size of BO (struct drm_gem_object.base)
247+
* For BOs being allocated using DRM_IOCTL_QAIC_CREATE_BO, size of
248+
* BO requested is PAGE_SIZE aligned then allocated hence allocated
249+
* BO size maybe bigger. This size should not exceed the new
250+
* PAGE_SIZE aligned BO size.
251251
* @dev_addr: In. Device address this slice pushes to or pulls from.
252252
* @db_addr: In. Address of the doorbell to ring.
253253
* @db_data: In. Data to write to the doorbell.

0 commit comments

Comments
 (0)