Commit 8ce00296 authored by Suzuki K Poulose's avatar Suzuki K Poulose Committed by Greg Kroah-Hartman
Browse files

coresight: Convert claim/disclaim operations to use access wrappers

Convert the generic CLAIM tag management APIs to use the
device access layer abstraction.

Link: https://lore.kernel.org/r/20210110224850.1880240-7-suzuki.poulose@arm.com


Cc: Mike Leach <mike.leach@linaro.org>
Signed-off-by: default avatarSuzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: default avatarMathieu Poirier <mathieu.poirier@linaro.org>
Link: https://lore.kernel.org/r/20210201181351.1475223-9-mathieu.poirier@linaro.org


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 02005282
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -412,6 +412,7 @@ static int catu_enable_hw(struct catu_drvdata *drvdata, void *data)
	u32 control, mode;
	struct etr_buf *etr_buf = data;
	struct device *dev = &drvdata->csdev->dev;
	struct coresight_device *csdev = drvdata->csdev;

	if (catu_wait_for_ready(drvdata))
		dev_warn(dev, "Timeout while waiting for READY\n");
@@ -422,7 +423,7 @@ static int catu_enable_hw(struct catu_drvdata *drvdata, void *data)
		return -EBUSY;
	}

	rc = coresight_claim_device_unlocked(drvdata->base);
	rc = coresight_claim_device_unlocked(csdev);
	if (rc)
		return rc;

