Skip to content

Commit edc77a0

Browse files
author
Jarkko Sakkinen
committed
tpm: drop 'base' from struct tpm_vendor_specific
Dropped the field 'base' from struct tpm_vendor_specific and migrated it to the private structures of tpm_atmel and tpm_nsc. Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
1 parent ceea3a7 commit edc77a0

File tree

4 files changed

+52
-25
lines changed

4 files changed

+52
-25
lines changed

drivers/char/tpm/tpm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ struct tpm_chip;
132132

133133
struct tpm_vendor_specific {
134134
void __iomem *iobase; /* ioremapped address */
135-
unsigned long base; /* TPM base address */
136135

137136
int irq;
138137

drivers/char/tpm/tpm_atmel.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ static void atml_plat_remove(void)
141141
if (chip) {
142142
tpm_chip_unregister(chip);
143143
if (priv->have_region)
144-
atmel_release_region(chip->vendor.base,
145-
priv->region_size);
144+
atmel_release_region(priv->base, priv->region_size);
146145
atmel_put_base_addr(chip->vendor.iobase);
147146
platform_device_unregister(pdev);
148147
}
@@ -191,6 +190,7 @@ static int __init init_atmel(void)
191190
goto err_unreg_dev;
192191
}
193192

193+
priv->base = base;
194194
priv->have_region = have_region;
195195
priv->region_size = region_size;
196196

@@ -201,7 +201,6 @@ static int __init init_atmel(void)
201201
}
202202

203203
chip->vendor.iobase = iobase;
204-
chip->vendor.base = base;
205204
chip->vendor.priv = priv;
206205

207206
rc = tpm_chip_register(chip);

drivers/char/tpm/tpm_atmel.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@
2525
struct tpm_atmel_priv {
2626
int region_size;
2727
int have_region;
28+
unsigned long base;
2829
};
2930

31+
static inline struct tpm_atmel_priv *atmel_get_priv(struct tpm_chip *chip)
32+
{
33+
return chip->vendor.priv;
34+
}
35+
3036
#ifdef CONFIG_PPC64
3137

3238
#include <asm/prom.h>
@@ -83,8 +89,9 @@ static void __iomem * atmel_get_base_addr(unsigned long *base, int *region_size)
8389
return ioremap(*base, *region_size);
8490
}
8591
#else
86-
#define atmel_getb(chip, offset) inb(chip->vendor->base + offset)
87-
#define atmel_putb(val, chip, offset) outb(val, chip->vendor->base + offset)
92+
#define atmel_getb(chip, offset) inb(atmel_get_priv(chip)->base + offset)
93+
#define atmel_putb(val, chip, offset) \
94+
outb(val, atmel_get_priv(chip)->base + offset)
8895
#define atmel_request_region request_region
8996
#define atmel_release_region release_region
9097
/* Atmel definitions */

drivers/char/tpm/tpm_nsc.c

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ enum tpm_nsc_cmd_mode {
6464
NSC_COMMAND_EOC = 0x03,
6565
NSC_COMMAND_CANCEL = 0x22
6666
};
67+
68+
struct tpm_nsc_priv {
69+
unsigned long base;
70+
};
71+
72+
static inline struct tpm_nsc_priv *nsc_get_priv(struct tpm_chip *chip)
73+
{
74+
return chip->vendor.priv;
75+
}
76+
6777
/*
6878
* Wait for a certain status to appear
6979
*/
@@ -72,15 +82,15 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
7282
unsigned long stop;
7383

7484
/* status immediately available check */
75-
*data = inb(chip->vendor.base + NSC_STATUS);
85+
*data = inb(nsc_get_priv(chip)->base + NSC_STATUS);
7686
if ((*data & mask) == val)
7787
return 0;
7888

7989
/* wait for status */
8090
stop = jiffies + 10 * HZ;
8191
do {
8292
msleep(TPM_TIMEOUT);
83-
*data = inb(chip->vendor.base + 1);
93+
*data = inb(nsc_get_priv(chip)->base + 1);
8494
if ((*data & mask) == val)
8595
return 0;
8696
}
@@ -95,19 +105,19 @@ static int nsc_wait_for_ready(struct tpm_chip *chip)
95105
unsigned long stop;
96106

97107
/* status immediately available check */
98-
status = inb(chip->vendor.base + NSC_STATUS);
108+
status = inb(nsc_get_priv(chip)->base + NSC_STATUS);
99109
if (status & NSC_STATUS_OBF)
100-
status = inb(chip->vendor.base + NSC_DATA);
110+
status = inb(nsc_get_priv(chip)->base + NSC_DATA);
101111
if (status & NSC_STATUS_RDY)
102112
return 0;
103113

