Commit d2a259f2 authored by Alex Elder's avatar Alex Elder Committed by Greg Kroah-Hartman

greybus: allocate space without gbufs

This begins the transition to buffer allocation that does not rely
on the gbuf construct.

The host driver allocation routine will return a pointer to the
buffer to be used, and the caller will be responsible for keeping
track of that pointer, as well as the requested buffer size.

Rename the allocation method to reflect it's no longer tied to a
gbuf.
Signed-off-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 0f4c808a
...@@ -169,7 +169,7 @@ struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver ...@@ -169,7 +169,7 @@ struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver
* Validate that the driver implements all of the callbacks * Validate that the driver implements all of the callbacks
* so that we don't have to every time we make them. * so that we don't have to every time we make them.
*/ */
if ((!driver->alloc_gbuf_data) || if ((!driver->buffer_alloc) ||
(!driver->free_gbuf_data) || (!driver->free_gbuf_data) ||
(!driver->submit_svc) || (!driver->submit_svc) ||
(!driver->submit_gbuf) || (!driver->submit_gbuf) ||
......
...@@ -85,21 +85,12 @@ static inline struct es1_ap_dev *hd_to_es1(struct greybus_host_device *hd) ...@@ -85,21 +85,12 @@ static inline struct es1_ap_dev *hd_to_es1(struct greybus_host_device *hd)
static void cport_out_callback(struct urb *urb); static void cport_out_callback(struct urb *urb);
/* /*
* Allocate the actual buffer for this gbuf and device and cport * Allocate a buffer to be sent via UniPro.
*
* We are responsible for setting the following fields in a struct gbuf:
* void *hcpriv;
* void *transfer_buffer;
* u32 transfer_buffer_length;
*/ */
static int alloc_gbuf_data(struct gbuf *gbuf, unsigned int size, static void *buffer_alloc(unsigned int size, gfp_t gfp_mask)
gfp_t gfp_mask)
{ {
u8 *buffer; u8 *buffer;
if (gbuf->transfer_buffer)
return -EALREADY;
if (size > ES1_GBUF_MSG_SIZE) { if (size > ES1_GBUF_MSG_SIZE) {
pr_err("guf was asked to be bigger than %ld!\n", pr_err("guf was asked to be bigger than %ld!\n",
ES1_GBUF_MSG_SIZE); ES1_GBUF_MSG_SIZE);
...@@ -117,14 +108,10 @@ static int alloc_gbuf_data(struct gbuf *gbuf, unsigned int size, ...@@ -117,14 +108,10 @@ static int alloc_gbuf_data(struct gbuf *gbuf, unsigned int size,
* XXX Do we need to indicate the destination device id too? * XXX Do we need to indicate the destination device id too?
*/ */
buffer = kzalloc(GB_BUFFER_ALIGN + size, gfp_mask); buffer = kzalloc(GB_BUFFER_ALIGN + size, gfp_mask);
if (!buffer) if (buffer)
return -ENOMEM; buffer += GB_BUFFER_ALIGN;
buffer += GB_BUFFER_ALIGN;
gbuf->transfer_buffer = buffer; return buffer;
gbuf->transfer_buffer_length = size;
return 0;
} }
/* Free the memory we allocated with a gbuf */ /* Free the memory we allocated with a gbuf */
...@@ -252,7 +239,7 @@ static void kill_gbuf(struct gbuf *gbuf) ...@@ -252,7 +239,7 @@ static void kill_gbuf(struct gbuf *gbuf)
static struct greybus_host_driver es1_driver = { static struct greybus_host_driver es1_driver = {
.hd_priv_size = sizeof(struct es1_ap_dev), .hd_priv_size = sizeof(struct es1_ap_dev),
.alloc_gbuf_data = alloc_gbuf_data, .buffer_alloc = buffer_alloc,
.free_gbuf_data = free_gbuf_data, .free_gbuf_data = free_gbuf_data,
.submit_svc = submit_svc, .submit_svc = submit_svc,
.submit_gbuf = submit_gbuf, .submit_gbuf = submit_gbuf,
......
...@@ -79,8 +79,7 @@ struct gbuf; ...@@ -79,8 +79,7 @@ struct gbuf;
struct greybus_host_driver { struct greybus_host_driver {
size_t hd_priv_size; size_t hd_priv_size;
int (*alloc_gbuf_data)(struct gbuf *gbuf, unsigned int size, void *(*buffer_alloc)(unsigned int size, gfp_t gfp_mask);
gfp_t gfp_mask);
void (*free_gbuf_data)(struct gbuf *gbuf); void (*free_gbuf_data)(struct gbuf *gbuf);
int (*submit_svc)(struct svc_msg *svc_msg, int (*submit_svc)(struct svc_msg *svc_msg,
struct greybus_host_device *hd); struct greybus_host_device *hd);
......
...@@ -222,7 +222,6 @@ static int gb_operation_message_init(struct gb_operation *operation, ...@@ -222,7 +222,6 @@ static int gb_operation_message_init(struct gb_operation *operation,
struct gbuf *gbuf; struct gbuf *gbuf;
gfp_t gfp_flags = request && !outbound ? GFP_ATOMIC : GFP_KERNEL; gfp_t gfp_flags = request && !outbound ? GFP_ATOMIC : GFP_KERNEL;
u16 dest_cport_id; u16 dest_cport_id;
int ret;
if (size > GB_OPERATION_MESSAGE_SIZE_MAX) if (size > GB_OPERATION_MESSAGE_SIZE_MAX)
return -E2BIG; return -E2BIG;
...@@ -241,9 +240,10 @@ static int gb_operation_message_init(struct gb_operation *operation, ...@@ -241,9 +240,10 @@ static int gb_operation_message_init(struct gb_operation *operation,
else else
dest_cport_id = CPORT_ID_BAD; dest_cport_id = CPORT_ID_BAD;
ret = hd->driver->alloc_gbuf_data(gbuf, size, gfp_flags); gbuf->transfer_buffer = hd->driver->buffer_alloc(size, gfp_flags);
if (ret) if (!gbuf->transfer_buffer)
return ret; return -ENOMEM;
gbuf->transfer_buffer_length = size;
gbuf->hd = hd; gbuf->hd = hd;
gbuf->dest_cport_id = dest_cport_id; gbuf->dest_cport_id = dest_cport_id;
gbuf->status = -EBADR; /* Initial value--means "never set" */ gbuf->status = -EBADR; /* Initial value--means "never set" */
......
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