Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mailbox: Add ability for clients to request channels by name

This patch supplies a new framework API; mbox_request_channel_byname().

It works by supplying the usual client pointer as the first argument and
a string as the second. The API will search the client's node for a
'mbox-names' property then request a channel in the normal way using the
requested string's index as the expected second 'index' argument.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>

authored by

Lee Jones and committed by
Jassi Brar
dfabde20 0bae6af6

+31
+29
drivers/mailbox/mailbox.c
··· 362 362 } 363 363 EXPORT_SYMBOL_GPL(mbox_request_channel); 364 364 365 + struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl, 366 + const char *name) 367 + { 368 + struct device_node *np = cl->dev->of_node; 369 + struct property *prop; 370 + const char *mbox_name; 371 + int index = 0; 372 + 373 + if (!np) { 374 + dev_err(cl->dev, "%s() currently only supports DT\n", __func__); 375 + return ERR_PTR(-ENOSYS); 376 + } 377 + 378 + if (!of_get_property(np, "mbox-names", NULL)) { 379 + dev_err(cl->dev, 380 + "%s() requires an \"mbox-names\" property\n", __func__); 381 + return ERR_PTR(-ENOSYS); 382 + } 383 + 384 + of_property_for_each_string(np, "mbox-names", prop, mbox_name) { 385 + if (!strncmp(name, mbox_name, strlen(name))) 386 + break; 387 + index++; 388 + } 389 + 390 + return mbox_request_channel(cl, index); 391 + } 392 + EXPORT_SYMBOL_GPL(mbox_request_channel_byname); 393 + 365 394 /** 366 395 * mbox_free_channel - The client relinquishes control of a mailbox 367 396 * channel by this call.
+2
include/linux/mailbox_client.h
··· 40 40 void (*tx_done)(struct mbox_client *cl, void *mssg, int r); 41 41 }; 42 42 43 + struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl, 44 + const char *name); 43 45 struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index); 44 46 int mbox_send_message(struct mbox_chan *chan, void *mssg); 45 47 void mbox_client_txdone(struct mbox_chan *chan, int r); /* atomic */