104114
/* wait for status */
105115
stop = jiffies + 100;
106116
do {
107117
msleep(TPM_TIMEOUT);
108-
status = inb(chip->vendor.base + NSC_STATUS);
118+
status = inb(nsc_get_priv(chip)->base + NSC_STATUS);
109119
if (status & NSC_STATUS_OBF)
110-
status = inb(chip->vendor.base + NSC_DATA);
120+
status = inb(nsc_get_priv(chip)->base + NSC_DATA);
111121
if (status & NSC_STATUS_RDY)
112122
return 0;
113123
}
@@ -132,8 +142,9 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
132142
dev_err(&chip->dev, "F0 timeout\n");
133143
return -EIO;
134144
}
135-
if ((data =
136-
inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_NORMAL) {
145+
146+
data = inb(nsc_get_priv(chip)->base + NSC_DATA);
147+
if (data != NSC_COMMAND_NORMAL) {
137148
dev_err(&chip->dev, "not in normal mode (0x%x)\n",
138149
data);
139150
return -EIO;
@@ -149,15 +160,17 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
149160
}
150161
if (data & NSC_STATUS_F0)
151162
break;
152-
*p = inb(chip->vendor.base + NSC_DATA);
163+
*p = inb(nsc_get_priv(chip)->base + NSC_DATA);
153164
}
154165

155166
if ((data & NSC_STATUS_F0) == 0 &&
156167
(wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0)) {
157168
dev_err(&chip->dev, "F0 not set\n");
158169
return -EIO;
159170
}
160-
if ((data = inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_EOC) {
171+
172+
data = inb(nsc_get_priv(chip)->base + NSC_DATA);
173+
if (data != NSC_COMMAND_EOC) {
161174
dev_err(&chip->dev,
162175
"expected end of command(0x%x)\n", data);
163176
return -EIO;
@@ -183,7 +196,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
183196
* fix it. Not sure why this is needed, we followed the flow
184197
* chart in the manual to the letter.
185198
*/
186-
outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND);
199+
outb(NSC_COMMAND_CANCEL, nsc_get_priv(chip)->base + NSC_COMMAND);
187200

188201
if (nsc_wait_for_ready(chip) != 0)
189202
return -EIO;
@@ -193,7 +206,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
193206
return -EIO;
194207
}
195208

196-
outb(NSC_COMMAND_NORMAL, chip->vendor.base + NSC_COMMAND);
209+
outb(NSC_COMMAND_NORMAL, nsc_get_priv(chip)->base + NSC_COMMAND);
197210
if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) {
198211
dev_err(&chip->dev, "IBR timeout\n");
199212
return -EIO;
@@ -205,26 +218,26 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
205218
"IBF timeout (while writing data)\n");
206219
return -EIO;
207220
}
208-
outb(buf[i], chip->vendor.base + NSC_DATA);
221+
outb(buf[i], nsc_get_priv(chip)->base + NSC_DATA);
209222
}
210223

211224
if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
212225
dev_err(&chip->dev, "IBF timeout\n");
213226
return -EIO;
214227
}
215-
outb(NSC_COMMAND_EOC, chip->vendor.base + NSC_COMMAND);
228+
outb(NSC_COMMAND_EOC, nsc_get_priv(chip)->base + NSC_COMMAND);
216229

217230
return count;
218231
}
219232

220233
static void tpm_nsc_cancel(struct tpm_chip *chip)
221234
{
222-
outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND);
235+
outb(NSC_COMMAND_CANCEL, nsc_get_priv(chip)->base + NSC_COMMAND);
223236
}
224237

225238
static u8 tpm_nsc_status(struct tpm_chip *chip)
226239
{
227-
return inb(chip->vendor.base + NSC_STATUS);
240+
return inb(nsc_get_priv(chip)->base + NSC_STATUS);
228241
}
229242

230243
static bool tpm_nsc_req_canceled(struct tpm_chip *chip, u8 status)
@@ -249,7 +262,7 @@ static void tpm_nsc_remove(struct device *dev)
249262
struct tpm_chip *chip = dev_get_drvdata(dev);
250263

251264
tpm_chip_unregister(chip);
252-
release_region(chip->vendor.base, 2);
265+
release_region(nsc_get_priv(chip)->base, 2);
253266
}
254267

255268
static SIMPLE_DEV_PM_OPS(tpm_nsc_pm, tpm_pm_suspend, tpm_pm_resume);
@@ -268,6 +281,7 @@ static int __init init_nsc(void)
268281
int nscAddrBase = TPM_ADDR;
269282
struct tpm_chip *chip;
270283
unsigned long base;
284+
struct tpm_nsc_priv *priv;
271285

272286
/* verify that it is a National part (SID) */
273287
if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) {
@@ -301,6 +315,14 @@ static int __init init_nsc(void)
301315
if ((rc = platform_device_add(pdev)) < 0)
302316
goto err_put_dev;
303317

318+
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
319+
if (!priv) {
320+
rc = -ENOMEM;
321+
goto err_del_dev;
322+
}
323+
324+
priv->base = base;
325+
304326
if (request_region(base, 2, "tpm_nsc0") == NULL ) {
305327
rc = -EBUSY;
306328
goto err_del_dev;
@@ -312,6 +334,8 @@ static int __init init_nsc(void)
312334
goto err_rel_reg;
313335
}
314336

337+
chip->vendor.priv = priv;
338+
315339
rc = tpm_chip_register(chip);
316340
if (rc)
317341
goto err_rel_reg;
@@ -349,8 +373,6 @@ static int __init init_nsc(void)
349373
"NSC TPM revision %d\n",
350374
tpm_read_index(nscAddrBase, 0x27) & 0x1F);
351375

352-
chip->vendor.base = base;
353-
354376
return 0;
355377

356378
err_rel_reg:

0 commit comments

Comments
 (0)