diff options
author | Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> | 2016-03-23 02:16:09 -0400 |
---|---|---|
committer | Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> | 2016-06-25 10:26:35 -0400 |
commit | ee1779840d093ebf6893c97115422fb5171b54d7 (patch) | |
tree | 68f96928bc837f7992fd8395c6b4c923e4db86a9 /drivers/char/tpm | |
parent | d4956524f1b0ae010c6d6cc1369a7fae63b52165 (diff) |
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>
Diffstat (limited to 'drivers/char/tpm')
-rw-r--r-- | drivers/char/tpm/tpm.h | 1 | ||||
-rw-r--r-- | drivers/char/tpm/tpm_atmel.c | 5 | ||||
-rw-r--r-- | drivers/char/tpm/tpm_atmel.h | 11 | ||||
-rw-r--r-- | drivers/char/tpm/tpm_nsc.c | 60 |
4 files changed, 52 insertions, 25 deletions
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 6586b6aac23f..b9a5b2586932 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h | |||
@@ -132,7 +132,6 @@ struct tpm_chip; | |||
132 | 132 | ||
133 | struct tpm_vendor_specific { | 133 | struct tpm_vendor_specific { |
134 | void __iomem *iobase; /* ioremapped address */ | 134 | void __iomem *iobase; /* ioremapped address */ |
135 | unsigned long base; /* TPM base address */ | ||
136 | 135 | ||
137 | int irq; | 136 | int irq; |
138 | 137 | ||
diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c index 0267d8587518..68d5c0991c51 100644 --- a/drivers/char/tpm/tpm_atmel.c +++ b/drivers/char/tpm/tpm_atmel.c | |||
@@ -141,8 +141,7 @@ static void atml_plat_remove(void) | |||
141 | if (chip) { | 141 | if (chip) { |
142 | tpm_chip_unregister(chip); | 142 | tpm_chip_unregister(chip); |
143 | if (priv->have_region) | 143 | if (priv->have_region) |
144 | atmel_release_region(chip->vendor.base, | 144 | atmel_release_region(priv->base, priv->region_size); |
145 | priv->region_size); | ||
146 | atmel_put_base_addr(chip->vendor.iobase); | 145 | atmel_put_base_addr(chip->vendor.iobase); |
147 | platform_device_unregister(pdev); | 146 | platform_device_unregister(pdev); |
148 | } | 147 | } |
@@ -191,6 +190,7 @@ static int __init init_atmel(void) | |||
191 | goto err_unreg_dev; | 190 | goto err_unreg_dev; |
192 | } | 191 | } |
193 | 192 | ||
193 | priv->base = base; | ||
194 | priv->have_region = have_region; | 194 | priv->have_region = have_region; |
195 | priv->region_size = region_size; | 195 | priv->region_size = region_size; |
196 | 196 | ||
@@ -201,7 +201,6 @@ static int __init init_atmel(void) | |||
201 | } | 201 | } |
202 | 202 | ||
203 | chip->vendor.iobase = iobase; | 203 | chip->vendor.iobase = iobase; |
204 | chip->vendor.base = base; | ||
205 | chip->vendor.priv = priv; | 204 | chip->vendor.priv = priv; |
206 | 205 | ||
207 | rc = tpm_chip_register(chip); | 206 | rc = tpm_chip_register(chip); |
diff --git a/drivers/char/tpm/tpm_atmel.h b/drivers/char/tpm/tpm_atmel.h index 3fd929de9739..bced6780afe8 100644 --- a/drivers/char/tpm/tpm_atmel.h +++ b/drivers/char/tpm/tpm_atmel.h | |||
@@ -25,8 +25,14 @@ | |||
25 | struct tpm_atmel_priv { | 25 | struct tpm_atmel_priv { |
26 | int region_size; | 26 | int region_size; |
27 | int have_region; | 27 | int have_region; |
28 | unsigned long base; | ||
28 | }; | 29 | }; |
29 | 30 | ||
31 | static inline struct tpm_atmel_priv *atmel_get_priv(struct tpm_chip *chip) | ||
32 | { | ||
33 | return chip->vendor.priv; | ||
34 | } | ||
35 | |||
30 | #ifdef CONFIG_PPC64 | 36 | #ifdef CONFIG_PPC64 |
31 | 37 | ||
32 | #include <asm/prom.h> | 38 | #include <asm/prom.h> |
@@ -83,8 +89,9 @@ static void __iomem * atmel_get_base_addr(unsigned long *base, int *region_size) | |||
83 | return ioremap(*base, *region_size); | 89 | return ioremap(*base, *region_size); |
84 | } | 90 | } |
85 | #else | 91 | #else |
86 | #define atmel_getb(chip, offset) inb(chip->vendor->base + offset) | 92 | #define atmel_getb(chip, offset) inb(atmel_get_priv(chip)->base + offset) |
87 | #define atmel_putb(val, chip, offset) outb(val, chip->vendor->base + offset) | 93 | #define atmel_putb(val, chip, offset) \ |
94 | outb(val, atmel_get_priv(chip)->base + offset) | ||
88 | #define atmel_request_region request_region | 95 | #define atmel_request_region request_region |
89 | #define atmel_release_region release_region | 96 | #define atmel_release_region release_region |
90 | /* Atmel definitions */ | 97 | /* Atmel definitions */ |
diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c index 766370bed60c..07163a429fdf 100644 --- a/drivers/char/tpm/tpm_nsc.c +++ b/drivers/char/tpm/tpm_nsc.c | |||
@@ -64,6 +64,16 @@ enum tpm_nsc_cmd_mode { | |||
64 | NSC_COMMAND_EOC = 0x03, | 64 | NSC_COMMAND_EOC = 0x03, |
65 | NSC_COMMAND_CANCEL = 0x22 | 65 | NSC_COMMAND_CANCEL = 0x22 |
66 | }; | 66 | }; |
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 | |||
67 | /* | 77 | /* |
68 | * Wait for a certain status to appear | 78 | * Wait for a certain status to appear |
69 | */ | 79 | */ |
@@ -72,7 +82,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data) | |||
72 | unsigned long stop; | 82 | unsigned long stop; |
73 | 83 | ||
74 | /* status immediately available check */ | 84 | /* status immediately available check */ |
75 | *data = inb(chip->vendor.base + NSC_STATUS); | 85 | *data = inb(nsc_get_priv(chip)->base + NSC_STATUS); |
76 | if ((*data & mask) == val) | 86 | if ((*data & mask) == val) |
77 | return 0; | 87 | return 0; |
78 | 88 | ||
@@ -80,7 +90,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data) | |||
80 | stop = jiffies + 10 * HZ; | 90 | stop = jiffies + 10 * HZ; |
81 | do { | 91 | do { |
82 | msleep(TPM_TIMEOUT); | 92 | msleep(TPM_TIMEOUT); |
83 | *data = inb(chip->vendor.base + 1); | 93 | *data = inb(nsc_get_priv(chip)->base + 1); |
84 | if ((*data & mask) == val) | 94 | if ((*data & mask) == val) |
85 | return 0; | 95 | return 0; |
86 | } | 96 | } |
@@ -95,9 +105,9 @@ static int nsc_wait_for_ready(struct tpm_chip *chip) | |||
95 | unsigned long stop; | 105 | unsigned long stop; |
96 | 106 | ||
97 | /* status immediately available check */ | 107 | /* status immediately available check */ |
98 | status = inb(chip->vendor.base + NSC_STATUS); | 108 | status = inb(nsc_get_priv(chip)->base + NSC_STATUS); |
99 | if (status & NSC_STATUS_OBF) | 109 | if (status & NSC_STATUS_OBF) |
100 | status = inb(chip->vendor.base + NSC_DATA); | 110 | status = inb(nsc_get_priv(chip)->base + NSC_DATA); |
101 | if (status & NSC_STATUS_RDY) | 111 | if (status & NSC_STATUS_RDY) |
102 | return 0; | 112 | return 0; |
103 | 113 | ||
@@ -105,9 +115,9 @@ static int nsc_wait_for_ready(struct tpm_chip *chip) | |||
105 | stop = jiffies + 100; | 115 | stop = jiffies + 100; |
106 | do { | 116 | do { |
107 | msleep(TPM_TIMEOUT); | 117 | msleep(TPM_TIMEOUT); |
108 | status = inb(chip->vendor.base + NSC_STATUS); | 118 | status = inb(nsc_get_priv(chip)->base + NSC_STATUS); |
109 | if (status & NSC_STATUS_OBF) | 119 | if (status & NSC_STATUS_OBF) |
110 | status = inb(chip->vendor.base + NSC_DATA); | 120 | status = inb(nsc_get_priv(chip)->base + NSC_DATA); |
111 | if (status & NSC_STATUS_RDY) | 121 | if (status & NSC_STATUS_RDY) |
112 | return 0; | 122 | return 0; |
113 | } | 123 | } |
@@ -132,8 +142,9 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count) | |||
132 | dev_err(&chip->dev, "F0 timeout\n"); | 142 | dev_err(&chip->dev, "F0 timeout\n"); |
133 | return -EIO; | 143 | return -EIO; |
134 | } | 144 | } |
135 | if ((data = | 145 | |
136 | inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_NORMAL) { | 146 | data = inb(nsc_get_priv(chip)->base + NSC_DATA); |
147 | if (data != NSC_COMMAND_NORMAL) { | ||
137 | dev_err(&chip->dev, "not in normal mode (0x%x)\n", | 148 | dev_err(&chip->dev, "not in normal mode (0x%x)\n", |
138 | data); | 149 | data); |
139 | return -EIO; | 150 | return -EIO; |
@@ -149,7 +160,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count) | |||
149 | } | 160 | } |
150 | if (data & NSC_STATUS_F0) | 161 | if (data & NSC_STATUS_F0) |
151 | break; | 162 | break; |
152 | *p = inb(chip->vendor.base + NSC_DATA); | 163 | *p = inb(nsc_get_priv(chip)->base + NSC_DATA); |
153 | } | 164 | } |
154 | 165 | ||
155 | if ((data & NSC_STATUS_F0) == 0 && | 166 | if ((data & NSC_STATUS_F0) == 0 && |
@@ -157,7 +168,9 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count) | |||
157 | dev_err(&chip->dev, "F0 not set\n"); | 168 | dev_err(&chip->dev, "F0 not set\n"); |
158 | return -EIO; | 169 | return -EIO; |
159 | } | 170 | } |
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) { | ||
161 | dev_err(&chip->dev, | 174 | dev_err(&chip->dev, |
162 | "expected end of command(0x%x)\n", data); | 175 | "expected end of command(0x%x)\n", data); |
163 | return -EIO; | 176 | return -EIO; |
@@ -183,7 +196,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) | |||
183 | * fix it. Not sure why this is needed, we followed the flow | 196 | * fix it. Not sure why this is needed, we followed the flow |
184 | * chart in the manual to the letter. | 197 | * chart in the manual to the letter. |
185 | */ | 198 | */ |
186 | outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND); | 199 | outb(NSC_COMMAND_CANCEL, nsc_get_priv(chip)->base + NSC_COMMAND); |
187 | 200 | ||
188 | if (nsc_wait_for_ready(chip) != 0) | 201 | if (nsc_wait_for_ready(chip) != 0) |
189 | return -EIO; | 202 | return -EIO; |
@@ -193,7 +206,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) | |||
193 | return -EIO; | 206 | return -EIO; |
194 | } | 207 | } |
195 | 208 | ||
196 | outb(NSC_COMMAND_NORMAL, chip->vendor.base + NSC_COMMAND); | 209 | outb(NSC_COMMAND_NORMAL, nsc_get_priv(chip)->base + NSC_COMMAND); |
197 | if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) { | 210 | if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) { |
198 | dev_err(&chip->dev, "IBR timeout\n"); | 211 | dev_err(&chip->dev, "IBR timeout\n"); |
199 | return -EIO; | 212 | return -EIO; |
@@ -205,26 +218,26 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) | |||
205 | "IBF timeout (while writing data)\n"); | 218 | "IBF timeout (while writing data)\n"); |
206 | return -EIO; | 219 | return -EIO; |
207 | } | 220 | } |
208 | outb(buf[i], chip->vendor.base + NSC_DATA); | 221 | outb(buf[i], nsc_get_priv(chip)->base + NSC_DATA); |
209 | } | 222 | } |
210 | 223 | ||
211 | if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { | 224 | if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { |
212 | dev_err(&chip->dev, "IBF timeout\n"); | 225 | dev_err(&chip->dev, "IBF timeout\n"); |
213 | return -EIO; | 226 | return -EIO; |
214 | } | 227 | } |
215 | outb(NSC_COMMAND_EOC, chip->vendor.base + NSC_COMMAND); | 228 | outb(NSC_COMMAND_EOC, nsc_get_priv(chip)->base + NSC_COMMAND); |
216 | 229 | ||
217 | return count; | 230 | return count; |
218 | } | 231 | } |
219 | 232 | ||
220 | static void tpm_nsc_cancel(struct tpm_chip *chip) | 233 | static void tpm_nsc_cancel(struct tpm_chip *chip) |
221 | { | 234 | { |
222 | outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND); | 235 | outb(NSC_COMMAND_CANCEL, nsc_get_priv(chip)->base + NSC_COMMAND); |
223 | } | 236 | } |
224 | 237 | ||
225 | static u8 tpm_nsc_status(struct tpm_chip *chip) | 238 | static u8 tpm_nsc_status(struct tpm_chip *chip) |
226 | { | 239 | { |
227 | return inb(chip->vendor.base + NSC_STATUS); | 240 | return inb(nsc_get_priv(chip)->base + NSC_STATUS); |
228 | } | 241 | } |
229 | 242 | ||
230 | static bool tpm_nsc_req_canceled(struct tpm_chip *chip, u8 status) | 243 | static bool tpm_nsc_req_canceled(struct tpm_chip *chip, u8 status) |
@@ -249,7 +262,7 @@ static void tpm_nsc_remove(struct device *dev) | |||
249 | struct tpm_chip *chip = dev_get_drvdata(dev); | 262 | struct tpm_chip *chip = dev_get_drvdata(dev); |
250 | 263 | ||
251 | tpm_chip_unregister(chip); | 264 | tpm_chip_unregister(chip); |
252 | release_region(chip->vendor.base, 2); | 265 | release_region(nsc_get_priv(chip)->base, 2); |
253 | } | 266 | } |
254 | 267 | ||
255 | static SIMPLE_DEV_PM_OPS(tpm_nsc_pm, tpm_pm_suspend, tpm_pm_resume); | 268 | static SIMPLE_DEV_PM_OPS(tpm_nsc_pm, tpm_pm_suspend, tpm_pm_resume); |
@@ -268,6 +281,7 @@ static int __init init_nsc(void) | |||
268 | int nscAddrBase = TPM_ADDR; | 281 | int nscAddrBase = TPM_ADDR; |
269 | struct tpm_chip *chip; | 282 | struct tpm_chip *chip; |
270 | unsigned long base; | 283 | unsigned long base; |
284 | struct tpm_nsc_priv *priv; | ||
271 | 285 | ||
272 | /* verify that it is a National part (SID) */ | 286 | /* verify that it is a National part (SID) */ |
273 | if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) { | 287 | if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) { |
@@ -301,6 +315,14 @@ static int __init init_nsc(void) | |||
301 | if ((rc = platform_device_add(pdev)) < 0) | 315 | if ((rc = platform_device_add(pdev)) < 0) |
302 | goto err_put_dev; | 316 | goto err_put_dev; |
303 | 317 | ||
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 | |||
304 | if (request_region(base, 2, "tpm_nsc0") == NULL ) { | 326 | if (request_region(base, 2, "tpm_nsc0") == NULL ) { |
305 | rc = -EBUSY; | 327 | rc = -EBUSY; |
306 | goto err_del_dev; | 328 | goto err_del_dev; |
@@ -312,6 +334,8 @@ static int __init init_nsc(void) | |||
312 | goto err_rel_reg; | 334 | goto err_rel_reg; |
313 | } | 335 | } |
314 | 336 | ||
337 | chip->vendor.priv = priv; | ||
338 | |||
315 | rc = tpm_chip_register(chip); | 339 | rc = tpm_chip_register(chip); |
316 | if (rc) | 340 | if (rc) |
317 | goto err_rel_reg; | 341 | goto err_rel_reg; |
@@ -349,8 +373,6 @@ static int __init init_nsc(void) | |||
349 | "NSC TPM revision %d\n", | 373 | "NSC TPM revision %d\n", |
350 | tpm_read_index(nscAddrBase, 0x27) & 0x1F); | 374 | tpm_read_index(nscAddrBase, 0x27) & 0x1F); |
351 | 375 | ||
352 | chip->vendor.base = base; | ||
353 | |||
354 | return 0; | 376 | return 0; |
355 | 377 | ||
356 | err_rel_reg: | 378 | err_rel_reg: |