Skip to content

Commit a244a18

Browse files
james-c-linaroSuzuki K Poulose
authored andcommitted
coresight: Add claim tag warnings and debug messages
Add a dev_dbg() message so that external debugger conflicts are more visible. There are multiple reasons for -EBUSY so a message for this particular one could be helpful. Add errors for and enumerate all the other cases that are impossible. Reviewed-by: Leo Yan <[email protected]> Reviewed-by: Yeoreum Yun <[email protected]> Signed-off-by: James Clark <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a4e6584 commit a244a18

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

drivers/hwtracing/coresight/coresight-core.c

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,6 @@ static inline u32 coresight_read_claim_tags_unlocked(struct coresight_device *cs
135135
csdev_access_relaxed_read32(&csdev->access, CORESIGHT_CLAIMCLR));
136136
}
137137

138-
static inline bool coresight_is_claimed_self_hosted(struct coresight_device *csdev)
139-
{
140-
return coresight_read_claim_tags_unlocked(csdev) == CORESIGHT_CLAIM_SELF_HOSTED;
141-
}
142-
143-
static inline bool coresight_is_claimed_any(struct coresight_device *csdev)
144-
{
145-
return coresight_read_claim_tags_unlocked(csdev) != 0;
146-
}
147-
148138
static inline void coresight_set_self_claim_tag_unlocked(struct coresight_device *csdev)
149139
{
150140
csdev_access_relaxed_write32(&csdev->access, CORESIGHT_CLAIM_SELF_HOSTED,
@@ -182,18 +172,41 @@ EXPORT_SYMBOL_GPL(coresight_clear_self_claim_tag_unlocked);
182172
*/
183173
int coresight_claim_device_unlocked(struct coresight_device *csdev)
184174
{
175+
int tag;
176+
struct csdev_access *csa;
177+
185178
if (WARN_ON(!csdev))
186179
return -EINVAL;
187180

188-
if (coresight_is_claimed_any(csdev))
181+
csa = &csdev->access;
182+
tag = coresight_read_claim_tags_unlocked(csdev);
183+
184+
switch (tag) {
185+
case CORESIGHT_CLAIM_FREE:
186+
coresight_set_self_claim_tag_unlocked(csdev);
187+
if (coresight_read_claim_tags_unlocked(csdev) == CORESIGHT_CLAIM_SELF_HOSTED)
188+
return 0;
189+
190+
/* There was a race setting the tag, clean up and fail */
191+
coresight_clear_self_claim_tag_unlocked(csa);
192+
dev_dbg(&csdev->dev, "Busy: Couldn't set self claim tag");
189193
return -EBUSY;
190194

191-
coresight_set_self_claim_tag_unlocked(csdev);
192-
if (coresight_is_claimed_self_hosted(csdev))
193-
return 0;
194-
/* There was a race setting the tag, clean up and fail */
195-
coresight_clear_self_claim_tag_unlocked(&csdev->access);
196-
return -EBUSY;
195+
case CORESIGHT_CLAIM_EXTERNAL:
196+
/* External debug is an expected state, so log and report BUSY */
197+
dev_dbg(&csdev->dev, "Busy: Claimed by external debugger");
198+
return -EBUSY;
199+
200+
default:
201+
case CORESIGHT_CLAIM_SELF_HOSTED:
202+
case CORESIGHT_CLAIM_INVALID:
203+
/*
204+
* Warn here because we clear a lingering self hosted tag
205+
* on probe, so other tag combinations are impossible.
206+
*/
207+
dev_err_once(&csdev->dev, "Invalid claim tag state: %x", tag);
208+
return -EBUSY;
209+
}
197210
}
198211
EXPORT_SYMBOL_GPL(coresight_claim_device_unlocked);
199212

@@ -222,15 +235,15 @@ void coresight_disclaim_device_unlocked(struct coresight_device *csdev)
222235
if (WARN_ON(!csdev))
223236
return;
224237

225-
if (coresight_is_claimed_self_hosted(csdev))
238+
if (coresight_read_claim_tags_unlocked(csdev) == CORESIGHT_CLAIM_SELF_HOSTED)
226239
coresight_clear_self_claim_tag_unlocked(&csdev->access);
227240
else
228241
/*
229242
* The external agent may have not honoured our claim
230243
* and has manipulated it. Or something else has seriously
231244
* gone wrong in our driver.
232245
*/
233-
WARN_ON_ONCE(1);
246+
dev_WARN_ONCE(&csdev->dev, 1, "External agent took claim tag");
234247
}
235248
EXPORT_SYMBOL_GPL(coresight_disclaim_device_unlocked);
236249

drivers/hwtracing/coresight/coresight-priv.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ extern const struct device_type coresight_dev_type[];
3636
* See PSCI - ARM DEN 0022D, Section: 6.8.1 Debug and Trace save and restore.
3737
*/
3838
#define CORESIGHT_CLAIM_MASK GENMASK(1, 0)
39-
#define CORESIGHT_CLAIM_SELF_HOSTED BIT(1)
39+
#define CORESIGHT_CLAIM_FREE 0
40+
#define CORESIGHT_CLAIM_EXTERNAL 1
41+
#define CORESIGHT_CLAIM_SELF_HOSTED 2
42+
#define CORESIGHT_CLAIM_INVALID 3
4043

4144
#define TIMEOUT_US 100
4245
#define BMVAL(val, lsb, msb) ((val & GENMASK(msb, lsb)) >> lsb)

0 commit comments

Comments
 (0)