Skip to content

Commit 85f7550

Browse files
Chris Lewandersson
authored andcommitted
soc: qcom: smp2p: add feature negotiation and ssr ack feature support
This patch adds feature negotiation and ssr ack feature between local host and remote processor. Local host can negotiate on common features supported with remote processor. When ssr ack feature bit is set, the remote processor will tell local host when it is reinitialized. All clients registered for falling edge interrupts will be notified when the smp2p entries are cleared for ssr. Signed-off-by: Chris Lew <clew@codeaurora.org> Signed-off-by: Deepak Kumar Singh <deesin@codeaurora.org> Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> Link: https://lore.kernel.org/r/1633450403-21281-1-git-send-email-deesin@codeaurora.org
1 parent 1d77246 commit 85f7550

1 file changed

Lines changed: 96 additions & 25 deletions

File tree

‎drivers/soc/qcom/smp2p.c‎

Lines changed: 96 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@
4141
#define SMP2P_MAX_ENTRY_NAME 16
4242

4343
#define SMP2P_FEATURE_SSR_ACK 0x1
44+
#define SMP2P_FLAGS_RESTART_DONE_BIT 0
45+
#define SMP2P_FLAGS_RESTART_ACK_BIT 1
4446

4547
#define SMP2P_MAGIC 0x504d5324
48+
#define SMP2P_ALL_FEATURES SMP2P_FEATURE_SSR_ACK
4649

4750
/**
4851
* struct smp2p_smem_item - in memory communication structure
@@ -136,6 +139,10 @@ struct qcom_smp2p {
136139

137140
unsigned valid_entries;
138141

142+
bool ssr_ack_enabled;
143+
bool ssr_ack;
144+
bool negotiation_done;
145+
139146
unsigned local_pid;
140147
unsigned remote_pid;
141148

@@ -163,22 +170,53 @@ static void qcom_smp2p_kick(struct qcom_smp2p *smp2p)
163170
}
164171
}
165172

166-
/**
167-
* qcom_smp2p_intr() - interrupt handler for incoming notifications
168-
* @irq: unused
169-
* @data: smp2p driver context
170-
*
171-
* Handle notifications from the remote side to handle newly allocated entries
172-
* or any changes to the state bits of existing entries.
173-
*/
174-
static irqreturn_t qcom_smp2p_intr(int irq, void *data)
173+
static bool qcom_smp2p_check_ssr(struct qcom_smp2p *smp2p)
174+
{
175+
struct smp2p_smem_item *in = smp2p->in;
176+
bool restart;
177+
178+
if (!smp2p->ssr_ack_enabled)
179+
return false;
180+
181+
restart = in->flags & BIT(SMP2P_FLAGS_RESTART_DONE_BIT);
182+
183+
return restart != smp2p->ssr_ack;
184+
}
185+
186+
static void qcom_smp2p_do_ssr_ack(struct qcom_smp2p *smp2p)
187+
{
188+
struct smp2p_smem_item *out = smp2p->out;
189+
u32 val;
190+
191+
smp2p->ssr_ack = !smp2p->ssr_ack;
192+
193+
val = out->flags & ~BIT(SMP2P_FLAGS_RESTART_ACK_BIT);
194+
if (smp2p->ssr_ack)
195+
val |= BIT(SMP2P_FLAGS_RESTART_ACK_BIT);
196+
out->flags = val;
197+
198+
qcom_smp2p_kick(smp2p);
199+
}
200+
201+
static void qcom_smp2p_negotiate(struct qcom_smp2p *smp2p)
202+
{
203+
struct smp2p_smem_item *out = smp2p->out;
204+
struct smp2p_smem_item *in = smp2p->in;
205+
206+
if (in->version == out->version) {
207+
out->features &= in->features;
208+
209+
if (out->features & SMP2P_FEATURE_SSR_ACK)
210+
smp2p->ssr_ack_enabled = true;
211+
212+
smp2p->negotiation_done = true;
213+
}
214+
}
215+
216+
static void qcom_smp2p_notify_in(struct qcom_smp2p *smp2p)
175217
{
176218
struct smp2p_smem_item *in;
177219
struct smp2p_entry *entry;
178-
struct qcom_smp2p *smp2p = data;
179-
unsigned smem_id = smp2p->smem_items[SMP2P_INBOUND];
180-
unsigned pid = smp2p->remote_pid;
181-
size_t size;
182220
int irq_pin;
183221
u32 status;
184222
char buf[SMP2P_MAX_ENTRY_NAME];
@@ -187,18 +225,6 @@ static irqreturn_t qcom_smp2p_intr(int irq, void *data)
187225

188226
in = smp2p->in;
189227

190-
/* Acquire smem item, if not already found */
191-
if (!in) {
192-
in = qcom_smem_get(pid, smem_id, &size);
193-
if (IS_ERR(in)) {
194-
dev_err(smp2p->dev,
195-
"Unable to acquire remote smp2p item\n");
196-
return IRQ_HANDLED;
197-
}
198-
199-
smp2p->in = in;
200-
}
201-
202228
/* Match newly created entries */
203229
for (i = smp2p->valid_entries; i < in->valid_entries; i++) {
204230
list_for_each_entry(entry, &smp2p->inbound, node) {
@@ -237,7 +263,51 @@ static irqreturn_t qcom_smp2p_intr(int irq, void *data)
237263
}
238264
}
239265
}
266+
}
267+
268+
/**
269+
* qcom_smp2p_intr() - interrupt handler for incoming notifications
270+
* @irq: unused
271+
* @data: smp2p driver context
272+
*
273+
* Handle notifications from the remote side to handle newly allocated entries
274+
* or any changes to the state bits of existing entries.
275+
*/
276+
static irqreturn_t qcom_smp2p_intr(int irq, void *data)
277+
{
278+
struct smp2p_smem_item *in;
279+
struct qcom_smp2p *smp2p = data;
280+
unsigned int smem_id = smp2p->smem_items[SMP2P_INBOUND];
281+
unsigned int pid = smp2p->remote_pid;
282+
bool ack_restart;
283+
size_t size;
284+
285+
in = smp2p->in;
286+
287+
/* Acquire smem item, if not already found */
288+
if (!in) {
289+
in = qcom_smem_get(pid, smem_id, &size);
290+
if (IS_ERR(in)) {
291+
dev_err(smp2p->dev,
292+
"Unable to acquire remote smp2p item\n");
293+
goto out;
294+
}
295+
296+
smp2p->in = in;
297+
}
298+
299+
if (!smp2p->negotiation_done)
300+
qcom_smp2p_negotiate(smp2p);
301+
302+
if (smp2p->negotiation_done) {
303+
ack_restart = qcom_smp2p_check_ssr(smp2p);
304+
qcom_smp2p_notify_in(smp2p);
305+
306+
if (ack_restart)
307+
qcom_smp2p_do_ssr_ack(smp2p);
308+
}
240309

310+
out:
241311
return IRQ_HANDLED;
242312
}
243313

@@ -393,6 +463,7 @@ static int qcom_smp2p_alloc_outbound_item(struct qcom_smp2p *smp2p)
393463
out->remote_pid = smp2p->remote_pid;
394464
out->total_entries = SMP2P_MAX_ENTRY;
395465
out->valid_entries = 0;
466+
out->features = SMP2P_ALL_FEATURES;
396467

397468
/*
398469
* Make sure the rest of the header is written before we validate the

0 commit comments

Comments
 (0)