Skip to content

Commit 4525412

Browse files
mathieupoiriergregkh
authored andcommitted
coresight: tmc: making prepare/unprepare functions generic
Dealing with HW related matters in tmc_read_prepare/unprepare becomes convoluted when many cases need to be handled distinctively. As such moving processing related to HW setup to individual driver files and keep the core driver generic. Signed-off-by: Mathieu Poirier <[email protected]> Reviewed-by: Suzuki K Poulose <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6c6ed1e commit 4525412

File tree

4 files changed

+117
-50
lines changed

4 files changed

+117
-50
lines changed

Diff for: drivers/hwtracing/coresight/coresight-tmc-etf.c

+61-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static void tmc_etb_dump_hw(struct tmc_drvdata *drvdata)
7171
}
7272
}
7373

74-
void tmc_etb_disable_hw(struct tmc_drvdata *drvdata)
74+
static void tmc_etb_disable_hw(struct tmc_drvdata *drvdata)
7575
{
7676
CS_UNLOCK(drvdata->base);
7777

@@ -202,3 +202,63 @@ const struct coresight_ops tmc_etf_cs_ops = {
202202
.sink_ops = &tmc_etf_sink_ops,
203203
.link_ops = &tmc_etf_link_ops,
204204
};
205+
206+
int tmc_read_prepare_etb(struct tmc_drvdata *drvdata)
207+
{
208+
enum tmc_mode mode;
209+
int ret = 0;
210+
unsigned long flags;
211+
212+
/* config types are set a boot time and never change */
213+
if (WARN_ON_ONCE(drvdata->config_type != TMC_CONFIG_TYPE_ETB &&
214+
drvdata->config_type != TMC_CONFIG_TYPE_ETF))
215+
return -EINVAL;
216+
217+
spin_lock_irqsave(&drvdata->spinlock, flags);
218+
219+
/* There is no point in reading a TMC in HW FIFO mode */
220+
mode = readl_relaxed(drvdata->base + TMC_MODE);
221+
if (mode != TMC_MODE_CIRCULAR_BUFFER) {
222+
ret = -EINVAL;
223+
goto out;
224+
}
225+
226+
/* Disable the TMC if need be */
227+
if (drvdata->enable)
228+
tmc_etb_disable_hw(drvdata);
229+
230+
drvdata->reading = true;
231+
out:
232+
spin_unlock_irqrestore(&drvdata->spinlock, flags);
233+
234+
return ret;
235+
}
236+
237+
int tmc_read_unprepare_etb(struct tmc_drvdata *drvdata)
238+
{
239+
enum tmc_mode mode;
240+
unsigned long flags;
241+
242+
/* config types are set a boot time and never change */
243+
if (WARN_ON_ONCE(drvdata->config_type != TMC_CONFIG_TYPE_ETB &&
244+
drvdata->config_type != TMC_CONFIG_TYPE_ETF))
245+
return -EINVAL;
246+
247+
spin_lock_irqsave(&drvdata->spinlock, flags);
248+
249+
/* There is no point in reading a TMC in HW FIFO mode */
250+
mode = readl_relaxed(drvdata->base + TMC_MODE);
251+
if (mode != TMC_MODE_CIRCULAR_BUFFER) {
252+
spin_unlock_irqrestore(&drvdata->spinlock, flags);
253+
return -EINVAL;
254+
}
255+
256+
/* Re-enable the TMC if need be */
257+
if (drvdata->enable)
258+
tmc_etb_enable_hw(drvdata);
259+
260+
drvdata->reading = false;
261+
spin_unlock_irqrestore(&drvdata->spinlock, flags);
262+
263+
return 0;
264+
}

Diff for: drivers/hwtracing/coresight/coresight-tmc-etr.c

+41-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static void tmc_etr_dump_hw(struct tmc_drvdata *drvdata)
7070
drvdata->buf = drvdata->vaddr;
7171
}
7272