@@ -466,9 +467,10 @@ static int catu_disable_hw(struct catu_drvdata *drvdata)
{
	int rc = 0;
	struct device *dev = &drvdata->csdev->dev;
	struct coresight_device *csdev = drvdata->csdev;

	catu_write_control(drvdata, 0);
	coresight_disclaim_device_unlocked(drvdata->base);
	coresight_disclaim_device_unlocked(csdev);
	if (catu_wait_for_ready(drvdata)) {
		dev_info(dev, "Timeout while waiting for READY\n");
		rc = -EAGAIN;
+40 −26
Original line number Diff line number Diff line
@@ -145,30 +145,32 @@ static int coresight_find_link_outport(struct coresight_device *csdev,
	return -ENODEV;
}

static inline u32 coresight_read_claim_tags(void __iomem *base)
static inline u32 coresight_read_claim_tags(struct coresight_device *csdev)
{
	return readl_relaxed(base + CORESIGHT_CLAIMCLR);
	return csdev_access_relaxed_read32(&csdev->access, CORESIGHT_CLAIMCLR);
}

static inline bool coresight_is_claimed_self_hosted(void __iomem *base)
static inline bool coresight_is_claimed_self_hosted(struct coresight_device *csdev)
{
	return coresight_read_claim_tags(base) == CORESIGHT_CLAIM_SELF_HOSTED;
	return coresight_read_claim_tags(csdev) == CORESIGHT_CLAIM_SELF_HOSTED;
}

static inline bool coresight_is_claimed_any(void __iomem *base)
static inline bool coresight_is_claimed_any(struct coresight_device *csdev)
{
	return coresight_read_claim_tags(base) != 0;
	return coresight_read_claim_tags(csdev) != 0;
}

static inline void coresight_set_claim_tags(void __iomem *base)
static inline void coresight_set_claim_tags(struct coresight_device *csdev)
{
	writel_relaxed(CORESIGHT_CLAIM_SELF_HOSTED, base + CORESIGHT_CLAIMSET);
	csdev_access_relaxed_write32(&csdev->access, CORESIGHT_CLAIM_SELF_HOSTED,
				     CORESIGHT_CLAIMSET);
	isb();
}

static inline void coresight_clear_claim_tags(void __iomem *base)
static inline void coresight_clear_claim_tags(struct coresight_device *csdev)
{
	writel_relaxed(CORESIGHT_CLAIM_SELF_HOSTED, base + CORESIGHT_CLAIMCLR);
	csdev_access_relaxed_write32(&csdev->access, CORESIGHT_CLAIM_SELF_HOSTED,
				     CORESIGHT_CLAIMCLR);
	isb();
}

@@ -182,27 +184,33 @@ static inline void coresight_clear_claim_tags(void __iomem *base)
 * Called with CS_UNLOCKed for the component.
 * Returns : 0 on success
 */
int coresight_claim_device_unlocked(void __iomem *base)
int coresight_claim_device_unlocked(struct coresight_device *csdev)
{
	if (coresight_is_claimed_any(base))
	if (WARN_ON(!csdev))
		return -EINVAL;

	if (coresight_is_claimed_any(csdev))
		return -EBUSY;

	coresight_set_claim_tags(base);
	if (coresight_is_claimed_self_hosted(base))
	coresight_set_claim_tags(csdev);
	if (coresight_is_claimed_self_hosted(csdev))
		return 0;
	/* There was a race setting the tags, clean up and fail */
	coresight_clear_claim_tags(base);
	coresight_clear_claim_tags(csdev);
	return -EBUSY;
}
EXPORT_SYMBOL_GPL(coresight_claim_device_unlocked);

int coresight_claim_device(void __iomem *base)
int coresight_claim_device(struct coresight_device *csdev)
{
	int rc;

	CS_UNLOCK(base);
	rc = coresight_claim_device_unlocked(base);
	CS_LOCK(base);
	if (WARN_ON(!csdev))
		return -EINVAL;

	CS_UNLOCK(csdev->access.base);
	rc = coresight_claim_device_unlocked(csdev);
	CS_LOCK(csdev->access.base);

	return rc;
}
@@ -212,11 +220,14 @@ EXPORT_SYMBOL_GPL(coresight_claim_device);
 * coresight_disclaim_device_unlocked : Clear the claim tags for the device.
 * Called with CS_UNLOCKed for the component.
 */
void coresight_disclaim_device_unlocked(void __iomem *base)
void coresight_disclaim_device_unlocked(struct coresight_device *csdev)
{

	if (coresight_is_claimed_self_hosted(base))
		coresight_clear_claim_tags(base);
	if (WARN_ON(!csdev))
		return;

	if (coresight_is_claimed_self_hosted(csdev))
		coresight_clear_claim_tags(csdev);
	else
		/*
		 * The external agent may have not honoured our claim
@@ -227,11 +238,14 @@ void coresight_disclaim_device_unlocked(void __iomem *base)
}
EXPORT_SYMBOL_GPL(coresight_disclaim_device_unlocked);

void coresight_disclaim_device(void __iomem *base)
void coresight_disclaim_device(struct coresight_device *csdev)
{
	CS_UNLOCK(base);
	coresight_disclaim_device_unlocked(base);
	CS_LOCK(base);
	if (WARN_ON(!csdev))
		return;

	CS_UNLOCK(csdev->access.base);
	coresight_disclaim_device_unlocked(csdev);
	CS_LOCK(csdev->access.base);
}
EXPORT_SYMBOL_GPL(coresight_disclaim_device);

+10 −7
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ static int cti_enable_hw(struct cti_drvdata *drvdata)
		goto cti_state_unchanged;

	/* claim the device */
	rc = coresight_claim_device(drvdata->base);
	rc = coresight_claim_device(drvdata->csdev);
	if (rc)
		goto cti_err_not_enabled;

@@ -136,7 +136,7 @@ static void cti_cpuhp_enable_hw(struct cti_drvdata *drvdata)
		goto cti_hp_not_enabled;

	/* try to claim the device */
	if (coresight_claim_device(drvdata->base))
	if (coresight_claim_device(drvdata->csdev))
		goto cti_hp_not_enabled;

	cti_write_all_hw_regs(drvdata);
@@ -154,6 +154,7 @@ static int cti_disable_hw(struct cti_drvdata *drvdata)
{
	struct cti_config *config = &drvdata->config;
	struct device *dev = &drvdata->csdev->dev;
	struct coresight_device *csdev = drvdata->csdev;

	spin_lock(&drvdata->spinlock);

@@ -171,7 +172,7 @@ static int cti_disable_hw(struct cti_drvdata *drvdata)
	writel_relaxed(0, drvdata->base + CTICONTROL);
	config->hw_enabled = false;

	coresight_disclaim_device_unlocked(drvdata->base);
	coresight_disclaim_device_unlocked(csdev);
	CS_LOCK(drvdata->base);
	spin_unlock(&drvdata->spinlock);
	pm_runtime_put(dev);
@@ -655,6 +656,7 @@ static int cti_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
			     void *v)
{
	struct cti_drvdata *drvdata;
	struct coresight_device *csdev;
	unsigned int cpu = smp_processor_id();
	int notify_res = NOTIFY_OK;

@@ -662,6 +664,7 @@ static int cti_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
		return NOTIFY_OK;

	drvdata = cti_cpu_drvdata[cpu];
	csdev = drvdata->csdev;

	if (WARN_ON_ONCE(drvdata->ctidev.cpu != cpu))
		return NOTIFY_BAD;
@@ -673,13 +676,13 @@ static int cti_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
		/* CTI regs all static - we have a copy & nothing to save */
		drvdata->config.hw_powered = false;
		if (drvdata->config.hw_enabled)
			coresight_disclaim_device(drvdata->base);
			coresight_disclaim_device(csdev);
		break;

	case CPU_PM_ENTER_FAILED:
		drvdata->config.hw_powered = true;
		if (drvdata->config.hw_enabled) {
			if (coresight_claim_device(drvdata->base))
			if (coresight_claim_device(csdev))
				drvdata->config.hw_enabled = false;
		}
		break;
@@ -692,7 +695,7 @@ static int cti_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
		/* check enable reference count to enable HW */
		if (atomic_read(&drvdata->config.enable_req_count)) {
			/* check we can claim the device as we re-power */
			if (coresight_claim_device(drvdata->base))
			if (coresight_claim_device(csdev))
				goto cti_notify_exit;

			drvdata->config.hw_enabled = true;
@@ -736,7 +739,7 @@ static int cti_dying_cpu(unsigned int cpu)
	spin_lock(&drvdata->spinlock);
	drvdata->config.hw_powered = false;
	if (drvdata->config.hw_enabled)
		coresight_disclaim_device(drvdata->base);
		coresight_disclaim_device(drvdata->csdev);
	spin_unlock(&drvdata->spinlock);
	return 0;
}
+2 −2
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ static void __etb_enable_hw(struct etb_drvdata *drvdata)

static int etb_enable_hw(struct etb_drvdata *drvdata)
{
	int rc = coresight_claim_device(drvdata->base);
	int rc = coresight_claim_device(drvdata->csdev);

	if (rc)
		return rc;
@@ -345,7 +345,7 @@ static void etb_disable_hw(struct etb_drvdata *drvdata)
{
	__etb_disable_hw(drvdata);
	etb_dump_hw(drvdata);
	coresight_disclaim_device(drvdata->base);
	coresight_disclaim_device(drvdata->csdev);
}

static int etb_disable(struct coresight_device *csdev)
+5 −3
Original line number Diff line number Diff line
@@ -358,10 +358,11 @@ static int etm_enable_hw(struct etm_drvdata *drvdata)
	int i, rc;
	u32 etmcr;
	struct etm_config *config = &drvdata->config;
	struct coresight_device *csdev = drvdata->csdev;

	CS_UNLOCK(drvdata->base);

	rc = coresight_claim_device_unlocked(drvdata->base);
	rc = coresight_claim_device_unlocked(csdev);
	if (rc)
		goto done;

@@ -566,6 +567,7 @@ static void etm_disable_hw(void *info)
	int i;
	struct etm_drvdata *drvdata = info;
	struct etm_config *config = &drvdata->config;
	struct coresight_device *csdev = drvdata->csdev;

	CS_UNLOCK(drvdata->base);
	etm_set_prog(drvdata);
@@ -577,7 +579,7 @@ static void etm_disable_hw(void *info)
		config->cntr_val[i] = etm_readl(drvdata, ETMCNTVRn(i));

	etm_set_pwrdwn(drvdata);
	coresight_disclaim_device_unlocked(drvdata->base);
	coresight_disclaim_device_unlocked(csdev);

	CS_LOCK(drvdata->base);

@@ -602,7 +604,7 @@ static void etm_disable_perf(struct coresight_device *csdev)
	 * power down the tracer.
	 */
	etm_set_pwrdwn(drvdata);
	coresight_disclaim_device_unlocked(drvdata->base);
	coresight_disclaim_device_unlocked(csdev);

	CS_LOCK(drvdata->base);
}
Loading