/* * Sends a request to the firmware through the BCM2835 mailbox driver, * and synchronously waits for the reply.
*/ staticint
rpi_firmware_transaction(struct rpi_firmware *fw, u32 chan, u32 data)
{
u32 message = MBOX_MSG(chan, data); int ret;
WARN_ON(data & 0xf);
mutex_lock(&transaction_lock);
reinit_completion(&fw->c);
ret = mbox_send_message(fw->chan, &message); if (ret >= 0) { if (wait_for_completion_timeout(&fw->c, HZ)) {
ret = 0;
} else {
ret = -ETIMEDOUT;
}
} else {
dev_err(fw->cl.dev, "mbox_send_message returned %d\n", ret);
}
mutex_unlock(&transaction_lock);
return ret;
}
/** * rpi_firmware_property_list - Submit firmware property list * @fw: Pointer to firmware structure from rpi_firmware_get(). * @data: Buffer holding tags. * @tag_size: Size of tags buffer. * * Submits a set of concatenated tags to the VPU firmware through the * mailbox property interface. * * The buffer header and the ending tag are added by this function and * don't need to be supplied, just the actual tags for your operation. * See struct rpi_firmware_property_tag_header for the per-tag * structure.
*/ int rpi_firmware_property_list(struct rpi_firmware *fw, void *data, size_t tag_size)
{
size_t size = tag_size + 12;
u32 *buf;
dma_addr_t bus_addr; int ret;
/* Packets are processed a dword at a time. */ if (size & 3) return -EINVAL;
buf = dma_alloc_coherent(fw->chan->mbox->dev, PAGE_ALIGN(size),
&bus_addr, GFP_ATOMIC); if (!buf) return -ENOMEM;
/* The firmware will error out without parsing in this case. */
WARN_ON(size >= 1024 * 1024);
ret = rpi_firmware_transaction(fw, MBOX_CHAN_PROPERTY, bus_addr);
rmb();
memcpy(data, &buf[2], tag_size); if (ret == 0 && buf[1] != RPI_FIRMWARE_STATUS_SUCCESS) { /* * The tag name here might not be the one causing the * error, if there were multiple tags in the request. * But single-tag is the most common, so go with it.
*/
dev_err(fw->cl.dev, "Request 0x%08x returned status 0x%08x\n",
buf[2], buf[1]);
ret = -EINVAL;
} elseif (ret == -ETIMEDOUT) {
WARN_ONCE(1, "Firmware transaction 0x%08x timeout", buf[2]);
}
/** * rpi_firmware_property - Submit single firmware property * @fw: Pointer to firmware structure from rpi_firmware_get(). * @tag: One of enum_mbox_property_tag. * @tag_data: Tag data buffer. * @buf_size: Buffer size. * * Submits a single tag to the VPU firmware through the mailbox * property interface. * * This is a convenience wrapper around * rpi_firmware_property_list() to avoid some of the * boilerplate in property calls.
*/ int rpi_firmware_property(struct rpi_firmware *fw,
u32 tag, void *tag_data, size_t buf_size)
{ struct rpi_firmware_property_tag_header *header; int ret;
/* Some mailboxes can use over 1k bytes. Rather than checking * size and using stack or kmalloc depending on requirements, * just use kmalloc. Mailboxes don't get called enough to worry * too much about the time taken in the allocation.
*/ void *data = kmalloc(sizeof(*header) + buf_size, GFP_KERNEL);
/* * Earlier DTs don't have a node for the firmware clocks but * rely on us creating a platform device by hand. If we do * have a node for the firmware clocks, just bail out here.
*/
firmware = of_get_compatible_child(dev->of_node, "raspberrypi,firmware-clocks"); if (firmware) {
of_node_put(firmware); return;
}
ret = rpi_firmware_property(fw, RPI_FIRMWARE_GET_MAX_CLOCK_RATE,
&msg, sizeof(msg)); if (ret) /* * If our firmware doesn't support that operation, or fails, we * assume the maximum clock rate is absolute maximum we can * store over our type.
*/ return UINT_MAX;
/* * Memory will be freed by rpi_firmware_delete() once all users have * released their firmware handles. Don't use devm_kzalloc() here.
*/
fw = kzalloc(sizeof(*fw), GFP_KERNEL); if (!fw) return -ENOMEM;
fw->chan = mbox_request_channel(&fw->cl, 0); if (IS_ERR(fw->chan)) { int ret = PTR_ERR(fw->chan);
kfree(fw); return dev_err_probe(dev, ret, "Failed to get mbox channel\n");
}
/** * rpi_firmware_get - Get pointer to rpi_firmware structure. * @firmware_node: Pointer to the firmware Device Tree node. * * The reference to rpi_firmware has to be released with rpi_firmware_put(). * * Returns NULL is the firmware device is not ready.
*/ struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node)
{ struct platform_device *pdev = of_find_device_by_node(firmware_node); struct rpi_firmware *fw;
if (!pdev) return NULL;
fw = platform_get_drvdata(pdev); if (!fw) goto err_put_device;
if (!kref_get_unless_zero(&fw->consumers)) goto err_put_device;
/** * devm_rpi_firmware_get - Get pointer to rpi_firmware structure. * @dev: The firmware device structure * @firmware_node: Pointer to the firmware Device Tree node. * * Returns NULL is the firmware device is not ready.
*/ struct rpi_firmware *devm_rpi_firmware_get(struct device *dev, struct device_node *firmware_node)
{ struct rpi_firmware *fw;
fw = rpi_firmware_get(firmware_node); if (!fw) return NULL;
if (devm_add_action_or_reset(dev, devm_rpi_firmware_put, fw)) return NULL;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.