mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-30 08:56:45 +07:00
Qualcomm ARM Based SoC Updates for 4.3-rc2
* Fix errant private access in SMEM * Fix use of correct remote processor ID in SMD transactions * Correct SMD fBLOCKREADINTR handling -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAABAgAGBQJV8KPBAAoJEFKiBbHx2RXVWUwP/jn3Tth9UOBOem7/nLIPctQx O7knZBUJ3UtnC+xwkKFy/G6WYZ29ovCjzZ+3ExNQFFZNMkmE04c4x78J/XaO3gAl kwHLEsStmbAXyIi+gqDYFw7BS00yjB159gUg3zCZhfao5ZiaPDgI1tZAWgaU7ywp 7r6+VaJcN3/fhiNoV1PKSNy38w9yeS22MNdudkqeJm6Uumf30UXxsy8eMbZWYjgJ kpm7PGav/8mYEvrSWNe0nAuvkOTMNzTGjtwp9cQSZ+J0myZ4mOgHopNU2xAE0eaN TVrkxpyfiTkpa+x2Y3SGvIxNOepLT7BzL3V/NG3hBgHA/OApMjbBlQ+vDL6vsBbh UrRkpPCnwrH3q2GWOdrxlVKNxgfOmVEpQc1woj6Ykr1aFPSGK7OnqxKCQtD/BIkg zWZUVkbLyRYIcHql7tG9Q3TcjBG/nIV2XM76NJ1H06IrBRhpVA7mwDm11DfPma2Q y4641evunqJAZNTDtGpX/fyiqZeV5m9Md5PtOZKWuh83pqbk+X0tjZ0rsEt1K2wa szItTS896fKzP8DaGx0a0+1N4jsyJmWj1Dd6gR/Cz9wD+OasvBdIDvixYv7RPSXW kuAv2yzh8OPuCb5gWjVv0pOr/cMdvrJefvXhodcOQcjMEfSNCcBSc7StuKVg4qHw bEnGfjV5jj0NVr2hvTAw =w16T -----END PGP SIGNATURE----- Merge tag 'qcom-soc-for-4.3-rc2' of git://codeaurora.org/quic/kernel/agross-msm into next/late Qualcomm ARM Based SoC Updates for 4.3-rc2 * Fix errant private access in SMEM * Fix use of correct remote processor ID in SMD transactions * Correct SMD fBLOCKREADINTR handling * tag 'qcom-soc-for-4.3-rc2' of git://codeaurora.org/quic/kernel/agross-msm: soc: qcom: smd: Correct fBLOCKREADINTR handling soc: qcom: smd: Use correct remote processor ID soc: qcom: smem: Fix errant private access devicetree: soc: Add Qualcomm SMD based RPM DT binding soc: qcom: Driver for the Qualcomm RPM over SMD soc: qcom: Add Shared Memory Driver soc: qcom: Add device tree binding for Shared Memory Device drivers: qcom: Select QCOM_SCM unconditionally for QCOM_PM soc: qcom: Add Shared Memory Manager driver
This commit is contained in:
commit
c6e59bdac9
117
Documentation/devicetree/bindings/soc/qcom,smd-rpm.txt
Normal file
117
Documentation/devicetree/bindings/soc/qcom,smd-rpm.txt
Normal file
@ -0,0 +1,117 @@
|
||||
Qualcomm Resource Power Manager (RPM) over SMD
|
||||
|
||||
This driver is used to interface with the Resource Power Manager (RPM) found in
|
||||
various Qualcomm platforms. The RPM allows each component in the system to vote
|
||||
for state of the system resources, such as clocks, regulators and bus
|
||||
frequencies.
|
||||
|
||||
- compatible:
|
||||
Usage: required
|
||||
Value type: <string>
|
||||
Definition: must be one of:
|
||||
"qcom,rpm-msm8974"
|
||||
|
||||
- qcom,smd-channels:
|
||||
Usage: required
|
||||
Value type: <stringlist>
|
||||
Definition: Shared Memory channel used for communication with the RPM
|
||||
|
||||
= SUBDEVICES
|
||||
|
||||
The RPM exposes resources to its subnodes. The below bindings specify the set
|
||||
of valid subnodes that can operate on these resources.
|
||||
|
||||
== Regulators
|
||||
|
||||
Regulator nodes are identified by their compatible:
|
||||
|
||||
- compatible:
|
||||
Usage: required
|
||||
Value type: <string>
|
||||
Definition: must be one of:
|
||||
"qcom,rpm-pm8841-regulators"
|
||||
"qcom,rpm-pm8941-regulators"
|
||||
|
||||
- vdd_s1-supply:
|
||||
- vdd_s2-supply:
|
||||
- vdd_s3-supply:
|
||||
- vdd_s4-supply:
|
||||
- vdd_s5-supply:
|
||||
- vdd_s6-supply:
|
||||
- vdd_s7-supply:
|
||||
- vdd_s8-supply:
|
||||
Usage: optional (pm8841 only)
|
||||
Value type: <phandle>
|
||||
Definition: reference to regulator supplying the input pin, as
|
||||
described in the data sheet
|
||||
|
||||
- vdd_s1-supply:
|
||||
- vdd_s2-supply:
|
||||
- vdd_s3-supply:
|
||||
- vdd_l1_l3-supply:
|
||||
- vdd_l2_lvs1_2_3-supply:
|
||||
- vdd_l4_l11-supply:
|
||||
- vdd_l5_l7-supply:
|
||||
- vdd_l6_l12_l14_l15-supply:
|
||||
- vdd_l8_l16_l18_l19-supply:
|
||||
- vdd_l9_l10_l17_l22-supply:
|
||||
- vdd_l13_l20_l23_l24-supply:
|
||||
- vdd_l21-supply:
|
||||
- vin_5vs-supply:
|
||||
Usage: optional (pm8941 only)
|
||||
Value type: <phandle>
|
||||
Definition: reference to regulator supplying the input pin, as
|
||||
described in the data sheet
|
||||
|
||||
The regulator node houses sub-nodes for each regulator within the device. Each
|
||||
sub-node is identified using the node's name, with valid values listed for each
|
||||
of the pmics below.
|
||||
|
||||
pm8841:
|
||||
s1, s2, s3, s4, s5, s6, s7, s8
|
||||
|
||||
pm8941:
|
||||
s1, s2, s3, s4, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13,
|
||||
l14, l15, l16, l17, l18, l19, l20, l21, l22, l23, l24, lvs1, lvs2,
|
||||
lvs3, 5vs1, 5vs2
|
||||
|
||||
The content of each sub-node is defined by the standard binding for regulators -
|
||||
see regulator.txt.
|
||||
|
||||
= EXAMPLE
|
||||
|
||||
smd {
|
||||
compatible = "qcom,smd";
|
||||
|
||||
rpm {
|
||||
interrupts = <0 168 1>;
|
||||
qcom,ipc = <&apcs 8 0>;
|
||||
qcom,smd-edge = <15>;
|
||||
|
||||
rpm_requests {
|
||||
compatible = "qcom,rpm-msm8974";
|
||||
qcom,smd-channels = "rpm_requests";
|
||||
|
||||
pm8941-regulators {
|
||||
compatible = "qcom,rpm-pm8941-regulators";
|
||||
vdd_l13_l20_l23_l24-supply = <&pm8941_boost>;
|
||||
|
||||
pm8941_s3: s3 {
|
||||
regulator-min-microvolt = <1800000>;
|
||||
regulator-max-microvolt = <1800000>;
|
||||
};
|
||||
|
||||
pm8941_boost: s4 {
|
||||
regulator-min-microvolt = <5000000>;
|
||||
regulator-max-microvolt = <5000000>;
|
||||
};
|
||||
|
||||
pm8941_l20: l20 {
|
||||
regulator-min-microvolt = <2950000>;
|
||||
regulator-max-microvolt = <2950000>;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
85
Documentation/devicetree/bindings/soc/qcom/qcom,smd.txt
Normal file
85
Documentation/devicetree/bindings/soc/qcom/qcom,smd.txt
Normal file
@ -0,0 +1,85 @@
|
||||
Qualcomm Shared Memory Driver (SMD) binding
|
||||
|
||||
This binding describes the Qualcomm Shared Memory Driver, a fifo based
|
||||
communication channel for sending data between the various subsystems in
|
||||
Qualcomm platforms.
|
||||
|
||||
- compatible:
|
||||
Usage: required
|
||||
Value type: <stringlist>
|
||||
Definition: must be "qcom,smd"
|
||||
|
||||
= EDGES
|
||||
|
||||
Each subnode of the SMD node represents a remote subsystem or a remote
|
||||
processor of some sort - or in SMD language an "edge". The name of the edges
|
||||
are not important.
|
||||
The edge is described by the following properties:
|
||||
|
||||
- interrupts:
|
||||
Usage: required
|
||||
Value type: <prop-encoded-array>
|
||||
Definition: should specify the IRQ used by the remote processor to
|
||||
signal this processor about communication related updates
|
||||
|
||||
- qcom,ipc:
|
||||
Usage: required
|
||||
Value type: <prop-encoded-array>
|
||||
Definition: three entries specifying the outgoing ipc bit used for
|
||||
signaling the remote processor:
|
||||
- phandle to a syscon node representing the apcs registers
|
||||
- u32 representing offset to the register within the syscon
|
||||
- u32 representing the ipc bit within the register
|
||||
|
||||
- qcom,smd-edge:
|
||||
Usage: required
|
||||
Value type: <u32>
|
||||
Definition: the identifier of the remote processor in the smd channel
|
||||
allocation table
|
||||
|
||||
- qcom,remote-pid:
|
||||
Usage: optional
|
||||
Value type: <u32>
|
||||
Definition: the identifier for the remote processor as known by the rest
|
||||
of the system.
|
||||
|
||||
= SMD DEVICES
|
||||
|
||||
In turn, subnodes of the "edges" represent devices tied to SMD channels on that
|
||||
"edge". The names of the devices are not important. The properties of these
|
||||
nodes are defined by the individual bindings for the SMD devices - but must
|
||||
contain the following property:
|
||||
|
||||
- qcom,smd-channels:
|
||||
Usage: required
|
||||
Value type: <stringlist>
|
||||
Definition: a list of channels tied to this device, used for matching
|
||||
the device to channels
|
||||
|
||||
= EXAMPLE
|
||||
|
||||
The following example represents a smd node, with one edge representing the
|
||||
"rpm" subsystem. For the "rpm" subsystem we have a device tied to the
|
||||
"rpm_request" channel.
|
||||
|
||||
apcs: syscon@f9011000 {
|
||||
compatible = "syscon";
|
||||
reg = <0xf9011000 0x1000>;
|
||||
};
|
||||
|
||||
smd {
|
||||
compatible = "qcom,smd";
|
||||
|
||||
rpm {
|
||||
interrupts = <0 168 1>;
|
||||
qcom,ipc = <&apcs 8 0>;
|
||||
qcom,smd-edge = <15>;
|
||||
|
||||
rpm_requests {
|
||||
compatible = "qcom,rpm-msm8974";
|
||||
qcom,smd-channels = "rpm_requests";
|
||||
|
||||
...
|
||||
};
|
||||
};
|
||||
};
|
@ -13,7 +13,38 @@ config QCOM_GSBI
|
||||
config QCOM_PM
|
||||
bool "Qualcomm Power Management"
|
||||
depends on ARCH_QCOM && !ARM64
|
||||
select QCOM_SCM
|
||||
help
|
||||
QCOM Platform specific power driver to manage cores and L2 low power
|
||||
modes. It interface with various system drivers to put the cores in
|
||||
low power modes.
|
||||
|
||||
config QCOM_SMD
|
||||
tristate "Qualcomm Shared Memory Driver (SMD)"
|
||||
depends on QCOM_SMEM
|
||||
help
|
||||
Say y here to enable support for the Qualcomm Shared Memory Driver
|
||||
providing communication channels to remote processors in Qualcomm
|
||||
platforms.
|
||||
|
||||
config QCOM_SMD_RPM
|
||||
tristate "Qualcomm Resource Power Manager (RPM) over SMD"
|
||||
depends on QCOM_SMD && OF
|
||||
help
|
||||
If you say yes to this option, support will be included for the
|
||||
Resource Power Manager system found in the Qualcomm 8974 based
|
||||
devices.
|
||||
|
||||
This is required to access many regulators, clocks and bus
|
||||
frequencies controlled by the RPM on these devices.
|
||||
|
||||
Say M here if you want to include support for the Qualcomm RPM as a
|
||||
module. This will build a module called "qcom-smd-rpm".
|
||||
|
||||
config QCOM_SMEM
|
||||
tristate "Qualcomm Shared Memory Manager (SMEM)"
|
||||
depends on ARCH_QCOM
|
||||
help
|
||||
Say y here to enable support for the Qualcomm Shared Memory Manager.
|
||||
The driver provides an interface to items in a heap shared among all
|
||||
processors in a Qualcomm platform.
|
||||
|
@ -1,2 +1,5 @@
|
||||
obj-$(CONFIG_QCOM_GSBI) += qcom_gsbi.o
|
||||
obj-$(CONFIG_QCOM_PM) += spm.o
|
||||
obj-$(CONFIG_QCOM_SMD) += smd.o
|
||||
obj-$(CONFIG_QCOM_SMD_RPM) += smd-rpm.o
|
||||
obj-$(CONFIG_QCOM_SMEM) += smem.o
|
||||
|
244
drivers/soc/qcom/smd-rpm.c
Normal file
244
drivers/soc/qcom/smd-rpm.c
Normal file
@ -0,0 +1,244 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Sony Mobile Communications AB.
|
||||
* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 and
|
||||
* only version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/interrupt.h>
|
||||
|
||||
#include <linux/soc/qcom/smd.h>
|
||||
#include <linux/soc/qcom/smd-rpm.h>
|
||||
|
||||
#define RPM_REQUEST_TIMEOUT (5 * HZ)
|
||||
|
||||
/**
|
||||
* struct qcom_smd_rpm - state of the rpm device driver
|
||||
* @rpm_channel: reference to the smd channel
|
||||
* @ack: completion for acks
|
||||
* @lock: mutual exclusion around the send/complete pair
|
||||
* @ack_status: result of the rpm request
|
||||
*/
|
||||
struct qcom_smd_rpm {
|
||||
struct qcom_smd_channel *rpm_channel;
|
||||
|
||||
struct completion ack;
|
||||
struct mutex lock;
|
||||
int ack_status;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct qcom_rpm_header - header for all rpm requests and responses
|
||||
* @service_type: identifier of the service
|
||||
* @length: length of the payload
|
||||
*/
|
||||
struct qcom_rpm_header {
|
||||
u32 service_type;
|
||||
u32 length;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct qcom_rpm_request - request message to the rpm
|
||||
* @msg_id: identifier of the outgoing message
|
||||
* @flags: active/sleep state flags
|
||||
* @type: resource type
|
||||
* @id: resource id
|
||||
* @data_len: length of the payload following this header
|
||||
*/
|
||||
struct qcom_rpm_request {
|
||||
u32 msg_id;
|
||||
u32 flags;
|
||||
u32 type;
|
||||
u32 id;
|
||||
u32 data_len;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct qcom_rpm_message - response message from the rpm
|
||||
* @msg_type: indicator of the type of message
|
||||
* @length: the size of this message, including the message header
|
||||
* @msg_id: message id
|
||||
* @message: textual message from the rpm
|
||||
*
|
||||
* Multiple of these messages can be stacked in an rpm message.
|
||||
*/
|
||||
struct qcom_rpm_message {
|
||||
u32 msg_type;
|
||||
u32 length;
|
||||
union {
|
||||
u32 msg_id;
|
||||
u8 message[0];
|
||||
};
|
||||
};
|
||||
|
||||
#define RPM_SERVICE_TYPE_REQUEST 0x00716572 /* "req\0" */
|
||||
|
||||
#define RPM_MSG_TYPE_ERR 0x00727265 /* "err\0" */
|
||||
#define RPM_MSG_TYPE_MSG_ID 0x2367736d /* "msg#" */
|
||||
|
||||
/**
|
||||
* qcom_rpm_smd_write - write @buf to @type:@id
|
||||
* @rpm: rpm handle
|
||||
* @type: resource type
|
||||
* @id: resource identifier
|
||||
* @buf: the data to be written
|
||||
* @count: number of bytes in @buf
|
||||
*/
|
||||
int qcom_rpm_smd_write(struct qcom_smd_rpm *rpm,
|
||||
int state,
|
||||
u32 type, u32 id,
|
||||
void *buf,
|
||||
size_t count)
|
||||
{
|
||||
static unsigned msg_id = 1;
|
||||
int left;
|
||||
int ret;
|
||||
|
||||
struct {
|
||||
struct qcom_rpm_header hdr;
|
||||
struct qcom_rpm_request req;
|
||||
u8 payload[count];
|
||||
} pkt;
|
||||
|
||||
/* SMD packets to the RPM may not exceed 256 bytes */
|
||||
if (WARN_ON(sizeof(pkt) >= 256))
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&rpm->lock);
|
||||
|
||||
pkt.hdr.service_type = RPM_SERVICE_TYPE_REQUEST;
|
||||
pkt.hdr.length = sizeof(struct qcom_rpm_request) + count;
|
||||
|
||||
pkt.req.msg_id = msg_id++;
|
||||
pkt.req.flags = BIT(state);
|
||||
pkt.req.type = type;
|
||||
pkt.req.id = id;
|
||||
pkt.req.data_len = count;
|
||||
memcpy(pkt.payload, buf, count);
|
||||
|
||||
ret = qcom_smd_send(rpm->rpm_channel, &pkt, sizeof(pkt));
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
left = wait_for_completion_timeout(&rpm->ack, RPM_REQUEST_TIMEOUT);
|
||||
if (!left)
|
||||
ret = -ETIMEDOUT;
|
||||
else
|
||||
ret = rpm->ack_status;
|
||||
|
||||
out:
|
||||
mutex_unlock(&rpm->lock);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(qcom_rpm_smd_write);
|
||||
|
||||
static int qcom_smd_rpm_callback(struct qcom_smd_device *qsdev,
|
||||
const void *data,
|
||||
size_t count)
|
||||
{
|
||||
const struct qcom_rpm_header *hdr = data;
|
||||
const struct qcom_rpm_message *msg;
|
||||
struct qcom_smd_rpm *rpm = dev_get_drvdata(&qsdev->dev);
|
||||
const u8 *buf = data + sizeof(struct qcom_rpm_header);
|
||||
const u8 *end = buf + hdr->length;
|
||||
char msgbuf[32];
|
||||
int status = 0;
|
||||
u32 len;
|
||||
|
||||
if (hdr->service_type != RPM_SERVICE_TYPE_REQUEST ||
|
||||
hdr->length < sizeof(struct qcom_rpm_message)) {
|
||||
dev_err(&qsdev->dev, "invalid request\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (buf < end) {
|
||||
msg = (struct qcom_rpm_message *)buf;
|
||||
switch (msg->msg_type) {
|
||||
case RPM_MSG_TYPE_MSG_ID:
|
||||
break;
|
||||
case RPM_MSG_TYPE_ERR:
|
||||
len = min_t(u32, ALIGN(msg->length, 4), sizeof(msgbuf));
|
||||
memcpy_fromio(msgbuf, msg->message, len);
|
||||
msgbuf[len - 1] = 0;
|
||||
|
||||
if (!strcmp(msgbuf, "resource does not exist"))
|
||||
status = -ENXIO;
|
||||
else
|
||||
status = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
buf = PTR_ALIGN(buf + 2 * sizeof(u32) + msg->length, 4);
|
||||
}
|
||||
|
||||
rpm->ack_status = status;
|
||||
complete(&rpm->ack);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qcom_smd_rpm_probe(struct qcom_smd_device *sdev)
|
||||
{
|
||||
struct qcom_smd_rpm *rpm;
|
||||
|
||||
rpm = devm_kzalloc(&sdev->dev, sizeof(*rpm), GFP_KERNEL);
|
||||
if (!rpm)
|
||||
return -ENOMEM;
|
||||
|
||||
mutex_init(&rpm->lock);
|
||||
init_completion(&rpm->ack);
|
||||
|
||||
rpm->rpm_channel = sdev->channel;
|
||||
|
||||
dev_set_drvdata(&sdev->dev, rpm);
|
||||
|
||||
return of_platform_populate(sdev->dev.of_node, NULL, NULL, &sdev->dev);
|
||||
}
|
||||
|
||||
static void qcom_smd_rpm_remove(struct qcom_smd_device *sdev)
|
||||
{
|
||||
of_platform_depopulate(&sdev->dev);
|
||||
}
|
||||
|
||||
static const struct of_device_id qcom_smd_rpm_of_match[] = {
|
||||
{ .compatible = "qcom,rpm-msm8974" },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, qcom_smd_rpm_of_match);
|
||||
|
||||
static struct qcom_smd_driver qcom_smd_rpm_driver = {
|
||||
.probe = qcom_smd_rpm_probe,
|
||||
.remove = qcom_smd_rpm_remove,
|
||||
.callback = qcom_smd_rpm_callback,
|
||||
.driver = {
|
||||
.name = "qcom_smd_rpm",
|
||||
.owner = THIS_MODULE,
|
||||
.of_match_table = qcom_smd_rpm_of_match,
|
||||
},
|
||||
};
|
||||
|
||||
static int __init qcom_smd_rpm_init(void)
|
||||
{
|
||||
return qcom_smd_driver_register(&qcom_smd_rpm_driver);
|
||||
}
|
||||
arch_initcall(qcom_smd_rpm_init);
|
||||
|
||||
static void __exit qcom_smd_rpm_exit(void)
|
||||
{
|
||||
qcom_smd_driver_unregister(&qcom_smd_rpm_driver);
|
||||
}
|
||||
module_exit(qcom_smd_rpm_exit);
|
||||
|
||||
MODULE_AUTHOR("Bjorn Andersson <bjorn.andersson@sonymobile.com>");
|
||||
MODULE_DESCRIPTION("Qualcomm SMD backed RPM driver");
|
||||
MODULE_LICENSE("GPL v2");
|
1327
drivers/soc/qcom/smd.c
Normal file
1327
drivers/soc/qcom/smd.c
Normal file
File diff suppressed because it is too large
Load Diff
769
drivers/soc/qcom/smem.c
Normal file
769
drivers/soc/qcom/smem.c
Normal file
@ -0,0 +1,769 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Sony Mobile Communications AB.
|
||||
* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 and
|
||||
* only version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <linux/hwspinlock.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_address.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/soc/qcom/smem.h>
|
||||
|
||||
/*
|
||||
* The Qualcomm shared memory system is a allocate only heap structure that
|
||||
* consists of one of more memory areas that can be accessed by the processors
|
||||
* in the SoC.
|
||||
*
|
||||
* All systems contains a global heap, accessible by all processors in the SoC,
|
||||
* with a table of contents data structure (@smem_header) at the beginning of
|
||||
* the main shared memory block.
|
||||
*
|
||||
* The global header contains meta data for allocations as well as a fixed list
|
||||
* of 512 entries (@smem_global_entry) that can be initialized to reference
|
||||
* parts of the shared memory space.
|
||||
*
|
||||
*
|
||||
* In addition to this global heap a set of "private" heaps can be set up at
|
||||
* boot time with access restrictions so that only certain processor pairs can
|
||||
* access the data.
|
||||
*
|
||||
* These partitions are referenced from an optional partition table
|
||||
* (@smem_ptable), that is found 4kB from the end of the main smem region. The
|
||||
* partition table entries (@smem_ptable_entry) lists the involved processors
|
||||
* (or hosts) and their location in the main shared memory region.
|
||||
*
|
||||
* Each partition starts with a header (@smem_partition_header) that identifies
|
||||
* the partition and holds properties for the two internal memory regions. The
|
||||
* two regions are cached and non-cached memory respectively. Each region
|
||||
* contain a link list of allocation headers (@smem_private_entry) followed by
|
||||
* their data.
|
||||
*
|
||||
* Items in the non-cached region are allocated from the start of the partition
|
||||
* while items in the cached region are allocated from the end. The free area
|
||||
* is hence the region between the cached and non-cached offsets.
|
||||
*
|
||||
*
|
||||
* To synchronize allocations in the shared memory heaps a remote spinlock must
|
||||
* be held - currently lock number 3 of the sfpb or tcsr is used for this on all
|
||||
* platforms.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Item 3 of the global heap contains an array of versions for the various
|
||||
* software components in the SoC. We verify that the boot loader version is
|
||||
* what the expected version (SMEM_EXPECTED_VERSION) as a sanity check.
|
||||
*/
|
||||
#define SMEM_ITEM_VERSION 3
|
||||
#define SMEM_MASTER_SBL_VERSION_INDEX 7
|
||||
#define SMEM_EXPECTED_VERSION 11
|
||||
|
||||
/*
|
||||
* The first 8 items are only to be allocated by the boot loader while
|
||||
* initializing the heap.
|
||||
*/
|
||||
#define SMEM_ITEM_LAST_FIXED 8
|
||||
|
||||
/* Highest accepted item number, for both global and private heaps */
|
||||
#define SMEM_ITEM_COUNT 512
|
||||
|
||||
/* Processor/host identifier for the application processor */
|
||||
#define SMEM_HOST_APPS 0
|
||||
|
||||
/* Max number of processors/hosts in a system */
|
||||
#define SMEM_HOST_COUNT 9
|
||||
|
||||
/**
|
||||
* struct smem_proc_comm - proc_comm communication struct (legacy)
|
||||
* @command: current command to be executed
|
||||
* @status: status of the currently requested command
|
||||
* @params: parameters to the command
|
||||
*/
|
||||
struct smem_proc_comm {
|
||||
u32 command;
|
||||
u32 status;
|
||||
u32 params[2];
|
||||
};
|
||||
|
||||
/**
|
||||
* struct smem_global_entry - entry to reference smem items on the heap
|
||||
* @allocated: boolean to indicate if this entry is used
|
||||
* @offset: offset to the allocated space
|
||||
* @size: size of the allocated space, 8 byte aligned
|
||||
* @aux_base: base address for the memory region used by this unit, or 0 for
|
||||
* the default region. bits 0,1 are reserved
|
||||
*/
|
||||
struct smem_global_entry {
|
||||
u32 allocated;
|
||||
u32 offset;
|
||||
u32 size;
|
||||
u32 aux_base; /* bits 1:0 reserved */
|
||||
};
|
||||
#define AUX_BASE_MASK 0xfffffffc
|
||||
|
||||
/**
|
||||
* struct smem_header - header found in beginning of primary smem region
|
||||
* @proc_comm: proc_comm communication interface (legacy)
|
||||
* @version: array of versions for the various subsystems
|
||||
* @initialized: boolean to indicate that smem is initialized
|
||||
* @free_offset: index of the first unallocated byte in smem
|
||||
* @available: number of bytes available for allocation
|
||||
* @reserved: reserved field, must be 0
|
||||
* toc: array of references to items
|
||||
*/
|
||||
struct smem_header {
|
||||
struct smem_proc_comm proc_comm[4];
|
||||
u32 version[32];
|
||||
u32 initialized;
|
||||
u32 free_offset;
|
||||
u32 available;
|
||||
u32 reserved;
|
||||
struct smem_global_entry toc[SMEM_ITEM_COUNT];
|
||||
};
|
||||
|
||||
/**
|
||||
* struct smem_ptable_entry - one entry in the @smem_ptable list
|
||||
* @offset: offset, within the main shared memory region, of the partition
|
||||
* @size: size of the partition
|
||||
* @flags: flags for the partition (currently unused)
|
||||
* @host0: first processor/host with access to this partition
|
||||
* @host1: second processor/host with access to this partition
|
||||
* @reserved: reserved entries for later use
|
||||
*/
|
||||
struct smem_ptable_entry {
|
||||
u32 offset;
|
||||
u32 size;
|
||||
u32 flags;
|
||||
u16 host0;
|
||||
u16 host1;
|
||||
u32 reserved[8];
|
||||
};
|
||||
|
||||
/**
|
||||
* struct smem_ptable - partition table for the private partitions
|
||||
* @magic: magic number, must be SMEM_PTABLE_MAGIC
|
||||
* @version: version of the partition table
|
||||
* @num_entries: number of partitions in the table
|
||||
* @reserved: for now reserved entries
|
||||
* @entry: list of @smem_ptable_entry for the @num_entries partitions
|
||||
*/
|
||||
struct smem_ptable {
|
||||
u32 magic;
|
||||
u32 version;
|
||||
u32 num_entries;
|
||||
u32 reserved[5];
|
||||
struct smem_ptable_entry entry[];
|
||||
};
|
||||
#define SMEM_PTABLE_MAGIC 0x434f5424 /* "$TOC" */
|
||||
|
||||
/**
|
||||
* struct smem_partition_header - header of the partitions
|
||||
* @magic: magic number, must be SMEM_PART_MAGIC
|
||||
* @host0: first processor/host with access to this partition
|
||||
* @host1: second processor/host with access to this partition
|
||||
* @size: size of the partition
|
||||
* @offset_free_uncached: offset to the first free byte of uncached memory in
|
||||
* this partition
|
||||
* @offset_free_cached: offset to the first free byte of cached memory in this
|
||||
* partition
|
||||
* @reserved: for now reserved entries
|
||||
*/
|
||||
struct smem_partition_header {
|
||||
u32 magic;
|
||||
u16 host0;
|
||||
u16 host1;
|
||||
u32 size;
|
||||
u32 offset_free_uncached;
|
||||
u32 offset_free_cached;
|
||||
u32 reserved[3];
|
||||
};
|
||||
#define SMEM_PART_MAGIC 0x54525024 /* "$PRT" */
|
||||
|
||||
/**
|
||||
* struct smem_private_entry - header of each item in the private partition
|
||||
* @canary: magic number, must be SMEM_PRIVATE_CANARY
|
||||
* @item: identifying number of the smem item
|
||||
* @size: size of the data, including padding bytes
|
||||
* @padding_data: number of bytes of padding of data
|
||||
* @padding_hdr: number of bytes of padding between the header and the data
|
||||
* @reserved: for now reserved entry
|
||||
*/
|
||||
struct smem_private_entry {
|
||||
u16 canary;
|
||||
u16 item;
|
||||
u32 size; /* includes padding bytes */
|
||||
u16 padding_data;
|
||||
u16 padding_hdr;
|
||||
u32 reserved;
|
||||
};
|
||||
#define SMEM_PRIVATE_CANARY 0xa5a5
|
||||
|
||||
/**
|
||||
* struct smem_region - representation of a chunk of memory used for smem
|
||||
* @aux_base: identifier of aux_mem base
|
||||
* @virt_base: virtual base address of memory with this aux_mem identifier
|
||||
* @size: size of the memory region
|
||||
*/
|
||||
struct smem_region {
|
||||
u32 aux_base;
|
||||
void __iomem *virt_base;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct qcom_smem - device data for the smem device
|
||||
* @dev: device pointer
|
||||
* @hwlock: reference to a hwspinlock
|
||||
* @partitions: list of pointers to partitions affecting the current
|
||||
* processor/host
|
||||
* @num_regions: number of @regions
|
||||
* @regions: list of the memory regions defining the shared memory
|
||||
*/
|
||||
struct qcom_smem {
|
||||
struct device *dev;
|
||||
|
||||
struct hwspinlock *hwlock;
|
||||
|
||||
struct smem_partition_header *partitions[SMEM_HOST_COUNT];
|
||||
|
||||
unsigned num_regions;
|
||||
struct smem_region regions[0];
|
||||
};
|
||||
|
||||
/* Pointer to the one and only smem handle */
|
||||
static struct qcom_smem *__smem;
|
||||
|
||||
/* Timeout (ms) for the trylock of remote spinlocks */
|
||||
#define HWSPINLOCK_TIMEOUT 1000
|
||||
|
||||
static int qcom_smem_alloc_private(struct qcom_smem *smem,
|
||||
unsigned host,
|
||||
unsigned item,
|
||||
size_t size)
|
||||
{
|
||||
struct smem_partition_header *phdr;
|
||||
struct smem_private_entry *hdr;
|
||||
size_t alloc_size;
|
||||
void *p;
|
||||
|
||||
phdr = smem->partitions[host];
|
||||
|
||||
p = (void *)phdr + sizeof(*phdr);
|
||||
while (p < (void *)phdr + phdr->offset_free_uncached) {
|
||||
hdr = p;
|
||||
|
||||
if (hdr->canary != SMEM_PRIVATE_CANARY) {
|
||||
dev_err(smem->dev,
|
||||
"Found invalid canary in host %d partition\n",
|
||||
host);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (hdr->item == item)
|
||||
return -EEXIST;
|
||||
|
||||
p += sizeof(*hdr) + hdr->padding_hdr + hdr->size;
|
||||
}
|
||||
|
||||
/* Check that we don't grow into the cached region */
|
||||
alloc_size = sizeof(*hdr) + ALIGN(size, 8);
|
||||
if (p + alloc_size >= (void *)phdr + phdr->offset_free_cached) {
|
||||
dev_err(smem->dev, "Out of memory\n");
|
||||
return -ENOSPC;
|
||||
}
|
||||
|
||||
hdr = p;
|
||||
hdr->canary = SMEM_PRIVATE_CANARY;
|
||||
hdr->item = item;
|
||||
hdr->size = ALIGN(size, 8);
|
||||
hdr->padding_data = hdr->size - size;
|
||||
hdr->padding_hdr = 0;
|
||||
|
||||
/*
|
||||
* Ensure the header is written before we advance the free offset, so
|
||||
* that remote processors that does not take the remote spinlock still
|
||||
* gets a consistent view of the linked list.
|
||||
*/
|
||||
wmb();
|
||||
phdr->offset_free_uncached += alloc_size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qcom_smem_alloc_global(struct qcom_smem *smem,
|
||||
unsigned item,
|
||||
size_t size)
|
||||
{
|
||||
struct smem_header *header;
|
||||
struct smem_global_entry *entry;
|
||||
|
||||
if (WARN_ON(item >= SMEM_ITEM_COUNT))
|
||||
return -EINVAL;
|
||||
|
||||
header = smem->regions[0].virt_base;
|
||||
entry = &header->toc[item];
|
||||
if (entry->allocated)
|
||||
return -EEXIST;
|
||||
|
||||
size = ALIGN(size, 8);
|
||||
if (WARN_ON(size > header->available))
|
||||
return -ENOMEM;
|
||||
|
||||
entry->offset = header->free_offset;
|
||||
entry->size = size;
|
||||
|
||||
/*
|
||||
* Ensure the header is consistent before we mark the item allocated,
|
||||
* so that remote processors will get a consistent view of the item
|
||||
* even though they do not take the spinlock on read.
|
||||
*/
|
||||
wmb();
|
||||
entry->allocated = 1;
|
||||
|
||||
header->free_offset += size;
|
||||
header->available -= size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* qcom_smem_alloc() - allocate space for a smem item
|
||||
* @host: remote processor id, or -1
|
||||
* @item: smem item handle
|
||||
* @size: number of bytes to be allocated
|
||||
*
|
||||
* Allocate space for a given smem item of size @size, given that the item is
|
||||
* not yet allocated.
|
||||
*/
|
||||
int qcom_smem_alloc(unsigned host, unsigned item, size_t size)
|
||||
{
|
||||
unsigned long flags;
|
||||
int ret;
|
||||
|
||||
if (!__smem)
|
||||
return -EPROBE_DEFER;
|
||||
|
||||
if (item < SMEM_ITEM_LAST_FIXED) {
|
||||
dev_err(__smem->dev,
|
||||
"Rejecting allocation of static entry %d\n", item);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = hwspin_lock_timeout_irqsave(__smem->hwlock,
|
||||
HWSPINLOCK_TIMEOUT,
|
||||
&flags);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (host < SMEM_HOST_COUNT && __smem->partitions[host])
|
||||
ret = qcom_smem_alloc_private(__smem, host, item, size);
|
||||
else
|
||||
ret = qcom_smem_alloc_global(__smem, item, size);
|
||||
|
||||
hwspin_unlock_irqrestore(__smem->hwlock, &flags);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(qcom_smem_alloc);
|
||||
|
||||
static int qcom_smem_get_global(struct qcom_smem *smem,
|
||||
unsigned item,
|
||||
void **ptr,
|
||||
size_t *size)
|
||||
{
|
||||
struct smem_header *header;
|
||||
struct smem_region *area;
|
||||
struct smem_global_entry *entry;
|
||||
u32 aux_base;
|
||||
unsigned i;
|
||||
|
||||
if (WARN_ON(item >= SMEM_ITEM_COUNT))
|
||||
return -EINVAL;
|
||||
|
||||
header = smem->regions[0].virt_base;
|
||||
entry = &header->toc[item];
|
||||
if (!entry->allocated)
|
||||
return -ENXIO;
|
||||
|
||||
if (ptr != NULL) {
|
||||
aux_base = entry->aux_base & AUX_BASE_MASK;
|
||||
|
||||
for (i = 0; i < smem->num_regions; i++) {
|
||||
area = &smem->regions[i];
|
||||
|
||||
if (area->aux_base == aux_base || !aux_base) {
|
||||
*ptr = area->virt_base + entry->offset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (size != NULL)
|
||||
*size = entry->size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qcom_smem_get_private(struct qcom_smem *smem,
|
||||
unsigned host,
|
||||
unsigned item,
|
||||
void **ptr,
|
||||
size_t *size)
|
||||
{
|
||||
struct smem_partition_header *phdr;
|
||||
struct smem_private_entry *hdr;
|
||||
void *p;
|
||||
|
||||
phdr = smem->partitions[host];
|
||||
|
||||
p = (void *)phdr + sizeof(*phdr);
|
||||
while (p < (void *)phdr + phdr->offset_free_uncached) {
|
||||
hdr = p;
|
||||
|
||||
if (hdr->canary != SMEM_PRIVATE_CANARY) {
|
||||
dev_err(smem->dev,
|
||||
"Found invalid canary in host %d partition\n",
|
||||
host);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (hdr->item == item) {
|
||||
if (ptr != NULL)
|
||||
*ptr = p + sizeof(*hdr) + hdr->padding_hdr;
|
||||
|
||||
if (size != NULL)
|
||||
*size = hdr->size - hdr->padding_data;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
p += sizeof(*hdr) + hdr->padding_hdr + hdr->size;
|
||||
}
|
||||
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* qcom_smem_get() - resolve ptr of size of a smem item
|
||||
* @host: the remote processor, or -1
|
||||
* @item: smem item handle
|
||||
* @ptr: pointer to be filled out with address of the item
|
||||
* @size: pointer to be filled out with size of the item
|
||||
*
|
||||
* Looks up pointer and size of a smem item.
|
||||
*/
|
||||
int qcom_smem_get(unsigned host, unsigned item, void **ptr, size_t *size)
|
||||
{
|
||||
unsigned long flags;
|
||||
int ret;
|
||||
|
||||
if (!__smem)
|
||||
return -EPROBE_DEFER;
|
||||
|
||||
ret = hwspin_lock_timeout_irqsave(__smem->hwlock,
|
||||
HWSPINLOCK_TIMEOUT,
|
||||
&flags);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (host < SMEM_HOST_COUNT && __smem->partitions[host])
|
||||
ret = qcom_smem_get_private(__smem, host, item, ptr, size);
|
||||
else
|
||||
ret = qcom_smem_get_global(__smem, item, ptr, size);
|
||||
|
||||
hwspin_unlock_irqrestore(__smem->hwlock, &flags);
|
||||
return ret;
|
||||
|
||||
}
|
||||
EXPORT_SYMBOL(qcom_smem_get);
|
||||
|
||||
/**
|
||||
* qcom_smem_get_free_space() - retrieve amount of free space in a partition
|
||||
* @host: the remote processor identifying a partition, or -1
|
||||
*
|
||||
* To be used by smem clients as a quick way to determine if any new
|
||||
* allocations has been made.
|
||||
*/
|
||||
int qcom_smem_get_free_space(unsigned host)
|
||||
{
|
||||
struct smem_partition_header *phdr;
|
||||
struct smem_header *header;
|
||||
unsigned ret;
|
||||
|
||||
if (!__smem)
|
||||
return -EPROBE_DEFER;
|
||||
|
||||
if (host < SMEM_HOST_COUNT && __smem->partitions[host]) {
|
||||
phdr = __smem->partitions[host];
|
||||
ret = phdr->offset_free_cached - phdr->offset_free_uncached;
|
||||
} else {
|
||||
header = __smem->regions[0].virt_base;
|
||||
ret = header->available;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(qcom_smem_get_free_space);
|
||||
|
||||
static int qcom_smem_get_sbl_version(struct qcom_smem *smem)
|
||||
{
|
||||
unsigned *versions;
|
||||
size_t size;
|
||||
int ret;
|
||||
|
||||
ret = qcom_smem_get_global(smem, SMEM_ITEM_VERSION,
|
||||
(void **)&versions, &size);
|
||||
if (ret < 0) {
|
||||
dev_err(smem->dev, "Unable to read the version item\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if (size < sizeof(unsigned) * SMEM_MASTER_SBL_VERSION_INDEX) {
|
||||
dev_err(smem->dev, "Version item is too small\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return versions[SMEM_MASTER_SBL_VERSION_INDEX];
|
||||
}
|
||||
|
||||
static int qcom_smem_enumerate_partitions(struct qcom_smem *smem,
|
||||
unsigned local_host)
|
||||
{
|
||||
struct smem_partition_header *header;
|
||||
struct smem_ptable_entry *entry;
|
||||
struct smem_ptable *ptable;
|
||||
unsigned remote_host;
|
||||
int i;
|
||||
|
||||
ptable = smem->regions[0].virt_base + smem->regions[0].size - SZ_4K;
|
||||
if (ptable->magic != SMEM_PTABLE_MAGIC)
|
||||
return 0;
|
||||
|
||||
if (ptable->version != 1) {
|
||||
dev_err(smem->dev,
|
||||
"Unsupported partition header version %d\n",
|
||||
ptable->version);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
for (i = 0; i < ptable->num_entries; i++) {
|
||||
entry = &ptable->entry[i];
|
||||
|
||||
if (entry->host0 != local_host && entry->host1 != local_host)
|
||||
continue;
|
||||
|
||||
if (!entry->offset)
|
||||
continue;
|
||||
|
||||
if (!entry->size)
|
||||
continue;
|
||||
|
||||
if (entry->host0 == local_host)
|
||||
remote_host = entry->host1;
|
||||
else
|
||||
remote_host = entry->host0;
|
||||
|
||||
if (remote_host >= SMEM_HOST_COUNT) {
|
||||
dev_err(smem->dev,
|
||||
"Invalid remote host %d\n",
|
||||
remote_host);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (smem->partitions[remote_host]) {
|
||||
dev_err(smem->dev,
|
||||
"Already found a partition for host %d\n",
|
||||
remote_host);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
header = smem->regions[0].virt_base + entry->offset;
|
||||
|
||||
if (header->magic != SMEM_PART_MAGIC) {
|
||||
dev_err(smem->dev,
|
||||
"Partition %d has invalid magic\n", i);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (header->host0 != local_host && header->host1 != local_host) {
|
||||
dev_err(smem->dev,
|
||||
"Partition %d hosts are invalid\n", i);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (header->host0 != remote_host && header->host1 != remote_host) {
|
||||
dev_err(smem->dev,
|
||||
"Partition %d hosts are invalid\n", i);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (header->size != entry->size) {
|
||||
dev_err(smem->dev,
|
||||
"Partition %d has invalid size\n", i);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (header->offset_free_uncached > header->size) {
|
||||
dev_err(smem->dev,
|
||||
"Partition %d has invalid free pointer\n", i);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
smem->partitions[remote_host] = header;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qcom_smem_count_mem_regions(struct platform_device *pdev)
|
||||
{
|
||||
struct resource *res;
|
||||
int num_regions = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < pdev->num_resources; i++) {
|
||||
res = &pdev->resource[i];
|
||||
|
||||
if (resource_type(res) == IORESOURCE_MEM)
|
||||
num_regions++;
|
||||
}
|
||||
|
||||
return num_regions;
|
||||
}
|
||||
|
||||
static int qcom_smem_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct smem_header *header;
|
||||
struct device_node *np;
|
||||
struct qcom_smem *smem;
|
||||
struct resource *res;
|
||||
struct resource r;
|
||||
size_t array_size;
|
||||
int num_regions = 0;
|
||||
int hwlock_id;
|
||||
u32 version;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
num_regions = qcom_smem_count_mem_regions(pdev) + 1;
|
||||
|
||||
array_size = num_regions * sizeof(struct smem_region);
|
||||
smem = devm_kzalloc(&pdev->dev, sizeof(*smem) + array_size, GFP_KERNEL);
|
||||
if (!smem)
|
||||
return -ENOMEM;
|
||||
|
||||
smem->dev = &pdev->dev;
|
||||
smem->num_regions = num_regions;
|
||||
|
||||
np = of_parse_phandle(pdev->dev.of_node, "memory-region", 0);
|
||||
if (!np) {
|
||||
dev_err(&pdev->dev, "No memory-region specified\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = of_address_to_resource(np, 0, &r);
|
||||
of_node_put(np);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
smem->regions[0].aux_base = (u32)r.start;
|
||||
smem->regions[0].size = resource_size(&r);
|
||||
smem->regions[0].virt_base = devm_ioremap_nocache(&pdev->dev,
|
||||
r.start,
|
||||
resource_size(&r));
|
||||
if (!smem->regions[0].virt_base)
|
||||
return -ENOMEM;
|
||||
|
||||
for (i = 1; i < num_regions; i++) {
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, i - 1);
|
||||
|
||||
smem->regions[i].aux_base = (u32)res->start;
|
||||
smem->regions[i].size = resource_size(res);
|
||||
smem->regions[i].virt_base = devm_ioremap_nocache(&pdev->dev,
|
||||
res->start,
|
||||
resource_size(res));
|
||||
if (!smem->regions[i].virt_base)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
header = smem->regions[0].virt_base;
|
||||
if (header->initialized != 1 || header->reserved) {
|
||||
dev_err(&pdev->dev, "SMEM is not initialized by SBL\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
version = qcom_smem_get_sbl_version(smem);
|
||||
if (version >> 16 != SMEM_EXPECTED_VERSION) {
|
||||
dev_err(&pdev->dev, "Unsupported SMEM version 0x%x\n", version);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = qcom_smem_enumerate_partitions(smem, SMEM_HOST_APPS);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
hwlock_id = of_hwspin_lock_get_id(pdev->dev.of_node, 0);
|
||||
if (hwlock_id < 0) {
|
||||
dev_err(&pdev->dev, "failed to retrieve hwlock\n");
|
||||
return hwlock_id;
|
||||
}
|
||||
|
||||
smem->hwlock = hwspin_lock_request_specific(hwlock_id);
|
||||
if (!smem->hwlock)
|
||||
return -ENXIO;
|
||||
|
||||
__smem = smem;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qcom_smem_remove(struct platform_device *pdev)
|
||||
{
|
||||
__smem = NULL;
|
||||
hwspin_lock_free(__smem->hwlock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct of_device_id qcom_smem_of_match[] = {
|
||||
{ .compatible = "qcom,smem" },
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, qcom_smem_of_match);
|
||||
|
||||
static struct platform_driver qcom_smem_driver = {
|
||||
.probe = qcom_smem_probe,
|
||||
.remove = qcom_smem_remove,
|
||||
.driver = {
|
||||
.name = "qcom-smem",
|
||||
.of_match_table = qcom_smem_of_match,
|
||||
.suppress_bind_attrs = true,
|
||||
},
|
||||
};
|
||||
|
||||
static int __init qcom_smem_init(void)
|
||||
{
|
||||
return platform_driver_register(&qcom_smem_driver);
|
||||
}
|
||||
arch_initcall(qcom_smem_init);
|
||||
|
||||
static void __exit qcom_smem_exit(void)
|
||||
{
|
||||
platform_driver_unregister(&qcom_smem_driver);
|
||||
}
|
||||
module_exit(qcom_smem_exit)
|
||||
|
||||
MODULE_AUTHOR("Bjorn Andersson <bjorn.andersson@sonymobile.com>");
|
||||
MODULE_DESCRIPTION("Qualcomm Shared Memory Manager");
|
||||
MODULE_LICENSE("GPL v2");
|
35
include/linux/soc/qcom/smd-rpm.h
Normal file
35
include/linux/soc/qcom/smd-rpm.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef __QCOM_SMD_RPM_H__
|
||||
#define __QCOM_SMD_RPM_H__
|
||||
|
||||
struct qcom_smd_rpm;
|
||||
|
||||
#define QCOM_SMD_RPM_ACTIVE_STATE 0
|
||||
#define QCOM_SMD_RPM_SLEEP_STATE 1
|
||||
|
||||
/*
|
||||
* Constants used for addressing resources in the RPM.
|
||||
*/
|
||||
#define QCOM_SMD_RPM_BOOST 0x61747362
|
||||
#define QCOM_SMD_RPM_BUS_CLK 0x316b6c63
|
||||
#define QCOM_SMD_RPM_BUS_MASTER 0x73616d62
|
||||
#define QCOM_SMD_RPM_BUS_SLAVE 0x766c7362
|
||||
#define QCOM_SMD_RPM_CLK_BUF_A 0x616B6C63
|
||||
#define QCOM_SMD_RPM_LDOA 0x616f646c
|
||||
#define QCOM_SMD_RPM_LDOB 0x626F646C
|
||||
#define QCOM_SMD_RPM_MEM_CLK 0x326b6c63
|
||||
#define QCOM_SMD_RPM_MISC_CLK 0x306b6c63
|
||||
#define QCOM_SMD_RPM_NCPA 0x6170636E
|
||||
#define QCOM_SMD_RPM_NCPB 0x6270636E
|
||||
#define QCOM_SMD_RPM_OCMEM_PWR 0x706d636f
|
||||
#define QCOM_SMD_RPM_QPIC_CLK 0x63697071
|
||||
#define QCOM_SMD_RPM_SMPA 0x61706d73
|
||||
#define QCOM_SMD_RPM_SMPB 0x62706d73
|
||||
#define QCOM_SMD_RPM_SPDM 0x63707362
|
||||
#define QCOM_SMD_RPM_VSA 0x00617376
|
||||
|
||||
int qcom_rpm_smd_write(struct qcom_smd_rpm *rpm,
|
||||
int state,
|
||||
u32 resource_type, u32 resource_id,
|
||||
void *buf, size_t count);
|
||||
|
||||
#endif
|
46
include/linux/soc/qcom/smd.h
Normal file
46
include/linux/soc/qcom/smd.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef __QCOM_SMD_H__
|
||||
#define __QCOM_SMD_H__
|
||||
|
||||
#include <linux/device.h>
|
||||
#include <linux/mod_devicetable.h>
|
||||
|
||||
struct qcom_smd;
|
||||
struct qcom_smd_channel;
|
||||
struct qcom_smd_lookup;
|
||||
|
||||
/**
|
||||
* struct qcom_smd_device - smd device struct
|
||||
* @dev: the device struct
|
||||
* @channel: handle to the smd channel for this device
|
||||
*/
|
||||
struct qcom_smd_device {
|
||||
struct device dev;
|
||||
struct qcom_smd_channel *channel;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct qcom_smd_driver - smd driver struct
|
||||
* @driver: underlying device driver
|
||||
* @probe: invoked when the smd channel is found
|
||||
* @remove: invoked when the smd channel is closed
|
||||
* @callback: invoked when an inbound message is received on the channel,
|
||||
* should return 0 on success or -EBUSY if the data cannot be
|
||||
* consumed at this time
|
||||
*/
|
||||
struct qcom_smd_driver {
|
||||
struct device_driver driver;
|
||||
int (*probe)(struct qcom_smd_device *dev);
|
||||
void (*remove)(struct qcom_smd_device *dev);
|
||||
int (*callback)(struct qcom_smd_device *, const void *, size_t);
|
||||
};
|
||||
|
||||
int qcom_smd_driver_register(struct qcom_smd_driver *drv);
|
||||
void qcom_smd_driver_unregister(struct qcom_smd_driver *drv);
|
||||
|
||||
#define module_qcom_smd_driver(__smd_driver) \
|
||||
module_driver(__smd_driver, qcom_smd_driver_register, \
|
||||
qcom_smd_driver_unregister)
|
||||
|
||||
int qcom_smd_send(struct qcom_smd_channel *channel, const void *data, int len);
|
||||
|
||||
#endif
|
11
include/linux/soc/qcom/smem.h
Normal file
11
include/linux/soc/qcom/smem.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef __QCOM_SMEM_H__
|
||||
#define __QCOM_SMEM_H__
|
||||
|
||||
#define QCOM_SMEM_HOST_ANY -1
|
||||
|
||||
int qcom_smem_alloc(unsigned host, unsigned item, size_t size);
|
||||
int qcom_smem_get(unsigned host, unsigned item, void **ptr, size_t *size);
|
||||
|
||||
int qcom_smem_get_free_space(unsigned host);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user