73-
void tmc_etr_disable_hw(struct tmc_drvdata *drvdata)
73+
static void tmc_etr_disable_hw(struct tmc_drvdata *drvdata)
7474
{
7575
CS_UNLOCK(drvdata->base);
7676

@@ -126,3 +126,43 @@ static const struct coresight_ops_sink tmc_etr_sink_ops = {
126126
const struct coresight_ops tmc_etr_cs_ops = {
127127
.sink_ops = &tmc_etr_sink_ops,
128128
};
129+
130+
int tmc_read_prepare_etr(struct tmc_drvdata *drvdata)
131+
{
132+
unsigned long flags;
133+
134+
/* config types are set a boot time and never change */
135+
if (WARN_ON_ONCE(drvdata->config_type != TMC_CONFIG_TYPE_ETR))
136+
return -EINVAL;
137+
138+
spin_lock_irqsave(&drvdata->spinlock, flags);
139+
140+
/* Disable the TMC if need be */
141+
if (drvdata->enable)
142+
tmc_etr_disable_hw(drvdata);
143+
144+
drvdata->reading = true;
145+
spin_unlock_irqrestore(&drvdata->spinlock, flags);
146+
147+
return 0;
148+
}
149+
150+
int tmc_read_unprepare_etr(struct tmc_drvdata *drvdata)
151+
{
152+
unsigned long flags;
153+
154+
/* config types are set a boot time and never change */
155+
if (WARN_ON_ONCE(drvdata->config_type != TMC_CONFIG_TYPE_ETR))
156+
return -EINVAL;
157+
158+
spin_lock_irqsave(&drvdata->spinlock, flags);
159+
160+
/* RE-enable the TMC if need be */
161+
if (drvdata->enable)
162+
tmc_etr_enable_hw(drvdata);
163+
164+
drvdata->reading = false;
165+
spin_unlock_irqrestore(&drvdata->spinlock, flags);
166+
167+
return 0;
168+
}

Diff for: drivers/hwtracing/coresight/coresight-tmc.c

+11-44
Original file line numberDiff line numberDiff line change
@@ -76,76 +76,43 @@ void tmc_disable_hw(struct tmc_drvdata *drvdata)
7676
static int tmc_read_prepare(struct tmc_drvdata *drvdata)
7777
{
7878
int ret = 0;
79-
unsigned long flags;
80-
enum tmc_mode mode;
81-
82-
spin_lock_irqsave(&drvdata->spinlock, flags);
83-
if (!drvdata->enable)
84-
goto out;
8579

8680
switch (drvdata->config_type) {
8781
case TMC_CONFIG_TYPE_ETB:
88-
tmc_etb_disable_hw(drvdata);
89-
break;
9082
case TMC_CONFIG_TYPE_ETF:
91-
/* There is no point in reading a TMC in HW FIFO mode */
92-
mode = readl_relaxed(drvdata->base + TMC_MODE);
93-
if (mode != TMC_MODE_CIRCULAR_BUFFER) {
94-
ret = -EINVAL;
95-
goto err;
96-
}
97-
98-
tmc_etb_disable_hw(drvdata);
83+
ret = tmc_read_prepare_etb(drvdata);
9984
break;
10085
case TMC_CONFIG_TYPE_ETR:
101-
tmc_etr_disable_hw(drvdata);
86+
ret = tmc_read_prepare_etr(drvdata);
10287
break;
10388
default:
10489
ret = -EINVAL;
105-
goto err;
10690
}
10791

108-
out:
109-
drvdata->reading = true;
110-
dev_info(drvdata->dev, "TMC read start\n");
111-
err:
112-
spin_unlock_irqrestore(&drvdata->spinlock, flags);
92+
if (!ret)
93+
dev_info(drvdata->dev, "TMC read start\n");
94+
11395
return ret;
11496
}
11597

11698
static void tmc_read_unprepare(struct tmc_drvdata *drvdata)
11799
{
118-
unsigned long flags;
119-
enum tmc_mode mode;
120-
121-
spin_lock_irqsave(&drvdata->spinlock, flags);
122-
if (!drvdata->enable)
123-
goto out;
100+
int ret = 0;
124101

125102
switch (drvdata->config_type) {
126103
case TMC_CONFIG_TYPE_ETB:
127-
tmc_etb_enable_hw(drvdata);
128-
break;
129104
case TMC_CONFIG_TYPE_ETF:
130-
/* Make sure we don't re-enable a TMC in HW FIFO mode */
131-
mode = readl_relaxed(drvdata->base + TMC_MODE);
132-
if (mode != TMC_MODE_CIRCULAR_BUFFER)
133-
goto err;
134-
135-
tmc_etb_enable_hw(drvdata);
105+
ret = tmc_read_unprepare_etb(drvdata);
136106
break;
137107
case TMC_CONFIG_TYPE_ETR:
138-
tmc_etr_disable_hw(drvdata);
108+
ret = tmc_read_unprepare_etr(drvdata);
139109
break;
140110
default:
141-
goto err;
111+
ret = -EINVAL;
142112
}
143113

144-
out:
145-
drvdata->reading = false;
146-
dev_info(drvdata->dev, "TMC read end\n");
147-
err:
148-
spin_unlock_irqrestore(&drvdata->spinlock, flags);
114+
if (!ret)
115+
dev_info(drvdata->dev, "TMC read end\n");
149116
}
150117

151118
static int tmc_open(struct inode *inode, struct file *file)

Diff for: drivers/hwtracing/coresight/coresight-tmc.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ void tmc_enable_hw(struct tmc_drvdata *drvdata);
127127
void tmc_disable_hw(struct tmc_drvdata *drvdata);
128128

129129
/* ETB/ETF functions */
130-
void tmc_etb_enable_hw(struct tmc_drvdata *drvdata);
131-
void tmc_etb_disable_hw(struct tmc_drvdata *drvdata);
130+
int tmc_read_prepare_etb(struct tmc_drvdata *drvdata);
131+
int tmc_read_unprepare_etb(struct tmc_drvdata *drvdata);
132132
extern const struct coresight_ops tmc_etb_cs_ops;
133133
extern const struct coresight_ops tmc_etf_cs_ops;
134134

135135
/* ETR functions */
136-
void tmc_etr_enable_hw(struct tmc_drvdata *drvdata);
137-
void tmc_etr_disable_hw(struct tmc_drvdata *drvdata);
136+
int tmc_read_prepare_etr(struct tmc_drvdata *drvdata);
137+
int tmc_read_unprepare_etr(struct tmc_drvdata *drvdata);
138138
extern const struct coresight_ops tmc_etr_cs_ops;
139139
#endif

0 commit comments

Comments
 (0)