| @@ -64,6 +64,22 @@ struct ti_sci_xfers_info { · 63 unmodified lines |
| 64 | 64 | spinlock_t xfer_lock; |
| 65 | 65 | }; |
| 66 | 66 | |
| 67 | +/** |
| 68 | + * struct ti_sci_rm_type_map - Structure representing TISCI Resource |
| 69 | + * management representation of dev_ids. |
| 70 | + * @dev_id: TISCI device ID |
| 71 | + * @type: Corresponding id as identified by TISCI RM. |
| 72 | + * |
| 73 | + * Note: This is used only as a work around for using RM range apis |
| 74 | + * for AM654 SoC. For future SoCs dev_id will be used as type |
| 75 | + * for RM range APIs. In order to maintain ABI backward compatibility |
| 76 | + * type is not being changed for AM654 SoC. |
| 77 | + */ |
| 78 | +struct ti_sci_rm_type_map { |
| 79 | + u32 dev_id; |
| 80 | + u16 type; |
| 81 | +}; |
| 82 | + |
| 67 | 83 | /** |
| 68 | 84 | * struct ti_sci_desc - Description of SoC integration |
| 69 | 85 | * @default_host_id: Host identifier representing the compute entity |
| @@ -71,12 +87,14 @@ struct ti_sci_xfers_info { · 1 unmodified line |
| 71 | 87 | * @max_msgs: Maximum number of messages that can be pending |
| 72 | 88 | * simultaneously in the system |
| 73 | 89 | * @max_msg_size: Maximum size of data per message that can be handled. |
| 90 | + * @rm_type_map: RM resource type mapping structure. |
| 74 | 91 | */ |
| 75 | 92 | struct ti_sci_desc { |
| 76 | 93 | u8 default_host_id; |
| 77 | 94 | int max_rx_timeout_ms; |
| 78 | 95 | int max_msgs; |
| 79 | 96 | int max_msg_size; |
| 97 | + struct ti_sci_rm_type_map *rm_type_map; |
| 80 | 98 | }; |
| 81 | 99 | |
| 82 | 100 | /** |
| @@ -1600,6 +1618,153 @@ fail: · 1517 unmodified lines |
| 1600 | 1618 | return ret; |
| 1601 | 1619 | } |
| 1602 | 1620 | |
| 1621 | +static int ti_sci_get_resource_type(struct ti_sci_info *info, u16 dev_id, |
| 1622 | + u16 *type) |
| 1623 | +{ |
| 1624 | + struct ti_sci_rm_type_map *rm_type_map = info->desc->rm_type_map; |
| 1625 | + bool found = false; |
| 1626 | + int i; |
| 1627 | + |
| 1628 | + /* If map is not provided then assume dev_id is used as type */ |
| 1629 | + if (!rm_type_map) { |
| 1630 | + *type = dev_id; |
| 1631 | + return 0; |
| 1632 | + } |
| 1633 | + |
| 1634 | + for (i = 0; rm_type_map[i].dev_id; i++) { |
| 1635 | + if (rm_type_map[i].dev_id == dev_id) { |
| 1636 | + *type = rm_type_map[i].type; |
| 1637 | + found = true; |
| 1638 | + break; |
| 1639 | + } |
| 1640 | + } |
| 1641 | + |
| 1642 | + if (!found) |
| 1643 | + return -EINVAL; |
| 1644 | + |
| 1645 | + return 0; |
| 1646 | +} |
| 1647 | + |
| 1648 | +/** |
| 1649 | + * ti_sci_get_resource_range - Helper to get a range of resources assigned |
| 1650 | + * to a host. Resource is uniquely identified by |
| 1651 | + * type and subtype. |
| 1652 | + * @handle: Pointer to TISCI handle. |
| 1653 | + * @dev_id: TISCI device ID. |
| 1654 | + * @subtype: Resource assignment subtype that is being requested |
| 1655 | + * from the given device. |
| 1656 | + * @s_host: Host processor ID to which the resources are allocated |
| 1657 | + * @range_start: Start index of the resource range |
| 1658 | + * @range_num: Number of resources in the range |
| 1659 | + * |
| 1660 | + * Return: 0 if all went fine, else return appropriate error. |
| 1661 | + */ |
| 1662 | +static int ti_sci_get_resource_range(const struct ti_sci_handle *handle, |
| 1663 | + u32 dev_id, u8 subtype, u8 s_host, |
| 1664 | + u16 *range_start, u16 *range_num) |
| 1665 | +{ |
| 1666 | + struct ti_sci_msg_resp_get_resource_range *resp; |
| 1667 | + struct ti_sci_msg_req_get_resource_range *req; |
| 1668 | + struct ti_sci_xfer *xfer; |
| 1669 | + struct ti_sci_info *info; |
| 1670 | + struct device *dev; |
| 1671 | + u16 type; |
| 1672 | + int ret = 0; |
| 1673 | + |
| 1674 | + if (IS_ERR(handle)) |
| 1675 | + return PTR_ERR(handle); |
| 1676 | + if (!handle) |
| 1677 | + return -EINVAL; |
| 1678 | + |
| 1679 | + info = handle_to_ti_sci_info(handle); |
| 1680 | + dev = info->dev; |
| 1681 | + |
| 1682 | + xfer = ti_sci_get_one_xfer(info, TI_SCI_MSG_GET_RESOURCE_RANGE, |
| 1683 | + TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1684 | + sizeof(*req), sizeof(*resp)); |
| 1685 | + if (IS_ERR(xfer)) { |
| 1686 | + ret = PTR_ERR(xfer); |
| 1687 | + dev_err(dev, "Message alloc failed(%d)\n", ret); |
| 1688 | + return ret; |
| 1689 | + } |
| 1690 | + |
| 1691 | + ret = ti_sci_get_resource_type(info, dev_id, &type); |
| 1692 | + if (ret) { |
| 1693 | + dev_err(dev, "rm type lookup failed for %u\n", dev_id); |
| 1694 | + goto fail; |
| 1695 | + } |
| 1696 | + |
| 1697 | + req = (struct ti_sci_msg_req_get_resource_range *)xfer->xfer_buf; |
| 1698 | + req->secondary_host = s_host; |
| 1699 | + req->type = type & MSG_RM_RESOURCE_TYPE_MASK; |
| 1700 | + req->subtype = subtype & MSG_RM_RESOURCE_SUBTYPE_MASK; |
| 1701 | + |
| 1702 | + ret = ti_sci_do_xfer(info, xfer); |
| 1703 | + if (ret) { |
| 1704 | + dev_err(dev, "Mbox send fail %d\n", ret); |
| 1705 | + goto fail; |
| 1706 | + } |
| 1707 | + |
| 1708 | + resp = (struct ti_sci_msg_resp_get_resource_range *)xfer->xfer_buf; |
| 1709 | + |
| 1710 | + if (!ti_sci_is_response_ack(resp)) { |
| 1711 | + ret = -ENODEV; |
| 1712 | + } else if (!resp->range_start && !resp->range_num) { |
| 1713 | + ret = -ENODEV; |
| 1714 | + } else { |
| 1715 | + *range_start = resp->range_start; |
| 1716 | + *range_num = resp->range_num; |
| 1717 | + }; |
| 1718 | + |
| 1719 | +fail: |
| 1720 | + ti_sci_put_one_xfer(&info->minfo, xfer); |
| 1721 | + |
| 1722 | + return ret; |
| 1723 | +} |
| 1724 | + |
| 1725 | +/** |
| 1726 | + * ti_sci_cmd_get_resource_range - Get a range of resources assigned to host |
| 1727 | + * that is same as ti sci interface host. |
| 1728 | + * @handle: Pointer to TISCI handle. |
| 1729 | + * @dev_id: TISCI device ID. |
| 1730 | + * @subtype: Resource assignment subtype that is being requested |
| 1731 | + * from the given device. |
| 1732 | + * @range_start: Start index of the resource range |
| 1733 | + * @range_num: Number of resources in the range |
| 1734 | + * |
| 1735 | + * Return: 0 if all went fine, else return appropriate error. |
| 1736 | + */ |
| 1737 | +static int ti_sci_cmd_get_resource_range(const struct ti_sci_handle *handle, |
| 1738 | + u32 dev_id, u8 subtype, |
| 1739 | + u16 *range_start, u16 *range_num) |
| 1740 | +{ |
| 1741 | + return ti_sci_get_resource_range(handle, dev_id, subtype, |
| 1742 | + TI_SCI_IRQ_SECONDARY_HOST_INVALID, |
| 1743 | + range_start, range_num); |
| 1744 | +} |
| 1745 | + |
| 1746 | +/** |
| 1747 | + * ti_sci_cmd_get_resource_range_from_shost - Get a range of resources |
| 1748 | + * assigned to a specified host. |
| 1749 | + * @handle: Pointer to TISCI handle. |
| 1750 | + * @dev_id: TISCI device ID. |
| 1751 | + * @subtype: Resource assignment subtype that is being requested |
| 1752 | + * from the given device. |
| 1753 | + * @s_host: Host processor ID to which the resources are allocated |
| 1754 | + * @range_start: Start index of the resource range |
| 1755 | + * @range_num: Number of resources in the range |
| 1756 | + * |
| 1757 | + * Return: 0 if all went fine, else return appropriate error. |
| 1758 | + */ |
| 1759 | +static |
| 1760 | +int ti_sci_cmd_get_resource_range_from_shost(const struct ti_sci_handle *handle, |
| 1761 | + u32 dev_id, u8 subtype, u8 s_host, |
| 1762 | + u16 *range_start, u16 *range_num) |
| 1763 | +{ |
| 1764 | + return ti_sci_get_resource_range(handle, dev_id, subtype, s_host, |
| 1765 | + range_start, range_num); |
| 1766 | +} |
| 1767 | + |
| 1603 | 1768 | /* |
| 1604 | 1769 | * ti_sci_setup_ops() - Setup the operations structures |
| 1605 | 1770 | * @info: pointer to TISCI pointer |
| @@ -1610,6 +1775,7 @@ static void ti_sci_setup_ops(struct ti_sci_info *info) · 4 unmodified lines |
| 1610 | 1775 | struct ti_sci_core_ops *core_ops = &ops->core_ops; |
| 1611 | 1776 | struct ti_sci_dev_ops *dops = &ops->dev_ops; |
| 1612 | 1777 | struct ti_sci_clk_ops *cops = &ops->clk_ops; |
| 1778 | + struct ti_sci_rm_core_ops *rm_core_ops = &ops->rm_core_ops; |
| 1613 | 1779 | |
| 1614 | 1780 | core_ops->reboot_device = ti_sci_cmd_core_reboot; |
| 1615 | 1781 | |
| @@ -1640,6 +1806,10 @@ static void ti_sci_setup_ops(struct ti_sci_info *info) · 24 unmodified lines |
| 1640 | 1806 | cops->get_best_match_freq = ti_sci_cmd_clk_get_match_freq; |
| 1641 | 1807 | cops->set_freq = ti_sci_cmd_clk_set_freq; |
| 1642 | 1808 | cops->get_freq = ti_sci_cmd_clk_get_freq; |
| 1809 | + |
| 1810 | + rm_core_ops->get_range = ti_sci_cmd_get_resource_range; |
| 1811 | + rm_core_ops->get_range_from_shost = |
| 1812 | + ti_sci_cmd_get_resource_range_from_shost; |
| 1643 | 1813 | } |
| 1644 | 1814 | |
| 1645 | 1815 | /** |