Skip to content

Commit eb7c7e8

Browse files
author
Herton R. Krzesinski
committed
Merge: mailbox: qcom-ipcc: update qcom-ipcc
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/1333 Bugzilla: https://bugzilla.redhat.com/2123807 Tested: sanity boot on ampere-mtsnow-altra, sanity boot on qti-snapdragon with automotive configuration and NSP0 enabled. Update qcom-ipcc enabled in automotive (sa8540p). v2: * rebase post-merge of https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/1393 * remove the mentions of omitted fixes from the description. Both commits were backported in https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/1393 Signed-off-by: Eric Chanudet <echanude@redhat.com> Approved-by: Al Stone <ahs3@ahs3.net> Approved-by: Adrien Thierry <athierry@redhat.com> Approved-by: Brian Masney <bmasney@redhat.com> Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2 parents 0b86b88 + 980d2b0 commit eb7c7e8

File tree

3 files changed

+92
-42
lines changed

3 files changed

+92
-42
lines changed

Documentation/devicetree/bindings/mailbox/qcom-ipcc.yaml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ properties:
2424
compatible:
2525
items:
2626
- enum:
27+
- qcom,sm6350-ipcc
28+
- qcom,sm6375-ipcc
2729
- qcom,sm8250-ipcc
2830
- qcom,sm8350-ipcc
31+
- qcom,sm8450-ipcc
2932
- qcom,sc7280-ipcc
3033
- const: qcom,ipcc
3134

@@ -60,23 +63,14 @@ additionalProperties: false
6063

6164
examples:
6265
- |
63-
#include <dt-bindings/interrupt-controller/arm-gic.h>
64-
#include <dt-bindings/mailbox/qcom-ipcc.h>
66+
#include <dt-bindings/interrupt-controller/arm-gic.h>
67+
#include <dt-bindings/mailbox/qcom-ipcc.h>
6568
66-
mailbox@408000 {
67-
compatible = "qcom,sm8250-ipcc", "qcom,ipcc";
68-
reg = <0x408000 0x1000>;
69-
interrupts = <GIC_SPI 229 IRQ_TYPE_LEVEL_HIGH>;
70-
interrupt-controller;
71-
#interrupt-cells = <3>;
72-
#mbox-cells = <2>;
73-
};
74-
75-
smp2p-modem {
76-
compatible = "qcom,smp2p";
77-
interrupts-extended = <&ipcc_mproc IPCC_CLIENT_MPSS
78-
IPCC_MPROC_SIGNAL_SMP2P IRQ_TYPE_EDGE_RISING>;
79-
mboxes = <&ipcc_mproc IPCC_CLIENT_MPSS IPCC_MPROC_SIGNAL_SMP2P>;
80-
81-
/* Other SMP2P fields */
82-
};
69+
mailbox@408000 {
70+
compatible = "qcom,sm8250-ipcc", "qcom,ipcc";
71+
reg = <0x408000 0x1000>;
72+
interrupts = <GIC_SPI 229 IRQ_TYPE_LEVEL_HIGH>;
73+
interrupt-controller;
74+
#interrupt-cells = <3>;
75+
#mbox-cells = <2>;
76+
};

drivers/mailbox/qcom-ipcc.c

Lines changed: 76 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
#include <dt-bindings/mailbox/qcom-ipcc.h>
1515

16-
#define IPCC_MBOX_MAX_CHAN 48
17-
1816
/* IPCC Register offsets */
1917
#define IPCC_REG_SEND_ID 0x0c
2018
#define IPCC_REG_RECV_ID 0x10
@@ -53,9 +51,10 @@ struct qcom_ipcc {
5351
struct device *dev;
5452
void __iomem *base;
5553
struct irq_domain *irq_domain;
56-
struct mbox_chan chan[IPCC_MBOX_MAX_CHAN];
57-
struct qcom_ipcc_chan_info mchan[IPCC_MBOX_MAX_CHAN];
54+
struct mbox_chan *chans;
55+
struct qcom_ipcc_chan_info *mchan;
5856
struct mbox_controller mbox;
57+
int num_chans;
5958
int irq;
6059
};
6160

