diff options
Diffstat (limited to 'drivers')
89 files changed, 4665 insertions, 557 deletions
diff --git a/drivers/Kconfig b/drivers/Kconfig index b3138fbb46a4..e0a4ae61a2c4 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig | |||
| @@ -52,6 +52,8 @@ source "drivers/i2c/Kconfig" | |||
| 52 | 52 | ||
| 53 | source "drivers/spi/Kconfig" | 53 | source "drivers/spi/Kconfig" |
| 54 | 54 | ||
| 55 | source "drivers/spmi/Kconfig" | ||
| 56 | |||
| 55 | source "drivers/hsi/Kconfig" | 57 | source "drivers/hsi/Kconfig" |
| 56 | 58 | ||
| 57 | source "drivers/pps/Kconfig" | 59 | source "drivers/pps/Kconfig" |
diff --git a/drivers/Makefile b/drivers/Makefile index 8e3b8b06c0b2..3d6de8b489c5 100644 --- a/drivers/Makefile +++ b/drivers/Makefile | |||
| @@ -66,6 +66,7 @@ obj-$(CONFIG_ATA) += ata/ | |||
| 66 | obj-$(CONFIG_TARGET_CORE) += target/ | 66 | obj-$(CONFIG_TARGET_CORE) += target/ |
| 67 | obj-$(CONFIG_MTD) += mtd/ | 67 | obj-$(CONFIG_MTD) += mtd/ |
| 68 | obj-$(CONFIG_SPI) += spi/ | 68 | obj-$(CONFIG_SPI) += spi/ |
| 69 | obj-$(CONFIG_SPMI) += spmi/ | ||
| 69 | obj-y += hsi/ | 70 | obj-y += hsi/ |
| 70 | obj-y += net/ | 71 | obj-y += net/ |
| 71 | obj-$(CONFIG_ATM) += atm/ | 72 | obj-$(CONFIG_ATM) += atm/ |
diff --git a/drivers/base/regmap/regmap-spmi.c b/drivers/base/regmap/regmap-spmi.c index ac2391013db1..d7026dc33388 100644 --- a/drivers/base/regmap/regmap-spmi.c +++ b/drivers/base/regmap/regmap-spmi.c | |||
| @@ -22,69 +22,235 @@ | |||
| 22 | #include <linux/module.h> | 22 | #include <linux/module.h> |
| 23 | #include <linux/init.h> | 23 | #include <linux/init.h> |
| 24 | 24 | ||
| 25 | static int regmap_spmi_read(void *context, | 25 | static int regmap_spmi_base_read(void *context, |
| 26 | const void *reg, size_t reg_size, | 26 | const void *reg, size_t reg_size, |
| 27 | void *val, size_t val_size) | 27 | void *val, size_t val_size) |
| 28 | { | 28 | { |
| 29 | u8 addr = *(u8 *)reg; | ||
| 30 | int err = 0; | ||
| 31 | |||
| 32 | BUG_ON(reg_size != 1); | ||
| 33 | |||
| 34 | while (val_size-- && !err) | ||
| 35 | err = spmi_register_read(context, addr++, val++); | ||
| 36 | |||
| 37 | return err; | ||
| 38 | } | ||
| 39 | |||
| 40 | static int regmap_spmi_base_gather_write(void *context, | ||
| 41 | const void *reg, size_t reg_size, | ||
| 42 | const void *val, size_t val_size) | ||
| 43 | { | ||
| 44 | const u8 *data = val; | ||
| 45 | u8 addr = *(u8 *)reg; | ||
| 46 | int err = 0; | ||
| 47 | |||
| 48 | BUG_ON(reg_size != 1); | ||
| 49 | |||
| 50 | /* | ||
| 51 | * SPMI defines a more bandwidth-efficient 'Register 0 Write' sequence, | ||
| 52 | * use it when possible. | ||
| 53 | */ | ||
| 54 | if (addr == 0 && val_size) { | ||
| 55 | err = spmi_register_zero_write(context, *data); | ||
| 56 | if (err) | ||
| 57 | goto err_out; | ||
| 58 | |||
| 59 | data++; | ||
| 60 | addr++; | ||
| 61 | val_size--; | ||
| 62 | } | ||
| 63 | |||
| 64 | while (val_size) { | ||
| 65 | err = spmi_register_write(context, addr, *data); | ||
| 66 | if (err) | ||
| 67 | goto err_out; | ||
| 68 | |||
| 69 | data++; | ||
| 70 | addr++; | ||
| 71 | val_size--; | ||
| 72 | } | ||
| 73 | |||
| 74 | err_out: | ||
| 75 | return err; | ||
| 76 | } | ||
| 77 | |||
| 78 | static int regmap_spmi_base_write(void *context, const void *data, | ||
| 79 | size_t count) | ||
| 80 | { | ||
| 81 | BUG_ON(count < 1); | ||
| 82 | return regmap_spmi_base_gather_write(context, data, 1, data + 1, | ||
| 83 | count - 1); | ||
| 84 | } | ||
| 85 | |||
| 86 | static struct regmap_bus regmap_spmi_base = { | ||
| 87 | .read = regmap_spmi_base_read, | ||
| 88 | .write = regmap_spmi_base_write, | ||
| 89 | .gather_write = regmap_spmi_base_gather_write, | ||
| 90 | .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, | ||
| 91 | .val_format_endian_default = REGMAP_ENDIAN_NATIVE, | ||
| 92 | }; | ||
| 93 | |||
| 94 | /** | ||
| 95 | * regmap_init_spmi_base(): Create regmap for the Base register space | ||
| 96 | * @sdev: SPMI device that will be interacted with | ||
| 97 | * @config: Configuration for register map | ||
| 98 | * | ||
| 99 | * The return value will be an ERR_PTR() on error or a valid pointer to | ||
| 100 | * a struct regmap. | ||
| 101 | */ | ||
| 102 | struct regmap *regmap_init_spmi_base(struct spmi_device *sdev, | ||
| 103 | const struct regmap_config *config) | ||
| 104 | { | ||
| 105 | return regmap_init(&sdev->dev, ®map_spmi_base, sdev, config); | ||
| 106 | } | ||
| 107 | EXPORT_SYMBOL_GPL(regmap_init_spmi_base); | ||
| 108 | |||
| 109 | /** | ||
| 110 | * devm_regmap_init_spmi_base(): Create managed regmap for Base register space | ||
| 111 | * @sdev: SPMI device that will be interacted with | ||
| 112 | * @config: Configuration for register map | ||
| 113 | * | ||
| 114 | * The return value will be an ERR_PTR() on error or a valid pointer | ||
| 115 | * to a struct regmap. The regmap will be automatically freed by the | ||
| 116 | * device management code. | ||
| 117 | */ | ||
| 118 | struct regmap *devm_regmap_init_spmi_base(struct spmi_device *sdev, | ||
| 119 | const struct regmap_config *config) | ||
| 120 | { | ||
| 121 | return devm_regmap_init(&sdev->dev, ®map_spmi_base, sdev, config); | ||
| 122 | } | ||
| 123 | EXPORT_SYMBOL_GPL(devm_regmap_init_spmi_base); | ||
| 124 | |||
| 125 | static int regmap_spmi_ext_read(void *context, | ||
| 126 | const void *reg, size_t reg_size, | ||
| 127 | void *val, size_t val_size) | ||
| 128 | { | ||
| 129 | int err = 0; | ||
| 130 | size_t len; | ||
| 131 | u16 addr; | ||
| 132 | |||
| 29 | BUG_ON(reg_size != 2); | 133 | BUG_ON(reg_size != 2); |
| 30 | return spmi_ext_register_readl(context, *(u16 *)reg, | 134 | |
| 31 | val, val_size); | 135 | addr = *(u16 *)reg; |
| 136 | |||
| 137 | /* | ||
| 138 | * Split accesses into two to take advantage of the more | ||
| 139 | * bandwidth-efficient 'Extended Register Read' command when possible | ||
| 140 | */ | ||
| 141 | while (addr <= 0xFF && val_size) { | ||
| 142 | len = min_t(size_t, val_size, 16); | ||
| 143 | |||
| 144 | err = spmi_ext_register_read(context, addr, val, len); | ||
| 145 | if (err) | ||
| 146 | goto err_out; | ||
| 147 | |||
| 148 | addr += len; | ||
| 149 | val += len; | ||
| 150 | val_size -= len; | ||
| 151 | } | ||
| 152 | |||
| 153 | while (val_size) { | ||
| 154 | len = min_t(size_t, val_size, 8); | ||
| 155 | |||
| 156 | err = spmi_ext_register_readl(context, addr, val, val_size); | ||
| 157 | if (err) | ||
| 158 | goto err_out; | ||
| 159 | |||
| 160 | addr += len; | ||
| 161 | val += len; | ||
| 162 | val_size -= len; | ||
| 163 | } | ||
| 164 | |||
| 165 | err_out: | ||
| 166 | return err; | ||
| 32 | } | 167 | } |
| 33 | 168 | ||
| 34 | static int regmap_spmi_gather_write(void *context, | 169 | static int regmap_spmi_ext_gather_write(void *context, |
| 35 | const void *reg, size_t reg_size, | 170 | const void *reg, size_t reg_size, |
| 36 | const void *val, size_t val_size) | 171 | const void *val, size_t val_size) |
| 37 | { | 172 | { |
| 173 | int err = 0; | ||
| 174 | size_t len; | ||
| 175 | u16 addr; | ||
| 176 | |||
| 38 | BUG_ON(reg_size != 2); | 177 | BUG_ON(reg_size != 2); |
| 39 | return spmi_ext_register_writel(context, *(u16 *)reg, val, val_size); | 178 | |
| 179 | addr = *(u16 *)reg; | ||
| 180 | |||
| 181 | while (addr <= 0xFF && val_size) { | ||
| 182 | len = min_t(size_t, val_size, 16); | ||
| 183 | |||
| 184 | err = spmi_ext_register_write(context, addr, val, len); | ||
| 185 | if (err) | ||
| 186 | goto err_out; | ||
| 187 | |||
| 188 | addr += len; | ||
| 189 | val += len; | ||
| 190 | val_size -= len; | ||
| 191 | } | ||
| 192 | |||
| 193 | while (val_size) { | ||
| 194 | len = min_t(size_t, val_size, 8); | ||
| 195 | |||
| 196 | err = spmi_ext_register_writel(context, addr, val, len); | ||
| 197 | if (err) | ||
| 198 | goto err_out; | ||
| 199 | |||
| 200 | addr += len; | ||
| 201 | val += len; | ||
| 202 | val_size -= len; | ||
| 203 | } | ||
| 204 | |||
| 205 | err_out: | ||
| 206 | return err; | ||
| 40 | } | 207 | } |
| 41 | 208 | ||
| 42 | static int regmap_spmi_write(void *context, const void *data, | 209 | static int regmap_spmi_ext_write(void *context, const void *data, |
| 43 | size_t count) | 210 | size_t count) |
| 44 | { | 211 | { |
| 45 | BUG_ON(count < 2); | 212 | BUG_ON(count < 2); |
| 46 | return regmap_spmi_gather_write(context, data, 2, data + 2, count - 2); | 213 | return regmap_spmi_ext_gather_write(context, data, 2, data + 2, |
| 214 | count - 2); | ||
| 47 | } | 215 | } |
| 48 | 216 | ||
| 49 | static struct regmap_bus regmap_spmi = { | 217 | static struct regmap_bus regmap_spmi_ext = { |
| 50 | .read = regmap_spmi_read, | 218 | .read = regmap_spmi_ext_read, |
| 51 | .write = regmap_spmi_write, | 219 | .write = regmap_spmi_ext_write, |
| 52 | .gather_write = regmap_spmi_gather_write, | 220 | .gather_write = regmap_spmi_ext_gather_write, |
| 53 | .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, | 221 | .reg_format_endian_default = REGMAP_ENDIAN_NATIVE, |
| 54 | .val_format_endian_default = REGMAP_ENDIAN_NATIVE, | 222 | .val_format_endian_default = REGMAP_ENDIAN_NATIVE, |
| 55 | }; | 223 | }; |
| 56 | 224 | ||
| 57 | /** | 225 | /** |
| 58 | * regmap_init_spmi(): Initialize register map | 226 | * regmap_init_spmi_ext(): Create regmap for Ext register space |
| 59 | * | 227 | * @sdev: Device that will be interacted with |
| 60 | * @sdev: Device that will be interacted with | 228 | * @config: Configuration for register map |
| 61 | * @config: Configuration for register map | ||
| 62 | * | 229 | * |
| 63 | * The return value will be an ERR_PTR() on error or a valid pointer to | 230 | * The return value will be an ERR_PTR() on error or a valid pointer to |
| 64 | * a struct regmap. | 231 | * a struct regmap. |
| 65 | */ | 232 | */ |
| 66 | struct regmap *regmap_init_spmi(struct spmi_device *sdev, | 233 | struct regmap *regmap_init_spmi_ext(struct spmi_device *sdev, |
| 67 | const struct regmap_config *config) | 234 | const struct regmap_config *config) |
| 68 | { | 235 | { |
| 69 | return regmap_init(&sdev->dev, ®map_spmi, sdev, config); | 236 | return regmap_init(&sdev->dev, ®map_spmi_ext, sdev, config); |
| 70 | } | 237 | } |
| 71 | EXPORT_SYMBOL_GPL(regmap_init_spmi); | 238 | EXPORT_SYMBOL_GPL(regmap_init_spmi_ext); |
| 72 | 239 | ||
| 73 | /** | 240 | /** |
| 74 | * devm_regmap_init_spmi(): Initialise managed register map | 241 | * devm_regmap_init_spmi_ext(): Create managed regmap for Ext register space |
| 75 | * | 242 | * @sdev: SPMI device that will be interacted with |
| 76 | * @sdev: Device that will be interacted with | 243 | * @config: Configuration for register map |
| 77 | * @config: Configuration for register map | ||
| 78 | * | 244 | * |
| 79 | * The return value will be an ERR_PTR() on error or a valid pointer | 245 | * The return value will be an ERR_PTR() on error or a valid pointer |
| 80 | * to a struct regmap. The regmap will be automatically freed by the | 246 | * to a struct regmap. The regmap will be automatically freed by the |
| 81 | * device management code. | 247 | * device management code. |
| 82 | */ | 248 | */ |
| 83 | struct regmap *devm_regmap_init_spmi(struct spmi_device *sdev, | 249 | struct regmap *devm_regmap_init_spmi_ext(struct spmi_device *sdev, |
| 84 | const struct regmap_config *config) | 250 | const struct regmap_config *config) |
| 85 | { | 251 | { |
| 86 | return devm_regmap_init(&sdev->dev, ®map_spmi, sdev, config); | 252 | return devm_regmap_init(&sdev->dev, ®map_spmi_ext, sdev, config); |
| 87 | } | 253 | } |
| 88 | EXPORT_SYMBOL_GPL(devm_regmap_init_spmi); | 254 | EXPORT_SYMBOL_GPL(devm_regmap_init_spmi_ext); |
| 89 | 255 | ||
| 90 | MODULE_LICENSE("GPL"); | 256 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c index 1b192395a90c..8121b4c70ede 100644 --- a/drivers/char/agp/frontend.c +++ b/drivers/char/agp/frontend.c | |||
| @@ -31,7 +31,6 @@ | |||
| 31 | #include <linux/module.h> | 31 | #include <linux/module.h> |
| 32 | #include <linux/mman.h> | 32 | #include <linux/mman.h> |
| 33 | #include <linux/pci.h> | 33 | #include <linux/pci.h> |
| 34 | #include <linux/init.h> | ||
| 35 | #include <linux/miscdevice.h> | 34 | #include <linux/miscdevice.h> |
| 36 | #include <linux/agp_backend.h> | 35 | #include <linux/agp_backend.h> |
| 37 | #include <linux/agpgart.h> | 36 | #include <linux/agpgart.h> |
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c index f39437addb58..0fbccce1cee9 100644 --- a/drivers/char/agp/generic.c +++ b/drivers/char/agp/generic.c | |||
| @@ -29,7 +29,6 @@ | |||
| 29 | */ | 29 | */ |
| 30 | #include <linux/module.h> | 30 | #include <linux/module.h> |
| 31 | #include <linux/pci.h> | 31 | #include <linux/pci.h> |
| 32 | #include <linux/init.h> | ||
| 33 | #include <linux/pagemap.h> | 32 | #include <linux/pagemap.h> |
| 34 | #include <linux/miscdevice.h> | 33 | #include <linux/miscdevice.h> |
| 35 | #include <linux/pm.h> | 34 | #include <linux/pm.h> |
diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c index 5c85350f4c3d..9a024f899dd4 100644 --- a/drivers/char/agp/intel-gtt.c +++ b/drivers/char/agp/intel-gtt.c | |||
| @@ -17,7 +17,6 @@ | |||
| 17 | 17 | ||
| 18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
| 19 | #include <linux/pci.h> | 19 | #include <linux/pci.h> |
| 20 | #include <linux/init.h> | ||
| 21 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
| 22 | #include <linux/pagemap.h> | 21 | #include <linux/pagemap.h> |
| 23 | #include <linux/agp_backend.h> | 22 | #include <linux/agp_backend.h> |
diff --git a/drivers/char/agp/sgi-agp.c b/drivers/char/agp/sgi-agp.c index 05b8d0241bde..3051c73bc383 100644 --- a/drivers/char/agp/sgi-agp.c +++ b/drivers/char/agp/sgi-agp.c | |||
| @@ -15,7 +15,6 @@ | |||
| 15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
| 16 | #include <linux/pci.h> | 16 | #include <linux/pci.h> |
| 17 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
| 18 | #include <linux/init.h> | ||
| 19 | #include <linux/agp_backend.h> | 18 | #include <linux/agp_backend.h> |
| 20 | #include <asm/sn/addrs.h> | 19 | #include <asm/sn/addrs.h> |
| 21 | #include <asm/sn/io.h> | 20 | #include <asm/sn/io.h> |
diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 43577ca780e3..8c3b255e629a 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c | |||
| @@ -8,7 +8,6 @@ | |||
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | #include <linux/hw_random.h> | 10 | #include <linux/hw_random.h> |
| 11 | #include <linux/init.h> | ||
| 12 | #include <linux/io.h> | 11 | #include <linux/io.h> |
| 13 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> | 13 | #include <linux/module.h> |
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c index a0f7724852eb..b9495a8c05c6 100644 --- a/drivers/char/hw_random/core.c +++ b/drivers/char/hw_random/core.c | |||
| @@ -37,7 +37,6 @@ | |||
| 37 | #include <linux/kernel.h> | 37 | #include <linux/kernel.h> |
| 38 | #include <linux/fs.h> | 38 | #include <linux/fs.h> |
| 39 | #include <linux/sched.h> | 39 | #include <linux/sched.h> |
| 40 | #include <linux/init.h> | ||
| 41 | #include <linux/miscdevice.h> | 40 | #include <linux/miscdevice.h> |
| 42 | #include <linux/delay.h> | 41 | #include <linux/delay.h> |
| 43 | #include <linux/slab.h> | 42 | #include <linux/slab.h> |
diff --git a/drivers/char/hw_random/exynos-rng.c b/drivers/char/hw_random/exynos-rng.c index 402ccfb625c5..9f8277cc44b4 100644 --- a/drivers/char/hw_random/exynos-rng.c +++ b/drivers/char/hw_random/exynos-rng.c | |||
| @@ -22,7 +22,6 @@ | |||
| 22 | #include <linux/hw_random.h> | 22 | #include <linux/hw_random.h> |
| 23 | #include <linux/kernel.h> | 23 | #include <linux/kernel.h> |
| 24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
| 25 | #include <linux/init.h> | ||
| 26 | #include <linux/io.h> | 25 | #include <linux/io.h> |
| 27 | #include <linux/platform_device.h> | 26 | #include <linux/platform_device.h> |
| 28 | #include <linux/clk.h> | 27 | #include <linux/clk.h> |
diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c index f9beed54d0c8..432232eefe05 100644 --- a/drivers/char/hw_random/n2-drv.c +++ b/drivers/char/hw_random/n2-drv.c | |||
| @@ -7,7 +7,6 @@ | |||
| 7 | #include <linux/module.h> | 7 | #include <linux/module.h> |
| 8 | #include <linux/types.h> | 8 | #include <linux/types.h> |
| 9 | #include <linux/delay.h> | 9 | #include <linux/delay.h> |
| 10 | #include <linux/init.h> | ||
| 11 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
| 12 | #include <linux/workqueue.h> | 11 | #include <linux/workqueue.h> |
| 13 | #include <linux/preempt.h> | 12 | #include <linux/preempt.h> |
diff --git a/drivers/char/hw_random/nomadik-rng.c b/drivers/char/hw_random/nomadik-rng.c index 232b87fb5fc9..00e9d2d46634 100644 --- a/drivers/char/hw_random/nomadik-rng.c +++ b/drivers/char/hw_random/nomadik-rng.c | |||
| @@ -10,7 +10,6 @@ | |||
| 10 | 10 | ||
| 11 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
| 12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> | ||
| 14 | #include <linux/device.h> | 13 | #include <linux/device.h> |
| 15 | #include <linux/amba/bus.h> | 14 | #include <linux/amba/bus.h> |
| 16 | #include <linux/hw_random.h> | 15 | #include <linux/hw_random.h> |
diff --git a/drivers/char/hw_random/octeon-rng.c b/drivers/char/hw_random/octeon-rng.c index f2885dbe1849..b5cc3420c659 100644 --- a/drivers/char/hw_random/octeon-rng.c +++ b/drivers/char/hw_random/octeon-rng.c | |||
| @@ -10,7 +10,6 @@ | |||
| 10 | */ | 10 | */ |
| 11 | 11 | ||
| 12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> | ||
| 14 | #include <linux/platform_device.h> | 13 | #include <linux/platform_device.h> |
| 15 | #include <linux/device.h> | 14 | #include <linux/device.h> |
| 16 | #include <linux/hw_random.h> | 15 | #include <linux/hw_random.h> |
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c index 03f41896d090..b7efd3c1a882 100644 --- a/drivers/char/ipmi/ipmi_si_intf.c +++ b/drivers/char/ipmi/ipmi_si_intf.c | |||
| @@ -61,7 +61,6 @@ | |||
| 61 | #include <linux/ipmi_smi.h> | 61 | #include <linux/ipmi_smi.h> |
| 62 | #include <asm/io.h> | 62 | #include <asm/io.h> |
| 63 | #include "ipmi_si_sm.h" | 63 | #include "ipmi_si_sm.h" |
| 64 | #include <linux/init.h> | ||
| 65 | #include <linux/dmi.h> | 64 | #include <linux/dmi.h> |
| 66 | #include <linux/string.h> | 65 | #include <linux/string.h> |
| 67 | #include <linux/ctype.h> | 66 | #include <linux/ctype.h> |
diff --git a/drivers/char/mem.c b/drivers/char/mem.c index 92c5937f80c3..917403fe10da 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c | |||
| @@ -99,6 +99,9 @@ static ssize_t read_mem(struct file *file, char __user *buf, | |||
| 99 | ssize_t read, sz; | 99 | ssize_t read, sz; |
| 100 | char *ptr; | 100 | char *ptr; |
| 101 | 101 | ||
| 102 | if (p != *ppos) | ||
| 103 | return 0; | ||
| 104 | |||
| 102 | if (!valid_phys_addr_range(p, count)) | 105 | if (!valid_phys_addr_range(p, count)) |
| 103 | return -EFAULT; | 106 | return -EFAULT; |
| 104 | read = 0; | 107 | read = 0; |
| @@ -157,6 +160,9 @@ static ssize_t write_mem(struct file *file, const char __user *buf, | |||
| 157 | unsigned long copied; | 160 | unsigned long copied; |
| 158 | void *ptr; | 161 | void *ptr; |
| 159 | 162 | ||
| 163 | if (p != *ppos) | ||
| 164 | return -EFBIG; | ||
| 165 | |||
| 160 | if (!valid_phys_addr_range(p, count)) | 166 | if (!valid_phys_addr_range(p, count)) |
| 161 | return -EFAULT; | 167 | return -EFAULT; |
| 162 | 168 | ||
diff --git a/drivers/char/mwave/3780i.c b/drivers/char/mwave/3780i.c index 881c9e595939..28740046bc83 100644 --- a/drivers/char/mwave/3780i.c +++ b/drivers/char/mwave/3780i.c | |||
| @@ -50,7 +50,6 @@ | |||
| 50 | #include <linux/unistd.h> | 50 | #include <linux/unistd.h> |
| 51 | #include <linux/delay.h> | 51 | #include <linux/delay.h> |
| 52 | #include <linux/ioport.h> | 52 | #include <linux/ioport.h> |
| 53 | #include <linux/init.h> | ||
| 54 | #include <linux/bitops.h> | 53 | #include <linux/bitops.h> |
| 55 | #include <linux/sched.h> /* cond_resched() */ | 54 | #include <linux/sched.h> /* cond_resched() */ |
| 56 | 55 | ||
diff --git a/drivers/char/tile-srom.c b/drivers/char/tile-srom.c index 0e506bad1986..bd377472dcfb 100644 --- a/drivers/char/tile-srom.c +++ b/drivers/char/tile-srom.c | |||
| @@ -20,7 +20,6 @@ | |||
| 20 | 20 | ||
| 21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
| 22 | #include <linux/moduleparam.h> | 22 | #include <linux/moduleparam.h> |
| 23 | #include <linux/init.h> | ||
| 24 | #include <linux/kernel.h> /* printk() */ | 23 | #include <linux/kernel.h> /* printk() */ |
| 25 | #include <linux/slab.h> /* kmalloc() */ | 24 | #include <linux/slab.h> /* kmalloc() */ |
| 26 | #include <linux/fs.h> /* everything... */ | 25 | #include <linux/fs.h> /* everything... */ |
diff --git a/drivers/char/tpm/tpm_i2c_infineon.c b/drivers/char/tpm/tpm_i2c_infineon.c index 52b9b2b2f300..472af4bb1b61 100644 --- a/drivers/char/tpm/tpm_i2c_infineon.c +++ b/drivers/char/tpm/tpm_i2c_infineon.c | |||
| @@ -21,7 +21,6 @@ | |||
| 21 | * | 21 | * |
| 22 | * | 22 | * |
| 23 | */ | 23 | */ |
| 24 | #include <linux/init.h> | ||
| 25 | #include <linux/i2c.h> | 24 | #include <linux/i2c.h> |
| 26 | #include <linux/module.h> | 25 | #include <linux/module.h> |
| 27 | #include <linux/wait.h> | 26 | #include <linux/wait.h> |
diff --git a/drivers/char/tpm/tpm_i2c_stm_st33.c b/drivers/char/tpm/tpm_i2c_stm_st33.c index 5b0dd8ef74c0..3b7bf2162898 100644 --- a/drivers/char/tpm/tpm_i2c_stm_st33.c +++ b/drivers/char/tpm/tpm_i2c_stm_st33.c | |||
| @@ -38,7 +38,6 @@ | |||
| 38 | #include <linux/miscdevice.h> | 38 | #include <linux/miscdevice.h> |
| 39 | #include <linux/kernel.h> | 39 | #include <linux/kernel.h> |
| 40 | #include <linux/delay.h> | 40 | #include <linux/delay.h> |
| 41 | #include <linux/init.h> | ||
| 42 | #include <linux/wait.h> | 41 | #include <linux/wait.h> |
| 43 | #include <linux/string.h> | 42 | #include <linux/string.h> |
| 44 | #include <linux/interrupt.h> | 43 | #include <linux/interrupt.h> |
diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c index 18c5b9b16645..148d707a1d43 100644 --- a/drivers/connector/cn_proc.c +++ b/drivers/connector/cn_proc.c | |||
| @@ -95,7 +95,7 @@ void proc_fork_connector(struct task_struct *task) | |||
| 95 | msg->len = sizeof(*ev); | 95 | msg->len = sizeof(*ev); |
| 96 | msg->flags = 0; /* not used */ | 96 | msg->flags = 0; /* not used */ |
| 97 | /* If cn_netlink_send() failed, the data is not sent */ | 97 | /* If cn_netlink_send() failed, the data is not sent */ |
| 98 | cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); | 98 | cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | void proc_exec_connector(struct task_struct *task) | 101 | void proc_exec_connector(struct task_struct *task) |
| @@ -122,7 +122,7 @@ void proc_exec_connector(struct task_struct *task) | |||
| 122 | msg->ack = 0; /* not used */ | 122 | msg->ack = 0; /* not used */ |
| 123 | msg->len = sizeof(*ev); | 123 | msg->len = sizeof(*ev); |
| 124 | msg->flags = 0; /* not used */ | 124 | msg->flags = 0; /* not used */ |
| 125 | cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); | 125 | cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL); |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | void proc_id_connector(struct task_struct *task, int which_id) | 128 | void proc_id_connector(struct task_struct *task, int which_id) |
| @@ -163,7 +163,7 @@ void proc_id_connector(struct task_struct *task, int which_id) | |||
| 163 | msg->ack = 0; /* not used */ | 163 | msg->ack = 0; /* not used */ |
| 164 | msg->len = sizeof(*ev); | 164 | msg->len = sizeof(*ev); |
| 165 | msg->flags = 0; /* not used */ | 165 | msg->flags = 0; /* not used */ |
| 166 | cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); | 166 | cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL); |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | void proc_sid_connector(struct task_struct *task) | 169 | void proc_sid_connector(struct task_struct *task) |
| @@ -190,7 +190,7 @@ void proc_sid_connector(struct task_struct *task) | |||
| 190 | msg->ack = 0; /* not used */ | 190 | msg->ack = 0; /* not used */ |
| 191 | msg->len = sizeof(*ev); | 191 | msg->len = sizeof(*ev); |
| 192 | msg->flags = 0; /* not used */ | 192 | msg->flags = 0; /* not used */ |
| 193 | cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); | 193 | cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL); |
| 194 | } | 194 | } |
| 195 | 195 | ||
| 196 | void proc_ptrace_connector(struct task_struct *task, int ptrace_id) | 196 | void proc_ptrace_connector(struct task_struct *task, int ptrace_id) |
| @@ -225,7 +225,7 @@ void proc_ptrace_connector(struct task_struct *task, int ptrace_id) | |||
| 225 | msg->ack = 0; /* not used */ | 225 | msg->ack = 0; /* not used */ |
| 226 | msg->len = sizeof(*ev); | 226 | msg->len = sizeof(*ev); |
| 227 | msg->flags = 0; /* not used */ | 227 | msg->flags = 0; /* not used */ |
| 228 | cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); | 228 | cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL); |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | void proc_comm_connector(struct task_struct *task) | 231 | void proc_comm_connector(struct task_struct *task) |
| @@ -253,7 +253,7 @@ void proc_comm_connector(struct task_struct *task) | |||
| 253 | msg->ack = 0; /* not used */ | 253 | msg->ack = 0; /* not used */ |
| 254 | msg->len = sizeof(*ev); | 254 | msg->len = sizeof(*ev); |
| 255 | msg->flags = 0; /* not used */ | 255 | msg->flags = 0; /* not used */ |
| 256 | cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); | 256 | cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL); |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | void proc_coredump_connector(struct task_struct *task) | 259 | void proc_coredump_connector(struct task_struct *task) |
| @@ -280,7 +280,7 @@ void proc_coredump_connector(struct task_struct *task) | |||
| 280 | msg->ack = 0; /* not used */ | 280 | msg->ack = 0; /* not used */ |
| 281 | msg->len = sizeof(*ev); | 281 | msg->len = sizeof(*ev); |
| 282 | msg->flags = 0; /* not used */ | 282 | msg->flags = 0; /* not used */ |
| 283 | cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); | 283 | cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL); |
| 284 | } | 284 | } |
| 285 | 285 | ||
| 286 | void proc_exit_connector(struct task_struct *task) | 286 | void proc_exit_connector(struct task_struct *task) |
| @@ -309,7 +309,7 @@ void proc_exit_connector(struct task_struct *task) | |||
| 309 | msg->ack = 0; /* not used */ | 309 | msg->ack = 0; /* not used */ |
| 310 | msg->len = sizeof(*ev); | 310 | msg->len = sizeof(*ev); |
| 311 | msg->flags = 0; /* not used */ | 311 | msg->flags = 0; /* not used */ |
| 312 | cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); | 312 | cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL); |
| 313 | } | 313 | } |
| 314 | 314 | ||
| 315 | /* | 315 | /* |
| @@ -343,7 +343,7 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack) | |||
| 343 | msg->ack = rcvd_ack + 1; | 343 | msg->ack = rcvd_ack + 1; |
| 344 | msg->len = sizeof(*ev); | 344 | msg->len = sizeof(*ev); |
| 345 | msg->flags = 0; /* not used */ | 345 | msg->flags = 0; /* not used */ |
| 346 | cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); | 346 | cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_KERNEL); |
| 347 | } | 347 | } |
| 348 | 348 | ||
| 349 | /** | 349 | /** |
diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c index a36749f1e44a..77afe7487d34 100644 --- a/drivers/connector/connector.c +++ b/drivers/connector/connector.c | |||
| @@ -50,7 +50,7 @@ static int cn_already_initialized; | |||
| 50 | * | 50 | * |
| 51 | * Sequence number is incremented with each message to be sent. | 51 | * Sequence number is incremented with each message to be sent. |
| 52 | * | 52 | * |
| 53 | * If we expect reply to our message then the sequence number in | 53 | * If we expect a reply to our message then the sequence number in |
| 54 | * received message MUST be the same as in original message, and | 54 | * received message MUST be the same as in original message, and |
| 55 | * acknowledge number MUST be the same + 1. | 55 | * acknowledge number MUST be the same + 1. |
| 56 | * | 56 | * |
| @@ -62,8 +62,11 @@ static int cn_already_initialized; | |||
| 62 | * the acknowledgement number in the original message + 1, then it is | 62 | * the acknowledgement number in the original message + 1, then it is |
| 63 | * a new message. | 63 | * a new message. |
| 64 | * | 64 | * |
| 65 | * The message is sent to, the portid if given, the group if given, both if | ||
| 66 | * both, or if both are zero then the group is looked up and sent there. | ||
| 65 | */ | 67 | */ |
| 66 | int cn_netlink_send(struct cn_msg *msg, u32 __group, gfp_t gfp_mask) | 68 | int cn_netlink_send(struct cn_msg *msg, u32 portid, u32 __group, |
| 69 | gfp_t gfp_mask) | ||
| 67 | { | 70 | { |
| 68 | struct cn_callback_entry *__cbq; | 71 | struct cn_callback_entry *__cbq; |
| 69 | unsigned int size; | 72 | unsigned int size; |
| @@ -74,7 +77,9 @@ int cn_netlink_send(struct cn_msg *msg, u32 __group, gfp_t gfp_mask) | |||
| 74 | u32 group = 0; | 77 | u32 group = 0; |
| 75 | int found = 0; | 78 | int found = 0; |
| 76 | 79 | ||
| 77 | if (!__group) { | 80 | if (portid || __group) { |
| 81 | group = __group; | ||
| 82 | } else { | ||
| 78 | spin_lock_bh(&dev->cbdev->queue_lock); | 83 | spin_lock_bh(&dev->cbdev->queue_lock); |
| 79 | list_for_each_entry(__cbq, &dev->cbdev->queue_list, | 84 | list_for_each_entry(__cbq, &dev->cbdev->queue_list, |
| 80 | callback_entry) { | 85 | callback_entry) { |
| @@ -88,11 +93,9 @@ int cn_netlink_send(struct cn_msg *msg, u32 __group, gfp_t gfp_mask) | |||
| 88 | 93 | ||
| 89 | if (!found) | 94 | if (!found) |
| 90 | return -ENODEV; | 95 | return -ENODEV; |
| 91 | } else { | ||
| 92 | group = __group; | ||
| 93 | } | 96 | } |
| 94 | 97 | ||
| 95 | if (!netlink_has_listeners(dev->nls, group)) | 98 | if (!portid && !netlink_has_listeners(dev->nls, group)) |
| 96 | return -ESRCH; | 99 | return -ESRCH; |
| 97 | 100 | ||
| 98 | size = sizeof(*msg) + msg->len; | 101 | size = sizeof(*msg) + msg->len; |
| @@ -113,7 +116,10 @@ int cn_netlink_send(struct cn_msg *msg, u32 __group, gfp_t gfp_mask) | |||
| 113 | 116 | ||
| 114 | NETLINK_CB(skb).dst_group = group; | 117 | NETLINK_CB(skb).dst_group = group; |
| 115 | 118 | ||
| 116 | return netlink_broadcast(dev->nls, skb, 0, group, gfp_mask); | 119 | if (group) |
| 120 | return netlink_broadcast(dev->nls, skb, portid, group, | ||
| 121 | gfp_mask); | ||
| 122 | return netlink_unicast(dev->nls, skb, portid, !(gfp_mask&__GFP_WAIT)); | ||
| 117 | } | 123 | } |
| 118 | EXPORT_SYMBOL_GPL(cn_netlink_send); | 124 | EXPORT_SYMBOL_GPL(cn_netlink_send); |
| 119 | 125 | ||
diff --git a/drivers/fmc/fmc-core.c b/drivers/fmc/fmc-core.c index 24d52497524d..5a5e616c6324 100644 --- a/drivers/fmc/fmc-core.c +++ b/drivers/fmc/fmc-core.c | |||
| @@ -154,7 +154,7 @@ int fmc_device_register_n(struct fmc_device **devs, int n) | |||
| 154 | ret = -EINVAL; | 154 | ret = -EINVAL; |
| 155 | break; | 155 | break; |
| 156 | } | 156 | } |
| 157 | if (fmc->flags == FMC_DEVICE_NO_MEZZANINE) { | 157 | if (fmc->flags & FMC_DEVICE_NO_MEZZANINE) { |
| 158 | dev_info(fmc->hwdev, "absent mezzanine in slot %d\n", | 158 | dev_info(fmc->hwdev, "absent mezzanine in slot %d\n", |
| 159 | fmc->slot_id); | 159 | fmc->slot_id); |
| 160 | continue; | 160 | continue; |
| @@ -189,9 +189,6 @@ int fmc_device_register_n(struct fmc_device **devs, int n) | |||
| 189 | for (i = 0; i < n; i++) { | 189 | for (i = 0; i < n; i++) { |
| 190 | fmc = devarray[i]; | 190 | fmc = devarray[i]; |
| 191 | 191 | ||
| 192 | if (fmc->flags == FMC_DEVICE_NO_MEZZANINE) | ||
| 193 | continue; /* dev_info already done above */ | ||
| 194 | |||
| 195 | fmc->nr_slots = n; /* each slot must know how many are there */ | 192 | fmc->nr_slots = n; /* each slot must know how many are there */ |
| 196 | fmc->devarray = devarray; | 193 | fmc->devarray = devarray; |
| 197 | 194 | ||
| @@ -263,8 +260,6 @@ void fmc_device_unregister_n(struct fmc_device **devs, int n) | |||
| 263 | kfree(devs[0]->devarray); | 260 | kfree(devs[0]->devarray); |
| 264 | 261 | ||
| 265 | for (i = 0; i < n; i++) { | 262 | for (i = 0; i < n; i++) { |
| 266 | if (devs[i]->flags == FMC_DEVICE_NO_MEZZANINE) | ||
| 267 | continue; | ||
| 268 | sysfs_remove_bin_file(&devs[i]->dev.kobj, &fmc_eeprom_attr); | 263 | sysfs_remove_bin_file(&devs[i]->dev.kobj, &fmc_eeprom_attr); |
| 269 | device_del(&devs[i]->dev); | 264 | device_del(&devs[i]->dev); |
| 270 | fmc_free_id_info(devs[i]); | 265 | fmc_free_id_info(devs[i]); |
diff --git a/drivers/fmc/fmc-sdb.c b/drivers/fmc/fmc-sdb.c index 79adc39221ea..69f42d70bc74 100644 --- a/drivers/fmc/fmc-sdb.c +++ b/drivers/fmc/fmc-sdb.c | |||
| @@ -153,20 +153,17 @@ EXPORT_SYMBOL(fmc_reprogram); | |||
| 153 | static void __fmc_show_sdb_tree(const struct fmc_device *fmc, | 153 | static void __fmc_show_sdb_tree(const struct fmc_device *fmc, |
| 154 | const struct sdb_array *arr) | 154 | const struct sdb_array *arr) |
| 155 | { | 155 | { |
| 156 | unsigned long base = arr->baseaddr; | ||
| 156 | int i, j, n = arr->len, level = arr->level; | 157 | int i, j, n = arr->len, level = arr->level; |
| 157 | const struct sdb_array *ap; | ||
| 158 | 158 | ||
| 159 | for (i = 0; i < n; i++) { | 159 | for (i = 0; i < n; i++) { |
| 160 | unsigned long base; | ||
| 161 | union sdb_record *r; | 160 | union sdb_record *r; |
| 162 | struct sdb_product *p; | 161 | struct sdb_product *p; |
| 163 | struct sdb_component *c; | 162 | struct sdb_component *c; |
| 164 | r = &arr->record[i]; | 163 | r = &arr->record[i]; |
| 165 | c = &r->dev.sdb_component; | 164 | c = &r->dev.sdb_component; |
| 166 | p = &c->product; | 165 | p = &c->product; |
| 167 | base = 0; | 166 | |
| 168 | for (ap = arr; ap; ap = ap->parent) | ||
| 169 | base += ap->baseaddr; | ||
| 170 | dev_info(&fmc->dev, "SDB: "); | 167 | dev_info(&fmc->dev, "SDB: "); |
| 171 | 168 | ||
| 172 | for (j = 0; j < level; j++) | 169 | for (j = 0; j < level; j++) |
diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 69ea36f07b4d..602ca86a6488 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
| 28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
| 29 | #include <linux/hyperv.h> | 29 | #include <linux/hyperv.h> |
| 30 | #include <linux/uio.h> | ||
| 30 | 31 | ||
| 31 | #include "hyperv_vmbus.h" | 32 | #include "hyperv_vmbus.h" |
| 32 | 33 | ||
| @@ -554,14 +555,14 @@ EXPORT_SYMBOL_GPL(vmbus_close); | |||
| 554 | * | 555 | * |
| 555 | * Mainly used by Hyper-V drivers. | 556 | * Mainly used by Hyper-V drivers. |
| 556 | */ | 557 | */ |
| 557 | int vmbus_sendpacket(struct vmbus_channel *channel, const void *buffer, | 558 | int vmbus_sendpacket(struct vmbus_channel *channel, void *buffer, |
| 558 | u32 bufferlen, u64 requestid, | 559 | u32 bufferlen, u64 requestid, |
| 559 | enum vmbus_packet_type type, u32 flags) | 560 | enum vmbus_packet_type type, u32 flags) |
| 560 | { | 561 | { |
| 561 | struct vmpacket_descriptor desc; | 562 | struct vmpacket_descriptor desc; |
| 562 | u32 packetlen = sizeof(struct vmpacket_descriptor) + bufferlen; | 563 | u32 packetlen = sizeof(struct vmpacket_descriptor) + bufferlen; |
| 563 | u32 packetlen_aligned = ALIGN(packetlen, sizeof(u64)); | 564 | u32 packetlen_aligned = ALIGN(packetlen, sizeof(u64)); |
| 564 | struct scatterlist bufferlist[3]; | 565 | struct kvec bufferlist[3]; |
| 565 | u64 aligned_data = 0; | 566 | u64 aligned_data = 0; |
| 566 | int ret; | 567 | int ret; |
| 567 | bool signal = false; | 568 | bool signal = false; |
| @@ -575,11 +576,12 @@ int vmbus_sendpacket(struct vmbus_channel *channel, const void *buffer, | |||
| 575 | desc.len8 = (u16)(packetlen_aligned >> 3); | 576 | desc.len8 = (u16)(packetlen_aligned >> 3); |
| 576 | desc.trans_id = requestid; | 577 | desc.trans_id = requestid; |
| 577 | 578 | ||
| 578 | sg_init_table(bufferlist, 3); | 579 | bufferlist[0].iov_base = &desc; |
| 579 | sg_set_buf(&bufferlist[0], &desc, sizeof(struct vmpacket_descriptor)); | 580 | bufferlist[0].iov_len = sizeof(struct vmpacket_descriptor); |
| 580 | sg_set_buf(&bufferlist[1], buffer, bufferlen); | 581 | bufferlist[1].iov_base = buffer; |
| 581 | sg_set_buf(&bufferlist[2], &aligned_data, | 582 | bufferlist[1].iov_len = bufferlen; |
| 582 | packetlen_aligned - packetlen); | 583 | bufferlist[2].iov_base = &aligned_data; |
| 584 | bufferlist[2].iov_len = (packetlen_aligned - packetlen); | ||
| 583 | 585 | ||
| 584 | ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal); | 586 | ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal); |
| 585 | 587 | ||
| @@ -605,7 +607,7 @@ int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, | |||
| 605 | u32 descsize; | 607 | u32 descsize; |
| 606 | u32 packetlen; | 608 | u32 packetlen; |
| 607 | u32 packetlen_aligned; | 609 | u32 packetlen_aligned; |
| 608 | struct scatterlist bufferlist[3]; | 610 | struct kvec bufferlist[3]; |
| 609 | u64 aligned_data = 0; | 611 | u64 aligned_data = 0; |
| 610 | bool signal = false; | 612 | bool signal = false; |
| 611 | 613 | ||
| @@ -637,11 +639,12 @@ int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, | |||
| 637 | desc.range[i].pfn = pagebuffers[i].pfn; | 639 | desc.range[i].pfn = pagebuffers[i].pfn; |
| 638 | } | 640 | } |
| 639 | 641 | ||
| 640 | sg_init_table(bufferlist, 3); | 642 | bufferlist[0].iov_base = &desc; |
| 641 | sg_set_buf(&bufferlist[0], &desc, descsize); | 643 | bufferlist[0].iov_len = descsize; |
| 642 | sg_set_buf(&bufferlist[1], buffer, bufferlen); | 644 | bufferlist[1].iov_base = buffer; |
| 643 | sg_set_buf(&bufferlist[2], &aligned_data, | 645 | bufferlist[1].iov_len = bufferlen; |
| 644 | packetlen_aligned - packetlen); | 646 | bufferlist[2].iov_base = &aligned_data; |
| 647 | bufferlist[2].iov_len = (packetlen_aligned - packetlen); | ||
| 645 | 648 | ||
| 646 | ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal); | 649 | ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal); |
| 647 | 650 | ||
| @@ -665,7 +668,7 @@ int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, | |||
| 665 | u32 descsize; | 668 | u32 descsize; |
| 666 | u32 packetlen; | 669 | u32 packetlen; |
| 667 | u32 packetlen_aligned; | 670 | u32 packetlen_aligned; |
| 668 | struct scatterlist bufferlist[3]; | 671 | struct kvec bufferlist[3]; |
| 669 | u64 aligned_data = 0; | 672 | u64 aligned_data = 0; |
| 670 | bool signal = false; | 673 | bool signal = false; |
| 671 | u32 pfncount = NUM_PAGES_SPANNED(multi_pagebuffer->offset, | 674 | u32 pfncount = NUM_PAGES_SPANNED(multi_pagebuffer->offset, |
| @@ -700,11 +703,12 @@ int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, | |||
| 700 | memcpy(desc.range.pfn_array, multi_pagebuffer->pfn_array, | 703 | memcpy(desc.range.pfn_array, multi_pagebuffer->pfn_array, |
| 701 | pfncount * sizeof(u64)); | 704 | pfncount * sizeof(u64)); |
| 702 | 705 | ||
| 703 | sg_init_table(bufferlist, 3); | 706 | bufferlist[0].iov_base = &desc; |
| 704 | sg_set_buf(&bufferlist[0], &desc, descsize); | 707 | bufferlist[0].iov_len = descsize; |
| 705 | sg_set_buf(&bufferlist[1], buffer, bufferlen); | 708 | bufferlist[1].iov_base = buffer; |
| 706 | sg_set_buf(&bufferlist[2], &aligned_data, | 709 | bufferlist[1].iov_len = bufferlen; |
| 707 | packetlen_aligned - packetlen); | 710 | bufferlist[2].iov_base = &aligned_data; |
| 711 | bufferlist[2].iov_len = (packetlen_aligned - packetlen); | ||
| 708 | 712 | ||
| 709 | ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal); | 713 | ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal); |
| 710 | 714 | ||
diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index 7e17a5495e02..7e6d78dc9437 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c | |||
| @@ -1171,7 +1171,8 @@ static int dm_thread_func(void *dm_dev) | |||
| 1171 | int t; | 1171 | int t; |
| 1172 | 1172 | ||
| 1173 | while (!kthread_should_stop()) { | 1173 | while (!kthread_should_stop()) { |
| 1174 | t = wait_for_completion_timeout(&dm_device.config_event, 1*HZ); | 1174 | t = wait_for_completion_interruptible_timeout( |
| 1175 | &dm_device.config_event, 1*HZ); | ||
| 1175 | /* | 1176 | /* |
| 1176 | * The host expects us to post information on the memory | 1177 | * The host expects us to post information on the memory |
| 1177 | * pressure every second. | 1178 | * pressure every second. |
diff --git a/drivers/hv/hv_kvp.c b/drivers/hv/hv_kvp.c index 09988b289622..ea852537307e 100644 --- a/drivers/hv/hv_kvp.c +++ b/drivers/hv/hv_kvp.c | |||
| @@ -113,7 +113,7 @@ kvp_register(int reg_value) | |||
| 113 | kvp_msg->kvp_hdr.operation = reg_value; | 113 | kvp_msg->kvp_hdr.operation = reg_value; |
| 114 | strcpy(version, HV_DRV_VERSION); | 114 | strcpy(version, HV_DRV_VERSION); |
| 115 | msg->len = sizeof(struct hv_kvp_msg); | 115 | msg->len = sizeof(struct hv_kvp_msg); |
| 116 | cn_netlink_send(msg, 0, GFP_ATOMIC); | 116 | cn_netlink_send(msg, 0, 0, GFP_ATOMIC); |
| 117 | kfree(msg); | 117 | kfree(msg); |
| 118 | } | 118 | } |
| 119 | } | 119 | } |
| @@ -435,7 +435,7 @@ kvp_send_key(struct work_struct *dummy) | |||
| 435 | } | 435 | } |
| 436 | 436 | ||
| 437 | msg->len = sizeof(struct hv_kvp_msg); | 437 | msg->len = sizeof(struct hv_kvp_msg); |
| 438 | cn_netlink_send(msg, 0, GFP_ATOMIC); | 438 | cn_netlink_send(msg, 0, 0, GFP_ATOMIC); |
| 439 | kfree(msg); | 439 | kfree(msg); |
| 440 | 440 | ||
| 441 | return; | 441 | return; |
diff --git a/drivers/hv/hv_snapshot.c b/drivers/hv/hv_snapshot.c index 0c3546224376..34f14fddb666 100644 --- a/drivers/hv/hv_snapshot.c +++ b/drivers/hv/hv_snapshot.c | |||
| @@ -98,7 +98,7 @@ static void vss_send_op(struct work_struct *dummy) | |||
| 98 | vss_msg->vss_hdr.operation = op; | 98 | vss_msg->vss_hdr.operation = op; |
| 99 | msg->len = sizeof(struct hv_vss_msg); | 99 | msg->len = sizeof(struct hv_vss_msg); |
| 100 | 100 | ||
| 101 | cn_netlink_send(msg, 0, GFP_ATOMIC); | 101 | cn_netlink_send(msg, 0, 0, GFP_ATOMIC); |
| 102 | kfree(msg); | 102 | kfree(msg); |
| 103 | 103 | ||
| 104 | return; | 104 | return; |
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index e05517616a06..1544609881fe 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h | |||
| @@ -559,8 +559,8 @@ int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info, void *buffer, | |||
| 559 | void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info); | 559 | void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info); |
| 560 | 560 | ||
| 561 | int hv_ringbuffer_write(struct hv_ring_buffer_info *ring_info, | 561 | int hv_ringbuffer_write(struct hv_ring_buffer_info *ring_info, |
| 562 | struct scatterlist *sglist, | 562 | struct kvec *kv_list, |
| 563 | u32 sgcount, bool *signal); | 563 | u32 kv_count, bool *signal); |
| 564 | 564 | ||
| 565 | int hv_ringbuffer_peek(struct hv_ring_buffer_info *ring_info, void *buffer, | 565 | int hv_ringbuffer_peek(struct hv_ring_buffer_info *ring_info, void *buffer, |
| 566 | u32 buflen); | 566 | u32 buflen); |
diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index 26c93cf9f6be..15db66b74141 100644 --- a/drivers/hv/ring_buffer.c +++ b/drivers/hv/ring_buffer.c | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | #include <linux/kernel.h> | 26 | #include <linux/kernel.h> |
| 27 | #include <linux/mm.h> | 27 | #include <linux/mm.h> |
| 28 | #include <linux/hyperv.h> | 28 | #include <linux/hyperv.h> |
| 29 | #include <linux/uio.h> | ||
| 29 | 30 | ||
| 30 | #include "hyperv_vmbus.h" | 31 | #include "hyperv_vmbus.h" |
| 31 | 32 | ||
| @@ -387,23 +388,20 @@ void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info) | |||
| 387 | * | 388 | * |
| 388 | */ | 389 | */ |
| 389 | int hv_ringbuffer_write(struct hv_ring_buffer_info *outring_info, | 390 | int hv_ringbuffer_write(struct hv_ring_buffer_info *outring_info, |
| 390 | struct scatterlist *sglist, u32 sgcount, bool *signal) | 391 | struct kvec *kv_list, u32 kv_count, bool *signal) |
| 391 | { | 392 | { |
| 392 | int i = 0; | 393 | int i = 0; |
| 393 | u32 bytes_avail_towrite; | 394 | u32 bytes_avail_towrite; |
| 394 | u32 bytes_avail_toread; | 395 | u32 bytes_avail_toread; |
| 395 | u32 totalbytes_towrite = 0; | 396 | u32 totalbytes_towrite = 0; |
| 396 | 397 | ||
| 397 | struct scatterlist *sg; | ||
| 398 | u32 next_write_location; | 398 | u32 next_write_location; |
| 399 | u32 old_write; | 399 | u32 old_write; |
| 400 | u64 prev_indices = 0; | 400 | u64 prev_indices = 0; |
| 401 | unsigned long flags; | 401 | unsigned long flags; |
| 402 | 402 | ||
| 403 | for_each_sg(sglist, sg, sgcount, i) | 403 | for (i = 0; i < kv_count; i++) |
| 404 | { | 404 | totalbytes_towrite += kv_list[i].iov_len; |
| 405 | totalbytes_towrite += sg->length; | ||
| 406 | } | ||
| 407 | 405 | ||
| 408 | totalbytes_towrite += sizeof(u64); | 406 | totalbytes_towrite += sizeof(u64); |
| 409 | 407 | ||
| @@ -427,12 +425,11 @@ int hv_ringbuffer_write(struct hv_ring_buffer_info *outring_info, | |||
| 427 | 425 | ||
| 428 | old_write = next_write_location; | 426 | old_write = next_write_location; |
| 429 | 427 | ||
| 430 | for_each_sg(sglist, sg, sgcount, i) | 428 | for (i = 0; i < kv_count; i++) { |
| 431 | { | ||
| 432 | next_write_location = hv_copyto_ringbuffer(outring_info, | 429 | next_write_location = hv_copyto_ringbuffer(outring_info, |
| 433 | next_write_location, | 430 | next_write_location, |
| 434 | sg_virt(sg), | 431 | kv_list[i].iov_base, |
| 435 | sg->length); | 432 | kv_list[i].iov_len); |
| 436 | } | 433 | } |
| 437 | 434 | ||
| 438 | /* Set previous packet start */ | 435 | /* Set previous packet start */ |
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 077bb1bdac34..b37c91b6ba80 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c | |||
| @@ -43,6 +43,10 @@ static struct acpi_device *hv_acpi_dev; | |||
| 43 | static struct tasklet_struct msg_dpc; | 43 | static struct tasklet_struct msg_dpc; |
| 44 | static struct completion probe_event; | 44 | static struct completion probe_event; |
| 45 | static int irq; | 45 | static int irq; |
| 46 | u64 hyperv_mmio_start; | ||
| 47 | EXPORT_SYMBOL_GPL(hyperv_mmio_start); | ||
| 48 | u64 hyperv_mmio_size; | ||
| 49 | EXPORT_SYMBOL_GPL(hyperv_mmio_size); | ||
| 46 | 50 | ||
| 47 | static int vmbus_exists(void) | 51 | static int vmbus_exists(void) |
| 48 | { | 52 | { |
| @@ -886,18 +890,19 @@ void vmbus_device_unregister(struct hv_device *device_obj) | |||
| 886 | 890 | ||
| 887 | 891 | ||
| 888 | /* | 892 | /* |
| 889 | * VMBUS is an acpi enumerated device. Get the the IRQ information | 893 | * VMBUS is an acpi enumerated device. Get the the information we |
| 890 | * from DSDT. | 894 | * need from DSDT. |
| 891 | */ | 895 | */ |
| 892 | 896 | ||
| 893 | static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *irq) | 897 | static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *ctx) |
| 894 | { | 898 | { |
| 899 | switch (res->type) { | ||
| 900 | case ACPI_RESOURCE_TYPE_IRQ: | ||
| 901 | irq = res->data.irq.interrupts[0]; | ||
| 895 | 902 | ||
| 896 | if (res->type == ACPI_RESOURCE_TYPE_IRQ) { | 903 | case ACPI_RESOURCE_TYPE_ADDRESS64: |
| 897 | struct acpi_resource_irq *irqp; | 904 | hyperv_mmio_start = res->data.address64.minimum; |
| 898 | irqp = &res->data.irq; | 905 | hyperv_mmio_size = res->data.address64.address_length; |
| 899 | |||
| 900 | *((unsigned int *)irq) = irqp->interrupts[0]; | ||
| 901 | } | 906 | } |
| 902 | 907 | ||
| 903 | return AE_OK; | 908 | return AE_OK; |
| @@ -906,18 +911,32 @@ static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *irq) | |||
| 906 | static int vmbus_acpi_add(struct acpi_device *device) | 911 | static int vmbus_acpi_add(struct acpi_device *device) |
| 907 | { | 912 | { |
| 908 | acpi_status result; | 913 | acpi_status result; |
| 914 | int ret_val = -ENODEV; | ||
| 909 | 915 | ||
| 910 | hv_acpi_dev = device; | 916 | hv_acpi_dev = device; |
| 911 | 917 | ||
| 912 | result = acpi_walk_resources(device->handle, METHOD_NAME__CRS, | 918 | result = acpi_walk_resources(device->handle, METHOD_NAME__CRS, |
| 913 | vmbus_walk_resources, &irq); | 919 | vmbus_walk_resources, NULL); |
| 914 | 920 | ||
| 915 | if (ACPI_FAILURE(result)) { | 921 | if (ACPI_FAILURE(result)) |
| 916 | complete(&probe_event); | 922 | goto acpi_walk_err; |
| 917 | return -ENODEV; | 923 | /* |
| 924 | * The parent of the vmbus acpi device (Gen2 firmware) is the VMOD that | ||
| 925 | * has the mmio ranges. Get that. | ||
| 926 | */ | ||
| 927 | if (device->parent) { | ||
| 928 | result = acpi_walk_resources(device->parent->handle, | ||
| 929 | METHOD_NAME__CRS, | ||
| 930 | vmbus_walk_resources, NULL); | ||
| 931 | |||
| 932 | if (ACPI_FAILURE(result)) | ||
| 933 | goto acpi_walk_err; | ||
| 918 | } | 934 | } |
| 935 | ret_val = 0; | ||
| 936 | |||
| 937 | acpi_walk_err: | ||
| 919 | complete(&probe_event); | 938 | complete(&probe_event); |
| 920 | return 0; | 939 | return ret_val; |
| 921 | } | 940 | } |
| 922 | 941 | ||
| 923 | static const struct acpi_device_id vmbus_acpi_device_ids[] = { | 942 | static const struct acpi_device_id vmbus_acpi_device_ids[] = { |
diff --git a/drivers/md/dm-log-userspace-transfer.c b/drivers/md/dm-log-userspace-transfer.c index 08d9a207259a..b428c0ae63d5 100644 --- a/drivers/md/dm-log-userspace-transfer.c +++ b/drivers/md/dm-log-userspace-transfer.c | |||
| @@ -66,7 +66,7 @@ static int dm_ulog_sendto_server(struct dm_ulog_request *tfr) | |||
| 66 | msg->seq = tfr->seq; | 66 | msg->seq = tfr->seq; |
| 67 | msg->len = sizeof(struct dm_ulog_request) + tfr->data_size; | 67 | msg->len = sizeof(struct dm_ulog_request) + tfr->data_size; |
| 68 | 68 | ||
| 69 | r = cn_netlink_send(msg, 0, gfp_any()); | 69 | r = cn_netlink_send(msg, 0, 0, gfp_any()); |
| 70 | 70 | ||
| 71 | return r; | 71 | return r; |
| 72 | } | 72 | } |
diff --git a/drivers/misc/ad525x_dpot.c b/drivers/misc/ad525x_dpot.c index d3eee113baeb..a43053daad0e 100644 --- a/drivers/misc/ad525x_dpot.c +++ b/drivers/misc/ad525x_dpot.c | |||
| @@ -72,7 +72,6 @@ | |||
| 72 | #include <linux/module.h> | 72 | #include <linux/module.h> |
| 73 | #include <linux/device.h> | 73 | #include <linux/device.h> |
| 74 | #include <linux/kernel.h> | 74 | #include <linux/kernel.h> |
| 75 | #include <linux/init.h> | ||
| 76 | #include <linux/delay.h> | 75 | #include <linux/delay.h> |
| 77 | #include <linux/slab.h> | 76 | #include <linux/slab.h> |
| 78 | 77 | ||
diff --git a/drivers/misc/apds9802als.c b/drivers/misc/apds9802als.c index 0c6e037153d2..c6cc3dc8ae1f 100644 --- a/drivers/misc/apds9802als.c +++ b/drivers/misc/apds9802als.c | |||
| @@ -22,7 +22,6 @@ | |||
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
| 25 | #include <linux/init.h> | ||
| 26 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
| 27 | #include <linux/i2c.h> | 26 | #include <linux/i2c.h> |
| 28 | #include <linux/err.h> | 27 | #include <linux/err.h> |
diff --git a/drivers/misc/bmp085.c b/drivers/misc/bmp085.c index 820e53d0048f..9b313f7810f5 100644 --- a/drivers/misc/bmp085.c +++ b/drivers/misc/bmp085.c | |||
| @@ -47,7 +47,6 @@ | |||
| 47 | 47 | ||
| 48 | #include <linux/module.h> | 48 | #include <linux/module.h> |
| 49 | #include <linux/device.h> | 49 | #include <linux/device.h> |
| 50 | #include <linux/init.h> | ||
| 51 | #include <linux/slab.h> | 50 | #include <linux/slab.h> |
| 52 | #include <linux/of.h> | 51 | #include <linux/of.h> |
| 53 | #include "bmp085.h" | 52 | #include "bmp085.h" |
diff --git a/drivers/misc/carma/carma-fpga.c b/drivers/misc/carma/carma-fpga.c index 9e2b985293fc..14d90eae605b 100644 --- a/drivers/misc/carma/carma-fpga.c +++ b/drivers/misc/carma/carma-fpga.c | |||
| @@ -101,7 +101,6 @@ | |||
| 101 | #include <linux/kernel.h> | 101 | #include <linux/kernel.h> |
| 102 | #include <linux/module.h> | 102 | #include <linux/module.h> |
| 103 | #include <linux/poll.h> | 103 | #include <linux/poll.h> |
| 104 | #include <linux/init.h> | ||
| 105 | #include <linux/slab.h> | 104 | #include <linux/slab.h> |
| 106 | #include <linux/kref.h> | 105 | #include <linux/kref.h> |
| 107 | #include <linux/io.h> | 106 | #include <linux/io.h> |
diff --git a/drivers/misc/ds1682.c b/drivers/misc/ds1682.c index 154b02e5094f..6a672f9ef522 100644 --- a/drivers/misc/ds1682.c +++ b/drivers/misc/ds1682.c | |||
| @@ -32,7 +32,6 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #include <linux/module.h> | 34 | #include <linux/module.h> |
| 35 | #include <linux/init.h> | ||
| 36 | #include <linux/i2c.h> | 35 | #include <linux/i2c.h> |
| 37 | #include <linux/string.h> | 36 | #include <linux/string.h> |
| 38 | #include <linux/list.h> | 37 | #include <linux/list.h> |
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c index 4f3bca1003a1..634f72929e12 100644 --- a/drivers/misc/eeprom/at25.c +++ b/drivers/misc/eeprom/at25.c | |||
| @@ -10,7 +10,6 @@ | |||
| 10 | */ | 10 | */ |
| 11 | 11 | ||
| 12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
| 13 | #include <linux/init.h> | ||
| 14 | #include <linux/module.h> | 13 | #include <linux/module.h> |
| 15 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
| 16 | #include <linux/delay.h> | 15 | #include <linux/delay.h> |
diff --git a/drivers/misc/eeprom/eeprom.c b/drivers/misc/eeprom/eeprom.c index f0fa4e8ca124..33f8673d23a6 100644 --- a/drivers/misc/eeprom/eeprom.c +++ b/drivers/misc/eeprom/eeprom.c | |||
| @@ -17,7 +17,6 @@ | |||
| 17 | */ | 17 | */ |
| 18 | 18 | ||
| 19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/init.h> | ||
| 21 | #include <linux/module.h> | 20 | #include <linux/module.h> |
| 22 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
| 23 | #include <linux/jiffies.h> | 22 | #include <linux/jiffies.h> |
diff --git a/drivers/misc/eeprom/eeprom_93xx46.c b/drivers/misc/eeprom/eeprom_93xx46.c index 78e55b501c94..9ebeacdb8ec4 100644 --- a/drivers/misc/eeprom/eeprom_93xx46.c +++ b/drivers/misc/eeprom/eeprom_93xx46.c | |||
| @@ -11,7 +11,6 @@ | |||
| 11 | #include <linux/delay.h> | 11 | #include <linux/delay.h> |
| 12 | #include <linux/device.h> | 12 | #include <linux/device.h> |
| 13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
| 14 | #include <linux/init.h> | ||
| 15 | #include <linux/module.h> | 14 | #include <linux/module.h> |
| 16 | #include <linux/mutex.h> | 15 | #include <linux/mutex.h> |
| 17 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
diff --git a/drivers/misc/eeprom/max6875.c b/drivers/misc/eeprom/max6875.c index e36157d5d3ab..580ff9df5529 100644 --- a/drivers/misc/eeprom/max6875.c +++ b/drivers/misc/eeprom/max6875.c | |||
| @@ -27,7 +27,6 @@ | |||
| 27 | */ | 27 | */ |
| 28 | 28 | ||
| 29 | #include <linux/kernel.h> | 29 | #include <linux/kernel.h> |
| 30 | #include <linux/init.h> | ||
| 31 | #include <linux/module.h> | 30 | #include <linux/module.h> |
| 32 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
| 33 | #include <linux/i2c.h> | 32 | #include <linux/i2c.h> |
diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c index 9c34e5704304..3f2b625b2032 100644 --- a/drivers/misc/eeprom/sunxi_sid.c +++ b/drivers/misc/eeprom/sunxi_sid.c | |||
| @@ -21,7 +21,6 @@ | |||
| 21 | #include <linux/err.h> | 21 | #include <linux/err.h> |
| 22 | #include <linux/export.h> | 22 | #include <linux/export.h> |
| 23 | #include <linux/fs.h> | 23 | #include <linux/fs.h> |
| 24 | #include <linux/init.h> | ||
| 25 | #include <linux/io.h> | 24 | #include <linux/io.h> |
| 26 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
| 27 | #include <linux/kobject.h> | 26 | #include <linux/kobject.h> |
| @@ -96,7 +95,7 @@ static int sunxi_sid_remove(struct platform_device *pdev) | |||
| 96 | } | 95 | } |
| 97 | 96 | ||
| 98 | static const struct of_device_id sunxi_sid_of_match[] = { | 97 | static const struct of_device_id sunxi_sid_of_match[] = { |
| 99 | { .compatible = "allwinner,sun4i-sid", .data = (void *)16}, | 98 | { .compatible = "allwinner,sun4i-a10-sid", .data = (void *)16}, |
| 100 | { .compatible = "allwinner,sun7i-a20-sid", .data = (void *)512}, | 99 | { .compatible = "allwinner,sun7i-a20-sid", .data = (void *)512}, |
| 101 | {/* sentinel */}, | 100 | {/* sentinel */}, |
| 102 | }; | 101 | }; |
diff --git a/drivers/misc/genwqe/card_debugfs.c b/drivers/misc/genwqe/card_debugfs.c index 3bfdc07a7248..50d2096ea1c7 100644 --- a/drivers/misc/genwqe/card_debugfs.c +++ b/drivers/misc/genwqe/card_debugfs.c | |||
| @@ -26,7 +26,6 @@ | |||
| 26 | 26 | ||
| 27 | #include <linux/module.h> | 27 | #include <linux/module.h> |
| 28 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
| 29 | #include <linux/init.h> | ||
| 30 | #include <linux/debugfs.h> | 29 | #include <linux/debugfs.h> |
| 31 | #include <linux/seq_file.h> | 30 | #include <linux/seq_file.h> |
| 32 | #include <linux/uaccess.h> | 31 | #include <linux/uaccess.h> |
diff --git a/drivers/misc/hmc6352.c b/drivers/misc/hmc6352.c index 170bd3daf336..90520d76633f 100644 --- a/drivers/misc/hmc6352.c +++ b/drivers/misc/hmc6352.c | |||
| @@ -22,7 +22,6 @@ | |||
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
| 25 | #include <linux/init.h> | ||
| 26 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
| 27 | #include <linux/i2c.h> | 26 | #include <linux/i2c.h> |
| 28 | #include <linux/err.h> | 27 | #include <linux/err.h> |
diff --git a/drivers/misc/isl29003.c b/drivers/misc/isl29003.c index e3183f26216b..12c30b486b27 100644 --- a/drivers/misc/isl29003.c +++ b/drivers/misc/isl29003.c | |||
| @@ -26,7 +26,6 @@ | |||
| 26 | */ | 26 | */ |
| 27 | 27 | ||
| 28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
| 29 | #include <linux/init.h> | ||
| 30 | #include <linux/slab.h> | 29 | #include <linux/slab.h> |
| 31 | #include <linux/i2c.h> | 30 | #include <linux/i2c.h> |
| 32 | #include <linux/mutex.h> | 31 | #include <linux/mutex.h> |
diff --git a/drivers/misc/isl29020.c b/drivers/misc/isl29020.c index b7f84dacf822..4a9c50a43afb 100644 --- a/drivers/misc/isl29020.c +++ b/drivers/misc/isl29020.c | |||
| @@ -23,7 +23,6 @@ | |||
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
| 26 | #include <linux/init.h> | ||
| 27 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
| 28 | #include <linux/i2c.h> | 27 | #include <linux/i2c.h> |
| 29 | #include <linux/err.h> | 28 | #include <linux/err.h> |
diff --git a/drivers/misc/lattice-ecp3-config.c b/drivers/misc/lattice-ecp3-config.c index 61fbe6acabef..0a1565e63c71 100644 --- a/drivers/misc/lattice-ecp3-config.c +++ b/drivers/misc/lattice-ecp3-config.c | |||
| @@ -12,7 +12,6 @@ | |||
| 12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
| 13 | #include <linux/errno.h> | 13 | #include <linux/errno.h> |
| 14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/init.h> | ||
| 16 | #include <linux/spi/spi.h> | 15 | #include <linux/spi/spi.h> |
| 17 | #include <linux/platform_device.h> | 16 | #include <linux/platform_device.h> |
| 18 | #include <linux/delay.h> | 17 | #include <linux/delay.h> |
diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c index 036effe9a795..3ef4627f9cb1 100644 --- a/drivers/misc/lis3lv02d/lis3lv02d.c +++ b/drivers/misc/lis3lv02d/lis3lv02d.c | |||
| @@ -23,7 +23,6 @@ | |||
| 23 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 23 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 24 | 24 | ||
| 25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
| 26 | #include <linux/init.h> | ||
| 27 | #include <linux/dmi.h> | 26 | #include <linux/dmi.h> |
| 28 | #include <linux/module.h> | 27 | #include <linux/module.h> |
| 29 | #include <linux/types.h> | 28 | #include <linux/types.h> |
diff --git a/drivers/misc/lis3lv02d/lis3lv02d_i2c.c b/drivers/misc/lis3lv02d/lis3lv02d_i2c.c index 7c97550240f1..d324f8a97b88 100644 --- a/drivers/misc/lis3lv02d/lis3lv02d_i2c.c +++ b/drivers/misc/lis3lv02d/lis3lv02d_i2c.c | |||
| @@ -26,7 +26,6 @@ | |||
| 26 | 26 | ||
| 27 | #include <linux/module.h> | 27 | #include <linux/module.h> |
| 28 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
| 29 | #include <linux/init.h> | ||
| 30 | #include <linux/err.h> | 29 | #include <linux/err.h> |
| 31 | #include <linux/i2c.h> | 30 | #include <linux/i2c.h> |
| 32 | #include <linux/pm_runtime.h> | 31 | #include <linux/pm_runtime.h> |
diff --git a/drivers/misc/lis3lv02d/lis3lv02d_spi.c b/drivers/misc/lis3lv02d/lis3lv02d_spi.c index 9aa2bd2a71ae..bd06d0cfac45 100644 --- a/drivers/misc/lis3lv02d/lis3lv02d_spi.c +++ b/drivers/misc/lis3lv02d/lis3lv02d_spi.c | |||
| @@ -10,7 +10,6 @@ | |||
| 10 | 10 | ||
| 11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
| 12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
| 13 | #include <linux/init.h> | ||
| 14 | #include <linux/err.h> | 13 | #include <linux/err.h> |
| 15 | #include <linux/input.h> | 14 | #include <linux/input.h> |
| 16 | #include <linux/interrupt.h> | 15 | #include <linux/interrupt.h> |
diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c index 49c7a23f02fc..d66a2f24f6b3 100644 --- a/drivers/misc/lkdtm.c +++ b/drivers/misc/lkdtm.c | |||
| @@ -30,6 +30,7 @@ | |||
| 30 | * | 30 | * |
| 31 | * See Documentation/fault-injection/provoke-crashes.txt for instructions | 31 | * See Documentation/fault-injection/provoke-crashes.txt for instructions |
| 32 | */ | 32 | */ |
| 33 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 33 | 34 | ||
| 34 | #include <linux/kernel.h> | 35 | #include <linux/kernel.h> |
| 35 | #include <linux/fs.h> | 36 | #include <linux/fs.h> |
| @@ -45,6 +46,7 @@ | |||
| 45 | #include <linux/debugfs.h> | 46 | #include <linux/debugfs.h> |
| 46 | #include <linux/vmalloc.h> | 47 | #include <linux/vmalloc.h> |
| 47 | #include <linux/mman.h> | 48 | #include <linux/mman.h> |
| 49 | #include <asm/cacheflush.h> | ||
| 48 | 50 | ||
| 49 | #ifdef CONFIG_IDE | 51 | #ifdef CONFIG_IDE |
| 50 | #include <linux/ide.h> | 52 | #include <linux/ide.h> |
| @@ -101,6 +103,7 @@ enum ctype { | |||
| 101 | CT_EXEC_USERSPACE, | 103 | CT_EXEC_USERSPACE, |
| 102 | CT_ACCESS_USERSPACE, | 104 | CT_ACCESS_USERSPACE, |
| 103 | CT_WRITE_RO, | 105 | CT_WRITE_RO, |
| 106 | CT_WRITE_KERN, | ||
| 104 | }; | 107 | }; |
| 105 | 108 | ||
| 106 | static char* cp_name[] = { | 109 | static char* cp_name[] = { |
| @@ -137,6 +140,7 @@ static char* cp_type[] = { | |||
| 137 | "EXEC_USERSPACE", | 140 | "EXEC_USERSPACE", |
| 138 | "ACCESS_USERSPACE", | 141 | "ACCESS_USERSPACE", |
| 139 | "WRITE_RO", | 142 | "WRITE_RO", |
| 143 | "WRITE_KERN", | ||
| 140 | }; | 144 | }; |
| 141 | 145 | ||
| 142 | static struct jprobe lkdtm; | 146 | static struct jprobe lkdtm; |
| @@ -316,6 +320,13 @@ static void do_nothing(void) | |||
| 316 | return; | 320 | return; |
| 317 | } | 321 | } |
| 318 | 322 | ||
| 323 | /* Must immediately follow do_nothing for size calculuations to work out. */ | ||
| 324 | static void do_overwritten(void) | ||
| 325 | { | ||
| 326 | pr_info("do_overwritten wasn't overwritten!\n"); | ||
| 327 | return; | ||
| 328 | } | ||
| 329 | |||
| 319 | static noinline void corrupt_stack(void) | 330 | static noinline void corrupt_stack(void) |
| 320 | { | 331 | { |
| 321 | /* Use default char array length that triggers stack protection. */ | 332 | /* Use default char array length that triggers stack protection. */ |
| @@ -328,7 +339,12 @@ static void execute_location(void *dst) | |||
| 328 | { | 339 | { |
| 329 | void (*func)(void) = dst; | 340 | void (*func)(void) = dst; |
| 330 | 341 | ||
| 342 | pr_info("attempting ok execution at %p\n", do_nothing); | ||
| 343 | do_nothing(); | ||
| 344 | |||
| 331 | memcpy(dst, do_nothing, EXEC_SIZE); | 345 | memcpy(dst, do_nothing, EXEC_SIZE); |
| 346 | flush_icache_range((unsigned long)dst, (unsigned long)dst + EXEC_SIZE); | ||
| 347 | pr_info("attempting bad execution at %p\n", func); | ||
| 332 | func(); | 348 | func(); |
| 333 | } | 349 | } |
| 334 | 350 | ||
| @@ -337,8 +353,13 @@ static void execute_user_location(void *dst) | |||
| 337 | /* Intentionally crossing kernel/user memory boundary. */ | 353 | /* Intentionally crossing kernel/user memory boundary. */ |
| 338 | void (*func)(void) = dst; | 354 | void (*func)(void) = dst; |
| 339 | 355 | ||
| 356 | pr_info("attempting ok execution at %p\n", do_nothing); | ||
| 357 | do_nothing(); | ||
| 358 | |||
| 340 | if (copy_to_user((void __user *)dst, do_nothing, EXEC_SIZE)) | 359 | if (copy_to_user((void __user *)dst, do_nothing, EXEC_SIZE)) |
| 341 | return; | 360 | return; |
| 361 | flush_icache_range((unsigned long)dst, (unsigned long)dst + EXEC_SIZE); | ||
| 362 | pr_info("attempting bad execution at %p\n", func); | ||
| 342 | func(); | 363 | func(); |
| 343 | } | 364 | } |
| 344 | 365 | ||
| @@ -463,8 +484,12 @@ static void lkdtm_do_action(enum ctype which) | |||
| 463 | } | 484 | } |
| 464 | 485 | ||
| 465 | ptr = (unsigned long *)user_addr; | 486 | ptr = (unsigned long *)user_addr; |
| 487 | |||
| 488 | pr_info("attempting bad read at %p\n", ptr); | ||
| 466 | tmp = *ptr; | 489 | tmp = *ptr; |
| 467 | tmp += 0xc0dec0de; | 490 | tmp += 0xc0dec0de; |
| 491 | |||
| 492 | pr_info("attempting bad write at %p\n", ptr); | ||
| 468 | *ptr = tmp; | 493 | *ptr = tmp; |
| 469 | 494 | ||
| 470 | vm_munmap(user_addr, PAGE_SIZE); | 495 | vm_munmap(user_addr, PAGE_SIZE); |
| @@ -475,10 +500,28 @@ static void lkdtm_do_action(enum ctype which) | |||
| 475 | unsigned long *ptr; | 500 | unsigned long *ptr; |
| 476 | 501 | ||
| 477 | ptr = (unsigned long *)&rodata; | 502 | ptr = (unsigned long *)&rodata; |
| 503 | |||
| 504 | pr_info("attempting bad write at %p\n", ptr); | ||
| 478 | *ptr ^= 0xabcd1234; | 505 | *ptr ^= 0xabcd1234; |
| 479 | 506 | ||
| 480 | break; | 507 | break; |
| 481 | } | 508 | } |
| 509 | case CT_WRITE_KERN: { | ||
| 510 | size_t size; | ||
| 511 | unsigned char *ptr; | ||
| 512 | |||
| 513 | size = (unsigned long)do_overwritten - | ||
| 514 | (unsigned long)do_nothing; | ||
| 515 | ptr = (unsigned char *)do_overwritten; | ||
| 516 | |||
| 517 | pr_info("attempting bad %zu byte write at %p\n", size, ptr); | ||
| 518 | memcpy(ptr, (unsigned char *)do_nothing, size); | ||
| 519 | flush_icache_range((unsigned long)ptr, | ||
| 520 | (unsigned long)(ptr + size)); | ||
| 521 | |||
| 522 | do_overwritten(); | ||
| 523 | break; | ||
| 524 | } | ||
| 482 | case CT_NONE: | 525 | case CT_NONE: |
| 483 | default: | 526 | default: |
| 484 | break; | 527 | break; |
| @@ -493,8 +536,8 @@ static void lkdtm_handler(void) | |||
| 493 | 536 | ||
| 494 | spin_lock_irqsave(&count_lock, flags); | 537 | spin_lock_irqsave(&count_lock, flags); |
| 495 | count--; | 538 | count--; |
| 496 | printk(KERN_INFO "lkdtm: Crash point %s of type %s hit, trigger in %d rounds\n", | 539 | pr_info("Crash point %s of type %s hit, trigger in %d rounds\n", |
| 497 | cp_name_to_str(cpoint), cp_type_to_str(cptype), count); | 540 | cp_name_to_str(cpoint), cp_type_to_str(cptype), count); |
| 498 | 541 | ||
| 499 | if (count == 0) { | 542 | if (count == 0) { |
| 500 | do_it = true; | 543 | do_it = true; |
| @@ -551,18 +594,18 @@ static int lkdtm_register_cpoint(enum cname which) | |||
| 551 | lkdtm.kp.symbol_name = "generic_ide_ioctl"; | 594 | lkdtm.kp.symbol_name = "generic_ide_ioctl"; |
| 552 | lkdtm.entry = (kprobe_opcode_t*) jp_generic_ide_ioctl; | 595 | lkdtm.entry = (kprobe_opcode_t*) jp_generic_ide_ioctl; |
| 553 | #else | 596 | #else |
| 554 | printk(KERN_INFO "lkdtm: Crash point not available\n"); | 597 | pr_info("Crash point not available\n"); |
| 555 | return -EINVAL; | 598 | return -EINVAL; |
| 556 | #endif | 599 | #endif |
| 557 | break; | 600 | break; |
| 558 | default: | 601 | default: |
| 559 | printk(KERN_INFO "lkdtm: Invalid Crash Point\n"); | 602 | pr_info("Invalid Crash Point\n"); |
| 560 | return -EINVAL; | 603 | return -EINVAL; |
| 561 | } | 604 | } |
| 562 | 605 | ||
| 563 | cpoint = which; | 606 | cpoint = which; |
| 564 | if ((ret = register_jprobe(&lkdtm)) < 0) { | 607 | if ((ret = register_jprobe(&lkdtm)) < 0) { |
| 565 | printk(KERN_INFO "lkdtm: Couldn't register jprobe\n"); | 608 | pr_info("Couldn't register jprobe\n"); |
| 566 | cpoint = CN_INVALID; | 609 | cpoint = CN_INVALID; |
| 567 | } | 610 | } |
| 568 | 611 | ||
| @@ -709,8 +752,7 @@ static ssize_t direct_entry(struct file *f, const char __user *user_buf, | |||
| 709 | if (type == CT_NONE) | 752 | if (type == CT_NONE) |
| 710 | return -EINVAL; | 753 | return -EINVAL; |
| 711 | 754 | ||
| 712 | printk(KERN_INFO "lkdtm: Performing direct entry %s\n", | 755 | pr_info("Performing direct entry %s\n", cp_type_to_str(type)); |
| 713 | cp_type_to_str(type)); | ||
| 714 | lkdtm_do_action(type); | 756 | lkdtm_do_action(type); |
| 715 | *off += count; | 757 | *off += count; |
| 716 | 758 | ||
| @@ -772,7 +814,7 @@ static int __init lkdtm_module_init(void) | |||
| 772 | /* Register debugfs interface */ | 814 | /* Register debugfs interface */ |
| 773 | lkdtm_debugfs_root = debugfs_create_dir("provoke-crash", NULL); | 815 | lkdtm_debugfs_root = debugfs_create_dir("provoke-crash", NULL); |
| 774 | if (!lkdtm_debugfs_root) { | 816 | if (!lkdtm_debugfs_root) { |
| 775 | printk(KERN_ERR "lkdtm: creating root dir failed\n"); | 817 | pr_err("creating root dir failed\n"); |
| 776 | return -ENODEV; | 818 | return -ENODEV; |
| 777 | } | 819 | } |
| 778 | 820 | ||
| @@ -787,28 +829,26 @@ static int __init lkdtm_module_init(void) | |||
| 787 | de = debugfs_create_file(cur->name, 0644, lkdtm_debugfs_root, | 829 | de = debugfs_create_file(cur->name, 0644, lkdtm_debugfs_root, |
| 788 | NULL, &cur->fops); | 830 | NULL, &cur->fops); |
| 789 | if (de == NULL) { | 831 | if (de == NULL) { |
| 790 | printk(KERN_ERR "lkdtm: could not create %s\n", | 832 | pr_err("could not create %s\n", cur->name); |
| 791 | cur->name); | ||
| 792 | goto out_err; | 833 | goto out_err; |
| 793 | } | 834 | } |
| 794 | } | 835 | } |
| 795 | 836 | ||
| 796 | if (lkdtm_parse_commandline() == -EINVAL) { | 837 | if (lkdtm_parse_commandline() == -EINVAL) { |
| 797 | printk(KERN_INFO "lkdtm: Invalid command\n"); | 838 | pr_info("Invalid command\n"); |
| 798 | goto out_err; | 839 | goto out_err; |
| 799 | } | 840 | } |
| 800 | 841 | ||
| 801 | if (cpoint != CN_INVALID && cptype != CT_NONE) { | 842 | if (cpoint != CN_INVALID && cptype != CT_NONE) { |
| 802 | ret = lkdtm_register_cpoint(cpoint); | 843 | ret = lkdtm_register_cpoint(cpoint); |
| 803 | if (ret < 0) { | 844 | if (ret < 0) { |
| 804 | printk(KERN_INFO "lkdtm: Invalid crash point %d\n", | 845 | pr_info("Invalid crash point %d\n", cpoint); |
| 805 | cpoint); | ||
| 806 | goto out_err; | 846 | goto out_err; |
| 807 | } | 847 | } |
| 808 | printk(KERN_INFO "lkdtm: Crash point %s of type %s registered\n", | 848 | pr_info("Crash point %s of type %s registered\n", |
| 809 | cpoint_name, cpoint_type); | 849 | cpoint_name, cpoint_type); |
| 810 | } else { | 850 | } else { |
| 811 | printk(KERN_INFO "lkdtm: No crash points registered, enable through debugfs\n"); | 851 | pr_info("No crash points registered, enable through debugfs\n"); |
| 812 | } | 852 | } |
| 813 | 853 | ||
| 814 | return 0; | 854 | return 0; |
| @@ -823,7 +863,7 @@ static void __exit lkdtm_module_exit(void) | |||
| 823 | debugfs_remove_recursive(lkdtm_debugfs_root); | 863 | debugfs_remove_recursive(lkdtm_debugfs_root); |
| 824 | 864 | ||
| 825 | unregister_jprobe(&lkdtm); | 865 | unregister_jprobe(&lkdtm); |
| 826 | printk(KERN_INFO "lkdtm: Crash point unregistered\n"); | 866 | pr_info("Crash point unregistered\n"); |
| 827 | } | 867 | } |
| 828 | 868 | ||
| 829 | module_init(lkdtm_module_init); | 869 | module_init(lkdtm_module_init); |
diff --git a/drivers/misc/mei/Kconfig b/drivers/misc/mei/Kconfig index c76fa31e9bf6..d23384dde73b 100644 --- a/drivers/misc/mei/Kconfig +++ b/drivers/misc/mei/Kconfig | |||
| @@ -34,3 +34,12 @@ config INTEL_MEI_ME | |||
| 34 | 82Q33 Express | 34 | 82Q33 Express |
| 35 | 82X38/X48 Express | 35 | 82X38/X48 Express |
| 36 | 36 | ||
| 37 | config INTEL_MEI_TXE | ||
| 38 | tristate "Intel Trusted Execution Environment with ME Interface" | ||
| 39 | select INTEL_MEI | ||
| 40 | depends on X86 && PCI && WATCHDOG_CORE | ||
| 41 | help | ||
| 42 | MEI Support for Trusted Execution Environment device on Intel SoCs | ||
| 43 | |||
| 44 | Supported SoCs: | ||
| 45 | Intel Bay Trail | ||
diff --git a/drivers/misc/mei/Makefile b/drivers/misc/mei/Makefile index 08698a466268..8ebc6cda1373 100644 --- a/drivers/misc/mei/Makefile +++ b/drivers/misc/mei/Makefile | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # | 1 | # |
| 2 | # Makefile - Intel Management Engine Interface (Intel MEI) Linux driver | 2 | # Makefile - Intel Management Engine Interface (Intel MEI) Linux driver |
| 3 | # Copyright (c) 2010-2011, Intel Corporation. | 3 | # Copyright (c) 2010-2014, Intel Corporation. |
| 4 | # | 4 | # |
| 5 | obj-$(CONFIG_INTEL_MEI) += mei.o | 5 | obj-$(CONFIG_INTEL_MEI) += mei.o |
| 6 | mei-objs := init.o | 6 | mei-objs := init.o |
| @@ -17,3 +17,7 @@ mei-$(CONFIG_DEBUG_FS) += debugfs.o | |||
| 17 | obj-$(CONFIG_INTEL_MEI_ME) += mei-me.o | 17 | obj-$(CONFIG_INTEL_MEI_ME) += mei-me.o |
| 18 | mei-me-objs := pci-me.o | 18 | mei-me-objs := pci-me.o |
| 19 | mei-me-objs += hw-me.o | 19 | mei-me-objs += hw-me.o |
| 20 | |||
| 21 | obj-$(CONFIG_INTEL_MEI_TXE) += mei-txe.o | ||
| 22 | mei-txe-objs := pci-txe.o | ||
| 23 | mei-txe-objs += hw-txe.o | ||
diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c index 2fad84432829..f88cb26364f5 100644 --- a/drivers/misc/mei/amthif.c +++ b/drivers/misc/mei/amthif.c | |||
| @@ -21,7 +21,6 @@ | |||
| 21 | #include <linux/fcntl.h> | 21 | #include <linux/fcntl.h> |
| 22 | #include <linux/aio.h> | 22 | #include <linux/aio.h> |
| 23 | #include <linux/pci.h> | 23 | #include <linux/pci.h> |
| 24 | #include <linux/init.h> | ||
| 25 | #include <linux/ioctl.h> | 24 | #include <linux/ioctl.h> |
| 26 | #include <linux/cdev.h> | 25 | #include <linux/cdev.h> |
| 27 | #include <linux/list.h> | 26 | #include <linux/list.h> |
| @@ -365,7 +364,7 @@ int mei_amthif_write(struct mei_device *dev, struct mei_cl_cb *cb) | |||
| 365 | if (ret) | 364 | if (ret) |
| 366 | return ret; | 365 | return ret; |
| 367 | 366 | ||
| 368 | cb->fop_type = MEI_FOP_IOCTL; | 367 | cb->fop_type = MEI_FOP_WRITE; |
| 369 | 368 | ||
| 370 | if (!list_empty(&dev->amthif_cmd_list.list) || | 369 | if (!list_empty(&dev->amthif_cmd_list.list) || |
| 371 | dev->iamthif_state != MEI_IAMTHIF_IDLE) { | 370 | dev->iamthif_state != MEI_IAMTHIF_IDLE) { |
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c index 9b809cfc2899..9ac72f1ea6b9 100644 --- a/drivers/misc/mei/client.c +++ b/drivers/misc/mei/client.c | |||
| @@ -505,7 +505,7 @@ int mei_cl_connect(struct mei_cl *cl, struct file *file) | |||
| 505 | goto out; | 505 | goto out; |
| 506 | } | 506 | } |
| 507 | 507 | ||
| 508 | cb->fop_type = MEI_FOP_IOCTL; | 508 | cb->fop_type = MEI_FOP_CONNECT; |
| 509 | 509 | ||
| 510 | if (dev->hbuf_is_ready && !mei_cl_is_other_connecting(cl)) { | 510 | if (dev->hbuf_is_ready && !mei_cl_is_other_connecting(cl)) { |
| 511 | dev->hbuf_is_ready = false; | 511 | dev->hbuf_is_ready = false; |
diff --git a/drivers/misc/mei/debugfs.c b/drivers/misc/mei/debugfs.c index a3ae154444b2..ced5b777c70f 100644 --- a/drivers/misc/mei/debugfs.c +++ b/drivers/misc/mei/debugfs.c | |||
| @@ -75,6 +75,54 @@ static const struct file_operations mei_dbgfs_fops_meclients = { | |||
| 75 | .llseek = generic_file_llseek, | 75 | .llseek = generic_file_llseek, |
| 76 | }; | 76 | }; |
| 77 | 77 | ||
| 78 | static ssize_t mei_dbgfs_read_active(struct file *fp, char __user *ubuf, | ||
| 79 | size_t cnt, loff_t *ppos) | ||
| 80 | { | ||
| 81 | struct mei_device *dev = fp->private_data; | ||
| 82 | struct mei_cl *cl; | ||
| 83 | const size_t bufsz = 1024; | ||
| 84 | char *buf; | ||
| 85 | int i = 0; | ||
| 86 | int pos = 0; | ||
| 87 | int ret; | ||
| 88 | |||
| 89 | if (!dev) | ||
| 90 | return -ENODEV; | ||
| 91 | |||
| 92 | buf = kzalloc(bufsz, GFP_KERNEL); | ||
| 93 | if (!buf) | ||
| 94 | return -ENOMEM; | ||
| 95 | |||
| 96 | pos += scnprintf(buf + pos, bufsz - pos, | ||
| 97 | " |me|host|state|rd|wr|\n"); | ||
| 98 | |||
| 99 | mutex_lock(&dev->device_lock); | ||
| 100 | |||
| 101 | /* if the driver is not enabled the list won't b consitent */ | ||
| 102 | if (dev->dev_state != MEI_DEV_ENABLED) | ||
| 103 | goto out; | ||
| 104 | |||
| 105 | list_for_each_entry(cl, &dev->file_list, link) { | ||
| 106 | |||
| 107 | pos += scnprintf(buf + pos, bufsz - pos, | ||
| 108 | "%2d|%2d|%4d|%5d|%2d|%2d|\n", | ||
| 109 | i, cl->me_client_id, cl->host_client_id, cl->state, | ||
| 110 | cl->reading_state, cl->writing_state); | ||
| 111 | i++; | ||
| 112 | } | ||
| 113 | out: | ||
| 114 | mutex_unlock(&dev->device_lock); | ||
| 115 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos); | ||
| 116 | kfree(buf); | ||
| 117 | return ret; | ||
| 118 | } | ||
| 119 | |||
| 120 | static const struct file_operations mei_dbgfs_fops_active = { | ||
| 121 | .open = simple_open, | ||
| 122 | .read = mei_dbgfs_read_active, | ||
| 123 | .llseek = generic_file_llseek, | ||
| 124 | }; | ||
| 125 | |||
| 78 | static ssize_t mei_dbgfs_read_devstate(struct file *fp, char __user *ubuf, | 126 | static ssize_t mei_dbgfs_read_devstate(struct file *fp, char __user *ubuf, |
| 79 | size_t cnt, loff_t *ppos) | 127 | size_t cnt, loff_t *ppos) |
| 80 | { | 128 | { |
| @@ -128,6 +176,12 @@ int mei_dbgfs_register(struct mei_device *dev, const char *name) | |||
| 128 | dev_err(&dev->pdev->dev, "meclients: registration failed\n"); | 176 | dev_err(&dev->pdev->dev, "meclients: registration failed\n"); |
| 129 | goto err; | 177 | goto err; |
| 130 | } | 178 | } |
| 179 | f = debugfs_create_file("active", S_IRUSR, dir, | ||
| 180 | dev, &mei_dbgfs_fops_active); | ||
| 181 | if (!f) { | ||
| 182 | dev_err(&dev->pdev->dev, "meclients: registration failed\n"); | ||
| 183 | goto err; | ||
| 184 | } | ||
| 131 | f = debugfs_create_file("devstate", S_IRUSR, dir, | 185 | f = debugfs_create_file("devstate", S_IRUSR, dir, |
| 132 | dev, &mei_dbgfs_fops_devstate); | 186 | dev, &mei_dbgfs_fops_devstate); |
| 133 | if (!f) { | 187 | if (!f) { |
diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c index 28cd74c073b9..d3fcb23bb081 100644 --- a/drivers/misc/mei/hbm.c +++ b/drivers/misc/mei/hbm.c | |||
| @@ -147,7 +147,7 @@ int mei_hbm_start_wait(struct mei_device *dev) | |||
| 147 | ret = wait_event_interruptible_timeout(dev->wait_recvd_msg, | 147 | ret = wait_event_interruptible_timeout(dev->wait_recvd_msg, |
| 148 | dev->hbm_state == MEI_HBM_IDLE || | 148 | dev->hbm_state == MEI_HBM_IDLE || |
| 149 | dev->hbm_state >= MEI_HBM_STARTED, | 149 | dev->hbm_state >= MEI_HBM_STARTED, |
| 150 | mei_secs_to_jiffies(MEI_INTEROP_TIMEOUT)); | 150 | mei_secs_to_jiffies(MEI_HBM_TIMEOUT)); |
| 151 | mutex_lock(&dev->device_lock); | 151 | mutex_lock(&dev->device_lock); |
| 152 | 152 | ||
| 153 | if (ret <= 0 && (dev->hbm_state <= MEI_HBM_START)) { | 153 | if (ret <= 0 && (dev->hbm_state <= MEI_HBM_START)) { |
| @@ -283,17 +283,18 @@ static int mei_hbm_prop_req(struct mei_device *dev) | |||
| 283 | } | 283 | } |
| 284 | 284 | ||
| 285 | /** | 285 | /** |
| 286 | * mei_hbm_stop_req_prepare - prepare stop request message | 286 | * mei_hbm_stop_req - send stop request message |
| 287 | * | 287 | * |
| 288 | * @dev - mei device | 288 | * @dev - mei device |
| 289 | * @mei_hdr - mei message header | 289 | * @cl: client info |
| 290 | * @data - hbm message body buffer | 290 | * |
| 291 | * This function returns -EIO on write failure | ||
| 291 | */ | 292 | */ |
| 292 | static void mei_hbm_stop_req_prepare(struct mei_device *dev, | 293 | static int mei_hbm_stop_req(struct mei_device *dev) |
| 293 | struct mei_msg_hdr *mei_hdr, unsigned char *data) | ||
| 294 | { | 294 | { |
| 295 | struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; | ||
| 295 | struct hbm_host_stop_request *req = | 296 | struct hbm_host_stop_request *req = |
| 296 | (struct hbm_host_stop_request *)data; | 297 | (struct hbm_host_stop_request *)dev->wr_msg.data; |
| 297 | const size_t len = sizeof(struct hbm_host_stop_request); | 298 | const size_t len = sizeof(struct hbm_host_stop_request); |
| 298 | 299 | ||
| 299 | mei_hbm_hdr(mei_hdr, len); | 300 | mei_hbm_hdr(mei_hdr, len); |
| @@ -301,6 +302,8 @@ static void mei_hbm_stop_req_prepare(struct mei_device *dev, | |||
| 301 | memset(req, 0, len); | 302 | memset(req, 0, len); |
| 302 | req->hbm_cmd = HOST_STOP_REQ_CMD; | 303 | req->hbm_cmd = HOST_STOP_REQ_CMD; |
| 303 | req->reason = DRIVER_STOP_REQUEST; | 304 | req->reason = DRIVER_STOP_REQUEST; |
| 305 | |||
| 306 | return mei_write_message(dev, mei_hdr, dev->wr_msg.data); | ||
| 304 | } | 307 | } |
| 305 | 308 | ||
| 306 | /** | 309 | /** |
| @@ -405,6 +408,25 @@ int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl) | |||
| 405 | } | 408 | } |
| 406 | 409 | ||
| 407 | /** | 410 | /** |
| 411 | * mei_hbm_cl_disconnect_rsp - sends disconnect respose to the FW | ||
| 412 | * | ||
| 413 | * @dev: the device structure | ||
| 414 | * @cl: a client to disconnect from | ||
| 415 | * | ||
| 416 | * This function returns -EIO on write failure | ||
| 417 | */ | ||
| 418 | int mei_hbm_cl_disconnect_rsp(struct mei_device *dev, struct mei_cl *cl) | ||
| 419 | { | ||
| 420 | struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; | ||
| 421 | const size_t len = sizeof(struct hbm_client_connect_response); | ||
| 422 | |||
| 423 | mei_hbm_hdr(mei_hdr, len); | ||
| 424 | mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_RES_CMD, dev->wr_msg.data, len); | ||
| 425 | |||
| 426 | return mei_write_message(dev, mei_hdr, dev->wr_msg.data); | ||
| 427 | } | ||
| 428 | |||
| 429 | /** | ||
| 408 | * mei_hbm_cl_disconnect_res - disconnect response from ME | 430 | * mei_hbm_cl_disconnect_res - disconnect response from ME |
| 409 | * | 431 | * |
| 410 | * @dev: the device structure | 432 | * @dev: the device structure |
| @@ -507,7 +529,7 @@ static void mei_hbm_cl_connect_res(struct mei_device *dev, | |||
| 507 | list_del(&pos->list); | 529 | list_del(&pos->list); |
| 508 | return; | 530 | return; |
| 509 | } | 531 | } |
| 510 | if (pos->fop_type == MEI_FOP_IOCTL) { | 532 | if (pos->fop_type == MEI_FOP_CONNECT) { |
| 511 | if (is_treat_specially_client(cl, rs)) { | 533 | if (is_treat_specially_client(cl, rs)) { |
| 512 | list_del(&pos->list); | 534 | list_del(&pos->list); |
| 513 | cl->status = 0; | 535 | cl->status = 0; |
| @@ -525,12 +547,14 @@ static void mei_hbm_cl_connect_res(struct mei_device *dev, | |||
| 525 | * | 547 | * |
| 526 | * @dev: the device structure. | 548 | * @dev: the device structure. |
| 527 | * @disconnect_req: disconnect request bus message from the me | 549 | * @disconnect_req: disconnect request bus message from the me |
| 550 | * | ||
| 551 | * returns -ENOMEM on allocation failure | ||
| 528 | */ | 552 | */ |
| 529 | static void mei_hbm_fw_disconnect_req(struct mei_device *dev, | 553 | static int mei_hbm_fw_disconnect_req(struct mei_device *dev, |
| 530 | struct hbm_client_connect_request *disconnect_req) | 554 | struct hbm_client_connect_request *disconnect_req) |
| 531 | { | 555 | { |
| 532 | struct mei_cl *cl, *next; | 556 | struct mei_cl *cl, *next; |
| 533 | const size_t len = sizeof(struct hbm_client_connect_response); | 557 | struct mei_cl_cb *cb; |
| 534 | 558 | ||
| 535 | list_for_each_entry_safe(cl, next, &dev->file_list, link) { | 559 | list_for_each_entry_safe(cl, next, &dev->file_list, link) { |
| 536 | if (mei_hbm_cl_addr_equal(cl, disconnect_req)) { | 560 | if (mei_hbm_cl_addr_equal(cl, disconnect_req)) { |
| @@ -544,13 +568,17 @@ static void mei_hbm_fw_disconnect_req(struct mei_device *dev, | |||
| 544 | else if (cl == &dev->iamthif_cl) | 568 | else if (cl == &dev->iamthif_cl) |
| 545 | dev->iamthif_timer = 0; | 569 | dev->iamthif_timer = 0; |
| 546 | 570 | ||
| 547 | /* prepare disconnect response */ | 571 | cb = mei_io_cb_init(cl, NULL); |
| 548 | mei_hbm_hdr(&dev->wr_ext_msg.hdr, len); | 572 | if (!cb) |
| 549 | mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_RES_CMD, | 573 | return -ENOMEM; |
| 550 | dev->wr_ext_msg.data, len); | 574 | cb->fop_type = MEI_FOP_DISCONNECT_RSP; |
| 575 | cl_dbg(dev, cl, "add disconnect response as first\n"); | ||
| 576 | list_add(&cb->list, &dev->ctrl_wr_list.list); | ||
| 577 | |||
| 551 | break; | 578 | break; |
| 552 | } | 579 | } |
| 553 | } | 580 | } |
| 581 | return 0; | ||
| 554 | } | 582 | } |
| 555 | 583 | ||
| 556 | 584 | ||
| @@ -629,10 +657,7 @@ int mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr) | |||
| 629 | dev_warn(&dev->pdev->dev, "hbm: start: version mismatch - stopping the driver.\n"); | 657 | dev_warn(&dev->pdev->dev, "hbm: start: version mismatch - stopping the driver.\n"); |
| 630 | 658 | ||
| 631 | dev->hbm_state = MEI_HBM_STOPPED; | 659 | dev->hbm_state = MEI_HBM_STOPPED; |
| 632 | mei_hbm_stop_req_prepare(dev, &dev->wr_msg.hdr, | 660 | if (mei_hbm_stop_req(dev)) { |
| 633 | dev->wr_msg.data); | ||
| 634 | if (mei_write_message(dev, &dev->wr_msg.hdr, | ||
| 635 | dev->wr_msg.data)) { | ||
| 636 | dev_err(&dev->pdev->dev, "hbm: start: failed to send stop request\n"); | 661 | dev_err(&dev->pdev->dev, "hbm: start: failed to send stop request\n"); |
| 637 | return -EIO; | 662 | return -EIO; |
| 638 | } | 663 | } |
| @@ -778,10 +803,11 @@ int mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr) | |||
| 778 | 803 | ||
| 779 | case ME_STOP_REQ_CMD: | 804 | case ME_STOP_REQ_CMD: |
| 780 | dev_dbg(&dev->pdev->dev, "hbm: stop request: message received\n"); | 805 | dev_dbg(&dev->pdev->dev, "hbm: stop request: message received\n"); |
| 781 | |||
| 782 | dev->hbm_state = MEI_HBM_STOPPED; | 806 | dev->hbm_state = MEI_HBM_STOPPED; |
| 783 | mei_hbm_stop_req_prepare(dev, &dev->wr_ext_msg.hdr, | 807 | if (mei_hbm_stop_req(dev)) { |
| 784 | dev->wr_ext_msg.data); | 808 | dev_err(&dev->pdev->dev, "hbm: start: failed to send stop request\n"); |
| 809 | return -EIO; | ||
| 810 | } | ||
| 785 | break; | 811 | break; |
| 786 | default: | 812 | default: |
| 787 | BUG(); | 813 | BUG(); |
diff --git a/drivers/misc/mei/hbm.h b/drivers/misc/mei/hbm.h index 5f92188a5cd7..20e8782711c0 100644 --- a/drivers/misc/mei/hbm.h +++ b/drivers/misc/mei/hbm.h | |||
| @@ -54,6 +54,7 @@ int mei_hbm_start_req(struct mei_device *dev); | |||
| 54 | int mei_hbm_start_wait(struct mei_device *dev); | 54 | int mei_hbm_start_wait(struct mei_device *dev); |
| 55 | int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl); | 55 | int mei_hbm_cl_flow_control_req(struct mei_device *dev, struct mei_cl *cl); |
| 56 | int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl); | 56 | int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl); |
| 57 | int mei_hbm_cl_disconnect_rsp(struct mei_device *dev, struct mei_cl *cl); | ||
| 57 | int mei_hbm_cl_connect_req(struct mei_device *dev, struct mei_cl *cl); | 58 | int mei_hbm_cl_connect_req(struct mei_device *dev, struct mei_cl *cl); |
| 58 | bool mei_hbm_version_is_supported(struct mei_device *dev); | 59 | bool mei_hbm_version_is_supported(struct mei_device *dev); |
| 59 | 60 | ||
diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c index 6f656c053b14..847c9e5746cb 100644 --- a/drivers/misc/mei/hw-me.c +++ b/drivers/misc/mei/hw-me.c | |||
| @@ -240,7 +240,7 @@ static int mei_me_hw_ready_wait(struct mei_device *dev) | |||
| 240 | mutex_unlock(&dev->device_lock); | 240 | mutex_unlock(&dev->device_lock); |
| 241 | err = wait_event_interruptible_timeout(dev->wait_hw_ready, | 241 | err = wait_event_interruptible_timeout(dev->wait_hw_ready, |
| 242 | dev->recvd_hw_ready, | 242 | dev->recvd_hw_ready, |
| 243 | mei_secs_to_jiffies(MEI_INTEROP_TIMEOUT)); | 243 | mei_secs_to_jiffies(MEI_HW_READY_TIMEOUT)); |
| 244 | mutex_lock(&dev->device_lock); | 244 | mutex_lock(&dev->device_lock); |
| 245 | if (!err && !dev->recvd_hw_ready) { | 245 | if (!err && !dev->recvd_hw_ready) { |
| 246 | if (!err) | 246 | if (!err) |
| @@ -505,9 +505,6 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id) | |||
| 505 | /* check slots available for reading */ | 505 | /* check slots available for reading */ |
| 506 | slots = mei_count_full_read_slots(dev); | 506 | slots = mei_count_full_read_slots(dev); |
| 507 | while (slots > 0) { | 507 | while (slots > 0) { |
| 508 | /* we have urgent data to send so break the read */ | ||
| 509 | if (dev->wr_ext_msg.hdr.length) | ||
| 510 | break; | ||
| 511 | dev_dbg(&dev->pdev->dev, "slots to read = %08x\n", slots); | 508 | dev_dbg(&dev->pdev->dev, "slots to read = %08x\n", slots); |
| 512 | rets = mei_irq_read_handler(dev, &complete_list, &slots); | 509 | rets = mei_irq_read_handler(dev, &complete_list, &slots); |
| 513 | if (rets && dev->dev_state != MEI_DEV_RESETTING) { | 510 | if (rets && dev->dev_state != MEI_DEV_RESETTING) { |
diff --git a/drivers/misc/mei/hw-txe-regs.h b/drivers/misc/mei/hw-txe-regs.h new file mode 100644 index 000000000000..7283c24c1af1 --- /dev/null +++ b/drivers/misc/mei/hw-txe-regs.h | |||
| @@ -0,0 +1,294 @@ | |||
| 1 | /****************************************************************************** | ||
| 2 | * Intel Management Engine Interface (Intel MEI) Linux driver | ||
| 3 | * Intel MEI Interface Header | ||
| 4 | * | ||
| 5 | * This file is provided under a dual BSD/GPLv2 license. When using or | ||
| 6 | * redistributing this file, you may do so under either license. | ||
| 7 | * | ||
| 8 | * GPL LICENSE SUMMARY | ||
| 9 | * | ||
| 10 | * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved. | ||
| 11 | * | ||
| 12 | * This program is free software; you can redistribute it and/or modify | ||
| 13 | * it under the terms of version 2 of the GNU General Public License as | ||
| 14 | * published by the Free Software Foundation. | ||
| 15 | * | ||
| 16 | * This program is distributed in the hope that it will be useful, but | ||
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 19 | * General Public License for more details. | ||
| 20 | * | ||
| 21 | * The full GNU General Public License is included in this distribution | ||
| 22 | * in the file called COPYING | ||
| 23 | * | ||
| 24 | * Contact Information: | ||
| 25 | * Intel Corporation. | ||
| 26 | * linux-mei@linux.intel.com | ||
| 27 | * http://www.intel.com | ||
| 28 | * | ||
| 29 | * BSD LICENSE | ||
| 30 | * | ||
| 31 | * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved. | ||
| 32 | * All rights reserved. | ||
| 33 | * | ||
| 34 | * Redistribution and use in source and binary forms, with or without | ||
| 35 | * modification, are permitted provided that the following conditions | ||
| 36 | * are met: | ||
| 37 | * | ||
| 38 | * * Redistributions of source code must retain the above copyright | ||
| 39 | * notice, this list of conditions and the following disclaimer. | ||
| 40 | * * Redistributions in binary form must reproduce the above copyright | ||
| 41 | * notice, this list of conditions and the following disclaimer in | ||
| 42 | * the documentation and/or other materials provided with the | ||
| 43 | * distribution. | ||
| 44 | * * Neither the name Intel Corporation nor the names of its | ||
| 45 | * contributors may be used to endorse or promote products derived | ||
| 46 | * from this software without specific prior written permission. | ||
| 47 | * | ||
| 48 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 49 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 50 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 51 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 52 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 53 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 54 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 55 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 56 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 57 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 58 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 59 | * | ||
| 60 | *****************************************************************************/ | ||
| 61 | #ifndef _MEI_HW_TXE_REGS_H_ | ||
| 62 | #define _MEI_HW_TXE_REGS_H_ | ||
| 63 | |||
| 64 | #include "hw.h" | ||
| 65 | |||
| 66 | #define SEC_ALIVENESS_TIMER_TIMEOUT (5 * MSEC_PER_SEC) | ||
| 67 | #define SEC_ALIVENESS_WAIT_TIMEOUT (1 * MSEC_PER_SEC) | ||
| 68 | #define SEC_RESET_WAIT_TIMEOUT (1 * MSEC_PER_SEC) | ||
| 69 | #define SEC_READY_WAIT_TIMEOUT (5 * MSEC_PER_SEC) | ||
| 70 | #define START_MESSAGE_RESPONSE_WAIT_TIMEOUT (5 * MSEC_PER_SEC) | ||
| 71 | #define RESET_CANCEL_WAIT_TIMEOUT (1 * MSEC_PER_SEC) | ||
| 72 | |||
| 73 | enum { | ||
| 74 | SEC_BAR, | ||
| 75 | BRIDGE_BAR, | ||
| 76 | |||
| 77 | NUM_OF_MEM_BARS | ||
| 78 | }; | ||
| 79 | |||
| 80 | /* SeC FW Status Register | ||
| 81 | * | ||
| 82 | * FW uses this register in order to report its status to host. | ||
| 83 | * This register resides in PCI-E config space. | ||
| 84 | */ | ||
| 85 | #define PCI_CFG_TXE_FW_STS0 0x40 | ||
| 86 | # define PCI_CFG_TXE_FW_STS0_WRK_ST_MSK 0x0000000F | ||
| 87 | # define PCI_CFG_TXE_FW_STS0_OP_ST_MSK 0x000001C0 | ||
| 88 | # define PCI_CFG_TXE_FW_STS0_FW_INIT_CMPLT 0x00000200 | ||
| 89 | # define PCI_CFG_TXE_FW_STS0_ERR_CODE_MSK 0x0000F000 | ||
| 90 | # define PCI_CFG_TXE_FW_STS0_OP_MODE_MSK 0x000F0000 | ||
| 91 | # define PCI_CFG_TXE_FW_STS0_RST_CNT_MSK 0x00F00000 | ||
| 92 | |||
| 93 | |||
| 94 | #define IPC_BASE_ADDR 0x80400 /* SeC IPC Base Address */ | ||
| 95 | |||
| 96 | /* IPC Input Doorbell Register */ | ||
| 97 | #define SEC_IPC_INPUT_DOORBELL_REG (0x0000 + IPC_BASE_ADDR) | ||
| 98 | |||
| 99 | /* IPC Input Status Register | ||
| 100 | * This register indicates whether or not processing of | ||
| 101 | * the most recent command has been completed by the SEC | ||
| 102 | * New commands and payloads should not be written by the Host | ||
| 103 | * until this indicates that the previous command has been processed. | ||
| 104 | */ | ||
| 105 | #define SEC_IPC_INPUT_STATUS_REG (0x0008 + IPC_BASE_ADDR) | ||
| 106 | # define SEC_IPC_INPUT_STATUS_RDY BIT(0) | ||
| 107 | |||
| 108 | /* IPC Host Interrupt Status Register */ | ||
| 109 | #define SEC_IPC_HOST_INT_STATUS_REG (0x0010 + IPC_BASE_ADDR) | ||
| 110 | #define SEC_IPC_HOST_INT_STATUS_OUT_DB BIT(0) | ||
| 111 | #define SEC_IPC_HOST_INT_STATUS_IN_RDY BIT(1) | ||
| 112 | #define SEC_IPC_HOST_INT_STATUS_HDCP_M0_RCVD BIT(5) | ||
| 113 | #define SEC_IPC_HOST_INT_STATUS_ILL_MEM_ACCESS BIT(17) | ||
| 114 | #define SEC_IPC_HOST_INT_STATUS_AES_HKEY_ERR BIT(18) | ||
| 115 | #define SEC_IPC_HOST_INT_STATUS_DES_HKEY_ERR BIT(19) | ||
| 116 | #define SEC_IPC_HOST_INT_STATUS_TMRMTB_OVERFLOW BIT(21) | ||
| 117 | |||
| 118 | /* Convenient mask for pending interrupts */ | ||
| 119 | #define SEC_IPC_HOST_INT_STATUS_PENDING \ | ||
| 120 | (SEC_IPC_HOST_INT_STATUS_OUT_DB| \ | ||
| 121 | SEC_IPC_HOST_INT_STATUS_IN_RDY) | ||
| 122 | |||
| 123 | /* IPC Host Interrupt Mask Register */ | ||
| 124 | #define SEC_IPC_HOST_INT_MASK_REG (0x0014 + IPC_BASE_ADDR) | ||
| 125 | |||
| 126 | # define SEC_IPC_HOST_INT_MASK_OUT_DB BIT(0) /* Output Doorbell Int Mask */ | ||
| 127 | # define SEC_IPC_HOST_INT_MASK_IN_RDY BIT(1) /* Input Ready Int Mask */ | ||
| 128 | |||
| 129 | /* IPC Input Payload RAM */ | ||
| 130 | #define SEC_IPC_INPUT_PAYLOAD_REG (0x0100 + IPC_BASE_ADDR) | ||
| 131 | /* IPC Shared Payload RAM */ | ||
| 132 | #define IPC_SHARED_PAYLOAD_REG (0x0200 + IPC_BASE_ADDR) | ||
| 133 | |||
| 134 | /* SeC Address Translation Table Entry 2 - Ctrl | ||
| 135 | * | ||
| 136 | * This register resides also in SeC's PCI-E Memory space. | ||
| 137 | */ | ||
| 138 | #define SATT2_CTRL_REG 0x1040 | ||
| 139 | # define SATT2_CTRL_VALID_MSK BIT(0) | ||
| 140 | # define SATT2_CTRL_BR_BASE_ADDR_REG_SHIFT 8 | ||
| 141 | # define SATT2_CTRL_BRIDGE_HOST_EN_MSK BIT(12) | ||
| 142 | |||
| 143 | /* SATT Table Entry 2 SAP Base Address Register */ | ||
| 144 | #define SATT2_SAP_BA_REG 0x1044 | ||
| 145 | /* SATT Table Entry 2 SAP Size Register. */ | ||
| 146 | #define SATT2_SAP_SIZE_REG 0x1048 | ||
| 147 | /* SATT Table Entry 2 SAP Bridge Address - LSB Register */ | ||
| 148 | #define SATT2_BRG_BA_LSB_REG 0x104C | ||
| 149 | |||
| 150 | /* Host High-level Interrupt Status Register */ | ||
| 151 | #define HHISR_REG 0x2020 | ||
| 152 | /* Host High-level Interrupt Enable Register | ||
| 153 | * | ||
| 154 | * Resides in PCI memory space. This is the top hierarchy for | ||
| 155 | * interrupts from SeC to host, aggregating both interrupts that | ||
| 156 | * arrive through HICR registers as well as interrupts | ||
| 157 | * that arrive via IPC. | ||
| 158 | */ | ||
| 159 | #define HHIER_REG 0x2024 | ||
| 160 | #define IPC_HHIER_SEC BIT(0) | ||
| 161 | #define IPC_HHIER_BRIDGE BIT(1) | ||
| 162 | #define IPC_HHIER_MSK (IPC_HHIER_SEC | IPC_HHIER_BRIDGE) | ||
| 163 | |||
| 164 | /* Host High-level Interrupt Mask Register. | ||
| 165 | * | ||
| 166 | * Resides in PCI memory space. | ||
| 167 | * This is the top hierarchy for masking interrupts from SeC to host. | ||
| 168 | */ | ||
| 169 | #define HHIMR_REG 0x2028 | ||
| 170 | #define IPC_HHIMR_SEC BIT(0) | ||
| 171 | #define IPC_HHIMR_BRIDGE BIT(1) | ||
| 172 | |||
| 173 | /* Host High-level IRQ Status Register */ | ||
| 174 | #define HHIRQSR_REG 0x202C | ||
| 175 | |||
| 176 | /* Host Interrupt Cause Register 0 - SeC IPC Readiness | ||
| 177 | * | ||
| 178 | * This register is both an ICR to Host from PCI Memory Space | ||
| 179 | * and it is also exposed in the SeC memory space. | ||
| 180 | * This register is used by SeC's IPC driver in order | ||
| 181 | * to synchronize with host about IPC interface state. | ||
| 182 | */ | ||
| 183 | #define HICR_SEC_IPC_READINESS_REG 0x2040 | ||
| 184 | #define HICR_SEC_IPC_READINESS_HOST_RDY BIT(0) | ||
| 185 | #define HICR_SEC_IPC_READINESS_SEC_RDY BIT(1) | ||
| 186 | #define HICR_SEC_IPC_READINESS_SYS_RDY \ | ||
| 187 | (HICR_SEC_IPC_READINESS_HOST_RDY | \ | ||
| 188 | HICR_SEC_IPC_READINESS_SEC_RDY) | ||
| 189 | #define HICR_SEC_IPC_READINESS_RDY_CLR BIT(2) | ||
| 190 | |||
| 191 | /* Host Interrupt Cause Register 1 - Aliveness Response */ | ||
| 192 | /* This register is both an ICR to Host from PCI Memory Space | ||
| 193 | * and it is also exposed in the SeC memory space. | ||
| 194 | * The register may be used by SeC to ACK a host request for aliveness. | ||
| 195 | */ | ||
| 196 | #define HICR_HOST_ALIVENESS_RESP_REG 0x2044 | ||
| 197 | #define HICR_HOST_ALIVENESS_RESP_ACK BIT(0) | ||
| 198 | |||
| 199 | /* Host Interrupt Cause Register 2 - SeC IPC Output Doorbell */ | ||
| 200 | #define HICR_SEC_IPC_OUTPUT_DOORBELL_REG 0x2048 | ||
| 201 | |||
| 202 | /* Host Interrupt Status Register. | ||
| 203 | * | ||
| 204 | * Resides in PCI memory space. | ||
| 205 | * This is the main register involved in generating interrupts | ||
| 206 | * from SeC to host via HICRs. | ||
| 207 | * The interrupt generation rules are as follows: | ||
| 208 | * An interrupt will be generated whenever for any i, | ||
| 209 | * there is a transition from a state where at least one of | ||
| 210 | * the following conditions did not hold, to a state where | ||
| 211 | * ALL the following conditions hold: | ||
| 212 | * A) HISR.INT[i]_STS == 1. | ||
| 213 | * B) HIER.INT[i]_EN == 1. | ||
| 214 | */ | ||
| 215 | #define HISR_REG 0x2060 | ||
| 216 | #define HISR_INT_0_STS BIT(0) | ||
| 217 | #define HISR_INT_1_STS BIT(1) | ||
| 218 | #define HISR_INT_2_STS BIT(2) | ||
| 219 | #define HISR_INT_3_STS BIT(3) | ||
| 220 | #define HISR_INT_4_STS BIT(4) | ||
| 221 | #define HISR_INT_5_STS BIT(5) | ||
| 222 | #define HISR_INT_6_STS BIT(6) | ||
| 223 | #define HISR_INT_7_STS BIT(7) | ||
| 224 | #define HISR_INT_STS_MSK \ | ||
| 225 | (HISR_INT_0_STS | HISR_INT_1_STS | HISR_INT_2_STS) | ||
| 226 | |||
| 227 | /* Host Interrupt Enable Register. Resides in PCI memory space. */ | ||
| 228 | #define HIER_REG 0x2064 | ||
| 229 | #define HIER_INT_0_EN BIT(0) | ||
| 230 | #define HIER_INT_1_EN BIT(1) | ||
| 231 | #define HIER_INT_2_EN BIT(2) | ||
| 232 | #define HIER_INT_3_EN BIT(3) | ||
| 233 | #define HIER_INT_4_EN BIT(4) | ||
| 234 | #define HIER_INT_5_EN BIT(5) | ||
| 235 | #define HIER_INT_6_EN BIT(6) | ||
| 236 | #define HIER_INT_7_EN BIT(7) | ||
| 237 | |||
| 238 | #define HIER_INT_EN_MSK \ | ||
| 239 | (HIER_INT_0_EN | HIER_INT_1_EN | HIER_INT_2_EN) | ||
| 240 | |||
| 241 | |||
| 242 | /* SEC Memory Space IPC output payload. | ||
| 243 | * | ||
| 244 | * This register is part of the output payload which SEC provides to host. | ||
| 245 | */ | ||
| 246 | #define BRIDGE_IPC_OUTPUT_PAYLOAD_REG 0x20C0 | ||
| 247 | |||
| 248 | /* SeC Interrupt Cause Register - Host Aliveness Request | ||
| 249 | * This register is both an ICR to SeC and it is also exposed | ||
| 250 | * in the host-visible PCI memory space. | ||
| 251 | * The register is used by host to request SeC aliveness. | ||
| 252 | */ | ||
| 253 | #define SICR_HOST_ALIVENESS_REQ_REG 0x214C | ||
| 254 | #define SICR_HOST_ALIVENESS_REQ_REQUESTED BIT(0) | ||
| 255 | |||
| 256 | |||
| 257 | /* SeC Interrupt Cause Register - Host IPC Readiness | ||
| 258 | * | ||
| 259 | * This register is both an ICR to SeC and it is also exposed | ||
| 260 | * in the host-visible PCI memory space. | ||
| 261 | * This register is used by the host's SeC driver uses in order | ||
| 262 | * to synchronize with SeC about IPC interface state. | ||
| 263 | */ | ||
| 264 | #define SICR_HOST_IPC_READINESS_REQ_REG 0x2150 | ||
| 265 | |||
| 266 | |||
| 267 | #define SICR_HOST_IPC_READINESS_HOST_RDY BIT(0) | ||
| 268 | #define SICR_HOST_IPC_READINESS_SEC_RDY BIT(1) | ||
| 269 | #define SICR_HOST_IPC_READINESS_SYS_RDY \ | ||
| 270 | (SICR_HOST_IPC_READINESS_HOST_RDY | \ | ||
| 271 | SICR_HOST_IPC_READINESS_SEC_RDY) | ||
| 272 | #define SICR_HOST_IPC_READINESS_RDY_CLR BIT(2) | ||
| 273 | |||
| 274 | /* SeC Interrupt Cause Register - SeC IPC Output Status | ||
| 275 | * | ||
| 276 | * This register indicates whether or not processing of the most recent | ||
| 277 | * command has been completed by the Host. | ||
| 278 | * New commands and payloads should not be written by SeC until this | ||
| 279 | * register indicates that the previous command has been processed. | ||
| 280 | */ | ||
| 281 | #define SICR_SEC_IPC_OUTPUT_STATUS_REG 0x2154 | ||
| 282 | # define SEC_IPC_OUTPUT_STATUS_RDY BIT(0) | ||
| 283 | |||
| 284 | |||
| 285 | |||
| 286 | /* MEI IPC Message payload size 64 bytes */ | ||
| 287 | #define PAYLOAD_SIZE 64 | ||
| 288 | |||
| 289 | /* MAX size for SATT range 32MB */ | ||
| 290 | #define SATT_RANGE_MAX (32 << 20) | ||
| 291 | |||
| 292 | |||
| 293 | #endif /* _MEI_HW_TXE_REGS_H_ */ | ||
| 294 | |||
diff --git a/drivers/misc/mei/hw-txe.c b/drivers/misc/mei/hw-txe.c new file mode 100644 index 000000000000..19579e560dad --- /dev/null +++ b/drivers/misc/mei/hw-txe.c | |||
| @@ -0,0 +1,1106 @@ | |||
| 1 | /* | ||
| 2 | * | ||
| 3 | * Intel Management Engine Interface (Intel MEI) Linux driver | ||
| 4 | * Copyright (c) 2013-2014, Intel Corporation. | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify it | ||
| 7 | * under the terms and conditions of the GNU General Public License, | ||
| 8 | * version 2, as published by the Free Software Foundation. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 13 | * more details. | ||
| 14 | * | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <linux/pci.h> | ||
| 18 | #include <linux/jiffies.h> | ||
| 19 | #include <linux/delay.h> | ||
| 20 | #include <linux/kthread.h> | ||
| 21 | |||
| 22 | #include <linux/mei.h> | ||
| 23 | |||
| 24 | #include "mei_dev.h" | ||
| 25 | #include "hw-txe.h" | ||
| 26 | #include "client.h" | ||
| 27 | #include "hbm.h" | ||
| 28 | |||
| 29 | /** | ||
| 30 | * mei_txe_reg_read - Reads 32bit data from the device | ||
| 31 | * | ||
| 32 | * @base_addr: registers base address | ||
| 33 | * @offset: register offset | ||
| 34 | * | ||
| 35 | */ | ||
| 36 | static inline u32 mei_txe_reg_read(void __iomem *base_addr, | ||
| 37 | unsigned long offset) | ||
| 38 | { | ||
| 39 | return ioread32(base_addr + offset); | ||
| 40 | } | ||
| 41 | |||
| 42 | /** | ||
| 43 | * mei_txe_reg_write - Writes 32bit data to the device | ||
| 44 | * | ||
| 45 | * @base_addr: registers base address | ||
| 46 | * @offset: register offset | ||
| 47 | * @value: the value to write | ||
| 48 | */ | ||
| 49 | static inline void mei_txe_reg_write(void __iomem *base_addr, | ||
| 50 | unsigned long offset, u32 value) | ||
| 51 | { | ||
| 52 | iowrite32(value, base_addr + offset); | ||
| 53 | } | ||
| 54 | |||
| 55 | /** | ||
| 56 | * mei_txe_sec_reg_read_silent - Reads 32bit data from the SeC BAR | ||
| 57 | * | ||
| 58 | * @dev: the device structure | ||
| 59 | * @offset: register offset | ||
| 60 | * | ||
| 61 | * Doesn't check for aliveness while Reads 32bit data from the SeC BAR | ||
| 62 | */ | ||
| 63 | static inline u32 mei_txe_sec_reg_read_silent(struct mei_txe_hw *hw, | ||
| 64 | unsigned long offset) | ||
| 65 | { | ||
| 66 | return mei_txe_reg_read(hw->mem_addr[SEC_BAR], offset); | ||
| 67 | } | ||
| 68 | |||
| 69 | /** | ||
| 70 | * mei_txe_sec_reg_read - Reads 32bit data from the SeC BAR | ||
| 71 | * | ||
| 72 | * @dev: the device structure | ||
| 73 | * @offset: register offset | ||
| 74 | * | ||
| 75 | * Reads 32bit data from the SeC BAR and shout loud if aliveness is not set | ||
| 76 | */ | ||
| 77 | static inline u32 mei_txe_sec_reg_read(struct mei_txe_hw *hw, | ||
| 78 | unsigned long offset) | ||
| 79 | { | ||
| 80 | WARN(!hw->aliveness, "sec read: aliveness not asserted\n"); | ||
| 81 | return mei_txe_sec_reg_read_silent(hw, offset); | ||
| 82 | } | ||
| 83 | /** | ||
| 84 | * mei_txe_sec_reg_write_silent - Writes 32bit data to the SeC BAR | ||
| 85 | * doesn't check for aliveness | ||
| 86 | * | ||
| 87 | * @dev: the device structure | ||
| 88 | * @offset: register offset | ||
| 89 | * @value: value to write | ||
| 90 | * | ||
| 91 | * Doesn't check for aliveness while writes 32bit data from to the SeC BAR | ||
| 92 | */ | ||
| 93 | static inline void mei_txe_sec_reg_write_silent(struct mei_txe_hw *hw, | ||
| 94 | unsigned long offset, u32 value) | ||
| 95 | { | ||
| 96 | mei_txe_reg_write(hw->mem_addr[SEC_BAR], offset, value); | ||
| 97 | } | ||
| 98 | |||
| 99 | /** | ||
| 100 | * mei_txe_sec_reg_write - Writes 32bit data to the SeC BAR | ||
| 101 | * | ||
| 102 | * @dev: the device structure | ||
| 103 | * @offset: register offset | ||
| 104 | * @value: value to write | ||
| 105 | * | ||
| 106 | * Writes 32bit data from the SeC BAR and shout loud if aliveness is not set | ||
| 107 | */ | ||
| 108 | static inline void mei_txe_sec_reg_write(struct mei_txe_hw *hw, | ||
| 109 | unsigned long offset, u32 value) | ||
| 110 | { | ||
| 111 | WARN(!hw->aliveness, "sec write: aliveness not asserted\n"); | ||
| 112 | mei_txe_sec_reg_write_silent(hw, offset, value); | ||
| 113 | } | ||
| 114 | /** | ||
| 115 | * mei_txe_br_reg_read - Reads 32bit data from the Bridge BAR | ||
| 116 | * | ||
| 117 | * @hw: the device structure | ||
| 118 | * @offset: offset from which to read the data | ||
| 119 | * | ||
| 120 | */ | ||
| 121 | static inline u32 mei_txe_br_reg_read(struct mei_txe_hw *hw, | ||
| 122 | unsigned long offset) | ||
| 123 | { | ||
| 124 | return mei_txe_reg_read(hw->mem_addr[BRIDGE_BAR], offset); | ||
| 125 | } | ||
| 126 | |||
| 127 | /** | ||
| 128 | * mei_txe_br_reg_write - Writes 32bit data to the Bridge BAR | ||
| 129 | * | ||
| 130 | * @hw: the device structure | ||
| 131 | * @offset: offset from which to write the data | ||
| 132 | * @value: the byte to write | ||
| 133 | */ | ||
| 134 | static inline void mei_txe_br_reg_write(struct mei_txe_hw *hw, | ||
| 135 | unsigned long offset, u32 value) | ||
| 136 | { | ||
| 137 | mei_txe_reg_write(hw->mem_addr[BRIDGE_BAR], offset, value); | ||
| 138 | } | ||
| 139 | |||
| 140 | /** | ||
| 141 | * mei_txe_aliveness_set - request for aliveness change | ||
| 142 | * | ||
| 143 | * @dev: the device structure | ||
| 144 | * @req: requested aliveness value | ||
| 145 | * | ||
| 146 | * Request for aliveness change and returns true if the change is | ||
| 147 | * really needed and false if aliveness is already | ||
| 148 | * in the requested state | ||
| 149 | * Requires device lock to be held | ||
| 150 | */ | ||
| 151 | static bool mei_txe_aliveness_set(struct mei_device *dev, u32 req) | ||
| 152 | { | ||
| 153 | |||
| 154 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 155 | bool do_req = hw->aliveness != req; | ||
| 156 | |||
| 157 | dev_dbg(&dev->pdev->dev, "Aliveness current=%d request=%d\n", | ||
| 158 | hw->aliveness, req); | ||
| 159 | if (do_req) { | ||
| 160 | hw->recvd_aliveness = false; | ||
| 161 | mei_txe_br_reg_write(hw, SICR_HOST_ALIVENESS_REQ_REG, req); | ||
| 162 | } | ||
| 163 | return do_req; | ||
| 164 | } | ||
| 165 | |||
| 166 | |||
| 167 | /** | ||
| 168 | * mei_txe_aliveness_req_get - get aliveness requested register value | ||
| 169 | * | ||
| 170 | * @dev: the device structure | ||
| 171 | * | ||
| 172 | * Extract HICR_HOST_ALIVENESS_RESP_ACK bit from | ||
| 173 | * from HICR_HOST_ALIVENESS_REQ register value | ||
| 174 | */ | ||
| 175 | static u32 mei_txe_aliveness_req_get(struct mei_device *dev) | ||
| 176 | { | ||
| 177 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 178 | u32 reg; | ||
| 179 | reg = mei_txe_br_reg_read(hw, SICR_HOST_ALIVENESS_REQ_REG); | ||
| 180 | return reg & SICR_HOST_ALIVENESS_REQ_REQUESTED; | ||
| 181 | } | ||
| 182 | |||
| 183 | /** | ||
| 184 | * mei_txe_aliveness_get - get aliveness response register value | ||
| 185 | * @dev: the device structure | ||
| 186 | * | ||
| 187 | * Extract HICR_HOST_ALIVENESS_RESP_ACK bit | ||
| 188 | * from HICR_HOST_ALIVENESS_RESP register value | ||
| 189 | */ | ||
| 190 | static u32 mei_txe_aliveness_get(struct mei_device *dev) | ||
| 191 | { | ||
| 192 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 193 | u32 reg; | ||
| 194 | reg = mei_txe_br_reg_read(hw, HICR_HOST_ALIVENESS_RESP_REG); | ||
| 195 | return reg & HICR_HOST_ALIVENESS_RESP_ACK; | ||
| 196 | } | ||
| 197 | |||
| 198 | /** | ||
| 199 | * mei_txe_aliveness_poll - waits for aliveness to settle | ||
| 200 | * | ||
| 201 | * @dev: the device structure | ||
| 202 | * @expected: expected aliveness value | ||
| 203 | * | ||
| 204 | * Polls for HICR_HOST_ALIVENESS_RESP.ALIVENESS_RESP to be set | ||
| 205 | * returns > 0 if the expected value was received, -ETIME otherwise | ||
| 206 | */ | ||
| 207 | static int mei_txe_aliveness_poll(struct mei_device *dev, u32 expected) | ||
| 208 | { | ||
| 209 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 210 | int t = 0; | ||
| 211 | |||
| 212 | do { | ||
| 213 | hw->aliveness = mei_txe_aliveness_get(dev); | ||
| 214 | if (hw->aliveness == expected) { | ||
| 215 | dev_dbg(&dev->pdev->dev, | ||
| 216 | "aliveness settled after %d msecs\n", t); | ||
| 217 | return t; | ||
| 218 | } | ||
| 219 | mutex_unlock(&dev->device_lock); | ||
| 220 | msleep(MSEC_PER_SEC / 5); | ||
| 221 | mutex_lock(&dev->device_lock); | ||
| 222 | t += MSEC_PER_SEC / 5; | ||
| 223 | } while (t < SEC_ALIVENESS_WAIT_TIMEOUT); | ||
| 224 | |||
| 225 | dev_err(&dev->pdev->dev, "aliveness timed out\n"); | ||
| 226 | return -ETIME; | ||
| 227 | } | ||
| 228 | |||
| 229 | /** | ||
| 230 | * mei_txe_aliveness_wait - waits for aliveness to settle | ||
| 231 | * | ||
| 232 | * @dev: the device structure | ||
| 233 | * @expected: expected aliveness value | ||
| 234 | * | ||
| 235 | * Waits for HICR_HOST_ALIVENESS_RESP.ALIVENESS_RESP to be set | ||
| 236 | * returns returns 0 on success and < 0 otherwise | ||
| 237 | */ | ||
| 238 | static int mei_txe_aliveness_wait(struct mei_device *dev, u32 expected) | ||
| 239 | { | ||
| 240 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 241 | const unsigned long timeout = | ||
| 242 | msecs_to_jiffies(SEC_ALIVENESS_WAIT_TIMEOUT); | ||
| 243 | long err; | ||
| 244 | int ret; | ||
| 245 | |||
| 246 | hw->aliveness = mei_txe_aliveness_get(dev); | ||
| 247 | if (hw->aliveness == expected) | ||
| 248 | return 0; | ||
| 249 | |||
| 250 | mutex_unlock(&dev->device_lock); | ||
| 251 | err = wait_event_timeout(hw->wait_aliveness, | ||
| 252 | hw->recvd_aliveness, timeout); | ||
| 253 | mutex_lock(&dev->device_lock); | ||
| 254 | |||
| 255 | hw->aliveness = mei_txe_aliveness_get(dev); | ||
| 256 | ret = hw->aliveness == expected ? 0 : -ETIME; | ||
| 257 | |||
| 258 | if (ret) | ||
| 259 | dev_err(&dev->pdev->dev, "aliveness timed out"); | ||
| 260 | else | ||
| 261 | dev_dbg(&dev->pdev->dev, "aliveness settled after %d msecs\n", | ||
| 262 | jiffies_to_msecs(timeout - err)); | ||
| 263 | hw->recvd_aliveness = false; | ||
| 264 | return ret; | ||
| 265 | } | ||
| 266 | |||
| 267 | /** | ||
| 268 | * mei_txe_aliveness_set_sync - sets an wait for aliveness to complete | ||
| 269 | * | ||
| 270 | * @dev: the device structure | ||
| 271 | * | ||
| 272 | * returns returns 0 on success and < 0 otherwise | ||
| 273 | */ | ||
| 274 | int mei_txe_aliveness_set_sync(struct mei_device *dev, u32 req) | ||
| 275 | { | ||
| 276 | if (mei_txe_aliveness_set(dev, req)) | ||
| 277 | return mei_txe_aliveness_wait(dev, req); | ||
| 278 | return 0; | ||
| 279 | } | ||
| 280 | |||
| 281 | /** | ||
| 282 | * mei_txe_input_ready_interrupt_enable - sets the Input Ready Interrupt | ||
| 283 | * | ||
| 284 | * @dev: the device structure | ||
| 285 | */ | ||
| 286 | static void mei_txe_input_ready_interrupt_enable(struct mei_device *dev) | ||
| 287 | { | ||
| 288 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 289 | u32 hintmsk; | ||
| 290 | /* Enable the SEC_IPC_HOST_INT_MASK_IN_RDY interrupt */ | ||
| 291 | hintmsk = mei_txe_sec_reg_read(hw, SEC_IPC_HOST_INT_MASK_REG); | ||
| 292 | hintmsk |= SEC_IPC_HOST_INT_MASK_IN_RDY; | ||
| 293 | mei_txe_sec_reg_write(hw, SEC_IPC_HOST_INT_MASK_REG, hintmsk); | ||
| 294 | } | ||
| 295 | |||
| 296 | /** | ||
| 297 | * mei_txe_input_doorbell_set | ||
| 298 | * - Sets bit 0 in SEC_IPC_INPUT_DOORBELL.IPC_INPUT_DOORBELL. | ||
| 299 | * @dev: the device structure | ||
| 300 | */ | ||
| 301 | static void mei_txe_input_doorbell_set(struct mei_txe_hw *hw) | ||
| 302 | { | ||
| 303 | /* Clear the interrupt cause */ | ||
| 304 | clear_bit(TXE_INTR_IN_READY_BIT, &hw->intr_cause); | ||
| 305 | mei_txe_sec_reg_write(hw, SEC_IPC_INPUT_DOORBELL_REG, 1); | ||
| 306 | } | ||
| 307 | |||
| 308 | /** | ||
| 309 | * mei_txe_output_ready_set - Sets the SICR_SEC_IPC_OUTPUT_STATUS bit to 1 | ||
| 310 | * | ||
| 311 | * @dev: the device structure | ||
| 312 | */ | ||
| 313 | static void mei_txe_output_ready_set(struct mei_txe_hw *hw) | ||
| 314 | { | ||
| 315 | mei_txe_br_reg_write(hw, | ||
| 316 | SICR_SEC_IPC_OUTPUT_STATUS_REG, | ||
| 317 | SEC_IPC_OUTPUT_STATUS_RDY); | ||
| 318 | } | ||
| 319 | |||
| 320 | /** | ||
| 321 | * mei_txe_is_input_ready - check if TXE is ready for receiving data | ||
| 322 | * | ||
| 323 | * @dev: the device structure | ||
| 324 | */ | ||
| 325 | static bool mei_txe_is_input_ready(struct mei_device *dev) | ||
| 326 | { | ||
| 327 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 328 | u32 status; | ||
| 329 | status = mei_txe_sec_reg_read(hw, SEC_IPC_INPUT_STATUS_REG); | ||
| 330 | return !!(SEC_IPC_INPUT_STATUS_RDY & status); | ||
| 331 | } | ||
| 332 | |||
| 333 | /** | ||
| 334 | * mei_txe_intr_clear - clear all interrupts | ||
| 335 | * | ||
| 336 | * @dev: the device structure | ||
| 337 | */ | ||
| 338 | static inline void mei_txe_intr_clear(struct mei_device *dev) | ||
| 339 | { | ||
| 340 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 341 | mei_txe_sec_reg_write_silent(hw, SEC_IPC_HOST_INT_STATUS_REG, | ||
| 342 | SEC_IPC_HOST_INT_STATUS_PENDING); | ||
| 343 | mei_txe_br_reg_write(hw, HISR_REG, HISR_INT_STS_MSK); | ||
| 344 | mei_txe_br_reg_write(hw, HHISR_REG, IPC_HHIER_MSK); | ||
| 345 | } | ||
| 346 | |||
| 347 | /** | ||
| 348 | * mei_txe_intr_disable - disable all interrupts | ||
| 349 | * | ||
| 350 | * @dev: the device structure | ||
| 351 | */ | ||
| 352 | static void mei_txe_intr_disable(struct mei_device *dev) | ||
| 353 | { | ||
| 354 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 355 | mei_txe_br_reg_write(hw, HHIER_REG, 0); | ||
| 356 | mei_txe_br_reg_write(hw, HIER_REG, 0); | ||
| 357 | } | ||
| 358 | /** | ||
| 359 | * mei_txe_intr_disable - enable all interrupts | ||
| 360 | * | ||
| 361 | * @dev: the device structure | ||
| 362 | */ | ||
| 363 | static void mei_txe_intr_enable(struct mei_device *dev) | ||
| 364 | { | ||
| 365 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 366 | mei_txe_br_reg_write(hw, HHIER_REG, IPC_HHIER_MSK); | ||
| 367 | mei_txe_br_reg_write(hw, HIER_REG, HIER_INT_EN_MSK); | ||
| 368 | } | ||
| 369 | |||
| 370 | /** | ||
| 371 | * mei_txe_pending_interrupts - check if there are pending interrupts | ||
| 372 | * only Aliveness, Input ready, and output doorbell are of relevance | ||
| 373 | * | ||
| 374 | * @dev: the device structure | ||
| 375 | * | ||
| 376 | * Checks if there are pending interrupts | ||
| 377 | * only Aliveness, Readiness, Input ready, and Output doorbell are relevant | ||
| 378 | */ | ||
| 379 | static bool mei_txe_pending_interrupts(struct mei_device *dev) | ||
| 380 | { | ||
| 381 | |||
| 382 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 383 | bool ret = (hw->intr_cause & (TXE_INTR_READINESS | | ||
| 384 | TXE_INTR_ALIVENESS | | ||
| 385 | TXE_INTR_IN_READY | | ||
| 386 | TXE_INTR_OUT_DB)); | ||
| 387 | |||
| 388 | if (ret) { | ||
| 389 | dev_dbg(&dev->pdev->dev, | ||
| 390 | "Pending Interrupts InReady=%01d Readiness=%01d, Aliveness=%01d, OutDoor=%01d\n", | ||
| 391 | !!(hw->intr_cause & TXE_INTR_IN_READY), | ||
| 392 | !!(hw->intr_cause & TXE_INTR_READINESS), | ||
| 393 | !!(hw->intr_cause & TXE_INTR_ALIVENESS), | ||
| 394 | !!(hw->intr_cause & TXE_INTR_OUT_DB)); | ||
| 395 | } | ||
| 396 | return ret; | ||
| 397 | } | ||
| 398 | |||
| 399 | /** | ||
| 400 | * mei_txe_input_payload_write - write a dword to the host buffer | ||
| 401 | * at offset idx | ||
| 402 | * | ||
| 403 | * @dev: the device structure | ||
| 404 | * @idx: index in the host buffer | ||
| 405 | * @value: value | ||
| 406 | */ | ||
| 407 | static void mei_txe_input_payload_write(struct mei_device *dev, | ||
| 408 | unsigned long idx, u32 value) | ||
| 409 | { | ||
| 410 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 411 | mei_txe_sec_reg_write(hw, SEC_IPC_INPUT_PAYLOAD_REG + | ||
| 412 | (idx * sizeof(u32)), value); | ||
| 413 | } | ||
| 414 | |||
| 415 | /** | ||
| 416 | * mei_txe_out_data_read - read dword from the device buffer | ||
| 417 | * at offset idx | ||
| 418 | * | ||
| 419 | * @dev: the device structure | ||
| 420 | * @idx: index in the device buffer | ||
| 421 | * | ||
| 422 | * returns register value at index | ||
| 423 | */ | ||
| 424 | static u32 mei_txe_out_data_read(const struct mei_device *dev, | ||
| 425 | unsigned long idx) | ||
| 426 | { | ||
| 427 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 428 | return mei_txe_br_reg_read(hw, | ||
| 429 | BRIDGE_IPC_OUTPUT_PAYLOAD_REG + (idx * sizeof(u32))); | ||
| 430 | } | ||
| 431 | |||
| 432 | /* Readiness */ | ||
| 433 | |||
| 434 | /** | ||
| 435 | * mei_txe_readiness_set_host_rdy | ||
| 436 | * | ||
| 437 | * @dev: the device structure | ||
| 438 | */ | ||
| 439 | static void mei_txe_readiness_set_host_rdy(struct mei_device *dev) | ||
| 440 | { | ||
| 441 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 442 | mei_txe_br_reg_write(hw, | ||
| 443 | SICR_HOST_IPC_READINESS_REQ_REG, | ||
| 444 | SICR_HOST_IPC_READINESS_HOST_RDY); | ||
| 445 | } | ||
| 446 | |||
| 447 | /** | ||
| 448 | * mei_txe_readiness_clear | ||
| 449 | * | ||
| 450 | * @dev: the device structure | ||
| 451 | */ | ||
| 452 | static void mei_txe_readiness_clear(struct mei_device *dev) | ||
| 453 | { | ||
| 454 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 455 | mei_txe_br_reg_write(hw, SICR_HOST_IPC_READINESS_REQ_REG, | ||
| 456 | SICR_HOST_IPC_READINESS_RDY_CLR); | ||
| 457 | } | ||
| 458 | /** | ||
| 459 | * mei_txe_readiness_get - Reads and returns | ||
| 460 | * the HICR_SEC_IPC_READINESS register value | ||
| 461 | * | ||
| 462 | * @dev: the device structure | ||
| 463 | */ | ||
| 464 | static u32 mei_txe_readiness_get(struct mei_device *dev) | ||
| 465 | { | ||
| 466 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 467 | return mei_txe_br_reg_read(hw, HICR_SEC_IPC_READINESS_REG); | ||
| 468 | } | ||
| 469 | |||
| 470 | |||
| 471 | /** | ||
| 472 | * mei_txe_readiness_is_sec_rdy - check readiness | ||
| 473 | * for HICR_SEC_IPC_READINESS_SEC_RDY | ||
| 474 | * | ||
| 475 | * @readiness - cached readiness state | ||
| 476 | */ | ||
| 477 | static inline bool mei_txe_readiness_is_sec_rdy(u32 readiness) | ||
| 478 | { | ||
| 479 | return !!(readiness & HICR_SEC_IPC_READINESS_SEC_RDY); | ||
| 480 | } | ||
| 481 | |||
| 482 | /** | ||
| 483 | * mei_txe_hw_is_ready - check if the hw is ready | ||
| 484 | * | ||
| 485 | * @dev: the device structure | ||
| 486 | */ | ||
| 487 | static bool mei_txe_hw_is_ready(struct mei_device *dev) | ||
| 488 | { | ||
| 489 | u32 readiness = mei_txe_readiness_get(dev); | ||
| 490 | return mei_txe_readiness_is_sec_rdy(readiness); | ||
| 491 | } | ||
| 492 | |||
| 493 | /** | ||
| 494 | * mei_txe_host_is_ready - check if the host is ready | ||
| 495 | * | ||
| 496 | * @dev: the device structure | ||
| 497 | */ | ||
| 498 | static inline bool mei_txe_host_is_ready(struct mei_device *dev) | ||
| 499 | { | ||
| 500 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 501 | u32 reg = mei_txe_br_reg_read(hw, HICR_SEC_IPC_READINESS_REG); | ||
| 502 | return !!(reg & HICR_SEC_IPC_READINESS_HOST_RDY); | ||
| 503 | } | ||
| 504 | |||
| 505 | /** | ||
| 506 | * mei_txe_readiness_wait - wait till readiness settles | ||
| 507 | * | ||
| 508 | * @dev: the device structure | ||
| 509 | * | ||
| 510 | * returns 0 on success and -ETIME on timeout | ||
| 511 | */ | ||
| 512 | static int mei_txe_readiness_wait(struct mei_device *dev) | ||
| 513 | { | ||
| 514 | if (mei_txe_hw_is_ready(dev)) | ||
| 515 | return 0; | ||
| 516 | |||
| 517 | mutex_unlock(&dev->device_lock); | ||
| 518 | wait_event_timeout(dev->wait_hw_ready, dev->recvd_hw_ready, | ||
| 519 | msecs_to_jiffies(SEC_RESET_WAIT_TIMEOUT)); | ||
| 520 | mutex_lock(&dev->device_lock); | ||
| 521 | if (!dev->recvd_hw_ready) { | ||
| 522 | dev_err(&dev->pdev->dev, "wait for readiness failed\n"); | ||
| 523 | return -ETIME; | ||
| 524 | } | ||
| 525 | |||
| 526 | dev->recvd_hw_ready = false; | ||
| 527 | return 0; | ||
| 528 | } | ||
| 529 | |||
| 530 | /** | ||
| 531 | * mei_txe_hw_config - configure hardware at the start of the devices | ||
| 532 | * | ||
| 533 | * @dev: the device structure | ||
| 534 | * | ||
| 535 | * Configure hardware at the start of the device should be done only | ||
| 536 | * once at the device probe time | ||
| 537 | */ | ||
| 538 | static void mei_txe_hw_config(struct mei_device *dev) | ||
| 539 | { | ||
| 540 | |||
| 541 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 542 | /* Doesn't change in runtime */ | ||
| 543 | dev->hbuf_depth = PAYLOAD_SIZE / 4; | ||
| 544 | |||
| 545 | hw->aliveness = mei_txe_aliveness_get(dev); | ||
| 546 | hw->readiness = mei_txe_readiness_get(dev); | ||
| 547 | |||
| 548 | dev_dbg(&dev->pdev->dev, "aliveness_resp = 0x%08x, readiness = 0x%08x.\n", | ||
| 549 | hw->aliveness, hw->readiness); | ||
| 550 | } | ||
| 551 | |||
| 552 | |||
| 553 | /** | ||
| 554 | * mei_txe_write - writes a message to device. | ||
| 555 | * | ||
| 556 | * @dev: the device structure | ||
| 557 | * @header: header of message | ||
| 558 | * @buf: message buffer will be written | ||
| 559 | * returns 1 if success, 0 - otherwise. | ||
| 560 | */ | ||
| 561 | |||
| 562 | static int mei_txe_write(struct mei_device *dev, | ||
| 563 | struct mei_msg_hdr *header, unsigned char *buf) | ||
| 564 | { | ||
| 565 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 566 | unsigned long rem; | ||
| 567 | unsigned long length; | ||
| 568 | u32 *reg_buf = (u32 *)buf; | ||
| 569 | int i; | ||
| 570 | |||
| 571 | if (WARN_ON(!header || !buf)) | ||
| 572 | return -EINVAL; | ||
| 573 | |||
| 574 | length = header->length; | ||
| 575 | |||
| 576 | dev_dbg(&dev->pdev->dev, MEI_HDR_FMT, MEI_HDR_PRM(header)); | ||
| 577 | |||
| 578 | if ((length + sizeof(struct mei_msg_hdr)) > PAYLOAD_SIZE) { | ||
| 579 | dev_err(&dev->pdev->dev, "write length exceeded = %ld > %d\n", | ||
| 580 | length + sizeof(struct mei_msg_hdr), PAYLOAD_SIZE); | ||
| 581 | return -ERANGE; | ||
| 582 | } | ||
| 583 | |||
| 584 | if (WARN(!hw->aliveness, "txe write: aliveness not asserted\n")) | ||
| 585 | return -EAGAIN; | ||
| 586 | |||
| 587 | /* Enable Input Ready Interrupt. */ | ||
| 588 | mei_txe_input_ready_interrupt_enable(dev); | ||
| 589 | |||
| 590 | if (!mei_txe_is_input_ready(dev)) { | ||
| 591 | dev_err(&dev->pdev->dev, "Input is not ready"); | ||
| 592 | return -EAGAIN; | ||
| 593 | } | ||
| 594 | |||
| 595 | mei_txe_input_payload_write(dev, 0, *((u32 *)header)); | ||
| 596 | |||
| 597 | for (i = 0; i < length / 4; i++) | ||
| 598 | mei_txe_input_payload_write(dev, i + 1, reg_buf[i]); | ||
| 599 | |||
| 600 | rem = length & 0x3; | ||
| 601 | if (rem > 0) { | ||
| 602 | u32 reg = 0; | ||
| 603 | memcpy(®, &buf[length - rem], rem); | ||
| 604 | mei_txe_input_payload_write(dev, i + 1, reg); | ||
| 605 | } | ||
| 606 | |||
| 607 | dev->hbuf_is_ready = false; | ||
| 608 | /* Set Input-Doorbell */ | ||
| 609 | mei_txe_input_doorbell_set(hw); | ||
| 610 | |||
| 611 | return 0; | ||
| 612 | } | ||
| 613 | |||
| 614 | /** | ||
| 615 | * mei_txe_hbuf_max_len - mimics the me hbuf circular buffer | ||
| 616 | * | ||
| 617 | * @dev: the device structure | ||
| 618 | * | ||
| 619 | * returns the PAYLOAD_SIZE - 4 | ||
| 620 | */ | ||
| 621 | static size_t mei_txe_hbuf_max_len(const struct mei_device *dev) | ||
| 622 | { | ||
| 623 | return PAYLOAD_SIZE - sizeof(struct mei_msg_hdr); | ||
| 624 | } | ||
| 625 | |||
| 626 | /** | ||
| 627 | * mei_txe_hbuf_empty_slots - mimics the me hbuf circular buffer | ||
| 628 | * | ||
| 629 | * @dev: the device structure | ||
| 630 | * | ||
| 631 | * returns always hbuf_depth | ||
| 632 | */ | ||
| 633 | static int mei_txe_hbuf_empty_slots(struct mei_device *dev) | ||
| 634 | { | ||
| 635 | return dev->hbuf_depth; | ||
| 636 | } | ||
| 637 | |||
| 638 | /** | ||
| 639 | * mei_txe_count_full_read_slots - mimics the me device circular buffer | ||
| 640 | * | ||
| 641 | * @dev: the device structure | ||
| 642 | * | ||
| 643 | * returns always buffer size in dwords count | ||
| 644 | */ | ||
| 645 | static int mei_txe_count_full_read_slots(struct mei_device *dev) | ||
| 646 | { | ||
| 647 | /* read buffers has static size */ | ||
| 648 | return PAYLOAD_SIZE / 4; | ||
| 649 | } | ||
| 650 | |||
| 651 | /** | ||
| 652 | * mei_txe_read_hdr - read message header which is always in 4 first bytes | ||
| 653 | * | ||
| 654 | * @dev: the device structure | ||
| 655 | * | ||
| 656 | * returns mei message header | ||
| 657 | */ | ||
| 658 | |||
| 659 | static u32 mei_txe_read_hdr(const struct mei_device *dev) | ||
| 660 | { | ||
| 661 | return mei_txe_out_data_read(dev, 0); | ||
| 662 | } | ||
| 663 | /** | ||
| 664 | * mei_txe_read - reads a message from the txe device. | ||
| 665 | * | ||
| 666 | * @dev: the device structure | ||
| 667 | * @buf: message buffer will be written | ||
| 668 | * @len: message size will be read | ||
| 669 | * | ||
| 670 | * returns -EINVAL on error wrong argument and 0 on success | ||
| 671 | */ | ||
| 672 | static int mei_txe_read(struct mei_device *dev, | ||
| 673 | unsigned char *buf, unsigned long len) | ||
| 674 | { | ||
| 675 | |||
| 676 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 677 | u32 i; | ||
| 678 | u32 *reg_buf = (u32 *)buf; | ||
| 679 | u32 rem = len & 0x3; | ||
| 680 | |||
| 681 | if (WARN_ON(!buf || !len)) | ||
| 682 | return -EINVAL; | ||
| 683 | |||
| 684 | dev_dbg(&dev->pdev->dev, | ||
| 685 | "buffer-length = %lu buf[0]0x%08X\n", | ||
| 686 | len, mei_txe_out_data_read(dev, 0)); | ||
| 687 | |||
| 688 | for (i = 0; i < len / 4; i++) { | ||
| 689 | /* skip header: index starts from 1 */ | ||
| 690 | u32 reg = mei_txe_out_data_read(dev, i + 1); | ||
| 691 | dev_dbg(&dev->pdev->dev, "buf[%d] = 0x%08X\n", i, reg); | ||
| 692 | *reg_buf++ = reg; | ||
| 693 | } | ||
| 694 | |||
| 695 | if (rem) { | ||
| 696 | u32 reg = mei_txe_out_data_read(dev, i + 1); | ||
| 697 | memcpy(reg_buf, ®, rem); | ||
| 698 | } | ||
| 699 | |||
| 700 | mei_txe_output_ready_set(hw); | ||
| 701 | return 0; | ||
| 702 | } | ||
| 703 | |||
| 704 | /** | ||
| 705 | * mei_txe_hw_reset - resets host and fw. | ||
| 706 | * | ||
| 707 | * @dev: the device structure | ||
| 708 | * @intr_enable: if interrupt should be enabled after reset. | ||
| 709 | * | ||
| 710 | * returns 0 on success and < 0 in case of error | ||
| 711 | */ | ||
| 712 | static int mei_txe_hw_reset(struct mei_device *dev, bool intr_enable) | ||
| 713 | { | ||
| 714 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 715 | |||
| 716 | u32 aliveness_req; | ||
| 717 | /* | ||
| 718 | * read input doorbell to ensure consistency between Bridge and SeC | ||
| 719 | * return value might be garbage return | ||
| 720 | */ | ||
| 721 | (void)mei_txe_sec_reg_read_silent(hw, SEC_IPC_INPUT_DOORBELL_REG); | ||
| 722 | |||
| 723 | aliveness_req = mei_txe_aliveness_req_get(dev); | ||
| 724 | hw->aliveness = mei_txe_aliveness_get(dev); | ||
| 725 | |||
| 726 | /* Disable interrupts in this stage we will poll */ | ||
| 727 | mei_txe_intr_disable(dev); | ||
| 728 | |||
| 729 | /* | ||
| 730 | * If Aliveness Request and Aliveness Response are not equal then | ||
| 731 | * wait for them to be equal | ||
| 732 | * Since we might have interrupts disabled - poll for it | ||
| 733 | */ | ||
| 734 | if (aliveness_req != hw->aliveness) | ||
| 735 | if (mei_txe_aliveness_poll(dev, aliveness_req) < 0) { | ||
| 736 | dev_err(&dev->pdev->dev, | ||
| 737 | "wait for aliveness settle failed ... bailing out\n"); | ||
| 738 | return -EIO; | ||
| 739 | } | ||
| 740 | |||
| 741 | /* | ||
| 742 | * If Aliveness Request and Aliveness Response are set then clear them | ||
| 743 | */ | ||
| 744 | if (aliveness_req) { | ||
| 745 | mei_txe_aliveness_set(dev, 0); | ||
| 746 | if (mei_txe_aliveness_poll(dev, 0) < 0) { | ||
| 747 | dev_err(&dev->pdev->dev, | ||
| 748 | "wait for aliveness failed ... bailing out\n"); | ||
| 749 | return -EIO; | ||
| 750 | } | ||
| 751 | } | ||
| 752 | |||
| 753 | /* | ||
| 754 | * Set rediness RDY_CLR bit | ||
| 755 | */ | ||
| 756 | mei_txe_readiness_clear(dev); | ||
| 757 | |||
| 758 | return 0; | ||
| 759 | } | ||
| 760 | |||
| 761 | /** | ||
| 762 | * mei_txe_hw_start - start the hardware after reset | ||
| 763 | * | ||
| 764 | * @dev: the device structure | ||
| 765 | * | ||
| 766 | * returns 0 on success and < 0 in case of error | ||
| 767 | */ | ||
| 768 | static int mei_txe_hw_start(struct mei_device *dev) | ||
| 769 | { | ||
| 770 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 771 | int ret; | ||
| 772 | |||
| 773 | u32 hisr; | ||
| 774 | |||
| 775 | /* bring back interrupts */ | ||
| 776 | mei_txe_intr_enable(dev); | ||
| 777 | |||
| 778 | ret = mei_txe_readiness_wait(dev); | ||
| 779 | if (ret < 0) { | ||
| 780 | dev_err(&dev->pdev->dev, "wating for readiness failed\n"); | ||
| 781 | return ret; | ||
| 782 | } | ||
| 783 | |||
| 784 | /* | ||
| 785 | * If HISR.INT2_STS interrupt status bit is set then clear it. | ||
| 786 | */ | ||
| 787 | hisr = mei_txe_br_reg_read(hw, HISR_REG); | ||
| 788 | if (hisr & HISR_INT_2_STS) | ||
| 789 | mei_txe_br_reg_write(hw, HISR_REG, HISR_INT_2_STS); | ||
| 790 | |||
| 791 | /* Clear the interrupt cause of OutputDoorbell */ | ||
| 792 | clear_bit(TXE_INTR_OUT_DB_BIT, &hw->intr_cause); | ||
| 793 | |||
| 794 | ret = mei_txe_aliveness_set_sync(dev, 1); | ||
| 795 | if (ret < 0) { | ||
| 796 | dev_err(&dev->pdev->dev, "wait for aliveness failed ... bailing out\n"); | ||
| 797 | return ret; | ||
| 798 | } | ||
| 799 | |||
| 800 | /* enable input ready interrupts: | ||
| 801 | * SEC_IPC_HOST_INT_MASK.IPC_INPUT_READY_INT_MASK | ||
| 802 | */ | ||
| 803 | mei_txe_input_ready_interrupt_enable(dev); | ||
| 804 | |||
| 805 | |||
| 806 | /* Set the SICR_SEC_IPC_OUTPUT_STATUS.IPC_OUTPUT_READY bit */ | ||
| 807 | mei_txe_output_ready_set(hw); | ||
| 808 | |||
| 809 | /* Set bit SICR_HOST_IPC_READINESS.HOST_RDY | ||
| 810 | */ | ||
| 811 | mei_txe_readiness_set_host_rdy(dev); | ||
| 812 | |||
| 813 | return 0; | ||
| 814 | } | ||
| 815 | |||
| 816 | /** | ||
| 817 | * mei_txe_check_and_ack_intrs - translate multi BAR interrupt into | ||
| 818 | * single bit mask and acknowledge the interrupts | ||
| 819 | * | ||
| 820 | * @dev: the device structure | ||
| 821 | * @do_ack: acknowledge interrupts | ||
| 822 | */ | ||
| 823 | static bool mei_txe_check_and_ack_intrs(struct mei_device *dev, bool do_ack) | ||
| 824 | { | ||
| 825 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 826 | u32 hisr; | ||
| 827 | u32 hhisr; | ||
| 828 | u32 ipc_isr; | ||
| 829 | u32 aliveness; | ||
| 830 | bool generated; | ||
| 831 | |||
| 832 | /* read interrupt registers */ | ||
| 833 | hhisr = mei_txe_br_reg_read(hw, HHISR_REG); | ||
| 834 | generated = (hhisr & IPC_HHIER_MSK); | ||
| 835 | if (!generated) | ||
| 836 | goto out; | ||
| 837 | |||
| 838 | hisr = mei_txe_br_reg_read(hw, HISR_REG); | ||
| 839 | |||
| 840 | aliveness = mei_txe_aliveness_get(dev); | ||
| 841 | if (hhisr & IPC_HHIER_SEC && aliveness) | ||
| 842 | ipc_isr = mei_txe_sec_reg_read_silent(hw, | ||
| 843 | SEC_IPC_HOST_INT_STATUS_REG); | ||
| 844 | else | ||
| 845 | ipc_isr = 0; | ||
| 846 | |||
| 847 | generated = generated || | ||
| 848 | (hisr & HISR_INT_STS_MSK) || | ||
| 849 | (ipc_isr & SEC_IPC_HOST_INT_STATUS_PENDING); | ||
| 850 | |||
| 851 | if (generated && do_ack) { | ||
| 852 | /* Save the interrupt causes */ | ||
| 853 | hw->intr_cause |= hisr & HISR_INT_STS_MSK; | ||
| 854 | if (ipc_isr & SEC_IPC_HOST_INT_STATUS_IN_RDY) | ||
| 855 | hw->intr_cause |= TXE_INTR_IN_READY; | ||
| 856 | |||
| 857 | |||
| 858 | mei_txe_intr_disable(dev); | ||
| 859 | /* Clear the interrupts in hierarchy: | ||
| 860 | * IPC and Bridge, than the High Level */ | ||
| 861 | mei_txe_sec_reg_write_silent(hw, | ||
| 862 | SEC_IPC_HOST_INT_STATUS_REG, ipc_isr); | ||
| 863 | mei_txe_br_reg_write(hw, HISR_REG, hisr); | ||
| 864 | mei_txe_br_reg_write(hw, HHISR_REG, hhisr); | ||
| 865 | } | ||
| 866 | |||
| 867 | out: | ||
| 868 | return generated; | ||
| 869 | } | ||
| 870 | |||
| 871 | /** | ||
| 872 | * mei_txe_irq_quick_handler - The ISR of the MEI device | ||
| 873 | * | ||
| 874 | * @irq: The irq number | ||
| 875 | * @dev_id: pointer to the device structure | ||
| 876 | * | ||
| 877 | * returns irqreturn_t | ||
| 878 | */ | ||
| 879 | irqreturn_t mei_txe_irq_quick_handler(int irq, void *dev_id) | ||
| 880 | { | ||
| 881 | struct mei_device *dev = dev_id; | ||
| 882 | |||
| 883 | if (mei_txe_check_and_ack_intrs(dev, true)) | ||
| 884 | return IRQ_WAKE_THREAD; | ||
| 885 | return IRQ_NONE; | ||
| 886 | } | ||
| 887 | |||
| 888 | |||
| 889 | /** | ||
| 890 | * mei_txe_irq_thread_handler - txe interrupt thread | ||
| 891 | * | ||
| 892 | * @irq: The irq number | ||
| 893 | * @dev_id: pointer to the device structure | ||
| 894 | * | ||
| 895 | * returns irqreturn_t | ||
| 896 | * | ||
| 897 | */ | ||
| 898 | irqreturn_t mei_txe_irq_thread_handler(int irq, void *dev_id) | ||
| 899 | { | ||
| 900 | struct mei_device *dev = (struct mei_device *) dev_id; | ||
| 901 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 902 | struct mei_cl_cb complete_list; | ||
| 903 | s32 slots; | ||
| 904 | int rets = 0; | ||
| 905 | |||
| 906 | dev_dbg(&dev->pdev->dev, "irq thread: Interrupt Registers HHISR|HISR|SEC=%02X|%04X|%02X\n", | ||
| 907 | mei_txe_br_reg_read(hw, HHISR_REG), | ||
| 908 | mei_txe_br_reg_read(hw, HISR_REG), | ||
| 909 | mei_txe_sec_reg_read_silent(hw, SEC_IPC_HOST_INT_STATUS_REG)); | ||
| 910 | |||
| 911 | |||
| 912 | /* initialize our complete list */ | ||
| 913 | mutex_lock(&dev->device_lock); | ||
| 914 | mei_io_list_init(&complete_list); | ||
| 915 | |||
| 916 | if (pci_dev_msi_enabled(dev->pdev)) | ||
| 917 | mei_txe_check_and_ack_intrs(dev, true); | ||
| 918 | |||
| 919 | /* show irq events */ | ||
| 920 | mei_txe_pending_interrupts(dev); | ||
| 921 | |||
| 922 | hw->aliveness = mei_txe_aliveness_get(dev); | ||
| 923 | hw->readiness = mei_txe_readiness_get(dev); | ||
| 924 | |||
| 925 | /* Readiness: | ||
| 926 | * Detection of TXE driver going through reset | ||
| 927 | * or TXE driver resetting the HECI interface. | ||
| 928 | */ | ||
| 929 | if (test_and_clear_bit(TXE_INTR_READINESS_BIT, &hw->intr_cause)) { | ||
| 930 | dev_dbg(&dev->pdev->dev, "Readiness Interrupt was received...\n"); | ||
| 931 | |||
| 932 | /* Check if SeC is going through reset */ | ||
| 933 | if (mei_txe_readiness_is_sec_rdy(hw->readiness)) { | ||
| 934 | dev_dbg(&dev->pdev->dev, "we need to start the dev.\n"); | ||
| 935 | dev->recvd_hw_ready = true; | ||
| 936 | } else { | ||
| 937 | dev->recvd_hw_ready = false; | ||
| 938 | if (dev->dev_state != MEI_DEV_RESETTING) { | ||
| 939 | |||
| 940 | dev_warn(&dev->pdev->dev, "FW not ready: resetting.\n"); | ||
| 941 | schedule_work(&dev->reset_work); | ||
| 942 | goto end; | ||
| 943 | |||
| 944 | } | ||
| 945 | } | ||
| 946 | wake_up(&dev->wait_hw_ready); | ||
| 947 | } | ||
| 948 | |||
| 949 | /************************************************************/ | ||
| 950 | /* Check interrupt cause: | ||
| 951 | * Aliveness: Detection of SeC acknowledge of host request that | ||
| 952 | * it remain alive or host cancellation of that request. | ||
| 953 | */ | ||
| 954 | |||
| 955 | if (test_and_clear_bit(TXE_INTR_ALIVENESS_BIT, &hw->intr_cause)) { | ||
| 956 | /* Clear the interrupt cause */ | ||
| 957 | dev_dbg(&dev->pdev->dev, | ||
| 958 | "Aliveness Interrupt: Status: %d\n", hw->aliveness); | ||
| 959 | hw->recvd_aliveness = true; | ||
| 960 | if (waitqueue_active(&hw->wait_aliveness)) | ||
| 961 | wake_up(&hw->wait_aliveness); | ||
| 962 | } | ||
| 963 | |||
| 964 | |||
| 965 | /* Output Doorbell: | ||
| 966 | * Detection of SeC having sent output to host | ||
| 967 | */ | ||
| 968 | slots = mei_count_full_read_slots(dev); | ||
| 969 | if (test_and_clear_bit(TXE_INTR_OUT_DB_BIT, &hw->intr_cause)) { | ||
| 970 | /* Read from TXE */ | ||
| 971 | rets = mei_irq_read_handler(dev, &complete_list, &slots); | ||
| 972 | if (rets && dev->dev_state != MEI_DEV_RESETTING) { | ||
| 973 | dev_err(&dev->pdev->dev, | ||
| 974 | "mei_irq_read_handler ret = %d.\n", rets); | ||
| 975 | |||
| 976 | schedule_work(&dev->reset_work); | ||
| 977 | goto end; | ||
| 978 | } | ||
| 979 | } | ||
| 980 | /* Input Ready: Detection if host can write to SeC */ | ||
| 981 | if (test_and_clear_bit(TXE_INTR_IN_READY_BIT, &hw->intr_cause)) | ||
| 982 | dev->hbuf_is_ready = true; | ||
| 983 | |||
| 984 | if (hw->aliveness && dev->hbuf_is_ready) { | ||
| 985 | /* if SeC did not complete reading the written data by host */ | ||
| 986 | if (!mei_txe_is_input_ready(dev)) { | ||
| 987 | dev_dbg(&dev->pdev->dev, "got Input Ready Int, but SEC_IPC_INPUT_STATUS_RDY is 0.\n"); | ||
| 988 | goto end; | ||
| 989 | } | ||
| 990 | |||
| 991 | rets = mei_irq_write_handler(dev, &complete_list); | ||
| 992 | if (rets) | ||
| 993 | dev_err(&dev->pdev->dev, | ||
| 994 | "mei_irq_write_handler ret = %d.\n", rets); | ||
| 995 | } | ||
| 996 | |||
| 997 | |||
| 998 | |||
| 999 | mei_irq_compl_handler(dev, &complete_list); | ||
| 1000 | |||
| 1001 | end: | ||
| 1002 | dev_dbg(&dev->pdev->dev, "interrupt thread end ret = %d\n", rets); | ||
| 1003 | |||
| 1004 | mutex_unlock(&dev->device_lock); | ||
| 1005 | |||
| 1006 | mei_enable_interrupts(dev); | ||
| 1007 | return IRQ_HANDLED; | ||
| 1008 | } | ||
| 1009 | |||
| 1010 | static const struct mei_hw_ops mei_txe_hw_ops = { | ||
| 1011 | |||
| 1012 | .host_is_ready = mei_txe_host_is_ready, | ||
| 1013 | |||
| 1014 | .hw_is_ready = mei_txe_hw_is_ready, | ||
| 1015 | .hw_reset = mei_txe_hw_reset, | ||
| 1016 | .hw_config = mei_txe_hw_config, | ||
| 1017 | .hw_start = mei_txe_hw_start, | ||
| 1018 | |||
| 1019 | .intr_clear = mei_txe_intr_clear, | ||
| 1020 | .intr_enable = mei_txe_intr_enable, | ||
| 1021 | .intr_disable = mei_txe_intr_disable, | ||
| 1022 | |||
| 1023 | .hbuf_free_slots = mei_txe_hbuf_empty_slots, | ||
| 1024 | .hbuf_is_ready = mei_txe_is_input_ready, | ||
| 1025 | .hbuf_max_len = mei_txe_hbuf_max_len, | ||
| 1026 | |||
| 1027 | .write = mei_txe_write, | ||
| 1028 | |||
| 1029 | .rdbuf_full_slots = mei_txe_count_full_read_slots, | ||
| 1030 | .read_hdr = mei_txe_read_hdr, | ||
| 1031 | |||
| 1032 | .read = mei_txe_read, | ||
| 1033 | |||
| 1034 | }; | ||
| 1035 | |||
| 1036 | /** | ||
| 1037 | * mei_txe_dev_init - allocates and initializes txe hardware specific structure | ||
| 1038 | * | ||
| 1039 | * @pdev - pci device | ||
| 1040 | * returns struct mei_device * on success or NULL; | ||
| 1041 | * | ||
| 1042 | */ | ||
| 1043 | struct mei_device *mei_txe_dev_init(struct pci_dev *pdev) | ||
| 1044 | { | ||
| 1045 | struct mei_device *dev; | ||
| 1046 | struct mei_txe_hw *hw; | ||
| 1047 | |||
| 1048 | dev = kzalloc(sizeof(struct mei_device) + | ||
| 1049 | sizeof(struct mei_txe_hw), GFP_KERNEL); | ||
| 1050 | if (!dev) | ||
| 1051 | return NULL; | ||
| 1052 | |||
| 1053 | mei_device_init(dev); | ||
| 1054 | |||
| 1055 | hw = to_txe_hw(dev); | ||
| 1056 | |||
| 1057 | init_waitqueue_head(&hw->wait_aliveness); | ||
| 1058 | |||
| 1059 | dev->ops = &mei_txe_hw_ops; | ||
| 1060 | |||
| 1061 | dev->pdev = pdev; | ||
| 1062 | return dev; | ||
| 1063 | } | ||
| 1064 | |||
| 1065 | /** | ||
| 1066 | * mei_txe_setup_satt2 - SATT2 configuration for DMA support. | ||
| 1067 | * | ||
| 1068 | * @dev: the device structure | ||
| 1069 | * @addr: physical address start of the range | ||
| 1070 | * @range: physical range size | ||
| 1071 | */ | ||
| 1072 | int mei_txe_setup_satt2(struct mei_device *dev, phys_addr_t addr, u32 range) | ||
| 1073 | { | ||
| 1074 | struct mei_txe_hw *hw = to_txe_hw(dev); | ||
| 1075 | |||
| 1076 | u32 lo32 = lower_32_bits(addr); | ||
| 1077 | u32 hi32 = upper_32_bits(addr); | ||
| 1078 | u32 ctrl; | ||
| 1079 | |||
| 1080 | /* SATT is limited to 36 Bits */ | ||
| 1081 | if (hi32 & ~0xF) | ||
| 1082 | return -EINVAL; | ||
| 1083 | |||
| 1084 | /* SATT has to be 16Byte aligned */ | ||
| 1085 | if (lo32 & 0xF) | ||
| 1086 | return -EINVAL; | ||
| 1087 | |||
| 1088 | /* SATT range has to be 4Bytes aligned */ | ||
| 1089 | if (range & 0x4) | ||
| 1090 | return -EINVAL; | ||
| 1091 | |||
| 1092 | /* SATT is limited to 32 MB range*/ | ||
| 1093 | if (range > SATT_RANGE_MAX) | ||
| 1094 | return -EINVAL; | ||
| 1095 | |||
| 1096 | ctrl = SATT2_CTRL_VALID_MSK; | ||
| 1097 | ctrl |= hi32 << SATT2_CTRL_BR_BASE_ADDR_REG_SHIFT; | ||
| 1098 | |||
| 1099 | mei_txe_br_reg_write(hw, SATT2_SAP_SIZE_REG, range); | ||
| 1100 | mei_txe_br_reg_write(hw, SATT2_BRG_BA_LSB_REG, lo32); | ||
| 1101 | mei_txe_br_reg_write(hw, SATT2_CTRL_REG, ctrl); | ||
| 1102 | dev_dbg(&dev->pdev->dev, "SATT2: SAP_SIZE_OFFSET=0x%08X, BRG_BA_LSB_OFFSET=0x%08X, CTRL_OFFSET=0x%08X\n", | ||
| 1103 | range, lo32, ctrl); | ||
| 1104 | |||
| 1105 | return 0; | ||
| 1106 | } | ||
diff --git a/drivers/misc/mei/hw-txe.h b/drivers/misc/mei/hw-txe.h new file mode 100644 index 000000000000..857d88ccef61 --- /dev/null +++ b/drivers/misc/mei/hw-txe.h | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | /* | ||
| 2 | * | ||
| 3 | * Intel Management Engine Interface (Intel MEI) Linux driver | ||
| 4 | * Copyright (c) 2013-2014, Intel Corporation. | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify it | ||
| 7 | * under the terms and conditions of the GNU General Public License, | ||
| 8 | * version 2, as published by the Free Software Foundation. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 13 | * more details. | ||
| 14 | * | ||
| 15 | */ | ||
| 16 | |||
| 17 | #ifndef _MEI_HW_TXE_H_ | ||
| 18 | #define _MEI_HW_TXE_H_ | ||
| 19 | |||
| 20 | #include "hw.h" | ||
| 21 | #include "hw-txe-regs.h" | ||
| 22 | |||
| 23 | /* Flatten Hierarchy interrupt cause */ | ||
| 24 | #define TXE_INTR_READINESS_BIT 0 /* HISR_INT_0_STS */ | ||
| 25 | #define TXE_INTR_READINESS HISR_INT_0_STS | ||
| 26 | #define TXE_INTR_ALIVENESS_BIT 1 /* HISR_INT_1_STS */ | ||
| 27 | #define TXE_INTR_ALIVENESS HISR_INT_1_STS | ||
| 28 | #define TXE_INTR_OUT_DB_BIT 2 /* HISR_INT_2_STS */ | ||
| 29 | #define TXE_INTR_OUT_DB HISR_INT_2_STS | ||
| 30 | #define TXE_INTR_IN_READY_BIT 8 /* beyond HISR */ | ||
| 31 | #define TXE_INTR_IN_READY BIT(8) | ||
| 32 | |||
| 33 | /** | ||
| 34 | * struct mei_txe_hw - txe hardware specifics | ||
| 35 | * | ||
| 36 | * @mem_addr: SeC and BRIDGE bars | ||
| 37 | * @aliveness: aliveness (power gating) state of the hardware | ||
| 38 | * @readiness: readiness state of the hardware | ||
| 39 | * @wait_aliveness: aliveness wait queue | ||
| 40 | * @recvd_aliveness: aliveness interrupt was recived | ||
| 41 | * @intr_cause: translated interrupt cause | ||
| 42 | */ | ||
| 43 | struct mei_txe_hw { | ||
| 44 | void __iomem *mem_addr[NUM_OF_MEM_BARS]; | ||
| 45 | u32 aliveness; | ||
| 46 | u32 readiness; | ||
| 47 | |||
| 48 | wait_queue_head_t wait_aliveness; | ||
| 49 | bool recvd_aliveness; | ||
| 50 | |||
| 51 | unsigned long intr_cause; | ||
| 52 | }; | ||
| 53 | |||
| 54 | #define to_txe_hw(dev) (struct mei_txe_hw *)((dev)->hw) | ||
| 55 | |||
| 56 | static inline struct mei_device *hw_txe_to_mei(struct mei_txe_hw *hw) | ||
| 57 | { | ||
| 58 | return container_of((void *)hw, struct mei_device, hw); | ||
| 59 | } | ||
| 60 | |||
| 61 | struct mei_device *mei_txe_dev_init(struct pci_dev *pdev); | ||
| 62 | |||
| 63 | irqreturn_t mei_txe_irq_quick_handler(int irq, void *dev_id); | ||
| 64 | irqreturn_t mei_txe_irq_thread_handler(int irq, void *dev_id); | ||
| 65 | |||
| 66 | int mei_txe_aliveness_set_sync(struct mei_device *dev, u32 req); | ||
| 67 | |||
| 68 | int mei_txe_setup_satt2(struct mei_device *dev, phys_addr_t addr, u32 range); | ||
| 69 | |||
| 70 | |||
| 71 | #endif /* _MEI_HW_TXE_H_ */ | ||
diff --git a/drivers/misc/mei/hw.h b/drivers/misc/mei/hw.h index dd44e33ad2b6..e06779d4413e 100644 --- a/drivers/misc/mei/hw.h +++ b/drivers/misc/mei/hw.h | |||
| @@ -22,7 +22,7 @@ | |||
| 22 | /* | 22 | /* |
| 23 | * Timeouts in Seconds | 23 | * Timeouts in Seconds |
| 24 | */ | 24 | */ |
| 25 | #define MEI_INTEROP_TIMEOUT 7 /* Timeout on ready message */ | 25 | #define MEI_HW_READY_TIMEOUT 2 /* Timeout on ready message */ |
| 26 | #define MEI_CONNECT_TIMEOUT 3 /* HPS: at least 2 seconds */ | 26 | #define MEI_CONNECT_TIMEOUT 3 /* HPS: at least 2 seconds */ |
| 27 | 27 | ||
| 28 | #define MEI_CL_CONNECT_TIMEOUT 15 /* HPS: Client Connect Timeout */ | 28 | #define MEI_CL_CONNECT_TIMEOUT 15 /* HPS: Client Connect Timeout */ |
| @@ -31,13 +31,13 @@ | |||
| 31 | #define MEI_IAMTHIF_STALL_TIMER 12 /* HPS */ | 31 | #define MEI_IAMTHIF_STALL_TIMER 12 /* HPS */ |
| 32 | #define MEI_IAMTHIF_READ_TIMER 10 /* HPS */ | 32 | #define MEI_IAMTHIF_READ_TIMER 10 /* HPS */ |
| 33 | 33 | ||
| 34 | #define MEI_HBM_TIMEOUT 1 /* 1 second */ | ||
| 34 | 35 | ||
| 35 | /* | 36 | /* |
| 36 | * MEI Version | 37 | * MEI Version |
| 37 | */ | 38 | */ |
| 38 | #define HBM_MINOR_VERSION 0 | 39 | #define HBM_MINOR_VERSION 0 |
| 39 | #define HBM_MAJOR_VERSION 1 | 40 | #define HBM_MAJOR_VERSION 1 |
| 40 | #define HBM_TIMEOUT 1 /* 1 second */ | ||
| 41 | 41 | ||
| 42 | /* Host bus message command opcode */ | 42 | /* Host bus message command opcode */ |
| 43 | #define MEI_HBM_CMD_OP_MSK 0x7f | 43 | #define MEI_HBM_CMD_OP_MSK 0x7f |
diff --git a/drivers/misc/mei/init.c b/drivers/misc/mei/init.c index cdd31c2a2a2b..214dcef9750a 100644 --- a/drivers/misc/mei/init.c +++ b/drivers/misc/mei/init.c | |||
| @@ -116,7 +116,6 @@ int mei_reset(struct mei_device *dev) | |||
| 116 | mei_cl_unlink(&dev->wd_cl); | 116 | mei_cl_unlink(&dev->wd_cl); |
| 117 | mei_cl_unlink(&dev->iamthif_cl); | 117 | mei_cl_unlink(&dev->iamthif_cl); |
| 118 | mei_amthif_reset_params(dev); | 118 | mei_amthif_reset_params(dev); |
| 119 | memset(&dev->wr_ext_msg, 0, sizeof(dev->wr_ext_msg)); | ||
| 120 | } | 119 | } |
| 121 | 120 | ||
| 122 | 121 | ||
| @@ -126,7 +125,6 @@ int mei_reset(struct mei_device *dev) | |||
| 126 | 125 | ||
| 127 | if (ret) { | 126 | if (ret) { |
| 128 | dev_err(&dev->pdev->dev, "hw_reset failed ret = %d\n", ret); | 127 | dev_err(&dev->pdev->dev, "hw_reset failed ret = %d\n", ret); |
| 129 | dev->dev_state = MEI_DEV_DISABLED; | ||
| 130 | return ret; | 128 | return ret; |
| 131 | } | 129 | } |
| 132 | 130 | ||
| @@ -139,7 +137,6 @@ int mei_reset(struct mei_device *dev) | |||
| 139 | ret = mei_hw_start(dev); | 137 | ret = mei_hw_start(dev); |
| 140 | if (ret) { | 138 | if (ret) { |
| 141 | dev_err(&dev->pdev->dev, "hw_start failed ret = %d\n", ret); | 139 | dev_err(&dev->pdev->dev, "hw_start failed ret = %d\n", ret); |
| 142 | dev->dev_state = MEI_DEV_DISABLED; | ||
| 143 | return ret; | 140 | return ret; |
| 144 | } | 141 | } |
| 145 | 142 | ||
| @@ -149,7 +146,7 @@ int mei_reset(struct mei_device *dev) | |||
| 149 | ret = mei_hbm_start_req(dev); | 146 | ret = mei_hbm_start_req(dev); |
| 150 | if (ret) { | 147 | if (ret) { |
| 151 | dev_err(&dev->pdev->dev, "hbm_start failed ret = %d\n", ret); | 148 | dev_err(&dev->pdev->dev, "hbm_start failed ret = %d\n", ret); |
| 152 | dev->dev_state = MEI_DEV_DISABLED; | 149 | dev->dev_state = MEI_DEV_RESETTING; |
| 153 | return ret; | 150 | return ret; |
| 154 | } | 151 | } |
| 155 | 152 | ||
| @@ -166,6 +163,7 @@ EXPORT_SYMBOL_GPL(mei_reset); | |||
| 166 | */ | 163 | */ |
| 167 | int mei_start(struct mei_device *dev) | 164 | int mei_start(struct mei_device *dev) |
| 168 | { | 165 | { |
| 166 | int ret; | ||
| 169 | mutex_lock(&dev->device_lock); | 167 | mutex_lock(&dev->device_lock); |
| 170 | 168 | ||
| 171 | /* acknowledge interrupt and stop interrupts */ | 169 | /* acknowledge interrupt and stop interrupts */ |
| @@ -175,10 +173,18 @@ int mei_start(struct mei_device *dev) | |||
| 175 | 173 | ||
| 176 | dev_dbg(&dev->pdev->dev, "reset in start the mei device.\n"); | 174 | dev_dbg(&dev->pdev->dev, "reset in start the mei device.\n"); |
| 177 | 175 | ||
| 178 | dev->dev_state = MEI_DEV_INITIALIZING; | ||
| 179 | dev->reset_count = 0; | 176 | dev->reset_count = 0; |
| 180 | mei_reset(dev); | 177 | do { |
| 178 | dev->dev_state = MEI_DEV_INITIALIZING; | ||
| 179 | ret = mei_reset(dev); | ||
| 180 | |||
| 181 | if (ret == -ENODEV || dev->dev_state == MEI_DEV_DISABLED) { | ||
| 182 | dev_err(&dev->pdev->dev, "reset failed ret = %d", ret); | ||
| 183 | goto err; | ||
| 184 | } | ||
| 185 | } while (ret); | ||
| 181 | 186 | ||
| 187 | /* we cannot start the device w/o hbm start message completed */ | ||
| 182 | if (dev->dev_state == MEI_DEV_DISABLED) { | 188 | if (dev->dev_state == MEI_DEV_DISABLED) { |
| 183 | dev_err(&dev->pdev->dev, "reset failed"); | 189 | dev_err(&dev->pdev->dev, "reset failed"); |
| 184 | goto err; | 190 | goto err; |
| @@ -238,27 +244,40 @@ int mei_restart(struct mei_device *dev) | |||
| 238 | 244 | ||
| 239 | mutex_unlock(&dev->device_lock); | 245 | mutex_unlock(&dev->device_lock); |
| 240 | 246 | ||
| 241 | if (err || dev->dev_state == MEI_DEV_DISABLED) | 247 | if (err == -ENODEV || dev->dev_state == MEI_DEV_DISABLED) { |
| 248 | dev_err(&dev->pdev->dev, "device disabled = %d\n", err); | ||
| 242 | return -ENODEV; | 249 | return -ENODEV; |
| 250 | } | ||
| 251 | |||
| 252 | /* try to start again */ | ||
| 253 | if (err) | ||
| 254 | schedule_work(&dev->reset_work); | ||
| 255 | |||
| 243 | 256 | ||
| 244 | return 0; | 257 | return 0; |
| 245 | } | 258 | } |
| 246 | EXPORT_SYMBOL_GPL(mei_restart); | 259 | EXPORT_SYMBOL_GPL(mei_restart); |
| 247 | 260 | ||
| 248 | |||
| 249 | static void mei_reset_work(struct work_struct *work) | 261 | static void mei_reset_work(struct work_struct *work) |
| 250 | { | 262 | { |
| 251 | struct mei_device *dev = | 263 | struct mei_device *dev = |
| 252 | container_of(work, struct mei_device, reset_work); | 264 | container_of(work, struct mei_device, reset_work); |
| 265 | int ret; | ||
| 253 | 266 | ||
| 254 | mutex_lock(&dev->device_lock); | 267 | mutex_lock(&dev->device_lock); |
| 255 | 268 | ||
| 256 | mei_reset(dev); | 269 | ret = mei_reset(dev); |
| 257 | 270 | ||
| 258 | mutex_unlock(&dev->device_lock); | 271 | mutex_unlock(&dev->device_lock); |
| 259 | 272 | ||
| 260 | if (dev->dev_state == MEI_DEV_DISABLED) | 273 | if (dev->dev_state == MEI_DEV_DISABLED) { |
| 261 | dev_err(&dev->pdev->dev, "reset failed"); | 274 | dev_err(&dev->pdev->dev, "device disabled = %d\n", ret); |
| 275 | return; | ||
| 276 | } | ||
| 277 | |||
| 278 | /* retry reset in case of failure */ | ||
| 279 | if (ret) | ||
| 280 | schedule_work(&dev->reset_work); | ||
| 262 | } | 281 | } |
| 263 | 282 | ||
| 264 | void mei_stop(struct mei_device *dev) | 283 | void mei_stop(struct mei_device *dev) |
diff --git a/drivers/misc/mei/interrupt.c b/drivers/misc/mei/interrupt.c index f0fbb5179f80..75ff4092953e 100644 --- a/drivers/misc/mei/interrupt.c +++ b/drivers/misc/mei/interrupt.c | |||
| @@ -161,6 +161,41 @@ static int mei_cl_irq_read_msg(struct mei_device *dev, | |||
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | /** | 163 | /** |
| 164 | * mei_cl_irq_disconnect_rsp - send disconnection response message | ||
| 165 | * | ||
| 166 | * @cl: client | ||
| 167 | * @cb: callback block. | ||
| 168 | * @slots: free slots. | ||
| 169 | * @cmpl_list: complete list. | ||
| 170 | * | ||
| 171 | * returns 0, OK; otherwise, error. | ||
| 172 | */ | ||
| 173 | static int mei_cl_irq_disconnect_rsp(struct mei_cl *cl, struct mei_cl_cb *cb, | ||
| 174 | s32 *slots, struct mei_cl_cb *cmpl_list) | ||
| 175 | { | ||
| 176 | struct mei_device *dev = cl->dev; | ||
| 177 | int ret; | ||
| 178 | |||
| 179 | u32 msg_slots = | ||
| 180 | mei_data2slots(sizeof(struct hbm_client_connect_response)); | ||
| 181 | |||
| 182 | if (*slots < msg_slots) | ||
| 183 | return -EMSGSIZE; | ||
| 184 | |||
| 185 | *slots -= msg_slots; | ||
| 186 | |||
| 187 | ret = mei_hbm_cl_disconnect_rsp(dev, cl); | ||
| 188 | |||
| 189 | cl->state = MEI_FILE_DISCONNECTED; | ||
| 190 | cl->status = 0; | ||
| 191 | mei_io_cb_free(cb); | ||
| 192 | |||
| 193 | return ret; | ||
| 194 | } | ||
| 195 | |||
| 196 | |||
| 197 | |||
| 198 | /** | ||
| 164 | * mei_cl_irq_close - processes close related operation from | 199 | * mei_cl_irq_close - processes close related operation from |
| 165 | * interrupt thread context - send disconnect request | 200 | * interrupt thread context - send disconnect request |
| 166 | * | 201 | * |
| @@ -244,8 +279,7 @@ static int mei_cl_irq_read(struct mei_cl *cl, struct mei_cl_cb *cb, | |||
| 244 | 279 | ||
| 245 | 280 | ||
| 246 | /** | 281 | /** |
| 247 | * mei_cl_irq_ioctl - processes client ioctl related operation from the | 282 | * mei_cl_irq_connect - send connect request in irq_thread context |
| 248 | * interrupt thread context - send connection request | ||
| 249 | * | 283 | * |
| 250 | * @cl: client | 284 | * @cl: client |
| 251 | * @cb: callback block. | 285 | * @cb: callback block. |
| @@ -254,7 +288,7 @@ static int mei_cl_irq_read(struct mei_cl *cl, struct mei_cl_cb *cb, | |||
| 254 | * | 288 | * |
| 255 | * returns 0, OK; otherwise, error. | 289 | * returns 0, OK; otherwise, error. |
| 256 | */ | 290 | */ |
| 257 | static int mei_cl_irq_ioctl(struct mei_cl *cl, struct mei_cl_cb *cb, | 291 | static int mei_cl_irq_connect(struct mei_cl *cl, struct mei_cl_cb *cb, |
| 258 | s32 *slots, struct mei_cl_cb *cmpl_list) | 292 | s32 *slots, struct mei_cl_cb *cmpl_list) |
| 259 | { | 293 | { |
| 260 | struct mei_device *dev = cl->dev; | 294 | struct mei_device *dev = cl->dev; |
| @@ -263,6 +297,9 @@ static int mei_cl_irq_ioctl(struct mei_cl *cl, struct mei_cl_cb *cb, | |||
| 263 | u32 msg_slots = | 297 | u32 msg_slots = |
| 264 | mei_data2slots(sizeof(struct hbm_client_connect_request)); | 298 | mei_data2slots(sizeof(struct hbm_client_connect_request)); |
| 265 | 299 | ||
| 300 | if (mei_cl_is_other_connecting(cl)) | ||
| 301 | return 0; | ||
| 302 | |||
| 266 | if (*slots < msg_slots) { | 303 | if (*slots < msg_slots) { |
| 267 | /* return the cancel routine */ | 304 | /* return the cancel routine */ |
| 268 | list_del(&cb->list); | 305 | list_del(&cb->list); |
| @@ -450,12 +487,6 @@ int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list) | |||
| 450 | wake_up_interruptible(&dev->wait_stop_wd); | 487 | wake_up_interruptible(&dev->wait_stop_wd); |
| 451 | } | 488 | } |
| 452 | 489 | ||
| 453 | if (dev->wr_ext_msg.hdr.length) { | ||
| 454 | mei_write_message(dev, &dev->wr_ext_msg.hdr, | ||
| 455 | dev->wr_ext_msg.data); | ||
| 456 | slots -= mei_data2slots(dev->wr_ext_msg.hdr.length); | ||
| 457 | dev->wr_ext_msg.hdr.length = 0; | ||
| 458 | } | ||
| 459 | if (dev->dev_state == MEI_DEV_ENABLED) { | 490 | if (dev->dev_state == MEI_DEV_ENABLED) { |
| 460 | if (dev->wd_pending && | 491 | if (dev->wd_pending && |
| 461 | mei_cl_flow_ctrl_creds(&dev->wd_cl) > 0) { | 492 | mei_cl_flow_ctrl_creds(&dev->wd_cl) > 0) { |
| @@ -496,16 +527,18 @@ int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list) | |||
| 496 | return ret; | 527 | return ret; |
| 497 | 528 | ||
| 498 | break; | 529 | break; |
| 499 | case MEI_FOP_IOCTL: | 530 | case MEI_FOP_CONNECT: |
| 500 | /* connect message */ | 531 | /* connect message */ |
| 501 | if (mei_cl_is_other_connecting(cl)) | 532 | ret = mei_cl_irq_connect(cl, cb, &slots, cmpl_list); |
| 502 | continue; | ||
| 503 | ret = mei_cl_irq_ioctl(cl, cb, &slots, cmpl_list); | ||
| 504 | if (ret) | 533 | if (ret) |
| 505 | return ret; | 534 | return ret; |
| 506 | 535 | ||
| 507 | break; | 536 | break; |
| 508 | 537 | case MEI_FOP_DISCONNECT_RSP: | |
| 538 | /* send disconnect resp */ | ||
| 539 | ret = mei_cl_irq_disconnect_rsp(cl, cb, &slots, cmpl_list); | ||
| 540 | if (ret) | ||
| 541 | return ret; | ||
| 509 | default: | 542 | default: |
| 510 | BUG(); | 543 | BUG(); |
| 511 | } | 544 | } |
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h index f7de95b4cdd9..21e52496bc6e 100644 --- a/drivers/misc/mei/mei_dev.h +++ b/drivers/misc/mei/mei_dev.h | |||
| @@ -130,16 +130,18 @@ enum mei_wd_states { | |||
| 130 | 130 | ||
| 131 | /** | 131 | /** |
| 132 | * enum mei_cb_file_ops - file operation associated with the callback | 132 | * enum mei_cb_file_ops - file operation associated with the callback |
| 133 | * @MEI_FOP_READ - read | 133 | * @MEI_FOP_READ - read |
| 134 | * @MEI_FOP_WRITE - write | 134 | * @MEI_FOP_WRITE - write |
| 135 | * @MEI_FOP_IOCTL - ioctl | 135 | * @MEI_FOP_CONNECT - connect |
| 136 | * @MEI_FOP_OPEN - open | 136 | * @MEI_FOP_DISCONNECT_RSP - disconnect response |
| 137 | * @MEI_FOP_CLOSE - close | 137 | * @MEI_FOP_OPEN - open |
| 138 | * @MEI_FOP_CLOSE - close | ||
| 138 | */ | 139 | */ |
| 139 | enum mei_cb_file_ops { | 140 | enum mei_cb_file_ops { |
| 140 | MEI_FOP_READ = 0, | 141 | MEI_FOP_READ = 0, |
| 141 | MEI_FOP_WRITE, | 142 | MEI_FOP_WRITE, |
| 142 | MEI_FOP_IOCTL, | 143 | MEI_FOP_CONNECT, |
| 144 | MEI_FOP_DISCONNECT_RSP, | ||
| 143 | MEI_FOP_OPEN, | 145 | MEI_FOP_OPEN, |
| 144 | MEI_FOP_CLOSE | 146 | MEI_FOP_CLOSE |
| 145 | }; | 147 | }; |
| @@ -339,7 +341,6 @@ struct mei_cl_device { | |||
| 339 | * @hbuf_depth - depth of hardware host/write buffer is slots | 341 | * @hbuf_depth - depth of hardware host/write buffer is slots |
| 340 | * @hbuf_is_ready - query if the host host/write buffer is ready | 342 | * @hbuf_is_ready - query if the host host/write buffer is ready |
| 341 | * @wr_msg - the buffer for hbm control messages | 343 | * @wr_msg - the buffer for hbm control messages |
| 342 | * @wr_ext_msg - the buffer for hbm control responses (set in read cycle) | ||
| 343 | */ | 344 | */ |
| 344 | struct mei_device { | 345 | struct mei_device { |
| 345 | struct pci_dev *pdev; /* pointer to pci device struct */ | 346 | struct pci_dev *pdev; /* pointer to pci device struct */ |
| @@ -394,11 +395,6 @@ struct mei_device { | |||
| 394 | unsigned char data[128]; | 395 | unsigned char data[128]; |
| 395 | } wr_msg; | 396 | } wr_msg; |
| 396 | 397 | ||
| 397 | struct { | ||
| 398 | struct mei_msg_hdr hdr; | ||
| 399 | unsigned char data[4]; /* All HBM messages are 4 bytes */ | ||
| 400 | } wr_ext_msg; /* for control responses */ | ||
| 401 | |||
| 402 | struct hbm_version version; | 398 | struct hbm_version version; |
| 403 | 399 | ||
| 404 | struct mei_me_client *me_clients; /* Note: memory has to be allocated */ | 400 | struct mei_me_client *me_clients; /* Note: memory has to be allocated */ |
diff --git a/drivers/misc/mei/pci-me.c b/drivers/misc/mei/pci-me.c index ddadd08956f4..5434354cf1d5 100644 --- a/drivers/misc/mei/pci-me.c +++ b/drivers/misc/mei/pci-me.c | |||
| @@ -27,7 +27,6 @@ | |||
| 27 | #include <linux/aio.h> | 27 | #include <linux/aio.h> |
| 28 | #include <linux/pci.h> | 28 | #include <linux/pci.h> |
| 29 | #include <linux/poll.h> | 29 | #include <linux/poll.h> |
| 30 | #include <linux/init.h> | ||
| 31 | #include <linux/ioctl.h> | 30 | #include <linux/ioctl.h> |
| 32 | #include <linux/cdev.h> | 31 | #include <linux/cdev.h> |
| 33 | #include <linux/sched.h> | 32 | #include <linux/sched.h> |
diff --git a/drivers/misc/mei/pci-txe.c b/drivers/misc/mei/pci-txe.c new file mode 100644 index 000000000000..af4412cf2456 --- /dev/null +++ b/drivers/misc/mei/pci-txe.c | |||
| @@ -0,0 +1,293 @@ | |||
| 1 | /* | ||
| 2 | * | ||
| 3 | * Intel Management Engine Interface (Intel MEI) Linux driver | ||
| 4 | * Copyright (c) 2013-2014, Intel Corporation. | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify it | ||
| 7 | * under the terms and conditions of the GNU General Public License, | ||
| 8 | * version 2, as published by the Free Software Foundation. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 13 | * more details. | ||
| 14 | * | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/kernel.h> | ||
| 19 | #include <linux/device.h> | ||
| 20 | #include <linux/fs.h> | ||
| 21 | #include <linux/errno.h> | ||
| 22 | #include <linux/types.h> | ||
| 23 | #include <linux/pci.h> | ||
| 24 | #include <linux/init.h> | ||
| 25 | #include <linux/sched.h> | ||
| 26 | #include <linux/uuid.h> | ||
| 27 | #include <linux/jiffies.h> | ||
| 28 | #include <linux/interrupt.h> | ||
| 29 | #include <linux/workqueue.h> | ||
| 30 | |||
| 31 | #include <linux/mei.h> | ||
| 32 | |||
| 33 | |||
| 34 | #include "mei_dev.h" | ||
| 35 | #include "hw-txe.h" | ||
| 36 | |||
| 37 | static DEFINE_PCI_DEVICE_TABLE(mei_txe_pci_tbl) = { | ||
| 38 | {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0F18)}, /* Baytrail */ | ||
| 39 | {0, } | ||
| 40 | }; | ||
| 41 | MODULE_DEVICE_TABLE(pci, mei_txe_pci_tbl); | ||
| 42 | |||
| 43 | |||
| 44 | static void mei_txe_pci_iounmap(struct pci_dev *pdev, struct mei_txe_hw *hw) | ||
| 45 | { | ||
| 46 | int i; | ||
| 47 | for (i = SEC_BAR; i < NUM_OF_MEM_BARS; i++) { | ||
| 48 | if (hw->mem_addr[i]) { | ||
| 49 | pci_iounmap(pdev, hw->mem_addr[i]); | ||
| 50 | hw->mem_addr[i] = NULL; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | } | ||
| 54 | /** | ||
| 55 | * mei_probe - Device Initialization Routine | ||
| 56 | * | ||
| 57 | * @pdev: PCI device structure | ||
| 58 | * @ent: entry in mei_txe_pci_tbl | ||
| 59 | * | ||
| 60 | * returns 0 on success, <0 on failure. | ||
| 61 | */ | ||
| 62 | static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | ||
| 63 | { | ||
| 64 | struct mei_device *dev; | ||
| 65 | struct mei_txe_hw *hw; | ||
| 66 | int err; | ||
| 67 | int i; | ||
| 68 | |||
| 69 | /* enable pci dev */ | ||
| 70 | err = pci_enable_device(pdev); | ||
| 71 | if (err) { | ||
| 72 | dev_err(&pdev->dev, "failed to enable pci device.\n"); | ||
| 73 | goto end; | ||
| 74 | } | ||
| 75 | /* set PCI host mastering */ | ||
| 76 | pci_set_master(pdev); | ||
| 77 | /* pci request regions for mei driver */ | ||
| 78 | err = pci_request_regions(pdev, KBUILD_MODNAME); | ||
| 79 | if (err) { | ||
| 80 | dev_err(&pdev->dev, "failed to get pci regions.\n"); | ||
| 81 | goto disable_device; | ||
| 82 | } | ||
| 83 | |||
| 84 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36)); | ||
| 85 | if (err) { | ||
| 86 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); | ||
| 87 | if (err) { | ||
| 88 | dev_err(&pdev->dev, "No suitable DMA available.\n"); | ||
| 89 | goto release_regions; | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | /* allocates and initializes the mei dev structure */ | ||
| 94 | dev = mei_txe_dev_init(pdev); | ||
| 95 | if (!dev) { | ||
| 96 | err = -ENOMEM; | ||
| 97 | goto release_regions; | ||
| 98 | } | ||
| 99 | hw = to_txe_hw(dev); | ||
| 100 | |||
| 101 | /* mapping IO device memory */ | ||
| 102 | for (i = SEC_BAR; i < NUM_OF_MEM_BARS; i++) { | ||
| 103 | hw->mem_addr[i] = pci_iomap(pdev, i, 0); | ||
| 104 | if (!hw->mem_addr[i]) { | ||
| 105 | dev_err(&pdev->dev, "mapping I/O device memory failure.\n"); | ||
| 106 | err = -ENOMEM; | ||
| 107 | goto free_device; | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | |||
| 112 | pci_enable_msi(pdev); | ||
| 113 | |||
| 114 | /* clear spurious interrupts */ | ||
| 115 | mei_clear_interrupts(dev); | ||
| 116 | |||
| 117 | /* request and enable interrupt */ | ||
| 118 | if (pci_dev_msi_enabled(pdev)) | ||
| 119 | err = request_threaded_irq(pdev->irq, | ||
| 120 | NULL, | ||
| 121 | mei_txe_irq_thread_handler, | ||
| 122 | IRQF_ONESHOT, KBUILD_MODNAME, dev); | ||
| 123 | else | ||
| 124 | err = request_threaded_irq(pdev->irq, | ||
| 125 | mei_txe_irq_quick_handler, | ||
| 126 | mei_txe_irq_thread_handler, | ||
| 127 | IRQF_SHARED, KBUILD_MODNAME, dev); | ||
| 128 | if (err) { | ||
| 129 | dev_err(&pdev->dev, "mei: request_threaded_irq failure. irq = %d\n", | ||
| 130 | pdev->irq); | ||
| 131 | goto free_device; | ||
| 132 | } | ||
| 133 | |||
| 134 | if (mei_start(dev)) { | ||
| 135 | dev_err(&pdev->dev, "init hw failure.\n"); | ||
| 136 | err = -ENODEV; | ||
| 137 | goto release_irq; | ||
| 138 | } | ||
| 139 | |||
| 140 | err = mei_register(dev); | ||
| 141 | if (err) | ||
| 142 | goto release_irq; | ||
| 143 | |||
| 144 | pci_set_drvdata(pdev, dev); | ||
| 145 | |||
| 146 | return 0; | ||
| 147 | |||
| 148 | release_irq: | ||
| 149 | |||
| 150 | mei_cancel_work(dev); | ||
| 151 | |||
| 152 | /* disable interrupts */ | ||
| 153 | mei_disable_interrupts(dev); | ||
| 154 | |||
| 155 | free_irq(pdev->irq, dev); | ||
| 156 | pci_disable_msi(pdev); | ||
| 157 | |||
| 158 | free_device: | ||
| 159 | mei_txe_pci_iounmap(pdev, hw); | ||
| 160 | |||
| 161 | kfree(dev); | ||
| 162 | release_regions: | ||
| 163 | pci_release_regions(pdev); | ||
| 164 | disable_device: | ||
| 165 | pci_disable_device(pdev); | ||
| 166 | end: | ||
| 167 | dev_err(&pdev->dev, "initialization failed.\n"); | ||
| 168 | return err; | ||
| 169 | } | ||
| 170 | |||
| 171 | /** | ||
| 172 | * mei_remove - Device Removal Routine | ||
| 173 | * | ||
| 174 | * @pdev: PCI device structure | ||
| 175 | * | ||
| 176 | * mei_remove is called by the PCI subsystem to alert the driver | ||
| 177 | * that it should release a PCI device. | ||
| 178 | */ | ||
| 179 | static void mei_txe_remove(struct pci_dev *pdev) | ||
| 180 | { | ||
| 181 | struct mei_device *dev; | ||
| 182 | struct mei_txe_hw *hw; | ||
| 183 | |||
| 184 | dev = pci_get_drvdata(pdev); | ||
| 185 | if (!dev) { | ||
| 186 | dev_err(&pdev->dev, "mei: dev =NULL\n"); | ||
| 187 | return; | ||
| 188 | } | ||
| 189 | |||
| 190 | hw = to_txe_hw(dev); | ||
| 191 | |||
| 192 | mei_stop(dev); | ||
| 193 | |||
| 194 | /* disable interrupts */ | ||
| 195 | mei_disable_interrupts(dev); | ||
| 196 | free_irq(pdev->irq, dev); | ||
| 197 | pci_disable_msi(pdev); | ||
| 198 | |||
| 199 | pci_set_drvdata(pdev, NULL); | ||
| 200 | |||
| 201 | mei_txe_pci_iounmap(pdev, hw); | ||
| 202 | |||
| 203 | mei_deregister(dev); | ||
| 204 | |||
| 205 | kfree(dev); | ||
| 206 | |||
| 207 | pci_release_regions(pdev); | ||
| 208 | pci_disable_device(pdev); | ||
| 209 | } | ||
| 210 | |||
| 211 | |||
| 212 | #ifdef CONFIG_PM | ||
| 213 | static int mei_txe_pci_suspend(struct device *device) | ||
| 214 | { | ||
| 215 | struct pci_dev *pdev = to_pci_dev(device); | ||
| 216 | struct mei_device *dev = pci_get_drvdata(pdev); | ||
| 217 | |||
| 218 | if (!dev) | ||
| 219 | return -ENODEV; | ||
| 220 | |||
| 221 | dev_dbg(&pdev->dev, "suspend\n"); | ||
| 222 | |||
| 223 | mei_stop(dev); | ||
| 224 | |||
| 225 | mei_disable_interrupts(dev); | ||
| 226 | |||
| 227 | free_irq(pdev->irq, dev); | ||
| 228 | pci_disable_msi(pdev); | ||
| 229 | |||
| 230 | return 0; | ||
| 231 | } | ||
| 232 | |||
| 233 | static int mei_txe_pci_resume(struct device *device) | ||
| 234 | { | ||
| 235 | struct pci_dev *pdev = to_pci_dev(device); | ||
| 236 | struct mei_device *dev; | ||
| 237 | int err; | ||
| 238 | |||
| 239 | dev = pci_get_drvdata(pdev); | ||
| 240 | if (!dev) | ||
| 241 | return -ENODEV; | ||
| 242 | |||
| 243 | pci_enable_msi(pdev); | ||
| 244 | |||
| 245 | mei_clear_interrupts(dev); | ||
| 246 | |||
| 247 | /* request and enable interrupt */ | ||
| 248 | if (pci_dev_msi_enabled(pdev)) | ||
| 249 | err = request_threaded_irq(pdev->irq, | ||
| 250 | NULL, | ||
| 251 | mei_txe_irq_thread_handler, | ||
| 252 | IRQF_ONESHOT, KBUILD_MODNAME, dev); | ||
| 253 | else | ||
| 254 | err = request_threaded_irq(pdev->irq, | ||
| 255 | mei_txe_irq_quick_handler, | ||
| 256 | mei_txe_irq_thread_handler, | ||
| 257 | IRQF_SHARED, KBUILD_MODNAME, dev); | ||
| 258 | if (err) { | ||
| 259 | dev_err(&pdev->dev, "request_threaded_irq failed: irq = %d.\n", | ||
| 260 | pdev->irq); | ||
| 261 | return err; | ||
| 262 | } | ||
| 263 | |||
| 264 | err = mei_restart(dev); | ||
| 265 | |||
| 266 | return err; | ||
| 267 | } | ||
| 268 | |||
| 269 | static SIMPLE_DEV_PM_OPS(mei_txe_pm_ops, | ||
| 270 | mei_txe_pci_suspend, | ||
| 271 | mei_txe_pci_resume); | ||
| 272 | |||
| 273 | #define MEI_TXE_PM_OPS (&mei_txe_pm_ops) | ||
| 274 | #else | ||
| 275 | #define MEI_TXE_PM_OPS NULL | ||
| 276 | #endif /* CONFIG_PM */ | ||
| 277 | /* | ||
| 278 | * PCI driver structure | ||
| 279 | */ | ||
| 280 | static struct pci_driver mei_txe_driver = { | ||
| 281 | .name = KBUILD_MODNAME, | ||
| 282 | .id_table = mei_txe_pci_tbl, | ||
| 283 | .probe = mei_txe_probe, | ||
| 284 | .remove = mei_txe_remove, | ||
| 285 | .shutdown = mei_txe_remove, | ||
| 286 | .driver.pm = MEI_TXE_PM_OPS, | ||
| 287 | }; | ||
| 288 | |||
| 289 | module_pci_driver(mei_txe_driver); | ||
| 290 | |||
| 291 | MODULE_AUTHOR("Intel Corporation"); | ||
| 292 | MODULE_DESCRIPTION("Intel(R) Trusted Execution Environment Interface"); | ||
| 293 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c index afe66571ce0b..e3e421d97ad4 100644 --- a/drivers/misc/sram.c +++ b/drivers/misc/sram.c | |||
| @@ -87,8 +87,6 @@ static int sram_remove(struct platform_device *pdev) | |||
| 87 | if (gen_pool_avail(sram->pool) < gen_pool_size(sram->pool)) | 87 | if (gen_pool_avail(sram->pool) < gen_pool_size(sram->pool)) |
| 88 | dev_dbg(&pdev->dev, "removed while SRAM allocated\n"); | 88 | dev_dbg(&pdev->dev, "removed while SRAM allocated\n"); |
| 89 | 89 | ||
| 90 | gen_pool_destroy(sram->pool); | ||
| 91 | |||
| 92 | if (sram->clk) | 90 | if (sram->clk) |
| 93 | clk_disable_unprepare(sram->clk); | 91 | clk_disable_unprepare(sram->clk); |
| 94 | 92 | ||
diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c index 3aed525e55b4..1972d57aadb3 100644 --- a/drivers/misc/ti-st/st_core.c +++ b/drivers/misc/ti-st/st_core.c | |||
| @@ -22,7 +22,6 @@ | |||
| 22 | #define pr_fmt(fmt) "(stc): " fmt | 22 | #define pr_fmt(fmt) "(stc): " fmt |
| 23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
| 24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
| 25 | #include <linux/init.h> | ||
| 26 | #include <linux/tty.h> | 25 | #include <linux/tty.h> |
| 27 | 26 | ||
| 28 | #include <linux/seq_file.h> | 27 | #include <linux/seq_file.h> |
diff --git a/drivers/misc/ti_dac7512.c b/drivers/misc/ti_dac7512.c index 83da711ce9f1..cb0289b44a17 100644 --- a/drivers/misc/ti_dac7512.c +++ b/drivers/misc/ti_dac7512.c | |||
| @@ -20,7 +20,6 @@ | |||
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | #include <linux/module.h> | 22 | #include <linux/module.h> |
| 23 | #include <linux/init.h> | ||
| 24 | #include <linux/spi/spi.h> | 23 | #include <linux/spi/spi.h> |
| 25 | #include <linux/of.h> | 24 | #include <linux/of.h> |
| 26 | 25 | ||
diff --git a/drivers/misc/tsl2550.c b/drivers/misc/tsl2550.c index 5bc10fa193de..b00335652e52 100644 --- a/drivers/misc/tsl2550.c +++ b/drivers/misc/tsl2550.c | |||
| @@ -20,7 +20,6 @@ | |||
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | #include <linux/module.h> | 22 | #include <linux/module.h> |
| 23 | #include <linux/init.h> | ||
| 24 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
| 25 | #include <linux/i2c.h> | 24 | #include <linux/i2c.h> |
| 26 | #include <linux/mutex.h> | 25 | #include <linux/mutex.h> |
diff --git a/drivers/spmi/Kconfig b/drivers/spmi/Kconfig new file mode 100644 index 000000000000..075bd79e1ac4 --- /dev/null +++ b/drivers/spmi/Kconfig | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | # | ||
| 2 | # SPMI driver configuration | ||
| 3 | # | ||
| 4 | menuconfig SPMI | ||
| 5 | tristate "SPMI support" | ||
| 6 | help | ||
| 7 | SPMI (System Power Management Interface) is a two-wire | ||
| 8 | serial interface between baseband and application processors | ||
| 9 | and Power Management Integrated Circuits (PMIC). | ||
| 10 | |||
| 11 | if SPMI | ||
| 12 | |||
| 13 | config SPMI_MSM_PMIC_ARB | ||
| 14 | tristate "Qualcomm MSM SPMI Controller (PMIC Arbiter)" | ||
| 15 | depends on ARM | ||
| 16 | depends on IRQ_DOMAIN | ||
| 17 | depends on ARCH_MSM || COMPILE_TEST | ||
| 18 | default ARCH_MSM | ||
| 19 | help | ||
| 20 | If you say yes to this option, support will be included for the | ||
| 21 | built-in SPMI PMIC Arbiter interface on Qualcomm MSM family | ||
| 22 | processors. | ||
| 23 | |||
| 24 | This is required for communicating with Qualcomm PMICs and | ||
| 25 | other devices that have the SPMI interface. | ||
| 26 | |||
| 27 | endif | ||
diff --git a/drivers/spmi/Makefile b/drivers/spmi/Makefile new file mode 100644 index 000000000000..fc75104a5aab --- /dev/null +++ b/drivers/spmi/Makefile | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | # | ||
| 2 | # Makefile for kernel SPMI framework. | ||
| 3 | # | ||
| 4 | obj-$(CONFIG_SPMI) += spmi.o | ||
| 5 | |||
| 6 | obj-$(CONFIG_SPMI_MSM_PMIC_ARB) += spmi-pmic-arb.o | ||
diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c new file mode 100644 index 000000000000..246e03a18c94 --- /dev/null +++ b/drivers/spmi/spmi-pmic-arb.c | |||
| @@ -0,0 +1,778 @@ | |||
| 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. | ||
| 2 | * | ||
| 3 | * This program is free software; you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License version 2 and | ||
| 5 | * only version 2 as published by the Free Software Foundation. | ||
| 6 | * | ||
| 7 | * This program is distributed in the hope that it will be useful, | ||
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 10 | * GNU General Public License for more details. | ||
| 11 | */ | ||
| 12 | #include <linux/delay.h> | ||
| 13 | #include <linux/err.h> | ||
| 14 | #include <linux/interrupt.h> | ||
| 15 | #include <linux/io.h> | ||
| 16 | #include <linux/irqchip/chained_irq.h> | ||
| 17 | #include <linux/irqdomain.h> | ||
| 18 | #include <linux/irq.h> | ||
| 19 | #include <linux/kernel.h> | ||
| 20 | #include <linux/module.h> | ||
| 21 | #include <linux/of.h> | ||
| 22 | #include <linux/platform_device.h> | ||
| 23 | #include <linux/slab.h> | ||
| 24 | #include <linux/spmi.h> | ||
| 25 | |||
| 26 | /* PMIC Arbiter configuration registers */ | ||
| 27 | #define PMIC_ARB_VERSION 0x0000 | ||
| 28 | #define PMIC_ARB_INT_EN 0x0004 | ||
| 29 | |||
| 30 | /* PMIC Arbiter channel registers */ | ||
| 31 | #define PMIC_ARB_CMD(N) (0x0800 + (0x80 * (N))) | ||
| 32 | #define PMIC_ARB_CONFIG(N) (0x0804 + (0x80 * (N))) | ||
| 33 | #define PMIC_ARB_STATUS(N) (0x0808 + (0x80 * (N))) | ||
| 34 | #define PMIC_ARB_WDATA0(N) (0x0810 + (0x80 * (N))) | ||
| 35 | #define PMIC_ARB_WDATA1(N) (0x0814 + (0x80 * (N))) | ||
| 36 | #define PMIC_ARB_RDATA0(N) (0x0818 + (0x80 * (N))) | ||
| 37 | #define PMIC_ARB_RDATA1(N) (0x081C + (0x80 * (N))) | ||
| 38 | |||
| 39 | /* Interrupt Controller */ | ||
| 40 | #define SPMI_PIC_OWNER_ACC_STATUS(M, N) (0x0000 + ((32 * (M)) + (4 * (N)))) | ||
| 41 | #define SPMI_PIC_ACC_ENABLE(N) (0x0200 + (4 * (N))) | ||
| 42 | #define SPMI_PIC_IRQ_STATUS(N) (0x0600 + (4 * (N))) | ||
| 43 | #define SPMI_PIC_IRQ_CLEAR(N) (0x0A00 + (4 * (N))) | ||
| 44 | |||
| 45 | /* Mapping Table */ | ||
| 46 | #define SPMI_MAPPING_TABLE_REG(N) (0x0B00 + (4 * (N))) | ||
| 47 | #define SPMI_MAPPING_BIT_INDEX(X) (((X) >> 18) & 0xF) | ||
| 48 | #define SPMI_MAPPING_BIT_IS_0_FLAG(X) (((X) >> 17) & 0x1) | ||
| 49 | #define SPMI_MAPPING_BIT_IS_0_RESULT(X) (((X) >> 9) & 0xFF) | ||
| 50 | #define SPMI_MAPPING_BIT_IS_1_FLAG(X) (((X) >> 8) & 0x1) | ||
| 51 | #define SPMI_MAPPING_BIT_IS_1_RESULT(X) (((X) >> 0) & 0xFF) | ||
| 52 | |||
| 53 | #define SPMI_MAPPING_TABLE_LEN 255 | ||
| 54 | #define SPMI_MAPPING_TABLE_TREE_DEPTH 16 /* Maximum of 16-bits */ | ||
| 55 | |||
| 56 | /* Ownership Table */ | ||
| 57 | #define SPMI_OWNERSHIP_TABLE_REG(N) (0x0700 + (4 * (N))) | ||
| 58 | #define SPMI_OWNERSHIP_PERIPH2OWNER(X) ((X) & 0x7) | ||
| 59 | |||
| 60 | /* Channel Status fields */ | ||
| 61 | enum pmic_arb_chnl_status { | ||
| 62 | PMIC_ARB_STATUS_DONE = (1 << 0), | ||
| 63 | PMIC_ARB_STATUS_FAILURE = (1 << 1), | ||
| 64 | PMIC_ARB_STATUS_DENIED = (1 << 2), | ||
| 65 | PMIC_ARB_STATUS_DROPPED = (1 << 3), | ||
| 66 | }; | ||
| 67 | |||
| 68 | /* Command register fields */ | ||
| 69 | #define PMIC_ARB_CMD_MAX_BYTE_COUNT 8 | ||
| 70 | |||
| 71 | /* Command Opcodes */ | ||
| 72 | enum pmic_arb_cmd_op_code { | ||
| 73 | PMIC_ARB_OP_EXT_WRITEL = 0, | ||
| 74 | PMIC_ARB_OP_EXT_READL = 1, | ||
| 75 | PMIC_ARB_OP_EXT_WRITE = 2, | ||
| 76 | PMIC_ARB_OP_RESET = 3, | ||
| 77 | PMIC_ARB_OP_SLEEP = 4, | ||
| 78 | PMIC_ARB_OP_SHUTDOWN = 5, | ||
| 79 | PMIC_ARB_OP_WAKEUP = 6, | ||
| 80 | PMIC_ARB_OP_AUTHENTICATE = 7, | ||
| 81 | PMIC_ARB_OP_MSTR_READ = 8, | ||
| 82 | PMIC_ARB_OP_MSTR_WRITE = 9, | ||
| 83 | PMIC_ARB_OP_EXT_READ = 13, | ||
| 84 | PMIC_ARB_OP_WRITE = 14, | ||
| 85 | PMIC_ARB_OP_READ = 15, | ||
| 86 | PMIC_ARB_OP_ZERO_WRITE = 16, | ||
| 87 | }; | ||
| 88 | |||
| 89 | /* Maximum number of support PMIC peripherals */ | ||
| 90 | #define PMIC_ARB_MAX_PERIPHS 256 | ||
| 91 | #define PMIC_ARB_PERIPH_ID_VALID (1 << 15) | ||
| 92 | #define PMIC_ARB_TIMEOUT_US 100 | ||
| 93 | #define PMIC_ARB_MAX_TRANS_BYTES (8) | ||
| 94 | |||
| 95 | #define PMIC_ARB_APID_MASK 0xFF | ||
| 96 | #define PMIC_ARB_PPID_MASK 0xFFF | ||
| 97 | |||
| 98 | /* interrupt enable bit */ | ||
| 99 | #define SPMI_PIC_ACC_ENABLE_BIT BIT(0) | ||
| 100 | |||
| 101 | /** | ||
| 102 | * spmi_pmic_arb_dev - SPMI PMIC Arbiter object | ||
| 103 | * | ||
| 104 | * @base: address of the PMIC Arbiter core registers. | ||
| 105 | * @intr: address of the SPMI interrupt control registers. | ||
| 106 | * @cnfg: address of the PMIC Arbiter configuration registers. | ||
| 107 | * @lock: lock to synchronize accesses. | ||
| 108 | * @channel: which channel to use for accesses. | ||
| 109 | * @irq: PMIC ARB interrupt. | ||
| 110 | * @ee: the current Execution Environment | ||
| 111 | * @min_apid: minimum APID (used for bounding IRQ search) | ||
| 112 | * @max_apid: maximum APID | ||
| 113 | * @mapping_table: in-memory copy of PPID -> APID mapping table. | ||
| 114 | * @domain: irq domain object for PMIC IRQ domain | ||
| 115 | * @spmic: SPMI controller object | ||
| 116 | * @apid_to_ppid: cached mapping from APID to PPID | ||
| 117 | */ | ||
| 118 | struct spmi_pmic_arb_dev { | ||
| 119 | void __iomem *base; | ||
| 120 | void __iomem *intr; | ||
| 121 | void __iomem *cnfg; | ||
| 122 | raw_spinlock_t lock; | ||
| 123 | u8 channel; | ||
| 124 | int irq; | ||
| 125 | u8 ee; | ||
| 126 | u8 min_apid; | ||
| 127 | u8 max_apid; | ||
| 128 | u32 mapping_table[SPMI_MAPPING_TABLE_LEN]; | ||
| 129 | struct irq_domain *domain; | ||
| 130 | struct spmi_controller *spmic; | ||
| 131 | u16 apid_to_ppid[256]; | ||
| 132 | }; | ||
| 133 | |||
| 134 | static inline u32 pmic_arb_base_read(struct spmi_pmic_arb_dev *dev, u32 offset) | ||
| 135 | { | ||
| 136 | return readl_relaxed(dev->base + offset); | ||
| 137 | } | ||
| 138 | |||
| 139 | static inline void pmic_arb_base_write(struct spmi_pmic_arb_dev *dev, | ||
| 140 | u32 offset, u32 val) | ||
| 141 | { | ||
| 142 | writel_relaxed(val, dev->base + offset); | ||
| 143 | } | ||
| 144 | |||
| 145 | /** | ||
| 146 | * pa_read_data: reads pmic-arb's register and copy 1..4 bytes to buf | ||
| 147 | * @bc: byte count -1. range: 0..3 | ||
| 148 | * @reg: register's address | ||
| 149 | * @buf: output parameter, length must be bc + 1 | ||
| 150 | */ | ||
| 151 | static void pa_read_data(struct spmi_pmic_arb_dev *dev, u8 *buf, u32 reg, u8 bc) | ||
| 152 | { | ||
| 153 | u32 data = pmic_arb_base_read(dev, reg); | ||
| 154 | memcpy(buf, &data, (bc & 3) + 1); | ||
| 155 | } | ||
| 156 | |||
| 157 | /** | ||
| 158 | * pa_write_data: write 1..4 bytes from buf to pmic-arb's register | ||
| 159 | * @bc: byte-count -1. range: 0..3. | ||
| 160 | * @reg: register's address. | ||
| 161 | * @buf: buffer to write. length must be bc + 1. | ||
| 162 | */ | ||
| 163 | static void | ||
| 164 | pa_write_data(struct spmi_pmic_arb_dev *dev, const u8 *buf, u32 reg, u8 bc) | ||
| 165 | { | ||
| 166 | u32 data = 0; | ||
| 167 | memcpy(&data, buf, (bc & 3) + 1); | ||
| 168 | pmic_arb_base_write(dev, reg, data); | ||
| 169 | } | ||
| 170 | |||
| 171 | static int pmic_arb_wait_for_done(struct spmi_controller *ctrl) | ||
| 172 | { | ||
| 173 | struct spmi_pmic_arb_dev *dev = spmi_controller_get_drvdata(ctrl); | ||
| 174 | u32 status = 0; | ||
| 175 | u32 timeout = PMIC_ARB_TIMEOUT_US; | ||
| 176 | u32 offset = PMIC_ARB_STATUS(dev->channel); | ||
| 177 | |||
| 178 | while (timeout--) { | ||
| 179 | status = pmic_arb_base_read(dev, offset); | ||
| 180 | |||
| 181 | if (status & PMIC_ARB_STATUS_DONE) { | ||
| 182 | if (status & PMIC_ARB_STATUS_DENIED) { | ||
| 183 | dev_err(&ctrl->dev, | ||
| 184 | "%s: transaction denied (0x%x)\n", | ||
| 185 | __func__, status); | ||
| 186 | return -EPERM; | ||
| 187 | } | ||
| 188 | |||
| 189 | if (status & PMIC_ARB_STATUS_FAILURE) { | ||
| 190 | dev_err(&ctrl->dev, | ||
| 191 | "%s: transaction failed (0x%x)\n", | ||
| 192 | __func__, status); | ||
| 193 | return -EIO; | ||
| 194 | } | ||
| 195 | |||
| 196 | if (status & PMIC_ARB_STATUS_DROPPED) { | ||
| 197 | dev_err(&ctrl->dev, | ||
| 198 | "%s: transaction dropped (0x%x)\n", | ||
| 199 | __func__, status); | ||
| 200 | return -EIO; | ||
| 201 | } | ||
| 202 | |||
| 203 | return 0; | ||
| 204 | } | ||
| 205 | udelay(1); | ||
| 206 | } | ||
| 207 | |||
| 208 | dev_err(&ctrl->dev, | ||
| 209 | "%s: timeout, status 0x%x\n", | ||
| 210 | __func__, status); | ||
| 211 | return -ETIMEDOUT; | ||
| 212 | } | ||
| 213 | |||
| 214 | /* Non-data command */ | ||
| 215 | static int pmic_arb_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid) | ||
| 216 | { | ||
| 217 | struct spmi_pmic_arb_dev *pmic_arb = spmi_controller_get_drvdata(ctrl); | ||
| 218 | unsigned long flags; | ||
| 219 | u32 cmd; | ||
| 220 | int rc; | ||
| 221 | |||
| 222 | /* Check for valid non-data command */ | ||
| 223 | if (opc < SPMI_CMD_RESET || opc > SPMI_CMD_WAKEUP) | ||
| 224 | return -EINVAL; | ||
| 225 | |||
| 226 | cmd = ((opc | 0x40) << 27) | ((sid & 0xf) << 20); | ||
| 227 | |||
| 228 | raw_spin_lock_irqsave(&pmic_arb->lock, flags); | ||
| 229 | pmic_arb_base_write(pmic_arb, PMIC_ARB_CMD(pmic_arb->channel), cmd); | ||
| 230 | rc = pmic_arb_wait_for_done(ctrl); | ||
| 231 | raw_spin_unlock_irqrestore(&pmic_arb->lock, flags); | ||
| 232 | |||
| 233 | return rc; | ||
| 234 | } | ||
| 235 | |||
| 236 | static int pmic_arb_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid, | ||
| 237 | u16 addr, u8 *buf, size_t len) | ||
| 238 | { | ||
| 239 | struct spmi_pmic_arb_dev *pmic_arb = spmi_controller_get_drvdata(ctrl); | ||
| 240 | unsigned long flags; | ||
| 241 | u8 bc = len - 1; | ||
| 242 | u32 cmd; | ||
| 243 | int rc; | ||
| 244 | |||
| 245 | if (bc >= PMIC_ARB_MAX_TRANS_BYTES) { | ||
| 246 | dev_err(&ctrl->dev, | ||
| 247 | "pmic-arb supports 1..%d bytes per trans, but %d requested", | ||
| 248 | PMIC_ARB_MAX_TRANS_BYTES, len); | ||
| 249 | return -EINVAL; | ||
| 250 | } | ||
| 251 | |||
| 252 | /* Check the opcode */ | ||
| 253 | if (opc >= 0x60 && opc <= 0x7F) | ||
| 254 | opc = PMIC_ARB_OP_READ; | ||
| 255 | else if (opc >= 0x20 && opc <= 0x2F) | ||
| 256 | opc = PMIC_ARB_OP_EXT_READ; | ||
| 257 | else if (opc >= 0x38 && opc <= 0x3F) | ||
| 258 | opc = PMIC_ARB_OP_EXT_READL; | ||
| 259 | else | ||
| 260 | return -EINVAL; | ||
| 261 | |||
| 262 | cmd = (opc << 27) | ((sid & 0xf) << 20) | (addr << 4) | (bc & 0x7); | ||
| 263 | |||
| 264 | raw_spin_lock_irqsave(&pmic_arb->lock, flags); | ||
| 265 | pmic_arb_base_write(pmic_arb, PMIC_ARB_CMD(pmic_arb->channel), cmd); | ||
| 266 | rc = pmic_arb_wait_for_done(ctrl); | ||
| 267 | if (rc) | ||
| 268 | goto done; | ||
| 269 | |||
| 270 | pa_read_data(pmic_arb, buf, PMIC_ARB_RDATA0(pmic_arb->channel), | ||
| 271 | min_t(u8, bc, 3)); | ||
| 272 | |||
| 273 | if (bc > 3) | ||
| 274 | pa_read_data(pmic_arb, buf + 4, | ||
| 275 | PMIC_ARB_RDATA1(pmic_arb->channel), bc - 4); | ||
| 276 | |||
| 277 | done: | ||
| 278 | raw_spin_unlock_irqrestore(&pmic_arb->lock, flags); | ||
| 279 | return rc; | ||
| 280 | } | ||
| 281 | |||
| 282 | static int pmic_arb_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid, | ||
| 283 | u16 addr, const u8 *buf, size_t len) | ||
| 284 | { | ||
| 285 | struct spmi_pmic_arb_dev *pmic_arb = spmi_controller_get_drvdata(ctrl); | ||
| 286 | unsigned long flags; | ||
| 287 | u8 bc = len - 1; | ||
| 288 | u32 cmd; | ||
| 289 | int rc; | ||
| 290 | |||
| 291 | if (bc >= PMIC_ARB_MAX_TRANS_BYTES) { | ||
| 292 | dev_err(&ctrl->dev, | ||
| 293 | "pmic-arb supports 1..%d bytes per trans, but:%d requested", | ||
| 294 | PMIC_ARB_MAX_TRANS_BYTES, len); | ||
| 295 | return -EINVAL; | ||
| 296 | } | ||
| 297 | |||
| 298 | /* Check the opcode */ | ||
| 299 | if (opc >= 0x40 && opc <= 0x5F) | ||
| 300 | opc = PMIC_ARB_OP_WRITE; | ||
| 301 | else if (opc >= 0x00 && opc <= 0x0F) | ||
| 302 | opc = PMIC_ARB_OP_EXT_WRITE; | ||
| 303 | else if (opc >= 0x30 && opc <= 0x37) | ||
| 304 | opc = PMIC_ARB_OP_EXT_WRITEL; | ||
| 305 | else if (opc >= 0x80 && opc <= 0xFF) | ||
| 306 | opc = PMIC_ARB_OP_ZERO_WRITE; | ||
| 307 | else | ||
| 308 | return -EINVAL; | ||
| 309 | |||
| 310 | cmd = (opc << 27) | ((sid & 0xf) << 20) | (addr << 4) | (bc & 0x7); | ||
| 311 | |||
| 312 | /* Write data to FIFOs */ | ||
| 313 | raw_spin_lock_irqsave(&pmic_arb->lock, flags); | ||
| 314 | pa_write_data(pmic_arb, buf, PMIC_ARB_WDATA0(pmic_arb->channel) | ||
| 315 | , min_t(u8, bc, 3)); | ||
| 316 | if (bc > 3) | ||
| 317 | pa_write_data(pmic_arb, buf + 4, | ||
| 318 | PMIC_ARB_WDATA1(pmic_arb->channel), bc - 4); | ||
| 319 | |||
| 320 | /* Start the transaction */ | ||
| 321 | pmic_arb_base_write(pmic_arb, PMIC_ARB_CMD(pmic_arb->channel), cmd); | ||
| 322 | rc = pmic_arb_wait_for_done(ctrl); | ||
| 323 | raw_spin_unlock_irqrestore(&pmic_arb->lock, flags); | ||
| 324 | |||
| 325 | return rc; | ||
| 326 | } | ||
| 327 | |||
| 328 | enum qpnpint_regs { | ||
| 329 | QPNPINT_REG_RT_STS = 0x10, | ||
| 330 | QPNPINT_REG_SET_TYPE = 0x11, | ||
| 331 | QPNPINT_REG_POLARITY_HIGH = 0x12, | ||
| 332 | QPNPINT_REG_POLARITY_LOW = 0x13, | ||
| 333 | QPNPINT_REG_LATCHED_CLR = 0x14, | ||
| 334 | QPNPINT_REG_EN_SET = 0x15, | ||
| 335 | QPNPINT_REG_EN_CLR = 0x16, | ||
| 336 | QPNPINT_REG_LATCHED_STS = 0x18, | ||
| 337 | }; | ||
| 338 | |||
| 339 | struct spmi_pmic_arb_qpnpint_type { | ||
| 340 | u8 type; /* 1 -> edge */ | ||
| 341 | u8 polarity_high; | ||
| 342 | u8 polarity_low; | ||
| 343 | } __packed; | ||
| 344 | |||
| 345 | /* Simplified accessor functions for irqchip callbacks */ | ||
| 346 | static void qpnpint_spmi_write(struct irq_data *d, u8 reg, void *buf, | ||
| 347 | size_t len) | ||
| 348 | { | ||
| 349 | struct spmi_pmic_arb_dev *pa = irq_data_get_irq_chip_data(d); | ||
| 350 | u8 sid = d->hwirq >> 24; | ||
| 351 | u8 per = d->hwirq >> 16; | ||
| 352 | |||
| 353 | if (pmic_arb_write_cmd(pa->spmic, SPMI_CMD_EXT_WRITEL, sid, | ||
| 354 | (per << 8) + reg, buf, len)) | ||
| 355 | dev_err_ratelimited(&pa->spmic->dev, | ||
| 356 | "failed irqchip transaction on %x\n", | ||
| 357 | d->irq); | ||
| 358 | } | ||
| 359 | |||
| 360 | static void qpnpint_spmi_read(struct irq_data *d, u8 reg, void *buf, size_t len) | ||
| 361 | { | ||
| 362 | struct spmi_pmic_arb_dev *pa = irq_data_get_irq_chip_data(d); | ||
| 363 | u8 sid = d->hwirq >> 24; | ||
| 364 | u8 per = d->hwirq >> 16; | ||
| 365 | |||
| 366 | if (pmic_arb_read_cmd(pa->spmic, SPMI_CMD_EXT_READL, sid, | ||
| 367 | (per << 8) + reg, buf, len)) | ||
| 368 | dev_err_ratelimited(&pa->spmic->dev, | ||
| 369 | "failed irqchip transaction on %x\n", | ||
| 370 | d->irq); | ||
| 371 | } | ||
| 372 | |||
| 373 | static void periph_interrupt(struct spmi_pmic_arb_dev *pa, u8 apid) | ||
| 374 | { | ||
| 375 | unsigned int irq; | ||
| 376 | u32 status; | ||
| 377 | int id; | ||
| 378 | |||
| 379 | status = readl_relaxed(pa->intr + SPMI_PIC_IRQ_STATUS(apid)); | ||
| 380 | while (status) { | ||
| 381 | id = ffs(status) - 1; | ||
| 382 | status &= ~(1 << id); | ||
| 383 | irq = irq_find_mapping(pa->domain, | ||
| 384 | pa->apid_to_ppid[apid] << 16 | ||
| 385 | | id << 8 | ||
| 386 | | apid); | ||
| 387 | generic_handle_irq(irq); | ||
| 388 | } | ||
| 389 | } | ||
| 390 | |||
| 391 | static void pmic_arb_chained_irq(unsigned int irq, struct irq_desc *desc) | ||
| 392 | { | ||
| 393 | struct spmi_pmic_arb_dev *pa = irq_get_handler_data(irq); | ||
| 394 | struct irq_chip *chip = irq_get_chip(irq); | ||
| 395 | void __iomem *intr = pa->intr; | ||
| 396 | int first = pa->min_apid >> 5; | ||
| 397 | int last = pa->max_apid >> 5; | ||
| 398 | u32 status; | ||
| 399 | int i, id; | ||
| 400 | |||
| 401 | chained_irq_enter(chip, desc); | ||
| 402 | |||
| 403 | for (i = first; i <= last; ++i) { | ||
| 404 | status = readl_relaxed(intr + | ||
| 405 | SPMI_PIC_OWNER_ACC_STATUS(pa->ee, i)); | ||
| 406 | while (status) { | ||
| 407 | id = ffs(status) - 1; | ||
| 408 | status &= ~(1 << id); | ||
| 409 | periph_interrupt(pa, id + i * 32); | ||
| 410 | } | ||
| 411 | } | ||
| 412 | |||
| 413 | chained_irq_exit(chip, desc); | ||
| 414 | } | ||
| 415 | |||
| 416 | static void qpnpint_irq_ack(struct irq_data *d) | ||
| 417 | { | ||
| 418 | struct spmi_pmic_arb_dev *pa = irq_data_get_irq_chip_data(d); | ||
| 419 | u8 irq = d->hwirq >> 8; | ||
| 420 | u8 apid = d->hwirq; | ||
| 421 | unsigned long flags; | ||
| 422 | u8 data; | ||
| 423 | |||
| 424 | raw_spin_lock_irqsave(&pa->lock, flags); | ||
| 425 | writel_relaxed(1 << irq, pa->intr + SPMI_PIC_IRQ_CLEAR(apid)); | ||
| 426 | raw_spin_unlock_irqrestore(&pa->lock, flags); | ||
| 427 | |||
| 428 | data = 1 << irq; | ||
| 429 | qpnpint_spmi_write(d, QPNPINT_REG_LATCHED_CLR, &data, 1); | ||
| 430 | } | ||
| 431 | |||
| 432 | static void qpnpint_irq_mask(struct irq_data *d) | ||
| 433 | { | ||
| 434 | struct spmi_pmic_arb_dev *pa = irq_data_get_irq_chip_data(d); | ||
| 435 | u8 irq = d->hwirq >> 8; | ||
| 436 | u8 apid = d->hwirq; | ||
| 437 | unsigned long flags; | ||
| 438 | u32 status; | ||
| 439 | u8 data; | ||
| 440 | |||
| 441 | raw_spin_lock_irqsave(&pa->lock, flags); | ||
| 442 | status = readl_relaxed(pa->intr + SPMI_PIC_ACC_ENABLE(apid)); | ||
| 443 | if (status & SPMI_PIC_ACC_ENABLE_BIT) { | ||
| 444 | status = status & ~SPMI_PIC_ACC_ENABLE_BIT; | ||
| 445 | writel_relaxed(status, pa->intr + SPMI_PIC_ACC_ENABLE(apid)); | ||
| 446 | } | ||
| 447 | raw_spin_unlock_irqrestore(&pa->lock, flags); | ||
| 448 | |||
| 449 | data = 1 << irq; | ||
| 450 | qpnpint_spmi_write(d, QPNPINT_REG_EN_CLR, &data, 1); | ||
| 451 | } | ||
| 452 | |||
| 453 | static void qpnpint_irq_unmask(struct irq_data *d) | ||
| 454 | { | ||
| 455 | struct spmi_pmic_arb_dev *pa = irq_data_get_irq_chip_data(d); | ||
| 456 | u8 irq = d->hwirq >> 8; | ||
| 457 | u8 apid = d->hwirq; | ||
| 458 | unsigned long flags; | ||
| 459 | u32 status; | ||
| 460 | u8 data; | ||
| 461 | |||
| 462 | raw_spin_lock_irqsave(&pa->lock, flags); | ||
| 463 | status = readl_relaxed(pa->intr + SPMI_PIC_ACC_ENABLE(apid)); | ||
| 464 | if (!(status & SPMI_PIC_ACC_ENABLE_BIT)) { | ||
| 465 | writel_relaxed(status | SPMI_PIC_ACC_ENABLE_BIT, | ||
| 466 | pa->intr + SPMI_PIC_ACC_ENABLE(apid)); | ||
| 467 | } | ||
| 468 | raw_spin_unlock_irqrestore(&pa->lock, flags); | ||
| 469 | |||
| 470 | data = 1 << irq; | ||
| 471 | qpnpint_spmi_write(d, QPNPINT_REG_EN_SET, &data, 1); | ||
| 472 | } | ||
| 473 | |||
| 474 | static void qpnpint_irq_enable(struct irq_data *d) | ||
| 475 | { | ||
| 476 | u8 irq = d->hwirq >> 8; | ||
| 477 | u8 data; | ||
| 478 | |||
| 479 | qpnpint_irq_unmask(d); | ||
| 480 | |||
| 481 | data = 1 << irq; | ||
| 482 | qpnpint_spmi_write(d, QPNPINT_REG_LATCHED_CLR, &data, 1); | ||
| 483 | } | ||
| 484 | |||
| 485 | static int qpnpint_irq_set_type(struct irq_data *d, unsigned int flow_type) | ||
| 486 | { | ||
| 487 | struct spmi_pmic_arb_qpnpint_type type; | ||
| 488 | u8 irq = d->hwirq >> 8; | ||
| 489 | |||
| 490 | qpnpint_spmi_read(d, QPNPINT_REG_SET_TYPE, &type, sizeof(type)); | ||
| 491 | |||
| 492 | if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) { | ||
| 493 | type.type |= 1 << irq; | ||
| 494 | if (flow_type & IRQF_TRIGGER_RISING) | ||
| 495 | type.polarity_high |= 1 << irq; | ||
| 496 | if (flow_type & IRQF_TRIGGER_FALLING) | ||
| 497 | type.polarity_low |= 1 << irq; | ||
| 498 | } else { | ||
| 499 | if ((flow_type & (IRQF_TRIGGER_HIGH)) && | ||
| 500 | (flow_type & (IRQF_TRIGGER_LOW))) | ||
| 501 | return -EINVAL; | ||
| 502 | |||
| 503 | type.type &= ~(1 << irq); /* level trig */ | ||
| 504 | if (flow_type & IRQF_TRIGGER_HIGH) | ||
| 505 | type.polarity_high |= 1 << irq; | ||
| 506 | else | ||
| 507 | type.polarity_low |= 1 << irq; | ||
| 508 | } | ||
| 509 | |||
| 510 | qpnpint_spmi_write(d, QPNPINT_REG_SET_TYPE, &type, sizeof(type)); | ||
| 511 | return 0; | ||
| 512 | } | ||
| 513 | |||
| 514 | static struct irq_chip pmic_arb_irqchip = { | ||
| 515 | .name = "pmic_arb", | ||
| 516 | .irq_enable = qpnpint_irq_enable, | ||
| 517 | .irq_ack = qpnpint_irq_ack, | ||
| 518 | .irq_mask = qpnpint_irq_mask, | ||
| 519 | .irq_unmask = qpnpint_irq_unmask, | ||
| 520 | .irq_set_type = qpnpint_irq_set_type, | ||
| 521 | .flags = IRQCHIP_MASK_ON_SUSPEND | ||
| 522 | | IRQCHIP_SKIP_SET_WAKE, | ||
| 523 | }; | ||
| 524 | |||
| 525 | struct spmi_pmic_arb_irq_spec { | ||
| 526 | unsigned slave:4; | ||
| 527 | unsigned per:8; | ||
| 528 | unsigned irq:3; | ||
| 529 | }; | ||
| 530 | |||
| 531 | static int search_mapping_table(struct spmi_pmic_arb_dev *pa, | ||
| 532 | struct spmi_pmic_arb_irq_spec *spec, | ||
| 533 | u8 *apid) | ||
| 534 | { | ||
| 535 | u16 ppid = spec->slave << 8 | spec->per; | ||
| 536 | u32 *mapping_table = pa->mapping_table; | ||
| 537 | int index = 0, i; | ||
| 538 | u32 data; | ||
| 539 | |||
| 540 | for (i = 0; i < SPMI_MAPPING_TABLE_TREE_DEPTH; ++i) { | ||
| 541 | data = mapping_table[index]; | ||
| 542 | |||
| 543 | if (ppid & (1 << SPMI_MAPPING_BIT_INDEX(data))) { | ||
| 544 | if (SPMI_MAPPING_BIT_IS_1_FLAG(data)) { | ||
| 545 | index = SPMI_MAPPING_BIT_IS_1_RESULT(data); | ||
| 546 | } else { | ||
| 547 | *apid = SPMI_MAPPING_BIT_IS_1_RESULT(data); | ||
| 548 | return 0; | ||
| 549 | } | ||
| 550 | } else { | ||
| 551 | if (SPMI_MAPPING_BIT_IS_0_FLAG(data)) { | ||
| 552 | index = SPMI_MAPPING_BIT_IS_0_RESULT(data); | ||
| 553 | } else { | ||
| 554 | *apid = SPMI_MAPPING_BIT_IS_0_RESULT(data); | ||
| 555 | return 0; | ||
| 556 | } | ||
| 557 | } | ||
| 558 | } | ||
| 559 | |||
| 560 | return -ENODEV; | ||
| 561 | } | ||
| 562 | |||
| 563 | static int qpnpint_irq_domain_dt_translate(struct irq_domain *d, | ||
| 564 | struct device_node *controller, | ||
| 565 | const u32 *intspec, | ||
| 566 | unsigned int intsize, | ||
| 567 | unsigned long *out_hwirq, | ||
| 568 | unsigned int *out_type) | ||
| 569 | { | ||
| 570 | struct spmi_pmic_arb_dev *pa = d->host_data; | ||
| 571 | struct spmi_pmic_arb_irq_spec spec; | ||
| 572 | int err; | ||
| 573 | u8 apid; | ||
| 574 | |||
| 575 | dev_dbg(&pa->spmic->dev, | ||
| 576 | "intspec[0] 0x%1x intspec[1] 0x%02x intspec[2] 0x%02x\n", | ||
| 577 | intspec[0], intspec[1], intspec[2]); | ||
| 578 | |||
| 579 | if (d->of_node != controller) | ||
| 580 | return -EINVAL; | ||
| 581 | if (intsize != 4) | ||
| 582 | return -EINVAL; | ||
| 583 | if (intspec[0] > 0xF || intspec[1] > 0xFF || intspec[2] > 0x7) | ||
| 584 | return -EINVAL; | ||
| 585 | |||
| 586 | spec.slave = intspec[0]; | ||
| 587 | spec.per = intspec[1]; | ||
| 588 | spec.irq = intspec[2]; | ||
| 589 | |||
| 590 | err = search_mapping_table(pa, &spec, &apid); | ||
| 591 | if (err) | ||
| 592 | return err; | ||
| 593 | |||
| 594 | pa->apid_to_ppid[apid] = spec.slave << 8 | spec.per; | ||
| 595 | |||
| 596 | /* Keep track of {max,min}_apid for bounding search during interrupt */ | ||
| 597 | if (apid > pa->max_apid) | ||
| 598 | pa->max_apid = apid; | ||
| 599 | if (apid < pa->min_apid) | ||
| 600 | pa->min_apid = apid; | ||
| 601 | |||
| 602 | *out_hwirq = spec.slave << 24 | ||
| 603 | | spec.per << 16 | ||
| 604 | | spec.irq << 8 | ||
| 605 | | apid; | ||
| 606 | *out_type = intspec[3] & IRQ_TYPE_SENSE_MASK; | ||
| 607 | |||
| 608 | dev_dbg(&pa->spmic->dev, "out_hwirq = %lu\n", *out_hwirq); | ||
| 609 | |||
| 610 | return 0; | ||
| 611 | } | ||
| 612 | |||
| 613 | static int qpnpint_irq_domain_map(struct irq_domain *d, | ||
| 614 | unsigned int virq, | ||
| 615 | irq_hw_number_t hwirq) | ||
| 616 | { | ||
| 617 | struct spmi_pmic_arb_dev *pa = d->host_data; | ||
| 618 | |||
| 619 | dev_dbg(&pa->spmic->dev, "virq = %u, hwirq = %lu\n", virq, hwirq); | ||
| 620 | |||
| 621 | irq_set_chip_and_handler(virq, &pmic_arb_irqchip, handle_level_irq); | ||
| 622 | irq_set_chip_data(virq, d->host_data); | ||
| 623 | irq_set_noprobe(virq); | ||
| 624 | return 0; | ||
| 625 | } | ||
| 626 | |||
| 627 | static const struct irq_domain_ops pmic_arb_irq_domain_ops = { | ||
| 628 | .map = qpnpint_irq_domain_map, | ||
| 629 | .xlate = qpnpint_irq_domain_dt_translate, | ||
| 630 | }; | ||
| 631 | |||
| 632 | static int spmi_pmic_arb_probe(struct platform_device *pdev) | ||
| 633 | { | ||
| 634 | struct spmi_pmic_arb_dev *pa; | ||
| 635 | struct spmi_controller *ctrl; | ||
| 636 | struct resource *res; | ||
| 637 | u32 channel, ee; | ||
| 638 | int err, i; | ||
| 639 | |||
| 640 | ctrl = spmi_controller_alloc(&pdev->dev, sizeof(*pa)); | ||
| 641 | if (!ctrl) | ||
| 642 | return -ENOMEM; | ||
| 643 | |||
| 644 | pa = spmi_controller_get_drvdata(ctrl); | ||
| 645 | pa->spmic = ctrl; | ||
| 646 | |||
| 647 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); | ||
| 648 | pa->base = devm_ioremap_resource(&ctrl->dev, res); | ||
| 649 | if (IS_ERR(pa->base)) { | ||
| 650 | err = PTR_ERR(pa->base); | ||
| 651 | goto err_put_ctrl; | ||
| 652 | } | ||
| 653 | |||
| 654 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "intr"); | ||
| 655 | pa->intr = devm_ioremap_resource(&ctrl->dev, res); | ||
| 656 | if (IS_ERR(pa->intr)) { | ||
| 657 | err = PTR_ERR(pa->intr); | ||
| 658 | goto err_put_ctrl; | ||
| 659 | } | ||
| 660 | |||
| 661 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cnfg"); | ||
| 662 | pa->cnfg = devm_ioremap_resource(&ctrl->dev, res); | ||
| 663 | if (IS_ERR(pa->cnfg)) { | ||
| 664 | err = PTR_ERR(pa->cnfg); | ||
| 665 | goto err_put_ctrl; | ||
| 666 | } | ||
| 667 | |||
| 668 | pa->irq = platform_get_irq_byname(pdev, "periph_irq"); | ||
| 669 | if (pa->irq < 0) { | ||
| 670 | err = pa->irq; | ||
| 671 | goto err_put_ctrl; | ||
| 672 | } | ||
| 673 | |||
| 674 | err = of_property_read_u32(pdev->dev.of_node, "qcom,channel", &channel); | ||
| 675 | if (err) { | ||
| 676 | dev_err(&pdev->dev, "channel unspecified.\n"); | ||
| 677 | goto err_put_ctrl; | ||
| 678 | } | ||
| 679 | |||
| 680 | if (channel > 5) { | ||
| 681 | dev_err(&pdev->dev, "invalid channel (%u) specified.\n", | ||
| 682 | channel); | ||
| 683 | goto err_put_ctrl; | ||
| 684 | } | ||
| 685 | |||
| 686 | pa->channel = channel; | ||
| 687 | |||
| 688 | err = of_property_read_u32(pdev->dev.of_node, "qcom,ee", &ee); | ||
| 689 | if (err) { | ||
| 690 | dev_err(&pdev->dev, "EE unspecified.\n"); | ||
| 691 | goto err_put_ctrl; | ||
| 692 | } | ||
| 693 | |||
| 694 | if (ee > 5) { | ||
| 695 | dev_err(&pdev->dev, "invalid EE (%u) specified\n", ee); | ||
| 696 | err = -EINVAL; | ||
| 697 | goto err_put_ctrl; | ||
| 698 | } | ||
| 699 | |||
| 700 | pa->ee = ee; | ||
| 701 | |||
| 702 | for (i = 0; i < ARRAY_SIZE(pa->mapping_table); ++i) | ||
| 703 | pa->mapping_table[i] = readl_relaxed( | ||
| 704 | pa->cnfg + SPMI_MAPPING_TABLE_REG(i)); | ||
| 705 | |||
| 706 | /* Initialize max_apid/min_apid to the opposite bounds, during | ||
| 707 | * the irq domain translation, we are sure to update these */ | ||
| 708 | pa->max_apid = 0; | ||
| 709 | pa->min_apid = PMIC_ARB_MAX_PERIPHS - 1; | ||
| 710 | |||
| 711 | platform_set_drvdata(pdev, ctrl); | ||
| 712 | raw_spin_lock_init(&pa->lock); | ||
| 713 | |||
| 714 | ctrl->cmd = pmic_arb_cmd; | ||
| 715 | ctrl->read_cmd = pmic_arb_read_cmd; | ||
| 716 | ctrl->write_cmd = pmic_arb_write_cmd; | ||
| 717 | |||
| 718 | dev_dbg(&pdev->dev, "adding irq domain\n"); | ||
| 719 | pa->domain = irq_domain_add_tree(pdev->dev.of_node, | ||
| 720 | &pmic_arb_irq_domain_ops, pa); | ||
| 721 | if (!pa->domain) { | ||
| 722 | dev_err(&pdev->dev, "unable to create irq_domain\n"); | ||
| 723 | err = -ENOMEM; | ||
| 724 | goto err_put_ctrl; | ||
| 725 | } | ||
| 726 | |||
| 727 | irq_set_handler_data(pa->irq, pa); | ||
| 728 | irq_set_chained_handler(pa->irq, pmic_arb_chained_irq); | ||
| 729 | |||
| 730 | err = spmi_controller_add(ctrl); | ||
| 731 | if (err) | ||
| 732 | goto err_domain_remove; | ||
| 733 | |||
| 734 | dev_dbg(&ctrl->dev, "PMIC Arb Version 0x%x\n", | ||
| 735 | pmic_arb_base_read(pa, PMIC_ARB_VERSION)); | ||
| 736 | |||
| 737 | return 0; | ||
| 738 | |||
| 739 | err_domain_remove: | ||
| 740 | irq_set_chained_handler(pa->irq, NULL); | ||
| 741 | irq_set_handler_data(pa->irq, NULL); | ||
| 742 | irq_domain_remove(pa->domain); | ||
| 743 | err_put_ctrl: | ||
| 744 | spmi_controller_put(ctrl); | ||
| 745 | return err; | ||
| 746 | } | ||
| 747 | |||
| 748 | static int spmi_pmic_arb_remove(struct platform_device *pdev) | ||
| 749 | { | ||
| 750 | struct spmi_controller *ctrl = platform_get_drvdata(pdev); | ||
| 751 | struct spmi_pmic_arb_dev *pa = spmi_controller_get_drvdata(ctrl); | ||
| 752 | spmi_controller_remove(ctrl); | ||
| 753 | irq_set_chained_handler(pa->irq, NULL); | ||
| 754 | irq_set_handler_data(pa->irq, NULL); | ||
| 755 | irq_domain_remove(pa->domain); | ||
| 756 | spmi_controller_put(ctrl); | ||
| 757 | return 0; | ||
| 758 | } | ||
| 759 | |||
| 760 | static const struct of_device_id spmi_pmic_arb_match_table[] = { | ||
| 761 | { .compatible = "qcom,spmi-pmic-arb", }, | ||
| 762 | {}, | ||
| 763 | }; | ||
| 764 | MODULE_DEVICE_TABLE(of, spmi_pmic_arb_match_table); | ||
| 765 | |||
| 766 | static struct platform_driver spmi_pmic_arb_driver = { | ||
| 767 | .probe = spmi_pmic_arb_probe, | ||
| 768 | .remove = spmi_pmic_arb_remove, | ||
| 769 | .driver = { | ||
| 770 | .name = "spmi_pmic_arb", | ||
| 771 | .owner = THIS_MODULE, | ||
| 772 | .of_match_table = spmi_pmic_arb_match_table, | ||
| 773 | }, | ||
| 774 | }; | ||
| 775 | module_platform_driver(spmi_pmic_arb_driver); | ||
| 776 | |||
| 777 | MODULE_LICENSE("GPL v2"); | ||
| 778 | MODULE_ALIAS("platform:spmi_pmic_arb"); | ||
diff --git a/drivers/spmi/spmi.c b/drivers/spmi/spmi.c new file mode 100644 index 000000000000..6122c8f2f4e3 --- /dev/null +++ b/drivers/spmi/spmi.c | |||
| @@ -0,0 +1,609 @@ | |||
| 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. | ||
| 2 | * | ||
| 3 | * This program is free software; you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License version 2 and | ||
| 5 | * only version 2 as published by the Free Software Foundation. | ||
| 6 | * | ||
| 7 | * This program is distributed in the hope that it will be useful, | ||
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 10 | * GNU General Public License for more details. | ||
| 11 | */ | ||
| 12 | #include <linux/kernel.h> | ||
| 13 | #include <linux/errno.h> | ||
| 14 | #include <linux/idr.h> | ||
| 15 | #include <linux/slab.h> | ||
| 16 | #include <linux/module.h> | ||
| 17 | #include <linux/of.h> | ||
| 18 | #include <linux/of_device.h> | ||
| 19 | #include <linux/platform_device.h> | ||
| 20 | #include <linux/spmi.h> | ||
| 21 | #include <linux/module.h> | ||
| 22 | #include <linux/pm_runtime.h> | ||
| 23 | |||
| 24 | #include <dt-bindings/spmi/spmi.h> | ||
| 25 | |||
| 26 | static DEFINE_IDA(ctrl_ida); | ||
| 27 | |||
| 28 | static void spmi_dev_release(struct device *dev) | ||
| 29 | { | ||
| 30 | struct spmi_device *sdev = to_spmi_device(dev); | ||
| 31 | kfree(sdev); | ||
| 32 | } | ||
| 33 | |||
| 34 | static const struct device_type spmi_dev_type = { | ||
| 35 | .release = spmi_dev_release, | ||
| 36 | }; | ||
| 37 | |||
| 38 | static void spmi_ctrl_release(struct device *dev) | ||
| 39 | { | ||
| 40 | struct spmi_controller *ctrl = to_spmi_controller(dev); | ||
| 41 | ida_simple_remove(&ctrl_ida, ctrl->nr); | ||
| 42 | kfree(ctrl); | ||
| 43 | } | ||
| 44 | |||
| 45 | static const struct device_type spmi_ctrl_type = { | ||
| 46 | .release = spmi_ctrl_release, | ||
| 47 | }; | ||
| 48 | |||
| 49 | #ifdef CONFIG_PM_RUNTIME | ||
| 50 | static int spmi_runtime_suspend(struct device *dev) | ||
| 51 | { | ||
| 52 | struct spmi_device *sdev = to_spmi_device(dev); | ||
| 53 | int err; | ||
| 54 | |||
| 55 | err = pm_generic_runtime_suspend(dev); | ||
| 56 | if (err) | ||
| 57 | return err; | ||
| 58 | |||
| 59 | return spmi_command_sleep(sdev); | ||
| 60 | } | ||
| 61 | |||
| 62 | static int spmi_runtime_resume(struct device *dev) | ||
| 63 | { | ||
| 64 | struct spmi_device *sdev = to_spmi_device(dev); | ||
| 65 | int err; | ||
| 66 | |||
| 67 | err = spmi_command_wakeup(sdev); | ||
| 68 | if (err) | ||
| 69 | return err; | ||
| 70 | |||
| 71 | return pm_generic_runtime_resume(dev); | ||
| 72 | } | ||
| 73 | #endif | ||
| 74 | |||
| 75 | static const struct dev_pm_ops spmi_pm_ops = { | ||
| 76 | SET_RUNTIME_PM_OPS( | ||
| 77 | spmi_runtime_suspend, | ||
| 78 | spmi_runtime_resume, | ||
| 79 | NULL | ||
| 80 | ) | ||
| 81 | }; | ||
| 82 | |||
| 83 | static int spmi_device_match(struct device *dev, struct device_driver *drv) | ||
| 84 | { | ||
| 85 | if (of_driver_match_device(dev, drv)) | ||
| 86 | return 1; | ||
| 87 | |||
| 88 | if (drv->name) | ||
| 89 | return strncmp(dev_name(dev), drv->name, | ||
| 90 | SPMI_NAME_SIZE) == 0; | ||
| 91 | |||
| 92 | return 0; | ||
| 93 | } | ||
| 94 | |||
| 95 | /** | ||
| 96 | * spmi_device_add() - add a device previously constructed via spmi_device_alloc() | ||
| 97 | * @sdev: spmi_device to be added | ||
| 98 | */ | ||
| 99 | int spmi_device_add(struct spmi_device *sdev) | ||
| 100 | { | ||
| 101 | struct spmi_controller *ctrl = sdev->ctrl; | ||
| 102 | int err; | ||
| 103 | |||
| 104 | dev_set_name(&sdev->dev, "%d-%02x", ctrl->nr, sdev->usid); | ||
| 105 | |||
| 106 | err = device_add(&sdev->dev); | ||
| 107 | if (err < 0) { | ||
| 108 | dev_err(&sdev->dev, "Can't add %s, status %d\n", | ||
| 109 | dev_name(&sdev->dev), err); | ||
| 110 | goto err_device_add; | ||
| 111 | } | ||
| 112 | |||
| 113 | dev_dbg(&sdev->dev, "device %s registered\n", dev_name(&sdev->dev)); | ||
| 114 | |||
| 115 | err_device_add: | ||
| 116 | return err; | ||
| 117 | } | ||
| 118 | EXPORT_SYMBOL_GPL(spmi_device_add); | ||
| 119 | |||
| 120 | /** | ||
| 121 | * spmi_device_remove(): remove an SPMI device | ||
| 122 | * @sdev: spmi_device to be removed | ||
| 123 | */ | ||
| 124 | void spmi_device_remove(struct spmi_device *sdev) | ||
| 125 | { | ||
| 126 | device_unregister(&sdev->dev); | ||
| 127 | } | ||
| 128 | EXPORT_SYMBOL_GPL(spmi_device_remove); | ||
| 129 | |||
| 130 | static inline int | ||
| 131 | spmi_cmd(struct spmi_controller *ctrl, u8 opcode, u8 sid) | ||
| 132 | { | ||
| 133 | if (!ctrl || !ctrl->cmd || ctrl->dev.type != &spmi_ctrl_type) | ||
| 134 | return -EINVAL; | ||
| 135 | |||
| 136 | return ctrl->cmd(ctrl, opcode, sid); | ||
| 137 | } | ||
| 138 | |||
| 139 | static inline int spmi_read_cmd(struct spmi_controller *ctrl, u8 opcode, | ||
| 140 | u8 sid, u16 addr, u8 *buf, size_t len) | ||
| 141 | { | ||
| 142 | if (!ctrl || !ctrl->read_cmd || ctrl->dev.type != &spmi_ctrl_type) | ||
| 143 | return -EINVAL; | ||
| 144 | |||
| 145 | return ctrl->read_cmd(ctrl, opcode, sid, addr, buf, len); | ||
| 146 | } | ||
| 147 | |||
| 148 | static inline int spmi_write_cmd(struct spmi_controller *ctrl, u8 opcode, | ||
| 149 | u8 sid, u16 addr, const u8 *buf, size_t len) | ||
| 150 | { | ||
| 151 | if (!ctrl || !ctrl->write_cmd || ctrl->dev.type != &spmi_ctrl_type) | ||
| 152 | return -EINVAL; | ||
| 153 | |||
| 154 | return ctrl->write_cmd(ctrl, opcode, sid, addr, buf, len); | ||
| 155 | } | ||
| 156 | |||
| 157 | /** | ||
| 158 | * spmi_register_read() - register read | ||
| 159 | * @sdev: SPMI device. | ||
| 160 | * @addr: slave register address (5-bit address). | ||
| 161 | * @buf: buffer to be populated with data from the Slave. | ||
| 162 | * | ||
| 163 | * Reads 1 byte of data from a Slave device register. | ||
| 164 | */ | ||
| 165 | int spmi_register_read(struct spmi_device *sdev, u8 addr, u8 *buf) | ||
| 166 | { | ||
| 167 | /* 5-bit register address */ | ||
| 168 | if (addr > 0x1F) | ||
| 169 | return -EINVAL; | ||
| 170 | |||
| 171 | return spmi_read_cmd(sdev->ctrl, SPMI_CMD_READ, sdev->usid, addr, | ||
| 172 | buf, 1); | ||
| 173 | } | ||
| 174 | EXPORT_SYMBOL_GPL(spmi_register_read); | ||
| 175 | |||
| 176 | /** | ||
| 177 | * spmi_ext_register_read() - extended register read | ||
| 178 | * @sdev: SPMI device. | ||
| 179 | * @addr: slave register address (8-bit address). | ||
| 180 | * @buf: buffer to be populated with data from the Slave. | ||
| 181 | * @len: the request number of bytes to read (up to 16 bytes). | ||
| 182 | * | ||
| 183 | * Reads up to 16 bytes of data from the extended register space on a | ||
| 184 | * Slave device. | ||
| 185 | */ | ||
| 186 | int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf, | ||
| 187 | size_t len) | ||
| 188 | { | ||
| 189 | /* 8-bit register address, up to 16 bytes */ | ||
| 190 | if (len == 0 || len > 16) | ||
| 191 | return -EINVAL; | ||
| 192 | |||
| 193 | return spmi_read_cmd(sdev->ctrl, SPMI_CMD_EXT_READ, sdev->usid, addr, | ||
| 194 | buf, len); | ||
| 195 | } | ||
| 196 | EXPORT_SYMBOL_GPL(spmi_ext_register_read); | ||
| 197 | |||
| 198 | /** | ||
| 199 | * spmi_ext_register_readl() - extended register read long | ||
| 200 | * @sdev: SPMI device. | ||
| 201 | * @addr: slave register address (16-bit address). | ||
| 202 | * @buf: buffer to be populated with data from the Slave. | ||
| 203 | * @len: the request number of bytes to read (up to 8 bytes). | ||
| 204 | * | ||
| 205 | * Reads up to 8 bytes of data from the extended register space on a | ||
| 206 | * Slave device using 16-bit address. | ||
| 207 | */ | ||
| 208 | int spmi_ext_register_readl(struct spmi_device *sdev, u16 addr, u8 *buf, | ||
| 209 | size_t len) | ||
| 210 | { | ||
| 211 | /* 16-bit register address, up to 8 bytes */ | ||
| 212 | if (len == 0 || len > 8) | ||
| 213 | return -EINVAL; | ||
| 214 | |||
| 215 | return spmi_read_cmd(sdev->ctrl, SPMI_CMD_EXT_READL, sdev->usid, addr, | ||
| 216 | buf, len); | ||
| 217 | } | ||
| 218 | EXPORT_SYMBOL_GPL(spmi_ext_register_readl); | ||
| 219 | |||
| 220 | /** | ||
| 221 | * spmi_register_write() - register write | ||
| 222 | * @sdev: SPMI device | ||
| 223 | * @addr: slave register address (5-bit address). | ||
| 224 | * @data: buffer containing the data to be transferred to the Slave. | ||
| 225 | * | ||
| 226 | * Writes 1 byte of data to a Slave device register. | ||
| 227 | */ | ||
| 228 | int spmi_register_write(struct spmi_device *sdev, u8 addr, u8 data) | ||
| 229 | { | ||
| 230 | /* 5-bit register address */ | ||
| 231 | if (addr > 0x1F) | ||
| 232 | return -EINVAL; | ||
| 233 | |||
| 234 | return spmi_write_cmd(sdev->ctrl, SPMI_CMD_WRITE, sdev->usid, addr, | ||
| 235 | &data, 1); | ||
| 236 | } | ||
| 237 | EXPORT_SYMBOL_GPL(spmi_register_write); | ||
| 238 | |||
| 239 | /** | ||
| 240 | * spmi_register_zero_write() - register zero write | ||
| 241 | * @sdev: SPMI device. | ||
| 242 | * @data: the data to be written to register 0 (7-bits). | ||
| 243 | * | ||
| 244 | * Writes data to register 0 of the Slave device. | ||
| 245 | */ | ||
| 246 | int spmi_register_zero_write(struct spmi_device *sdev, u8 data) | ||
| 247 | { | ||
| 248 | return spmi_write_cmd(sdev->ctrl, SPMI_CMD_ZERO_WRITE, sdev->usid, 0, | ||
| 249 | &data, 1); | ||
| 250 | } | ||
| 251 | EXPORT_SYMBOL_GPL(spmi_register_zero_write); | ||
| 252 | |||
| 253 | /** | ||
| 254 | * spmi_ext_register_write() - extended register write | ||
| 255 | * @sdev: SPMI device. | ||
| 256 | * @addr: slave register address (8-bit address). | ||
| 257 | * @buf: buffer containing the data to be transferred to the Slave. | ||
| 258 | * @len: the request number of bytes to read (up to 16 bytes). | ||
| 259 | * | ||
| 260 | * Writes up to 16 bytes of data to the extended register space of a | ||
| 261 | * Slave device. | ||
| 262 | */ | ||
| 263 | int spmi_ext_register_write(struct spmi_device *sdev, u8 addr, const u8 *buf, | ||
| 264 | size_t len) | ||
| 265 | { | ||
| 266 | /* 8-bit register address, up to 16 bytes */ | ||
| 267 | if (len == 0 || len > 16) | ||
| 268 | return -EINVAL; | ||
| 269 | |||
| 270 | return spmi_write_cmd(sdev->ctrl, SPMI_CMD_EXT_WRITE, sdev->usid, addr, | ||
| 271 | buf, len); | ||
| 272 | } | ||
| 273 | EXPORT_SYMBOL_GPL(spmi_ext_register_write); | ||
| 274 | |||
| 275 | /** | ||
| 276 | * spmi_ext_register_writel() - extended register write long | ||
| 277 | * @sdev: SPMI device. | ||
| 278 | * @addr: slave register address (16-bit address). | ||
| 279 | * @buf: buffer containing the data to be transferred to the Slave. | ||
| 280 | * @len: the request number of bytes to read (up to 8 bytes). | ||
| 281 | * | ||
| 282 | * Writes up to 8 bytes of data to the extended register space of a | ||
| 283 | * Slave device using 16-bit address. | ||
| 284 | */ | ||
| 285 | int spmi_ext_register_writel(struct spmi_device *sdev, u16 addr, const u8 *buf, | ||
| 286 | size_t len) | ||
| 287 | { | ||
| 288 | /* 4-bit Slave Identifier, 16-bit register address, up to 8 bytes */ | ||
| 289 | if (len == 0 || len > 8) | ||
| 290 | return -EINVAL; | ||
| 291 | |||
| 292 | return spmi_write_cmd(sdev->ctrl, SPMI_CMD_EXT_WRITEL, sdev->usid, | ||
| 293 | addr, buf, len); | ||
| 294 | } | ||
| 295 | EXPORT_SYMBOL_GPL(spmi_ext_register_writel); | ||
| 296 | |||
| 297 | /** | ||
| 298 | * spmi_command_reset() - sends RESET command to the specified slave | ||
| 299 | * @sdev: SPMI device. | ||
| 300 | * | ||
| 301 | * The Reset command initializes the Slave and forces all registers to | ||
| 302 | * their reset values. The Slave shall enter the STARTUP state after | ||
| 303 | * receiving a Reset command. | ||
| 304 | */ | ||
| 305 | int spmi_command_reset(struct spmi_device *sdev) | ||
| 306 | { | ||
| 307 | return spmi_cmd(sdev->ctrl, SPMI_CMD_RESET, sdev->usid); | ||
| 308 | } | ||
| 309 | EXPORT_SYMBOL_GPL(spmi_command_reset); | ||
| 310 | |||
| 311 | /** | ||
| 312 | * spmi_command_sleep() - sends SLEEP command to the specified SPMI device | ||
| 313 | * @sdev: SPMI device. | ||
| 314 | * | ||
| 315 | * The Sleep command causes the Slave to enter the user defined SLEEP state. | ||
| 316 | */ | ||
| 317 | int spmi_command_sleep(struct spmi_device *sdev) | ||
| 318 | { | ||
| 319 | return spmi_cmd(sdev->ctrl, SPMI_CMD_SLEEP, sdev->usid); | ||
| 320 | } | ||
| 321 | EXPORT_SYMBOL_GPL(spmi_command_sleep); | ||
| 322 | |||
| 323 | /** | ||
| 324 | * spmi_command_wakeup() - sends WAKEUP command to the specified SPMI device | ||
| 325 | * @sdev: SPMI device. | ||
| 326 | * | ||
| 327 | * The Wakeup command causes the Slave to move from the SLEEP state to | ||
| 328 | * the ACTIVE state. | ||
| 329 | */ | ||
| 330 | int spmi_command_wakeup(struct spmi_device *sdev) | ||
| 331 | { | ||
| 332 | return spmi_cmd(sdev->ctrl, SPMI_CMD_WAKEUP, sdev->usid); | ||
| 333 | } | ||
| 334 | EXPORT_SYMBOL_GPL(spmi_command_wakeup); | ||
| 335 | |||
| 336 | /** | ||
| 337 | * spmi_command_shutdown() - sends SHUTDOWN command to the specified SPMI device | ||
| 338 | * @sdev: SPMI device. | ||
| 339 | * | ||
| 340 | * The Shutdown command causes the Slave to enter the SHUTDOWN state. | ||
| 341 | */ | ||
| 342 | int spmi_command_shutdown(struct spmi_device *sdev) | ||
| 343 | { | ||
| 344 | return spmi_cmd(sdev->ctrl, SPMI_CMD_SHUTDOWN, sdev->usid); | ||
| 345 | } | ||
| 346 | EXPORT_SYMBOL_GPL(spmi_command_shutdown); | ||
| 347 | |||
| 348 | static int spmi_drv_probe(struct device *dev) | ||
| 349 | { | ||
| 350 | const struct spmi_driver *sdrv = to_spmi_driver(dev->driver); | ||
| 351 | struct spmi_device *sdev = to_spmi_device(dev); | ||
| 352 | int err; | ||
| 353 | |||
| 354 | /* Ensure the slave is in ACTIVE state */ | ||
| 355 | err = spmi_command_wakeup(sdev); | ||
| 356 | if (err) | ||
| 357 | goto fail_wakeup; | ||
| 358 | |||
| 359 | pm_runtime_get_noresume(dev); | ||
| 360 | pm_runtime_set_active(dev); | ||
| 361 | pm_runtime_enable(dev); | ||
| 362 | |||
| 363 | err = sdrv->probe(sdev); | ||
| 364 | if (err) | ||
| 365 | goto fail_probe; | ||
| 366 | |||
| 367 | return 0; | ||
| 368 | |||
| 369 | fail_probe: | ||
| 370 | pm_runtime_disable(dev); | ||
| 371 | pm_runtime_set_suspended(dev); | ||
| 372 | pm_runtime_put_noidle(dev); | ||
| 373 | fail_wakeup: | ||
| 374 | return err; | ||
| 375 | } | ||
| 376 | |||
| 377 | static int spmi_drv_remove(struct device *dev) | ||
| 378 | { | ||
| 379 | const struct spmi_driver *sdrv = to_spmi_driver(dev->driver); | ||
| 380 | |||
| 381 | pm_runtime_get_sync(dev); | ||
| 382 | sdrv->remove(to_spmi_device(dev)); | ||
| 383 | pm_runtime_put_noidle(dev); | ||
| 384 | |||
| 385 | pm_runtime_disable(dev); | ||
| 386 | pm_runtime_set_suspended(dev); | ||
| 387 | pm_runtime_put_noidle(dev); | ||
| 388 | return 0; | ||
| 389 | } | ||
| 390 | |||
| 391 | static struct bus_type spmi_bus_type = { | ||
| 392 | .name = "spmi", | ||
| 393 | .match = spmi_device_match, | ||
| 394 | .pm = &spmi_pm_ops, | ||
| 395 | .probe = spmi_drv_probe, | ||
| 396 | .remove = spmi_drv_remove, | ||
| 397 | }; | ||
| 398 | |||
| 399 | /** | ||
| 400 | * spmi_controller_alloc() - Allocate a new SPMI device | ||
| 401 | * @ctrl: associated controller | ||
| 402 | * | ||
| 403 | * Caller is responsible for either calling spmi_device_add() to add the | ||
| 404 | * newly allocated controller, or calling spmi_device_put() to discard it. | ||
| 405 | */ | ||
| 406 | struct spmi_device *spmi_device_alloc(struct spmi_controller *ctrl) | ||
| 407 | { | ||
| 408 | struct spmi_device *sdev; | ||
| 409 | |||
| 410 | sdev = kzalloc(sizeof(*sdev), GFP_KERNEL); | ||
| 411 | if (!sdev) | ||
| 412 | return NULL; | ||
| 413 | |||
| 414 | sdev->ctrl = ctrl; | ||
| 415 | device_initialize(&sdev->dev); | ||
| 416 | sdev->dev.parent = &ctrl->dev; | ||
| 417 | sdev->dev.bus = &spmi_bus_type; | ||
| 418 | sdev->dev.type = &spmi_dev_type; | ||
| 419 | return sdev; | ||
| 420 | } | ||
| 421 | EXPORT_SYMBOL_GPL(spmi_device_alloc); | ||
| 422 | |||
| 423 | /** | ||
| 424 | * spmi_controller_alloc() - Allocate a new SPMI controller | ||
| 425 | * @parent: parent device | ||
| 426 | * @size: size of private data | ||
| 427 | * | ||
| 428 | * Caller is responsible for either calling spmi_controller_add() to add the | ||
| 429 | * newly allocated controller, or calling spmi_controller_put() to discard it. | ||
| 430 | * The allocated private data region may be accessed via | ||
| 431 | * spmi_controller_get_drvdata() | ||
| 432 | */ | ||
| 433 | struct spmi_controller *spmi_controller_alloc(struct device *parent, | ||
| 434 | size_t size) | ||
| 435 | { | ||
| 436 | struct spmi_controller *ctrl; | ||
| 437 | int id; | ||
| 438 | |||
| 439 | if (WARN_ON(!parent)) | ||
| 440 | return NULL; | ||
| 441 | |||
| 442 | ctrl = kzalloc(sizeof(*ctrl) + size, GFP_KERNEL); | ||
| 443 | if (!ctrl) | ||
| 444 | return NULL; | ||
| 445 | |||
| 446 | device_initialize(&ctrl->dev); | ||
| 447 | ctrl->dev.type = &spmi_ctrl_type; | ||
| 448 | ctrl->dev.bus = &spmi_bus_type; | ||
| 449 | ctrl->dev.parent = parent; | ||
| 450 | ctrl->dev.of_node = parent->of_node; | ||
| 451 | spmi_controller_set_drvdata(ctrl, &ctrl[1]); | ||
| 452 | |||
| 453 | id = ida_simple_get(&ctrl_ida, 0, 0, GFP_KERNEL); | ||
| 454 | if (id < 0) { | ||
| 455 | dev_err(parent, | ||
| 456 | "unable to allocate SPMI controller identifier.\n"); | ||
| 457 | spmi_controller_put(ctrl); | ||
| 458 | return NULL; | ||
| 459 | } | ||
| 460 | |||
| 461 | ctrl->nr = id; | ||
| 462 | dev_set_name(&ctrl->dev, "spmi-%d", id); | ||
| 463 | |||
| 464 | dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id); | ||
| 465 | return ctrl; | ||
| 466 | } | ||
| 467 | EXPORT_SYMBOL_GPL(spmi_controller_alloc); | ||
| 468 | |||
| 469 | static void of_spmi_register_devices(struct spmi_controller *ctrl) | ||
| 470 | { | ||
| 471 | struct device_node *node; | ||
| 472 | int err; | ||
| 473 | |||
| 474 | if (!ctrl->dev.of_node) | ||
| 475 | return; | ||
| 476 | |||
| 477 | for_each_available_child_of_node(ctrl->dev.of_node, node) { | ||
| 478 | struct spmi_device *sdev; | ||
| 479 | u32 reg[2]; | ||
| 480 | |||
| 481 | dev_dbg(&ctrl->dev, "adding child %s\n", node->full_name); | ||
| 482 | |||
| 483 | err = of_property_read_u32_array(node, "reg", reg, 2); | ||
| 484 | if (err) { | ||
| 485 | dev_err(&ctrl->dev, | ||
| 486 | "node %s err (%d) does not have 'reg' property\n", | ||
| 487 | node->full_name, err); | ||
| 488 | continue; | ||
| 489 | } | ||
| 490 | |||
| 491 | if (reg[1] != SPMI_USID) { | ||
| 492 | dev_err(&ctrl->dev, | ||
| 493 | "node %s contains unsupported 'reg' entry\n", | ||
| 494 | node->full_name); | ||
| 495 | continue; | ||
| 496 | } | ||
| 497 | |||
| 498 | if (reg[0] >= SPMI_MAX_SLAVE_ID) { | ||
| 499 | dev_err(&ctrl->dev, | ||
| 500 | "invalid usid on node %s\n", | ||
| 501 | node->full_name); | ||
| 502 | continue; | ||
| 503 | } | ||
| 504 | |||
| 505 | dev_dbg(&ctrl->dev, "read usid %02x\n", reg[0]); | ||
| 506 | |||
| 507 | sdev = spmi_device_alloc(ctrl); | ||
| 508 | if (!sdev) | ||
| 509 | continue; | ||
| 510 | |||
| 511 | sdev->dev.of_node = node; | ||
| 512 | sdev->usid = (u8) reg[0]; | ||
| 513 | |||
| 514 | err = spmi_device_add(sdev); | ||
| 515 | if (err) { | ||
| 516 | dev_err(&sdev->dev, | ||
| 517 | "failure adding device. status %d\n", err); | ||
| 518 | spmi_device_put(sdev); | ||
| 519 | } | ||
| 520 | } | ||
| 521 | } | ||
| 522 | |||
| 523 | /** | ||
| 524 | * spmi_controller_add() - Add an SPMI controller | ||
| 525 | * @ctrl: controller to be registered. | ||
| 526 | * | ||
| 527 | * Register a controller previously allocated via spmi_controller_alloc() with | ||
| 528 | * the SPMI core. | ||
| 529 | */ | ||
| 530 | int spmi_controller_add(struct spmi_controller *ctrl) | ||
| 531 | { | ||
| 532 | int ret; | ||
| 533 | |||
| 534 | /* Can't register until after driver model init */ | ||
| 535 | if (WARN_ON(!spmi_bus_type.p)) | ||
| 536 | return -EAGAIN; | ||
| 537 | |||
| 538 | ret = device_add(&ctrl->dev); | ||
| 539 | if (ret) | ||
| 540 | return ret; | ||
| 541 | |||
| 542 | if (IS_ENABLED(CONFIG_OF)) | ||
| 543 | of_spmi_register_devices(ctrl); | ||
| 544 | |||
| 545 | dev_dbg(&ctrl->dev, "spmi-%d registered: dev:%p\n", | ||
| 546 | ctrl->nr, &ctrl->dev); | ||
| 547 | |||
| 548 | return 0; | ||
| 549 | }; | ||
| 550 | EXPORT_SYMBOL_GPL(spmi_controller_add); | ||
| 551 | |||
| 552 | /* Remove a device associated with a controller */ | ||
| 553 | static int spmi_ctrl_remove_device(struct device *dev, void *data) | ||
| 554 | { | ||
| 555 | struct spmi_device *spmidev = to_spmi_device(dev); | ||
| 556 | if (dev->type == &spmi_dev_type) | ||
| 557 | spmi_device_remove(spmidev); | ||
| 558 | return 0; | ||
| 559 | } | ||
| 560 | |||
| 561 | /** | ||
| 562 | * spmi_controller_remove(): remove an SPMI controller | ||
| 563 | * @ctrl: controller to remove | ||
| 564 | * | ||
| 565 | * Remove a SPMI controller. Caller is responsible for calling | ||
| 566 | * spmi_controller_put() to discard the allocated controller. | ||
| 567 | */ | ||
| 568 | void spmi_controller_remove(struct spmi_controller *ctrl) | ||
| 569 | { | ||
| 570 | int dummy; | ||
| 571 | |||
| 572 | if (!ctrl) | ||
| 573 | return; | ||
| 574 | |||
| 575 | dummy = device_for_each_child(&ctrl->dev, NULL, | ||
| 576 | spmi_ctrl_remove_device); | ||
| 577 | device_del(&ctrl->dev); | ||
| 578 | } | ||
| 579 | EXPORT_SYMBOL_GPL(spmi_controller_remove); | ||
| 580 | |||
| 581 | /** | ||
| 582 | * spmi_driver_register() - Register client driver with SPMI core | ||
| 583 | * @sdrv: client driver to be associated with client-device. | ||
| 584 | * | ||
| 585 | * This API will register the client driver with the SPMI framework. | ||
| 586 | * It is typically called from the driver's module-init function. | ||
| 587 | */ | ||
| 588 | int spmi_driver_register(struct spmi_driver *sdrv) | ||
| 589 | { | ||
| 590 | sdrv->driver.bus = &spmi_bus_type; | ||
| 591 | return driver_register(&sdrv->driver); | ||
| 592 | } | ||
| 593 | EXPORT_SYMBOL_GPL(spmi_driver_register); | ||
| 594 | |||
| 595 | static void __exit spmi_exit(void) | ||
| 596 | { | ||
| 597 | bus_unregister(&spmi_bus_type); | ||
| 598 | } | ||
| 599 | module_exit(spmi_exit); | ||
| 600 | |||
| 601 | static int __init spmi_init(void) | ||
| 602 | { | ||
| 603 | return bus_register(&spmi_bus_type); | ||
| 604 | } | ||
| 605 | postcore_initcall(spmi_init); | ||
| 606 | |||
| 607 | MODULE_LICENSE("GPL v2"); | ||
| 608 | MODULE_DESCRIPTION("SPMI module"); | ||
| 609 | MODULE_ALIAS("platform:spmi"); | ||
diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c index 256fba7f4641..1f38445014c1 100644 --- a/drivers/video/uvesafb.c +++ b/drivers/video/uvesafb.c | |||
| @@ -190,7 +190,7 @@ static int uvesafb_exec(struct uvesafb_ktask *task) | |||
| 190 | uvfb_tasks[seq] = task; | 190 | uvfb_tasks[seq] = task; |
| 191 | mutex_unlock(&uvfb_lock); | 191 | mutex_unlock(&uvfb_lock); |
| 192 | 192 | ||
| 193 | err = cn_netlink_send(m, 0, GFP_KERNEL); | 193 | err = cn_netlink_send(m, 0, 0, GFP_KERNEL); |
| 194 | if (err == -ESRCH) { | 194 | if (err == -ESRCH) { |
| 195 | /* | 195 | /* |
| 196 | * Try to start the userspace helper if sending | 196 | * Try to start the userspace helper if sending |
| @@ -204,7 +204,7 @@ static int uvesafb_exec(struct uvesafb_ktask *task) | |||
| 204 | "helper is installed and executable\n"); | 204 | "helper is installed and executable\n"); |
| 205 | } else { | 205 | } else { |
| 206 | v86d_started = 1; | 206 | v86d_started = 1; |
| 207 | err = cn_netlink_send(m, 0, gfp_any()); | 207 | err = cn_netlink_send(m, 0, 0, gfp_any()); |
| 208 | if (err == -ENOBUFS) | 208 | if (err == -ENOBUFS) |
| 209 | err = 0; | 209 | err = 0; |
| 210 | } | 210 | } |
diff --git a/drivers/vme/bridges/vme_ca91cx42.c b/drivers/vme/bridges/vme_ca91cx42.c index 1b5d48c578e1..bfb2d3f06738 100644 --- a/drivers/vme/bridges/vme_ca91cx42.c +++ b/drivers/vme/bridges/vme_ca91cx42.c | |||
| @@ -869,14 +869,13 @@ static ssize_t ca91cx42_master_read(struct vme_master_resource *image, | |||
| 869 | 869 | ||
| 870 | spin_lock(&image->lock); | 870 | spin_lock(&image->lock); |
| 871 | 871 | ||
| 872 | /* The following code handles VME address alignment problem | 872 | /* The following code handles VME address alignment. We cannot use |
| 873 | * in order to assure the maximal data width cycle. | 873 | * memcpy_xxx here because it may cut data transfers in to 8-bit |
| 874 | * We cannot use memcpy_xxx directly here because it | 874 | * cycles when D16 or D32 cycles are required on the VME bus. |
| 875 | * may cut data transfer in 8-bits cycles, thus making | 875 | * On the other hand, the bridge itself assures that the maximum data |
| 876 | * D16 cycle impossible. | 876 | * cycle configured for the transfer is used and splits it |
| 877 | * From the other hand, the bridge itself assures that | 877 | * automatically for non-aligned addresses, so we don't want the |
| 878 | * maximal configured data cycle is used and splits it | 878 | * overhead of needlessly forcing small transfers for the entire cycle. |
| 879 | * automatically for non-aligned addresses. | ||
| 880 | */ | 879 | */ |
| 881 | if ((uintptr_t)addr & 0x1) { | 880 | if ((uintptr_t)addr & 0x1) { |
| 882 | *(u8 *)buf = ioread8(addr); | 881 | *(u8 *)buf = ioread8(addr); |
| @@ -896,9 +895,9 @@ static ssize_t ca91cx42_master_read(struct vme_master_resource *image, | |||
| 896 | } | 895 | } |
| 897 | 896 | ||
| 898 | count32 = (count - done) & ~0x3; | 897 | count32 = (count - done) & ~0x3; |
| 899 | if (count32 > 0) { | 898 | while (done < count32) { |
| 900 | memcpy_fromio(buf + done, addr + done, (unsigned int)count); | 899 | *(u32 *)(buf + done) = ioread32(addr + done); |
| 901 | done += count32; | 900 | done += 4; |
| 902 | } | 901 | } |
| 903 | 902 | ||
| 904 | if ((count - done) & 0x2) { | 903 | if ((count - done) & 0x2) { |
| @@ -930,7 +929,7 @@ static ssize_t ca91cx42_master_write(struct vme_master_resource *image, | |||
| 930 | spin_lock(&image->lock); | 929 | spin_lock(&image->lock); |
| 931 | 930 | ||
| 932 | /* Here we apply for the same strategy we do in master_read | 931 | /* Here we apply for the same strategy we do in master_read |
| 933 | * function in order to assure D16 cycle when required. | 932 | * function in order to assure the correct cycles. |
| 934 | */ | 933 | */ |
| 935 | if ((uintptr_t)addr & 0x1) { | 934 | if ((uintptr_t)addr & 0x1) { |
| 936 | iowrite8(*(u8 *)buf, addr); | 935 | iowrite8(*(u8 *)buf, addr); |
| @@ -950,9 +949,9 @@ static ssize_t ca91cx42_master_write(struct vme_master_resource *image, | |||
| 950 | } | 949 | } |
| 951 | 950 | ||
| 952 | count32 = (count - done) & ~0x3; | 951 | count32 = (count - done) & ~0x3; |
| 953 | if (count32 > 0) { | 952 | while (done < count32) { |
| 954 | memcpy_toio(addr + done, buf + done, count32); | 953 | iowrite32(*(u32 *)(buf + done), addr + done); |
| 955 | done += count32; | 954 | done += 4; |
| 956 | } | 955 | } |
| 957 | 956 | ||
| 958 | if ((count - done) & 0x2) { | 957 | if ((count - done) & 0x2) { |
diff --git a/drivers/vme/bridges/vme_tsi148.c b/drivers/vme/bridges/vme_tsi148.c index 9911cd5fddb5..06990c6a1a69 100644 --- a/drivers/vme/bridges/vme_tsi148.c +++ b/drivers/vme/bridges/vme_tsi148.c | |||
| @@ -1276,8 +1276,8 @@ static ssize_t tsi148_master_read(struct vme_master_resource *image, void *buf, | |||
| 1276 | spin_lock(&image->lock); | 1276 | spin_lock(&image->lock); |
| 1277 | 1277 | ||
| 1278 | /* The following code handles VME address alignment. We cannot use | 1278 | /* The following code handles VME address alignment. We cannot use |
| 1279 | * memcpy_xxx directly here because it may cut small data transfers in | 1279 | * memcpy_xxx here because it may cut data transfers in to 8-bit |
| 1280 | * to 8-bit cycles, thus making D16 cycle impossible. | 1280 | * cycles when D16 or D32 cycles are required on the VME bus. |
| 1281 | * On the other hand, the bridge itself assures that the maximum data | 1281 | * On the other hand, the bridge itself assures that the maximum data |
| 1282 | * cycle configured for the transfer is used and splits it | 1282 | * cycle configured for the transfer is used and splits it |
| 1283 | * automatically for non-aligned addresses, so we don't want the | 1283 | * automatically for non-aligned addresses, so we don't want the |
| @@ -1301,9 +1301,9 @@ static ssize_t tsi148_master_read(struct vme_master_resource *image, void *buf, | |||
| 1301 | } | 1301 | } |
| 1302 | 1302 | ||
| 1303 | count32 = (count - done) & ~0x3; | 1303 | count32 = (count - done) & ~0x3; |
| 1304 | if (count32 > 0) { | 1304 | while (done < count32) { |
| 1305 | memcpy_fromio(buf + done, addr + done, count32); | 1305 | *(u32 *)(buf + done) = ioread32(addr + done); |
| 1306 | done += count32; | 1306 | done += 4; |
| 1307 | } | 1307 | } |
| 1308 | 1308 | ||
| 1309 | if ((count - done) & 0x2) { | 1309 | if ((count - done) & 0x2) { |
| @@ -1363,7 +1363,7 @@ static ssize_t tsi148_master_write(struct vme_master_resource *image, void *buf, | |||
| 1363 | spin_lock(&image->lock); | 1363 | spin_lock(&image->lock); |
| 1364 | 1364 | ||
| 1365 | /* Here we apply for the same strategy we do in master_read | 1365 | /* Here we apply for the same strategy we do in master_read |
| 1366 | * function in order to assure D16 cycle when required. | 1366 | * function in order to assure the correct cycles. |
| 1367 | */ | 1367 | */ |
| 1368 | if ((uintptr_t)addr & 0x1) { | 1368 | if ((uintptr_t)addr & 0x1) { |
| 1369 | iowrite8(*(u8 *)buf, addr); | 1369 | iowrite8(*(u8 *)buf, addr); |
| @@ -1383,9 +1383,9 @@ static ssize_t tsi148_master_write(struct vme_master_resource *image, void *buf, | |||
| 1383 | } | 1383 | } |
| 1384 | 1384 | ||
| 1385 | count32 = (count - done) & ~0x3; | 1385 | count32 = (count - done) & ~0x3; |
| 1386 | if (count32 > 0) { | 1386 | while (done < count32) { |
| 1387 | memcpy_toio(addr + done, buf + done, count32); | 1387 | iowrite32(*(u32 *)(buf + done), addr + done); |
| 1388 | done += count32; | 1388 | done += 4; |
| 1389 | } | 1389 | } |
| 1390 | 1390 | ||
| 1391 | if ((count - done) & 0x2) { | 1391 | if ((count - done) & 0x2) { |
diff --git a/drivers/w1/masters/ds2490.c b/drivers/w1/masters/ds2490.c index 4f7e1d770f81..7404ad3062b7 100644 --- a/drivers/w1/masters/ds2490.c +++ b/drivers/w1/masters/ds2490.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * dscore.c | 2 | * ds2490.c USB to one wire bridge |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 2004 Evgeniy Polyakov <zbr@ioremap.net> | 4 | * Copyright (c) 2004 Evgeniy Polyakov <zbr@ioremap.net> |
| 5 | * | 5 | * |
| @@ -28,6 +28,10 @@ | |||
| 28 | #include "../w1_int.h" | 28 | #include "../w1_int.h" |
| 29 | #include "../w1.h" | 29 | #include "../w1.h" |
| 30 | 30 | ||
| 31 | /* USB Standard */ | ||
| 32 | /* USB Control request vendor type */ | ||
| 33 | #define VENDOR 0x40 | ||
| 34 | |||
| 31 | /* COMMAND TYPE CODES */ | 35 | /* COMMAND TYPE CODES */ |
| 32 | #define CONTROL_CMD 0x00 | 36 | #define CONTROL_CMD 0x00 |
| 33 | #define COMM_CMD 0x01 | 37 | #define COMM_CMD 0x01 |
| @@ -107,6 +111,8 @@ | |||
| 107 | #define ST_HALT 0x10 /* DS2490 is currently halted */ | 111 | #define ST_HALT 0x10 /* DS2490 is currently halted */ |
| 108 | #define ST_IDLE 0x20 /* DS2490 is currently idle */ | 112 | #define ST_IDLE 0x20 /* DS2490 is currently idle */ |
| 109 | #define ST_EPOF 0x80 | 113 | #define ST_EPOF 0x80 |
| 114 | /* Status transfer size, 16 bytes status, 16 byte result flags */ | ||
| 115 | #define ST_SIZE 0x20 | ||
| 110 | 116 | ||
| 111 | /* Result Register flags */ | 117 | /* Result Register flags */ |
| 112 | #define RR_DETECT 0xA5 /* New device detected */ | 118 | #define RR_DETECT 0xA5 /* New device detected */ |
| @@ -198,7 +204,7 @@ static int ds_send_control_cmd(struct ds_device *dev, u16 value, u16 index) | |||
| 198 | int err; | 204 | int err; |
| 199 | 205 | ||
| 200 | err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]), | 206 | err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]), |
| 201 | CONTROL_CMD, 0x40, value, index, NULL, 0, 1000); | 207 | CONTROL_CMD, VENDOR, value, index, NULL, 0, 1000); |
| 202 | if (err < 0) { | 208 | if (err < 0) { |
| 203 | printk(KERN_ERR "Failed to send command control message %x.%x: err=%d.\n", | 209 | printk(KERN_ERR "Failed to send command control message %x.%x: err=%d.\n", |
| 204 | value, index, err); | 210 | value, index, err); |
| @@ -213,7 +219,7 @@ static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index) | |||
| 213 | int err; | 219 | int err; |
| 214 | 220 | ||
| 215 | err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]), | 221 | err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]), |
| 216 | MODE_CMD, 0x40, value, index, NULL, 0, 1000); | 222 | MODE_CMD, VENDOR, value, index, NULL, 0, 1000); |
| 217 | if (err < 0) { | 223 | if (err < 0) { |
| 218 | printk(KERN_ERR "Failed to send mode control message %x.%x: err=%d.\n", | 224 | printk(KERN_ERR "Failed to send mode control message %x.%x: err=%d.\n", |
| 219 | value, index, err); | 225 | value, index, err); |
| @@ -228,7 +234,7 @@ static int ds_send_control(struct ds_device *dev, u16 value, u16 index) | |||
| 228 | int err; | 234 | int err; |
| 229 | 235 | ||
| 230 | err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]), | 236 | err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, dev->ep[EP_CONTROL]), |
| 231 | COMM_CMD, 0x40, value, index, NULL, 0, 1000); | 237 | COMM_CMD, VENDOR, value, index, NULL, 0, 1000); |
| 232 | if (err < 0) { | 238 | if (err < 0) { |
| 233 | printk(KERN_ERR "Failed to send control message %x.%x: err=%d.\n", | 239 | printk(KERN_ERR "Failed to send control message %x.%x: err=%d.\n", |
| 234 | value, index, err); | 240 | value, index, err); |
| @@ -246,7 +252,8 @@ static int ds_recv_status_nodump(struct ds_device *dev, struct ds_status *st, | |||
| 246 | memset(st, 0, sizeof(*st)); | 252 | memset(st, 0, sizeof(*st)); |
| 247 | 253 | ||
| 248 | count = 0; | 254 | count = 0; |
| 249 | err = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_STATUS]), buf, size, &count, 100); | 255 | err = usb_interrupt_msg(dev->udev, usb_rcvintpipe(dev->udev, |
| 256 | dev->ep[EP_STATUS]), buf, size, &count, 100); | ||
| 250 | if (err < 0) { | 257 | if (err < 0) { |
| 251 | printk(KERN_ERR "Failed to read 1-wire data from 0x%x: err=%d.\n", dev->ep[EP_STATUS], err); | 258 | printk(KERN_ERR "Failed to read 1-wire data from 0x%x: err=%d.\n", dev->ep[EP_STATUS], err); |
| 252 | return err; | 259 | return err; |
| @@ -353,7 +360,7 @@ static int ds_recv_data(struct ds_device *dev, unsigned char *buf, int size) | |||
| 353 | err = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN]), | 360 | err = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN]), |
| 354 | buf, size, &count, 1000); | 361 | buf, size, &count, 1000); |
| 355 | if (err < 0) { | 362 | if (err < 0) { |
| 356 | u8 buf[0x20]; | 363 | u8 buf[ST_SIZE]; |
| 357 | int count; | 364 | int count; |
| 358 | 365 | ||
| 359 | printk(KERN_INFO "Clearing ep0x%x.\n", dev->ep[EP_DATA_IN]); | 366 | printk(KERN_INFO "Clearing ep0x%x.\n", dev->ep[EP_DATA_IN]); |
| @@ -398,7 +405,7 @@ int ds_stop_pulse(struct ds_device *dev, int limit) | |||
| 398 | { | 405 | { |
| 399 | struct ds_status st; | 406 | struct ds_status st; |
| 400 | int count = 0, err = 0; | 407 | int count = 0, err = 0; |
| 401 | u8 buf[0x20]; | 408 | u8 buf[ST_SIZE]; |
| 402 | 409 | ||
| 403 | do { | 410 | do { |
| 404 | err = ds_send_control(dev, CTL_HALT_EXE_IDLE, 0); | 411 | err = ds_send_control(dev, CTL_HALT_EXE_IDLE, 0); |
| @@ -450,10 +457,11 @@ int ds_detect(struct ds_device *dev, struct ds_status *st) | |||
| 450 | 457 | ||
| 451 | static int ds_wait_status(struct ds_device *dev, struct ds_status *st) | 458 | static int ds_wait_status(struct ds_device *dev, struct ds_status *st) |
| 452 | { | 459 | { |
| 453 | u8 buf[0x20]; | 460 | u8 buf[ST_SIZE]; |
| 454 | int err, count = 0; | 461 | int err, count = 0; |
| 455 | 462 | ||
| 456 | do { | 463 | do { |
| 464 | st->status = 0; | ||
| 457 | err = ds_recv_status_nodump(dev, st, buf, sizeof(buf)); | 465 | err = ds_recv_status_nodump(dev, st, buf, sizeof(buf)); |
| 458 | #if 0 | 466 | #if 0 |
| 459 | if (err >= 0) { | 467 | if (err >= 0) { |
| @@ -464,7 +472,7 @@ static int ds_wait_status(struct ds_device *dev, struct ds_status *st) | |||
| 464 | printk("\n"); | 472 | printk("\n"); |
| 465 | } | 473 | } |
| 466 | #endif | 474 | #endif |
| 467 | } while (!(buf[0x08] & ST_IDLE) && !(err < 0) && ++count < 100); | 475 | } while (!(st->status & ST_IDLE) && !(err < 0) && ++count < 100); |
| 468 | 476 | ||
| 469 | if (err >= 16 && st->status & ST_EPOF) { | 477 | if (err >= 16 && st->status & ST_EPOF) { |
| 470 | printk(KERN_INFO "Resetting device after ST_EPOF.\n"); | 478 | printk(KERN_INFO "Resetting device after ST_EPOF.\n"); |
| @@ -690,37 +698,106 @@ static int ds_write_block(struct ds_device *dev, u8 *buf, int len) | |||
| 690 | return !(err == len); | 698 | return !(err == len); |
| 691 | } | 699 | } |
| 692 | 700 | ||
| 693 | #if 0 | 701 | static void ds9490r_search(void *data, struct w1_master *master, |
| 694 | 702 | u8 search_type, w1_slave_found_callback callback) | |
| 695 | static int ds_search(struct ds_device *dev, u64 init, u64 *buf, u8 id_number, int conditional_search) | ||
| 696 | { | 703 | { |
| 704 | /* When starting with an existing id, the first id returned will | ||
| 705 | * be that device (if it is still on the bus most likely). | ||
| 706 | * | ||
| 707 | * If the number of devices found is less than or equal to the | ||
| 708 | * search_limit, that number of IDs will be returned. If there are | ||
| 709 | * more, search_limit IDs will be returned followed by a non-zero | ||
| 710 | * discrepency value. | ||
| 711 | */ | ||
| 712 | struct ds_device *dev = data; | ||
| 697 | int err; | 713 | int err; |
| 698 | u16 value, index; | 714 | u16 value, index; |
| 699 | struct ds_status st; | 715 | struct ds_status st; |
| 716 | u8 st_buf[ST_SIZE]; | ||
| 717 | int search_limit; | ||
| 718 | int found = 0; | ||
| 719 | int i; | ||
| 700 | 720 | ||
| 701 | memset(buf, 0, sizeof(buf)); | 721 | /* DS18b20 spec, 13.16 ms per device, 75 per second, sleep for |
| 722 | * discovering 8 devices (1 bulk transfer and 1/2 FIFO size) at a time. | ||
| 723 | */ | ||
| 724 | const unsigned long jtime = msecs_to_jiffies(1000*8/75); | ||
| 725 | /* FIFO 128 bytes, bulk packet size 64, read a multiple of the | ||
| 726 | * packet size. | ||
| 727 | */ | ||
| 728 | u64 buf[2*64/8]; | ||
| 702 | 729 | ||
| 703 | err = ds_send_data(ds_dev, (unsigned char *)&init, 8); | 730 | mutex_lock(&master->bus_mutex); |
| 704 | if (err) | ||
| 705 | return err; | ||
| 706 | 731 | ||
| 707 | ds_wait_status(ds_dev, &st); | 732 | /* address to start searching at */ |
| 733 | if (ds_send_data(dev, (u8 *)&master->search_id, 8) < 0) | ||
| 734 | goto search_out; | ||
| 735 | master->search_id = 0; | ||
| 708 | 736 | ||
| 709 | value = COMM_SEARCH_ACCESS | COMM_IM | COMM_SM | COMM_F | COMM_RTS; | 737 | value = COMM_SEARCH_ACCESS | COMM_IM | COMM_RST | COMM_SM | COMM_F | |
| 710 | index = (conditional_search ? 0xEC : 0xF0) | (id_number << 8); | 738 | COMM_RTS; |
| 711 | err = ds_send_control(ds_dev, value, index); | 739 | search_limit = master->max_slave_count; |
| 712 | if (err) | 740 | if (search_limit > 255) |
| 713 | return err; | 741 | search_limit = 0; |
| 742 | index = search_type | (search_limit << 8); | ||
| 743 | if (ds_send_control(dev, value, index) < 0) | ||
| 744 | goto search_out; | ||
| 714 | 745 | ||
| 715 | ds_wait_status(ds_dev, &st); | 746 | do { |
| 747 | schedule_timeout(jtime); | ||
| 716 | 748 | ||
| 717 | err = ds_recv_data(ds_dev, (unsigned char *)buf, 8*id_number); | 749 | if (ds_recv_status_nodump(dev, &st, st_buf, sizeof(st_buf)) < |
| 718 | if (err < 0) | 750 | sizeof(st)) { |
| 719 | return err; | 751 | break; |
| 752 | } | ||
| 720 | 753 | ||
| 721 | return err/8; | 754 | if (st.data_in_buffer_status) { |
| 755 | /* Bulk in can receive partial ids, but when it does | ||
| 756 | * they fail crc and will be discarded anyway. | ||
| 757 | * That has only been seen when status in buffer | ||
| 758 | * is 0 and bulk is read anyway, so don't read | ||
| 759 | * bulk without first checking if status says there | ||
| 760 | * is data to read. | ||
| 761 | */ | ||
| 762 | err = ds_recv_data(dev, (u8 *)buf, sizeof(buf)); | ||
| 763 | if (err < 0) | ||
| 764 | break; | ||
| 765 | for (i = 0; i < err/8; ++i) { | ||
| 766 | ++found; | ||
| 767 | if (found <= search_limit) | ||
| 768 | callback(master, buf[i]); | ||
| 769 | /* can't know if there will be a discrepancy | ||
| 770 | * value after until the next id */ | ||
| 771 | if (found == search_limit) | ||
| 772 | master->search_id = buf[i]; | ||
| 773 | } | ||
| 774 | } | ||
| 775 | |||
| 776 | if (test_bit(W1_ABORT_SEARCH, &master->flags)) | ||
| 777 | break; | ||
| 778 | } while (!(st.status & (ST_IDLE | ST_HALT))); | ||
| 779 | |||
| 780 | /* only continue the search if some weren't found */ | ||
| 781 | if (found <= search_limit) { | ||
| 782 | master->search_id = 0; | ||
| 783 | } else if (!test_bit(W1_WARN_MAX_COUNT, &master->flags)) { | ||
| 784 | /* Only max_slave_count will be scanned in a search, | ||
| 785 | * but it will start where it left off next search | ||
| 786 | * until all ids are identified and then it will start | ||
| 787 | * over. A continued search will report the previous | ||
| 788 | * last id as the first id (provided it is still on the | ||
| 789 | * bus). | ||
| 790 | */ | ||
| 791 | dev_info(&dev->udev->dev, "%s: max_slave_count %d reached, " | ||
| 792 | "will continue next search.\n", __func__, | ||
| 793 | master->max_slave_count); | ||
| 794 | set_bit(W1_WARN_MAX_COUNT, &master->flags); | ||
| 795 | } | ||
| 796 | search_out: | ||
| 797 | mutex_unlock(&master->bus_mutex); | ||
| 722 | } | 798 | } |
| 723 | 799 | ||
| 800 | #if 0 | ||
| 724 | static int ds_match_access(struct ds_device *dev, u64 init) | 801 | static int ds_match_access(struct ds_device *dev, u64 init) |
| 725 | { | 802 | { |
| 726 | int err; | 803 | int err; |
| @@ -894,6 +971,7 @@ static int ds_w1_init(struct ds_device *dev) | |||
| 894 | dev->master.write_block = &ds9490r_write_block; | 971 | dev->master.write_block = &ds9490r_write_block; |
| 895 | dev->master.reset_bus = &ds9490r_reset; | 972 | dev->master.reset_bus = &ds9490r_reset; |
| 896 | dev->master.set_pullup = &ds9490r_set_pullup; | 973 | dev->master.set_pullup = &ds9490r_set_pullup; |
| 974 | dev->master.search = &ds9490r_search; | ||
| 897 | 975 | ||
| 898 | return w1_add_master_device(&dev->master); | 976 | return w1_add_master_device(&dev->master); |
| 899 | } | 977 | } |
| @@ -910,15 +988,13 @@ static int ds_probe(struct usb_interface *intf, | |||
| 910 | struct usb_endpoint_descriptor *endpoint; | 988 | struct usb_endpoint_descriptor *endpoint; |
| 911 | struct usb_host_interface *iface_desc; | 989 | struct usb_host_interface *iface_desc; |
| 912 | struct ds_device *dev; | 990 | struct ds_device *dev; |
| 913 | int i, err; | 991 | int i, err, alt; |
| 914 | 992 | ||
| 915 | dev = kmalloc(sizeof(struct ds_device), GFP_KERNEL); | 993 | dev = kzalloc(sizeof(struct ds_device), GFP_KERNEL); |
| 916 | if (!dev) { | 994 | if (!dev) { |
| 917 | printk(KERN_INFO "Failed to allocate new DS9490R structure.\n"); | 995 | printk(KERN_INFO "Failed to allocate new DS9490R structure.\n"); |
| 918 | return -ENOMEM; | 996 | return -ENOMEM; |
| 919 | } | 997 | } |
| 920 | dev->spu_sleep = 0; | ||
| 921 | dev->spu_bit = 0; | ||
| 922 | dev->udev = usb_get_dev(udev); | 998 | dev->udev = usb_get_dev(udev); |
| 923 | if (!dev->udev) { | 999 | if (!dev->udev) { |
| 924 | err = -ENOMEM; | 1000 | err = -ENOMEM; |
| @@ -928,20 +1004,25 @@ static int ds_probe(struct usb_interface *intf, | |||
| 928 | 1004 | ||
| 929 | usb_set_intfdata(intf, dev); | 1005 | usb_set_intfdata(intf, dev); |
| 930 | 1006 | ||
| 931 | err = usb_set_interface(dev->udev, intf->altsetting[0].desc.bInterfaceNumber, 3); | 1007 | err = usb_reset_configuration(dev->udev); |
| 932 | if (err) { | 1008 | if (err) { |
| 933 | printk(KERN_ERR "Failed to set alternative setting 3 for %d interface: err=%d.\n", | 1009 | dev_err(&dev->udev->dev, |
| 934 | intf->altsetting[0].desc.bInterfaceNumber, err); | 1010 | "Failed to reset configuration: err=%d.\n", err); |
| 935 | goto err_out_clear; | 1011 | goto err_out_clear; |
| 936 | } | 1012 | } |
| 937 | 1013 | ||
| 938 | err = usb_reset_configuration(dev->udev); | 1014 | /* alternative 3, 1ms interrupt (greatly speeds search), 64 byte bulk */ |
| 1015 | alt = 3; | ||
| 1016 | err = usb_set_interface(dev->udev, | ||
| 1017 | intf->altsetting[alt].desc.bInterfaceNumber, alt); | ||
| 939 | if (err) { | 1018 | if (err) { |
| 940 | printk(KERN_ERR "Failed to reset configuration: err=%d.\n", err); | 1019 | dev_err(&dev->udev->dev, "Failed to set alternative setting %d " |
| 1020 | "for %d interface: err=%d.\n", alt, | ||
| 1021 | intf->altsetting[alt].desc.bInterfaceNumber, err); | ||
| 941 | goto err_out_clear; | 1022 | goto err_out_clear; |
| 942 | } | 1023 | } |
| 943 | 1024 | ||
| 944 | iface_desc = &intf->altsetting[0]; | 1025 | iface_desc = &intf->altsetting[alt]; |
| 945 | if (iface_desc->desc.bNumEndpoints != NUM_EP-1) { | 1026 | if (iface_desc->desc.bNumEndpoints != NUM_EP-1) { |
| 946 | printk(KERN_INFO "Num endpoints=%d. It is not DS9490R.\n", iface_desc->desc.bNumEndpoints); | 1027 | printk(KERN_INFO "Num endpoints=%d. It is not DS9490R.\n", iface_desc->desc.bNumEndpoints); |
| 947 | err = -EINVAL; | 1028 | err = -EINVAL; |
diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c index 9709b8b484ba..1d111e56c8c8 100644 --- a/drivers/w1/masters/w1-gpio.c +++ b/drivers/w1/masters/w1-gpio.c | |||
| @@ -89,11 +89,22 @@ static int w1_gpio_probe_dt(struct platform_device *pdev) | |||
| 89 | pdata->is_open_drain = 1; | 89 | pdata->is_open_drain = 1; |
| 90 | 90 | ||
| 91 | gpio = of_get_gpio(np, 0); | 91 | gpio = of_get_gpio(np, 0); |
| 92 | if (gpio < 0) | 92 | if (gpio < 0) { |
| 93 | if (gpio != -EPROBE_DEFER) | ||
| 94 | dev_err(&pdev->dev, | ||
| 95 | "Failed to parse gpio property for data pin (%d)\n", | ||
| 96 | gpio); | ||
| 97 | |||
| 93 | return gpio; | 98 | return gpio; |
| 99 | } | ||
| 94 | pdata->pin = gpio; | 100 | pdata->pin = gpio; |
| 95 | 101 | ||
| 96 | pdata->ext_pullup_enable_pin = of_get_gpio(np, 1); | 102 | gpio = of_get_gpio(np, 1); |
| 103 | if (gpio == -EPROBE_DEFER) | ||
| 104 | return gpio; | ||
| 105 | /* ignore other errors as the pullup gpio is optional */ | ||
| 106 | pdata->ext_pullup_enable_pin = gpio; | ||
| 107 | |||
| 97 | pdev->dev.platform_data = pdata; | 108 | pdev->dev.platform_data = pdata; |
| 98 | 109 | ||
| 99 | return 0; | 110 | return 0; |
| @@ -107,10 +118,8 @@ static int w1_gpio_probe(struct platform_device *pdev) | |||
| 107 | 118 | ||
| 108 | if (of_have_populated_dt()) { | 119 | if (of_have_populated_dt()) { |
| 109 | err = w1_gpio_probe_dt(pdev); | 120 | err = w1_gpio_probe_dt(pdev); |
| 110 | if (err < 0) { | 121 | if (err < 0) |
| 111 | dev_err(&pdev->dev, "Failed to parse DT\n"); | ||
| 112 | return err; | 122 | return err; |
| 113 | } | ||
| 114 | } | 123 | } |
| 115 | 124 | ||
| 116 | pdata = dev_get_platdata(&pdev->dev); | 125 | pdata = dev_get_platdata(&pdev->dev); |
diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c index 8b5ff33f72cf..1f11a20a8ab9 100644 --- a/drivers/w1/slaves/w1_therm.c +++ b/drivers/w1/slaves/w1_therm.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #include <linux/sched.h> | 27 | #include <linux/sched.h> |
| 28 | #include <linux/device.h> | 28 | #include <linux/device.h> |
| 29 | #include <linux/types.h> | 29 | #include <linux/types.h> |
| 30 | #include <linux/slab.h> | ||
| 30 | #include <linux/delay.h> | 31 | #include <linux/delay.h> |
| 31 | 32 | ||
| 32 | #include "../w1.h" | 33 | #include "../w1.h" |
| @@ -58,6 +59,19 @@ MODULE_ALIAS("w1-family-" __stringify(W1_THERM_DS28EA00)); | |||
| 58 | static int w1_strong_pullup = 1; | 59 | static int w1_strong_pullup = 1; |
| 59 | module_param_named(strong_pullup, w1_strong_pullup, int, 0); | 60 | module_param_named(strong_pullup, w1_strong_pullup, int, 0); |
| 60 | 61 | ||
| 62 | static int w1_therm_add_slave(struct w1_slave *sl) | ||
| 63 | { | ||
| 64 | sl->family_data = kzalloc(9, GFP_KERNEL); | ||
| 65 | if (!sl->family_data) | ||
| 66 | return -ENOMEM; | ||
| 67 | return 0; | ||
| 68 | } | ||
| 69 | |||
| 70 | static void w1_therm_remove_slave(struct w1_slave *sl) | ||
| 71 | { | ||
| 72 | kfree(sl->family_data); | ||
| 73 | sl->family_data = NULL; | ||
| 74 | } | ||
| 61 | 75 | ||
| 62 | static ssize_t w1_slave_show(struct device *device, | 76 | static ssize_t w1_slave_show(struct device *device, |
| 63 | struct device_attribute *attr, char *buf); | 77 | struct device_attribute *attr, char *buf); |
| @@ -71,6 +85,8 @@ static struct attribute *w1_therm_attrs[] = { | |||
| 71 | ATTRIBUTE_GROUPS(w1_therm); | 85 | ATTRIBUTE_GROUPS(w1_therm); |
| 72 | 86 | ||
| 73 | static struct w1_family_ops w1_therm_fops = { | 87 | static struct w1_family_ops w1_therm_fops = { |
| 88 | .add_slave = w1_therm_add_slave, | ||
| 89 | .remove_slave = w1_therm_remove_slave, | ||
| 74 | .groups = w1_therm_groups, | 90 | .groups = w1_therm_groups, |
| 75 | }; | 91 | }; |
| 76 | 92 | ||
| @@ -253,12 +269,13 @@ static ssize_t w1_slave_show(struct device *device, | |||
| 253 | c -= snprintf(buf + PAGE_SIZE - c, c, ": crc=%02x %s\n", | 269 | c -= snprintf(buf + PAGE_SIZE - c, c, ": crc=%02x %s\n", |
| 254 | crc, (verdict) ? "YES" : "NO"); | 270 | crc, (verdict) ? "YES" : "NO"); |
| 255 | if (verdict) | 271 | if (verdict) |
| 256 | memcpy(sl->rom, rom, sizeof(sl->rom)); | 272 | memcpy(sl->family_data, rom, sizeof(rom)); |
| 257 | else | 273 | else |
| 258 | dev_warn(device, "Read failed CRC check\n"); | 274 | dev_warn(device, "Read failed CRC check\n"); |
| 259 | 275 | ||
| 260 | for (i = 0; i < 9; ++i) | 276 | for (i = 0; i < 9; ++i) |
| 261 | c -= snprintf(buf + PAGE_SIZE - c, c, "%02x ", sl->rom[i]); | 277 | c -= snprintf(buf + PAGE_SIZE - c, c, "%02x ", |
| 278 | ((u8 *)sl->family_data)[i]); | ||
| 262 | 279 | ||
| 263 | c -= snprintf(buf + PAGE_SIZE - c, c, "t=%d\n", | 280 | c -= snprintf(buf + PAGE_SIZE - c, c, "t=%d\n", |
| 264 | w1_convert_temp(rom, sl->family->fid)); | 281 | w1_convert_temp(rom, sl->family->fid)); |
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index 66efa96c4603..b96f61b15dc6 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c | |||
| @@ -46,18 +46,29 @@ MODULE_AUTHOR("Evgeniy Polyakov <zbr@ioremap.net>"); | |||
| 46 | MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol."); | 46 | MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol."); |
| 47 | 47 | ||
| 48 | static int w1_timeout = 10; | 48 | static int w1_timeout = 10; |
| 49 | int w1_max_slave_count = 10; | 49 | int w1_max_slave_count = 64; |
| 50 | int w1_max_slave_ttl = 10; | 50 | int w1_max_slave_ttl = 10; |
| 51 | 51 | ||
| 52 | module_param_named(timeout, w1_timeout, int, 0); | 52 | module_param_named(timeout, w1_timeout, int, 0); |
| 53 | MODULE_PARM_DESC(timeout, "time in seconds between automatic slave searches"); | ||
| 54 | /* A search stops when w1_max_slave_count devices have been found in that | ||
| 55 | * search. The next search will start over and detect the same set of devices | ||
| 56 | * on a static 1-wire bus. Memory is not allocated based on this number, just | ||
| 57 | * on the number of devices known to the kernel. Having a high number does not | ||
| 58 | * consume additional resources. As a special case, if there is only one | ||
| 59 | * device on the network and w1_max_slave_count is set to 1, the device id can | ||
| 60 | * be read directly skipping the normal slower search process. | ||
| 61 | */ | ||
| 53 | module_param_named(max_slave_count, w1_max_slave_count, int, 0); | 62 | module_param_named(max_slave_count, w1_max_slave_count, int, 0); |
| 63 | MODULE_PARM_DESC(max_slave_count, | ||
| 64 | "maximum number of slaves detected in a search"); | ||
| 54 | module_param_named(slave_ttl, w1_max_slave_ttl, int, 0); | 65 | module_param_named(slave_ttl, w1_max_slave_ttl, int, 0); |
| 66 | MODULE_PARM_DESC(slave_ttl, | ||
| 67 | "Number of searches not seeing a slave before it will be removed"); | ||
| 55 | 68 | ||
| 56 | DEFINE_MUTEX(w1_mlock); | 69 | DEFINE_MUTEX(w1_mlock); |
| 57 | LIST_HEAD(w1_masters); | 70 | LIST_HEAD(w1_masters); |
| 58 | 71 | ||
| 59 | static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn); | ||
| 60 | |||
| 61 | static int w1_master_match(struct device *dev, struct device_driver *drv) | 72 | static int w1_master_match(struct device *dev, struct device_driver *drv) |
| 62 | { | 73 | { |
| 63 | return 1; | 74 | return 1; |
| @@ -81,19 +92,10 @@ static void w1_slave_release(struct device *dev) | |||
| 81 | { | 92 | { |
| 82 | struct w1_slave *sl = dev_to_w1_slave(dev); | 93 | struct w1_slave *sl = dev_to_w1_slave(dev); |
| 83 | 94 | ||
| 84 | dev_dbg(dev, "%s: Releasing %s.\n", __func__, sl->name); | 95 | dev_dbg(dev, "%s: Releasing %s [%p]\n", __func__, sl->name, sl); |
| 85 | |||
| 86 | while (atomic_read(&sl->refcnt)) { | ||
| 87 | dev_dbg(dev, "Waiting for %s to become free: refcnt=%d.\n", | ||
| 88 | sl->name, atomic_read(&sl->refcnt)); | ||
| 89 | if (msleep_interruptible(1000)) | ||
| 90 | flush_signals(current); | ||
| 91 | } | ||
| 92 | 96 | ||
| 93 | w1_family_put(sl->family); | 97 | w1_family_put(sl->family); |
| 94 | sl->master->slave_count--; | 98 | sl->master->slave_count--; |
| 95 | |||
| 96 | complete(&sl->released); | ||
| 97 | } | 99 | } |
| 98 | 100 | ||
| 99 | static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf) | 101 | static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf) |
| @@ -243,7 +245,9 @@ static ssize_t w1_master_attribute_store_search(struct device * dev, | |||
| 243 | mutex_lock(&md->mutex); | 245 | mutex_lock(&md->mutex); |
| 244 | md->search_count = tmp; | 246 | md->search_count = tmp; |
| 245 | mutex_unlock(&md->mutex); | 247 | mutex_unlock(&md->mutex); |
| 246 | wake_up_process(md->thread); | 248 | /* Only wake if it is going to be searching. */ |
| 249 | if (tmp) | ||
| 250 | wake_up_process(md->thread); | ||
| 247 | 251 | ||
| 248 | return count; | 252 | return count; |
| 249 | } | 253 | } |
| @@ -277,7 +281,6 @@ static ssize_t w1_master_attribute_store_pullup(struct device *dev, | |||
| 277 | mutex_lock(&md->mutex); | 281 | mutex_lock(&md->mutex); |
| 278 | md->enable_pullup = tmp; | 282 | md->enable_pullup = tmp; |
| 279 | mutex_unlock(&md->mutex); | 283 | mutex_unlock(&md->mutex); |
| 280 | wake_up_process(md->thread); | ||
| 281 | 284 | ||
| 282 | return count; | 285 | return count; |
| 283 | } | 286 | } |
| @@ -314,6 +317,24 @@ static ssize_t w1_master_attribute_show_timeout(struct device *dev, struct devic | |||
| 314 | return count; | 317 | return count; |
| 315 | } | 318 | } |
| 316 | 319 | ||
| 320 | static ssize_t w1_master_attribute_store_max_slave_count(struct device *dev, | ||
| 321 | struct device_attribute *attr, const char *buf, size_t count) | ||
| 322 | { | ||
| 323 | int tmp; | ||
| 324 | struct w1_master *md = dev_to_w1_master(dev); | ||
| 325 | |||
| 326 | if (kstrtoint(buf, 0, &tmp) == -EINVAL || tmp < 1) | ||
| 327 | return -EINVAL; | ||
| 328 | |||
| 329 | mutex_lock(&md->mutex); | ||
| 330 | md->max_slave_count = tmp; | ||
| 331 | /* allow each time the max_slave_count is updated */ | ||
| 332 | clear_bit(W1_WARN_MAX_COUNT, &md->flags); | ||
| 333 | mutex_unlock(&md->mutex); | ||
| 334 | |||
| 335 | return count; | ||
| 336 | } | ||
| 337 | |||
| 317 | static ssize_t w1_master_attribute_show_max_slave_count(struct device *dev, struct device_attribute *attr, char *buf) | 338 | static ssize_t w1_master_attribute_show_max_slave_count(struct device *dev, struct device_attribute *attr, char *buf) |
| 318 | { | 339 | { |
| 319 | struct w1_master *md = dev_to_w1_master(dev); | 340 | struct w1_master *md = dev_to_w1_master(dev); |
| @@ -352,23 +373,20 @@ static ssize_t w1_master_attribute_show_slaves(struct device *dev, | |||
| 352 | { | 373 | { |
| 353 | struct w1_master *md = dev_to_w1_master(dev); | 374 | struct w1_master *md = dev_to_w1_master(dev); |
| 354 | int c = PAGE_SIZE; | 375 | int c = PAGE_SIZE; |
| 376 | struct list_head *ent, *n; | ||
| 377 | struct w1_slave *sl = NULL; | ||
| 355 | 378 | ||
| 356 | mutex_lock(&md->mutex); | 379 | mutex_lock(&md->list_mutex); |
| 357 | |||
| 358 | if (md->slave_count == 0) | ||
| 359 | c -= snprintf(buf + PAGE_SIZE - c, c, "not found.\n"); | ||
| 360 | else { | ||
| 361 | struct list_head *ent, *n; | ||
| 362 | struct w1_slave *sl; | ||
| 363 | 380 | ||
| 364 | list_for_each_safe(ent, n, &md->slist) { | 381 | list_for_each_safe(ent, n, &md->slist) { |
| 365 | sl = list_entry(ent, struct w1_slave, w1_slave_entry); | 382 | sl = list_entry(ent, struct w1_slave, w1_slave_entry); |
| 366 | 383 | ||
| 367 | c -= snprintf(buf + PAGE_SIZE - c, c, "%s\n", sl->name); | 384 | c -= snprintf(buf + PAGE_SIZE - c, c, "%s\n", sl->name); |
| 368 | } | ||
| 369 | } | 385 | } |
| 386 | if (!sl) | ||
| 387 | c -= snprintf(buf + PAGE_SIZE - c, c, "not found.\n"); | ||
| 370 | 388 | ||
| 371 | mutex_unlock(&md->mutex); | 389 | mutex_unlock(&md->list_mutex); |
| 372 | 390 | ||
| 373 | return PAGE_SIZE - c; | 391 | return PAGE_SIZE - c; |
| 374 | } | 392 | } |
| @@ -422,19 +440,22 @@ static int w1_atoreg_num(struct device *dev, const char *buf, size_t count, | |||
| 422 | } | 440 | } |
| 423 | 441 | ||
| 424 | /* Searches the slaves in the w1_master and returns a pointer or NULL. | 442 | /* Searches the slaves in the w1_master and returns a pointer or NULL. |
| 425 | * Note: must hold the mutex | 443 | * Note: must not hold list_mutex |
| 426 | */ | 444 | */ |
| 427 | static struct w1_slave *w1_slave_search_device(struct w1_master *dev, | 445 | struct w1_slave *w1_slave_search_device(struct w1_master *dev, |
| 428 | struct w1_reg_num *rn) | 446 | struct w1_reg_num *rn) |
| 429 | { | 447 | { |
| 430 | struct w1_slave *sl; | 448 | struct w1_slave *sl; |
| 449 | mutex_lock(&dev->list_mutex); | ||
| 431 | list_for_each_entry(sl, &dev->slist, w1_slave_entry) { | 450 | list_for_each_entry(sl, &dev->slist, w1_slave_entry) { |
| 432 | if (sl->reg_num.family == rn->family && | 451 | if (sl->reg_num.family == rn->family && |
| 433 | sl->reg_num.id == rn->id && | 452 | sl->reg_num.id == rn->id && |
| 434 | sl->reg_num.crc == rn->crc) { | 453 | sl->reg_num.crc == rn->crc) { |
| 454 | mutex_unlock(&dev->list_mutex); | ||
| 435 | return sl; | 455 | return sl; |
| 436 | } | 456 | } |
| 437 | } | 457 | } |
| 458 | mutex_unlock(&dev->list_mutex); | ||
| 438 | return NULL; | 459 | return NULL; |
| 439 | } | 460 | } |
| 440 | 461 | ||
| @@ -491,7 +512,10 @@ static ssize_t w1_master_attribute_store_remove(struct device *dev, | |||
| 491 | mutex_lock(&md->mutex); | 512 | mutex_lock(&md->mutex); |
| 492 | sl = w1_slave_search_device(md, &rn); | 513 | sl = w1_slave_search_device(md, &rn); |
| 493 | if (sl) { | 514 | if (sl) { |
| 494 | w1_slave_detach(sl); | 515 | result = w1_slave_detach(sl); |
| 516 | /* refcnt 0 means it was detached in the call */ | ||
| 517 | if (result == 0) | ||
| 518 | result = count; | ||
| 495 | } else { | 519 | } else { |
| 496 | dev_info(dev, "Device %02x-%012llx doesn't exists\n", rn.family, | 520 | dev_info(dev, "Device %02x-%012llx doesn't exists\n", rn.family, |
| 497 | (unsigned long long)rn.id); | 521 | (unsigned long long)rn.id); |
| @@ -516,7 +540,7 @@ static ssize_t w1_master_attribute_store_remove(struct device *dev, | |||
| 516 | static W1_MASTER_ATTR_RO(name, S_IRUGO); | 540 | static W1_MASTER_ATTR_RO(name, S_IRUGO); |
| 517 | static W1_MASTER_ATTR_RO(slaves, S_IRUGO); | 541 | static W1_MASTER_ATTR_RO(slaves, S_IRUGO); |
| 518 | static W1_MASTER_ATTR_RO(slave_count, S_IRUGO); | 542 | static W1_MASTER_ATTR_RO(slave_count, S_IRUGO); |
| 519 | static W1_MASTER_ATTR_RO(max_slave_count, S_IRUGO); | 543 | static W1_MASTER_ATTR_RW(max_slave_count, S_IRUGO | S_IWUSR | S_IWGRP); |
| 520 | static W1_MASTER_ATTR_RO(attempts, S_IRUGO); | 544 | static W1_MASTER_ATTR_RO(attempts, S_IRUGO); |
| 521 | static W1_MASTER_ATTR_RO(timeout, S_IRUGO); | 545 | static W1_MASTER_ATTR_RO(timeout, S_IRUGO); |
| 522 | static W1_MASTER_ATTR_RO(pointer, S_IRUGO); | 546 | static W1_MASTER_ATTR_RO(pointer, S_IRUGO); |
| @@ -686,12 +710,14 @@ static int __w1_attach_slave_device(struct w1_slave *sl) | |||
| 686 | dev_set_uevent_suppress(&sl->dev, false); | 710 | dev_set_uevent_suppress(&sl->dev, false); |
| 687 | kobject_uevent(&sl->dev.kobj, KOBJ_ADD); | 711 | kobject_uevent(&sl->dev.kobj, KOBJ_ADD); |
| 688 | 712 | ||
| 713 | mutex_lock(&sl->master->list_mutex); | ||
| 689 | list_add_tail(&sl->w1_slave_entry, &sl->master->slist); | 714 | list_add_tail(&sl->w1_slave_entry, &sl->master->slist); |
| 715 | mutex_unlock(&sl->master->list_mutex); | ||
| 690 | 716 | ||
| 691 | return 0; | 717 | return 0; |
| 692 | } | 718 | } |
| 693 | 719 | ||
| 694 | static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) | 720 | int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) |
| 695 | { | 721 | { |
| 696 | struct w1_slave *sl; | 722 | struct w1_slave *sl; |
| 697 | struct w1_family *f; | 723 | struct w1_family *f; |
| @@ -713,8 +739,8 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) | |||
| 713 | 739 | ||
| 714 | memset(&msg, 0, sizeof(msg)); | 740 | memset(&msg, 0, sizeof(msg)); |
| 715 | memcpy(&sl->reg_num, rn, sizeof(sl->reg_num)); | 741 | memcpy(&sl->reg_num, rn, sizeof(sl->reg_num)); |
| 716 | atomic_set(&sl->refcnt, 0); | 742 | atomic_set(&sl->refcnt, 1); |
| 717 | init_completion(&sl->released); | 743 | atomic_inc(&sl->master->refcnt); |
| 718 | 744 | ||
| 719 | /* slave modules need to be loaded in a context with unlocked mutex */ | 745 | /* slave modules need to be loaded in a context with unlocked mutex */ |
| 720 | mutex_unlock(&dev->mutex); | 746 | mutex_unlock(&dev->mutex); |
| @@ -754,23 +780,48 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) | |||
| 754 | return 0; | 780 | return 0; |
| 755 | } | 781 | } |
| 756 | 782 | ||
| 757 | void w1_slave_detach(struct w1_slave *sl) | 783 | int w1_unref_slave(struct w1_slave *sl) |
| 758 | { | 784 | { |
| 759 | struct w1_netlink_msg msg; | 785 | struct w1_master *dev = sl->master; |
| 760 | 786 | int refcnt; | |
| 761 | dev_dbg(&sl->dev, "%s: detaching %s [%p].\n", __func__, sl->name, sl); | 787 | mutex_lock(&dev->list_mutex); |
| 762 | 788 | refcnt = atomic_sub_return(1, &sl->refcnt); | |
| 763 | list_del(&sl->w1_slave_entry); | 789 | if (refcnt == 0) { |
| 764 | 790 | struct w1_netlink_msg msg; | |
| 765 | memset(&msg, 0, sizeof(msg)); | 791 | |
| 766 | memcpy(msg.id.id, &sl->reg_num, sizeof(msg.id)); | 792 | dev_dbg(&sl->dev, "%s: detaching %s [%p].\n", __func__, |
| 767 | msg.type = W1_SLAVE_REMOVE; | 793 | sl->name, sl); |
| 768 | w1_netlink_send(sl->master, &msg); | 794 | |
| 769 | 795 | list_del(&sl->w1_slave_entry); | |
| 770 | device_unregister(&sl->dev); | 796 | |
| 797 | memset(&msg, 0, sizeof(msg)); | ||
| 798 | memcpy(msg.id.id, &sl->reg_num, sizeof(msg.id)); | ||
| 799 | msg.type = W1_SLAVE_REMOVE; | ||
| 800 | w1_netlink_send(sl->master, &msg); | ||
| 801 | |||
| 802 | device_unregister(&sl->dev); | ||
| 803 | #ifdef DEBUG | ||
| 804 | memset(sl, 0, sizeof(*sl)); | ||
| 805 | #endif | ||
| 806 | kfree(sl); | ||
| 807 | } | ||
| 808 | atomic_dec(&dev->refcnt); | ||
| 809 | mutex_unlock(&dev->list_mutex); | ||
| 810 | return refcnt; | ||
| 811 | } | ||
| 771 | 812 | ||
| 772 | wait_for_completion(&sl->released); | 813 | int w1_slave_detach(struct w1_slave *sl) |
| 773 | kfree(sl); | 814 | { |
| 815 | /* Only detach a slave once as it decreases the refcnt each time. */ | ||
| 816 | int destroy_now; | ||
| 817 | mutex_lock(&sl->master->list_mutex); | ||
| 818 | destroy_now = !test_bit(W1_SLAVE_DETACH, &sl->flags); | ||
| 819 | set_bit(W1_SLAVE_DETACH, &sl->flags); | ||
| 820 | mutex_unlock(&sl->master->list_mutex); | ||
| 821 | |||
| 822 | if (destroy_now) | ||
| 823 | destroy_now = !w1_unref_slave(sl); | ||
| 824 | return destroy_now ? 0 : -EBUSY; | ||
| 774 | } | 825 | } |
| 775 | 826 | ||
| 776 | struct w1_master *w1_search_master_id(u32 id) | 827 | struct w1_master *w1_search_master_id(u32 id) |
| @@ -799,7 +850,7 @@ struct w1_slave *w1_search_slave(struct w1_reg_num *id) | |||
| 799 | 850 | ||
| 800 | mutex_lock(&w1_mlock); | 851 | mutex_lock(&w1_mlock); |
| 801 | list_for_each_entry(dev, &w1_masters, w1_master_entry) { | 852 | list_for_each_entry(dev, &w1_masters, w1_master_entry) { |
| 802 | mutex_lock(&dev->mutex); | 853 | mutex_lock(&dev->list_mutex); |
| 803 | list_for_each_entry(sl, &dev->slist, w1_slave_entry) { | 854 | list_for_each_entry(sl, &dev->slist, w1_slave_entry) { |
| 804 | if (sl->reg_num.family == id->family && | 855 | if (sl->reg_num.family == id->family && |
| 805 | sl->reg_num.id == id->id && | 856 | sl->reg_num.id == id->id && |
| @@ -810,7 +861,7 @@ struct w1_slave *w1_search_slave(struct w1_reg_num *id) | |||
| 810 | break; | 861 | break; |
| 811 | } | 862 | } |
| 812 | } | 863 | } |
| 813 | mutex_unlock(&dev->mutex); | 864 | mutex_unlock(&dev->list_mutex); |
| 814 | 865 | ||
| 815 | if (found) | 866 | if (found) |
| 816 | break; | 867 | break; |
| @@ -830,6 +881,7 @@ void w1_reconnect_slaves(struct w1_family *f, int attach) | |||
| 830 | dev_dbg(&dev->dev, "Reconnecting slaves in device %s " | 881 | dev_dbg(&dev->dev, "Reconnecting slaves in device %s " |
| 831 | "for family %02x.\n", dev->name, f->fid); | 882 | "for family %02x.\n", dev->name, f->fid); |
| 832 | mutex_lock(&dev->mutex); | 883 | mutex_lock(&dev->mutex); |
| 884 | mutex_lock(&dev->list_mutex); | ||
| 833 | list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { | 885 | list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { |
| 834 | /* If it is a new family, slaves with the default | 886 | /* If it is a new family, slaves with the default |
| 835 | * family driver and are that family will be | 887 | * family driver and are that family will be |
| @@ -841,14 +893,19 @@ void w1_reconnect_slaves(struct w1_family *f, int attach) | |||
| 841 | (!attach && sl->family->fid == f->fid)) { | 893 | (!attach && sl->family->fid == f->fid)) { |
| 842 | struct w1_reg_num rn; | 894 | struct w1_reg_num rn; |
| 843 | 895 | ||
| 896 | mutex_unlock(&dev->list_mutex); | ||
| 844 | memcpy(&rn, &sl->reg_num, sizeof(rn)); | 897 | memcpy(&rn, &sl->reg_num, sizeof(rn)); |
| 845 | w1_slave_detach(sl); | 898 | /* If it was already in use let the automatic |
| 846 | 899 | * scan pick it up again later. | |
| 847 | w1_attach_slave_device(dev, &rn); | 900 | */ |
| 901 | if (!w1_slave_detach(sl)) | ||
| 902 | w1_attach_slave_device(dev, &rn); | ||
| 903 | mutex_lock(&dev->list_mutex); | ||
| 848 | } | 904 | } |
| 849 | } | 905 | } |
| 850 | dev_dbg(&dev->dev, "Reconnecting slaves in device %s " | 906 | dev_dbg(&dev->dev, "Reconnecting slaves in device %s " |
| 851 | "has been finished.\n", dev->name); | 907 | "has been finished.\n", dev->name); |
| 908 | mutex_unlock(&dev->list_mutex); | ||
| 852 | mutex_unlock(&dev->mutex); | 909 | mutex_unlock(&dev->mutex); |
| 853 | } | 910 | } |
| 854 | mutex_unlock(&w1_mlock); | 911 | mutex_unlock(&w1_mlock); |
| @@ -876,7 +933,12 @@ void w1_slave_found(struct w1_master *dev, u64 rn) | |||
| 876 | } | 933 | } |
| 877 | 934 | ||
| 878 | /** | 935 | /** |
| 879 | * Performs a ROM Search & registers any devices found. | 936 | * w1_search() - Performs a ROM Search & registers any devices found. |
| 937 | * @dev: The master device to search | ||
| 938 | * @search_type: W1_SEARCH to search all devices, or W1_ALARM_SEARCH | ||
| 939 | * to return only devices in the alarmed state | ||
| 940 | * @cb: Function to call when a device is found | ||
| 941 | * | ||
| 880 | * The 1-wire search is a simple binary tree search. | 942 | * The 1-wire search is a simple binary tree search. |
| 881 | * For each bit of the address, we read two bits and write one bit. | 943 | * For each bit of the address, we read two bits and write one bit. |
| 882 | * The bit written will put to sleep all devies that don't match that bit. | 944 | * The bit written will put to sleep all devies that don't match that bit. |
| @@ -886,8 +948,6 @@ void w1_slave_found(struct w1_master *dev, u64 rn) | |||
| 886 | * | 948 | * |
| 887 | * See "Application note 187 1-wire search algorithm" at www.maxim-ic.com | 949 | * See "Application note 187 1-wire search algorithm" at www.maxim-ic.com |
| 888 | * | 950 | * |
| 889 | * @dev The master device to search | ||
| 890 | * @cb Function to call when a device is found | ||
| 891 | */ | 951 | */ |
| 892 | void w1_search(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb) | 952 | void w1_search(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb) |
| 893 | { | 953 | { |
| @@ -898,7 +958,8 @@ void w1_search(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb | |||
| 898 | u8 triplet_ret = 0; | 958 | u8 triplet_ret = 0; |
| 899 | 959 | ||
| 900 | search_bit = 0; | 960 | search_bit = 0; |
| 901 | rn = last_rn = 0; | 961 | rn = dev->search_id; |
| 962 | last_rn = 0; | ||
| 902 | last_device = 0; | 963 | last_device = 0; |
| 903 | last_zero = -1; | 964 | last_zero = -1; |
| 904 | 965 | ||
| @@ -945,7 +1006,7 @@ void w1_search(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb | |||
| 945 | else | 1006 | else |
| 946 | search_bit = ((last_rn >> i) & 0x1); | 1007 | search_bit = ((last_rn >> i) & 0x1); |
| 947 | 1008 | ||
| 948 | /** Read two bits and write one bit */ | 1009 | /* Read two bits and write one bit */ |
| 949 | triplet_ret = w1_triplet(dev, search_bit); | 1010 | triplet_ret = w1_triplet(dev, search_bit); |
| 950 | 1011 | ||
| 951 | /* quit if no device responded */ | 1012 | /* quit if no device responded */ |
| @@ -960,8 +1021,7 @@ void w1_search(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb | |||
| 960 | tmp64 = (triplet_ret >> 2); | 1021 | tmp64 = (triplet_ret >> 2); |
| 961 | rn |= (tmp64 << i); | 1022 | rn |= (tmp64 << i); |
| 962 | 1023 | ||
| 963 | /* ensure we're called from kthread and not by netlink callback */ | 1024 | if (test_bit(W1_ABORT_SEARCH, &dev->flags)) { |
| 964 | if (!dev->priv && kthread_should_stop()) { | ||
| 965 | mutex_unlock(&dev->bus_mutex); | 1025 | mutex_unlock(&dev->bus_mutex); |
| 966 | dev_dbg(&dev->dev, "Abort w1_search\n"); | 1026 | dev_dbg(&dev->dev, "Abort w1_search\n"); |
| 967 | return; | 1027 | return; |
| @@ -970,11 +1030,30 @@ void w1_search(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb | |||
| 970 | mutex_unlock(&dev->bus_mutex); | 1030 | mutex_unlock(&dev->bus_mutex); |
| 971 | 1031 | ||
| 972 | if ( (triplet_ret & 0x03) != 0x03 ) { | 1032 | if ( (triplet_ret & 0x03) != 0x03 ) { |
| 973 | if ( (desc_bit == last_zero) || (last_zero < 0)) | 1033 | if ((desc_bit == last_zero) || (last_zero < 0)) { |
| 974 | last_device = 1; | 1034 | last_device = 1; |
| 1035 | dev->search_id = 0; | ||
| 1036 | } else { | ||
| 1037 | dev->search_id = rn; | ||
| 1038 | } | ||
| 975 | desc_bit = last_zero; | 1039 | desc_bit = last_zero; |
| 976 | cb(dev, rn); | 1040 | cb(dev, rn); |
| 977 | } | 1041 | } |
| 1042 | |||
| 1043 | if (!last_device && slave_count == dev->max_slave_count && | ||
| 1044 | !test_bit(W1_WARN_MAX_COUNT, &dev->flags)) { | ||
| 1045 | /* Only max_slave_count will be scanned in a search, | ||
| 1046 | * but it will start where it left off next search | ||
| 1047 | * until all ids are identified and then it will start | ||
| 1048 | * over. A continued search will report the previous | ||
| 1049 | * last id as the first id (provided it is still on the | ||
| 1050 | * bus). | ||
| 1051 | */ | ||
| 1052 | dev_info(&dev->dev, "%s: max_slave_count %d reached, " | ||
| 1053 | "will continue next search.\n", __func__, | ||
| 1054 | dev->max_slave_count); | ||
| 1055 | set_bit(W1_WARN_MAX_COUNT, &dev->flags); | ||
| 1056 | } | ||
| 978 | } | 1057 | } |
| 979 | } | 1058 | } |
| 980 | 1059 | ||
| @@ -983,17 +1062,24 @@ void w1_search_process_cb(struct w1_master *dev, u8 search_type, | |||
| 983 | { | 1062 | { |
| 984 | struct w1_slave *sl, *sln; | 1063 | struct w1_slave *sl, *sln; |
| 985 | 1064 | ||
| 1065 | mutex_lock(&dev->list_mutex); | ||
| 986 | list_for_each_entry(sl, &dev->slist, w1_slave_entry) | 1066 | list_for_each_entry(sl, &dev->slist, w1_slave_entry) |
| 987 | clear_bit(W1_SLAVE_ACTIVE, &sl->flags); | 1067 | clear_bit(W1_SLAVE_ACTIVE, &sl->flags); |
| 1068 | mutex_unlock(&dev->list_mutex); | ||
| 988 | 1069 | ||
| 989 | w1_search_devices(dev, search_type, cb); | 1070 | w1_search_devices(dev, search_type, cb); |
| 990 | 1071 | ||
| 1072 | mutex_lock(&dev->list_mutex); | ||
| 991 | list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { | 1073 | list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { |
| 992 | if (!test_bit(W1_SLAVE_ACTIVE, &sl->flags) && !--sl->ttl) | 1074 | if (!test_bit(W1_SLAVE_ACTIVE, &sl->flags) && !--sl->ttl) { |
| 1075 | mutex_unlock(&dev->list_mutex); | ||
| 993 | w1_slave_detach(sl); | 1076 | w1_slave_detach(sl); |
| 1077 | mutex_lock(&dev->list_mutex); | ||
| 1078 | } | ||
| 994 | else if (test_bit(W1_SLAVE_ACTIVE, &sl->flags)) | 1079 | else if (test_bit(W1_SLAVE_ACTIVE, &sl->flags)) |
| 995 | sl->ttl = dev->slave_ttl; | 1080 | sl->ttl = dev->slave_ttl; |
| 996 | } | 1081 | } |
| 1082 | mutex_unlock(&dev->list_mutex); | ||
| 997 | 1083 | ||
| 998 | if (dev->search_count > 0) | 1084 | if (dev->search_count > 0) |
| 999 | dev->search_count--; | 1085 | dev->search_count--; |
| @@ -1004,6 +1090,32 @@ static void w1_search_process(struct w1_master *dev, u8 search_type) | |||
| 1004 | w1_search_process_cb(dev, search_type, w1_slave_found); | 1090 | w1_search_process_cb(dev, search_type, w1_slave_found); |
| 1005 | } | 1091 | } |
| 1006 | 1092 | ||
| 1093 | /** | ||
| 1094 | * w1_process_callbacks() - execute each dev->async_list callback entry | ||
| 1095 | * @dev: w1_master device | ||
| 1096 | * | ||
| 1097 | * Return: 1 if there were commands to executed 0 otherwise | ||
| 1098 | */ | ||
| 1099 | int w1_process_callbacks(struct w1_master *dev) | ||
| 1100 | { | ||
| 1101 | int ret = 0; | ||
| 1102 | struct w1_async_cmd *async_cmd, *async_n; | ||
| 1103 | |||
| 1104 | /* The list can be added to in another thread, loop until it is empty */ | ||
| 1105 | while (!list_empty(&dev->async_list)) { | ||
| 1106 | list_for_each_entry_safe(async_cmd, async_n, &dev->async_list, | ||
| 1107 | async_entry) { | ||
| 1108 | /* drop the lock, if it is a search it can take a long | ||
| 1109 | * time */ | ||
| 1110 | mutex_unlock(&dev->list_mutex); | ||
| 1111 | async_cmd->cb(dev, async_cmd); | ||
| 1112 | ret = 1; | ||
| 1113 | mutex_lock(&dev->list_mutex); | ||
| 1114 | } | ||
| 1115 | } | ||
| 1116 | return ret; | ||
| 1117 | } | ||
| 1118 | |||
| 1007 | int w1_process(void *data) | 1119 | int w1_process(void *data) |
| 1008 | { | 1120 | { |
| 1009 | struct w1_master *dev = (struct w1_master *) data; | 1121 | struct w1_master *dev = (struct w1_master *) data; |
| @@ -1011,23 +1123,46 @@ int w1_process(void *data) | |||
| 1011 | * time can be calculated in jiffies once. | 1123 | * time can be calculated in jiffies once. |
| 1012 | */ | 1124 | */ |
| 1013 | const unsigned long jtime = msecs_to_jiffies(w1_timeout * 1000); | 1125 | const unsigned long jtime = msecs_to_jiffies(w1_timeout * 1000); |
| 1126 | /* remainder if it woke up early */ | ||
| 1127 | unsigned long jremain = 0; | ||
| 1014 | 1128 | ||
| 1015 | while (!kthread_should_stop()) { | 1129 | for (;;) { |
| 1016 | if (dev->search_count) { | 1130 | |
| 1131 | if (!jremain && dev->search_count) { | ||
| 1017 | mutex_lock(&dev->mutex); | 1132 | mutex_lock(&dev->mutex); |
| 1018 | w1_search_process(dev, W1_SEARCH); | 1133 | w1_search_process(dev, W1_SEARCH); |
| 1019 | mutex_unlock(&dev->mutex); | 1134 | mutex_unlock(&dev->mutex); |
| 1020 | } | 1135 | } |
| 1021 | 1136 | ||
| 1137 | mutex_lock(&dev->list_mutex); | ||
| 1138 | /* Note, w1_process_callback drops the lock while processing, | ||
| 1139 | * but locks it again before returning. | ||
| 1140 | */ | ||
| 1141 | if (!w1_process_callbacks(dev) && jremain) { | ||
| 1142 | /* a wake up is either to stop the thread, process | ||
| 1143 | * callbacks, or search, it isn't process callbacks, so | ||
| 1144 | * schedule a search. | ||
| 1145 | */ | ||
| 1146 | jremain = 1; | ||
| 1147 | } | ||
| 1148 | |||
| 1022 | try_to_freeze(); | 1149 | try_to_freeze(); |
| 1023 | __set_current_state(TASK_INTERRUPTIBLE); | 1150 | __set_current_state(TASK_INTERRUPTIBLE); |
| 1024 | 1151 | ||
| 1152 | /* hold list_mutex until after interruptible to prevent loosing | ||
| 1153 | * the wakeup signal when async_cmd is added. | ||
| 1154 | */ | ||
| 1155 | mutex_unlock(&dev->list_mutex); | ||
| 1156 | |||
| 1025 | if (kthread_should_stop()) | 1157 | if (kthread_should_stop()) |
| 1026 | break; | 1158 | break; |
| 1027 | 1159 | ||
| 1028 | /* Only sleep when the search is active. */ | 1160 | /* Only sleep when the search is active. */ |
| 1029 | if (dev->search_count) | 1161 | if (dev->search_count) { |
| 1030 | schedule_timeout(jtime); | 1162 | if (!jremain) |
| 1163 | jremain = jtime; | ||
| 1164 | jremain = schedule_timeout(jremain); | ||
| 1165 | } | ||
| 1031 | else | 1166 | else |
| 1032 | schedule(); | 1167 | schedule(); |
| 1033 | } | 1168 | } |
diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h index ca8081a101d6..734dab7fc687 100644 --- a/drivers/w1/w1.h +++ b/drivers/w1/w1.h | |||
| @@ -22,6 +22,13 @@ | |||
| 22 | #ifndef __W1_H | 22 | #ifndef __W1_H |
| 23 | #define __W1_H | 23 | #define __W1_H |
| 24 | 24 | ||
| 25 | /** | ||
| 26 | * struct w1_reg_num - broken out slave device id | ||
| 27 | * | ||
| 28 | * @family: identifies the type of device | ||
| 29 | * @id: along with family is the unique device id | ||
| 30 | * @crc: checksum of the other bytes | ||
| 31 | */ | ||
| 25 | struct w1_reg_num | 32 | struct w1_reg_num |
| 26 | { | 33 | { |
| 27 | #if defined(__LITTLE_ENDIAN_BITFIELD) | 34 | #if defined(__LITTLE_ENDIAN_BITFIELD) |
| @@ -58,7 +65,24 @@ struct w1_reg_num | |||
| 58 | #define W1_RESUME_CMD 0xA5 | 65 | #define W1_RESUME_CMD 0xA5 |
| 59 | 66 | ||
| 60 | #define W1_SLAVE_ACTIVE 0 | 67 | #define W1_SLAVE_ACTIVE 0 |
| 68 | #define W1_SLAVE_DETACH 1 | ||
| 61 | 69 | ||
| 70 | /** | ||
| 71 | * struct w1_slave - holds a single slave device on the bus | ||
| 72 | * | ||
| 73 | * @owner: Points to the one wire "wire" kernel module. | ||
| 74 | * @name: Device id is ascii. | ||
| 75 | * @w1_slave_entry: data for the linked list | ||
| 76 | * @reg_num: the slave id in binary | ||
| 77 | * @refcnt: reference count, delete when 0 | ||
| 78 | * @flags: bit flags for W1_SLAVE_ACTIVE W1_SLAVE_DETACH | ||
| 79 | * @ttl: decrement per search this slave isn't found, deatch at 0 | ||
| 80 | * @master: bus which this slave is on | ||
| 81 | * @family: module for device family type | ||
| 82 | * @family_data: pointer for use by the family module | ||
| 83 | * @dev: kernel device identifier | ||
| 84 | * | ||
| 85 | */ | ||
| 62 | struct w1_slave | 86 | struct w1_slave |
| 63 | { | 87 | { |
| 64 | struct module *owner; | 88 | struct module *owner; |
| @@ -66,7 +90,6 @@ struct w1_slave | |||
| 66 | struct list_head w1_slave_entry; | 90 | struct list_head w1_slave_entry; |
| 67 | struct w1_reg_num reg_num; | 91 | struct w1_reg_num reg_num; |
| 68 | atomic_t refcnt; | 92 | atomic_t refcnt; |
| 69 | u8 rom[9]; | ||
| 70 | int ttl; | 93 | int ttl; |
| 71 | unsigned long flags; | 94 | unsigned long flags; |
| 72 | 95 | ||
| @@ -74,99 +97,146 @@ struct w1_slave | |||
| 74 | struct w1_family *family; | 97 | struct w1_family *family; |
| 75 | void *family_data; | 98 | void *family_data; |
| 76 | struct device dev; | 99 | struct device dev; |
| 77 | struct completion released; | ||
| 78 | }; | 100 | }; |
| 79 | 101 | ||
| 80 | typedef void (*w1_slave_found_callback)(struct w1_master *, u64); | 102 | typedef void (*w1_slave_found_callback)(struct w1_master *, u64); |
| 81 | 103 | ||
| 82 | 104 | ||
| 83 | /** | 105 | /** |
| 106 | * struct w1_bus_master - operations available on a bus master | ||
| 107 | * | ||
| 108 | * @data: the first parameter in all the functions below | ||
| 109 | * | ||
| 110 | * @read_bit: Sample the line level @return the level read (0 or 1) | ||
| 111 | * | ||
| 112 | * @write_bit: Sets the line level | ||
| 113 | * | ||
| 114 | * @touch_bit: the lowest-level function for devices that really support the | ||
| 115 | * 1-wire protocol. | ||
| 116 | * touch_bit(0) = write-0 cycle | ||
| 117 | * touch_bit(1) = write-1 / read cycle | ||
| 118 | * @return the bit read (0 or 1) | ||
| 119 | * | ||
| 120 | * @read_byte: Reads a bytes. Same as 8 touch_bit(1) calls. | ||
| 121 | * @return the byte read | ||
| 122 | * | ||
| 123 | * @write_byte: Writes a byte. Same as 8 touch_bit(x) calls. | ||
| 124 | * | ||
| 125 | * @read_block: Same as a series of read_byte() calls | ||
| 126 | * @return the number of bytes read | ||
| 127 | * | ||
| 128 | * @write_block: Same as a series of write_byte() calls | ||
| 129 | * | ||
| 130 | * @triplet: Combines two reads and a smart write for ROM searches | ||
| 131 | * @return bit0=Id bit1=comp_id bit2=dir_taken | ||
| 132 | * | ||
| 133 | * @reset_bus: long write-0 with a read for the presence pulse detection | ||
| 134 | * @return -1=Error, 0=Device present, 1=No device present | ||
| 135 | * | ||
| 136 | * @set_pullup: Put out a strong pull-up pulse of the specified duration. | ||
| 137 | * @return -1=Error, 0=completed | ||
| 138 | * | ||
| 139 | * @search: Really nice hardware can handles the different types of ROM search | ||
| 140 | * w1_master* is passed to the slave found callback. | ||
| 141 | * u8 is search_type, W1_SEARCH or W1_ALARM_SEARCH | ||
| 142 | * | ||
| 84 | * Note: read_bit and write_bit are very low level functions and should only | 143 | * Note: read_bit and write_bit are very low level functions and should only |
| 85 | * be used with hardware that doesn't really support 1-wire operations, | 144 | * be used with hardware that doesn't really support 1-wire operations, |
| 86 | * like a parallel/serial port. | 145 | * like a parallel/serial port. |
| 87 | * Either define read_bit and write_bit OR define, at minimum, touch_bit and | 146 | * Either define read_bit and write_bit OR define, at minimum, touch_bit and |
| 88 | * reset_bus. | 147 | * reset_bus. |
| 148 | * | ||
| 89 | */ | 149 | */ |
| 90 | struct w1_bus_master | 150 | struct w1_bus_master |
| 91 | { | 151 | { |
| 92 | /** the first parameter in all the functions below */ | ||
| 93 | void *data; | 152 | void *data; |
| 94 | 153 | ||
| 95 | /** | ||
| 96 | * Sample the line level | ||
| 97 | * @return the level read (0 or 1) | ||
| 98 | */ | ||
| 99 | u8 (*read_bit)(void *); | 154 | u8 (*read_bit)(void *); |
| 100 | 155 | ||
| 101 | /** Sets the line level */ | ||
| 102 | void (*write_bit)(void *, u8); | 156 | void (*write_bit)(void *, u8); |
| 103 | 157 | ||
| 104 | /** | ||
| 105 | * touch_bit is the lowest-level function for devices that really | ||
| 106 | * support the 1-wire protocol. | ||
| 107 | * touch_bit(0) = write-0 cycle | ||
| 108 | * touch_bit(1) = write-1 / read cycle | ||
| 109 | * @return the bit read (0 or 1) | ||
| 110 | */ | ||
| 111 | u8 (*touch_bit)(void *, u8); | 158 | u8 (*touch_bit)(void *, u8); |
| 112 | 159 | ||
| 113 | /** | ||
| 114 | * Reads a bytes. Same as 8 touch_bit(1) calls. | ||
| 115 | * @return the byte read | ||
| 116 | */ | ||
| 117 | u8 (*read_byte)(void *); | 160 | u8 (*read_byte)(void *); |
| 118 | 161 | ||
| 119 | /** | ||
| 120 | * Writes a byte. Same as 8 touch_bit(x) calls. | ||
| 121 | */ | ||
| 122 | void (*write_byte)(void *, u8); | 162 | void (*write_byte)(void *, u8); |
| 123 | 163 | ||
| 124 | /** | ||
| 125 | * Same as a series of read_byte() calls | ||
| 126 | * @return the number of bytes read | ||
| 127 | */ | ||
| 128 | u8 (*read_block)(void *, u8 *, int); | 164 | u8 (*read_block)(void *, u8 *, int); |
| 129 | 165 | ||
| 130 | /** Same as a series of write_byte() calls */ | ||
| 131 | void (*write_block)(void *, const u8 *, int); | 166 | void (*write_block)(void *, const u8 *, int); |
| 132 | 167 | ||
| 133 | /** | ||
| 134 | * Combines two reads and a smart write for ROM searches | ||
| 135 | * @return bit0=Id bit1=comp_id bit2=dir_taken | ||
| 136 | */ | ||
| 137 | u8 (*triplet)(void *, u8); | 168 | u8 (*triplet)(void *, u8); |
| 138 | 169 | ||
| 139 | /** | ||
| 140 | * long write-0 with a read for the presence pulse detection | ||
| 141 | * @return -1=Error, 0=Device present, 1=No device present | ||
| 142 | */ | ||
| 143 | u8 (*reset_bus)(void *); | 170 | u8 (*reset_bus)(void *); |
| 144 | 171 | ||
| 145 | /** | ||
| 146 | * Put out a strong pull-up pulse of the specified duration. | ||
| 147 | * @return -1=Error, 0=completed | ||
| 148 | */ | ||
| 149 | u8 (*set_pullup)(void *, int); | 172 | u8 (*set_pullup)(void *, int); |
| 150 | 173 | ||
| 151 | /** Really nice hardware can handles the different types of ROM search | ||
| 152 | * w1_master* is passed to the slave found callback. | ||
| 153 | */ | ||
| 154 | void (*search)(void *, struct w1_master *, | 174 | void (*search)(void *, struct w1_master *, |
| 155 | u8, w1_slave_found_callback); | 175 | u8, w1_slave_found_callback); |
| 156 | }; | 176 | }; |
| 157 | 177 | ||
| 178 | /** | ||
| 179 | * enum w1_master_flags - bitfields used in w1_master.flags | ||
| 180 | * @W1_ABORT_SEARCH: abort searching early on shutdown | ||
| 181 | * @W1_WARN_MAX_COUNT: limit warning when the maximum count is reached | ||
| 182 | */ | ||
| 183 | enum w1_master_flags { | ||
| 184 | W1_ABORT_SEARCH = 0, | ||
| 185 | W1_WARN_MAX_COUNT = 1, | ||
| 186 | }; | ||
| 187 | |||
| 188 | /** | ||
| 189 | * struct w1_master - one per bus master | ||
| 190 | * @w1_master_entry: master linked list | ||
| 191 | * @owner: module owner | ||
| 192 | * @name: dynamically allocate bus name | ||
| 193 | * @list_mutex: protect slist and async_list | ||
| 194 | * @slist: linked list of slaves | ||
| 195 | * @async_list: linked list of netlink commands to execute | ||
| 196 | * @max_slave_count: maximum number of slaves to search for at a time | ||
| 197 | * @slave_count: current number of slaves known | ||
| 198 | * @attempts: number of searches ran | ||
| 199 | * @slave_ttl: number of searches before a slave is timed out | ||
| 200 | * @initialized: prevent init/removal race conditions | ||
| 201 | * @id: w1 bus number | ||
| 202 | * @search_count: number of automatic searches to run, -1 unlimited | ||
| 203 | * @search_id: allows continuing a search | ||
| 204 | * @refcnt: reference count | ||
| 205 | * @priv: private data storage | ||
| 206 | * @priv_size: size allocated | ||
| 207 | * @enable_pullup: allows a strong pullup | ||
| 208 | * @pullup_duration: time for the next strong pullup | ||
| 209 | * @flags: one of w1_master_flags | ||
| 210 | * @thread: thread for bus search and netlink commands | ||
| 211 | * @mutex: protect most of w1_master | ||
| 212 | * @bus_mutex: pretect concurrent bus access | ||
| 213 | * @driver: sysfs driver | ||
| 214 | * @dev: sysfs device | ||
| 215 | * @bus_master: io operations available | ||
| 216 | * @seq: sequence number used for netlink broadcasts | ||
| 217 | * @portid: destination for the current netlink command | ||
| 218 | */ | ||
| 158 | struct w1_master | 219 | struct w1_master |
| 159 | { | 220 | { |
| 160 | struct list_head w1_master_entry; | 221 | struct list_head w1_master_entry; |
| 161 | struct module *owner; | 222 | struct module *owner; |
| 162 | unsigned char name[W1_MAXNAMELEN]; | 223 | unsigned char name[W1_MAXNAMELEN]; |
| 224 | /* list_mutex protects just slist and async_list so slaves can be | ||
| 225 | * searched for and async commands added while the master has | ||
| 226 | * w1_master.mutex locked and is operating on the bus. | ||
| 227 | * lock order w1_mlock, w1_master.mutex, w1_master.list_mutex | ||
| 228 | */ | ||
| 229 | struct mutex list_mutex; | ||
| 163 | struct list_head slist; | 230 | struct list_head slist; |
| 231 | struct list_head async_list; | ||
| 164 | int max_slave_count, slave_count; | 232 | int max_slave_count, slave_count; |
| 165 | unsigned long attempts; | 233 | unsigned long attempts; |
| 166 | int slave_ttl; | 234 | int slave_ttl; |
| 167 | int initialized; | 235 | int initialized; |
| 168 | u32 id; | 236 | u32 id; |
| 169 | int search_count; | 237 | int search_count; |
| 238 | /* id to start searching on, to continue a search or 0 to restart */ | ||
| 239 | u64 search_id; | ||
| 170 | 240 | ||
| 171 | atomic_t refcnt; | 241 | atomic_t refcnt; |
| 172 | 242 | ||
| @@ -178,6 +248,8 @@ struct w1_master | |||
| 178 | /** 5V strong pullup duration in milliseconds, zero disabled. */ | 248 | /** 5V strong pullup duration in milliseconds, zero disabled. */ |
| 179 | int pullup_duration; | 249 | int pullup_duration; |
| 180 | 250 | ||
| 251 | long flags; | ||
| 252 | |||
| 181 | struct task_struct *thread; | 253 | struct task_struct *thread; |
| 182 | struct mutex mutex; | 254 | struct mutex mutex; |
| 183 | struct mutex bus_mutex; | 255 | struct mutex bus_mutex; |
| @@ -188,16 +260,41 @@ struct w1_master | |||
| 188 | struct w1_bus_master *bus_master; | 260 | struct w1_bus_master *bus_master; |
| 189 | 261 | ||
| 190 | u32 seq; | 262 | u32 seq; |
| 263 | /* port id to send netlink responses to. The value is temporarily | ||
| 264 | * stored here while processing a message, set after locking the | ||
| 265 | * mutex, zero before unlocking the mutex. | ||
| 266 | */ | ||
| 267 | u32 portid; | ||
| 268 | }; | ||
| 269 | |||
| 270 | /** | ||
| 271 | * struct w1_async_cmd - execute callback from the w1_process kthread | ||
| 272 | * @async_entry: link entry | ||
| 273 | * @cb: callback function, must list_del and destroy this list before | ||
| 274 | * returning | ||
| 275 | * | ||
| 276 | * When inserted into the w1_master async_list, w1_process will execute | ||
| 277 | * the callback. Embed this into the structure with the command details. | ||
| 278 | */ | ||
| 279 | struct w1_async_cmd { | ||
| 280 | struct list_head async_entry; | ||
| 281 | void (*cb)(struct w1_master *dev, struct w1_async_cmd *async_cmd); | ||
| 191 | }; | 282 | }; |
| 192 | 283 | ||
| 193 | int w1_create_master_attributes(struct w1_master *); | 284 | int w1_create_master_attributes(struct w1_master *); |
| 194 | void w1_destroy_master_attributes(struct w1_master *master); | 285 | void w1_destroy_master_attributes(struct w1_master *master); |
| 195 | void w1_search(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb); | 286 | void w1_search(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb); |
| 196 | void w1_search_devices(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb); | 287 | void w1_search_devices(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb); |
| 288 | /* call w1_unref_slave to release the reference counts w1_search_slave added */ | ||
| 197 | struct w1_slave *w1_search_slave(struct w1_reg_num *id); | 289 | struct w1_slave *w1_search_slave(struct w1_reg_num *id); |
| 290 | /* decrements the reference on sl->master and sl, and cleans up if zero | ||
| 291 | * returns the reference count after it has been decremented */ | ||
| 292 | int w1_unref_slave(struct w1_slave *sl); | ||
| 198 | void w1_slave_found(struct w1_master *dev, u64 rn); | 293 | void w1_slave_found(struct w1_master *dev, u64 rn); |
| 199 | void w1_search_process_cb(struct w1_master *dev, u8 search_type, | 294 | void w1_search_process_cb(struct w1_master *dev, u8 search_type, |
| 200 | w1_slave_found_callback cb); | 295 | w1_slave_found_callback cb); |
| 296 | struct w1_slave *w1_slave_search_device(struct w1_master *dev, | ||
| 297 | struct w1_reg_num *rn); | ||
| 201 | struct w1_master *w1_search_master_id(u32 id); | 298 | struct w1_master *w1_search_master_id(u32 id); |
| 202 | 299 | ||
| 203 | /* Disconnect and reconnect devices in the given family. Used for finding | 300 | /* Disconnect and reconnect devices in the given family. Used for finding |
| @@ -206,7 +303,9 @@ struct w1_master *w1_search_master_id(u32 id); | |||
| 206 | * has just been registered, to 0 when it has been unregistered. | 303 | * has just been registered, to 0 when it has been unregistered. |
| 207 | */ | 304 | */ |
| 208 | void w1_reconnect_slaves(struct w1_family *f, int attach); | 305 | void w1_reconnect_slaves(struct w1_family *f, int attach); |
| 209 | void w1_slave_detach(struct w1_slave *sl); | 306 | int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn); |
| 307 | /* 0 success, otherwise EBUSY */ | ||
| 308 | int w1_slave_detach(struct w1_slave *sl); | ||
| 210 | 309 | ||
| 211 | u8 w1_triplet(struct w1_master *dev, int bdir); | 310 | u8 w1_triplet(struct w1_master *dev, int bdir); |
| 212 | void w1_write_8(struct w1_master *, u8); | 311 | void w1_write_8(struct w1_master *, u8); |
| @@ -242,6 +341,7 @@ extern int w1_max_slave_ttl; | |||
| 242 | extern struct list_head w1_masters; | 341 | extern struct list_head w1_masters; |
| 243 | extern struct mutex w1_mlock; | 342 | extern struct mutex w1_mlock; |
| 244 | 343 | ||
| 344 | extern int w1_process_callbacks(struct w1_master *dev); | ||
| 245 | extern int w1_process(void *); | 345 | extern int w1_process(void *); |
| 246 | 346 | ||
| 247 | #endif /* __KERNEL__ */ | 347 | #endif /* __KERNEL__ */ |
diff --git a/drivers/w1/w1_family.c b/drivers/w1/w1_family.c index e9309778ee72..3bff6b37b472 100644 --- a/drivers/w1/w1_family.c +++ b/drivers/w1/w1_family.c | |||
| @@ -31,6 +31,10 @@ | |||
| 31 | DEFINE_SPINLOCK(w1_flock); | 31 | DEFINE_SPINLOCK(w1_flock); |
| 32 | static LIST_HEAD(w1_families); | 32 | static LIST_HEAD(w1_families); |
| 33 | 33 | ||
| 34 | /** | ||
| 35 | * w1_register_family() - register a device family driver | ||
| 36 | * @newf: family to register | ||
| 37 | */ | ||
| 34 | int w1_register_family(struct w1_family *newf) | 38 | int w1_register_family(struct w1_family *newf) |
| 35 | { | 39 | { |
| 36 | struct list_head *ent, *n; | 40 | struct list_head *ent, *n; |
| @@ -59,6 +63,10 @@ int w1_register_family(struct w1_family *newf) | |||
| 59 | return ret; | 63 | return ret; |
| 60 | } | 64 | } |
| 61 | 65 | ||
| 66 | /** | ||
| 67 | * w1_unregister_family() - unregister a device family driver | ||
| 68 | * @fent: family to unregister | ||
| 69 | */ | ||
| 62 | void w1_unregister_family(struct w1_family *fent) | 70 | void w1_unregister_family(struct w1_family *fent) |
| 63 | { | 71 | { |
| 64 | struct list_head *ent, *n; | 72 | struct list_head *ent, *n; |
diff --git a/drivers/w1/w1_family.h b/drivers/w1/w1_family.h index 4ad0e81b6404..26ca1343055b 100644 --- a/drivers/w1/w1_family.h +++ b/drivers/w1/w1_family.h | |||
| @@ -48,6 +48,12 @@ | |||
| 48 | 48 | ||
| 49 | struct w1_slave; | 49 | struct w1_slave; |
| 50 | 50 | ||
| 51 | /** | ||
| 52 | * struct w1_family_ops - operations for a family type | ||
| 53 | * @add_slave: add_slave | ||
| 54 | * @remove_slave: remove_slave | ||
| 55 | * @groups: sysfs group | ||
| 56 | */ | ||
| 51 | struct w1_family_ops | 57 | struct w1_family_ops |
| 52 | { | 58 | { |
| 53 | int (* add_slave)(struct w1_slave *); | 59 | int (* add_slave)(struct w1_slave *); |
| @@ -55,6 +61,13 @@ struct w1_family_ops | |||
| 55 | const struct attribute_group **groups; | 61 | const struct attribute_group **groups; |
| 56 | }; | 62 | }; |
| 57 | 63 | ||
| 64 | /** | ||
| 65 | * struct w1_family - reference counted family structure. | ||
| 66 | * @family_entry: family linked list | ||
| 67 | * @fid: 8 bit family identifier | ||
| 68 | * @fops: operations for this family | ||
| 69 | * @refcnt: reference counter | ||
| 70 | */ | ||
| 58 | struct w1_family | 71 | struct w1_family |
| 59 | { | 72 | { |
| 60 | struct list_head family_entry; | 73 | struct list_head family_entry; |
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c index 590bd8a7cd1b..9b084db739c7 100644 --- a/drivers/w1/w1_int.c +++ b/drivers/w1/w1_int.c | |||
| @@ -75,8 +75,10 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl, | |||
| 75 | atomic_set(&dev->refcnt, 2); | 75 | atomic_set(&dev->refcnt, 2); |
| 76 | 76 | ||
| 77 | INIT_LIST_HEAD(&dev->slist); | 77 | INIT_LIST_HEAD(&dev->slist); |
| 78 | INIT_LIST_HEAD(&dev->async_list); | ||
| 78 | mutex_init(&dev->mutex); | 79 | mutex_init(&dev->mutex); |
| 79 | mutex_init(&dev->bus_mutex); | 80 | mutex_init(&dev->bus_mutex); |
| 81 | mutex_init(&dev->list_mutex); | ||
| 80 | 82 | ||
| 81 | memcpy(&dev->dev, device, sizeof(struct device)); | 83 | memcpy(&dev->dev, device, sizeof(struct device)); |
| 82 | dev_set_name(&dev->dev, "w1_bus_master%u", dev->id); | 84 | dev_set_name(&dev->dev, "w1_bus_master%u", dev->id); |
| @@ -103,6 +105,10 @@ static void w1_free_dev(struct w1_master *dev) | |||
| 103 | device_unregister(&dev->dev); | 105 | device_unregister(&dev->dev); |
| 104 | } | 106 | } |
| 105 | 107 | ||
| 108 | /** | ||
| 109 | * w1_add_master_device() - registers a new master device | ||
| 110 | * @master: master bus device to register | ||
| 111 | */ | ||
| 106 | int w1_add_master_device(struct w1_bus_master *master) | 112 | int w1_add_master_device(struct w1_bus_master *master) |
| 107 | { | 113 | { |
| 108 | struct w1_master *dev, *entry; | 114 | struct w1_master *dev, *entry; |
| @@ -172,6 +178,7 @@ int w1_add_master_device(struct w1_bus_master *master) | |||
| 172 | 178 | ||
| 173 | #if 0 /* Thread cleanup code, not required currently. */ | 179 | #if 0 /* Thread cleanup code, not required currently. */ |
| 174 | err_out_kill_thread: | 180 | err_out_kill_thread: |
| 181 | set_bit(W1_ABORT_SEARCH, &dev->flags); | ||
| 175 | kthread_stop(dev->thread); | 182 | kthread_stop(dev->thread); |
| 176 | #endif | 183 | #endif |
| 177 | err_out_rm_attr: | 184 | err_out_rm_attr: |
| @@ -187,16 +194,22 @@ void __w1_remove_master_device(struct w1_master *dev) | |||
| 187 | struct w1_netlink_msg msg; | 194 | struct w1_netlink_msg msg; |
| 188 | struct w1_slave *sl, *sln; | 195 | struct w1_slave *sl, *sln; |
| 189 | 196 | ||
| 190 | kthread_stop(dev->thread); | ||
| 191 | |||
| 192 | mutex_lock(&w1_mlock); | 197 | mutex_lock(&w1_mlock); |
| 193 | list_del(&dev->w1_master_entry); | 198 | list_del(&dev->w1_master_entry); |
| 194 | mutex_unlock(&w1_mlock); | 199 | mutex_unlock(&w1_mlock); |
| 195 | 200 | ||
| 201 | set_bit(W1_ABORT_SEARCH, &dev->flags); | ||
| 202 | kthread_stop(dev->thread); | ||
| 203 | |||
| 196 | mutex_lock(&dev->mutex); | 204 | mutex_lock(&dev->mutex); |
| 197 | list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) | 205 | mutex_lock(&dev->list_mutex); |
| 206 | list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { | ||
| 207 | mutex_unlock(&dev->list_mutex); | ||
| 198 | w1_slave_detach(sl); | 208 | w1_slave_detach(sl); |
| 209 | mutex_lock(&dev->list_mutex); | ||
| 210 | } | ||
| 199 | w1_destroy_master_attributes(dev); | 211 | w1_destroy_master_attributes(dev); |
| 212 | mutex_unlock(&dev->list_mutex); | ||
| 200 | mutex_unlock(&dev->mutex); | 213 | mutex_unlock(&dev->mutex); |
| 201 | atomic_dec(&dev->refcnt); | 214 | atomic_dec(&dev->refcnt); |
| 202 | 215 | ||
| @@ -206,7 +219,9 @@ void __w1_remove_master_device(struct w1_master *dev) | |||
| 206 | 219 | ||
| 207 | if (msleep_interruptible(1000)) | 220 | if (msleep_interruptible(1000)) |
| 208 | flush_signals(current); | 221 | flush_signals(current); |
| 222 | w1_process_callbacks(dev); | ||
| 209 | } | 223 | } |
| 224 | w1_process_callbacks(dev); | ||
| 210 | 225 | ||
| 211 | memset(&msg, 0, sizeof(msg)); | 226 | memset(&msg, 0, sizeof(msg)); |
| 212 | msg.id.mst.id = dev->id; | 227 | msg.id.mst.id = dev->id; |
| @@ -216,6 +231,10 @@ void __w1_remove_master_device(struct w1_master *dev) | |||
| 216 | w1_free_dev(dev); | 231 | w1_free_dev(dev); |
| 217 | } | 232 | } |
| 218 | 233 | ||
| 234 | /** | ||
| 235 | * w1_remove_master_device() - unregister a master device | ||
| 236 | * @bm: master bus device to remove | ||
| 237 | */ | ||
| 219 | void w1_remove_master_device(struct w1_bus_master *bm) | 238 | void w1_remove_master_device(struct w1_bus_master *bm) |
| 220 | { | 239 | { |
| 221 | struct w1_master *dev, *found = NULL; | 240 | struct w1_master *dev, *found = NULL; |
diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c index e10acc237733..282092421cc9 100644 --- a/drivers/w1/w1_io.c +++ b/drivers/w1/w1_io.c | |||
| @@ -62,7 +62,9 @@ static void w1_write_bit(struct w1_master *dev, int bit); | |||
| 62 | static u8 w1_read_bit(struct w1_master *dev); | 62 | static u8 w1_read_bit(struct w1_master *dev); |
| 63 | 63 | ||
| 64 | /** | 64 | /** |
| 65 | * Generates a write-0 or write-1 cycle and samples the level. | 65 | * w1_touch_bit() - Generates a write-0 or write-1 cycle and samples the level. |
| 66 | * @dev: the master device | ||
| 67 | * @bit: 0 - write a 0, 1 - write a 0 read the level | ||
| 66 | */ | 68 | */ |
| 67 | static u8 w1_touch_bit(struct w1_master *dev, int bit) | 69 | static u8 w1_touch_bit(struct w1_master *dev, int bit) |
| 68 | { | 70 | { |
| @@ -77,7 +79,10 @@ static u8 w1_touch_bit(struct w1_master *dev, int bit) | |||
| 77 | } | 79 | } |
| 78 | 80 | ||
| 79 | /** | 81 | /** |
| 80 | * Generates a write-0 or write-1 cycle. | 82 | * w1_write_bit() - Generates a write-0 or write-1 cycle. |
| 83 | * @dev: the master device | ||
| 84 | * @bit: bit to write | ||
| 85 | * | ||
| 81 | * Only call if dev->bus_master->touch_bit is NULL | 86 | * Only call if dev->bus_master->touch_bit is NULL |
| 82 | */ | 87 | */ |
| 83 | static void w1_write_bit(struct w1_master *dev, int bit) | 88 | static void w1_write_bit(struct w1_master *dev, int bit) |
| @@ -102,11 +107,12 @@ static void w1_write_bit(struct w1_master *dev, int bit) | |||
| 102 | } | 107 | } |
| 103 | 108 | ||
| 104 | /** | 109 | /** |
| 110 | * w1_pre_write() - pre-write operations | ||
| 111 | * @dev: the master device | ||
| 112 | * | ||
| 105 | * Pre-write operation, currently only supporting strong pullups. | 113 | * Pre-write operation, currently only supporting strong pullups. |
| 106 | * Program the hardware for a strong pullup, if one has been requested and | 114 | * Program the hardware for a strong pullup, if one has been requested and |
| 107 | * the hardware supports it. | 115 | * the hardware supports it. |
| 108 | * | ||
| 109 | * @param dev the master device | ||
| 110 | */ | 116 | */ |
| 111 | static void w1_pre_write(struct w1_master *dev) | 117 | static void w1_pre_write(struct w1_master *dev) |
| 112 | { | 118 | { |
| @@ -118,11 +124,12 @@ static void w1_pre_write(struct w1_master *dev) | |||
| 118 | } | 124 | } |
| 119 | 125 | ||
| 120 | /** | 126 | /** |
| 127 | * w1_post_write() - post-write options | ||
| 128 | * @dev: the master device | ||
| 129 | * | ||
| 121 | * Post-write operation, currently only supporting strong pullups. | 130 | * Post-write operation, currently only supporting strong pullups. |
| 122 | * If a strong pullup was requested, clear it if the hardware supports | 131 | * If a strong pullup was requested, clear it if the hardware supports |
| 123 | * them, or execute the delay otherwise, in either case clear the request. | 132 | * them, or execute the delay otherwise, in either case clear the request. |
| 124 | * | ||
| 125 | * @param dev the master device | ||
| 126 | */ | 133 | */ |
| 127 | static void w1_post_write(struct w1_master *dev) | 134 | static void w1_post_write(struct w1_master *dev) |
| 128 | { | 135 | { |
| @@ -136,10 +143,9 @@ static void w1_post_write(struct w1_master *dev) | |||
| 136 | } | 143 | } |
| 137 | 144 | ||
| 138 | /** | 145 | /** |
| 139 | * Writes 8 bits. | 146 | * w1_write_8() - Writes 8 bits. |
| 140 | * | 147 | * @dev: the master device |
| 141 | * @param dev the master device | 148 | * @byte: the byte to write |
| 142 | * @param byte the byte to write | ||
| 143 | */ | 149 | */ |
| 144 | void w1_write_8(struct w1_master *dev, u8 byte) | 150 | void w1_write_8(struct w1_master *dev, u8 byte) |
| 145 | { | 151 | { |
| @@ -161,7 +167,9 @@ EXPORT_SYMBOL_GPL(w1_write_8); | |||
| 161 | 167 | ||
| 162 | 168 | ||
| 163 | /** | 169 | /** |
| 164 | * Generates a write-1 cycle and samples the level. | 170 | * w1_read_bit() - Generates a write-1 cycle and samples the level. |
| 171 | * @dev: the master device | ||
| 172 | * | ||
| 165 | * Only call if dev->bus_master->touch_bit is NULL | 173 | * Only call if dev->bus_master->touch_bit is NULL |
| 166 | */ | 174 | */ |
| 167 | static u8 w1_read_bit(struct w1_master *dev) | 175 | static u8 w1_read_bit(struct w1_master *dev) |
| @@ -185,16 +193,17 @@ static u8 w1_read_bit(struct w1_master *dev) | |||
| 185 | } | 193 | } |
| 186 | 194 | ||
| 187 | /** | 195 | /** |
| 188 | * Does a triplet - used for searching ROM addresses. | 196 | * w1_triplet() - * Does a triplet - used for searching ROM addresses. |
| 197 | * @dev: the master device | ||
| 198 | * @bdir: the bit to write if both id_bit and comp_bit are 0 | ||
| 199 | * | ||
| 189 | * Return bits: | 200 | * Return bits: |
| 190 | * bit 0 = id_bit | 201 | * bit 0 = id_bit |
| 191 | * bit 1 = comp_bit | 202 | * bit 1 = comp_bit |
| 192 | * bit 2 = dir_taken | 203 | * bit 2 = dir_taken |
| 193 | * If both bits 0 & 1 are set, the search should be restarted. | 204 | * If both bits 0 & 1 are set, the search should be restarted. |
| 194 | * | 205 | * |
| 195 | * @param dev the master device | 206 | * Return: bit fields - see above |
| 196 | * @param bdir the bit to write if both id_bit and comp_bit are 0 | ||
| 197 | * @return bit fields - see above | ||
| 198 | */ | 207 | */ |
| 199 | u8 w1_triplet(struct w1_master *dev, int bdir) | 208 | u8 w1_triplet(struct w1_master *dev, int bdir) |
| 200 | { | 209 | { |
| @@ -226,10 +235,10 @@ u8 w1_triplet(struct w1_master *dev, int bdir) | |||
| 226 | } | 235 | } |
| 227 | 236 | ||
| 228 | /** | 237 | /** |
| 229 | * Reads 8 bits. | 238 | * w1_read_8() - Reads 8 bits. |
| 239 | * @dev: the master device | ||
| 230 | * | 240 | * |
| 231 | * @param dev the master device | 241 | * Return: the byte read |
| 232 | * @return the byte read | ||
| 233 | */ | 242 | */ |
| 234 | u8 w1_read_8(struct w1_master *dev) | 243 | u8 w1_read_8(struct w1_master *dev) |
| 235 | { | 244 | { |
| @@ -247,11 +256,10 @@ u8 w1_read_8(struct w1_master *dev) | |||
| 247 | EXPORT_SYMBOL_GPL(w1_read_8); | 256 | EXPORT_SYMBOL_GPL(w1_read_8); |
| 248 | 257 | ||
| 249 | /** | 258 | /** |
| 250 | * Writes a series of bytes. | 259 | * w1_write_block() - Writes a series of bytes. |
| 251 | * | 260 | * @dev: the master device |
| 252 | * @param dev the master device | 261 | * @buf: pointer to the data to write |
| 253 | * @param buf pointer to the data to write | 262 | * @len: the number of bytes to write |
| 254 | * @param len the number of bytes to write | ||
| 255 | */ | 263 | */ |
| 256 | void w1_write_block(struct w1_master *dev, const u8 *buf, int len) | 264 | void w1_write_block(struct w1_master *dev, const u8 *buf, int len) |
| 257 | { | 265 | { |
| @@ -269,11 +277,10 @@ void w1_write_block(struct w1_master *dev, const u8 *buf, int len) | |||
| 269 | EXPORT_SYMBOL_GPL(w1_write_block); | 277 | EXPORT_SYMBOL_GPL(w1_write_block); |
| 270 | 278 | ||
| 271 | /** | 279 | /** |
| 272 | * Touches a series of bytes. | 280 | * w1_touch_block() - Touches a series of bytes. |
| 273 | * | 281 | * @dev: the master device |
| 274 | * @param dev the master device | 282 | * @buf: pointer to the data to write |
| 275 | * @param buf pointer to the data to write | 283 | * @len: the number of bytes to write |
| 276 | * @param len the number of bytes to write | ||
| 277 | */ | 284 | */ |
| 278 | void w1_touch_block(struct w1_master *dev, u8 *buf, int len) | 285 | void w1_touch_block(struct w1_master *dev, u8 *buf, int len) |
| 279 | { | 286 | { |
| @@ -294,12 +301,11 @@ void w1_touch_block(struct w1_master *dev, u8 *buf, int len) | |||
| 294 | EXPORT_SYMBOL_GPL(w1_touch_block); | 301 | EXPORT_SYMBOL_GPL(w1_touch_block); |
| 295 | 302 | ||
| 296 | /** | 303 | /** |
| 297 | * Reads a series of bytes. | 304 | * w1_read_block() - Reads a series of bytes. |
| 298 | * | 305 | * @dev: the master device |
| 299 | * @param dev the master device | 306 | * @buf: pointer to the buffer to fill |
| 300 | * @param buf pointer to the buffer to fill | 307 | * @len: the number of bytes to read |
| 301 | * @param len the number of bytes to read | 308 | * Return: the number of bytes read |
| 302 | * @return the number of bytes read | ||
| 303 | */ | 309 | */ |
| 304 | u8 w1_read_block(struct w1_master *dev, u8 *buf, int len) | 310 | u8 w1_read_block(struct w1_master *dev, u8 *buf, int len) |
| 305 | { | 311 | { |
| @@ -319,10 +325,9 @@ u8 w1_read_block(struct w1_master *dev, u8 *buf, int len) | |||
| 319 | EXPORT_SYMBOL_GPL(w1_read_block); | 325 | EXPORT_SYMBOL_GPL(w1_read_block); |
| 320 | 326 | ||
| 321 | /** | 327 | /** |
| 322 | * Issues a reset bus sequence. | 328 | * w1_reset_bus() - Issues a reset bus sequence. |
| 323 | * | 329 | * @dev: the master device |
| 324 | * @param dev The bus master pointer | 330 | * Return: 0=Device present, 1=No device present or error |
| 325 | * @return 0=Device present, 1=No device present or error | ||
| 326 | */ | 331 | */ |
| 327 | int w1_reset_bus(struct w1_master *dev) | 332 | int w1_reset_bus(struct w1_master *dev) |
| 328 | { | 333 | { |
| @@ -383,12 +388,15 @@ void w1_search_devices(struct w1_master *dev, u8 search_type, w1_slave_found_cal | |||
| 383 | } | 388 | } |
| 384 | 389 | ||
| 385 | /** | 390 | /** |
| 391 | * w1_reset_select_slave() - reset and select a slave | ||
| 392 | * @sl: the slave to select | ||
| 393 | * | ||
| 386 | * Resets the bus and then selects the slave by sending either a skip rom | 394 | * Resets the bus and then selects the slave by sending either a skip rom |
| 387 | * or a rom match. | 395 | * or a rom match. A skip rom is issued if there is only one device |
| 396 | * registered on the bus. | ||
| 388 | * The w1 master lock must be held. | 397 | * The w1 master lock must be held. |
| 389 | * | 398 | * |
| 390 | * @param sl the slave to select | 399 | * Return: 0=success, anything else=error |
| 391 | * @return 0=success, anything else=error | ||
| 392 | */ | 400 | */ |
| 393 | int w1_reset_select_slave(struct w1_slave *sl) | 401 | int w1_reset_select_slave(struct w1_slave *sl) |
| 394 | { | 402 | { |
| @@ -409,6 +417,9 @@ int w1_reset_select_slave(struct w1_slave *sl) | |||
| 409 | EXPORT_SYMBOL_GPL(w1_reset_select_slave); | 417 | EXPORT_SYMBOL_GPL(w1_reset_select_slave); |
| 410 | 418 | ||
| 411 | /** | 419 | /** |
| 420 | * w1_reset_resume_command() - resume instead of another match ROM | ||
| 421 | * @dev: the master device | ||
| 422 | * | ||
| 412 | * When the workflow with a slave amongst many requires several | 423 | * When the workflow with a slave amongst many requires several |
| 413 | * successive commands a reset between each, this function is similar | 424 | * successive commands a reset between each, this function is similar |
| 414 | * to doing a reset then a match ROM for the last matched ROM. The | 425 | * to doing a reset then a match ROM for the last matched ROM. The |
| @@ -420,8 +431,6 @@ EXPORT_SYMBOL_GPL(w1_reset_select_slave); | |||
| 420 | * doesn't work of course, but the resume command is the next best thing. | 431 | * doesn't work of course, but the resume command is the next best thing. |
| 421 | * | 432 | * |
| 422 | * The w1 master lock must be held. | 433 | * The w1 master lock must be held. |
| 423 | * | ||
| 424 | * @param dev the master device | ||
| 425 | */ | 434 | */ |
| 426 | int w1_reset_resume_command(struct w1_master *dev) | 435 | int w1_reset_resume_command(struct w1_master *dev) |
| 427 | { | 436 | { |
| @@ -435,6 +444,10 @@ int w1_reset_resume_command(struct w1_master *dev) | |||
| 435 | EXPORT_SYMBOL_GPL(w1_reset_resume_command); | 444 | EXPORT_SYMBOL_GPL(w1_reset_resume_command); |
| 436 | 445 | ||
| 437 | /** | 446 | /** |
| 447 | * w1_next_pullup() - register for a strong pullup | ||
| 448 | * @dev: the master device | ||
| 449 | * @delay: time in milliseconds | ||
| 450 | * | ||
| 438 | * Put out a strong pull-up of the specified duration after the next write | 451 | * Put out a strong pull-up of the specified duration after the next write |
| 439 | * operation. Not all hardware supports strong pullups. Hardware that | 452 | * operation. Not all hardware supports strong pullups. Hardware that |
| 440 | * doesn't support strong pullups will sleep for the given time after the | 453 | * doesn't support strong pullups will sleep for the given time after the |
| @@ -442,8 +455,7 @@ EXPORT_SYMBOL_GPL(w1_reset_resume_command); | |||
| 442 | * the next write, specifying zero will clear a previous request. | 455 | * the next write, specifying zero will clear a previous request. |
| 443 | * The w1 master lock must be held. | 456 | * The w1 master lock must be held. |
| 444 | * | 457 | * |
| 445 | * @param delay time in milliseconds | 458 | * Return: 0=success, anything else=error |
| 446 | * @return 0=success, anything else=error | ||
| 447 | */ | 459 | */ |
| 448 | void w1_next_pullup(struct w1_master *dev, int delay) | 460 | void w1_next_pullup(struct w1_master *dev, int delay) |
| 449 | { | 461 | { |
diff --git a/drivers/w1/w1_netlink.c b/drivers/w1/w1_netlink.c index 40788c925d1c..5234964fe001 100644 --- a/drivers/w1/w1_netlink.c +++ b/drivers/w1/w1_netlink.c | |||
| @@ -45,7 +45,7 @@ void w1_netlink_send(struct w1_master *dev, struct w1_netlink_msg *msg) | |||
| 45 | 45 | ||
| 46 | memcpy(w, msg, sizeof(struct w1_netlink_msg)); | 46 | memcpy(w, msg, sizeof(struct w1_netlink_msg)); |
| 47 | 47 | ||
| 48 | cn_netlink_send(m, 0, GFP_KERNEL); | 48 | cn_netlink_send(m, dev->portid, 0, GFP_KERNEL); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | static void w1_send_slave(struct w1_master *dev, u64 rn) | 51 | static void w1_send_slave(struct w1_master *dev, u64 rn) |
| @@ -54,53 +54,95 @@ static void w1_send_slave(struct w1_master *dev, u64 rn) | |||
| 54 | struct w1_netlink_msg *hdr = (struct w1_netlink_msg *)(msg + 1); | 54 | struct w1_netlink_msg *hdr = (struct w1_netlink_msg *)(msg + 1); |
| 55 | struct w1_netlink_cmd *cmd = (struct w1_netlink_cmd *)(hdr + 1); | 55 | struct w1_netlink_cmd *cmd = (struct w1_netlink_cmd *)(hdr + 1); |
| 56 | int avail; | 56 | int avail; |
| 57 | 57 | u64 *data; | |
| 58 | /* update kernel slave list */ | ||
| 59 | w1_slave_found(dev, rn); | ||
| 60 | 58 | ||
| 61 | avail = dev->priv_size - cmd->len; | 59 | avail = dev->priv_size - cmd->len; |
| 62 | 60 | ||
| 63 | if (avail > 8) { | 61 | if (avail < 8) { |
| 64 | u64 *data = (void *)(cmd + 1) + cmd->len; | 62 | msg->ack++; |
| 63 | cn_netlink_send(msg, dev->portid, 0, GFP_KERNEL); | ||
| 65 | 64 | ||
| 66 | *data = rn; | 65 | msg->len = sizeof(struct w1_netlink_msg) + |
| 67 | cmd->len += 8; | 66 | sizeof(struct w1_netlink_cmd); |
| 68 | hdr->len += 8; | 67 | hdr->len = sizeof(struct w1_netlink_cmd); |
| 69 | msg->len += 8; | 68 | cmd->len = 0; |
| 70 | return; | ||
| 71 | } | 69 | } |
| 72 | 70 | ||
| 73 | msg->ack++; | 71 | data = (void *)(cmd + 1) + cmd->len; |
| 74 | cn_netlink_send(msg, 0, GFP_KERNEL); | ||
| 75 | 72 | ||
| 76 | msg->len = sizeof(struct w1_netlink_msg) + sizeof(struct w1_netlink_cmd); | 73 | *data = rn; |
| 77 | hdr->len = sizeof(struct w1_netlink_cmd); | 74 | cmd->len += 8; |
| 78 | cmd->len = 0; | 75 | hdr->len += 8; |
| 76 | msg->len += 8; | ||
| 79 | } | 77 | } |
| 80 | 78 | ||
| 81 | static int w1_process_search_command(struct w1_master *dev, struct cn_msg *msg, | 79 | static void w1_found_send_slave(struct w1_master *dev, u64 rn) |
| 82 | unsigned int avail) | ||
| 83 | { | 80 | { |
| 84 | struct w1_netlink_msg *hdr = (struct w1_netlink_msg *)(msg + 1); | 81 | /* update kernel slave list */ |
| 85 | struct w1_netlink_cmd *cmd = (struct w1_netlink_cmd *)(hdr + 1); | 82 | w1_slave_found(dev, rn); |
| 86 | int search_type = (cmd->cmd == W1_CMD_ALARM_SEARCH)?W1_ALARM_SEARCH:W1_SEARCH; | ||
| 87 | 83 | ||
| 88 | dev->priv = msg; | 84 | w1_send_slave(dev, rn); |
| 89 | dev->priv_size = avail; | 85 | } |
| 86 | |||
| 87 | /* Get the current slave list, or search (with or without alarm) */ | ||
| 88 | static int w1_get_slaves(struct w1_master *dev, | ||
| 89 | struct cn_msg *req_msg, struct w1_netlink_msg *req_hdr, | ||
| 90 | struct w1_netlink_cmd *req_cmd) | ||
| 91 | { | ||
| 92 | struct cn_msg *msg; | ||
| 93 | struct w1_netlink_msg *hdr; | ||
| 94 | struct w1_netlink_cmd *cmd; | ||
| 95 | struct w1_slave *sl; | ||
| 96 | |||
| 97 | msg = kzalloc(PAGE_SIZE, GFP_KERNEL); | ||
| 98 | if (!msg) | ||
| 99 | return -ENOMEM; | ||
| 100 | |||
| 101 | msg->id = req_msg->id; | ||
| 102 | msg->seq = req_msg->seq; | ||
| 103 | msg->ack = 0; | ||
| 104 | msg->len = sizeof(struct w1_netlink_msg) + | ||
| 105 | sizeof(struct w1_netlink_cmd); | ||
| 106 | |||
| 107 | hdr = (struct w1_netlink_msg *)(msg + 1); | ||
| 108 | cmd = (struct w1_netlink_cmd *)(hdr + 1); | ||
| 109 | |||
| 110 | hdr->type = W1_MASTER_CMD; | ||
| 111 | hdr->id = req_hdr->id; | ||
| 112 | hdr->len = sizeof(struct w1_netlink_cmd); | ||
| 113 | |||
| 114 | cmd->cmd = req_cmd->cmd; | ||
| 115 | cmd->len = 0; | ||
| 90 | 116 | ||
| 91 | w1_search_process_cb(dev, search_type, w1_send_slave); | 117 | dev->priv = msg; |
| 118 | dev->priv_size = PAGE_SIZE - msg->len - sizeof(struct cn_msg); | ||
| 119 | |||
| 120 | if (req_cmd->cmd == W1_CMD_LIST_SLAVES) { | ||
| 121 | __u64 rn; | ||
| 122 | mutex_lock(&dev->list_mutex); | ||
| 123 | list_for_each_entry(sl, &dev->slist, w1_slave_entry) { | ||
| 124 | memcpy(&rn, &sl->reg_num, sizeof(rn)); | ||
| 125 | w1_send_slave(dev, rn); | ||
| 126 | } | ||
| 127 | mutex_unlock(&dev->list_mutex); | ||
| 128 | } else { | ||
| 129 | w1_search_process_cb(dev, cmd->cmd == W1_CMD_ALARM_SEARCH ? | ||
| 130 | W1_ALARM_SEARCH : W1_SEARCH, w1_found_send_slave); | ||
| 131 | } | ||
| 92 | 132 | ||
| 93 | msg->ack = 0; | 133 | msg->ack = 0; |
| 94 | cn_netlink_send(msg, 0, GFP_KERNEL); | 134 | cn_netlink_send(msg, dev->portid, 0, GFP_KERNEL); |
| 95 | 135 | ||
| 96 | dev->priv = NULL; | 136 | dev->priv = NULL; |
| 97 | dev->priv_size = 0; | 137 | dev->priv_size = 0; |
| 98 | 138 | ||
| 139 | kfree(msg); | ||
| 140 | |||
| 99 | return 0; | 141 | return 0; |
| 100 | } | 142 | } |
| 101 | 143 | ||
| 102 | static int w1_send_read_reply(struct cn_msg *msg, struct w1_netlink_msg *hdr, | 144 | static int w1_send_read_reply(struct cn_msg *msg, struct w1_netlink_msg *hdr, |
| 103 | struct w1_netlink_cmd *cmd) | 145 | struct w1_netlink_cmd *cmd, u32 portid) |
| 104 | { | 146 | { |
| 105 | void *data; | 147 | void *data; |
| 106 | struct w1_netlink_msg *h; | 148 | struct w1_netlink_msg *h; |
| @@ -131,7 +173,7 @@ static int w1_send_read_reply(struct cn_msg *msg, struct w1_netlink_msg *hdr, | |||
| 131 | 173 | ||
| 132 | memcpy(c->data, cmd->data, c->len); | 174 | memcpy(c->data, cmd->data, c->len); |
| 133 | 175 | ||
| 134 | err = cn_netlink_send(cm, 0, GFP_KERNEL); | 176 | err = cn_netlink_send(cm, portid, 0, GFP_KERNEL); |
| 135 | 177 | ||
| 136 | kfree(data); | 178 | kfree(data); |
| 137 | 179 | ||
| @@ -146,11 +188,11 @@ static int w1_process_command_io(struct w1_master *dev, struct cn_msg *msg, | |||
| 146 | switch (cmd->cmd) { | 188 | switch (cmd->cmd) { |
| 147 | case W1_CMD_TOUCH: | 189 | case W1_CMD_TOUCH: |
| 148 | w1_touch_block(dev, cmd->data, cmd->len); | 190 | w1_touch_block(dev, cmd->data, cmd->len); |
| 149 | w1_send_read_reply(msg, hdr, cmd); | 191 | w1_send_read_reply(msg, hdr, cmd, dev->portid); |
| 150 | break; | 192 | break; |
| 151 | case W1_CMD_READ: | 193 | case W1_CMD_READ: |
| 152 | w1_read_block(dev, cmd->data, cmd->len); | 194 | w1_read_block(dev, cmd->data, cmd->len); |
| 153 | w1_send_read_reply(msg, hdr, cmd); | 195 | w1_send_read_reply(msg, hdr, cmd, dev->portid); |
| 154 | break; | 196 | break; |
| 155 | case W1_CMD_WRITE: | 197 | case W1_CMD_WRITE: |
| 156 | w1_write_block(dev, cmd->data, cmd->len); | 198 | w1_write_block(dev, cmd->data, cmd->len); |
| @@ -163,38 +205,57 @@ static int w1_process_command_io(struct w1_master *dev, struct cn_msg *msg, | |||
| 163 | return err; | 205 | return err; |
| 164 | } | 206 | } |
| 165 | 207 | ||
| 166 | static int w1_process_command_master(struct w1_master *dev, struct cn_msg *req_msg, | 208 | static int w1_process_command_addremove(struct w1_master *dev, |
| 167 | struct w1_netlink_msg *req_hdr, struct w1_netlink_cmd *req_cmd) | 209 | struct cn_msg *msg, struct w1_netlink_msg *hdr, |
| 210 | struct w1_netlink_cmd *cmd) | ||
| 168 | { | 211 | { |
| 169 | int err = -EINVAL; | 212 | struct w1_slave *sl; |
| 170 | struct cn_msg *msg; | 213 | int err = 0; |
| 171 | struct w1_netlink_msg *hdr; | 214 | struct w1_reg_num *id; |
| 172 | struct w1_netlink_cmd *cmd; | ||
| 173 | 215 | ||
| 174 | msg = kzalloc(PAGE_SIZE, GFP_KERNEL); | 216 | if (cmd->len != 8) |
| 175 | if (!msg) | 217 | return -EINVAL; |
| 176 | return -ENOMEM; | ||
| 177 | 218 | ||
| 178 | msg->id = req_msg->id; | 219 | id = (struct w1_reg_num *)cmd->data; |
| 179 | msg->seq = req_msg->seq; | ||
| 180 | msg->ack = 0; | ||
| 181 | msg->len = sizeof(struct w1_netlink_msg) + sizeof(struct w1_netlink_cmd); | ||
| 182 | 220 | ||
| 183 | hdr = (struct w1_netlink_msg *)(msg + 1); | 221 | sl = w1_slave_search_device(dev, id); |
| 184 | cmd = (struct w1_netlink_cmd *)(hdr + 1); | 222 | switch (cmd->cmd) { |
| 223 | case W1_CMD_SLAVE_ADD: | ||
| 224 | if (sl) | ||
| 225 | err = -EINVAL; | ||
| 226 | else | ||
| 227 | err = w1_attach_slave_device(dev, id); | ||
| 228 | break; | ||
| 229 | case W1_CMD_SLAVE_REMOVE: | ||
| 230 | if (sl) | ||
| 231 | w1_slave_detach(sl); | ||
| 232 | else | ||
| 233 | err = -EINVAL; | ||
| 234 | break; | ||
| 235 | default: | ||
| 236 | err = -EINVAL; | ||
| 237 | break; | ||
| 238 | } | ||
| 185 | 239 | ||
| 186 | hdr->type = W1_MASTER_CMD; | 240 | return err; |
| 187 | hdr->id = req_hdr->id; | 241 | } |
| 188 | hdr->len = sizeof(struct w1_netlink_cmd); | ||
| 189 | 242 | ||
| 190 | cmd->cmd = req_cmd->cmd; | 243 | static int w1_process_command_master(struct w1_master *dev, |
| 191 | cmd->len = 0; | 244 | struct cn_msg *req_msg, struct w1_netlink_msg *req_hdr, |
| 245 | struct w1_netlink_cmd *req_cmd) | ||
| 246 | { | ||
| 247 | int err = -EINVAL; | ||
| 192 | 248 | ||
| 193 | switch (cmd->cmd) { | 249 | /* drop bus_mutex for search (does it's own locking), and add/remove |
| 250 | * which doesn't use the bus | ||
| 251 | */ | ||
| 252 | switch (req_cmd->cmd) { | ||
| 194 | case W1_CMD_SEARCH: | 253 | case W1_CMD_SEARCH: |
| 195 | case W1_CMD_ALARM_SEARCH: | 254 | case W1_CMD_ALARM_SEARCH: |
| 196 | err = w1_process_search_command(dev, msg, | 255 | case W1_CMD_LIST_SLAVES: |
| 197 | PAGE_SIZE - msg->len - sizeof(struct cn_msg)); | 256 | mutex_unlock(&dev->bus_mutex); |
| 257 | err = w1_get_slaves(dev, req_msg, req_hdr, req_cmd); | ||
| 258 | mutex_lock(&dev->bus_mutex); | ||
| 198 | break; | 259 | break; |
| 199 | case W1_CMD_READ: | 260 | case W1_CMD_READ: |
| 200 | case W1_CMD_WRITE: | 261 | case W1_CMD_WRITE: |
| @@ -204,12 +265,20 @@ static int w1_process_command_master(struct w1_master *dev, struct cn_msg *req_m | |||
| 204 | case W1_CMD_RESET: | 265 | case W1_CMD_RESET: |
| 205 | err = w1_reset_bus(dev); | 266 | err = w1_reset_bus(dev); |
| 206 | break; | 267 | break; |
| 268 | case W1_CMD_SLAVE_ADD: | ||
| 269 | case W1_CMD_SLAVE_REMOVE: | ||
| 270 | mutex_unlock(&dev->bus_mutex); | ||
| 271 | mutex_lock(&dev->mutex); | ||
| 272 | err = w1_process_command_addremove(dev, req_msg, req_hdr, | ||
| 273 | req_cmd); | ||
| 274 | mutex_unlock(&dev->mutex); | ||
| 275 | mutex_lock(&dev->bus_mutex); | ||
| 276 | break; | ||
| 207 | default: | 277 | default: |
| 208 | err = -EINVAL; | 278 | err = -EINVAL; |
| 209 | break; | 279 | break; |
| 210 | } | 280 | } |
| 211 | 281 | ||
| 212 | kfree(msg); | ||
| 213 | return err; | 282 | return err; |
| 214 | } | 283 | } |
| 215 | 284 | ||
| @@ -223,7 +292,8 @@ static int w1_process_command_slave(struct w1_slave *sl, struct cn_msg *msg, | |||
| 223 | return w1_process_command_io(sl->master, msg, hdr, cmd); | 292 | return w1_process_command_io(sl->master, msg, hdr, cmd); |
| 224 | } | 293 | } |
| 225 | 294 | ||
| 226 | static int w1_process_command_root(struct cn_msg *msg, struct w1_netlink_msg *mcmd) | 295 | static int w1_process_command_root(struct cn_msg *msg, |
| 296 | struct w1_netlink_msg *mcmd, u32 portid) | ||
| 227 | { | 297 | { |
| 228 | struct w1_master *m; | 298 | struct w1_master *m; |
| 229 | struct cn_msg *cn; | 299 | struct cn_msg *cn; |
| @@ -256,7 +326,7 @@ static int w1_process_command_root(struct cn_msg *msg, struct w1_netlink_msg *mc | |||
| 256 | mutex_lock(&w1_mlock); | 326 | mutex_lock(&w1_mlock); |
| 257 | list_for_each_entry(m, &w1_masters, w1_master_entry) { | 327 | list_for_each_entry(m, &w1_masters, w1_master_entry) { |
| 258 | if (cn->len + sizeof(*id) > PAGE_SIZE - sizeof(struct cn_msg)) { | 328 | if (cn->len + sizeof(*id) > PAGE_SIZE - sizeof(struct cn_msg)) { |
| 259 | cn_netlink_send(cn, 0, GFP_KERNEL); | 329 | cn_netlink_send(cn, portid, 0, GFP_KERNEL); |
| 260 | cn->ack++; | 330 | cn->ack++; |
| 261 | cn->len = sizeof(struct w1_netlink_msg); | 331 | cn->len = sizeof(struct w1_netlink_msg); |
| 262 | w->len = 0; | 332 | w->len = 0; |
| @@ -269,7 +339,7 @@ static int w1_process_command_root(struct cn_msg *msg, struct w1_netlink_msg *mc | |||
| 269 | id++; | 339 | id++; |
| 270 | } | 340 | } |
| 271 | cn->ack = 0; | 341 | cn->ack = 0; |
| 272 | cn_netlink_send(cn, 0, GFP_KERNEL); | 342 | cn_netlink_send(cn, portid, 0, GFP_KERNEL); |
| 273 | mutex_unlock(&w1_mlock); | 343 | mutex_unlock(&w1_mlock); |
| 274 | 344 | ||
| 275 | kfree(cn); | 345 | kfree(cn); |
| @@ -277,7 +347,7 @@ static int w1_process_command_root(struct cn_msg *msg, struct w1_netlink_msg *mc | |||
| 277 | } | 347 | } |
| 278 | 348 | ||
| 279 | static int w1_netlink_send_error(struct cn_msg *rcmsg, struct w1_netlink_msg *rmsg, | 349 | static int w1_netlink_send_error(struct cn_msg *rcmsg, struct w1_netlink_msg *rmsg, |
| 280 | struct w1_netlink_cmd *rcmd, int error) | 350 | struct w1_netlink_cmd *rcmd, int portid, int error) |
| 281 | { | 351 | { |
| 282 | struct cn_msg *cmsg; | 352 | struct cn_msg *cmsg; |
| 283 | struct w1_netlink_msg *msg; | 353 | struct w1_netlink_msg *msg; |
| @@ -304,35 +374,147 @@ static int w1_netlink_send_error(struct cn_msg *rcmsg, struct w1_netlink_msg *rm | |||
| 304 | cmsg->len += sizeof(*cmd); | 374 | cmsg->len += sizeof(*cmd); |
| 305 | } | 375 | } |
| 306 | 376 | ||
| 307 | error = cn_netlink_send(cmsg, 0, GFP_KERNEL); | 377 | error = cn_netlink_send(cmsg, portid, 0, GFP_KERNEL); |
| 308 | kfree(cmsg); | 378 | kfree(cmsg); |
| 309 | 379 | ||
| 310 | return error; | 380 | return error; |
| 311 | } | 381 | } |
| 312 | 382 | ||
| 383 | /* Bundle together a reference count, the full message, and broken out | ||
| 384 | * commands to be executed on each w1 master kthread in one memory allocation. | ||
| 385 | */ | ||
| 386 | struct w1_cb_block { | ||
| 387 | atomic_t refcnt; | ||
| 388 | u32 portid; /* Sending process port ID */ | ||
| 389 | struct cn_msg msg; | ||
| 390 | /* cn_msg data */ | ||
| 391 | /* one or more variable length struct w1_cb_node */ | ||
| 392 | }; | ||
| 393 | struct w1_cb_node { | ||
| 394 | struct w1_async_cmd async; | ||
| 395 | /* pointers within w1_cb_block and msg data */ | ||
| 396 | struct w1_cb_block *block; | ||
| 397 | struct w1_netlink_msg *m; | ||
| 398 | struct w1_slave *sl; | ||
| 399 | struct w1_master *dev; | ||
| 400 | }; | ||
| 401 | |||
| 402 | static void w1_process_cb(struct w1_master *dev, struct w1_async_cmd *async_cmd) | ||
| 403 | { | ||
| 404 | struct w1_cb_node *node = container_of(async_cmd, struct w1_cb_node, | ||
| 405 | async); | ||
| 406 | u16 mlen = node->m->len; | ||
| 407 | u8 *cmd_data = node->m->data; | ||
| 408 | int err = 0; | ||
| 409 | struct w1_slave *sl = node->sl; | ||
| 410 | struct w1_netlink_cmd *cmd = NULL; | ||
| 411 | |||
| 412 | mutex_lock(&dev->bus_mutex); | ||
| 413 | dev->portid = node->block->portid; | ||
| 414 | if (sl && w1_reset_select_slave(sl)) | ||
| 415 | err = -ENODEV; | ||
| 416 | |||
| 417 | while (mlen && !err) { | ||
| 418 | cmd = (struct w1_netlink_cmd *)cmd_data; | ||
| 419 | |||
| 420 | if (cmd->len + sizeof(struct w1_netlink_cmd) > mlen) { | ||
| 421 | err = -E2BIG; | ||
| 422 | break; | ||
| 423 | } | ||
| 424 | |||
| 425 | if (sl) | ||
| 426 | err = w1_process_command_slave(sl, &node->block->msg, | ||
| 427 | node->m, cmd); | ||
| 428 | else | ||
| 429 | err = w1_process_command_master(dev, &node->block->msg, | ||
| 430 | node->m, cmd); | ||
| 431 | |||
| 432 | w1_netlink_send_error(&node->block->msg, node->m, cmd, | ||
| 433 | node->block->portid, err); | ||
| 434 | err = 0; | ||
| 435 | |||
| 436 | cmd_data += cmd->len + sizeof(struct w1_netlink_cmd); | ||
| 437 | mlen -= cmd->len + sizeof(struct w1_netlink_cmd); | ||
| 438 | } | ||
| 439 | |||
| 440 | if (!cmd || err) | ||
| 441 | w1_netlink_send_error(&node->block->msg, node->m, cmd, | ||
| 442 | node->block->portid, err); | ||
| 443 | |||
| 444 | if (sl) | ||
| 445 | w1_unref_slave(sl); | ||
| 446 | else | ||
| 447 | atomic_dec(&dev->refcnt); | ||
| 448 | dev->portid = 0; | ||
| 449 | mutex_unlock(&dev->bus_mutex); | ||
| 450 | |||
| 451 | mutex_lock(&dev->list_mutex); | ||
| 452 | list_del(&async_cmd->async_entry); | ||
| 453 | mutex_unlock(&dev->list_mutex); | ||
| 454 | |||
| 455 | if (atomic_sub_return(1, &node->block->refcnt) == 0) | ||
| 456 | kfree(node->block); | ||
| 457 | } | ||
| 458 | |||
| 313 | static void w1_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp) | 459 | static void w1_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp) |
| 314 | { | 460 | { |
| 315 | struct w1_netlink_msg *m = (struct w1_netlink_msg *)(msg + 1); | 461 | struct w1_netlink_msg *m = (struct w1_netlink_msg *)(msg + 1); |
| 316 | struct w1_netlink_cmd *cmd; | ||
| 317 | struct w1_slave *sl; | 462 | struct w1_slave *sl; |
| 318 | struct w1_master *dev; | 463 | struct w1_master *dev; |
| 464 | u16 msg_len; | ||
| 319 | int err = 0; | 465 | int err = 0; |
| 466 | struct w1_cb_block *block = NULL; | ||
| 467 | struct w1_cb_node *node = NULL; | ||
| 468 | int node_count = 0; | ||
| 469 | |||
| 470 | /* Count the number of master or slave commands there are to allocate | ||
| 471 | * space for one cb_node each. | ||
| 472 | */ | ||
| 473 | msg_len = msg->len; | ||
| 474 | while (msg_len && !err) { | ||
| 475 | if (m->len + sizeof(struct w1_netlink_msg) > msg_len) { | ||
| 476 | err = -E2BIG; | ||
| 477 | break; | ||
| 478 | } | ||
| 479 | |||
| 480 | if (m->type == W1_MASTER_CMD || m->type == W1_SLAVE_CMD) | ||
| 481 | ++node_count; | ||
| 320 | 482 | ||
| 321 | while (msg->len && !err) { | 483 | msg_len -= sizeof(struct w1_netlink_msg) + m->len; |
| 484 | m = (struct w1_netlink_msg *)(((u8 *)m) + | ||
| 485 | sizeof(struct w1_netlink_msg) + m->len); | ||
| 486 | } | ||
| 487 | m = (struct w1_netlink_msg *)(msg + 1); | ||
| 488 | if (node_count) { | ||
| 489 | /* msg->len doesn't include itself */ | ||
| 490 | long size = sizeof(struct w1_cb_block) + msg->len + | ||
| 491 | node_count*sizeof(struct w1_cb_node); | ||
| 492 | block = kmalloc(size, GFP_KERNEL); | ||
| 493 | if (!block) { | ||
| 494 | w1_netlink_send_error(msg, m, NULL, nsp->portid, | ||
| 495 | -ENOMEM); | ||
| 496 | return; | ||
| 497 | } | ||
| 498 | atomic_set(&block->refcnt, 1); | ||
| 499 | block->portid = nsp->portid; | ||
| 500 | memcpy(&block->msg, msg, sizeof(*msg) + msg->len); | ||
| 501 | node = (struct w1_cb_node *)((u8 *)block->msg.data + msg->len); | ||
| 502 | } | ||
| 503 | |||
| 504 | msg_len = msg->len; | ||
| 505 | while (msg_len && !err) { | ||
| 322 | struct w1_reg_num id; | 506 | struct w1_reg_num id; |
| 323 | u16 mlen = m->len; | 507 | u16 mlen = m->len; |
| 324 | u8 *cmd_data = m->data; | ||
| 325 | 508 | ||
| 326 | dev = NULL; | 509 | dev = NULL; |
| 327 | sl = NULL; | 510 | sl = NULL; |
| 328 | cmd = NULL; | ||
| 329 | 511 | ||
| 330 | memcpy(&id, m->id.id, sizeof(id)); | 512 | memcpy(&id, m->id.id, sizeof(id)); |
| 331 | #if 0 | 513 | #if 0 |
| 332 | printk("%s: %02x.%012llx.%02x: type=%02x, len=%u.\n", | 514 | printk("%s: %02x.%012llx.%02x: type=%02x, len=%u.\n", |
| 333 | __func__, id.family, (unsigned long long)id.id, id.crc, m->type, m->len); | 515 | __func__, id.family, (unsigned long long)id.id, id.crc, m->type, m->len); |
| 334 | #endif | 516 | #endif |
| 335 | if (m->len + sizeof(struct w1_netlink_msg) > msg->len) { | 517 | if (m->len + sizeof(struct w1_netlink_msg) > msg_len) { |
| 336 | err = -E2BIG; | 518 | err = -E2BIG; |
| 337 | break; | 519 | break; |
| 338 | } | 520 | } |
| @@ -344,7 +526,7 @@ static void w1_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp) | |||
| 344 | if (sl) | 526 | if (sl) |
| 345 | dev = sl->master; | 527 | dev = sl->master; |
| 346 | } else { | 528 | } else { |
| 347 | err = w1_process_command_root(msg, m); | 529 | err = w1_process_command_root(msg, m, nsp->portid); |
| 348 | goto out_cont; | 530 | goto out_cont; |
| 349 | } | 531 | } |
| 350 | 532 | ||
| @@ -357,41 +539,24 @@ static void w1_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp) | |||
| 357 | if (!mlen) | 539 | if (!mlen) |
| 358 | goto out_cont; | 540 | goto out_cont; |
| 359 | 541 | ||
| 360 | mutex_lock(&dev->mutex); | 542 | atomic_inc(&block->refcnt); |
| 361 | 543 | node->async.cb = w1_process_cb; | |
| 362 | if (sl && w1_reset_select_slave(sl)) { | 544 | node->block = block; |
| 363 | err = -ENODEV; | 545 | node->m = (struct w1_netlink_msg *)((u8 *)&block->msg + |
| 364 | goto out_up; | 546 | (size_t)((u8 *)m - (u8 *)msg)); |
| 365 | } | 547 | node->sl = sl; |
| 548 | node->dev = dev; | ||
| 366 | 549 | ||
| 367 | while (mlen) { | 550 | mutex_lock(&dev->list_mutex); |
| 368 | cmd = (struct w1_netlink_cmd *)cmd_data; | 551 | list_add_tail(&node->async.async_entry, &dev->async_list); |
| 552 | wake_up_process(dev->thread); | ||
| 553 | mutex_unlock(&dev->list_mutex); | ||
| 554 | ++node; | ||
| 369 | 555 | ||
| 370 | if (cmd->len + sizeof(struct w1_netlink_cmd) > mlen) { | ||
| 371 | err = -E2BIG; | ||
| 372 | break; | ||
| 373 | } | ||
| 374 | |||
| 375 | if (sl) | ||
| 376 | err = w1_process_command_slave(sl, msg, m, cmd); | ||
| 377 | else | ||
| 378 | err = w1_process_command_master(dev, msg, m, cmd); | ||
| 379 | |||
| 380 | w1_netlink_send_error(msg, m, cmd, err); | ||
| 381 | err = 0; | ||
| 382 | |||
| 383 | cmd_data += cmd->len + sizeof(struct w1_netlink_cmd); | ||
| 384 | mlen -= cmd->len + sizeof(struct w1_netlink_cmd); | ||
| 385 | } | ||
| 386 | out_up: | ||
| 387 | atomic_dec(&dev->refcnt); | ||
| 388 | if (sl) | ||
| 389 | atomic_dec(&sl->refcnt); | ||
| 390 | mutex_unlock(&dev->mutex); | ||
| 391 | out_cont: | 556 | out_cont: |
| 392 | if (!cmd || err) | 557 | if (err) |
| 393 | w1_netlink_send_error(msg, m, cmd, err); | 558 | w1_netlink_send_error(msg, m, NULL, nsp->portid, err); |
| 394 | msg->len -= sizeof(struct w1_netlink_msg) + m->len; | 559 | msg_len -= sizeof(struct w1_netlink_msg) + m->len; |
| 395 | m = (struct w1_netlink_msg *)(((u8 *)m) + sizeof(struct w1_netlink_msg) + m->len); | 560 | m = (struct w1_netlink_msg *)(((u8 *)m) + sizeof(struct w1_netlink_msg) + m->len); |
| 396 | 561 | ||
| 397 | /* | 562 | /* |
| @@ -400,6 +565,8 @@ out_cont: | |||
| 400 | if (err == -ENODEV) | 565 | if (err == -ENODEV) |
| 401 | err = 0; | 566 | err = 0; |
| 402 | } | 567 | } |
| 568 | if (block && atomic_sub_return(1, &block->refcnt) == 0) | ||
| 569 | kfree(block); | ||
| 403 | } | 570 | } |
| 404 | 571 | ||
| 405 | int w1_init_netlink(void) | 572 | int w1_init_netlink(void) |
diff --git a/drivers/w1/w1_netlink.h b/drivers/w1/w1_netlink.h index b0922dc29658..1e9504e67650 100644 --- a/drivers/w1/w1_netlink.h +++ b/drivers/w1/w1_netlink.h | |||
| @@ -27,6 +27,18 @@ | |||
| 27 | 27 | ||
| 28 | #include "w1.h" | 28 | #include "w1.h" |
| 29 | 29 | ||
| 30 | /** | ||
| 31 | * enum w1_netlink_message_types - message type | ||
| 32 | * | ||
| 33 | * @W1_SLAVE_ADD: notification that a slave device was added | ||
| 34 | * @W1_SLAVE_REMOVE: notification that a slave device was removed | ||
| 35 | * @W1_MASTER_ADD: notification that a new bus master was added | ||
| 36 | * @W1_MASTER_REMOVE: notification that a bus masterwas removed | ||
| 37 | * @W1_MASTER_CMD: initiate operations on a specific master | ||
| 38 | * @W1_SLAVE_CMD: sends reset, selects the slave, then does a read/write/touch | ||
| 39 | * operation | ||
| 40 | * @W1_LIST_MASTERS: used to determine the bus master identifiers | ||
| 41 | */ | ||
| 30 | enum w1_netlink_message_types { | 42 | enum w1_netlink_message_types { |
| 31 | W1_SLAVE_ADD = 0, | 43 | W1_SLAVE_ADD = 0, |
| 32 | W1_SLAVE_REMOVE, | 44 | W1_SLAVE_REMOVE, |
| @@ -52,6 +64,22 @@ struct w1_netlink_msg | |||
| 52 | __u8 data[0]; | 64 | __u8 data[0]; |
| 53 | }; | 65 | }; |
| 54 | 66 | ||
| 67 | /** | ||
| 68 | * enum w1_commands - commands available for master or slave operations | ||
| 69 | * @W1_CMD_READ: read len bytes | ||
| 70 | * @W1_CMD_WRITE: write len bytes | ||
| 71 | * @W1_CMD_SEARCH: initiate a standard search, returns only the slave | ||
| 72 | * devices found during that search | ||
| 73 | * @W1_CMD_ALARM_SEARCH: search for devices that are currently alarming | ||
| 74 | * @W1_CMD_TOUCH: Touches a series of bytes. | ||
| 75 | * @W1_CMD_RESET: sends a bus reset on the given master | ||
| 76 | * @W1_CMD_SLAVE_ADD: adds a slave to the given master, | ||
| 77 | * 8 byte slave id at data[0] | ||
| 78 | * @W1_CMD_SLAVE_REMOVE: removes a slave to the given master, | ||
| 79 | * 8 byte slave id at data[0] | ||
| 80 | * @W1_CMD_LIST_SLAVES: list of slaves registered on this master | ||
| 81 | * @W1_CMD_MAX: number of available commands | ||
| 82 | */ | ||
| 55 | enum w1_commands { | 83 | enum w1_commands { |
| 56 | W1_CMD_READ = 0, | 84 | W1_CMD_READ = 0, |
| 57 | W1_CMD_WRITE, | 85 | W1_CMD_WRITE, |
| @@ -59,7 +87,10 @@ enum w1_commands { | |||
| 59 | W1_CMD_ALARM_SEARCH, | 87 | W1_CMD_ALARM_SEARCH, |
| 60 | W1_CMD_TOUCH, | 88 | W1_CMD_TOUCH, |
| 61 | W1_CMD_RESET, | 89 | W1_CMD_RESET, |
| 62 | W1_CMD_MAX, | 90 | W1_CMD_SLAVE_ADD, |
| 91 | W1_CMD_SLAVE_REMOVE, | ||
| 92 | W1_CMD_LIST_SLAVES, | ||
| 93 | W1_CMD_MAX | ||
| 63 | }; | 94 | }; |
| 64 | 95 | ||
| 65 | struct w1_netlink_cmd | 96 | struct w1_netlink_cmd |
