firmware: ti_sci: Introduce RM support
cover firmware: ti_sci: Introduce RM support
This series adds support for:
- Resource management(RM) core apis to get the range of resources assigned to a device.
- RM IRQ management apis to configure/release the irq route between requested source and destination.
More information on RM APIs can be found here[1].
Based on tag: next-20181005
Boot Log: https://pastebin.ubuntu.com/p/FCvgrRMXtM/
[1] http://downloads.ti.com/tisci/esd/latest/
Grygorii Strashko (1):
firmware: ti_sci: Add support to get TISCI handle using of_phandle
Lokesh Vutla (3):
firmware: ti_sci: Add support for RM core ops
firmware: ti_sci: Add support for IRQ management
firmware: ti_sci: Add helper apis to mange resources
drivers/firmware/ti_sci.c | 759 +++++++++++++++++++++++++ drivers/firmware/ti_sci.h | 102 ++++ include/linux/soc/ti/ti_sci_protocol.h | 168 ++++++ 3 files changed, 1029 insertions(+)
Signature · 1 line
2.19.0
PATCH 1/4 firmware: ti_sci: Add support to get TISCI handle using of_phandle
From: Grygorii Strashko <[email protected]>
TISCI has been updated to have support for Resource management(likes interrupts etc..). And there can be multiple device instances of a resource type in a SoC. So every driver corresponding to a resource type should get a TISCI handle so that it can make TISCI calls. And each DT node corresponding to a device should exist under its corresponding bus node as per the SoC architecture.
But existing apis in TISCI library assumes that all TISCI users are child nodes of TISCI. Which is not true in the above case. So introduce (devm_)ti_sci_get_by_phandle() apis that can be used by TISCI users to get TISCI handle using of phandle property.
--- drivers/firmware/ti_sci.c | 83 ++++++++++++++++++++++++++ include/linux/soc/ti/ti_sci_protocol.h | 17 ++++++ 2 files changed, 100 insertions(+)
drivers/firmware/ti_sci.c +83 -0
@@ -1781,6 +1781,89 @@ const struct ti_sci_handle *devm_ti_sci_get_handle(struct device *dev) }EXPORT_SYMBOL_GPL (devm_ti_sci_get_handle); +/** +* ti_sci_get_by_phandle() - Get the TI SCI handle using DT phandle +* @np: device node +* @propname: property name containing phandle on TISCI node +* +* NOTE: The function does not track individual clients of the framework +* and is expected to be maintained by caller of TI SCI protocol library. +* ti_sci_put_handle must be balanced with successful ti_sci_get_by_phandle +* Return: pointer to handle if successful, else: +* -EPROBE_DEFER if the instance is not ready +* -ENODEV if the required node handler is missing +* -EINVAL if invalid conditions are encountered. +*/ +const struct ti_sci_handle *ti_sci_get_by_phandle (struct device_node *np, +const char *property) +{ +struct ti_sci_handle *handle =NULL ; +struct device_node *ti_sci_np; +struct ti_sci_info *info; +struct list_head *p; + +if (!np) { +pr_err ("I need a device pointer\n" ); +return ERR_PTR (-EINVAL ); + } + + ti_sci_np =of_parse_phandle (np, property,0 ); +if (!ti_sci_np) +return ERR_PTR (-ENODEV ); + +mutex_lock (&ti_sci_list_mutex); +list_for_each (p, &ti_sci_list) { + info = list_entry(p, struct ti_sci_info, node); +if (ti_sci_np == info->dev->of_node) { + handle = &info->handle; + info->users++; +break ; + } + } +mutex_unlock (&ti_sci_list_mutex); +of_node_put (ti_sci_np); + +if (!handle) +return ERR_PTR (-EPROBE_DEFER ); + +return handle; +} +EXPORT_SYMBOL_GPL (ti_sci_get_by_phandle); + +/** +* devm_ti_sci_get_by_phandle() - Managed get handle using phandle +* @dev: Device pointer requesting TISCI handle +* @propname: property name containing phandle on TISCI node +* +* NOTE: This releases the handle once the device resources are +* no longer needed. MUST NOT BE released with ti_sci_put_handle. +* The function does not track individual clients of the framework +* and is expected to be maintained by caller of TI SCI protocol library. +* +* Return: 0 if all went fine, else corresponding error. +*/ +const struct ti_sci_handle *devm_ti_sci_get_by_phandle (struct device *dev, +const char *property) +{ +const struct ti_sci_handle *handle; +const struct ti_sci_handle **ptr; + + ptr =devres_alloc (devm_ti_sci_release,sizeof (*ptr),GFP_KERNEL ); +if (!ptr) +return ERR_PTR (-ENOMEM ); + handle =ti_sci_get_by_phandle (dev_of_node (dev), property); + +if (!IS_ERR (handle)) { + *ptr = handle; +devres_add (dev, ptr); + }else { +devres_free (ptr); + } + +return handle; +} +EXPORT_SYMBOL_GPL (devm_ti_sci_get_by_phandle); +static int tisci_reboot_handler (struct notifier_block *nb,unsigned long mode,void *cmd) {
include/linux/soc/ti/ti_sci_protocol.h +17 -0
@@ -217,6 +217,10 @@ struct ti_sci_handle {const struct ti_sci_handle *ti_sci_get_handle (struct device *dev);int ti_sci_put_handle (const struct ti_sci_handle *handle);const struct ti_sci_handle *devm_ti_sci_get_handle (struct device *dev); +const struct ti_sci_handle *ti_sci_get_by_phandle (struct device_node *np, +const char *property); +const struct ti_sci_handle *devm_ti_sci_get_by_phandle (struct device *dev, +const char *property);#else /* CONFIG_TI_SCI_PROTOCOL */
@@ -236,6 +240,19 @@ const struct ti_sci_handle *devm_ti_sci_get_handle(struct device *dev)return ERR_PTR (-EINVAL ); } +static inline +const struct ti_sci_handle *ti_sci_get_by_phandle (struct device_node *np, +const char *property) +{ +return ERR_PTR (-EINVAL ); +} + +static inline +const struct ti_sci_handle *devm_ti_sci_get_by_phandle (struct device *dev, +const char *property) +{ +return ERR_PTR (-EINVAL ); +}#endif /* CONFIG_TI_SCI_PROTOCOL */ #endif /* __TISCI_PROTOCOL_H */
Signature · 1 line
2.19.0
PATCH 2/4 firmware: ti_sci: Add support for RM core ops
In reply to Lokesh VutlaTISCI provides support for getting the resources(IRQ, RING etc..) assigned to a specific device. These resources can be handled by the client and in turn sends TISCI cmd to configure the resources.
It is very important that client should keep track on usage of these resources.
Add support for TISCI commands to get resource ranges.
--- drivers/firmware/ti_sci.c | 114 +++++++++++++++++++++++++ drivers/firmware/ti_sci.h | 42 +++++++++ include/linux/soc/ti/ti_sci_protocol.h | 26 ++++++ 3 files changed, 182 insertions(+)
drivers/firmware/ti_sci.c +114 -0
@@ -1617,6 +1617,115 @@ static int ti_sci_cmd_core_reboot(const struct ti_sci_handle *handle)return ret; } +/** +* ti_sci_get_resource_range - Helper to get a range of resources assigned +* to a host. Resource is uniquely identified by +* type and subtype. +* @handle: Pointer to TISCI handle. +* @type: Resource assignment type that is being requested for +* @subtype: Resource assignment subtype that is being requested for +* @s_host: Host processor ID to which the resources are allocated +* @range_start: Start index of the resource range +* @range_num: Number of resources in the range +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_get_resource_range (const struct ti_sci_handle *handle, +u16 type,u8 subtype,u8 s_host, +u16 *range_start,u16 *range_num) +{ +struct ti_sci_msg_resp_get_resource_range *resp; +struct ti_sci_msg_req_get_resource_range *req; +struct ti_sci_xfer *xfer; +struct ti_sci_info *info; +struct device *dev; +int ret =0 ; + +if (IS_ERR (handle)) +return PTR_ERR (handle); +if (!handle) +return -EINVAL ; + + info =handle_to_ti_sci_info (handle); + dev = info->dev; + + xfer =ti_sci_get_one_xfer (info,TI_SCI_MSG_GET_RESOURCE_RANGE , +TI_SCI_FLAG_REQ_ACK_ON_PROCESSED , +sizeof (*req),sizeof (*resp)); +if (IS_ERR (xfer)) { + ret =PTR_ERR (xfer); +dev_err (dev,"Message alloc failed(%d)\n" , ret); +return ret; + } + req = (struct ti_sci_msg_req_get_resource_range *)xfer->xfer_buf; + req->secondary_host = s_host; + req->type = type &MSG_RM_RESOURCE_TYPE_MASK ; + req->subtype = subtype &MSG_RM_RESOURCE_SUBTYPE_MASK ; + + ret =ti_sci_do_xfer (info, xfer); +if (ret) { +dev_err (dev,"Mbox send fail %d\n" , ret); + goto fail; + } + + resp = (struct ti_sci_msg_resp_get_resource_range *)xfer->xfer_buf; + +if (!ti_sci_is_response_ack (resp)) { + ret = -ENODEV ; + }else if (!resp->range_start && !resp->range_num) { + ret = -ENODEV ; + }else { + *range_start = resp->range_start; + *range_num = resp->range_num; + }; + +fail: +ti_sci_put_one_xfer (&info->minfo, xfer); + +return ret; +} + +/** +* ti_sci_cmd_get_resource_range - Get a range of resources assigned to host +* that is same as ti sci interface host. +* @handle: Pointer to TISCI handle. +* @type: Resource assignment type that is being requested for +* @subtype: Resource assignment subtype that is being requested for +* @range_start: Start index of the resource range +* @range_num: Number of resources in the range +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_get_resource_range (const struct ti_sci_handle *handle, +u16 type,u8 subtype, +u16 *range_start,u16 *range_num) +{ +return ti_sci_get_resource_range (handle, type, subtype, +TI_SCI_IRQ_SECONDARY_HOST_INVALID , + range_start, range_num); +} + +/** +* ti_sci_cmd_get_resource_range_from_shost - Get a range of resources +* assigned to a specified host. +* @handle: Pointer to TISCI handle. +* @type: Resource assignment type that is being requested for +* @subtype: Resource assignment subtype that is being requested for +* @s_host: Host processor ID to which the resources are allocated +* @range_start: Start index of the resource range +* @range_num: Number of resources in the range +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static +int ti_sci_cmd_get_resource_range_from_shost (const struct ti_sci_handle *handle, +u16 type,u8 subtype,u8 s_host, +u16 *range_start,u16 *range_num) +{ +return ti_sci_get_resource_range (handle, type, subtype, s_host, + range_start, range_num); +} +/* * ti_sci_setup_ops() - Setup the operations structures * @info: pointer to TISCI pointer
@@ -1627,6 +1736,7 @@ static void ti_sci_setup_ops(struct ti_sci_info *info)struct ti_sci_core_ops *core_ops = &ops->core_ops;struct ti_sci_dev_ops *dops = &ops->dev_ops;struct ti_sci_clk_ops *cops = &ops->clk_ops; +struct ti_sci_rm_core_ops *rm_core_ops = &ops->rm_core_ops; core_ops->reboot_device = ti_sci_cmd_core_reboot;
@@ -1657,6 +1767,10 @@ static void ti_sci_setup_ops(struct ti_sci_info *info) cops->get_best_match_freq = ti_sci_cmd_clk_get_match_freq; cops->set_freq = ti_sci_cmd_clk_set_freq; cops->get_freq = ti_sci_cmd_clk_get_freq; + + rm_core_ops->get_range = ti_sci_cmd_get_resource_range; + rm_core_ops->get_range_from_shost = + ti_sci_cmd_get_resource_range_from_shost; }/**
drivers/firmware/ti_sci.h +42 -0
52 lines not on this page · raw message
include/linux/soc/ti/ti_sci_protocol.h +26 -0
@@ -192,15 +192,41 @@ struct ti_sci_clk_ops { u64 *current_freq); }; +/** +* struct ti_sci_rm_core_ops - Resource management core operations +* @get_range: Get a range of resources belonging to ti sci host. +* @get_rage_from_shost: Get a range of resources belonging to +* specified host id. +* - s_host: Host processing entity to which the +* resources are allocated +* +* NOTE: for these functions, all the parameters are consolidated and defined +* as below: +* - handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle +* - type: resource assignment type that is being requested for +* - subtype: resource assignment subtype that is being requested for +* - range_start: Start index of the resource range +* - range_end: Number of resources in the range +*/ +struct ti_sci_rm_core_ops { +int (*get_range)(const struct ti_sci_handle *handle,u16 type, +u8 subtype,u16 *range_start,u16 *range_num); +int (*get_range_from_shost)(const struct ti_sci_handle *handle, +u16 type,u8 subtype,u8 s_host, +u16 *range_start,u16 *range_num); +}; +/** * struct ti_sci_ops - Function support for TI SCI * @dev_ops: Device specific operations * @clk_ops: Clock specific operations +* @rm_core_ops: Resource management core operations. */ struct ti_sci_ops {struct ti_sci_core_ops core_ops;struct ti_sci_dev_ops dev_ops;struct ti_sci_clk_ops clk_ops; +struct ti_sci_rm_core_ops rm_core_ops; };/**
Signature · 1 line
2.19.0
PATCH 3/4 firmware: ti_sci: Add support for IRQ management
In reply to Lokesh VutlaTISCI abstracts the handling of IRQ routes where interrupt sources are not directly connected to interrupt controller. Add support for the set of TISCI commands for requesting and releasing IRQs.
--- drivers/firmware/ti_sci.c | 436 +++++++++++++++++++++++++ drivers/firmware/ti_sci.h | 60 ++++ include/linux/soc/ti/ti_sci_protocol.h | 77 +++++ 3 files changed, 573 insertions(+)
drivers/firmware/ti_sci.c +436 -0
@@ -1726,6 +1726,429 @@ int ti_sci_cmd_get_resource_range_from_shost(const struct ti_sci_handle *handle, range_start, range_num); } +/** +* ti_sci_manage_irq() - Helper api to configure/release the irq route between +* the requested source and destination +* @handle: Pointer to TISCI handle. +* @valid_params: Bit fields defining the validity of certain params +* @src_id: Device ID of the IRQ source +* @src_index: IRQ source index within the source device +* @dst_id: Device ID of the IRQ destination +* @dt_host_irq: IRQ number of the destination device +* @ia_id: Device ID of the IA, if the IRQ flows through this IA +* @vint: Virtual interrupt to be used within the IA +* @global_event: Global event number to be used for the requesting event +* @vint_status_bit: Virtual interrupt status bit to be used for the event +* @s_host: Secondary host ID to which the irq/event is being +* requested for. +* @type: Request type irq set or release. +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_manage_irq (const struct ti_sci_handle *handle, +u32 valid_params,u16 src_id,u16 src_index, +u16 dst_id,u16 dst_host_irq,u16 ia_id,u16 vint, +u16 global_event,u8 vint_status_bit,u8 s_host, +u16 type) +{ +struct ti_sci_msg_req_manage_irq *req; +struct ti_sci_msg_hdr *resp; +struct ti_sci_xfer *xfer; +struct ti_sci_info *info; +struct device *dev; +int ret =0 ; + +if (IS_ERR (handle)) +return PTR_ERR (handle); +if (!handle) +return -EINVAL ; + + info =handle_to_ti_sci_info (handle); + dev = info->dev; + + xfer =ti_sci_get_one_xfer (info, type,TI_SCI_FLAG_REQ_ACK_ON_PROCESSED , +sizeof (*req),sizeof (*resp)); +if (IS_ERR (xfer)) { + ret =PTR_ERR (xfer); +dev_err (dev,"Message alloc failed(%d)\n" , ret); +return ret; + } + req = (struct ti_sci_msg_req_manage_irq *)xfer->xfer_buf; + req->valid_params = valid_params; + req->src_id = src_id; + req->src_index = src_index; + req->dst_id = dst_id; + req->dst_host_irq = dst_host_irq; + req->ia_id = ia_id; + req->vint = vint; + req->global_event = global_event; + req->vint_status_bit = vint_status_bit; + req->secondary_host = s_host; + + ret =ti_sci_do_xfer (info, xfer); +if (ret) { +dev_err (dev,"Mbox send fail %d\n" , ret); + goto fail; + } + + resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; + + ret =ti_sci_is_response_ack (resp) ?0 : -ENODEV ; + +fail: +ti_sci_put_one_xfer (&info->minfo, xfer); + +return ret; +} + +/** +* ti_sci_set_irq() - Helper api to configure the irq route between the +* requested source and destination +* @handle: Pointer to TISCI handle. +* @valid_params: Bit fields defining the validity of certain params +* @src_id: Device ID of the IRQ source +* @src_index: IRQ source index within the source device +* @dst_id: Device ID of the IRQ destination +* @dt_host_irq: IRQ number of the destination device +* @ia_id: Device ID of the IA, if the IRQ flows through this IA +* @vint: Virtual interrupt to be used within the IA +* @global_event: Global event number to be used for the requesting event +* @vint_status_bit: Virtual interrupt status bit to be used for the event +* @s_host: Secondary host ID to which the irq/event is being +* requested for. +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_set_irq (const struct ti_sci_handle *handle,u32 valid_params, +u16 src_id,u16 src_index,u16 dst_id, +u16 dst_host_irq,u16 ia_id,u16 vint, +u16 global_event,u8 vint_status_bit,u8 s_host) +{ +return ti_sci_manage_irq (handle, valid_params, src_id, src_index, + dst_id, dst_host_irq, ia_id, vint, + global_event, vint_status_bit, s_host, +TI_SCI_MSG_SET_IRQ ); +} + +/** +* ti_sci_free_irq() - Helper api to free the irq route between the +* requested source and destination +* @handle: Pointer to TISCI handle. +* @valid_params: Bit fields defining the validity of certain params +* @src_id: Device ID of the IRQ source +* @src_index: IRQ source index within the source device +* @dst_id: Device ID of the IRQ destination +* @dt_host_irq: IRQ number of the destination device +* @ia_id: Device ID of the IA, if the IRQ flows through this IA +* @vint: Virtual interrupt to be used within the IA +* @global_event: Global event number to be used for the requesting event +* @vint_status_bit: Virtual interrupt status bit to be used for the event +* @s_host: Secondary host ID to which the irq/event is being +* requested for. +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_free_irq (const struct ti_sci_handle *handle,u32 valid_params, +u16 src_id,u16 src_index,u16 dst_id, +u16 dst_host_irq,u16 ia_id,u16 vint, +u16 global_event,u8 vint_status_bit,u8 s_host) +{ +return ti_sci_manage_irq (handle, valid_params, src_id, src_index, + dst_id, dst_host_irq, ia_id, vint, + global_event, vint_status_bit, s_host, +TI_SCI_MSG_FREE_IRQ ); +} + +/** +* ti_sci_cmd_set_direct_irq() - Configure a non-event based direct irq route +* between the requested source and destination. +* @handle: Pointer to TISCI handle. +* @src_id: Device ID of the IRQ source +* @src_index: IRQ source index within the source device +* @dst_id: Device ID of the IRQ destination +* @dt_host_irq: IRQ number of the destination device +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_set_direct_irq (const struct ti_sci_handle *handle, +u16 src_id,u16 src_index,u16 dst_id, +u16 dst_host_irq) +{ +u32 valid_params =MSG_FLAG_DST_ID_VALID |MSG_FLAG_DST_HOST_IRQ_VALID ; + +return ti_sci_set_irq (handle, valid_params, src_id, src_index, + dst_id, dst_host_irq,0 ,0 ,0 ,0 ,0 ); +} + +/** +* ti_sci_cmd_set_event_irq() - Configure an event based irq route between the +* requested source and destination +* @handle: Pointer to TISCI handle. +* @src_id: Device ID of the IRQ source +* @src_index: IRQ source index within the source device +* @dst_id: Device ID of the IRQ destination +* @dt_host_irq: IRQ number of the destination device +* @ia_id: Device ID of the IA, if the IRQ flows through this IA +* @vint: Virtual interrupt to be used within the IA +* @global_event: Global event number to be used for the requesting event +* @vint_status_bit: Virtual interrupt status bit to be used for the event +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_set_event_irq (const struct ti_sci_handle *handle, +u16 src_id,u16 src_index,u16 dst_id, +u16 dst_host_irq,u16 ia_id,u16 vint, +u16 global_event,u8 vint_status_bit) +{ +u32 valid_params =MSG_FLAG_DST_ID_VALID | +MSG_FLAG_DST_HOST_IRQ_VALID |MSG_FLAG_IA_ID_VALID | +MSG_FLAG_VINT_VALID |MSG_FLAG_GLB_EVNT_VALID | +MSG_FLAG_VINT_STS_BIT_VALID ; + +return ti_sci_set_irq (handle, valid_params, src_id, src_index, dst_id, + dst_host_irq, ia_id, vint, global_event, + vint_status_bit,0 ); +} + +/** +* ti_sci_cmd_set_direct_irq_from_shost() - Configure a non-event based direct +* irq route between the source and +* destination belonging to a +* specified host. +* @handle: Pointer to TISCI handle. +* @src_id: Device ID of the IRQ source +* @src_index: IRQ source index within the source device +* @dst_id: Device ID of the IRQ destination +* @dt_host_irq: IRQ number of the destination device +* @s_host: Secondary host ID to which the irq/event is being +* requested for. +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static +int ti_sci_cmd_set_direct_irq_from_shost (const struct ti_sci_handle *handle, +u16 src_id,u16 src_index,u16 dst_id, +u16 dst_host_irq,u8 s_host) +{ +u32 valid_params =MSG_FLAG_DST_ID_VALID |MSG_FLAG_DST_HOST_IRQ_VALID | +MSG_FLAG_SHOST_VALID ; + +return ti_sci_set_irq (handle, valid_params, src_id, src_index, + dst_id, dst_host_irq,0 ,0 ,0 ,0 , s_host); +} + +/** +* ti_sci_cmd_set_event_irq_from_shost() - Configure an event based irq +* route between the source and +* destination belonging to a +* specified host. +* @handle: Pointer to TISCI handle. +* @src_id: Device ID of the IRQ source +* @src_index: IRQ source index within the source device +* @dst_id: Device ID of the IRQ destination +* @dt_host_irq: IRQ number of the destination device +* @ia_id: Device ID of the IA, if the IRQ flows through this IA +* @vint: Virtual interrupt to be used within the IA +* @global_event: Global event number to be used for the requesting event +* @vint_status_bit: Virtual interrupt status bit to be used for the event +* @s_host: Secondary host ID to which the irq/event is being +* requested for. +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static +int ti_sci_cmd_set_event_irq_from_shost (const struct ti_sci_handle *handle, +u16 src_id,u16 src_index,u16 dst_id, +u16 dst_host_irq,u16 ia_id,u16 vint, +u16 global_event,u8 vint_status_bit, +u8 s_host) +{ +u32 valid_params =MSG_FLAG_DST_ID_VALID | +MSG_FLAG_DST_HOST_IRQ_VALID |MSG_FLAG_IA_ID_VALID | +MSG_FLAG_VINT_VALID |MSG_FLAG_GLB_EVNT_VALID | +MSG_FLAG_VINT_STS_BIT_VALID |MSG_FLAG_SHOST_VALID ; + +return ti_sci_set_irq (handle, valid_params, src_id, src_index, + dst_id, dst_host_irq, ia_id, vint, + global_event, vint_status_bit, s_host); +} + +/** +* ti_sci_cmd_set_event_irq_to_poll() - Configure an event based irq +* in polling mode +* @handle: Pointer to TISCI handle. +* @src_id: Device ID of the IRQ source +* @src_index: IRQ source index within the source device +* @dst_id: Device ID of the IRQ destination +* @dt_host_irq: IRQ number of the destination device +* @ia_id: Device ID of the IA, if the IRQ flows through this IA +* @vint: Virtual interrupt to be used within the IA +* @global_event: Global event number to be used for the requesting event +* @vint_status_bit: Virtual interrupt status bit to be used for the event +* @s_host: Secondary host ID to which the irq/event is being +* requested for. +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_set_event_irq_to_poll (const struct ti_sci_handle *handle, +u16 src_id,u16 src_index, +u16 ia_id,u16 vint, +u16 global_event, +u8 vint_status_bit) +{ +u32 valid_params =MSG_FLAG_IA_ID_VALID |MSG_FLAG_VINT_VALID | +MSG_FLAG_GLB_EVNT_VALID | +MSG_FLAG_VINT_STS_BIT_VALID ; + +return ti_sci_set_irq (handle, valid_params, src_id, src_index,0 ,0 , + ia_id, vint, global_event, vint_status_bit,0 ); +} + +/** +* ti_sci_cmd_free_direct_irq() - Free a non-event based direct irq route +* between the requested source and destination. +* @handle: Pointer to TISCI handle. +* @src_id: Device ID of the IRQ source +* @src_index: IRQ source index within the source device +* @dst_id: Device ID of the IRQ destination +* @dt_host_irq: IRQ number of the destination device +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_free_direct_irq (const struct ti_sci_handle *handle, +u16 src_id,u16 src_index,u16 dst_id, +u16 dst_host_irq) +{ +u32 valid_params =MSG_FLAG_DST_ID_VALID |MSG_FLAG_DST_HOST_IRQ_VALID ; + +return ti_sci_free_irq (handle, valid_params, src_id, src_index, + dst_id, dst_host_irq,0 ,0 ,0 ,0 ,0 ); +} + +/** +* ti_sci_cmd_free_event_irq() - Free an event based irq route between the +* requested source and destination +* @handle: Pointer to TISCI handle. +* @src_id: Device ID of the IRQ source +* @src_index: IRQ source index within the source device +* @dst_id: Device ID of the IRQ destination +* @dt_host_irq: IRQ number of the destination device +* @ia_id: Device ID of the IA, if the IRQ flows through this IA +* @vint: Virtual interrupt to be used within the IA +* @global_event: Global event number to be used for the requesting event +* @vint_status_bit: Virtual interrupt status bit to be used for the event +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_free_event_irq (const struct ti_sci_handle *handle, +u16 src_id,u16 src_index,u16 dst_id, +u16 dst_host_irq,u16 ia_id,u16 vint, +u16 global_event,u8 vint_status_bit) +{ +u32 valid_params =MSG_FLAG_DST_ID_VALID | +MSG_FLAG_DST_HOST_IRQ_VALID |MSG_FLAG_IA_ID_VALID | +MSG_FLAG_VINT_VALID |MSG_FLAG_GLB_EVNT_VALID | +MSG_FLAG_VINT_STS_BIT_VALID ; + +return ti_sci_free_irq (handle, valid_params, src_id, src_index, + dst_id, dst_host_irq, ia_id, vint, + global_event, vint_status_bit,0 ); +} + +/** +* ti_sci_cmd_free_direct_irq_from_shost() - Free a non-event based direct irq +* route between the source and +* destination belonging to a +* specified host. +* @handle: Pointer to TISCI handle. +* @src_id: Device ID of the IRQ source +* @src_index: IRQ source index within the source device +* @dst_id: Device ID of the IRQ destination +* @dt_host_irq: IRQ number of the destination device +* @s_host: Secondary host ID to which the irq/event is being +* requested for. +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static +int ti_sci_cmd_free_direct_irq_from_shost (const struct ti_sci_handle *handle, +u16 src_id,u16 src_index,u16 dst_id, +u16 dst_host_irq,u8 s_host) +{ +u32 valid_params =MSG_FLAG_DST_ID_VALID |MSG_FLAG_DST_HOST_IRQ_VALID | +MSG_FLAG_SHOST_VALID ; + +return ti_sci_free_irq (handle, valid_params, src_id, src_index, + dst_id, dst_host_irq,0 ,0 ,0 ,0 , s_host); +} + +/** +* ti_sci_cmd_free_event_irq_from_shost() - Free an event based irq +* route between the source and +* destination belonging to a +* specified host. +* @handle: Pointer to TISCI handle. +* @src_id: Device ID of the IRQ source +* @src_index: IRQ source index within the source device +* @dst_id: Device ID of the IRQ destination +* @dt_host_irq: IRQ number of the destination device +* @ia_id: Device ID of the IA, if the IRQ flows through this IA +* @vint: Virtual interrupt to be used within the IA +* @global_event: Global event number to be used for the requesting event +* @vint_status_bit: Virtual interrupt status bit to be used for the event +* @s_host: Secondary host ID to which the irq/event is being +* requested for. +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static +int ti_sci_cmd_free_event_irq_from_shost (const struct ti_sci_handle *handle, +u16 src_id,u16 src_index,u16 dst_id, +u16 dst_host_irq,u16 ia_id,u16 vint, +u16 global_event,u8 vint_status_bit, +u8 s_host) +{ +u32 valid_params =MSG_FLAG_DST_ID_VALID | +MSG_FLAG_DST_HOST_IRQ_VALID |MSG_FLAG_IA_ID_VALID | +MSG_FLAG_VINT_VALID |MSG_FLAG_GLB_EVNT_VALID | +MSG_FLAG_VINT_STS_BIT_VALID |MSG_FLAG_SHOST_VALID ; + +return ti_sci_free_irq (handle, valid_params, src_id, src_index, + dst_id, dst_host_irq, ia_id, vint, + global_event, vint_status_bit, s_host); +} + +/** +* ti_sci_cmd_free_event_irq_to_poll() - Free an event based irq +* in polling mode +* @handle: Pointer to TISCI handle. +* @src_id: Device ID of the IRQ source +* @src_index: IRQ source index within the source device +* @dst_id: Device ID of the IRQ destination +* @dt_host_irq: IRQ number of the destination device +* @ia_id: Device ID of the IA, if the IRQ flows through this IA +* @vint: Virtual interrupt to be used within the IA +* @global_event: Global event number to be used for the requesting event +* @vint_status_bit: Virtual interrupt status bit to be used for the event +* @s_host: Secondary host ID to which the irq/event is being +* requested for. +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_free_event_irq_to_poll (const struct ti_sci_handle *handle, +u16 src_id,u16 src_index, +u16 ia_id,u16 vint, +u16 global_event, +u8 vint_status_bit) +{ +u32 valid_params =MSG_FLAG_IA_ID_VALID |MSG_FLAG_VINT_VALID | +MSG_FLAG_GLB_EVNT_VALID | +MSG_FLAG_VINT_STS_BIT_VALID ; + +return ti_sci_free_irq (handle, valid_params, src_id, src_index,0 ,0 , + ia_id, vint, global_event, vint_status_bit,0 ); +} +/* * ti_sci_setup_ops() - Setup the operations structures * @info: pointer to TISCI pointer
@@ -1737,6 +2160,7 @@ static void ti_sci_setup_ops(struct ti_sci_info *info)struct ti_sci_dev_ops *dops = &ops->dev_ops;struct ti_sci_clk_ops *cops = &ops->clk_ops;struct ti_sci_rm_core_ops *rm_core_ops = &ops->rm_core_ops; +struct ti_sci_rm_irq_ops *iops = &ops->rm_irq_ops; core_ops->reboot_device = ti_sci_cmd_core_reboot;
@@ -1771,6 +2195,18 @@ static void ti_sci_setup_ops(struct ti_sci_info *info) rm_core_ops->get_range = ti_sci_cmd_get_resource_range; rm_core_ops->get_range_from_shost = ti_sci_cmd_get_resource_range_from_shost; + + iops->set_direct_irq = ti_sci_cmd_set_direct_irq; + iops->set_event_irq = ti_sci_cmd_set_event_irq; + iops->set_direct_irq_from_shost = ti_sci_cmd_set_direct_irq_from_shost; + iops->set_event_irq_from_shost = ti_sci_cmd_set_event_irq_from_shost; + iops->set_event_irq_to_poll = ti_sci_cmd_set_event_irq_to_poll; + iops->free_direct_irq = ti_sci_cmd_free_direct_irq; + iops->free_event_irq = ti_sci_cmd_free_event_irq; + iops->free_direct_irq_from_shost = + ti_sci_cmd_free_direct_irq_from_shost; + iops->free_event_irq_from_shost = ti_sci_cmd_free_event_irq_from_shost; + iops->free_event_irq_to_poll = ti_sci_cmd_free_event_irq_to_poll; }/**
drivers/firmware/ti_sci.h +60 -0
70 lines not on this page · raw message
include/linux/soc/ti/ti_sci_protocol.h +77 -0
94 lines not on this page · raw message
Signature · 1 line
2.19.0
PATCH 4/4 firmware: ti_sci: Add helper apis to mange resources
In reply to Lokesh VutlaEach resource with in the device can be uniquely identified by a type and subtype as defined by TISCI. Since this is generic across the devices, resource allocation also can be made generic instead of each client driver handling the resource. So add helper apis to manage the resource.
devm_ti_sci_get_of_resource() expects resource from dt in form of tuples <type, subtype>.
--- drivers/firmware/ti_sci.c | 126 +++++++++++++++++++++++++ include/linux/soc/ti/ti_sci_protocol.h | 48 ++++++++++ 2 files changed, 174 insertions(+)
drivers/firmware/ti_sci.c +126 -0
@@ -2414,6 +2414,132 @@ const struct ti_sci_handle *devm_ti_sci_get_by_phandle(struct device *dev, }EXPORT_SYMBOL_GPL (devm_ti_sci_get_by_phandle); +/* +* ti_sci_get_free_resource() - Get a free resource from TISCI resource. +* @res: Pointer to the TISCI resource +* +* Return: resource num if all went ok else TI_SCI_RESOURCE_NULL. +*/ +u16 ti_sci_get_free_resource (struct ti_sci_resource *res) +{ +unsigned long flags; +u16 set, free_bit; + +raw_spin_lock_irqsave (&res->lock, flags); +for (set =0 ; set < res->sets; set++) { + free_bit =find_first_zero_bit (res->desc[set].res_map, + res->desc[set].num); +if (free_bit != res->desc[set].num) { +set_bit (free_bit, res->desc[set].res_map); +raw_spin_unlock_irqrestore (&res->lock, flags); +return res->desc[set].start + free_bit; + } + } +raw_spin_unlock_irqrestore (&res->lock, flags); + +return TI_SCI_RESOURCE_NULL ; +} +EXPORT_SYMBOL_GPL (ti_sci_get_free_resource); + +/** +* ti_sci_release_resource() - Release a resource from TISCI resource. +* @res: Pointer to the TISCI resource +*/ +void ti_sci_release_resource (struct ti_sci_resource *res,u16 id) +{ +unsigned long flags; +u16 set; + +raw_spin_lock_irqsave (&res->lock, flags); +for (set =0 ; set < res->sets; set++) { +if (res->desc[set].start <= id && + (res->desc[set].num + res->desc[set].start) > id) +clear_bit (id - res->desc[set].start, + res->desc[set].res_map); + } +raw_spin_unlock_irqrestore (&res->lock, flags); +} +EXPORT_SYMBOL_GPL (ti_sci_release_resource); + +/** +* devm_ti_sci_get_of_resource() - Get a TISCI resource assigned to a device +* @handle: TISCI handle +* @dev: Device pointer to which the resource is assigned +* @of_prop: property name by which the resource are represented +* +* Note: This function expects of_prop to be in the form of tuples +* <type, subtype>. Allocates and initializes ti_sci_resource structure +* for each of_prop. Client driver can directly call +* ti_sci_(get_free, release)_resource apis for handling the resource. +* +* Return: Pointer to ti_sci_resource if all went well else appropriate +* error pointer. +*/ +struct ti_sci_resource * +devm_ti_sci_get_of_resource (const struct ti_sci_handle *handle, +struct device *dev,char *of_prop) +{ +u32 resource_type, resource_subtype; +struct ti_sci_resource *res; +int sets, i, ret; + + res =devm_kzalloc (dev,sizeof (*res),GFP_KERNEL ); +if (!res) +return ERR_PTR (-ENOMEM ); + + sets =of_property_count_elems_of_size (dev_of_node (dev), of_prop, +sizeof (u32)); +if (sets <0 ) { +dev_err (dev,"%s resource type ids not available\n" , of_prop); +return ERR_PTR (sets); + } + + res->sets = sets /2 ; + + res->desc =devm_kcalloc (dev, res->sets,sizeof (*res->desc), +GFP_KERNEL ); +if (!res->desc) +return ERR_PTR (-ENOMEM ); + +for (i =0 ; i < res->sets; i++) { + ret =of_property_read_u32_index (dev_of_node (dev), of_prop, + i *2 , &resource_type); +if (ret) +return ERR_PTR (-EINVAL ); + + ret =of_property_read_u32_index (dev_of_node (dev), of_prop, + (i *2 ) +1 , + &resource_subtype); +if (ret) +return ERR_PTR (-EINVAL ); + + ret = handle->ops.rm_core_ops.get_range (handle, resource_type, + resource_subtype, + &res->desc[i].start, + &res->desc[i].num); +if (ret) { +dev_err (dev,"type %d subtype %d not allocated for host %d\n" , + resource_type, resource_subtype, +handle_to_ti_sci_info (handle)->host_id); +return ERR_PTR (ret); + } + +dev_dbg (dev,"res type = %d, subtype = %d, start = %d, num = %d\n" , + resource_type, resource_subtype, res->desc[i].start, + res->desc[i].num); + + res->desc[i].res_map = +devm_kzalloc (dev,BITS_TO_LONGS (res->desc[i].num) * +sizeof (*res->desc[i].res_map),GFP_KERNEL ); +if (!res->desc[i].res_map) +return ERR_PTR (-ENOMEM ); + } +raw_spin_lock_init (&res->lock); + +return res; +} +EXPORT_SYMBOL_GPL (devm_ti_sci_get_of_resource); +static int tisci_reboot_handler (struct notifier_block *nb,unsigned long mode,void *cmd) {
include/linux/soc/ti/ti_sci_protocol.h +48 -0
66 lines not on this page · raw message
Signature · 1 line
2.19.0
Nishanth Menon
maintainerPATCH 4/4 firmware: ti_sci: Add helper apis to mange resources
Quoted 42 lines · Lokesh Vutla
drivers/firmware/ti_sci.c +42
-0+struct ti_sci_resource * +devm_ti_sci_get_of_resource (const struct ti_sci_handle *handle, +struct device *dev,char *of_prop) +{ +u32 resource_type, resource_subtype; +struct ti_sci_resource *res; +int sets, i, ret; + + res =devm_kzalloc (dev,sizeof (*res),GFP_KERNEL ); +if (!res) +return ERR_PTR (-ENOMEM ); + + sets =of_property_count_elems_of_size (dev_of_node (dev), of_prop, +sizeof (u32)); +if (sets <0 ) { +dev_err (dev,"%s resource type ids not available\n" , of_prop); +return ERR_PTR (sets); + } + + res->sets = sets /2 ; + + res->desc =devm_kcalloc (dev, res->sets,sizeof (*res->desc), +GFP_KERNEL ); +if (!res->desc) +return ERR_PTR (-ENOMEM ); + +for (i =0 ; i < res->sets; i++) { + ret =of_property_read_u32_index (dev_of_node (dev), of_prop, + i *2 , &resource_type); +if (ret) +return ERR_PTR (-EINVAL ); + + ret =of_property_read_u32_index (dev_of_node (dev), of_prop, + (i *2 ) +1 , + &resource_subtype); +if (ret) +return ERR_PTR (-EINVAL ); + + ret = handle->ops.rm_core_ops.get_range (handle, resource_type, + resource_subtype, + &res->desc[i].start, + &res->desc[i].num);
drivers/firmware/ti_sci.c const struct ti_sci_handle *devm_ti_sci_get_by_phandle(struct device *dev, · line 2529
Quoted 10 lines
drivers/firmware/ti_sci.c +10
-0+if (ret) { +dev_err (dev,"type %d subtype %d not allocated for host %d\n" , + resource_type, resource_subtype, +handle_to_ti_sci_info (handle)->host_id); +return ERR_PTR (ret); + } + +dev_dbg (dev,"res type = %d, subtype = %d, start = %d, num = %d\n" , + resource_type, resource_subtype, res->desc[i].start, + res->desc[i].num);
NAK. Where is the binding for this? What is this decoding? Please don't decode binding without having an official binding.
Signature · 2 lines
Regards, Nishanth Menon
PATCH 4/4 firmware: ti_sci: Add helper apis to mange resources
Quoted 48 lines · Nishanth Menon
Quoted 47 lines · Lokesh Vutla
drivers/firmware/ti_sci.c +47
-0+struct ti_sci_resource * +devm_ti_sci_get_of_resource (const struct ti_sci_handle *handle, +struct device *dev,char *of_prop) +{ +u32 resource_type, resource_subtype; +struct ti_sci_resource *res; +int sets, i, ret; + + res =devm_kzalloc (dev,sizeof (*res),GFP_KERNEL ); +if (!res) +return ERR_PTR (-ENOMEM ); + + sets =of_property_count_elems_of_size (dev_of_node (dev), of_prop, +sizeof (u32)); +if (sets <0 ) { +dev_err (dev,"%s resource type ids not available\n" , of_prop); +return ERR_PTR (sets); + } + + res->sets = sets /2 ; + + res->desc =devm_kcalloc (dev, res->sets,sizeof (*res->desc), +GFP_KERNEL ); +if (!res->desc) +return ERR_PTR (-ENOMEM ); + +for (i =0 ; i < res->sets; i++) { + ret =of_property_read_u32_index (dev_of_node (dev), of_prop, + i *2 , &resource_type); +if (ret) +return ERR_PTR (-EINVAL ); + + ret =of_property_read_u32_index (dev_of_node (dev), of_prop, + (i *2 ) +1 , + &resource_subtype); +if (ret) +return ERR_PTR (-EINVAL ); + + ret = handle->ops.rm_core_ops.get_range (handle, resource_type, + resource_subtype, + &res->desc[i].start, + &res->desc[i].num); +if (ret) { +dev_err (dev,"type %d subtype %d not allocated for host %d\n" , + resource_type, resource_subtype, +handle_to_ti_sci_info (handle)->host_id); +return ERR_PTR (ret);
Quoted 8 lines
drivers/firmware/ti_sci.c const struct ti_sci_handle *devm_ti_sci_get_by_phandle(struct device *dev, · line 2529
Quoted 5 lines
drivers/firmware/ti_sci.c +5
-0+ } + +dev_dbg (dev,"res type = %d, subtype = %d, start = %d, num = %d\n" , + resource_type, resource_subtype, res->desc[i].start, + res->desc[i].num);NAK. Where is the binding for this? What is this decoding? Please don't decode binding without having an official binding.
This is a helper library for the clients to get resource range from DT and is not compulsory for clients to use this library to managing these resources. So in my understanding DT bindings should go into the client DT doc as posted here[1]. If you really insist I can add these details in ti,sci documentation but not sure if we are doing the same for all other helper apis.
[1] https://patchwork.kernel.org/patch/10629215/
Thanks and regards,
Lokesh
Nishanth Menon
maintainerPATCH 4/4 firmware: ti_sci: Add helper apis to mange resources
Quoted 10 lines · Lokesh Vutla
Quoted 2 lines · Nishanth Menon
NAK. Where is the binding for this? What is this decoding? Please don't decode binding without having an official binding.
This is a helper library for the clients to get resource range from DT and is not compulsory for clients to use this library to managing these resources. So in my understanding DT bindings should go into the client DT doc as posted here[1]. If you really insist I can add these details
Thanks.. Please get the binding approved before we discuss implementation in driver.
Quoted 2 lines
in ti,sci documentation but not sure if we are doing the same for all other helper apis.
the core TISCI device does'nt require any ranges property. these need to be parsed and handled in corresponding tisci drivers? I don't see the benefit in dealing with OF parsing in generic TISCI firmware driver. yes, there might be a little similarities, but really we'd have to argue strongly why it needs to belong to the firmware driver. So far it looks like just a single irq-chip driver seems to need it, I cant see the argument for it getting caught up in that path.
--
Regards,
Nishanth Menon
PATCH 4/4 firmware: ti_sci: Add helper apis to mange resources
Quoted 7 lines · Nishanth Menon
Quoted 6 lines · Lokesh Vutla
Quoted 2 lines · Nishanth Menon
NAK. Where is the binding for this? What is this decoding? Please don't decode binding without having an official binding.
Quoted 8 lines
Quoted 4 lines
This is a helper library for the clients to get resource range from DT and is not compulsory for clients to use this library to managing these resources. So in my understanding DT bindings should go into the client DT doc as posted here[1]. If you really insist I can add these details
Thanks.. Please get the binding approved before we discuss implementation in driver.
Absolutely. Infact there is no rush to post driver patches before the DT binding are approved. Lets stick to the usual flow.
Regards,
Santosh