@@ -167,41 +166,87 @@ static struct mbox_chan *qcom_ipcc_mbox_xlate(struct mbox_controller *mbox,
167166
struct qcom_ipcc *ipcc = to_qcom_ipcc(mbox);
168167
struct qcom_ipcc_chan_info *mchan;
169168
struct mbox_chan *chan;
170-
unsigned int i;
169+
struct device *dev;
170+
int chan_id;
171+
172+
dev = ipcc->dev;
171173

172174
if (ph->args_count != 2)
173175
return ERR_PTR(-EINVAL);
174176

175-
for (i = 0; i < IPCC_MBOX_MAX_CHAN; i++) {
176-
chan = &ipcc->chan[i];
177-
if (!chan->con_priv) {
178-
mchan = &ipcc->mchan[i];
179-
mchan->client_id = ph->args[0];
180-
mchan->signal_id = ph->args[1];
181-
chan->con_priv = mchan;
182-
break;
183-
}
177+
for (chan_id = 0; chan_id < mbox->num_chans; chan_id++) {
178+
chan = &ipcc->chans[chan_id];
179+
mchan = chan->con_priv;
184180

185-
chan = NULL;
181+
if (!mchan)
182+
break;
183+
else if (mchan->client_id == ph->args[0] &&
184+
mchan->signal_id == ph->args[1])
185+
return ERR_PTR(-EBUSY);
186186
}
187187

188-
return chan ?: ERR_PTR(-EBUSY);
188+
if (chan_id >= mbox->num_chans)
189+
return ERR_PTR(-EBUSY);
190+
191+
mchan = devm_kzalloc(dev, sizeof(*mchan), GFP_KERNEL);
192+
if (!mchan)
193+
return ERR_PTR(-ENOMEM);
194+
195+
mchan->client_id = ph->args[0];
196+
mchan->signal_id = ph->args[1];
197+
chan->con_priv = mchan;
198+
199+
return chan;
189200
}
190201

191202
static const struct mbox_chan_ops ipcc_mbox_chan_ops = {
192203
.send_data = qcom_ipcc_mbox_send_data,
193204
.shutdown = qcom_ipcc_mbox_shutdown,
194205
};
195206

196-
static int qcom_ipcc_setup_mbox(struct qcom_ipcc *ipcc)
207+
static int qcom_ipcc_setup_mbox(struct qcom_ipcc *ipcc,
208+
struct device_node *controller_dn)
197209
{
210+
struct of_phandle_args curr_ph;
211+
struct device_node *client_dn;
198212
struct mbox_controller *mbox;
199213
struct device *dev = ipcc->dev;
214+
int i, j, ret;
215+
216+
/*
217+
* Find out the number of clients interested in this mailbox
218+
* and create channels accordingly.
219+
*/
220+
ipcc->num_chans = 0;
221+
for_each_node_with_property(client_dn, "mboxes") {
222+
if (!of_device_is_available(client_dn))
223+
continue;
224+
i = of_count_phandle_with_args(client_dn,
225+
"mboxes", "#mbox-cells");
226+
for (j = 0; j < i; j++) {
227+
ret = of_parse_phandle_with_args(client_dn, "mboxes",
228+
"#mbox-cells", j, &curr_ph);
229+
of_node_put(curr_ph.np);
230+
if (!ret && curr_ph.np == controller_dn) {
231+
ipcc->num_chans++;
232+
break;
233+
}
234+
}
235+
}
236+
237+
/* If no clients are found, skip registering as a mbox controller */
238+
if (!ipcc->num_chans)
239+
return 0;
240+
241+
ipcc->chans = devm_kcalloc(dev, ipcc->num_chans,
242+
sizeof(struct mbox_chan), GFP_KERNEL);
243+
if (!ipcc->chans)
244+
return -ENOMEM;
200245

201246
mbox = &ipcc->mbox;
202247
mbox->dev = dev;
203-
mbox->num_chans = IPCC_MBOX_MAX_CHAN;
204-
mbox->chans = ipcc->chan;
248+
mbox->num_chans = ipcc->num_chans;
249+
mbox->chans = ipcc->chans;
205250
mbox->ops = &ipcc_mbox_chan_ops;
206251
mbox->of_xlate = qcom_ipcc_mbox_xlate;
207252
mbox->txdone_irq = false;
@@ -231,6 +276,8 @@ static int qcom_ipcc_pm_resume(struct device *dev)
231276
static int qcom_ipcc_probe(struct platform_device *pdev)
232277
{
233278
struct qcom_ipcc *ipcc;
279+
static int id;
280+
char *name;
234281
int ret;
235282

236283
ipcc = devm_kzalloc(&pdev->dev, sizeof(*ipcc), GFP_KERNEL);
@@ -247,27 +294,33 @@ static int qcom_ipcc_probe(struct platform_device *pdev)
247294
if (ipcc->irq < 0)
248295
return ipcc->irq;
249296

297+
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "ipcc_%d", id++);
298+
if (!name)
299+
return -ENOMEM;
300+
250301
ipcc->irq_domain = irq_domain_add_tree(pdev->dev.of_node,
251302
&qcom_ipcc_irq_ops, ipcc);
252303
if (!ipcc->irq_domain)
253304
return -ENOMEM;
254305

255-
ret = qcom_ipcc_setup_mbox(ipcc);
306+
ret = qcom_ipcc_setup_mbox(ipcc, pdev->dev.of_node);
256307
if (ret)
257308
goto err_mbox;
258309

259310
ret = devm_request_irq(&pdev->dev, ipcc->irq, qcom_ipcc_irq_fn,
260-
IRQF_TRIGGER_HIGH, "ipcc", ipcc);
311+
IRQF_TRIGGER_HIGH | IRQF_NO_SUSPEND, name, ipcc);
261312
if (ret < 0) {
262313
dev_err(&pdev->dev, "Failed to register the irq: %d\n", ret);
263-
goto err_mbox;
314+
goto err_req_irq;
264315
}
265316

266-
enable_irq_wake(ipcc->irq);
267317
platform_set_drvdata(pdev, ipcc);
268318

269319
return 0;
270320

321+
err_req_irq:
322+
if (ipcc->num_chans)
323+
mbox_controller_unregister(&ipcc->mbox);
271324
err_mbox:
272325
irq_domain_remove(ipcc->irq_domain);
273326

include/dt-bindings/mailbox/qcom-ipcc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Signal IDs for MPROC protocol */
1010
#define IPCC_MPROC_SIGNAL_GLINK_QMP 0
11+
#define IPCC_MPROC_SIGNAL_TZ 1
1112
#define IPCC_MPROC_SIGNAL_SMP2P 2
1213
#define IPCC_MPROC_SIGNAL_PING 3
1314

@@ -29,6 +30,8 @@
2930
#define IPCC_CLIENT_PCIE1 14
3031
#define IPCC_CLIENT_PCIE2 15
3132
#define IPCC_CLIENT_SPSS 16
33+
#define IPCC_CLIENT_NSP1 18
34+
#define IPCC_CLIENT_TME 23
3235
#define IPCC_CLIENT_WPSS 24
3336

3437
#endif

0 commit comments

Comments
 (0)