Skip to content

Commit

Permalink
mei: bus: add client dma interface
Browse files Browse the repository at this point in the history
Expose the client dma mapping via mei client bus interface.
The client dma has to be mapped before the device is enabled,
therefore we need to create device linking already during mapping
and we need to unmap after the client is disable hence we need to
postpone the unlink and flush till unmapping or when
destroying the device.

Signed-off-by: Alexander Usyskin <[email protected]>
Co-developed-by: Tomas Winkler <[email protected]>
Signed-off-by: Tomas Winkler <[email protected]>
Signed-off-by: Emmanuel Grumbach <[email protected]>
Acked-by: Greg Kroah-Hartman <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Kalle Valo <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
ausyskin authored and Kalle Valo committed Nov 26, 2021
1 parent 84d94e1 commit 2cca346
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
67 changes: 64 additions & 3 deletions drivers/misc/mei/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,64 @@ static void mei_cl_bus_vtag_free(struct mei_cl_device *cldev)
kfree(cl_vtag);
}

void *mei_cldev_dma_map(struct mei_cl_device *cldev, u8 buffer_id, size_t size)
{
struct mei_device *bus;
struct mei_cl *cl;
int ret;

if (!cldev || !buffer_id || !size)
return ERR_PTR(-EINVAL);

if (!IS_ALIGNED(size, MEI_FW_PAGE_SIZE)) {
dev_err(&cldev->dev, "Map size should be aligned to %lu\n",
MEI_FW_PAGE_SIZE);
return ERR_PTR(-EINVAL);
}

cl = cldev->cl;
bus = cldev->bus;

mutex_lock(&bus->device_lock);
if (cl->state == MEI_FILE_UNINITIALIZED) {
ret = mei_cl_link(cl);
if (ret)
goto out;
/* update pointers */
cl->cldev = cldev;
}

ret = mei_cl_dma_alloc_and_map(cl, NULL, buffer_id, size);
out:
mutex_unlock(&bus->device_lock);
if (ret)
return ERR_PTR(ret);
return cl->dma.vaddr;
}
EXPORT_SYMBOL_GPL(mei_cldev_dma_map);

int mei_cldev_dma_unmap(struct mei_cl_device *cldev)
{
struct mei_device *bus;
struct mei_cl *cl;
int ret;

if (!cldev)
return -EINVAL;

cl = cldev->cl;
bus = cldev->bus;

mutex_lock(&bus->device_lock);
ret = mei_cl_dma_unmap(cl, NULL);

mei_cl_flush_queues(cl, NULL);
mei_cl_unlink(cl);
mutex_unlock(&bus->device_lock);
return ret;
}
EXPORT_SYMBOL_GPL(mei_cldev_dma_unmap);

/**
* mei_cldev_enable - enable me client device
* create connection with me client
Expand Down Expand Up @@ -753,9 +811,11 @@ int mei_cldev_disable(struct mei_cl_device *cldev)
dev_err(bus->dev, "Could not disconnect from the ME client\n");

out:
/* Flush queues and remove any pending read */
mei_cl_flush_queues(cl, NULL);
mei_cl_unlink(cl);
/* Flush queues and remove any pending read unless we have mapped DMA */
if (!cl->dma_mapped) {
mei_cl_flush_queues(cl, NULL);
mei_cl_unlink(cl);
}

mutex_unlock(&bus->device_lock);
return err;
Expand Down Expand Up @@ -1052,6 +1112,7 @@ static void mei_cl_bus_dev_release(struct device *dev)
if (!cldev)
return;

mei_cl_flush_queues(cldev->cl, NULL);
mei_me_cl_put(cldev->me_cl);
mei_dev_bus_put(cldev->bus);
mei_cl_unlink(cldev->cl);
Expand Down
3 changes: 3 additions & 0 deletions drivers/misc/mei/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,9 @@ int mei_cl_unlink(struct mei_cl *cl)

cl_dbg(dev, cl, "unlink client");

if (cl->state == MEI_FILE_UNINITIALIZED)
return 0;

if (dev->open_handle_count > 0)
dev->open_handle_count--;

Expand Down
5 changes: 5 additions & 0 deletions drivers/misc/mei/hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#define MEI_D0I3_TIMEOUT 5 /* D0i3 set/unset max response time */
#define MEI_HBM_TIMEOUT 1 /* 1 second */

/*
* FW page size for DMA allocations
*/
#define MEI_FW_PAGE_SIZE 4096UL

/*
* MEI Version
*/
Expand Down
3 changes: 3 additions & 0 deletions include/linux/mei_cl_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@ int mei_cldev_enable(struct mei_cl_device *cldev);
int mei_cldev_disable(struct mei_cl_device *cldev);
bool mei_cldev_enabled(const struct mei_cl_device *cldev);

void *mei_cldev_dma_map(struct mei_cl_device *cldev, u8 buffer_id, size_t size);
int mei_cldev_dma_unmap(struct mei_cl_device *cldev);

#endif /* _LINUX_MEI_CL_BUS_H */

0 comments on commit 2cca346

Please sign in to comment.