summaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2016-02-12 08:24:37 -0500
committerDaniel Vetter <daniel.vetter@ffwll.ch>2016-02-12 08:24:37 -0500
commit05fd934ba585ea8c9f129f15f11327adb1f96fe3 (patch)
tree7b678c512c43419ccf484e71c84d69caee84a6da /drivers/char
parentebb7c78d358b2ea45c7d997423e6feb42e5ce4ef (diff)
parent382ab95d1af85381d8a5dff09b16a80c7e492534 (diff)
Merge tag 'topic/drm-misc-2016-02-12' into drm-intel-next-queued
Backmerge to get at the new encoder_mask support in atomic helpers. Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/generic_nvram.c21
-rw-r--r--drivers/char/hw_random/Kconfig1
-rw-r--r--drivers/char/hw_random/core.c6
-rw-r--r--drivers/char/hw_random/omap3-rom-rng.c13
-rw-r--r--drivers/char/hw_random/via-rng.c5
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c7
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c31
-rw-r--r--drivers/char/ipmi/ipmi_ssif.c1
-rw-r--r--drivers/char/mbcs.c28
-rw-r--r--drivers/char/mem.c4
-rw-r--r--drivers/char/mspec.c15
-rw-r--r--drivers/char/nvram.c18
-rw-r--r--drivers/char/nwflash.c31
-rw-r--r--drivers/char/ps3flash.c4
-rw-r--r--drivers/char/raw.c2
-rw-r--r--drivers/char/tpm/tpm-interface.c23
-rw-r--r--drivers/char/tpm/tpm.h11
-rw-r--r--drivers/char/tpm/tpm2-cmd.c60
-rw-r--r--drivers/char/tpm/tpm_crb.c14
-rw-r--r--drivers/char/tpm/tpm_ibmvtpm.c22
-rw-r--r--drivers/char/tpm/tpm_ibmvtpm.h1
-rw-r--r--drivers/char/tpm/tpm_tis.c256
22 files changed, 268 insertions, 306 deletions
diff --git a/drivers/char/generic_nvram.c b/drivers/char/generic_nvram.c
index 6c4f4b5a9dd3..073db9558379 100644
--- a/drivers/char/generic_nvram.c
+++ b/drivers/char/generic_nvram.c
@@ -20,6 +20,7 @@
20#include <linux/fcntl.h> 20#include <linux/fcntl.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/mutex.h> 22#include <linux/mutex.h>
23#include <linux/pagemap.h>
23#include <asm/uaccess.h> 24#include <asm/uaccess.h>
24#include <asm/nvram.h> 25#include <asm/nvram.h>
25#ifdef CONFIG_PPC_PMAC 26#ifdef CONFIG_PPC_PMAC
@@ -33,24 +34,8 @@ static ssize_t nvram_len;
33 34
34static loff_t nvram_llseek(struct file *file, loff_t offset, int origin) 35static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
35{ 36{
36 switch (origin) { 37 return generic_file_llseek_size(file, offset, origin,
37 case 0: 38 MAX_LFS_FILESIZE, nvram_len);
38 break;
39 case 1:
40 offset += file->f_pos;
41 break;
42 case 2:
43 offset += nvram_len;
44 break;
45 default:
46 offset = -1;
47 }
48 if (offset < 0)
49 return -EINVAL;
50
51 file->f_pos = offset;
52
53 return file->f_pos;
54} 39}
55 40
56static ssize_t read_nvram(struct file *file, char __user *buf, 41static ssize_t read_nvram(struct file *file, char __user *buf,
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index dbf22719462f..ff00331bff49 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -372,6 +372,7 @@ config HW_RANDOM_XGENE
372config HW_RANDOM_STM32 372config HW_RANDOM_STM32
373 tristate "STMicroelectronics STM32 random number generator" 373 tristate "STMicroelectronics STM32 random number generator"
374 depends on HW_RANDOM && (ARCH_STM32 || COMPILE_TEST) 374 depends on HW_RANDOM && (ARCH_STM32 || COMPILE_TEST)
375 depends on HAS_IOMEM
375 help 376 help
376 This driver provides kernel-side support for the Random Number 377 This driver provides kernel-side support for the Random Number
377 Generator hardware found on STM32 microcontrollers. 378 Generator hardware found on STM32 microcontrollers.
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 6f497aa1b276..9203f2d130c0 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -238,7 +238,10 @@ static ssize_t rng_dev_read(struct file *filp, char __user *buf,
238 goto out; 238 goto out;
239 } 239 }
240 240
241 mutex_lock(&reading_mutex); 241 if (mutex_lock_interruptible(&reading_mutex)) {
242 err = -ERESTARTSYS;
243 goto out_put;
244 }
242 if (!data_avail) { 245 if (!data_avail) {
243 bytes_read = rng_get_data(rng, rng_buffer, 246 bytes_read = rng_get_data(rng, rng_buffer,
244 rng_buffer_size(), 247 rng_buffer_size(),
@@ -288,6 +291,7 @@ out:
288 291
289out_unlock_reading: 292out_unlock_reading:
290 mutex_unlock(&reading_mutex); 293 mutex_unlock(&reading_mutex);
294out_put:
291 put_rng(rng); 295 put_rng(rng);
292 goto out; 296 goto out;
293} 297}
diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c
index a405cdcd8dd2..8da14f1a1f56 100644
--- a/drivers/char/hw_random/omap3-rom-rng.c
+++ b/drivers/char/hw_random/omap3-rom-rng.c
@@ -17,7 +17,7 @@
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/random.h> 18#include <linux/random.h>
19#include <linux/hw_random.h> 19#include <linux/hw_random.h>
20#include <linux/timer.h> 20#include <linux/workqueue.h>
21#include <linux/clk.h> 21#include <linux/clk.h>
22#include <linux/err.h> 22#include <linux/err.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
@@ -29,11 +29,11 @@
29/* param1: ptr, param2: count, param3: flag */ 29/* param1: ptr, param2: count, param3: flag */
30static u32 (*omap3_rom_rng_call)(u32, u32, u32); 30static u32 (*omap3_rom_rng_call)(u32, u32, u32);
31 31
32static struct timer_list idle_timer; 32static struct delayed_work idle_work;
33static int rng_idle; 33static int rng_idle;
34static struct clk *rng_clk; 34static struct clk *rng_clk;
35 35
36static void omap3_rom_rng_idle(unsigned long data) 36static void omap3_rom_rng_idle(struct work_struct *work)
37{ 37{
38 int r; 38 int r;
39 39
@@ -51,7 +51,7 @@ static int omap3_rom_rng_get_random(void *buf, unsigned int count)
51 u32 r; 51 u32 r;
52 u32 ptr; 52 u32 ptr;
53 53
54 del_timer_sync(&idle_timer); 54 cancel_delayed_work_sync(&idle_work);
55 if (rng_idle) { 55 if (rng_idle) {
56 clk_prepare_enable(rng_clk); 56 clk_prepare_enable(rng_clk);
57 r = omap3_rom_rng_call(0, 0, RNG_GEN_PRNG_HW_INIT); 57 r = omap3_rom_rng_call(0, 0, RNG_GEN_PRNG_HW_INIT);
@@ -65,7 +65,7 @@ static int omap3_rom_rng_get_random(void *buf, unsigned int count)
65 65
66 ptr = virt_to_phys(buf); 66 ptr = virt_to_phys(buf);
67 r = omap3_rom_rng_call(ptr, count, RNG_GEN_HW); 67 r = omap3_rom_rng_call(ptr, count, RNG_GEN_HW);
68 mod_timer(&idle_timer, jiffies + msecs_to_jiffies(500)); 68 schedule_delayed_work(&idle_work, msecs_to_jiffies(500));
69 if (r != 0) 69 if (r != 0)
70 return -EINVAL; 70 return -EINVAL;
71 return 0; 71 return 0;
@@ -102,7 +102,7 @@ static int omap3_rom_rng_probe(struct platform_device *pdev)
102 return -EINVAL; 102 return -EINVAL;
103 } 103 }
104 104
105 setup_timer(&idle_timer, omap3_rom_rng_idle, 0); 105 INIT_DELAYED_WORK(&idle_work, omap3_rom_rng_idle);
106 rng_clk = devm_clk_get(&pdev->dev, "ick"); 106 rng_clk = devm_clk_get(&pdev->dev, "ick");
107 if (IS_ERR(rng_clk)) { 107 if (IS_ERR(rng_clk)) {
108 pr_err("unable to get RNG clock\n"); 108 pr_err("unable to get RNG clock\n");
@@ -118,6 +118,7 @@ static int omap3_rom_rng_probe(struct platform_device *pdev)
118 118
119static int omap3_rom_rng_remove(struct platform_device *pdev) 119static int omap3_rom_rng_remove(struct platform_device *pdev)
120{ 120{
121 cancel_delayed_work_sync(&idle_work);
121 hwrng_unregister(&omap3_rom_rng_ops); 122 hwrng_unregister(&omap3_rom_rng_ops);
122 clk_disable_unprepare(rng_clk); 123 clk_disable_unprepare(rng_clk);
123 return 0; 124 return 0;
diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
index 0c98a9d51a24..44ce80606944 100644
--- a/drivers/char/hw_random/via-rng.c
+++ b/drivers/char/hw_random/via-rng.c
@@ -140,7 +140,7 @@ static int via_rng_init(struct hwrng *rng)
140 * RNG configuration like it used to be the case in this 140 * RNG configuration like it used to be the case in this
141 * register */ 141 * register */
142 if ((c->x86 == 6) && (c->x86_model >= 0x0f)) { 142 if ((c->x86 == 6) && (c->x86_model >= 0x0f)) {
143 if (!cpu_has_xstore_enabled) { 143 if (!boot_cpu_has(X86_FEATURE_XSTORE_EN)) {
144 pr_err(PFX "can't enable hardware RNG " 144 pr_err(PFX "can't enable hardware RNG "
145 "if XSTORE is not enabled\n"); 145 "if XSTORE is not enabled\n");
146 return -ENODEV; 146 return -ENODEV;
@@ -200,8 +200,9 @@ static int __init mod_init(void)
200{ 200{
201 int err; 201 int err;
202 202
203 if (!cpu_has_xstore) 203 if (!boot_cpu_has(X86_FEATURE_XSTORE))
204 return -ENODEV; 204 return -ENODEV;
205
205 pr_info("VIA RNG detected\n"); 206 pr_info("VIA RNG detected\n");
206 err = hwrng_register(&via_rng); 207 err = hwrng_register(&via_rng);
207 if (err) { 208 if (err) {
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index e3536da05c88..94fb407d8561 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -472,9 +472,10 @@ static DEFINE_MUTEX(smi_watchers_mutex);
472#define ipmi_get_stat(intf, stat) \ 472#define ipmi_get_stat(intf, stat) \
473 ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat])) 473 ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
474 474
475static char *addr_src_to_str[] = { "invalid", "hotmod", "hardcoded", "SPMI", 475static const char * const addr_src_to_str[] = {
476 "ACPI", "SMBIOS", "PCI", 476 "invalid", "hotmod", "hardcoded", "SPMI", "ACPI", "SMBIOS", "PCI",
477 "device-tree", "default" }; 477 "device-tree", "default"
478};
478 479
479const char *ipmi_addr_src_to_str(enum ipmi_addr_src src) 480const char *ipmi_addr_src_to_str(enum ipmi_addr_src src)
480{ 481{
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 4cc72fa017c7..7fddd8696211 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -68,6 +68,7 @@
68#include <linux/of_platform.h> 68#include <linux/of_platform.h>
69#include <linux/of_address.h> 69#include <linux/of_address.h>
70#include <linux/of_irq.h> 70#include <linux/of_irq.h>
71#include <linux/acpi.h>
71 72
72#ifdef CONFIG_PARISC 73#ifdef CONFIG_PARISC
73#include <asm/hardware.h> /* for register_parisc_driver() stuff */ 74#include <asm/hardware.h> /* for register_parisc_driver() stuff */
@@ -105,7 +106,8 @@ enum si_intf_state {
105enum si_type { 106enum si_type {
106 SI_KCS, SI_SMIC, SI_BT 107 SI_KCS, SI_SMIC, SI_BT
107}; 108};
108static char *si_to_str[] = { "kcs", "smic", "bt" }; 109
110static const char * const si_to_str[] = { "kcs", "smic", "bt" };
109 111
110#define DEVICE_NAME "ipmi_si" 112#define DEVICE_NAME "ipmi_si"
111 113
@@ -1341,7 +1343,7 @@ static unsigned int num_slave_addrs;
1341 1343
1342#define IPMI_IO_ADDR_SPACE 0 1344#define IPMI_IO_ADDR_SPACE 0
1343#define IPMI_MEM_ADDR_SPACE 1 1345#define IPMI_MEM_ADDR_SPACE 1
1344static char *addr_space_to_str[] = { "i/o", "mem" }; 1346static const char * const addr_space_to_str[] = { "i/o", "mem" };
1345 1347
1346static int hotmod_handler(const char *val, struct kernel_param *kp); 1348static int hotmod_handler(const char *val, struct kernel_param *kp);
1347 1349
@@ -1723,27 +1725,31 @@ static int mem_setup(struct smi_info *info)
1723 */ 1725 */
1724enum hotmod_op { HM_ADD, HM_REMOVE }; 1726enum hotmod_op { HM_ADD, HM_REMOVE };
1725struct hotmod_vals { 1727struct hotmod_vals {
1726 char *name; 1728 const char *name;
1727 int val; 1729 const int val;
1728}; 1730};
1729static struct hotmod_vals hotmod_ops[] = { 1731
1732static const struct hotmod_vals hotmod_ops[] = {
1730 { "add", HM_ADD }, 1733 { "add", HM_ADD },
1731 { "remove", HM_REMOVE }, 1734 { "remove", HM_REMOVE },
1732 { NULL } 1735 { NULL }
1733}; 1736};
1734static struct hotmod_vals hotmod_si[] = { 1737
1738static const struct hotmod_vals hotmod_si[] = {
1735 { "kcs", SI_KCS }, 1739 { "kcs", SI_KCS },
1736 { "smic", SI_SMIC }, 1740 { "smic", SI_SMIC },
1737 { "bt", SI_BT }, 1741 { "bt", SI_BT },
1738 { NULL } 1742 { NULL }
1739}; 1743};
1740static struct hotmod_vals hotmod_as[] = { 1744
1745static const struct hotmod_vals hotmod_as[] = {
1741 { "mem", IPMI_MEM_ADDR_SPACE }, 1746 { "mem", IPMI_MEM_ADDR_SPACE },
1742 { "i/o", IPMI_IO_ADDR_SPACE }, 1747 { "i/o", IPMI_IO_ADDR_SPACE },
1743 { NULL } 1748 { NULL }
1744}; 1749};
1745 1750
1746static int parse_str(struct hotmod_vals *v, int *val, char *name, char **curr) 1751static int parse_str(const struct hotmod_vals *v, int *val, char *name,
1752 char **curr)
1747{ 1753{
1748 char *s; 1754 char *s;
1749 int i; 1755 int i;
@@ -2049,8 +2055,6 @@ static int hardcode_find_bmc(void)
2049 2055
2050#ifdef CONFIG_ACPI 2056#ifdef CONFIG_ACPI
2051 2057
2052#include <linux/acpi.h>
2053
2054/* 2058/*
2055 * Once we get an ACPI failure, we don't try any more, because we go 2059 * Once we get an ACPI failure, we don't try any more, because we go
2056 * through the tables sequentially. Once we don't find a table, there 2060 * through the tables sequentially. Once we don't find a table, there
@@ -2554,7 +2558,6 @@ static void ipmi_pci_remove(struct pci_dev *pdev)
2554{ 2558{
2555 struct smi_info *info = pci_get_drvdata(pdev); 2559 struct smi_info *info = pci_get_drvdata(pdev);
2556 cleanup_one_si(info); 2560 cleanup_one_si(info);
2557 pci_disable_device(pdev);
2558} 2561}
2559 2562
2560static const struct pci_device_id ipmi_pci_devices[] = { 2563static const struct pci_device_id ipmi_pci_devices[] = {
@@ -2870,7 +2873,7 @@ static int ipmi_parisc_remove(struct parisc_device *dev)
2870 return 0; 2873 return 0;
2871} 2874}
2872 2875
2873static struct parisc_device_id ipmi_parisc_tbl[] = { 2876static const struct parisc_device_id ipmi_parisc_tbl[] = {
2874 { HPHW_MC, HVERSION_REV_ANY_ID, 0x004, 0xC0 }, 2877 { HPHW_MC, HVERSION_REV_ANY_ID, 0x004, 0xC0 },
2875 { 0, } 2878 { 0, }
2876}; 2879};
@@ -3444,8 +3447,8 @@ static inline void wait_for_timer_and_thread(struct smi_info *smi_info)
3444 3447
3445static const struct ipmi_default_vals 3448static const struct ipmi_default_vals
3446{ 3449{
3447 int type; 3450 const int type;
3448 int port; 3451 const int port;
3449} ipmi_defaults[] = 3452} ipmi_defaults[] =
3450{ 3453{
3451 { .type = SI_KCS, .port = 0xca2 }, 3454 { .type = SI_KCS, .port = 0xca2 },
diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index 90e624662257..5f1c3d08ba65 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1959,7 +1959,6 @@ MODULE_DEVICE_TABLE(i2c, ssif_id);
1959static struct i2c_driver ssif_i2c_driver = { 1959static struct i2c_driver ssif_i2c_driver = {
1960 .class = I2C_CLASS_HWMON, 1960 .class = I2C_CLASS_HWMON,
1961 .driver = { 1961 .driver = {
1962 .owner = THIS_MODULE,
1963 .name = DEVICE_NAME 1962 .name = DEVICE_NAME
1964 }, 1963 },
1965 .probe = ssif_probe, 1964 .probe = ssif_probe,
diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
index e5d3e3f7a49b..67d426470e53 100644
--- a/drivers/char/mbcs.c
+++ b/drivers/char/mbcs.c
@@ -26,6 +26,7 @@
26#include <linux/uio.h> 26#include <linux/uio.h>
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/pagemap.h>
29#include <asm/io.h> 30#include <asm/io.h>
30#include <asm/uaccess.h> 31#include <asm/uaccess.h>
31#include <asm/pgtable.h> 32#include <asm/pgtable.h>
@@ -451,31 +452,8 @@ mbcs_sram_write(struct file * fp, const char __user *buf, size_t len, loff_t * o
451 452
452static loff_t mbcs_sram_llseek(struct file * filp, loff_t off, int whence) 453static loff_t mbcs_sram_llseek(struct file * filp, loff_t off, int whence)
453{ 454{
454 loff_t newpos; 455 return generic_file_llseek_size(filp, off, whence, MAX_LFS_FILESIZE,
455 456 MBCS_SRAM_SIZE);
456 switch (whence) {
457 case SEEK_SET:
458 newpos = off;
459 break;
460
461 case SEEK_CUR:
462 newpos = filp->f_pos + off;
463 break;
464
465 case SEEK_END:
466 newpos = MBCS_SRAM_SIZE + off;
467 break;
468
469 default: /* can't happen */
470 return -EINVAL;
471 }
472
473 if (newpos < 0)
474 return -EINVAL;
475
476 filp->f_pos = newpos;
477
478 return newpos;
479} 457}
480 458
481static uint64_t mbcs_pioaddr(struct mbcs_soft *soft, uint64_t offset) 459static uint64_t mbcs_pioaddr(struct mbcs_soft *soft, uint64_t offset)
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 6b1721f978c2..4f6f94c43412 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -689,7 +689,7 @@ static loff_t memory_lseek(struct file *file, loff_t offset, int orig)
689{ 689{
690 loff_t ret; 690 loff_t ret;
691 691
692 mutex_lock(&file_inode(file)->i_mutex); 692 inode_lock(file_inode(file));
693 switch (orig) { 693 switch (orig) {
694 case SEEK_CUR: 694 case SEEK_CUR:
695 offset += file->f_pos; 695 offset += file->f_pos;
@@ -706,7 +706,7 @@ static loff_t memory_lseek(struct file *file, loff_t offset, int orig)
706 default: 706 default:
707 ret = -EINVAL; 707 ret = -EINVAL;
708 } 708 }
709 mutex_unlock(&file_inode(file)->i_mutex); 709 inode_unlock(file_inode(file));
710 return ret; 710 return ret;
711} 711}
712 712
diff --git a/drivers/char/mspec.c b/drivers/char/mspec.c
index f1d7fa45c275..f3f92d5fcda0 100644
--- a/drivers/char/mspec.c
+++ b/drivers/char/mspec.c
@@ -93,14 +93,11 @@ struct vma_data {
93 spinlock_t lock; /* Serialize access to this structure. */ 93 spinlock_t lock; /* Serialize access to this structure. */
94 int count; /* Number of pages allocated. */ 94 int count; /* Number of pages allocated. */
95 enum mspec_page_type type; /* Type of pages allocated. */ 95 enum mspec_page_type type; /* Type of pages allocated. */
96 int flags; /* See VMD_xxx below. */
97 unsigned long vm_start; /* Original (unsplit) base. */ 96 unsigned long vm_start; /* Original (unsplit) base. */
98 unsigned long vm_end; /* Original (unsplit) end. */ 97 unsigned long vm_end; /* Original (unsplit) end. */
99 unsigned long maddr[0]; /* Array of MSPEC addresses. */ 98 unsigned long maddr[0]; /* Array of MSPEC addresses. */
100}; 99};
101 100
102#define VMD_VMALLOCED 0x1 /* vmalloc'd rather than kmalloc'd */
103
104/* used on shub2 to clear FOP cache in the HUB */ 101/* used on shub2 to clear FOP cache in the HUB */
105static unsigned long scratch_page[MAX_NUMNODES]; 102static unsigned long scratch_page[MAX_NUMNODES];
106#define SH2_AMO_CACHE_ENTRIES 4 103#define SH2_AMO_CACHE_ENTRIES 4
@@ -185,10 +182,7 @@ mspec_close(struct vm_area_struct *vma)
185 "failed to zero page %ld\n", my_page); 182 "failed to zero page %ld\n", my_page);
186 } 183 }
187 184
188 if (vdata->flags & VMD_VMALLOCED) 185 kvfree(vdata);
189 vfree(vdata);
190 else
191 kfree(vdata);
192} 186}
193 187
194/* 188/*
@@ -256,7 +250,7 @@ mspec_mmap(struct file *file, struct vm_area_struct *vma,
256 enum mspec_page_type type) 250 enum mspec_page_type type)
257{ 251{
258 struct vma_data *vdata; 252 struct vma_data *vdata;
259 int pages, vdata_size, flags = 0; 253 int pages, vdata_size;
260 254
261 if (vma->vm_pgoff != 0) 255 if (vma->vm_pgoff != 0)
262 return -EINVAL; 256 return -EINVAL;
@@ -271,16 +265,13 @@ mspec_mmap(struct file *file, struct vm_area_struct *vma,
271 vdata_size = sizeof(struct vma_data) + pages * sizeof(long); 265 vdata_size = sizeof(struct vma_data) + pages * sizeof(long);
272 if (vdata_size <= PAGE_SIZE) 266 if (vdata_size <= PAGE_SIZE)
273 vdata = kzalloc(vdata_size, GFP_KERNEL); 267 vdata = kzalloc(vdata_size, GFP_KERNEL);
274 else { 268 else
275 vdata = vzalloc(vdata_size); 269 vdata = vzalloc(vdata_size);
276 flags = VMD_VMALLOCED;
277 }
278 if (!vdata) 270 if (!vdata)
279 return -ENOMEM; 271 return -ENOMEM;
280 272
281 vdata->vm_start = vma->vm_start; 273 vdata->vm_start = vma->vm_start;
282 vdata->vm_end = vma->vm_end; 274 vdata->vm_end = vma->vm_end;
283 vdata->flags = flags;
284 vdata->type = type; 275 vdata->type = type;
285 spin_lock_init(&vdata->lock); 276 spin_lock_init(&vdata->lock);
286 atomic_set(&vdata->refcnt, 1); 277 atomic_set(&vdata->refcnt, 1);
diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
index 97c2d8d433d6..01292328a456 100644
--- a/drivers/char/nvram.c
+++ b/drivers/char/nvram.c
@@ -110,6 +110,7 @@
110#include <linux/io.h> 110#include <linux/io.h>
111#include <linux/uaccess.h> 111#include <linux/uaccess.h>
112#include <linux/mutex.h> 112#include <linux/mutex.h>
113#include <linux/pagemap.h>
113 114
114 115
115static DEFINE_MUTEX(nvram_mutex); 116static DEFINE_MUTEX(nvram_mutex);
@@ -213,21 +214,8 @@ void nvram_set_checksum(void)
213 214
214static loff_t nvram_llseek(struct file *file, loff_t offset, int origin) 215static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
215{ 216{
216 switch (origin) { 217 return generic_file_llseek_size(file, offset, origin, MAX_LFS_FILESIZE,
217 case 0: 218 NVRAM_BYTES);
218 /* nothing to do */
219 break;
220 case 1:
221 offset += file->f_pos;
222 break;
223 case 2:
224 offset += NVRAM_BYTES;
225 break;
226 default:
227 return -EINVAL;
228 }
229
230 return (offset >= 0) ? (file->f_pos = offset) : -EINVAL;
231} 219}
232 220
233static ssize_t nvram_read(struct file *file, char __user *buf, 221static ssize_t nvram_read(struct file *file, char __user *buf,
diff --git a/drivers/char/nwflash.c b/drivers/char/nwflash.c
index e371480d3639..dbe598de9b74 100644
--- a/drivers/char/nwflash.c
+++ b/drivers/char/nwflash.c
@@ -277,36 +277,7 @@ static loff_t flash_llseek(struct file *file, loff_t offset, int orig)
277 printk(KERN_DEBUG "flash_llseek: offset=0x%X, orig=0x%X.\n", 277 printk(KERN_DEBUG "flash_llseek: offset=0x%X, orig=0x%X.\n",
278 (unsigned int) offset, orig); 278 (unsigned int) offset, orig);
279 279
280 switch (orig) { 280 ret = no_seek_end_llseek_size(file, offset, orig, gbFlashSize);
281 case 0:
282 if (offset < 0) {
283 ret = -EINVAL;
284 break;
285 }
286
287 if ((unsigned int) offset > gbFlashSize) {
288 ret = -EINVAL;
289 break;
290 }
291
292 file->f_pos = (unsigned int) offset;
293 ret = file->f_pos;
294 break;
295 case 1:
296 if ((file->f_pos + offset) > gbFlashSize) {
297 ret = -EINVAL;
298 break;
299 }
300 if ((file->f_pos + offset) < 0) {
301 ret = -EINVAL;
302 break;
303 }
304 file->f_pos += offset;
305 ret = file->f_pos;
306 break;
307 default:
308 ret = -EINVAL;
309 }
310 mutex_unlock(&flash_mutex); 281 mutex_unlock(&flash_mutex);
311 return ret; 282 return ret;
312} 283}
diff --git a/drivers/char/ps3flash.c b/drivers/char/ps3flash.c
index 0b311fa277ef..b526dc15c271 100644
--- a/drivers/char/ps3flash.c
+++ b/drivers/char/ps3flash.c
@@ -290,9 +290,9 @@ static int ps3flash_fsync(struct file *file, loff_t start, loff_t end, int datas
290{ 290{
291 struct inode *inode = file_inode(file); 291 struct inode *inode = file_inode(file);
292 int err; 292 int err;
293 mutex_lock(&inode->i_mutex); 293 inode_lock(inode);
294 err = ps3flash_writeback(ps3flash_dev); 294 err = ps3flash_writeback(ps3flash_dev);
295 mutex_unlock(&inode->i_mutex); 295 inode_unlock(inode);
296 return err; 296 return err;
297} 297}
298 298
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 60316fbaf295..9b9809b709a5 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -71,7 +71,7 @@ static int raw_open(struct inode *inode, struct file *filp)
71 err = -ENODEV; 71 err = -ENODEV;
72 if (!bdev) 72 if (!bdev)
73 goto out; 73 goto out;
74 igrab(bdev->bd_inode); 74 bdgrab(bdev);
75 err = blkdev_get(bdev, filp->f_mode | FMODE_EXCL, raw_open); 75 err = blkdev_get(bdev, filp->f_mode | FMODE_EXCL, raw_open);
76 if (err) 76 if (err)
77 goto out; 77 goto out;
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index c50637db3a8a..e2fa89c88304 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -310,10 +310,12 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip,
310{ 310{
311 int duration_idx = TPM_UNDEFINED; 311 int duration_idx = TPM_UNDEFINED;
312 int duration = 0; 312 int duration = 0;
313 u8 category = (ordinal >> 24) & 0xFF;
314 313
315 if ((category == TPM_PROTECTED_COMMAND && ordinal < TPM_MAX_ORDINAL) || 314 /*
316 (category == TPM_CONNECTION_COMMAND && ordinal < TSC_MAX_ORDINAL)) 315 * We only have a duration table for protected commands, where the upper
316 * 16 bits are 0. For the few other ordinals the fallback will be used.
317 */
318 if (ordinal < TPM_MAX_ORDINAL)
317 duration_idx = tpm_ordinal_duration[ordinal]; 319 duration_idx = tpm_ordinal_duration[ordinal];
318 320
319 if (duration_idx != TPM_UNDEFINED) 321 if (duration_idx != TPM_UNDEFINED)
@@ -501,6 +503,21 @@ int tpm_get_timeouts(struct tpm_chip *chip)
501 struct duration_t *duration_cap; 503 struct duration_t *duration_cap;
502 ssize_t rc; 504 ssize_t rc;
503 505
506 if (chip->flags & TPM_CHIP_FLAG_TPM2) {
507 /* Fixed timeouts for TPM2 */
508 chip->vendor.timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A);
509 chip->vendor.timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B);
510 chip->vendor.timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C);
511 chip->vendor.timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D);
512 chip->vendor.duration[TPM_SHORT] =
513 msecs_to_jiffies(TPM2_DURATION_SHORT);
514 chip->vendor.duration[TPM_MEDIUM] =
515 msecs_to_jiffies(TPM2_DURATION_MEDIUM);
516 chip->vendor.duration[TPM_LONG] =
517 msecs_to_jiffies(TPM2_DURATION_LONG);
518 return 0;
519 }
520
504 tpm_cmd.header.in = tpm_getcap_header; 521 tpm_cmd.header.in = tpm_getcap_header;
505 tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; 522 tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP;
506 tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4); 523 tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index a4257a32964f..542a80cbfd9c 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -83,16 +83,20 @@ enum tpm2_structures {
83}; 83};
84 84
85enum tpm2_return_codes { 85enum tpm2_return_codes {
86 TPM2_RC_INITIALIZE = 0x0100, 86 TPM2_RC_HASH = 0x0083, /* RC_FMT1 */
87 TPM2_RC_TESTING = 0x090A, 87 TPM2_RC_INITIALIZE = 0x0100, /* RC_VER1 */
88 TPM2_RC_DISABLED = 0x0120, 88 TPM2_RC_DISABLED = 0x0120,
89 TPM2_RC_TESTING = 0x090A, /* RC_WARN */
89}; 90};
90 91
91enum tpm2_algorithms { 92enum tpm2_algorithms {
92 TPM2_ALG_SHA1 = 0x0004, 93 TPM2_ALG_SHA1 = 0x0004,
93 TPM2_ALG_KEYEDHASH = 0x0008, 94 TPM2_ALG_KEYEDHASH = 0x0008,
94 TPM2_ALG_SHA256 = 0x000B, 95 TPM2_ALG_SHA256 = 0x000B,
95 TPM2_ALG_NULL = 0x0010 96 TPM2_ALG_SHA384 = 0x000C,
97 TPM2_ALG_SHA512 = 0x000D,
98 TPM2_ALG_NULL = 0x0010,
99 TPM2_ALG_SM3_256 = 0x0012,
96}; 100};
97 101
98enum tpm2_command_codes { 102enum tpm2_command_codes {
@@ -138,7 +142,6 @@ struct tpm_vendor_specific {
138 unsigned long base; /* TPM base address */ 142 unsigned long base; /* TPM base address */
139 143
140 int irq; 144 int irq;
141 int probed_irq;
142 145
143 int region_size; 146 int region_size;
144 int have_region; 147 int have_region;
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index c12130485fc1..45a634016f95 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include "tpm.h" 18#include "tpm.h"
19#include <crypto/hash_info.h>
19#include <keys/trusted-type.h> 20#include <keys/trusted-type.h>
20 21
21enum tpm2_object_attributes { 22enum tpm2_object_attributes {
@@ -104,6 +105,19 @@ struct tpm2_cmd {
104 union tpm2_cmd_params params; 105 union tpm2_cmd_params params;
105} __packed; 106} __packed;
106 107
108struct tpm2_hash {
109 unsigned int crypto_id;
110 unsigned int tpm_id;
111};
112
113static struct tpm2_hash tpm2_hash_map[] = {
114 {HASH_ALGO_SHA1, TPM2_ALG_SHA1},
115 {HASH_ALGO_SHA256, TPM2_ALG_SHA256},
116 {HASH_ALGO_SHA384, TPM2_ALG_SHA384},
117 {HASH_ALGO_SHA512, TPM2_ALG_SHA512},
118 {HASH_ALGO_SM3_256, TPM2_ALG_SM3_256},
119};
120
107/* 121/*
108 * Array with one entry per ordinal defining the maximum amount 122 * Array with one entry per ordinal defining the maximum amount
109 * of time the chip could take to return the result. The values 123 * of time the chip could take to return the result. The values
@@ -429,8 +443,20 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
429{ 443{
430 unsigned int blob_len; 444 unsigned int blob_len;
431 struct tpm_buf buf; 445 struct tpm_buf buf;
446 u32 hash;
447 int i;
432 int rc; 448 int rc;
433 449
450 for (i = 0; i < ARRAY_SIZE(tpm2_hash_map); i++) {
451 if (options->hash == tpm2_hash_map[i].crypto_id) {
452 hash = tpm2_hash_map[i].tpm_id;
453 break;
454 }
455 }
456
457 if (i == ARRAY_SIZE(tpm2_hash_map))
458 return -EINVAL;
459
434 rc = tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_CREATE); 460 rc = tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_CREATE);
435 if (rc) 461 if (rc)
436 return rc; 462 return rc;
@@ -452,12 +478,26 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
452 tpm_buf_append_u8(&buf, payload->migratable); 478 tpm_buf_append_u8(&buf, payload->migratable);
453 479
454 /* public */ 480 /* public */
455 tpm_buf_append_u16(&buf, 14); 481 if (options->policydigest)
482 tpm_buf_append_u16(&buf, 14 + options->digest_len);
483 else
484 tpm_buf_append_u16(&buf, 14);
456 485
457 tpm_buf_append_u16(&buf, TPM2_ALG_KEYEDHASH); 486 tpm_buf_append_u16(&buf, TPM2_ALG_KEYEDHASH);
458 tpm_buf_append_u16(&buf, TPM2_ALG_SHA256); 487 tpm_buf_append_u16(&buf, hash);
459 tpm_buf_append_u32(&buf, TPM2_ATTR_USER_WITH_AUTH); 488
460 tpm_buf_append_u16(&buf, 0); /* policy digest size */ 489 /* policy */
490 if (options->policydigest) {
491 tpm_buf_append_u32(&buf, 0);
492 tpm_buf_append_u16(&buf, options->digest_len);
493 tpm_buf_append(&buf, options->policydigest,
494 options->digest_len);
495 } else {
496 tpm_buf_append_u32(&buf, TPM2_ATTR_USER_WITH_AUTH);
497 tpm_buf_append_u16(&buf, 0);
498 }
499
500 /* public parameters */
461 tpm_buf_append_u16(&buf, TPM2_ALG_NULL); 501 tpm_buf_append_u16(&buf, TPM2_ALG_NULL);
462 tpm_buf_append_u16(&buf, 0); 502 tpm_buf_append_u16(&buf, 0);
463 503
@@ -488,8 +528,12 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
488out: 528out:
489 tpm_buf_destroy(&buf); 529 tpm_buf_destroy(&buf);
490 530
491 if (rc > 0) 531 if (rc > 0) {
492 rc = -EPERM; 532 if ((rc & TPM2_RC_HASH) == TPM2_RC_HASH)
533 rc = -EINVAL;
534 else
535 rc = -EPERM;
536 }
493 537
494 return rc; 538 return rc;
495} 539}
@@ -583,7 +627,9 @@ static int tpm2_unseal(struct tpm_chip *chip,
583 return rc; 627 return rc;
584 628
585 tpm_buf_append_u32(&buf, blob_handle); 629 tpm_buf_append_u32(&buf, blob_handle);
586 tpm2_buf_append_auth(&buf, TPM2_RS_PW, 630 tpm2_buf_append_auth(&buf,
631 options->policyhandle ?
632 options->policyhandle : TPM2_RS_PW,
587 NULL /* nonce */, 0, 633 NULL /* nonce */, 0,
588 0 /* session_attributes */, 634 0 /* session_attributes */,
589 options->blobauth /* hmac */, 635 options->blobauth /* hmac */,
diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
index 4bb9727c1047..8342cf51ffdc 100644
--- a/drivers/char/tpm/tpm_crb.c
+++ b/drivers/char/tpm/tpm_crb.c
@@ -284,17 +284,9 @@ static int crb_acpi_add(struct acpi_device *device)
284 284
285 chip->vendor.priv = priv; 285 chip->vendor.priv = priv;
286 286
287 /* Default timeouts and durations */ 287 rc = tpm_get_timeouts(chip);
288 chip->vendor.timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A); 288 if (rc)
289 chip->vendor.timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B); 289 return rc;
290 chip->vendor.timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C);
291 chip->vendor.timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D);
292 chip->vendor.duration[TPM_SHORT] =
293 msecs_to_jiffies(TPM2_DURATION_SHORT);
294 chip->vendor.duration[TPM_MEDIUM] =
295 msecs_to_jiffies(TPM2_DURATION_MEDIUM);
296 chip->vendor.duration[TPM_LONG] =
297 msecs_to_jiffies(TPM2_DURATION_LONG);
298 290
299 chip->acpi_dev_handle = device->handle; 291 chip->acpi_dev_handle = device->handle;
300 292
diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
index 3e6a22658b63..b0a9a9e34241 100644
--- a/drivers/char/tpm/tpm_ibmvtpm.c
+++ b/drivers/char/tpm/tpm_ibmvtpm.c
@@ -90,7 +90,7 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
90 return 0; 90 return 0;
91 } 91 }
92 92
93 sig = wait_event_interruptible(ibmvtpm->wq, ibmvtpm->res_len != 0); 93 sig = wait_event_interruptible(ibmvtpm->wq, !ibmvtpm->tpm_processing_cmd);
94 if (sig) 94 if (sig)
95 return -EINTR; 95 return -EINTR;
96 96
@@ -125,7 +125,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
125 struct ibmvtpm_dev *ibmvtpm; 125 struct ibmvtpm_dev *ibmvtpm;
126 struct ibmvtpm_crq crq; 126 struct ibmvtpm_crq crq;
127 __be64 *word = (__be64 *)&crq; 127 __be64 *word = (__be64 *)&crq;
128 int rc; 128 int rc, sig;
129 129
130 ibmvtpm = (struct ibmvtpm_dev *)TPM_VPRIV(chip); 130 ibmvtpm = (struct ibmvtpm_dev *)TPM_VPRIV(chip);
131 131
@@ -141,18 +141,35 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
141 return -EIO; 141 return -EIO;
142 } 142 }
143 143
144 if (ibmvtpm->tpm_processing_cmd) {
145 dev_info(ibmvtpm->dev,
146 "Need to wait for TPM to finish\n");
147 /* wait for previous command to finish */
148 sig = wait_event_interruptible(ibmvtpm->wq, !ibmvtpm->tpm_processing_cmd);
149 if (sig)
150 return -EINTR;
151 }
152
144 spin_lock(&ibmvtpm->rtce_lock); 153 spin_lock(&ibmvtpm->rtce_lock);
154 ibmvtpm->res_len = 0;
145 memcpy((void *)ibmvtpm->rtce_buf, (void *)buf, count); 155 memcpy((void *)ibmvtpm->rtce_buf, (void *)buf, count);
146 crq.valid = (u8)IBMVTPM_VALID_CMD; 156 crq.valid = (u8)IBMVTPM_VALID_CMD;
147 crq.msg = (u8)VTPM_TPM_COMMAND; 157 crq.msg = (u8)VTPM_TPM_COMMAND;
148 crq.len = cpu_to_be16(count); 158 crq.len = cpu_to_be16(count);
149 crq.data = cpu_to_be32(ibmvtpm->rtce_dma_handle); 159 crq.data = cpu_to_be32(ibmvtpm->rtce_dma_handle);
150 160
161 /*
162 * set the processing flag before the Hcall, since we may get the
163 * result (interrupt) before even being able to check rc.
164 */
165 ibmvtpm->tpm_processing_cmd = true;
166
151 rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]), 167 rc = ibmvtpm_send_crq(ibmvtpm->vdev, be64_to_cpu(word[0]),
152 be64_to_cpu(word[1])); 168 be64_to_cpu(word[1]));
153 if (rc != H_SUCCESS) { 169 if (rc != H_SUCCESS) {
154 dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc); 170 dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
155 rc = 0; 171 rc = 0;
172 ibmvtpm->tpm_processing_cmd = false;
156 } else 173 } else
157 rc = count; 174 rc = count;
158 175
@@ -515,6 +532,7 @@ static void ibmvtpm_crq_process(struct ibmvtpm_crq *crq,
515 case VTPM_TPM_COMMAND_RES: 532 case VTPM_TPM_COMMAND_RES:
516 /* len of the data in rtce buffer */ 533 /* len of the data in rtce buffer */
517 ibmvtpm->res_len = be16_to_cpu(crq->len); 534 ibmvtpm->res_len = be16_to_cpu(crq->len);
535 ibmvtpm->tpm_processing_cmd = false;
518 wake_up_interruptible(&ibmvtpm->wq); 536 wake_up_interruptible(&ibmvtpm->wq);
519 return; 537 return;
520 default: 538 default:
diff --git a/drivers/char/tpm/tpm_ibmvtpm.h b/drivers/char/tpm/tpm_ibmvtpm.h
index 6af92890518f..91dfe766d080 100644
--- a/drivers/char/tpm/tpm_ibmvtpm.h
+++ b/drivers/char/tpm/tpm_ibmvtpm.h
@@ -45,6 +45,7 @@ struct ibmvtpm_dev {
45 wait_queue_head_t wq; 45 wait_queue_head_t wq;
46 u16 res_len; 46 u16 res_len;
47 u32 vtpm_version; 47 u32 vtpm_version;
48 bool tpm_processing_cmd;
48}; 49};
49 50
50#define CRQ_RES_BUF_SIZE PAGE_SIZE 51#define CRQ_RES_BUF_SIZE PAGE_SIZE
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index 65f7eecc45b0..8a3509cb10da 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -401,7 +401,7 @@ static void disable_interrupts(struct tpm_chip *chip)
401 iowrite32(intmask, 401 iowrite32(intmask,
402 chip->vendor.iobase + 402 chip->vendor.iobase +
403 TPM_INT_ENABLE(chip->vendor.locality)); 403 TPM_INT_ENABLE(chip->vendor.locality));
404 free_irq(chip->vendor.irq, chip); 404 devm_free_irq(chip->pdev, chip->vendor.irq, chip);
405 chip->vendor.irq = 0; 405 chip->vendor.irq = 0;
406} 406}
407 407
@@ -461,11 +461,8 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
461 chip->vendor.irq = irq; 461 chip->vendor.irq = irq;
462 if (!priv->irq_tested) 462 if (!priv->irq_tested)
463 msleep(1); 463 msleep(1);
464 if (!priv->irq_tested) { 464 if (!priv->irq_tested)
465 disable_interrupts(chip); 465 disable_interrupts(chip);
466 dev_err(chip->pdev,
467 FW_BUG "TPM interrupt not working, polling instead\n");
468 }
469 priv->irq_tested = true; 466 priv->irq_tested = true;
470 return rc; 467 return rc;
471} 468}
@@ -570,26 +567,6 @@ static const struct tpm_class_ops tpm_tis = {
570 .req_canceled = tpm_tis_req_canceled, 567 .req_canceled = tpm_tis_req_canceled,
571}; 568};
572 569
573static irqreturn_t tis_int_probe(int irq, void *dev_id)
574{
575 struct tpm_chip *chip = dev_id;
576 u32 interrupt;
577
578 interrupt = ioread32(chip->vendor.iobase +
579 TPM_INT_STATUS(chip->vendor.locality));
580
581 if (interrupt == 0)
582 return IRQ_NONE;
583
584 chip->vendor.probed_irq = irq;
585
586 /* Clear interrupts handled with TPM_EOI */
587 iowrite32(interrupt,
588 chip->vendor.iobase +
589 TPM_INT_STATUS(chip->vendor.locality));
590 return IRQ_HANDLED;
591}
592
593static irqreturn_t tis_int_handler(int dummy, void *dev_id) 570static irqreturn_t tis_int_handler(int dummy, void *dev_id)
594{ 571{
595 struct tpm_chip *chip = dev_id; 572 struct tpm_chip *chip = dev_id;
@@ -622,6 +599,84 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id)
622 return IRQ_HANDLED; 599 return IRQ_HANDLED;
623} 600}
624 601
602/* Register the IRQ and issue a command that will cause an interrupt. If an
603 * irq is seen then leave the chip setup for IRQ operation, otherwise reverse
604 * everything and leave in polling mode. Returns 0 on success.
605 */
606static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask,
607 int flags, int irq)
608{
609 struct priv_data *priv = chip->vendor.priv;
610 u8 original_int_vec;
611
612 if (devm_request_irq(chip->pdev, irq, tis_int_handler, flags,
613 chip->devname, chip) != 0) {
614 dev_info(chip->pdev, "Unable to request irq: %d for probe\n",
615 irq);
616 return -1;
617 }
618 chip->vendor.irq = irq;
619
620 original_int_vec = ioread8(chip->vendor.iobase +
621 TPM_INT_VECTOR(chip->vendor.locality));
622 iowrite8(irq,
623 chip->vendor.iobase + TPM_INT_VECTOR(chip->vendor.locality));
624
625 /* Clear all existing */
626 iowrite32(ioread32(chip->vendor.iobase +
627 TPM_INT_STATUS(chip->vendor.locality)),
628 chip->vendor.iobase + TPM_INT_STATUS(chip->vendor.locality));
629
630 /* Turn on */
631 iowrite32(intmask | TPM_GLOBAL_INT_ENABLE,
632 chip->vendor.iobase + TPM_INT_ENABLE(chip->vendor.locality));
633
634 priv->irq_tested = false;
635
636 /* Generate an interrupt by having the core call through to
637 * tpm_tis_send
638 */
639 if (chip->flags & TPM_CHIP_FLAG_TPM2)
640 tpm2_gen_interrupt(chip);
641 else
642 tpm_gen_interrupt(chip);
643
644 /* tpm_tis_send will either confirm the interrupt is working or it
645 * will call disable_irq which undoes all of the above.
646 */
647 if (!chip->vendor.irq) {
648 iowrite8(original_int_vec,
649 chip->vendor.iobase +
650 TPM_INT_VECTOR(chip->vendor.locality));
651 return 1;
652 }
653
654 return 0;
655}
656
657/* Try to find the IRQ the TPM is using. This is for legacy x86 systems that
658 * do not have ACPI/etc. We typically expect the interrupt to be declared if
659 * present.
660 */
661static void tpm_tis_probe_irq(struct tpm_chip *chip, u32 intmask)
662{
663 u8 original_int_vec;
664 int i;
665
666 original_int_vec = ioread8(chip->vendor.iobase +
667 TPM_INT_VECTOR(chip->vendor.locality));
668
669 if (!original_int_vec) {
670 if (IS_ENABLED(CONFIG_X86))
671 for (i = 3; i <= 15; i++)
672 if (!tpm_tis_probe_irq_single(chip, intmask, 0,
673 i))
674 return;
675 } else if (!tpm_tis_probe_irq_single(chip, intmask, 0,
676 original_int_vec))
677 return;
678}
679
625static bool interrupts = true; 680static bool interrupts = true;
626module_param(interrupts, bool, 0444); 681module_param(interrupts, bool, 0444);
627MODULE_PARM_DESC(interrupts, "Enable interrupts"); 682MODULE_PARM_DESC(interrupts, "Enable interrupts");
@@ -644,8 +699,7 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info,
644 acpi_handle acpi_dev_handle) 699 acpi_handle acpi_dev_handle)
645{ 700{
646 u32 vendor, intfcaps, intmask; 701 u32 vendor, intfcaps, intmask;
647 int rc, i, irq_s, irq_e, probe; 702 int rc, probe;
648 int irq_r = -1;
649 struct tpm_chip *chip; 703 struct tpm_chip *chip;
650 struct priv_data *priv; 704 struct priv_data *priv;
651 705
@@ -677,6 +731,15 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info,
677 goto out_err; 731 goto out_err;
678 } 732 }
679 733
734 /* Take control of the TPM's interrupt hardware and shut it off */
735 intmask = ioread32(chip->vendor.iobase +
736 TPM_INT_ENABLE(chip->vendor.locality));
737 intmask |= TPM_INTF_CMD_READY_INT | TPM_INTF_LOCALITY_CHANGE_INT |
738 TPM_INTF_DATA_AVAIL_INT | TPM_INTF_STS_VALID_INT;
739 intmask &= ~TPM_GLOBAL_INT_ENABLE;
740 iowrite32(intmask,
741 chip->vendor.iobase + TPM_INT_ENABLE(chip->vendor.locality));
742
680 if (request_locality(chip, 0) != 0) { 743 if (request_locality(chip, 0) != 0) {
681 rc = -ENODEV; 744 rc = -ENODEV;
682 goto out_err; 745 goto out_err;
@@ -731,126 +794,31 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info,
731 if (intfcaps & TPM_INTF_DATA_AVAIL_INT) 794 if (intfcaps & TPM_INTF_DATA_AVAIL_INT)
732 dev_dbg(dev, "\tData Avail Int Support\n"); 795 dev_dbg(dev, "\tData Avail Int Support\n");
733 796
797 /* Very early on issue a command to the TPM in polling mode to make
798 * sure it works. May as well use that command to set the proper
799 * timeouts for the driver.
800 */
801 if (tpm_get_timeouts(chip)) {
802 dev_err(dev, "Could not get TPM timeouts and durations\n");
803 rc = -ENODEV;
804 goto out_err;
805 }
806
734 /* INTERRUPT Setup */ 807 /* INTERRUPT Setup */
735 init_waitqueue_head(&chip->vendor.read_queue); 808 init_waitqueue_head(&chip->vendor.read_queue);
736 init_waitqueue_head(&chip->vendor.int_queue); 809 init_waitqueue_head(&chip->vendor.int_queue);
737 810 if (interrupts) {
738 intmask = 811 if (tpm_info->irq) {
739 ioread32(chip->vendor.iobase + 812 tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
740 TPM_INT_ENABLE(chip->vendor.locality)); 813 tpm_info->irq);
741 814 if (!chip->vendor.irq)
742 intmask |= TPM_INTF_CMD_READY_INT 815 dev_err(chip->pdev, FW_BUG
743 | TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT 816 "TPM interrupt not working, polling instead\n");
744 | TPM_INTF_STS_VALID_INT; 817 } else
745 818 tpm_tis_probe_irq(chip, intmask);
746 iowrite32(intmask,
747 chip->vendor.iobase +
748 TPM_INT_ENABLE(chip->vendor.locality));
749 if (interrupts)
750 chip->vendor.irq = tpm_info->irq;
751 if (interrupts && !chip->vendor.irq) {
752 irq_s =
753 ioread8(chip->vendor.iobase +
754 TPM_INT_VECTOR(chip->vendor.locality));
755 irq_r = irq_s;
756 if (irq_s) {
757 irq_e = irq_s;
758 } else {
759 irq_s = 3;
760 irq_e = 15;
761 }
762
763 for (i = irq_s; i <= irq_e && chip->vendor.irq == 0; i++) {
764 iowrite8(i, chip->vendor.iobase +
765 TPM_INT_VECTOR(chip->vendor.locality));
766 if (devm_request_irq
767 (dev, i, tis_int_probe, IRQF_SHARED,
768 chip->devname, chip) != 0) {
769 dev_info(chip->pdev,
770 "Unable to request irq: %d for probe\n",
771 i);
772 continue;
773 }
774
775 /* Clear all existing */
776 iowrite32(ioread32
777 (chip->vendor.iobase +
778 TPM_INT_STATUS(chip->vendor.locality)),
779 chip->vendor.iobase +
780 TPM_INT_STATUS(chip->vendor.locality));
781
782 /* Turn on */
783 iowrite32(intmask | TPM_GLOBAL_INT_ENABLE,
784 chip->vendor.iobase +
785 TPM_INT_ENABLE(chip->vendor.locality));
786
787 chip->vendor.probed_irq = 0;
788
789 /* Generate Interrupts */
790 if (chip->flags & TPM_CHIP_FLAG_TPM2)
791 tpm2_gen_interrupt(chip);
792 else
793 tpm_gen_interrupt(chip);
794
795 chip->vendor.irq = chip->vendor.probed_irq;
796
797 /* free_irq will call into tis_int_probe;
798 clear all irqs we haven't seen while doing
799 tpm_gen_interrupt */
800 iowrite32(ioread32
801 (chip->vendor.iobase +
802 TPM_INT_STATUS(chip->vendor.locality)),
803 chip->vendor.iobase +
804 TPM_INT_STATUS(chip->vendor.locality));
805
806 /* Turn off */
807 iowrite32(intmask,
808 chip->vendor.iobase +
809 TPM_INT_ENABLE(chip->vendor.locality));
810
811 devm_free_irq(dev, i, chip);
812 }
813 } 819 }
814 if (chip->vendor.irq) {
815 iowrite8(chip->vendor.irq,
816 chip->vendor.iobase +
817 TPM_INT_VECTOR(chip->vendor.locality));
818 if (devm_request_irq
819 (dev, chip->vendor.irq, tis_int_handler, IRQF_SHARED,
820 chip->devname, chip) != 0) {
821 dev_info(chip->pdev,
822 "Unable to request irq: %d for use\n",
823 chip->vendor.irq);
824 chip->vendor.irq = 0;
825 } else {
826 /* Clear all existing */
827 iowrite32(ioread32
828 (chip->vendor.iobase +
829 TPM_INT_STATUS(chip->vendor.locality)),
830 chip->vendor.iobase +
831 TPM_INT_STATUS(chip->vendor.locality));
832
833 /* Turn on */
834 iowrite32(intmask | TPM_GLOBAL_INT_ENABLE,
835 chip->vendor.iobase +
836 TPM_INT_ENABLE(chip->vendor.locality));
837 }
838 } else if (irq_r != -1)
839 iowrite8(irq_r, chip->vendor.iobase +
840 TPM_INT_VECTOR(chip->vendor.locality));
841 820
842 if (chip->flags & TPM_CHIP_FLAG_TPM2) { 821 if (chip->flags & TPM_CHIP_FLAG_TPM2) {
843 chip->vendor.timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A);
844 chip->vendor.timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B);
845 chip->vendor.timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C);
846 chip->vendor.timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D);
847 chip->vendor.duration[TPM_SHORT] =
848 msecs_to_jiffies(TPM2_DURATION_SHORT);
849 chip->vendor.duration[TPM_MEDIUM] =
850 msecs_to_jiffies(TPM2_DURATION_MEDIUM);
851 chip->vendor.duration[TPM_LONG] =
852 msecs_to_jiffies(TPM2_DURATION_LONG);
853
854 rc = tpm2_do_selftest(chip); 822 rc = tpm2_do_selftest(chip);
855 if (rc == TPM2_RC_INITIALIZE) { 823 if (rc == TPM2_RC_INITIALIZE) {
856 dev_warn(dev, "Firmware has not started TPM\n"); 824 dev_warn(dev, "Firmware has not started TPM\n");
@@ -866,12 +834,6 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info,
866 goto out_err; 834 goto out_err;
867 } 835 }
868 } else { 836 } else {
869 if (tpm_get_timeouts(chip)) {
870 dev_err(dev, "Could not get TPM timeouts and durations\n");
871 rc = -ENODEV;
872 goto out_err;
873 }
874
875 if (tpm_do_selftest(chip)) { 837 if (tpm_do_selftest(chip)) {
876 dev_err(dev, "TPM self test failed\n"); 838 dev_err(dev, "TPM self test failed\n");
877 rc = -ENODEV; 839 rc = -ENODEV;