Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'char-misc-4.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc

Pull char/misc driver updates from Greg KH:
"Here's the big char/misc driver patchset for 4.1-rc1.

Lots of different driver subsystem updates here, nothing major, full
details are in the shortlog.

All of this has been in linux-next for a while"

* tag 'char-misc-4.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (133 commits)
mei: trace: remove unused TRACE_SYSTEM_STRING
DTS: ARM: OMAP3-N900: Add lis3lv02d support
Documentation: DT: lis302: update wakeup binding
lis3lv02d: DT: add wakeup unit 2 and wakeup threshold
lis3lv02d: DT: use s32 to support negative values
Drivers: hv: hv_balloon: correctly handle num_pages>INT_MAX case
Drivers: hv: hv_balloon: correctly handle val.freeram<num_pages case
mei: replace check for connection instead of transitioning
mei: use mei_cl_is_connected consistently
mei: fix mei_poll operation
hv_vmbus: Add gradually increased delay for retries in vmbus_post_msg()
Drivers: hv: hv_balloon: survive ballooning request with num_pages=0
Drivers: hv: hv_balloon: eliminate jumps in piecewiese linear floor function
Drivers: hv: hv_balloon: do not online pages in offline blocks
hv: remove the per-channel workqueue
hv: don't schedule new works in vmbus_onoffer()/vmbus_onoffer_rescind()
hv: run non-blocking message handlers in the dispatch tasklet
coresight: moving to new "hwtracing" directory
coresight-tmc: Adding a status interface to sysfs
coresight: remove the unnecessary configuration coresight-default-sink
...

+4045 -1494
-1
Documentation/devicetree/bindings/arm/coresight.txt
··· 61 61 compatible = "arm,coresight-etb10", "arm,primecell"; 62 62 reg = <0 0x20010000 0 0x1000>; 63 63 64 - coresight-default-sink; 65 64 clocks = <&oscclk6a>; 66 65 clock-names = "apb_pclk"; 67 66 port {
+18
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
··· 1 + USB GPIO Extcon device 2 + 3 + This is a virtual device used to generate USB cable states from the USB ID pin 4 + connected to a GPIO pin. 5 + 6 + Required properties: 7 + - compatible: Should be "linux,extcon-usb-gpio" 8 + - id-gpio: gpio for USB ID pin. See gpio binding. 9 + 10 + Example: Examples of extcon-usb-gpio node in dra7-evm.dts as listed below: 11 + extcon_usb1 { 12 + compatible = "linux,extcon-usb-gpio"; 13 + id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>; 14 + } 15 + 16 + &omap_dwc3_1 { 17 + extcon = <&extcon_usb1>; 18 + };
+75
Documentation/devicetree/bindings/memory-controllers/ingenic,jz4780-nemc.txt
··· 1 + * Ingenic JZ4780 NAND/external memory controller (NEMC) 2 + 3 + This file documents the device tree bindings for the NEMC external memory 4 + controller in Ingenic JZ4780 5 + 6 + Required properties: 7 + - compatible: Should be set to one of: 8 + "ingenic,jz4780-nemc" (JZ4780) 9 + - reg: Should specify the NEMC controller registers location and length. 10 + - clocks: Clock for the NEMC controller. 11 + - #address-cells: Must be set to 2. 12 + - #size-cells: Must be set to 1. 13 + - ranges: A set of ranges for each bank describing the physical memory layout. 14 + Each should specify the following 4 integer values: 15 + 16 + <cs number> 0 <physical address of mapping> <size of mapping> 17 + 18 + Each child of the NEMC node describes a device connected to the NEMC. 19 + 20 + Required child node properties: 21 + - reg: Should contain at least one register specifier, given in the following 22 + format: 23 + 24 + <cs number> <offset> <size> 25 + 26 + Multiple registers can be specified across multiple banks. This is needed, 27 + for example, for packaged NAND devices with multiple dies. Such devices 28 + should be grouped into a single node. 29 + 30 + Optional child node properties: 31 + - ingenic,nemc-bus-width: Specifies the bus width in bits. Defaults to 8 bits. 32 + - ingenic,nemc-tAS: Address setup time in nanoseconds. 33 + - ingenic,nemc-tAH: Address hold time in nanoseconds. 34 + - ingenic,nemc-tBP: Burst pitch time in nanoseconds. 35 + - ingenic,nemc-tAW: Access wait time in nanoseconds. 36 + - ingenic,nemc-tSTRV: Static memory recovery time in nanoseconds. 37 + 38 + If a child node references multiple banks in its "reg" property, the same value 39 + for all optional parameters will be configured for all banks. If any optional 40 + parameters are omitted, they will be left unchanged from whatever they are 41 + configured to when the NEMC device is probed (which may be the reset value as 42 + given in the hardware reference manual, or a value configured by the boot 43 + loader). 44 + 45 + Example (NEMC node with a NAND child device attached at CS1): 46 + 47 + nemc: nemc@13410000 { 48 + compatible = "ingenic,jz4780-nemc"; 49 + reg = <0x13410000 0x10000>; 50 + 51 + #address-cells = <2>; 52 + #size-cells = <1>; 53 + 54 + ranges = <1 0 0x1b000000 0x1000000 55 + 2 0 0x1a000000 0x1000000 56 + 3 0 0x19000000 0x1000000 57 + 4 0 0x18000000 0x1000000 58 + 5 0 0x17000000 0x1000000 59 + 6 0 0x16000000 0x1000000>; 60 + 61 + clocks = <&cgu JZ4780_CLK_NEMC>; 62 + 63 + nand: nand@1 { 64 + compatible = "ingenic,jz4780-nand"; 65 + reg = <1 0 0x1000000>; 66 + 67 + ingenic,nemc-tAS = <10>; 68 + ingenic,nemc-tAH = <5>; 69 + ingenic,nemc-tBP = <10>; 70 + ingenic,nemc-tAW = <15>; 71 + ingenic,nemc-tSTRV = <100>; 72 + 73 + ... 74 + }; 75 + };
+8 -1
Documentation/devicetree/bindings/misc/lis302.txt
··· 46 46 interrupt 2 47 47 - st,wakeup-{x,y,z}-{lo,hi}: set wakeup condition on x/y/z axis for 48 48 upper/lower limit 49 + - st,wakeup-threshold: set wakeup threshold 50 + - st,wakeup2-{x,y,z}-{lo,hi}: set wakeup condition on x/y/z axis for 51 + upper/lower limit for second wakeup 52 + engine. 53 + - st,wakeup2-threshold: set wakeup threshold for second wakeup 54 + engine. 49 55 - st,highpass-cutoff-hz=: 1, 2, 4 or 8 for 1Hz, 2Hz, 4Hz or 8Hz of 50 56 highpass cut-off frequency 51 57 - st,hipass{1,2}-disable: disable highpass 1/2. 52 58 - st,default-rate=: set the default rate 53 - - st,axis-{x,y,z}=: set the axis to map to the three coordinates 59 + - st,axis-{x,y,z}=: set the axis to map to the three coordinates. 60 + Negative values can be used for inverted axis. 54 61 - st,{min,max}-limit-{x,y,z} set the min/max limits for x/y/z axis 55 62 (used by self-test) 56 63
+5 -1
Documentation/devicetree/bindings/spmi/qcom,spmi-pmic-arb.txt
··· 1 1 Qualcomm SPMI Controller (PMIC Arbiter) 2 2 3 - The SPMI PMIC Arbiter is found on the Snapdragon 800 Series. It is an SPMI 3 + The SPMI PMIC Arbiter is found on Snapdragon chipsets. It is an SPMI 4 4 controller with wrapping arbitration logic to allow for multiple on-chip 5 5 devices to control a single SPMI master. 6 6 ··· 19 19 "core" - core registers 20 20 "intr" - interrupt controller registers 21 21 "cnfg" - configuration registers 22 + Registers used only for V2 PMIC Arbiter: 23 + "chnls" - tx-channel per virtual slave registers. 24 + "obsrvr" - rx-channel (called observer) per virtual slave registers. 25 + 22 26 - reg : address + size pairs describing the PMIC arb register sets; order must 23 27 correspond with the order of entries in reg-names 24 28 - #address-cells : must be set to 2
+1
Documentation/driver-model/devres.txt
··· 276 276 devm_ioport_unmap() 277 277 devm_ioremap() 278 278 devm_ioremap_nocache() 279 + devm_ioremap_wc() 279 280 devm_ioremap_resource() : checks resource, requests memory region, ioremaps 280 281 devm_iounmap() 281 282 pcim_iomap()
+1 -1
Documentation/trace/coresight.txt
··· 14 14 HW assisted tracing is becoming increasingly useful when dealing with systems 15 15 that have many SoCs and other components like GPU and DMA engines. ARM has 16 16 developed a HW assisted tracing solution by means of different components, each 17 - being added to a design at systhesis time to cater to specific tracing needs. 17 + being added to a design at synthesis time to cater to specific tracing needs. 18 18 Compoments are generally categorised as source, link and sinks and are 19 19 (usually) discovered using the AMBA bus. 20 20
+2 -2
MAINTAINERS
··· 958 958 M: Mathieu Poirier <mathieu.poirier@linaro.org> 959 959 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 960 960 S: Maintained 961 - F: drivers/coresight/* 961 + F: drivers/hwtracing/coresight/* 962 962 F: Documentation/trace/coresight.txt 963 963 F: Documentation/devicetree/bindings/arm/coresight.txt 964 964 F: Documentation/ABI/testing/sysfs-bus-coresight-devices-* ··· 1828 1828 F: drivers/spi/spi-atmel.* 1829 1829 1830 1830 ATMEL SSC DRIVER 1831 - M: Bo Shen <voice.shen@atmel.com> 1831 + M: Nicolas Ferre <nicolas.ferre@atmel.com> 1832 1832 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1833 1833 S: Supported 1834 1834 F: drivers/misc/atmel-ssc.c
+1 -54
arch/arm/Kconfig.debug
··· 1610 1610 against certain classes of kernel exploits. 1611 1611 If in doubt, say "N". 1612 1612 1613 - menuconfig CORESIGHT 1614 - bool "CoreSight Tracing Support" 1615 - select ARM_AMBA 1616 - help 1617 - This framework provides a kernel interface for the CoreSight debug 1618 - and trace drivers to register themselves with. It's intended to build 1619 - a topological view of the CoreSight components based on a DT 1620 - specification and configure the right serie of components when a 1621 - trace source gets enabled. 1613 + source "drivers/hwtracing/coresight/Kconfig" 1622 1614 1623 - if CORESIGHT 1624 - config CORESIGHT_LINKS_AND_SINKS 1625 - bool "CoreSight Link and Sink drivers" 1626 - help 1627 - This enables support for CoreSight link and sink drivers that are 1628 - responsible for transporting and collecting the trace data 1629 - respectively. Link and sinks are dynamically aggregated with a trace 1630 - entity at run time to form a complete trace path. 1631 - 1632 - config CORESIGHT_LINK_AND_SINK_TMC 1633 - bool "Coresight generic TMC driver" 1634 - depends on CORESIGHT_LINKS_AND_SINKS 1635 - help 1636 - This enables support for the Trace Memory Controller driver. Depending 1637 - on its configuration the device can act as a link (embedded trace router 1638 - - ETR) or sink (embedded trace FIFO). The driver complies with the 1639 - generic implementation of the component without special enhancement or 1640 - added features. 1641 - 1642 - config CORESIGHT_SINK_TPIU 1643 - bool "Coresight generic TPIU driver" 1644 - depends on CORESIGHT_LINKS_AND_SINKS 1645 - help 1646 - This enables support for the Trace Port Interface Unit driver, responsible 1647 - for bridging the gap between the on-chip coresight components and a trace 1648 - port collection engine, typically connected to an external host for use 1649 - case capturing more traces than the on-board coresight memory can handle. 1650 - 1651 - config CORESIGHT_SINK_ETBV10 1652 - bool "Coresight ETBv1.0 driver" 1653 - depends on CORESIGHT_LINKS_AND_SINKS 1654 - help 1655 - This enables support for the Embedded Trace Buffer version 1.0 driver 1656 - that complies with the generic implementation of the component without 1657 - special enhancement or added features. 1658 - 1659 - config CORESIGHT_SOURCE_ETM3X 1660 - bool "CoreSight Embedded Trace Macrocell 3.x driver" 1661 - select CORESIGHT_LINKS_AND_SINKS 1662 - help 1663 - This driver provides support for processor ETM3.x and PTM1.x modules, 1664 - which allows tracing the instructions that a processor is executing 1665 - This is primarily useful for instruction level tracing. Depending 1666 - the ETM version data tracing may also be available. 1667 - endif 1668 1615 endmenu
-1
arch/arm/boot/dts/hip04.dtsi
··· 275 275 compatible = "arm,coresight-etb10", "arm,primecell"; 276 276 reg = <0 0xe3c42000 0 0x1000>; 277 277 278 - coresight-default-sink; 279 278 clocks = <&clk_375m>; 280 279 clock-names = "apb_pclk"; 281 280 port {
-1
arch/arm/boot/dts/omap3-beagle-xm.dts
··· 150 150 compatible = "arm,coresight-etb10", "arm,primecell"; 151 151 reg = <0x5401b000 0x1000>; 152 152 153 - coresight-default-sink; 154 153 clocks = <&emu_src_ck>; 155 154 clock-names = "apb_pclk"; 156 155 port {
-1
arch/arm/boot/dts/omap3-beagle.dts
··· 145 145 compatible = "arm,coresight-etb10", "arm,primecell"; 146 146 reg = <0x5401b000 0x1000>; 147 147 148 - coresight-default-sink; 149 148 clocks = <&emu_src_ck>; 150 149 clock-names = "apb_pclk"; 151 150 port {
+52
arch/arm/boot/dts/omap3-n900.dts
··· 609 609 pinctrl-0 = <&i2c3_pins>; 610 610 611 611 clock-frequency = <400000>; 612 + 613 + lis302dl: lis3lv02d@1d { 614 + compatible = "st,lis3lv02d"; 615 + reg = <0x1d>; 616 + 617 + Vdd-supply = <&vaux1>; 618 + Vdd_IO-supply = <&vio>; 619 + 620 + interrupt-parent = <&gpio6>; 621 + interrupts = <21 20>; /* 181 and 180 */ 622 + 623 + /* click flags */ 624 + st,click-single-x; 625 + st,click-single-y; 626 + st,click-single-z; 627 + 628 + /* Limits are 0.5g * value */ 629 + st,click-threshold-x = <8>; 630 + st,click-threshold-y = <8>; 631 + st,click-threshold-z = <10>; 632 + 633 + /* Click must be longer than time limit */ 634 + st,click-time-limit = <9>; 635 + 636 + /* Kind of debounce filter */ 637 + st,click-latency = <50>; 638 + 639 + /* Interrupt line 2 for click detection */ 640 + st,irq2-click; 641 + 642 + st,wakeup-x-hi; 643 + st,wakeup-y-hi; 644 + st,wakeup-threshold = <(800/18)>; /* millig-value / 18 to get HW values */ 645 + 646 + st,wakeup2-z-hi; 647 + st,wakeup2-threshold = <(900/18)>; /* millig-value / 18 to get HW values */ 648 + 649 + st,hipass1-disable; 650 + st,hipass2-disable; 651 + 652 + st,axis-x = <1>; /* LIS3_DEV_X */ 653 + st,axis-y = <(-2)>; /* LIS3_INV_DEV_Y */ 654 + st,axis-z = <(-3)>; /* LIS3_INV_DEV_Z */ 655 + 656 + st,min-limit-x = <(-32)>; 657 + st,min-limit-y = <3>; 658 + st,min-limit-z = <3>; 659 + 660 + st,max-limit-x = <(-3)>; 661 + st,max-limit-y = <32>; 662 + st,max-limit-z = <32>; 663 + }; 612 664 }; 613 665 614 666 &mmc1 {
-1
arch/arm/boot/dts/vexpress-v2p-ca15_a7.dts
··· 362 362 compatible = "arm,coresight-etb10", "arm,primecell"; 363 363 reg = <0 0x20010000 0 0x1000>; 364 364 365 - coresight-default-sink; 366 365 clocks = <&oscclk6a>; 367 366 clock-names = "apb_pclk"; 368 367 port {
+2
arch/arm64/Kconfig.debug
··· 89 89 90 90 If in doubt, say N 91 91 92 + source "drivers/hwtracing/coresight/Kconfig" 93 + 92 94 endmenu
+1
arch/m32r/include/asm/io.h
··· 67 67 68 68 extern void iounmap(volatile void __iomem *addr); 69 69 #define ioremap_nocache(off,size) ioremap(off,size) 70 + #define ioremap_wc ioremap_nocache 70 71 71 72 /* 72 73 * IO bus memory addresses are also 1:1 with the physical address
+2
arch/x86/include/uapi/asm/hyperv.h
··· 225 225 #define HV_STATUS_INVALID_HYPERCALL_CODE 2 226 226 #define HV_STATUS_INVALID_HYPERCALL_INPUT 3 227 227 #define HV_STATUS_INVALID_ALIGNMENT 4 228 + #define HV_STATUS_INSUFFICIENT_MEMORY 11 229 + #define HV_STATUS_INVALID_CONNECTION_ID 18 228 230 #define HV_STATUS_INSUFFICIENT_BUFFERS 19 229 231 230 232 typedef struct _HV_REFERENCE_TSC_PAGE {
+1 -1
drivers/Makefile
··· 163 163 obj-$(CONFIG_MCB) += mcb/ 164 164 obj-$(CONFIG_RAS) += ras/ 165 165 obj-$(CONFIG_THUNDERBOLT) += thunderbolt/ 166 - obj-$(CONFIG_CORESIGHT) += coresight/ 166 + obj-$(CONFIG_CORESIGHT) += hwtracing/coresight/ 167 167 obj-$(CONFIG_ANDROID) += android/
+11 -23
drivers/char/hw_random/core.c
··· 300 300 .llseek = noop_llseek, 301 301 }; 302 302 303 + static const struct attribute_group *rng_dev_groups[]; 304 + 303 305 static struct miscdevice rng_miscdev = { 304 306 .minor = RNG_MISCDEV_MINOR, 305 307 .name = RNG_MODULE_NAME, 306 308 .nodename = "hwrng", 307 309 .fops = &rng_chrdev_ops, 310 + .groups = rng_dev_groups, 308 311 }; 309 312 310 313 ··· 380 377 hwrng_attr_available_show, 381 378 NULL); 382 379 380 + static struct attribute *rng_dev_attrs[] = { 381 + &dev_attr_rng_current.attr, 382 + &dev_attr_rng_available.attr, 383 + NULL 384 + }; 385 + 386 + ATTRIBUTE_GROUPS(rng_dev); 383 387 384 388 static void __exit unregister_miscdev(void) 385 389 { 386 - device_remove_file(rng_miscdev.this_device, &dev_attr_rng_available); 387 - device_remove_file(rng_miscdev.this_device, &dev_attr_rng_current); 388 390 misc_deregister(&rng_miscdev); 389 391 } 390 392 391 393 static int __init register_miscdev(void) 392 394 { 393 - int err; 394 - 395 - err = misc_register(&rng_miscdev); 396 - if (err) 397 - goto out; 398 - err = device_create_file(rng_miscdev.this_device, 399 - &dev_attr_rng_current); 400 - if (err) 401 - goto err_misc_dereg; 402 - err = device_create_file(rng_miscdev.this_device, 403 - &dev_attr_rng_available); 404 - if (err) 405 - goto err_remove_current; 406 - out: 407 - return err; 408 - 409 - err_remove_current: 410 - device_remove_file(rng_miscdev.this_device, &dev_attr_rng_current); 411 - err_misc_dereg: 412 - misc_deregister(&rng_miscdev); 413 - goto out; 395 + return misc_register(&rng_miscdev); 414 396 } 415 397 416 398 static int hwrng_fillfn(void *unused)
+1 -1
drivers/char/hw_random/pasemi-rng.c
··· 133 133 return 0; 134 134 } 135 135 136 - static struct of_device_id rng_match[] = { 136 + static const struct of_device_id rng_match[] = { 137 137 { .compatible = "1682m-rng", }, 138 138 { .compatible = "pasemi,pwrficient-rng", }, 139 139 { },
+1 -1
drivers/char/hw_random/powernv-rng.c
··· 61 61 return 0; 62 62 } 63 63 64 - static struct of_device_id powernv_rng_match[] = { 64 + static const struct of_device_id powernv_rng_match[] = { 65 65 { .compatible = "ibm,power-rng",}, 66 66 {}, 67 67 };
+1 -1
drivers/char/hw_random/ppc4xx-rng.c
··· 123 123 return 0; 124 124 } 125 125 126 - static struct of_device_id ppc4xx_rng_match[] = { 126 + static const struct of_device_id ppc4xx_rng_match[] = { 127 127 { .compatible = "ppc4xx-rng", }, 128 128 { .compatible = "amcc,ppc460ex-rng", }, 129 129 { .compatible = "amcc,ppc440epx-rng", },
+9 -7
drivers/char/i8k.c
··· 510 510 * 9) AC power 511 511 * 10) Fn Key status 512 512 */ 513 - return seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n", 514 - I8K_PROC_FMT, 515 - bios_version, 516 - i8k_get_dmi_data(DMI_PRODUCT_SERIAL), 517 - cpu_temp, 518 - left_fan, right_fan, left_speed, right_speed, 519 - ac_power, fn_key); 513 + seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n", 514 + I8K_PROC_FMT, 515 + bios_version, 516 + i8k_get_dmi_data(DMI_PRODUCT_SERIAL), 517 + cpu_temp, 518 + left_fan, right_fan, left_speed, right_speed, 519 + ac_power, fn_key); 520 + 521 + return 0; 520 522 } 521 523 522 524 static int i8k_open_fs(struct inode *inode, struct file *file)
+2 -2
drivers/char/ipmi/ipmi_si_intf.c
··· 2667 2667 }; 2668 2668 #endif /* CONFIG_PCI */ 2669 2669 2670 - static struct of_device_id ipmi_match[]; 2670 + static const struct of_device_id ipmi_match[]; 2671 2671 static int ipmi_probe(struct platform_device *dev) 2672 2672 { 2673 2673 #ifdef CONFIG_OF ··· 2764 2764 return 0; 2765 2765 } 2766 2766 2767 - static struct of_device_id ipmi_match[] = 2767 + static const struct of_device_id ipmi_match[] = 2768 2768 { 2769 2769 { .type = "ipmi", .compatible = "ipmi-kcs", 2770 2770 .data = (void *)(unsigned long) SI_KCS },
+14 -6
drivers/char/misc.c
··· 140 140 goto fail; 141 141 } 142 142 143 + /* 144 + * Place the miscdevice in the file's 145 + * private_data so it can be used by the 146 + * file operations, including f_op->open below 147 + */ 148 + file->private_data = c; 149 + 143 150 err = 0; 144 151 replace_fops(file, new_fops); 145 - if (file->f_op->open) { 146 - file->private_data = c; 152 + if (file->f_op->open) 147 153 err = file->f_op->open(inode,file); 148 - } 149 154 fail: 150 155 mutex_unlock(&misc_mtx); 151 156 return err; ··· 174 169 * the minor number requested is used. 175 170 * 176 171 * The structure passed is linked into the kernel and may not be 177 - * destroyed until it has been unregistered. 172 + * destroyed until it has been unregistered. By default, an open() 173 + * syscall to the device sets file->private_data to point to the 174 + * structure. Drivers don't need open in fops for this. 178 175 * 179 176 * A zero is returned on success and a negative errno code for 180 177 * failure. ··· 212 205 213 206 dev = MKDEV(MISC_MAJOR, misc->minor); 214 207 215 - misc->this_device = device_create(misc_class, misc->parent, dev, 216 - misc, "%s", misc->name); 208 + misc->this_device = 209 + device_create_with_groups(misc_class, misc->parent, dev, 210 + misc, misc->groups, "%s", misc->name); 217 211 if (IS_ERR(misc->this_device)) { 218 212 int i = DYNAMIC_MINORS - misc->minor - 1; 219 213 if (i < DYNAMIC_MINORS && i >= 0)
+1 -1
drivers/char/virtio_console.c
··· 355 355 * early_init 356 356 */ 357 357 if (!portdev->vdev) 358 - return 0; 358 + return false; 359 359 return __virtio_test_bit(portdev->vdev, VIRTIO_CONSOLE_F_MULTIPORT); 360 360 } 361 361
+2
drivers/char/xillybus/xillybus_core.c
··· 1237 1237 unsigned char *tail; 1238 1238 int i; 1239 1239 1240 + howmany = 0; 1241 + 1240 1242 end_offset_plus1 = bufpos >> 1241 1243 channel->log2_element_size; 1242 1244
+1 -1
drivers/char/xillybus/xillybus_of.c
··· 31 31 static const char xillyname[] = "xillybus_of"; 32 32 33 33 /* Match table for of_platform binding */ 34 - static struct of_device_id xillybus_of_match[] = { 34 + static const struct of_device_id xillybus_of_match[] = { 35 35 { .compatible = "xillybus,xillybus-1.00.a", }, 36 36 { .compatible = "xlnx,xillybus-1.00.a", }, /* Deprecated */ 37 37 {}
drivers/coresight/Makefile drivers/hwtracing/coresight/Makefile
+2 -2
drivers/coresight/coresight-etb10.c drivers/hwtracing/coresight/coresight-etb10.c
··· 313 313 314 314 *ppos += len; 315 315 316 - dev_dbg(drvdata->dev, "%s: %d bytes copied, %d bytes left\n", 317 - __func__, len, (int) (depth * 4 - *ppos)); 316 + dev_dbg(drvdata->dev, "%s: %zu bytes copied, %d bytes left\n", 317 + __func__, len, (int)(depth * 4 - *ppos)); 318 318 return len; 319 319 } 320 320
drivers/coresight/coresight-etm-cp14.c drivers/hwtracing/coresight/coresight-etm-cp14.c
drivers/coresight/coresight-etm.h drivers/hwtracing/coresight/coresight-etm.h
drivers/coresight/coresight-etm3x.c drivers/hwtracing/coresight/coresight-etm3x.c
drivers/coresight/coresight-funnel.c drivers/hwtracing/coresight/coresight-funnel.c
drivers/coresight/coresight-priv.h drivers/hwtracing/coresight/coresight-priv.h
+1 -1
drivers/coresight/coresight-replicator.c drivers/hwtracing/coresight/coresight-replicator.c
··· 107 107 return 0; 108 108 } 109 109 110 - static struct of_device_id replicator_match[] = { 110 + static const struct of_device_id replicator_match[] = { 111 111 {.compatible = "arm,coresight-replicator"}, 112 112 {} 113 113 };
+58 -2
drivers/coresight/coresight-tmc.c drivers/hwtracing/coresight/coresight-tmc.c
··· 533 533 534 534 *ppos += len; 535 535 536 - dev_dbg(drvdata->dev, "%s: %d bytes copied, %d bytes left\n", 537 - __func__, len, (int) (drvdata->size - *ppos)); 536 + dev_dbg(drvdata->dev, "%s: %zu bytes copied, %d bytes left\n", 537 + __func__, len, (int)(drvdata->size - *ppos)); 538 538 return len; 539 539 } 540 540 ··· 565 565 .llseek = no_llseek, 566 566 }; 567 567 568 + static ssize_t status_show(struct device *dev, 569 + struct device_attribute *attr, char *buf) 570 + { 571 + int ret; 572 + unsigned long flags; 573 + u32 tmc_rsz, tmc_sts, tmc_rrp, tmc_rwp, tmc_trg; 574 + u32 tmc_ctl, tmc_ffsr, tmc_ffcr, tmc_mode, tmc_pscr; 575 + u32 devid; 576 + struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent); 577 + 578 + ret = clk_prepare_enable(drvdata->clk); 579 + if (ret) 580 + goto out; 581 + 582 + spin_lock_irqsave(&drvdata->spinlock, flags); 583 + CS_UNLOCK(drvdata->base); 584 + 585 + tmc_rsz = readl_relaxed(drvdata->base + TMC_RSZ); 586 + tmc_sts = readl_relaxed(drvdata->base + TMC_STS); 587 + tmc_rrp = readl_relaxed(drvdata->base + TMC_RRP); 588 + tmc_rwp = readl_relaxed(drvdata->base + TMC_RWP); 589 + tmc_trg = readl_relaxed(drvdata->base + TMC_TRG); 590 + tmc_ctl = readl_relaxed(drvdata->base + TMC_CTL); 591 + tmc_ffsr = readl_relaxed(drvdata->base + TMC_FFSR); 592 + tmc_ffcr = readl_relaxed(drvdata->base + TMC_FFCR); 593 + tmc_mode = readl_relaxed(drvdata->base + TMC_MODE); 594 + tmc_pscr = readl_relaxed(drvdata->base + TMC_PSCR); 595 + devid = readl_relaxed(drvdata->base + CORESIGHT_DEVID); 596 + 597 + CS_LOCK(drvdata->base); 598 + spin_unlock_irqrestore(&drvdata->spinlock, flags); 599 + 600 + clk_disable_unprepare(drvdata->clk); 601 + 602 + return sprintf(buf, 603 + "Depth:\t\t0x%x\n" 604 + "Status:\t\t0x%x\n" 605 + "RAM read ptr:\t0x%x\n" 606 + "RAM wrt ptr:\t0x%x\n" 607 + "Trigger cnt:\t0x%x\n" 608 + "Control:\t0x%x\n" 609 + "Flush status:\t0x%x\n" 610 + "Flush ctrl:\t0x%x\n" 611 + "Mode:\t\t0x%x\n" 612 + "PSRC:\t\t0x%x\n" 613 + "DEVID:\t\t0x%x\n", 614 + tmc_rsz, tmc_sts, tmc_rrp, tmc_rwp, tmc_trg, 615 + tmc_ctl, tmc_ffsr, tmc_ffcr, tmc_mode, tmc_pscr, devid); 616 + out: 617 + return -EINVAL; 618 + } 619 + static DEVICE_ATTR_RO(status); 620 + 568 621 static ssize_t trigger_cntr_show(struct device *dev, 569 622 struct device_attribute *attr, char *buf) 570 623 { ··· 646 593 647 594 static struct attribute *coresight_etb_attrs[] = { 648 595 &dev_attr_trigger_cntr.attr, 596 + &dev_attr_status.attr, 649 597 NULL, 650 598 }; 651 599 ATTRIBUTE_GROUPS(coresight_etb); 652 600 653 601 static struct attribute *coresight_etr_attrs[] = { 654 602 &dev_attr_trigger_cntr.attr, 603 + &dev_attr_status.attr, 655 604 NULL, 656 605 }; 657 606 ATTRIBUTE_GROUPS(coresight_etr); 658 607 659 608 static struct attribute *coresight_etf_attrs[] = { 660 609 &dev_attr_trigger_cntr.attr, 610 + &dev_attr_status.attr, 661 611 NULL, 662 612 }; 663 613 ATTRIBUTE_GROUPS(coresight_etf);
drivers/coresight/coresight-tpiu.c drivers/hwtracing/coresight/coresight-tpiu.c
+3 -1
drivers/coresight/coresight.c drivers/hwtracing/coresight/coresight.c
··· 305 305 306 306 list_add(&csdev->path_link, path); 307 307 308 - if (csdev->type == CORESIGHT_DEV_TYPE_SINK && csdev->activated) { 308 + if ((csdev->type == CORESIGHT_DEV_TYPE_SINK || 309 + csdev->type == CORESIGHT_DEV_TYPE_LINKSINK) && 310 + csdev->activated) { 309 311 if (enable) 310 312 ret = coresight_enable_path(path); 311 313 else
+6 -12
drivers/coresight/of_coresight.c drivers/hwtracing/coresight/of_coresight.c
··· 22 22 #include <linux/platform_device.h> 23 23 #include <linux/amba/bus.h> 24 24 #include <linux/coresight.h> 25 + #include <linux/cpumask.h> 25 26 #include <asm/smp_plat.h> 26 27 27 28 ··· 105 104 struct coresight_platform_data *of_get_coresight_platform_data( 106 105 struct device *dev, struct device_node *node) 107 106 { 108 - int i = 0, ret = 0; 107 + int i = 0, ret = 0, cpu; 109 108 struct coresight_platform_data *pdata; 110 109 struct of_endpoint endpoint, rendpoint; 111 110 struct device *rdev; ··· 179 178 /* Affinity defaults to CPU0 */ 180 179 pdata->cpu = 0; 181 180 dn = of_parse_phandle(node, "cpu", 0); 182 - if (dn) { 183 - const u32 *cell; 184 - int len, index; 185 - u64 hwid; 186 - 187 - cell = of_get_property(dn, "reg", &len); 188 - if (cell) { 189 - hwid = of_read_number(cell, of_n_addr_cells(dn)); 190 - index = get_logical_index(hwid); 191 - if (index != -EINVAL) 192 - pdata->cpu = index; 181 + for (cpu = 0; dn && cpu < nr_cpu_ids; cpu++) { 182 + if (dn == of_get_cpu_node(cpu, NULL)) { 183 + pdata->cpu = cpu; 184 + break; 193 185 } 194 186 } 195 187
+17
drivers/extcon/Kconfig
··· 55 55 Maxim MAX77693 PMIC. The MAX77693 MUIC is a USB port accessory 56 56 detector and switch. 57 57 58 + config EXTCON_MAX77843 59 + tristate "MAX77843 EXTCON Support" 60 + depends on MFD_MAX77843 61 + select IRQ_DOMAIN 62 + select REGMAP_I2C 63 + help 64 + If you say yes here you get support for the MUIC device of 65 + Maxim MAX77843. The MAX77843 MUIC is a USB port accessory 66 + detector add switch. 67 + 58 68 config EXTCON_MAX8997 59 69 tristate "MAX8997 EXTCON Support" 60 70 depends on MFD_MAX8997 && IRQ_DOMAIN ··· 102 92 If you say yes here you get support for the MUIC device of 103 93 Silicon Mitus SM5502. The SM5502 is a USB port accessory 104 94 detector and switch. 95 + 96 + config EXTCON_USB_GPIO 97 + tristate "USB GPIO extcon support" 98 + depends on GPIOLIB 99 + help 100 + Say Y here to enable GPIO based USB cable detection extcon support. 101 + Used typically if GPIO is used for USB ID pin detection. 105 102 106 103 endif # MULTISTATE_SWITCH
+3 -1
drivers/extcon/Makefile
··· 2 2 # Makefile for external connector class (extcon) devices 3 3 # 4 4 5 - obj-$(CONFIG_EXTCON) += extcon-class.o 5 + obj-$(CONFIG_EXTCON) += extcon.o 6 6 obj-$(CONFIG_EXTCON_ADC_JACK) += extcon-adc-jack.o 7 7 obj-$(CONFIG_EXTCON_ARIZONA) += extcon-arizona.o 8 8 obj-$(CONFIG_EXTCON_GPIO) += extcon-gpio.o 9 9 obj-$(CONFIG_EXTCON_MAX14577) += extcon-max14577.o 10 10 obj-$(CONFIG_EXTCON_MAX77693) += extcon-max77693.o 11 + obj-$(CONFIG_EXTCON_MAX77843) += extcon-max77843.o 11 12 obj-$(CONFIG_EXTCON_MAX8997) += extcon-max8997.o 12 13 obj-$(CONFIG_EXTCON_PALMAS) += extcon-palmas.o 13 14 obj-$(CONFIG_EXTCON_RT8973A) += extcon-rt8973a.o 14 15 obj-$(CONFIG_EXTCON_SM5502) += extcon-sm5502.o 16 + obj-$(CONFIG_EXTCON_USB_GPIO) += extcon-usb-gpio.o
+33 -16
drivers/extcon/extcon-arizona.c
··· 136 136 137 137 static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info); 138 138 139 - static void arizona_extcon_do_magic(struct arizona_extcon_info *info, 140 - unsigned int magic) 139 + static void arizona_extcon_hp_clamp(struct arizona_extcon_info *info, 140 + bool clamp) 141 141 { 142 142 struct arizona *arizona = info->arizona; 143 + unsigned int mask = 0, val = 0; 143 144 int ret; 145 + 146 + switch (arizona->type) { 147 + case WM5110: 148 + mask = ARIZONA_HP1L_SHRTO | ARIZONA_HP1L_FLWR | 149 + ARIZONA_HP1L_SHRTI; 150 + if (clamp) 151 + val = ARIZONA_HP1L_SHRTO; 152 + else 153 + val = ARIZONA_HP1L_FLWR | ARIZONA_HP1L_SHRTI; 154 + break; 155 + default: 156 + mask = ARIZONA_RMV_SHRT_HP1L; 157 + if (clamp) 158 + val = ARIZONA_RMV_SHRT_HP1L; 159 + break; 160 + }; 144 161 145 162 mutex_lock(&arizona->dapm->card->dapm_mutex); 146 163 147 - arizona->hpdet_magic = magic; 164 + arizona->hpdet_clamp = clamp; 148 165 149 - /* Keep the HP output stages disabled while doing the magic */ 150 - if (magic) { 166 + /* Keep the HP output stages disabled while doing the clamp */ 167 + if (clamp) { 151 168 ret = regmap_update_bits(arizona->regmap, 152 169 ARIZONA_OUTPUT_ENABLES_1, 153 170 ARIZONA_OUT1L_ENA | ··· 175 158 ret); 176 159 } 177 160 178 - ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, 179 - magic); 161 + ret = regmap_update_bits(arizona->regmap, ARIZONA_HP_CTRL_1L, 162 + mask, val); 180 163 if (ret != 0) 181 - dev_warn(arizona->dev, "Failed to do magic: %d\n", 164 + dev_warn(arizona->dev, "Failed to do clamp: %d\n", 182 165 ret); 183 166 184 - ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, 185 - magic); 167 + ret = regmap_update_bits(arizona->regmap, ARIZONA_HP_CTRL_1R, 168 + mask, val); 186 169 if (ret != 0) 187 - dev_warn(arizona->dev, "Failed to do magic: %d\n", 170 + dev_warn(arizona->dev, "Failed to do clamp: %d\n", 188 171 ret); 189 172 190 - /* Restore the desired state while not doing the magic */ 191 - if (!magic) { 173 + /* Restore the desired state while not doing the clamp */ 174 + if (!clamp) { 192 175 ret = regmap_update_bits(arizona->regmap, 193 176 ARIZONA_OUTPUT_ENABLES_1, 194 177 ARIZONA_OUT1L_ENA | ··· 620 603 ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL, 621 604 0); 622 605 623 - arizona_extcon_do_magic(info, 0); 606 + arizona_extcon_hp_clamp(info, false); 624 607 625 608 if (id_gpio) 626 609 gpio_set_value_cansleep(id_gpio, 0); ··· 665 648 if (info->mic) 666 649 arizona_stop_mic(info); 667 650 668 - arizona_extcon_do_magic(info, 0x4000); 651 + arizona_extcon_hp_clamp(info, true); 669 652 670 653 ret = regmap_update_bits(arizona->regmap, 671 654 ARIZONA_ACCESSORY_DETECT_MODE_1, ··· 716 699 717 700 info->hpdet_active = true; 718 701 719 - arizona_extcon_do_magic(info, 0x4000); 702 + arizona_extcon_hp_clamp(info, true); 720 703 721 704 ret = regmap_update_bits(arizona->regmap, 722 705 ARIZONA_ACCESSORY_DETECT_MODE_1,
+32 -4
drivers/extcon/extcon-class.c drivers/extcon/extcon.c
··· 158 158 /* Optional callback given by the user */ 159 159 if (edev->print_name) { 160 160 int ret = edev->print_name(edev, buf); 161 + 161 162 if (ret >= 0) 162 163 return ret; 163 164 } ··· 445 444 const char *extcon_name, const char *cable_name, 446 445 struct notifier_block *nb) 447 446 { 447 + unsigned long flags; 448 + int ret; 449 + 448 450 if (!obj || !cable_name || !nb) 449 451 return -EINVAL; 450 452 ··· 465 461 466 462 obj->internal_nb.notifier_call = _call_per_cable; 467 463 468 - return raw_notifier_chain_register(&obj->edev->nh, 464 + spin_lock_irqsave(&obj->edev->lock, flags); 465 + ret = raw_notifier_chain_register(&obj->edev->nh, 469 466 &obj->internal_nb); 467 + spin_unlock_irqrestore(&obj->edev->lock, flags); 468 + return ret; 470 469 } else { 471 470 struct class_dev_iter iter; 472 471 struct extcon_dev *extd; ··· 502 495 */ 503 496 int extcon_unregister_interest(struct extcon_specific_cable_nb *obj) 504 497 { 498 + unsigned long flags; 499 + int ret; 500 + 505 501 if (!obj) 506 502 return -EINVAL; 507 503 508 - return raw_notifier_chain_unregister(&obj->edev->nh, &obj->internal_nb); 504 + spin_lock_irqsave(&obj->edev->lock, flags); 505 + ret = raw_notifier_chain_unregister(&obj->edev->nh, &obj->internal_nb); 506 + spin_unlock_irqrestore(&obj->edev->lock, flags); 507 + 508 + return ret; 509 509 } 510 510 EXPORT_SYMBOL_GPL(extcon_unregister_interest); 511 511 ··· 529 515 int extcon_register_notifier(struct extcon_dev *edev, 530 516 struct notifier_block *nb) 531 517 { 532 - return raw_notifier_chain_register(&edev->nh, nb); 518 + unsigned long flags; 519 + int ret; 520 + 521 + spin_lock_irqsave(&edev->lock, flags); 522 + ret = raw_notifier_chain_register(&edev->nh, nb); 523 + spin_unlock_irqrestore(&edev->lock, flags); 524 + 525 + return ret; 533 526 } 534 527 EXPORT_SYMBOL_GPL(extcon_register_notifier); 535 528 ··· 548 527 int extcon_unregister_notifier(struct extcon_dev *edev, 549 528 struct notifier_block *nb) 550 529 { 551 - return raw_notifier_chain_unregister(&edev->nh, nb); 530 + unsigned long flags; 531 + int ret; 532 + 533 + spin_lock_irqsave(&edev->lock, flags); 534 + ret = raw_notifier_chain_unregister(&edev->nh, nb); 535 + spin_unlock_irqrestore(&edev->lock, flags); 536 + 537 + return ret; 552 538 } 553 539 EXPORT_SYMBOL_GPL(extcon_unregister_notifier); 554 540
+1 -4
drivers/extcon/extcon-max14577.c
··· 539 539 dev_err(info->dev, "failed to handle MUIC interrupt\n"); 540 540 541 541 mutex_unlock(&info->mutex); 542 - 543 - return; 544 542 } 545 543 546 544 /* ··· 728 730 muic_irq->name, info); 729 731 if (ret) { 730 732 dev_err(&pdev->dev, 731 - "failed: irq request (IRQ: %d," 732 - " error :%d)\n", 733 + "failed: irq request (IRQ: %d, error :%d)\n", 733 734 muic_irq->irq, ret); 734 735 return ret; 735 736 }
+17 -20
drivers/extcon/extcon-max77693.c
··· 190 190 /* The below accessories have same ADC value so ADCLow and 191 191 ADC1K bit is used to separate specific accessory */ 192 192 /* ADC|VBVolot|ADCLow|ADC1K| */ 193 - MAX77693_MUIC_GND_USB_OTG = 0x100, /* 0x0| 0| 0| 0| */ 194 - MAX77693_MUIC_GND_USB_OTG_VB = 0x104, /* 0x0| 1| 0| 0| */ 193 + MAX77693_MUIC_GND_USB_HOST = 0x100, /* 0x0| 0| 0| 0| */ 194 + MAX77693_MUIC_GND_USB_HOST_VB = 0x104, /* 0x0| 1| 0| 0| */ 195 195 MAX77693_MUIC_GND_AV_CABLE_LOAD = 0x102,/* 0x0| 0| 1| 0| */ 196 196 MAX77693_MUIC_GND_MHL = 0x103, /* 0x0| 0| 1| 1| */ 197 197 MAX77693_MUIC_GND_MHL_VB = 0x107, /* 0x0| 1| 1| 1| */ ··· 228 228 [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger", 229 229 [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream", 230 230 [EXTCON_CABLE_MHL] = "MHL", 231 - [EXTCON_CABLE_MHL_TA] = "MHL_TA", 231 + [EXTCON_CABLE_MHL_TA] = "MHL-TA", 232 232 [EXTCON_CABLE_JIG_USB_ON] = "JIG-USB-ON", 233 233 [EXTCON_CABLE_JIG_USB_OFF] = "JIG-USB-OFF", 234 234 [EXTCON_CABLE_JIG_UART_OFF] = "JIG-UART-OFF", ··· 403 403 404 404 /** 405 405 * [0x1|VBVolt|ADCLow|ADC1K] 406 - * [0x1| 0| 0| 0] USB_OTG 407 - * [0x1| 1| 0| 0] USB_OTG_VB 406 + * [0x1| 0| 0| 0] USB_HOST 407 + * [0x1| 1| 0| 0] USB_HSOT_VB 408 408 * [0x1| 0| 1| 0] Audio Video cable with load 409 409 * [0x1| 0| 1| 1] MHL without charging cable 410 410 * [0x1| 1| 1| 1] MHL with charging cable ··· 523 523 * - Support charging and data connection through micro-usb port 524 524 * if USB cable is connected between target and host 525 525 * device. 526 - * - Support OTG device (Mouse/Keyboard) 526 + * - Support OTG(On-The-Go) device (Ex: Mouse/Keyboard) 527 527 */ 528 528 ret = max77693_muic_set_path(info, info->path_usb, attached); 529 529 if (ret < 0) ··· 609 609 MAX77693_CABLE_GROUP_ADC_GND, &attached); 610 610 611 611 switch (cable_type_gnd) { 612 - case MAX77693_MUIC_GND_USB_OTG: 613 - case MAX77693_MUIC_GND_USB_OTG_VB: 614 - /* USB_OTG, PATH: AP_USB */ 612 + case MAX77693_MUIC_GND_USB_HOST: 613 + case MAX77693_MUIC_GND_USB_HOST_VB: 614 + /* USB_HOST, PATH: AP_USB */ 615 615 ret = max77693_muic_set_path(info, CONTROL1_SW_USB, attached); 616 616 if (ret < 0) 617 617 return ret; ··· 704 704 705 705 switch (cable_type) { 706 706 case MAX77693_MUIC_ADC_GROUND: 707 - /* USB_OTG/MHL/Audio */ 707 + /* USB_HOST/MHL/Audio */ 708 708 max77693_muic_adc_ground_handler(info); 709 709 break; 710 710 case MAX77693_MUIC_ADC_FACTORY_MODE_USB_OFF: ··· 823 823 case MAX77693_MUIC_GND_MHL: 824 824 case MAX77693_MUIC_GND_MHL_VB: 825 825 /* 826 - * MHL cable with MHL_TA(USB/TA) cable 826 + * MHL cable with MHL-TA(USB/TA) cable 827 827 * - MHL cable include two port(HDMI line and separate 828 828 * micro-usb port. When the target connect MHL cable, 829 - * extcon driver check whether MHL_TA(USB/TA) cable is 830 - * connected. If MHL_TA cable is connected, extcon 829 + * extcon driver check whether MHL-TA(USB/TA) cable is 830 + * connected. If MHL-TA cable is connected, extcon 831 831 * driver notify state to notifiee for charging battery. 832 832 * 833 - * Features of 'MHL_TA(USB/TA) with MHL cable' 833 + * Features of 'MHL-TA(USB/TA) with MHL cable' 834 834 * - Support MHL 835 835 * - Support charging through micro-usb port without 836 836 * data connection 837 837 */ 838 - extcon_set_cable_state(info->edev, "MHL_TA", attached); 838 + extcon_set_cable_state(info->edev, "MHL-TA", attached); 839 839 if (!cable_attached) 840 840 extcon_set_cable_state(info->edev, 841 841 "MHL", cable_attached); ··· 886 886 * - Support charging and data connection through micro- 887 887 * usb port if USB cable is connected between target 888 888 * and host device 889 - * - Support OTG device (Mouse/Keyboard) 889 + * - Support OTG(On-The-Go) device (Ex: Mouse/Keyboard) 890 890 */ 891 891 ret = max77693_muic_set_path(info, info->path_usb, 892 892 attached); ··· 1019 1019 dev_err(info->dev, "failed to handle MUIC interrupt\n"); 1020 1020 1021 1021 mutex_unlock(&info->mutex); 1022 - 1023 - return; 1024 1022 } 1025 1023 1026 1024 static irqreturn_t max77693_muic_irq_handler(int irq, void *data) ··· 1169 1171 muic_irq->name, info); 1170 1172 if (ret) { 1171 1173 dev_err(&pdev->dev, 1172 - "failed: irq request (IRQ: %d," 1173 - " error :%d)\n", 1174 + "failed: irq request (IRQ: %d, error :%d)\n", 1174 1175 muic_irq->irq, ret); 1175 1176 return ret; 1176 1177 }
+881
drivers/extcon/extcon-max77843.c
··· 1 + /* 2 + * extcon-max77843.c - Maxim MAX77843 extcon driver to support 3 + * MUIC(Micro USB Interface Controller) 4 + * 5 + * Copyright (C) 2015 Samsung Electronics 6 + * Author: Jaewon Kim <jaewon02.kim@samsung.com> 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License as published by 10 + * the Free Software Foundation; either version 2 of the License, or 11 + * (at your option) any later version. 12 + */ 13 + 14 + #include <linux/extcon.h> 15 + #include <linux/i2c.h> 16 + #include <linux/interrupt.h> 17 + #include <linux/kernel.h> 18 + #include <linux/mfd/max77843-private.h> 19 + #include <linux/module.h> 20 + #include <linux/platform_device.h> 21 + #include <linux/workqueue.h> 22 + 23 + #define DELAY_MS_DEFAULT 15000 /* unit: millisecond */ 24 + 25 + enum max77843_muic_status { 26 + MAX77843_MUIC_STATUS1 = 0, 27 + MAX77843_MUIC_STATUS2, 28 + MAX77843_MUIC_STATUS3, 29 + 30 + MAX77843_MUIC_STATUS_NUM, 31 + }; 32 + 33 + struct max77843_muic_info { 34 + struct device *dev; 35 + struct max77843 *max77843; 36 + struct extcon_dev *edev; 37 + 38 + struct mutex mutex; 39 + struct work_struct irq_work; 40 + struct delayed_work wq_detcable; 41 + 42 + u8 status[MAX77843_MUIC_STATUS_NUM]; 43 + int prev_cable_type; 44 + int prev_chg_type; 45 + int prev_gnd_type; 46 + 47 + bool irq_adc; 48 + bool irq_chg; 49 + }; 50 + 51 + enum max77843_muic_cable_group { 52 + MAX77843_CABLE_GROUP_ADC = 0, 53 + MAX77843_CABLE_GROUP_ADC_GND, 54 + MAX77843_CABLE_GROUP_CHG, 55 + }; 56 + 57 + enum max77843_muic_adc_debounce_time { 58 + MAX77843_DEBOUNCE_TIME_5MS = 0, 59 + MAX77843_DEBOUNCE_TIME_10MS, 60 + MAX77843_DEBOUNCE_TIME_25MS, 61 + MAX77843_DEBOUNCE_TIME_38_62MS, 62 + }; 63 + 64 + /* Define accessory cable type */ 65 + enum max77843_muic_accessory_type { 66 + MAX77843_MUIC_ADC_GROUND = 0, 67 + MAX77843_MUIC_ADC_SEND_END_BUTTON, 68 + MAX77843_MUIC_ADC_REMOTE_S1_BUTTON, 69 + MAX77843_MUIC_ADC_REMOTE_S2_BUTTON, 70 + MAX77843_MUIC_ADC_REMOTE_S3_BUTTON, 71 + MAX77843_MUIC_ADC_REMOTE_S4_BUTTON, 72 + MAX77843_MUIC_ADC_REMOTE_S5_BUTTON, 73 + MAX77843_MUIC_ADC_REMOTE_S6_BUTTON, 74 + MAX77843_MUIC_ADC_REMOTE_S7_BUTTON, 75 + MAX77843_MUIC_ADC_REMOTE_S8_BUTTON, 76 + MAX77843_MUIC_ADC_REMOTE_S9_BUTTON, 77 + MAX77843_MUIC_ADC_REMOTE_S10_BUTTON, 78 + MAX77843_MUIC_ADC_REMOTE_S11_BUTTON, 79 + MAX77843_MUIC_ADC_REMOTE_S12_BUTTON, 80 + MAX77843_MUIC_ADC_RESERVED_ACC_1, 81 + MAX77843_MUIC_ADC_RESERVED_ACC_2, 82 + MAX77843_MUIC_ADC_RESERVED_ACC_3, 83 + MAX77843_MUIC_ADC_RESERVED_ACC_4, 84 + MAX77843_MUIC_ADC_RESERVED_ACC_5, 85 + MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE2, 86 + MAX77843_MUIC_ADC_PHONE_POWERED_DEV, 87 + MAX77843_MUIC_ADC_TTY_CONVERTER, 88 + MAX77843_MUIC_ADC_UART_CABLE, 89 + MAX77843_MUIC_ADC_CEA936A_TYPE1_CHG, 90 + MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF, 91 + MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON, 92 + MAX77843_MUIC_ADC_AV_CABLE_NOLOAD, 93 + MAX77843_MUIC_ADC_CEA936A_TYPE2_CHG, 94 + MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF, 95 + MAX77843_MUIC_ADC_FACTORY_MODE_UART_ON, 96 + MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE1, 97 + MAX77843_MUIC_ADC_OPEN, 98 + 99 + /* The blow accessories should check 100 + not only ADC value but also ADC1K and VBVolt value. */ 101 + /* Offset|ADC1K|VBVolt| */ 102 + MAX77843_MUIC_GND_USB_HOST = 0x100, /* 0x1| 0| 0| */ 103 + MAX77843_MUIC_GND_USB_HOST_VB = 0x101, /* 0x1| 0| 1| */ 104 + MAX77843_MUIC_GND_MHL = 0x102, /* 0x1| 1| 0| */ 105 + MAX77843_MUIC_GND_MHL_VB = 0x103, /* 0x1| 1| 1| */ 106 + }; 107 + 108 + /* Define charger cable type */ 109 + enum max77843_muic_charger_type { 110 + MAX77843_MUIC_CHG_NONE = 0, 111 + MAX77843_MUIC_CHG_USB, 112 + MAX77843_MUIC_CHG_DOWNSTREAM, 113 + MAX77843_MUIC_CHG_DEDICATED, 114 + MAX77843_MUIC_CHG_SPECIAL_500MA, 115 + MAX77843_MUIC_CHG_SPECIAL_1A, 116 + MAX77843_MUIC_CHG_SPECIAL_BIAS, 117 + MAX77843_MUIC_CHG_RESERVED, 118 + MAX77843_MUIC_CHG_GND, 119 + }; 120 + 121 + enum { 122 + MAX77843_CABLE_USB = 0, 123 + MAX77843_CABLE_USB_HOST, 124 + MAX77843_CABLE_TA, 125 + MAX77843_CABLE_CHARGE_DOWNSTREAM, 126 + MAX77843_CABLE_FAST_CHARGER, 127 + MAX77843_CABLE_SLOW_CHARGER, 128 + MAX77843_CABLE_MHL, 129 + MAX77843_CABLE_MHL_TA, 130 + MAX77843_CABLE_JIG_USB_ON, 131 + MAX77843_CABLE_JIG_USB_OFF, 132 + MAX77843_CABLE_JIG_UART_ON, 133 + MAX77843_CABLE_JIG_UART_OFF, 134 + 135 + MAX77843_CABLE_NUM, 136 + }; 137 + 138 + static const char *max77843_extcon_cable[] = { 139 + [MAX77843_CABLE_USB] = "USB", 140 + [MAX77843_CABLE_USB_HOST] = "USB-HOST", 141 + [MAX77843_CABLE_TA] = "TA", 142 + [MAX77843_CABLE_CHARGE_DOWNSTREAM] = "CHARGER-DOWNSTREAM", 143 + [MAX77843_CABLE_FAST_CHARGER] = "FAST-CHARGER", 144 + [MAX77843_CABLE_SLOW_CHARGER] = "SLOW-CHARGER", 145 + [MAX77843_CABLE_MHL] = "MHL", 146 + [MAX77843_CABLE_MHL_TA] = "MHL-TA", 147 + [MAX77843_CABLE_JIG_USB_ON] = "JIG-USB-ON", 148 + [MAX77843_CABLE_JIG_USB_OFF] = "JIG-USB-OFF", 149 + [MAX77843_CABLE_JIG_UART_ON] = "JIG-UART-ON", 150 + [MAX77843_CABLE_JIG_UART_OFF] = "JIG-UART-OFF", 151 + }; 152 + 153 + struct max77843_muic_irq { 154 + unsigned int irq; 155 + const char *name; 156 + unsigned int virq; 157 + }; 158 + 159 + static struct max77843_muic_irq max77843_muic_irqs[] = { 160 + { MAX77843_MUIC_IRQ_INT1_ADC, "MUIC-ADC" }, 161 + { MAX77843_MUIC_IRQ_INT1_ADCERROR, "MUIC-ADC_ERROR" }, 162 + { MAX77843_MUIC_IRQ_INT1_ADC1K, "MUIC-ADC1K" }, 163 + { MAX77843_MUIC_IRQ_INT2_CHGTYP, "MUIC-CHGTYP" }, 164 + { MAX77843_MUIC_IRQ_INT2_CHGDETRUN, "MUIC-CHGDETRUN" }, 165 + { MAX77843_MUIC_IRQ_INT2_DCDTMR, "MUIC-DCDTMR" }, 166 + { MAX77843_MUIC_IRQ_INT2_DXOVP, "MUIC-DXOVP" }, 167 + { MAX77843_MUIC_IRQ_INT2_VBVOLT, "MUIC-VBVOLT" }, 168 + { MAX77843_MUIC_IRQ_INT3_VBADC, "MUIC-VBADC" }, 169 + { MAX77843_MUIC_IRQ_INT3_VDNMON, "MUIC-VDNMON" }, 170 + { MAX77843_MUIC_IRQ_INT3_DNRES, "MUIC-DNRES" }, 171 + { MAX77843_MUIC_IRQ_INT3_MPNACK, "MUIC-MPNACK"}, 172 + { MAX77843_MUIC_IRQ_INT3_MRXBUFOW, "MUIC-MRXBUFOW"}, 173 + { MAX77843_MUIC_IRQ_INT3_MRXTRF, "MUIC-MRXTRF"}, 174 + { MAX77843_MUIC_IRQ_INT3_MRXPERR, "MUIC-MRXPERR"}, 175 + { MAX77843_MUIC_IRQ_INT3_MRXRDY, "MUIC-MRXRDY"}, 176 + }; 177 + 178 + static const struct regmap_config max77843_muic_regmap_config = { 179 + .reg_bits = 8, 180 + .val_bits = 8, 181 + .max_register = MAX77843_MUIC_REG_END, 182 + }; 183 + 184 + static const struct regmap_irq max77843_muic_irq[] = { 185 + /* INT1 interrupt */ 186 + { .reg_offset = 0, .mask = MAX77843_MUIC_ADC, }, 187 + { .reg_offset = 0, .mask = MAX77843_MUIC_ADCERROR, }, 188 + { .reg_offset = 0, .mask = MAX77843_MUIC_ADC1K, }, 189 + 190 + /* INT2 interrupt */ 191 + { .reg_offset = 1, .mask = MAX77843_MUIC_CHGTYP, }, 192 + { .reg_offset = 1, .mask = MAX77843_MUIC_CHGDETRUN, }, 193 + { .reg_offset = 1, .mask = MAX77843_MUIC_DCDTMR, }, 194 + { .reg_offset = 1, .mask = MAX77843_MUIC_DXOVP, }, 195 + { .reg_offset = 1, .mask = MAX77843_MUIC_VBVOLT, }, 196 + 197 + /* INT3 interrupt */ 198 + { .reg_offset = 2, .mask = MAX77843_MUIC_VBADC, }, 199 + { .reg_offset = 2, .mask = MAX77843_MUIC_VDNMON, }, 200 + { .reg_offset = 2, .mask = MAX77843_MUIC_DNRES, }, 201 + { .reg_offset = 2, .mask = MAX77843_MUIC_MPNACK, }, 202 + { .reg_offset = 2, .mask = MAX77843_MUIC_MRXBUFOW, }, 203 + { .reg_offset = 2, .mask = MAX77843_MUIC_MRXTRF, }, 204 + { .reg_offset = 2, .mask = MAX77843_MUIC_MRXPERR, }, 205 + { .reg_offset = 2, .mask = MAX77843_MUIC_MRXRDY, }, 206 + }; 207 + 208 + static const struct regmap_irq_chip max77843_muic_irq_chip = { 209 + .name = "max77843-muic", 210 + .status_base = MAX77843_MUIC_REG_INT1, 211 + .mask_base = MAX77843_MUIC_REG_INTMASK1, 212 + .mask_invert = true, 213 + .num_regs = 3, 214 + .irqs = max77843_muic_irq, 215 + .num_irqs = ARRAY_SIZE(max77843_muic_irq), 216 + }; 217 + 218 + static int max77843_muic_set_path(struct max77843_muic_info *info, 219 + u8 val, bool attached) 220 + { 221 + struct max77843 *max77843 = info->max77843; 222 + int ret = 0; 223 + unsigned int ctrl1, ctrl2; 224 + 225 + if (attached) 226 + ctrl1 = val; 227 + else 228 + ctrl1 = CONTROL1_SW_OPEN; 229 + 230 + ret = regmap_update_bits(max77843->regmap_muic, 231 + MAX77843_MUIC_REG_CONTROL1, 232 + CONTROL1_COM_SW, ctrl1); 233 + if (ret < 0) { 234 + dev_err(info->dev, "Cannot switch MUIC port\n"); 235 + return ret; 236 + } 237 + 238 + if (attached) 239 + ctrl2 = MAX77843_MUIC_CONTROL2_CPEN_MASK; 240 + else 241 + ctrl2 = MAX77843_MUIC_CONTROL2_LOWPWR_MASK; 242 + 243 + ret = regmap_update_bits(max77843->regmap_muic, 244 + MAX77843_MUIC_REG_CONTROL2, 245 + MAX77843_MUIC_CONTROL2_LOWPWR_MASK | 246 + MAX77843_MUIC_CONTROL2_CPEN_MASK, ctrl2); 247 + if (ret < 0) { 248 + dev_err(info->dev, "Cannot update lowpower mode\n"); 249 + return ret; 250 + } 251 + 252 + dev_dbg(info->dev, 253 + "CONTROL1 : 0x%02x, CONTROL2 : 0x%02x, state : %s\n", 254 + ctrl1, ctrl2, attached ? "attached" : "detached"); 255 + 256 + return 0; 257 + } 258 + 259 + static int max77843_muic_get_cable_type(struct max77843_muic_info *info, 260 + enum max77843_muic_cable_group group, bool *attached) 261 + { 262 + int adc, chg_type, cable_type, gnd_type; 263 + 264 + adc = info->status[MAX77843_MUIC_STATUS1] & 265 + MAX77843_MUIC_STATUS1_ADC_MASK; 266 + adc >>= STATUS1_ADC_SHIFT; 267 + 268 + switch (group) { 269 + case MAX77843_CABLE_GROUP_ADC: 270 + if (adc == MAX77843_MUIC_ADC_OPEN) { 271 + *attached = false; 272 + cable_type = info->prev_cable_type; 273 + info->prev_cable_type = MAX77843_MUIC_ADC_OPEN; 274 + } else { 275 + *attached = true; 276 + cable_type = info->prev_cable_type = adc; 277 + } 278 + break; 279 + case MAX77843_CABLE_GROUP_CHG: 280 + chg_type = info->status[MAX77843_MUIC_STATUS2] & 281 + MAX77843_MUIC_STATUS2_CHGTYP_MASK; 282 + 283 + /* Check GROUND accessory with charger cable */ 284 + if (adc == MAX77843_MUIC_ADC_GROUND) { 285 + if (chg_type == MAX77843_MUIC_CHG_NONE) { 286 + /* The following state when charger cable is 287 + * disconnected but the GROUND accessory still 288 + * connected */ 289 + *attached = false; 290 + cable_type = info->prev_chg_type; 291 + info->prev_chg_type = MAX77843_MUIC_CHG_NONE; 292 + } else { 293 + 294 + /* The following state when charger cable is 295 + * connected on the GROUND accessory */ 296 + *attached = true; 297 + cable_type = MAX77843_MUIC_CHG_GND; 298 + info->prev_chg_type = MAX77843_MUIC_CHG_GND; 299 + } 300 + break; 301 + } 302 + 303 + if (chg_type == MAX77843_MUIC_CHG_NONE) { 304 + *attached = false; 305 + cable_type = info->prev_chg_type; 306 + info->prev_chg_type = MAX77843_MUIC_CHG_NONE; 307 + } else { 308 + *attached = true; 309 + cable_type = info->prev_chg_type = chg_type; 310 + } 311 + break; 312 + case MAX77843_CABLE_GROUP_ADC_GND: 313 + if (adc == MAX77843_MUIC_ADC_OPEN) { 314 + *attached = false; 315 + cable_type = info->prev_gnd_type; 316 + info->prev_gnd_type = MAX77843_MUIC_ADC_OPEN; 317 + } else { 318 + *attached = true; 319 + 320 + /* Offset|ADC1K|VBVolt| 321 + * 0x1| 0| 0| USB-HOST 322 + * 0x1| 0| 1| USB-HOST with VB 323 + * 0x1| 1| 0| MHL 324 + * 0x1| 1| 1| MHL with VB */ 325 + /* Get ADC1K register bit */ 326 + gnd_type = (info->status[MAX77843_MUIC_STATUS1] & 327 + MAX77843_MUIC_STATUS1_ADC1K_MASK); 328 + 329 + /* Get VBVolt register bit */ 330 + gnd_type |= (info->status[MAX77843_MUIC_STATUS2] & 331 + MAX77843_MUIC_STATUS2_VBVOLT_MASK); 332 + gnd_type >>= STATUS2_VBVOLT_SHIFT; 333 + 334 + /* Offset of GND cable */ 335 + gnd_type |= MAX77843_MUIC_GND_USB_HOST; 336 + cable_type = info->prev_gnd_type = gnd_type; 337 + } 338 + break; 339 + default: 340 + dev_err(info->dev, "Unknown cable group (%d)\n", group); 341 + cable_type = -EINVAL; 342 + break; 343 + } 344 + 345 + return cable_type; 346 + } 347 + 348 + static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info) 349 + { 350 + int ret, gnd_cable_type; 351 + bool attached; 352 + 353 + gnd_cable_type = max77843_muic_get_cable_type(info, 354 + MAX77843_CABLE_GROUP_ADC_GND, &attached); 355 + dev_dbg(info->dev, "external connector is %s (gnd:0x%02x)\n", 356 + attached ? "attached" : "detached", gnd_cable_type); 357 + 358 + switch (gnd_cable_type) { 359 + case MAX77843_MUIC_GND_USB_HOST: 360 + case MAX77843_MUIC_GND_USB_HOST_VB: 361 + ret = max77843_muic_set_path(info, CONTROL1_SW_USB, attached); 362 + if (ret < 0) 363 + return ret; 364 + 365 + extcon_set_cable_state(info->edev, "USB-HOST", attached); 366 + break; 367 + case MAX77843_MUIC_GND_MHL_VB: 368 + case MAX77843_MUIC_GND_MHL: 369 + ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 370 + if (ret < 0) 371 + return ret; 372 + 373 + extcon_set_cable_state(info->edev, "MHL", attached); 374 + break; 375 + default: 376 + dev_err(info->dev, "failed to detect %s accessory(gnd:0x%x)\n", 377 + attached ? "attached" : "detached", gnd_cable_type); 378 + return -EINVAL; 379 + } 380 + 381 + return 0; 382 + } 383 + 384 + static int max77843_muic_jig_handler(struct max77843_muic_info *info, 385 + int cable_type, bool attached) 386 + { 387 + int ret; 388 + 389 + dev_dbg(info->dev, "external connector is %s (adc:0x%02x)\n", 390 + attached ? "attached" : "detached", cable_type); 391 + 392 + switch (cable_type) { 393 + case MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF: 394 + ret = max77843_muic_set_path(info, CONTROL1_SW_USB, attached); 395 + if (ret < 0) 396 + return ret; 397 + extcon_set_cable_state(info->edev, "JIG-USB-OFF", attached); 398 + break; 399 + case MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON: 400 + ret = max77843_muic_set_path(info, CONTROL1_SW_USB, attached); 401 + if (ret < 0) 402 + return ret; 403 + extcon_set_cable_state(info->edev, "JIG-USB-ON", attached); 404 + break; 405 + case MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF: 406 + ret = max77843_muic_set_path(info, CONTROL1_SW_UART, attached); 407 + if (ret < 0) 408 + return ret; 409 + extcon_set_cable_state(info->edev, "JIG-UART-OFF", attached); 410 + break; 411 + default: 412 + ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 413 + if (ret < 0) 414 + return ret; 415 + break; 416 + } 417 + 418 + return 0; 419 + } 420 + 421 + static int max77843_muic_adc_handler(struct max77843_muic_info *info) 422 + { 423 + int ret, cable_type; 424 + bool attached; 425 + 426 + cable_type = max77843_muic_get_cable_type(info, 427 + MAX77843_CABLE_GROUP_ADC, &attached); 428 + 429 + dev_dbg(info->dev, 430 + "external connector is %s (adc:0x%02x, prev_adc:0x%x)\n", 431 + attached ? "attached" : "detached", cable_type, 432 + info->prev_cable_type); 433 + 434 + switch (cable_type) { 435 + case MAX77843_MUIC_ADC_GROUND: 436 + ret = max77843_muic_adc_gnd_handler(info); 437 + if (ret < 0) 438 + return ret; 439 + break; 440 + case MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF: 441 + case MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON: 442 + case MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF: 443 + ret = max77843_muic_jig_handler(info, cable_type, attached); 444 + if (ret < 0) 445 + return ret; 446 + break; 447 + case MAX77843_MUIC_ADC_SEND_END_BUTTON: 448 + case MAX77843_MUIC_ADC_REMOTE_S1_BUTTON: 449 + case MAX77843_MUIC_ADC_REMOTE_S2_BUTTON: 450 + case MAX77843_MUIC_ADC_REMOTE_S3_BUTTON: 451 + case MAX77843_MUIC_ADC_REMOTE_S4_BUTTON: 452 + case MAX77843_MUIC_ADC_REMOTE_S5_BUTTON: 453 + case MAX77843_MUIC_ADC_REMOTE_S6_BUTTON: 454 + case MAX77843_MUIC_ADC_REMOTE_S7_BUTTON: 455 + case MAX77843_MUIC_ADC_REMOTE_S8_BUTTON: 456 + case MAX77843_MUIC_ADC_REMOTE_S9_BUTTON: 457 + case MAX77843_MUIC_ADC_REMOTE_S10_BUTTON: 458 + case MAX77843_MUIC_ADC_REMOTE_S11_BUTTON: 459 + case MAX77843_MUIC_ADC_REMOTE_S12_BUTTON: 460 + case MAX77843_MUIC_ADC_RESERVED_ACC_1: 461 + case MAX77843_MUIC_ADC_RESERVED_ACC_2: 462 + case MAX77843_MUIC_ADC_RESERVED_ACC_3: 463 + case MAX77843_MUIC_ADC_RESERVED_ACC_4: 464 + case MAX77843_MUIC_ADC_RESERVED_ACC_5: 465 + case MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE2: 466 + case MAX77843_MUIC_ADC_PHONE_POWERED_DEV: 467 + case MAX77843_MUIC_ADC_TTY_CONVERTER: 468 + case MAX77843_MUIC_ADC_UART_CABLE: 469 + case MAX77843_MUIC_ADC_CEA936A_TYPE1_CHG: 470 + case MAX77843_MUIC_ADC_AV_CABLE_NOLOAD: 471 + case MAX77843_MUIC_ADC_CEA936A_TYPE2_CHG: 472 + case MAX77843_MUIC_ADC_FACTORY_MODE_UART_ON: 473 + case MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE1: 474 + case MAX77843_MUIC_ADC_OPEN: 475 + dev_err(info->dev, 476 + "accessory is %s but it isn't used (adc:0x%x)\n", 477 + attached ? "attached" : "detached", cable_type); 478 + return -EAGAIN; 479 + default: 480 + dev_err(info->dev, 481 + "failed to detect %s accessory (adc:0x%x)\n", 482 + attached ? "attached" : "detached", cable_type); 483 + return -EINVAL; 484 + } 485 + 486 + return 0; 487 + } 488 + 489 + static int max77843_muic_chg_handler(struct max77843_muic_info *info) 490 + { 491 + int ret, chg_type, gnd_type; 492 + bool attached; 493 + 494 + chg_type = max77843_muic_get_cable_type(info, 495 + MAX77843_CABLE_GROUP_CHG, &attached); 496 + 497 + dev_dbg(info->dev, 498 + "external connector is %s(chg_type:0x%x, prev_chg_type:0x%x)\n", 499 + attached ? "attached" : "detached", 500 + chg_type, info->prev_chg_type); 501 + 502 + switch (chg_type) { 503 + case MAX77843_MUIC_CHG_USB: 504 + ret = max77843_muic_set_path(info, CONTROL1_SW_USB, attached); 505 + if (ret < 0) 506 + return ret; 507 + 508 + extcon_set_cable_state(info->edev, "USB", attached); 509 + break; 510 + case MAX77843_MUIC_CHG_DOWNSTREAM: 511 + ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 512 + if (ret < 0) 513 + return ret; 514 + 515 + extcon_set_cable_state(info->edev, 516 + "CHARGER-DOWNSTREAM", attached); 517 + break; 518 + case MAX77843_MUIC_CHG_DEDICATED: 519 + ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 520 + if (ret < 0) 521 + return ret; 522 + 523 + extcon_set_cable_state(info->edev, "TA", attached); 524 + break; 525 + case MAX77843_MUIC_CHG_SPECIAL_500MA: 526 + ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 527 + if (ret < 0) 528 + return ret; 529 + 530 + extcon_set_cable_state(info->edev, "SLOW-CHAREGER", attached); 531 + break; 532 + case MAX77843_MUIC_CHG_SPECIAL_1A: 533 + ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 534 + if (ret < 0) 535 + return ret; 536 + 537 + extcon_set_cable_state(info->edev, "FAST-CHARGER", attached); 538 + break; 539 + case MAX77843_MUIC_CHG_GND: 540 + gnd_type = max77843_muic_get_cable_type(info, 541 + MAX77843_CABLE_GROUP_ADC_GND, &attached); 542 + 543 + /* Charger cable on MHL accessory is attach or detach */ 544 + if (gnd_type == MAX77843_MUIC_GND_MHL_VB) 545 + extcon_set_cable_state(info->edev, "MHL-TA", true); 546 + else if (gnd_type == MAX77843_MUIC_GND_MHL) 547 + extcon_set_cable_state(info->edev, "MHL-TA", false); 548 + break; 549 + case MAX77843_MUIC_CHG_NONE: 550 + break; 551 + default: 552 + dev_err(info->dev, 553 + "failed to detect %s accessory (chg_type:0x%x)\n", 554 + attached ? "attached" : "detached", chg_type); 555 + 556 + max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 557 + return -EINVAL; 558 + } 559 + 560 + return 0; 561 + } 562 + 563 + static void max77843_muic_irq_work(struct work_struct *work) 564 + { 565 + struct max77843_muic_info *info = container_of(work, 566 + struct max77843_muic_info, irq_work); 567 + struct max77843 *max77843 = info->max77843; 568 + int ret = 0; 569 + 570 + mutex_lock(&info->mutex); 571 + 572 + ret = regmap_bulk_read(max77843->regmap_muic, 573 + MAX77843_MUIC_REG_STATUS1, info->status, 574 + MAX77843_MUIC_STATUS_NUM); 575 + if (ret) { 576 + dev_err(info->dev, "Cannot read STATUS registers\n"); 577 + mutex_unlock(&info->mutex); 578 + return; 579 + } 580 + 581 + if (info->irq_adc) { 582 + ret = max77843_muic_adc_handler(info); 583 + if (ret) 584 + dev_err(info->dev, "Unknown cable type\n"); 585 + info->irq_adc = false; 586 + } 587 + 588 + if (info->irq_chg) { 589 + ret = max77843_muic_chg_handler(info); 590 + if (ret) 591 + dev_err(info->dev, "Unknown charger type\n"); 592 + info->irq_chg = false; 593 + } 594 + 595 + mutex_unlock(&info->mutex); 596 + } 597 + 598 + static irqreturn_t max77843_muic_irq_handler(int irq, void *data) 599 + { 600 + struct max77843_muic_info *info = data; 601 + int i, irq_type = -1; 602 + 603 + for (i = 0; i < ARRAY_SIZE(max77843_muic_irqs); i++) 604 + if (irq == max77843_muic_irqs[i].virq) 605 + irq_type = max77843_muic_irqs[i].irq; 606 + 607 + switch (irq_type) { 608 + case MAX77843_MUIC_IRQ_INT1_ADC: 609 + case MAX77843_MUIC_IRQ_INT1_ADCERROR: 610 + case MAX77843_MUIC_IRQ_INT1_ADC1K: 611 + info->irq_adc = true; 612 + break; 613 + case MAX77843_MUIC_IRQ_INT2_CHGTYP: 614 + case MAX77843_MUIC_IRQ_INT2_CHGDETRUN: 615 + case MAX77843_MUIC_IRQ_INT2_DCDTMR: 616 + case MAX77843_MUIC_IRQ_INT2_DXOVP: 617 + case MAX77843_MUIC_IRQ_INT2_VBVOLT: 618 + info->irq_chg = true; 619 + break; 620 + case MAX77843_MUIC_IRQ_INT3_VBADC: 621 + case MAX77843_MUIC_IRQ_INT3_VDNMON: 622 + case MAX77843_MUIC_IRQ_INT3_DNRES: 623 + case MAX77843_MUIC_IRQ_INT3_MPNACK: 624 + case MAX77843_MUIC_IRQ_INT3_MRXBUFOW: 625 + case MAX77843_MUIC_IRQ_INT3_MRXTRF: 626 + case MAX77843_MUIC_IRQ_INT3_MRXPERR: 627 + case MAX77843_MUIC_IRQ_INT3_MRXRDY: 628 + break; 629 + default: 630 + dev_err(info->dev, "Cannot recognize IRQ(%d)\n", irq_type); 631 + break; 632 + } 633 + 634 + schedule_work(&info->irq_work); 635 + 636 + return IRQ_HANDLED; 637 + } 638 + 639 + static void max77843_muic_detect_cable_wq(struct work_struct *work) 640 + { 641 + struct max77843_muic_info *info = container_of(to_delayed_work(work), 642 + struct max77843_muic_info, wq_detcable); 643 + struct max77843 *max77843 = info->max77843; 644 + int chg_type, adc, ret; 645 + bool attached; 646 + 647 + mutex_lock(&info->mutex); 648 + 649 + ret = regmap_bulk_read(max77843->regmap_muic, 650 + MAX77843_MUIC_REG_STATUS1, info->status, 651 + MAX77843_MUIC_STATUS_NUM); 652 + if (ret) { 653 + dev_err(info->dev, "Cannot read STATUS registers\n"); 654 + goto err_cable_wq; 655 + } 656 + 657 + adc = max77843_muic_get_cable_type(info, 658 + MAX77843_CABLE_GROUP_ADC, &attached); 659 + if (attached && adc != MAX77843_MUIC_ADC_OPEN) { 660 + ret = max77843_muic_adc_handler(info); 661 + if (ret < 0) { 662 + dev_err(info->dev, "Cannot detect accessory\n"); 663 + goto err_cable_wq; 664 + } 665 + } 666 + 667 + chg_type = max77843_muic_get_cable_type(info, 668 + MAX77843_CABLE_GROUP_CHG, &attached); 669 + if (attached && chg_type != MAX77843_MUIC_CHG_NONE) { 670 + ret = max77843_muic_chg_handler(info); 671 + if (ret < 0) { 672 + dev_err(info->dev, "Cannot detect charger accessory\n"); 673 + goto err_cable_wq; 674 + } 675 + } 676 + 677 + err_cable_wq: 678 + mutex_unlock(&info->mutex); 679 + } 680 + 681 + static int max77843_muic_set_debounce_time(struct max77843_muic_info *info, 682 + enum max77843_muic_adc_debounce_time time) 683 + { 684 + struct max77843 *max77843 = info->max77843; 685 + int ret; 686 + 687 + switch (time) { 688 + case MAX77843_DEBOUNCE_TIME_5MS: 689 + case MAX77843_DEBOUNCE_TIME_10MS: 690 + case MAX77843_DEBOUNCE_TIME_25MS: 691 + case MAX77843_DEBOUNCE_TIME_38_62MS: 692 + ret = regmap_update_bits(max77843->regmap_muic, 693 + MAX77843_MUIC_REG_CONTROL4, 694 + MAX77843_MUIC_CONTROL4_ADCDBSET_MASK, 695 + time << CONTROL4_ADCDBSET_SHIFT); 696 + if (ret < 0) { 697 + dev_err(info->dev, "Cannot write MUIC regmap\n"); 698 + return ret; 699 + } 700 + break; 701 + default: 702 + dev_err(info->dev, "Invalid ADC debounce time\n"); 703 + return -EINVAL; 704 + } 705 + 706 + return 0; 707 + } 708 + 709 + static int max77843_init_muic_regmap(struct max77843 *max77843) 710 + { 711 + int ret; 712 + 713 + max77843->i2c_muic = i2c_new_dummy(max77843->i2c->adapter, 714 + I2C_ADDR_MUIC); 715 + if (!max77843->i2c_muic) { 716 + dev_err(&max77843->i2c->dev, 717 + "Cannot allocate I2C device for MUIC\n"); 718 + return -ENOMEM; 719 + } 720 + 721 + i2c_set_clientdata(max77843->i2c_muic, max77843); 722 + 723 + max77843->regmap_muic = devm_regmap_init_i2c(max77843->i2c_muic, 724 + &max77843_muic_regmap_config); 725 + if (IS_ERR(max77843->regmap_muic)) { 726 + ret = PTR_ERR(max77843->regmap_muic); 727 + goto err_muic_i2c; 728 + } 729 + 730 + ret = regmap_add_irq_chip(max77843->regmap_muic, max77843->irq, 731 + IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED, 732 + 0, &max77843_muic_irq_chip, &max77843->irq_data_muic); 733 + if (ret < 0) { 734 + dev_err(&max77843->i2c->dev, "Cannot add MUIC IRQ chip\n"); 735 + goto err_muic_i2c; 736 + } 737 + 738 + return 0; 739 + 740 + err_muic_i2c: 741 + i2c_unregister_device(max77843->i2c_muic); 742 + 743 + return ret; 744 + } 745 + 746 + static int max77843_muic_probe(struct platform_device *pdev) 747 + { 748 + struct max77843 *max77843 = dev_get_drvdata(pdev->dev.parent); 749 + struct max77843_muic_info *info; 750 + unsigned int id; 751 + int i, ret; 752 + 753 + info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); 754 + if (!info) 755 + return -ENOMEM; 756 + 757 + info->dev = &pdev->dev; 758 + info->max77843 = max77843; 759 + 760 + platform_set_drvdata(pdev, info); 761 + mutex_init(&info->mutex); 762 + 763 + /* Initialize i2c and regmap */ 764 + ret = max77843_init_muic_regmap(max77843); 765 + if (ret) { 766 + dev_err(&pdev->dev, "Failed to init MUIC regmap\n"); 767 + return ret; 768 + } 769 + 770 + /* Turn off auto detection configuration */ 771 + ret = regmap_update_bits(max77843->regmap_muic, 772 + MAX77843_MUIC_REG_CONTROL4, 773 + MAX77843_MUIC_CONTROL4_USBAUTO_MASK | 774 + MAX77843_MUIC_CONTROL4_FCTAUTO_MASK, 775 + CONTROL4_AUTO_DISABLE); 776 + 777 + /* Initialize extcon device */ 778 + info->edev = devm_extcon_dev_allocate(&pdev->dev, 779 + max77843_extcon_cable); 780 + if (IS_ERR(info->edev)) { 781 + dev_err(&pdev->dev, "Failed to allocate memory for extcon\n"); 782 + ret = -ENODEV; 783 + goto err_muic_irq; 784 + } 785 + 786 + ret = devm_extcon_dev_register(&pdev->dev, info->edev); 787 + if (ret) { 788 + dev_err(&pdev->dev, "Failed to register extcon device\n"); 789 + goto err_muic_irq; 790 + } 791 + 792 + /* Set ADC debounce time */ 793 + max77843_muic_set_debounce_time(info, MAX77843_DEBOUNCE_TIME_25MS); 794 + 795 + /* Set initial path for UART */ 796 + max77843_muic_set_path(info, CONTROL1_SW_UART, true); 797 + 798 + /* Check revision number of MUIC device */ 799 + ret = regmap_read(max77843->regmap_muic, MAX77843_MUIC_REG_ID, &id); 800 + if (ret < 0) { 801 + dev_err(&pdev->dev, "Failed to read revision number\n"); 802 + goto err_muic_irq; 803 + } 804 + dev_info(info->dev, "MUIC device ID : 0x%x\n", id); 805 + 806 + /* Support virtual irq domain for max77843 MUIC device */ 807 + INIT_WORK(&info->irq_work, max77843_muic_irq_work); 808 + 809 + for (i = 0; i < ARRAY_SIZE(max77843_muic_irqs); i++) { 810 + struct max77843_muic_irq *muic_irq = &max77843_muic_irqs[i]; 811 + unsigned int virq = 0; 812 + 813 + virq = regmap_irq_get_virq(max77843->irq_data_muic, 814 + muic_irq->irq); 815 + if (virq <= 0) { 816 + ret = -EINVAL; 817 + goto err_muic_irq; 818 + } 819 + muic_irq->virq = virq; 820 + 821 + ret = devm_request_threaded_irq(&pdev->dev, virq, NULL, 822 + max77843_muic_irq_handler, IRQF_NO_SUSPEND, 823 + muic_irq->name, info); 824 + if (ret) { 825 + dev_err(&pdev->dev, 826 + "Failed to request irq (IRQ: %d, error: %d)\n", 827 + muic_irq->irq, ret); 828 + goto err_muic_irq; 829 + } 830 + } 831 + 832 + /* Detect accessory after completing the initialization of platform */ 833 + INIT_DELAYED_WORK(&info->wq_detcable, max77843_muic_detect_cable_wq); 834 + queue_delayed_work(system_power_efficient_wq, 835 + &info->wq_detcable, msecs_to_jiffies(DELAY_MS_DEFAULT)); 836 + 837 + return 0; 838 + 839 + err_muic_irq: 840 + regmap_del_irq_chip(max77843->irq, max77843->irq_data_muic); 841 + i2c_unregister_device(max77843->i2c_muic); 842 + 843 + return ret; 844 + } 845 + 846 + static int max77843_muic_remove(struct platform_device *pdev) 847 + { 848 + struct max77843_muic_info *info = platform_get_drvdata(pdev); 849 + struct max77843 *max77843 = info->max77843; 850 + 851 + cancel_work_sync(&info->irq_work); 852 + regmap_del_irq_chip(max77843->irq, max77843->irq_data_muic); 853 + i2c_unregister_device(max77843->i2c_muic); 854 + 855 + return 0; 856 + } 857 + 858 + static const struct platform_device_id max77843_muic_id[] = { 859 + { "max77843-muic", }, 860 + { /* sentinel */ }, 861 + }; 862 + MODULE_DEVICE_TABLE(platform, max77843_muic_id); 863 + 864 + static struct platform_driver max77843_muic_driver = { 865 + .driver = { 866 + .name = "max77843-muic", 867 + }, 868 + .probe = max77843_muic_probe, 869 + .remove = max77843_muic_remove, 870 + .id_table = max77843_muic_id, 871 + }; 872 + 873 + static int __init max77843_muic_init(void) 874 + { 875 + return platform_driver_register(&max77843_muic_driver); 876 + } 877 + subsys_initcall(max77843_muic_init); 878 + 879 + MODULE_DESCRIPTION("Maxim MAX77843 Extcon driver"); 880 + MODULE_AUTHOR("Jaewon Kim <jaewon02.kim@samsung.com>"); 881 + MODULE_LICENSE("GPL");
+1 -4
drivers/extcon/extcon-max8997.c
··· 579 579 dev_err(info->dev, "failed to handle MUIC interrupt\n"); 580 580 581 581 mutex_unlock(&info->mutex); 582 - 583 - return; 584 582 } 585 583 586 584 static irqreturn_t max8997_muic_irq_handler(int irq, void *data) ··· 687 689 muic_irq->name, info); 688 690 if (ret) { 689 691 dev_err(&pdev->dev, 690 - "failed: irq request (IRQ: %d," 691 - " error :%d)\n", 692 + "failed: irq request (IRQ: %d, error :%d)\n", 692 693 muic_irq->irq, ret); 693 694 goto err_irq; 694 695 }
+2 -4
drivers/extcon/extcon-rt8973a.c
··· 582 582 return -EINVAL; 583 583 584 584 info = devm_kzalloc(&i2c->dev, sizeof(*info), GFP_KERNEL); 585 - if (!info) { 586 - dev_err(&i2c->dev, "failed to allocate memory\n"); 585 + if (!info) 587 586 return -ENOMEM; 588 - } 589 587 i2c_set_clientdata(i2c, info); 590 588 591 589 info->dev = &i2c->dev; ··· 679 681 return 0; 680 682 } 681 683 682 - static struct of_device_id rt8973a_dt_match[] = { 684 + static const struct of_device_id rt8973a_dt_match[] = { 683 685 { .compatible = "richtek,rt8973a-muic" }, 684 686 { }, 685 687 };
+3 -3
drivers/extcon/extcon-sm5502.c
··· 359 359 break; 360 360 default: 361 361 dev_dbg(info->dev, 362 - "cannot identify the cable type: adc(0x%x) " 363 - "dev_type1(0x%x)\n", adc, dev_type1); 362 + "cannot identify the cable type: adc(0x%x)\n", 363 + adc); 364 364 return -EINVAL; 365 365 }; 366 366 break; ··· 659 659 return 0; 660 660 } 661 661 662 - static struct of_device_id sm5502_dt_match[] = { 662 + static const struct of_device_id sm5502_dt_match[] = { 663 663 { .compatible = "siliconmitus,sm5502-muic" }, 664 664 { }, 665 665 };
+237
drivers/extcon/extcon-usb-gpio.c
··· 1 + /** 2 + * drivers/extcon/extcon-usb-gpio.c - USB GPIO extcon driver 3 + * 4 + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com 5 + * Author: Roger Quadros <rogerq@ti.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + */ 16 + 17 + #include <linux/extcon.h> 18 + #include <linux/init.h> 19 + #include <linux/interrupt.h> 20 + #include <linux/irq.h> 21 + #include <linux/kernel.h> 22 + #include <linux/module.h> 23 + #include <linux/of_gpio.h> 24 + #include <linux/platform_device.h> 25 + #include <linux/slab.h> 26 + #include <linux/workqueue.h> 27 + 28 + #define USB_GPIO_DEBOUNCE_MS 20 /* ms */ 29 + 30 + struct usb_extcon_info { 31 + struct device *dev; 32 + struct extcon_dev *edev; 33 + 34 + struct gpio_desc *id_gpiod; 35 + int id_irq; 36 + 37 + unsigned long debounce_jiffies; 38 + struct delayed_work wq_detcable; 39 + }; 40 + 41 + /* List of detectable cables */ 42 + enum { 43 + EXTCON_CABLE_USB = 0, 44 + EXTCON_CABLE_USB_HOST, 45 + 46 + EXTCON_CABLE_END, 47 + }; 48 + 49 + static const char *usb_extcon_cable[] = { 50 + [EXTCON_CABLE_USB] = "USB", 51 + [EXTCON_CABLE_USB_HOST] = "USB-HOST", 52 + NULL, 53 + }; 54 + 55 + static void usb_extcon_detect_cable(struct work_struct *work) 56 + { 57 + int id; 58 + struct usb_extcon_info *info = container_of(to_delayed_work(work), 59 + struct usb_extcon_info, 60 + wq_detcable); 61 + 62 + /* check ID and update cable state */ 63 + id = gpiod_get_value_cansleep(info->id_gpiod); 64 + if (id) { 65 + /* 66 + * ID = 1 means USB HOST cable detached. 67 + * As we don't have event for USB peripheral cable attached, 68 + * we simulate USB peripheral attach here. 69 + */ 70 + extcon_set_cable_state(info->edev, 71 + usb_extcon_cable[EXTCON_CABLE_USB_HOST], 72 + false); 73 + extcon_set_cable_state(info->edev, 74 + usb_extcon_cable[EXTCON_CABLE_USB], 75 + true); 76 + } else { 77 + /* 78 + * ID = 0 means USB HOST cable attached. 79 + * As we don't have event for USB peripheral cable detached, 80 + * we simulate USB peripheral detach here. 81 + */ 82 + extcon_set_cable_state(info->edev, 83 + usb_extcon_cable[EXTCON_CABLE_USB], 84 + false); 85 + extcon_set_cable_state(info->edev, 86 + usb_extcon_cable[EXTCON_CABLE_USB_HOST], 87 + true); 88 + } 89 + } 90 + 91 + static irqreturn_t usb_irq_handler(int irq, void *dev_id) 92 + { 93 + struct usb_extcon_info *info = dev_id; 94 + 95 + queue_delayed_work(system_power_efficient_wq, &info->wq_detcable, 96 + info->debounce_jiffies); 97 + 98 + return IRQ_HANDLED; 99 + } 100 + 101 + static int usb_extcon_probe(struct platform_device *pdev) 102 + { 103 + struct device *dev = &pdev->dev; 104 + struct device_node *np = dev->of_node; 105 + struct usb_extcon_info *info; 106 + int ret; 107 + 108 + if (!np) 109 + return -EINVAL; 110 + 111 + info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); 112 + if (!info) 113 + return -ENOMEM; 114 + 115 + info->dev = dev; 116 + info->id_gpiod = devm_gpiod_get(&pdev->dev, "id"); 117 + if (IS_ERR(info->id_gpiod)) { 118 + dev_err(dev, "failed to get ID GPIO\n"); 119 + return PTR_ERR(info->id_gpiod); 120 + } 121 + 122 + ret = gpiod_set_debounce(info->id_gpiod, 123 + USB_GPIO_DEBOUNCE_MS * 1000); 124 + if (ret < 0) 125 + info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEBOUNCE_MS); 126 + 127 + INIT_DELAYED_WORK(&info->wq_detcable, usb_extcon_detect_cable); 128 + 129 + info->id_irq = gpiod_to_irq(info->id_gpiod); 130 + if (info->id_irq < 0) { 131 + dev_err(dev, "failed to get ID IRQ\n"); 132 + return info->id_irq; 133 + } 134 + 135 + ret = devm_request_threaded_irq(dev, info->id_irq, NULL, 136 + usb_irq_handler, 137 + IRQF_TRIGGER_RISING | 138 + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 139 + pdev->name, info); 140 + if (ret < 0) { 141 + dev_err(dev, "failed to request handler for ID IRQ\n"); 142 + return ret; 143 + } 144 + 145 + info->edev = devm_extcon_dev_allocate(dev, usb_extcon_cable); 146 + if (IS_ERR(info->edev)) { 147 + dev_err(dev, "failed to allocate extcon device\n"); 148 + return -ENOMEM; 149 + } 150 + 151 + ret = devm_extcon_dev_register(dev, info->edev); 152 + if (ret < 0) { 153 + dev_err(dev, "failed to register extcon device\n"); 154 + return ret; 155 + } 156 + 157 + platform_set_drvdata(pdev, info); 158 + device_init_wakeup(dev, 1); 159 + 160 + /* Perform initial detection */ 161 + usb_extcon_detect_cable(&info->wq_detcable.work); 162 + 163 + return 0; 164 + } 165 + 166 + static int usb_extcon_remove(struct platform_device *pdev) 167 + { 168 + struct usb_extcon_info *info = platform_get_drvdata(pdev); 169 + 170 + cancel_delayed_work_sync(&info->wq_detcable); 171 + 172 + return 0; 173 + } 174 + 175 + #ifdef CONFIG_PM_SLEEP 176 + static int usb_extcon_suspend(struct device *dev) 177 + { 178 + struct usb_extcon_info *info = dev_get_drvdata(dev); 179 + int ret = 0; 180 + 181 + if (device_may_wakeup(dev)) { 182 + ret = enable_irq_wake(info->id_irq); 183 + if (ret) 184 + return ret; 185 + } 186 + 187 + /* 188 + * We don't want to process any IRQs after this point 189 + * as GPIOs used behind I2C subsystem might not be 190 + * accessible until resume completes. So disable IRQ. 191 + */ 192 + disable_irq(info->id_irq); 193 + 194 + return ret; 195 + } 196 + 197 + static int usb_extcon_resume(struct device *dev) 198 + { 199 + struct usb_extcon_info *info = dev_get_drvdata(dev); 200 + int ret = 0; 201 + 202 + if (device_may_wakeup(dev)) { 203 + ret = disable_irq_wake(info->id_irq); 204 + if (ret) 205 + return ret; 206 + } 207 + 208 + enable_irq(info->id_irq); 209 + 210 + return ret; 211 + } 212 + #endif 213 + 214 + static SIMPLE_DEV_PM_OPS(usb_extcon_pm_ops, 215 + usb_extcon_suspend, usb_extcon_resume); 216 + 217 + static const struct of_device_id usb_extcon_dt_match[] = { 218 + { .compatible = "linux,extcon-usb-gpio", }, 219 + { /* sentinel */ } 220 + }; 221 + MODULE_DEVICE_TABLE(of, usb_extcon_dt_match); 222 + 223 + static struct platform_driver usb_extcon_driver = { 224 + .probe = usb_extcon_probe, 225 + .remove = usb_extcon_remove, 226 + .driver = { 227 + .name = "extcon-usb-gpio", 228 + .pm = &usb_extcon_pm_ops, 229 + .of_match_table = usb_extcon_dt_match, 230 + }, 231 + }; 232 + 233 + module_platform_driver(usb_extcon_driver); 234 + 235 + MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>"); 236 + MODULE_DESCRIPTION("USB GPIO extcon driver"); 237 + MODULE_LICENSE("GPL v2");
+96 -29
drivers/hv/channel.c
··· 71 71 struct vmbus_channel_msginfo *open_info = NULL; 72 72 void *in, *out; 73 73 unsigned long flags; 74 - int ret, t, err = 0; 74 + int ret, err = 0; 75 + unsigned long t; 75 76 76 77 spin_lock_irqsave(&newchannel->lock, flags); 77 78 if (newchannel->state == CHANNEL_OPEN_STATE) { ··· 90 89 out = (void *)__get_free_pages(GFP_KERNEL|__GFP_ZERO, 91 90 get_order(send_ringbuffer_size + recv_ringbuffer_size)); 92 91 93 - if (!out) 94 - return -ENOMEM; 95 - 92 + if (!out) { 93 + err = -ENOMEM; 94 + goto error0; 95 + } 96 96 97 97 in = (void *)((unsigned long)out + send_ringbuffer_size); 98 98 ··· 137 135 GFP_KERNEL); 138 136 if (!open_info) { 139 137 err = -ENOMEM; 140 - goto error0; 138 + goto error_gpadl; 141 139 } 142 140 143 141 init_completion(&open_info->waitevent); ··· 153 151 154 152 if (userdatalen > MAX_USER_DEFINED_BYTES) { 155 153 err = -EINVAL; 156 - goto error0; 154 + goto error_gpadl; 157 155 } 158 156 159 157 if (userdatalen) ··· 197 195 list_del(&open_info->msglistentry); 198 196 spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); 199 197 198 + error_gpadl: 199 + vmbus_teardown_gpadl(newchannel, newchannel->ringbuffer_gpadlhandle); 200 + 200 201 error0: 201 202 free_pages((unsigned long)out, 202 203 get_order(send_ringbuffer_size + recv_ringbuffer_size)); 203 204 kfree(open_info); 205 + newchannel->state = CHANNEL_OPEN_STATE; 204 206 return err; 205 207 } 206 208 EXPORT_SYMBOL_GPL(vmbus_open); ··· 540 534 free_pages((unsigned long)channel->ringbuffer_pages, 541 535 get_order(channel->ringbuffer_pagecount * PAGE_SIZE)); 542 536 537 + /* 538 + * If the channel has been rescinded; process device removal. 539 + */ 540 + if (channel->rescind) 541 + hv_process_channel_removal(channel, 542 + channel->offermsg.child_relid); 543 543 return ret; 544 544 } 545 545 ··· 581 569 } 582 570 EXPORT_SYMBOL_GPL(vmbus_close); 583 571 584 - /** 585 - * vmbus_sendpacket() - Send the specified buffer on the given channel 586 - * @channel: Pointer to vmbus_channel structure. 587 - * @buffer: Pointer to the buffer you want to receive the data into. 588 - * @bufferlen: Maximum size of what the the buffer will hold 589 - * @requestid: Identifier of the request 590 - * @type: Type of packet that is being send e.g. negotiate, time 591 - * packet etc. 592 - * 593 - * Sends data in @buffer directly to hyper-v via the vmbus 594 - * This will send the data unparsed to hyper-v. 595 - * 596 - * Mainly used by Hyper-V drivers. 597 - */ 598 - int vmbus_sendpacket(struct vmbus_channel *channel, void *buffer, 572 + int vmbus_sendpacket_ctl(struct vmbus_channel *channel, void *buffer, 599 573 u32 bufferlen, u64 requestid, 600 - enum vmbus_packet_type type, u32 flags) 574 + enum vmbus_packet_type type, u32 flags, bool kick_q) 601 575 { 602 576 struct vmpacket_descriptor desc; 603 577 u32 packetlen = sizeof(struct vmpacket_descriptor) + bufferlen; ··· 611 613 612 614 ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal); 613 615 614 - if (ret == 0 && signal) 616 + /* 617 + * Signalling the host is conditional on many factors: 618 + * 1. The ring state changed from being empty to non-empty. 619 + * This is tracked by the variable "signal". 620 + * 2. The variable kick_q tracks if more data will be placed 621 + * on the ring. We will not signal if more data is 622 + * to be placed. 623 + * 624 + * If we cannot write to the ring-buffer; signal the host 625 + * even if we may not have written anything. This is a rare 626 + * enough condition that it should not matter. 627 + */ 628 + if (((ret == 0) && kick_q && signal) || (ret)) 615 629 vmbus_setevent(channel); 616 630 617 631 return ret; 618 632 } 633 + EXPORT_SYMBOL(vmbus_sendpacket_ctl); 634 + 635 + /** 636 + * vmbus_sendpacket() - Send the specified buffer on the given channel 637 + * @channel: Pointer to vmbus_channel structure. 638 + * @buffer: Pointer to the buffer you want to receive the data into. 639 + * @bufferlen: Maximum size of what the the buffer will hold 640 + * @requestid: Identifier of the request 641 + * @type: Type of packet that is being send e.g. negotiate, time 642 + * packet etc. 643 + * 644 + * Sends data in @buffer directly to hyper-v via the vmbus 645 + * This will send the data unparsed to hyper-v. 646 + * 647 + * Mainly used by Hyper-V drivers. 648 + */ 649 + int vmbus_sendpacket(struct vmbus_channel *channel, void *buffer, 650 + u32 bufferlen, u64 requestid, 651 + enum vmbus_packet_type type, u32 flags) 652 + { 653 + return vmbus_sendpacket_ctl(channel, buffer, bufferlen, requestid, 654 + type, flags, true); 655 + } 619 656 EXPORT_SYMBOL(vmbus_sendpacket); 620 657 621 658 /* 622 - * vmbus_sendpacket_pagebuffer - Send a range of single-page buffer 623 - * packets using a GPADL Direct packet type. 659 + * vmbus_sendpacket_pagebuffer_ctl - Send a range of single-page buffer 660 + * packets using a GPADL Direct packet type. This interface allows you 661 + * to control notifying the host. This will be useful for sending 662 + * batched data. Also the sender can control the send flags 663 + * explicitly. 624 664 */ 625 - int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, 665 + int vmbus_sendpacket_pagebuffer_ctl(struct vmbus_channel *channel, 626 666 struct hv_page_buffer pagebuffers[], 627 667 u32 pagecount, void *buffer, u32 bufferlen, 628 - u64 requestid) 668 + u64 requestid, 669 + u32 flags, 670 + bool kick_q) 629 671 { 630 672 int ret; 631 673 int i; ··· 693 655 694 656 /* Setup the descriptor */ 695 657 desc.type = VM_PKT_DATA_USING_GPA_DIRECT; 696 - desc.flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; 658 + desc.flags = flags; 697 659 desc.dataoffset8 = descsize >> 3; /* in 8-bytes grandularity */ 698 660 desc.length8 = (u16)(packetlen_aligned >> 3); 699 661 desc.transactionid = requestid; ··· 714 676 715 677 ret = hv_ringbuffer_write(&channel->outbound, bufferlist, 3, &signal); 716 678 717 - if (ret == 0 && signal) 679 + /* 680 + * Signalling the host is conditional on many factors: 681 + * 1. The ring state changed from being empty to non-empty. 682 + * This is tracked by the variable "signal". 683 + * 2. The variable kick_q tracks if more data will be placed 684 + * on the ring. We will not signal if more data is 685 + * to be placed. 686 + * 687 + * If we cannot write to the ring-buffer; signal the host 688 + * even if we may not have written anything. This is a rare 689 + * enough condition that it should not matter. 690 + */ 691 + if (((ret == 0) && kick_q && signal) || (ret)) 718 692 vmbus_setevent(channel); 719 693 720 694 return ret; 695 + } 696 + EXPORT_SYMBOL_GPL(vmbus_sendpacket_pagebuffer_ctl); 697 + 698 + /* 699 + * vmbus_sendpacket_pagebuffer - Send a range of single-page buffer 700 + * packets using a GPADL Direct packet type. 701 + */ 702 + int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, 703 + struct hv_page_buffer pagebuffers[], 704 + u32 pagecount, void *buffer, u32 bufferlen, 705 + u64 requestid) 706 + { 707 + u32 flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; 708 + return vmbus_sendpacket_pagebuffer_ctl(channel, pagebuffers, pagecount, 709 + buffer, bufferlen, requestid, 710 + flags, true); 711 + 721 712 } 722 713 EXPORT_SYMBOL_GPL(vmbus_sendpacket_pagebuffer); 723 714
+87 -136
drivers/hv/channel_mgmt.c
··· 32 32 33 33 #include "hyperv_vmbus.h" 34 34 35 - struct vmbus_channel_message_table_entry { 36 - enum vmbus_channel_message_type message_type; 37 - void (*message_handler)(struct vmbus_channel_message_header *msg); 38 - }; 39 - 40 - 41 35 /** 42 36 * vmbus_prep_negotiate_resp() - Create default response for Hyper-V Negotiate message 43 37 * @icmsghdrp: Pointer to msg header structure ··· 133 139 */ 134 140 static struct vmbus_channel *alloc_channel(void) 135 141 { 142 + static atomic_t chan_num = ATOMIC_INIT(0); 136 143 struct vmbus_channel *channel; 137 144 138 145 channel = kzalloc(sizeof(*channel), GFP_ATOMIC); 139 146 if (!channel) 140 147 return NULL; 141 148 149 + channel->id = atomic_inc_return(&chan_num); 142 150 spin_lock_init(&channel->inbound_lock); 143 151 spin_lock_init(&channel->lock); 144 152 145 153 INIT_LIST_HEAD(&channel->sc_list); 146 154 INIT_LIST_HEAD(&channel->percpu_list); 147 155 148 - channel->controlwq = create_workqueue("hv_vmbus_ctl"); 149 - if (!channel->controlwq) { 150 - kfree(channel); 151 - return NULL; 152 - } 153 - 154 156 return channel; 155 - } 156 - 157 - /* 158 - * release_hannel - Release the vmbus channel object itself 159 - */ 160 - static void release_channel(struct work_struct *work) 161 - { 162 - struct vmbus_channel *channel = container_of(work, 163 - struct vmbus_channel, 164 - work); 165 - 166 - destroy_workqueue(channel->controlwq); 167 - 168 - kfree(channel); 169 157 } 170 158 171 159 /* ··· 155 179 */ 156 180 static void free_channel(struct vmbus_channel *channel) 157 181 { 158 - 159 - /* 160 - * We have to release the channel's workqueue/thread in the vmbus's 161 - * workqueue/thread context 162 - * ie we can't destroy ourselves. 163 - */ 164 - INIT_WORK(&channel->work, release_channel); 165 - queue_work(vmbus_connection.work_queue, &channel->work); 182 + kfree(channel); 166 183 } 167 184 168 185 static void percpu_channel_enq(void *arg) ··· 173 204 list_del(&channel->percpu_list); 174 205 } 175 206 176 - /* 177 - * vmbus_process_rescind_offer - 178 - * Rescind the offer by initiating a device removal 179 - */ 180 - static void vmbus_process_rescind_offer(struct work_struct *work) 207 + 208 + void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid) 181 209 { 182 - struct vmbus_channel *channel = container_of(work, 183 - struct vmbus_channel, 184 - work); 210 + struct vmbus_channel_relid_released msg; 185 211 unsigned long flags; 186 212 struct vmbus_channel *primary_channel; 187 - struct vmbus_channel_relid_released msg; 188 - struct device *dev; 189 - 190 - if (channel->device_obj) { 191 - dev = get_device(&channel->device_obj->device); 192 - if (dev) { 193 - vmbus_device_unregister(channel->device_obj); 194 - put_device(dev); 195 - } 196 - } 197 213 198 214 memset(&msg, 0, sizeof(struct vmbus_channel_relid_released)); 199 - msg.child_relid = channel->offermsg.child_relid; 215 + msg.child_relid = relid; 200 216 msg.header.msgtype = CHANNELMSG_RELID_RELEASED; 201 217 vmbus_post_msg(&msg, sizeof(struct vmbus_channel_relid_released)); 218 + 219 + if (channel == NULL) 220 + return; 202 221 203 222 if (channel->target_cpu != get_cpu()) { 204 223 put_cpu(); ··· 216 259 217 260 list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) { 218 261 vmbus_device_unregister(channel->device_obj); 219 - kfree(channel->device_obj); 220 262 free_channel(channel); 221 263 } 222 264 } ··· 224 268 * vmbus_process_offer - Process the offer by creating a channel/device 225 269 * associated with this offer 226 270 */ 227 - static void vmbus_process_offer(struct work_struct *work) 271 + static void vmbus_process_offer(struct vmbus_channel *newchannel) 228 272 { 229 - struct vmbus_channel *newchannel = container_of(work, 230 - struct vmbus_channel, 231 - work); 232 273 struct vmbus_channel *channel; 233 274 bool fnew = true; 234 275 bool enq = false; 235 - int ret; 236 276 unsigned long flags; 237 277 238 278 /* Make sure this is a new offer */ ··· 287 335 } 288 336 289 337 newchannel->state = CHANNEL_OPEN_STATE; 338 + channel->num_sc++; 290 339 if (channel->sc_creation_callback != NULL) 291 340 channel->sc_creation_callback(newchannel); 292 341 293 - goto done_init_rescind; 342 + return; 294 343 } 295 344 296 345 goto err_free_chan; ··· 314 361 &newchannel->offermsg.offer.if_instance, 315 362 newchannel); 316 363 if (!newchannel->device_obj) 317 - goto err_free_chan; 364 + goto err_deq_chan; 318 365 319 366 /* 320 367 * Add the new device to the bus. This will kick off device-driver 321 368 * binding which eventually invokes the device driver's AddDevice() 322 369 * method. 323 370 */ 324 - ret = vmbus_device_register(newchannel->device_obj); 325 - if (ret != 0) { 371 + if (vmbus_device_register(newchannel->device_obj) != 0) { 326 372 pr_err("unable to add child device object (relid %d)\n", 327 - newchannel->offermsg.child_relid); 328 - 329 - spin_lock_irqsave(&vmbus_connection.channel_lock, flags); 330 - list_del(&newchannel->listentry); 331 - spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); 373 + newchannel->offermsg.child_relid); 332 374 kfree(newchannel->device_obj); 333 - goto err_free_chan; 375 + goto err_deq_chan; 334 376 } 335 - done_init_rescind: 336 - spin_lock_irqsave(&newchannel->lock, flags); 337 - /* The next possible work is rescind handling */ 338 - INIT_WORK(&newchannel->work, vmbus_process_rescind_offer); 339 - /* Check if rescind offer was already received */ 340 - if (newchannel->rescind) 341 - queue_work(newchannel->controlwq, &newchannel->work); 342 - spin_unlock_irqrestore(&newchannel->lock, flags); 343 377 return; 378 + 379 + err_deq_chan: 380 + spin_lock_irqsave(&vmbus_connection.channel_lock, flags); 381 + list_del(&newchannel->listentry); 382 + spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); 383 + 384 + if (newchannel->target_cpu != get_cpu()) { 385 + put_cpu(); 386 + smp_call_function_single(newchannel->target_cpu, 387 + percpu_channel_deq, newchannel, true); 388 + } else { 389 + percpu_channel_deq(newchannel); 390 + put_cpu(); 391 + } 392 + 344 393 err_free_chan: 345 394 free_channel(newchannel); 346 395 } ··· 366 411 { HV_SCSI_GUID, }, 367 412 /* Network */ 368 413 { HV_NIC_GUID, }, 414 + /* NetworkDirect Guest RDMA */ 415 + { HV_ND_GUID, }, 369 416 }; 370 417 371 418 ··· 468 511 newchannel->monitor_grp = (u8)offer->monitorid / 32; 469 512 newchannel->monitor_bit = (u8)offer->monitorid % 32; 470 513 471 - INIT_WORK(&newchannel->work, vmbus_process_offer); 472 - queue_work(newchannel->controlwq, &newchannel->work); 514 + vmbus_process_offer(newchannel); 473 515 } 474 516 475 517 /* ··· 481 525 struct vmbus_channel_rescind_offer *rescind; 482 526 struct vmbus_channel *channel; 483 527 unsigned long flags; 528 + struct device *dev; 484 529 485 530 rescind = (struct vmbus_channel_rescind_offer *)hdr; 486 531 channel = relid2channel(rescind->child_relid); 487 532 488 - if (channel == NULL) 489 - /* Just return here, no channel found */ 533 + if (channel == NULL) { 534 + hv_process_channel_removal(NULL, rescind->child_relid); 490 535 return; 536 + } 491 537 492 538 spin_lock_irqsave(&channel->lock, flags); 493 539 channel->rescind = true; 494 - /* 495 - * channel->work.func != vmbus_process_rescind_offer means we are still 496 - * processing offer request and the rescind offer processing should be 497 - * postponed. It will be done at the very end of vmbus_process_offer() 498 - * as rescind flag is being checked there. 499 - */ 500 - if (channel->work.func == vmbus_process_rescind_offer) 501 - /* work is initialized for vmbus_process_rescind_offer() from 502 - * vmbus_process_offer() where the channel got created */ 503 - queue_work(channel->controlwq, &channel->work); 504 - 505 540 spin_unlock_irqrestore(&channel->lock, flags); 541 + 542 + if (channel->device_obj) { 543 + /* 544 + * We will have to unregister this device from the 545 + * driver core. 546 + */ 547 + dev = get_device(&channel->device_obj->device); 548 + if (dev) { 549 + vmbus_device_unregister(channel->device_obj); 550 + put_device(dev); 551 + } 552 + } else { 553 + hv_process_channel_removal(channel, 554 + channel->offermsg.child_relid); 555 + } 506 556 } 507 557 508 558 /* ··· 693 731 } 694 732 695 733 /* Channel message dispatch table */ 696 - static struct vmbus_channel_message_table_entry 734 + struct vmbus_channel_message_table_entry 697 735 channel_message_table[CHANNELMSG_COUNT] = { 698 - {CHANNELMSG_INVALID, NULL}, 699 - {CHANNELMSG_OFFERCHANNEL, vmbus_onoffer}, 700 - {CHANNELMSG_RESCIND_CHANNELOFFER, vmbus_onoffer_rescind}, 701 - {CHANNELMSG_REQUESTOFFERS, NULL}, 702 - {CHANNELMSG_ALLOFFERS_DELIVERED, vmbus_onoffers_delivered}, 703 - {CHANNELMSG_OPENCHANNEL, NULL}, 704 - {CHANNELMSG_OPENCHANNEL_RESULT, vmbus_onopen_result}, 705 - {CHANNELMSG_CLOSECHANNEL, NULL}, 706 - {CHANNELMSG_GPADL_HEADER, NULL}, 707 - {CHANNELMSG_GPADL_BODY, NULL}, 708 - {CHANNELMSG_GPADL_CREATED, vmbus_ongpadl_created}, 709 - {CHANNELMSG_GPADL_TEARDOWN, NULL}, 710 - {CHANNELMSG_GPADL_TORNDOWN, vmbus_ongpadl_torndown}, 711 - {CHANNELMSG_RELID_RELEASED, NULL}, 712 - {CHANNELMSG_INITIATE_CONTACT, NULL}, 713 - {CHANNELMSG_VERSION_RESPONSE, vmbus_onversion_response}, 714 - {CHANNELMSG_UNLOAD, NULL}, 736 + {CHANNELMSG_INVALID, 0, NULL}, 737 + {CHANNELMSG_OFFERCHANNEL, 0, vmbus_onoffer}, 738 + {CHANNELMSG_RESCIND_CHANNELOFFER, 0, vmbus_onoffer_rescind}, 739 + {CHANNELMSG_REQUESTOFFERS, 0, NULL}, 740 + {CHANNELMSG_ALLOFFERS_DELIVERED, 1, vmbus_onoffers_delivered}, 741 + {CHANNELMSG_OPENCHANNEL, 0, NULL}, 742 + {CHANNELMSG_OPENCHANNEL_RESULT, 1, vmbus_onopen_result}, 743 + {CHANNELMSG_CLOSECHANNEL, 0, NULL}, 744 + {CHANNELMSG_GPADL_HEADER, 0, NULL}, 745 + {CHANNELMSG_GPADL_BODY, 0, NULL}, 746 + {CHANNELMSG_GPADL_CREATED, 1, vmbus_ongpadl_created}, 747 + {CHANNELMSG_GPADL_TEARDOWN, 0, NULL}, 748 + {CHANNELMSG_GPADL_TORNDOWN, 1, vmbus_ongpadl_torndown}, 749 + {CHANNELMSG_RELID_RELEASED, 0, NULL}, 750 + {CHANNELMSG_INITIATE_CONTACT, 0, NULL}, 751 + {CHANNELMSG_VERSION_RESPONSE, 1, vmbus_onversion_response}, 752 + {CHANNELMSG_UNLOAD, 0, NULL}, 715 753 }; 716 754 717 755 /* ··· 749 787 { 750 788 struct vmbus_channel_message_header *msg; 751 789 struct vmbus_channel_msginfo *msginfo; 752 - int ret, t; 790 + int ret; 753 791 754 792 msginfo = kmalloc(sizeof(*msginfo) + 755 793 sizeof(struct vmbus_channel_message_header), 756 794 GFP_KERNEL); 757 795 if (!msginfo) 758 796 return -ENOMEM; 759 - 760 - init_completion(&msginfo->waitevent); 761 797 762 798 msg = (struct vmbus_channel_message_header *)msginfo->msg; 763 799 ··· 770 810 goto cleanup; 771 811 } 772 812 773 - t = wait_for_completion_timeout(&msginfo->waitevent, 5*HZ); 774 - if (t == 0) { 775 - ret = -ETIMEDOUT; 776 - goto cleanup; 777 - } 778 - 779 - 780 - 781 813 cleanup: 782 814 kfree(msginfo); 783 815 ··· 778 826 779 827 /* 780 828 * Retrieve the (sub) channel on which to send an outgoing request. 781 - * When a primary channel has multiple sub-channels, we choose a 782 - * channel whose VCPU binding is closest to the VCPU on which 783 - * this call is being made. 829 + * When a primary channel has multiple sub-channels, we try to 830 + * distribute the load equally amongst all available channels. 784 831 */ 785 832 struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary) 786 833 { ··· 787 836 int cur_cpu; 788 837 struct vmbus_channel *cur_channel; 789 838 struct vmbus_channel *outgoing_channel = primary; 790 - int cpu_distance, new_cpu_distance; 839 + int next_channel; 840 + int i = 1; 791 841 792 842 if (list_empty(&primary->sc_list)) 793 843 return outgoing_channel; 844 + 845 + next_channel = primary->next_oc++; 846 + 847 + if (next_channel > (primary->num_sc)) { 848 + primary->next_oc = 0; 849 + return outgoing_channel; 850 + } 794 851 795 852 cur_cpu = hv_context.vp_index[get_cpu()]; 796 853 put_cpu(); ··· 810 851 if (cur_channel->target_vp == cur_cpu) 811 852 return cur_channel; 812 853 813 - cpu_distance = ((outgoing_channel->target_vp > cur_cpu) ? 814 - (outgoing_channel->target_vp - cur_cpu) : 815 - (cur_cpu - outgoing_channel->target_vp)); 854 + if (i == next_channel) 855 + return cur_channel; 816 856 817 - new_cpu_distance = ((cur_channel->target_vp > cur_cpu) ? 818 - (cur_channel->target_vp - cur_cpu) : 819 - (cur_cpu - cur_channel->target_vp)); 820 - 821 - if (cpu_distance < new_cpu_distance) 822 - continue; 823 - 824 - outgoing_channel = cur_channel; 857 + i++; 825 858 } 826 859 827 860 return outgoing_channel;
+27 -15
drivers/hv/connection.c
··· 216 216 217 217 cleanup: 218 218 pr_err("Unable to connect to host\n"); 219 - vmbus_connection.conn_state = DISCONNECTED; 220 219 221 - if (vmbus_connection.work_queue) 220 + vmbus_connection.conn_state = DISCONNECTED; 221 + vmbus_disconnect(); 222 + 223 + kfree(msginfo); 224 + 225 + return ret; 226 + } 227 + 228 + void vmbus_disconnect(void) 229 + { 230 + if (vmbus_connection.work_queue) { 231 + drain_workqueue(vmbus_connection.work_queue); 222 232 destroy_workqueue(vmbus_connection.work_queue); 233 + } 223 234 224 235 if (vmbus_connection.int_page) { 225 236 free_pages((unsigned long)vmbus_connection.int_page, 0); ··· 241 230 free_pages((unsigned long)vmbus_connection.monitor_pages[1], 0); 242 231 vmbus_connection.monitor_pages[0] = NULL; 243 232 vmbus_connection.monitor_pages[1] = NULL; 244 - 245 - kfree(msginfo); 246 - 247 - return ret; 248 233 } 249 234 250 235 /* ··· 318 311 */ 319 312 channel = pcpu_relid2channel(relid); 320 313 321 - if (!channel) { 322 - pr_err("channel not found for relid - %u\n", relid); 314 + if (!channel) 323 315 return; 324 - } 325 316 326 317 /* 327 318 * A channel once created is persistent even when there ··· 354 349 else 355 350 bytes_to_read = 0; 356 351 } while (read_state && (bytes_to_read != 0)); 357 - } else { 358 - pr_err("no channel callback for relid - %u\n", relid); 359 352 } 360 - 361 353 } 362 354 363 355 /* ··· 422 420 union hv_connection_id conn_id; 423 421 int ret = 0; 424 422 int retries = 0; 423 + u32 msec = 1; 425 424 426 425 conn_id.asu32 = 0; 427 426 conn_id.u.id = VMBUS_MESSAGE_CONNECTION_ID; ··· 432 429 * insufficient resources. Retry the operation a couple of 433 430 * times before giving up. 434 431 */ 435 - while (retries < 10) { 432 + while (retries < 20) { 436 433 ret = hv_post_message(conn_id, 1, buffer, buflen); 437 434 438 435 switch (ret) { 436 + case HV_STATUS_INVALID_CONNECTION_ID: 437 + /* 438 + * We could get this if we send messages too 439 + * frequently. 440 + */ 441 + ret = -EAGAIN; 442 + break; 443 + case HV_STATUS_INSUFFICIENT_MEMORY: 439 444 case HV_STATUS_INSUFFICIENT_BUFFERS: 440 445 ret = -ENOMEM; 441 - case -ENOMEM: 442 446 break; 443 447 case HV_STATUS_SUCCESS: 444 448 return ret; ··· 455 445 } 456 446 457 447 retries++; 458 - msleep(100); 448 + msleep(msec); 449 + if (msec < 2048) 450 + msec *= 2; 459 451 } 460 452 return ret; 461 453 }
+31 -3
drivers/hv/hv.c
··· 312 312 dev->features = CLOCK_EVT_FEAT_ONESHOT; 313 313 dev->cpumask = cpumask_of(cpu); 314 314 dev->rating = 1000; 315 - dev->owner = THIS_MODULE; 315 + /* 316 + * Avoid settint dev->owner = THIS_MODULE deliberately as doing so will 317 + * result in clockevents_config_and_register() taking additional 318 + * references to the hv_vmbus module making it impossible to unload. 319 + */ 316 320 317 321 dev->set_mode = hv_ce_setmode; 318 322 dev->set_next_event = hv_ce_set_next_event; ··· 474 470 } 475 471 476 472 /* 473 + * hv_synic_clockevents_cleanup - Cleanup clockevent devices 474 + */ 475 + void hv_synic_clockevents_cleanup(void) 476 + { 477 + int cpu; 478 + 479 + if (!(ms_hyperv.features & HV_X64_MSR_SYNTIMER_AVAILABLE)) 480 + return; 481 + 482 + for_each_online_cpu(cpu) 483 + clockevents_unbind_device(hv_context.clk_evt[cpu], cpu); 484 + } 485 + 486 + /* 477 487 * hv_synic_cleanup - Cleanup routine for hv_synic_init(). 478 488 */ 479 489 void hv_synic_cleanup(void *arg) ··· 495 477 union hv_synic_sint shared_sint; 496 478 union hv_synic_simp simp; 497 479 union hv_synic_siefp siefp; 480 + union hv_synic_scontrol sctrl; 498 481 int cpu = smp_processor_id(); 499 482 500 483 if (!hv_context.synic_initialized) 501 484 return; 485 + 486 + /* Turn off clockevent device */ 487 + if (ms_hyperv.features & HV_X64_MSR_SYNTIMER_AVAILABLE) 488 + hv_ce_setmode(CLOCK_EVT_MODE_SHUTDOWN, 489 + hv_context.clk_evt[cpu]); 502 490 503 491 rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64); 504 492 ··· 526 502 527 503 wrmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64); 528 504 529 - free_page((unsigned long)hv_context.synic_message_page[cpu]); 530 - free_page((unsigned long)hv_context.synic_event_page[cpu]); 505 + /* Disable the global synic bit */ 506 + rdmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64); 507 + sctrl.enable = 0; 508 + wrmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64); 509 + 510 + hv_synic_free_cpu(cpu); 531 511 }
+73 -70
drivers/hv/hv_balloon.c
··· 428 428 * currently hot added. We hot add in multiples of 128M 429 429 * chunks; it is possible that we may not be able to bring 430 430 * online all the pages in the region. The range 431 - * covered_start_pfn : covered_end_pfn defines the pages that can 431 + * covered_end_pfn defines the pages that can 432 432 * be brough online. 433 433 */ 434 434 435 435 struct hv_hotadd_state { 436 436 struct list_head list; 437 437 unsigned long start_pfn; 438 - unsigned long covered_start_pfn; 439 438 unsigned long covered_end_pfn; 440 439 unsigned long ha_end_pfn; 441 440 unsigned long end_pfn; ··· 502 503 * Number of pages we have currently ballooned out. 503 504 */ 504 505 unsigned int num_pages_ballooned; 506 + unsigned int num_pages_onlined; 507 + unsigned int num_pages_added; 505 508 506 509 /* 507 510 * State to manage the ballooning (up) operation. ··· 535 534 struct task_struct *thread; 536 535 537 536 struct mutex ha_region_mutex; 538 - struct completion waiter_event; 539 537 540 538 /* 541 539 * A list of hot-add regions. ··· 554 554 static void post_status(struct hv_dynmem_device *dm); 555 555 556 556 #ifdef CONFIG_MEMORY_HOTPLUG 557 - static void acquire_region_mutex(bool trylock) 558 - { 559 - if (trylock) { 560 - reinit_completion(&dm_device.waiter_event); 561 - while (!mutex_trylock(&dm_device.ha_region_mutex)) 562 - wait_for_completion(&dm_device.waiter_event); 563 - } else { 564 - mutex_lock(&dm_device.ha_region_mutex); 565 - } 566 - } 567 - 568 - static void release_region_mutex(bool trylock) 569 - { 570 - if (trylock) { 571 - mutex_unlock(&dm_device.ha_region_mutex); 572 - } else { 573 - mutex_unlock(&dm_device.ha_region_mutex); 574 - complete(&dm_device.waiter_event); 575 - } 576 - } 577 - 578 557 static int hv_memory_notifier(struct notifier_block *nb, unsigned long val, 579 558 void *v) 580 559 { 560 + struct memory_notify *mem = (struct memory_notify *)v; 561 + 581 562 switch (val) { 582 563 case MEM_GOING_ONLINE: 583 - acquire_region_mutex(true); 564 + mutex_lock(&dm_device.ha_region_mutex); 584 565 break; 585 566 586 567 case MEM_ONLINE: 568 + dm_device.num_pages_onlined += mem->nr_pages; 587 569 case MEM_CANCEL_ONLINE: 588 - release_region_mutex(true); 570 + mutex_unlock(&dm_device.ha_region_mutex); 589 571 if (dm_device.ha_waiting) { 590 572 dm_device.ha_waiting = false; 591 573 complete(&dm_device.ol_waitevent); 592 574 } 593 575 break; 594 576 595 - case MEM_GOING_OFFLINE: 596 577 case MEM_OFFLINE: 578 + mutex_lock(&dm_device.ha_region_mutex); 579 + dm_device.num_pages_onlined -= mem->nr_pages; 580 + mutex_unlock(&dm_device.ha_region_mutex); 581 + break; 582 + case MEM_GOING_OFFLINE: 597 583 case MEM_CANCEL_OFFLINE: 598 584 break; 599 585 } ··· 632 646 init_completion(&dm_device.ol_waitevent); 633 647 dm_device.ha_waiting = true; 634 648 635 - release_region_mutex(false); 649 + mutex_unlock(&dm_device.ha_region_mutex); 636 650 nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn)); 637 651 ret = add_memory(nid, PFN_PHYS((start_pfn)), 638 652 (HA_CHUNK << PAGE_SHIFT)); ··· 651 665 } 652 666 has->ha_end_pfn -= HA_CHUNK; 653 667 has->covered_end_pfn -= processed_pfn; 668 + mutex_lock(&dm_device.ha_region_mutex); 654 669 break; 655 670 } 656 671 ··· 662 675 * have not been "onlined" within the allowed time. 663 676 */ 664 677 wait_for_completion_timeout(&dm_device.ol_waitevent, 5*HZ); 665 - acquire_region_mutex(false); 678 + mutex_lock(&dm_device.ha_region_mutex); 666 679 post_status(&dm_device); 667 680 } 668 681 ··· 678 691 679 692 list_for_each(cur, &dm_device.ha_region_list) { 680 693 has = list_entry(cur, struct hv_hotadd_state, list); 681 - cur_start_pgp = (unsigned long) 682 - pfn_to_page(has->covered_start_pfn); 694 + cur_start_pgp = (unsigned long)pfn_to_page(has->start_pfn); 683 695 cur_end_pgp = (unsigned long)pfn_to_page(has->covered_end_pfn); 684 696 685 697 if (((unsigned long)pg >= cur_start_pgp) && ··· 690 704 __online_page_set_limits(pg); 691 705 __online_page_increment_counters(pg); 692 706 __online_page_free(pg); 693 - has->covered_start_pfn++; 694 707 } 695 708 } 696 709 } ··· 733 748 * is, update it. 734 749 */ 735 750 736 - if (has->covered_end_pfn != start_pfn) { 751 + if (has->covered_end_pfn != start_pfn) 737 752 has->covered_end_pfn = start_pfn; 738 - has->covered_start_pfn = start_pfn; 739 - } 753 + 740 754 return true; 741 755 742 756 } ··· 778 794 pgs_ol = has->ha_end_pfn - start_pfn; 779 795 if (pgs_ol > pfn_cnt) 780 796 pgs_ol = pfn_cnt; 781 - hv_bring_pgs_online(start_pfn, pgs_ol); 797 + 798 + /* 799 + * Check if the corresponding memory block is already 800 + * online by checking its last previously backed page. 801 + * In case it is we need to bring rest (which was not 802 + * backed previously) online too. 803 + */ 804 + if (start_pfn > has->start_pfn && 805 + !PageReserved(pfn_to_page(start_pfn - 1))) 806 + hv_bring_pgs_online(start_pfn, pgs_ol); 807 + 782 808 has->covered_end_pfn += pgs_ol; 783 - has->covered_start_pfn += pgs_ol; 784 809 pfn_cnt -= pgs_ol; 785 810 } 786 811 ··· 850 857 list_add_tail(&ha_region->list, &dm_device.ha_region_list); 851 858 ha_region->start_pfn = rg_start; 852 859 ha_region->ha_end_pfn = rg_start; 853 - ha_region->covered_start_pfn = pg_start; 854 860 ha_region->covered_end_pfn = pg_start; 855 861 ha_region->end_pfn = rg_start + rg_size; 856 862 } ··· 878 886 resp.hdr.size = sizeof(struct dm_hot_add_response); 879 887 880 888 #ifdef CONFIG_MEMORY_HOTPLUG 881 - acquire_region_mutex(false); 889 + mutex_lock(&dm_device.ha_region_mutex); 882 890 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page; 883 891 pfn_cnt = dm->ha_wrk.ha_page_range.finfo.page_cnt; 884 892 ··· 910 918 if (do_hot_add) 911 919 resp.page_count = process_hot_add(pg_start, pfn_cnt, 912 920 rg_start, rg_sz); 913 - release_region_mutex(false); 921 + 922 + dm->num_pages_added += resp.page_count; 923 + mutex_unlock(&dm_device.ha_region_mutex); 914 924 #endif 915 925 /* 916 926 * The result field of the response structure has the ··· 976 982 * 128 72 (1/2) 977 983 * 512 168 (1/4) 978 984 * 2048 360 (1/8) 979 - * 8192 768 (1/16) 980 - * 32768 1536 (1/32) 985 + * 8192 744 (1/16) 986 + * 32768 1512 (1/32) 981 987 */ 982 988 if (totalram_pages < MB2PAGES(128)) 983 989 min_pages = MB2PAGES(8) + (totalram_pages >> 1); ··· 986 992 else if (totalram_pages < MB2PAGES(2048)) 987 993 min_pages = MB2PAGES(104) + (totalram_pages >> 3); 988 994 else if (totalram_pages < MB2PAGES(8192)) 989 - min_pages = MB2PAGES(256) + (totalram_pages >> 4); 995 + min_pages = MB2PAGES(232) + (totalram_pages >> 4); 990 996 else 991 - min_pages = MB2PAGES(512) + (totalram_pages >> 5); 997 + min_pages = MB2PAGES(488) + (totalram_pages >> 5); 992 998 #undef MB2PAGES 993 999 return min_pages; 994 1000 } ··· 1025 1031 status.hdr.trans_id = atomic_inc_return(&trans_id); 1026 1032 1027 1033 /* 1028 - * The host expects the guest to report free memory. 1029 - * Further, the host expects the pressure information to 1030 - * include the ballooned out pages. 1031 - * For a given amount of memory that we are managing, we 1032 - * need to compute a floor below which we should not balloon. 1033 - * Compute this and add it to the pressure report. 1034 + * The host expects the guest to report free and committed memory. 1035 + * Furthermore, the host expects the pressure information to include 1036 + * the ballooned out pages. For a given amount of memory that we are 1037 + * managing we need to compute a floor below which we should not 1038 + * balloon. Compute this and add it to the pressure report. 1039 + * We also need to report all offline pages (num_pages_added - 1040 + * num_pages_onlined) as committed to the host, otherwise it can try 1041 + * asking us to balloon them out. 1034 1042 */ 1035 1043 status.num_avail = val.freeram; 1036 1044 status.num_committed = vm_memory_committed() + 1037 - dm->num_pages_ballooned + 1038 - compute_balloon_floor(); 1045 + dm->num_pages_ballooned + 1046 + (dm->num_pages_added > dm->num_pages_onlined ? 1047 + dm->num_pages_added - dm->num_pages_onlined : 0) + 1048 + compute_balloon_floor(); 1039 1049 1040 1050 /* 1041 1051 * If our transaction ID is no longer current, just don't ··· 1081 1083 1082 1084 1083 1085 1084 - static int alloc_balloon_pages(struct hv_dynmem_device *dm, int num_pages, 1085 - struct dm_balloon_response *bl_resp, int alloc_unit, 1086 - bool *alloc_error) 1086 + static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm, 1087 + unsigned int num_pages, 1088 + struct dm_balloon_response *bl_resp, 1089 + int alloc_unit) 1087 1090 { 1088 - int i = 0; 1091 + unsigned int i = 0; 1089 1092 struct page *pg; 1090 1093 1091 1094 if (num_pages < alloc_unit) ··· 1105 1106 __GFP_NOMEMALLOC | __GFP_NOWARN, 1106 1107 get_order(alloc_unit << PAGE_SHIFT)); 1107 1108 1108 - if (!pg) { 1109 - *alloc_error = true; 1109 + if (!pg) 1110 1110 return i * alloc_unit; 1111 - } 1112 - 1113 1111 1114 1112 dm->num_pages_ballooned += alloc_unit; 1115 1113 ··· 1133 1137 1134 1138 static void balloon_up(struct work_struct *dummy) 1135 1139 { 1136 - int num_pages = dm_device.balloon_wrk.num_pages; 1137 - int num_ballooned = 0; 1140 + unsigned int num_pages = dm_device.balloon_wrk.num_pages; 1141 + unsigned int num_ballooned = 0; 1138 1142 struct dm_balloon_response *bl_resp; 1139 1143 int alloc_unit; 1140 1144 int ret; 1141 - bool alloc_error; 1142 1145 bool done = false; 1143 1146 int i; 1147 + struct sysinfo val; 1148 + unsigned long floor; 1144 1149 1145 1150 /* The host balloons pages in 2M granularity. */ 1146 1151 WARN_ON_ONCE(num_pages % PAGES_IN_2M != 0); ··· 1152 1155 */ 1153 1156 alloc_unit = 512; 1154 1157 1158 + si_meminfo(&val); 1159 + floor = compute_balloon_floor(); 1160 + 1161 + /* Refuse to balloon below the floor, keep the 2M granularity. */ 1162 + if (val.freeram < num_pages || val.freeram - num_pages < floor) { 1163 + num_pages = val.freeram > floor ? (val.freeram - floor) : 0; 1164 + num_pages -= num_pages % PAGES_IN_2M; 1165 + } 1166 + 1155 1167 while (!done) { 1156 1168 bl_resp = (struct dm_balloon_response *)send_buffer; 1157 1169 memset(send_buffer, 0, PAGE_SIZE); ··· 1170 1164 1171 1165 1172 1166 num_pages -= num_ballooned; 1173 - alloc_error = false; 1174 1167 num_ballooned = alloc_balloon_pages(&dm_device, num_pages, 1175 - bl_resp, alloc_unit, 1176 - &alloc_error); 1168 + bl_resp, alloc_unit); 1177 1169 1178 1170 if (alloc_unit != 1 && num_ballooned == 0) { 1179 1171 alloc_unit = 1; 1180 1172 continue; 1181 1173 } 1182 1174 1183 - if ((alloc_unit == 1 && alloc_error) || 1184 - (num_ballooned == num_pages)) { 1175 + if (num_ballooned == 0 || num_ballooned == num_pages) { 1185 1176 bl_resp->more_pages = 0; 1186 1177 done = true; 1187 1178 dm_device.state = DM_INITIALIZED; ··· 1417 1414 static int balloon_probe(struct hv_device *dev, 1418 1415 const struct hv_vmbus_device_id *dev_id) 1419 1416 { 1420 - int ret, t; 1417 + int ret; 1418 + unsigned long t; 1421 1419 struct dm_version_request version_req; 1422 1420 struct dm_capabilities cap_msg; 1423 1421 ··· 1443 1439 dm_device.next_version = DYNMEM_PROTOCOL_VERSION_WIN7; 1444 1440 init_completion(&dm_device.host_event); 1445 1441 init_completion(&dm_device.config_event); 1446 - init_completion(&dm_device.waiter_event); 1447 1442 INIT_LIST_HEAD(&dm_device.ha_region_list); 1448 1443 mutex_init(&dm_device.ha_region_mutex); 1449 1444 INIT_WORK(&dm_device.balloon_wrk.wrk, balloon_up);
+7 -6
drivers/hv/hv_util.c
··· 340 340 341 341 set_channel_read_state(dev->channel, false); 342 342 343 - ret = vmbus_open(dev->channel, 4 * PAGE_SIZE, 4 * PAGE_SIZE, NULL, 0, 344 - srv->util_cb, dev->channel); 345 - if (ret) 346 - goto error; 347 - 348 343 hv_set_drvdata(dev, srv); 344 + 349 345 /* 350 346 * Based on the host; initialize the framework and 351 347 * service version numbers we will negotiate. ··· 361 365 hb_srv_version = HB_VERSION; 362 366 } 363 367 368 + ret = vmbus_open(dev->channel, 4 * PAGE_SIZE, 4 * PAGE_SIZE, NULL, 0, 369 + srv->util_cb, dev->channel); 370 + if (ret) 371 + goto error; 372 + 364 373 return 0; 365 374 366 375 error: ··· 380 379 { 381 380 struct hv_util_service *srv = hv_get_drvdata(dev); 382 381 383 - vmbus_close(dev->channel); 384 382 if (srv->util_deinit) 385 383 srv->util_deinit(); 384 + vmbus_close(dev->channel); 386 385 kfree(srv->recv_buffer); 387 386 388 387 return 0;
+31
drivers/hv/hyperv_vmbus.h
··· 49 49 HVCPUID_IMPLEMENTATION_LIMITS = 0x40000005, 50 50 }; 51 51 52 + #define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE 0x400 53 + 54 + #define HV_X64_MSR_CRASH_P0 0x40000100 55 + #define HV_X64_MSR_CRASH_P1 0x40000101 56 + #define HV_X64_MSR_CRASH_P2 0x40000102 57 + #define HV_X64_MSR_CRASH_P3 0x40000103 58 + #define HV_X64_MSR_CRASH_P4 0x40000104 59 + #define HV_X64_MSR_CRASH_CTL 0x40000105 60 + 61 + #define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63) 62 + 52 63 /* Define version of the synthetic interrupt controller. */ 53 64 #define HV_SYNIC_VERSION (1) 54 65 ··· 583 572 584 573 extern void hv_synic_cleanup(void *arg); 585 574 575 + extern void hv_synic_clockevents_cleanup(void); 576 + 586 577 /* 587 578 * Host version information. 588 579 */ ··· 685 672 686 673 extern struct vmbus_connection vmbus_connection; 687 674 675 + enum vmbus_message_handler_type { 676 + /* The related handler can sleep. */ 677 + VMHT_BLOCKING = 0, 678 + 679 + /* The related handler must NOT sleep. */ 680 + VMHT_NON_BLOCKING = 1, 681 + }; 682 + 683 + struct vmbus_channel_message_table_entry { 684 + enum vmbus_channel_message_type message_type; 685 + enum vmbus_message_handler_type handler_type; 686 + void (*message_handler)(struct vmbus_channel_message_header *msg); 687 + }; 688 + 689 + extern struct vmbus_channel_message_table_entry 690 + channel_message_table[CHANNELMSG_COUNT]; 691 + 688 692 /* General vmbus interface */ 689 693 690 694 struct hv_device *vmbus_device_create(const uuid_le *type, ··· 722 692 /* Connection interface */ 723 693 724 694 int vmbus_connect(void); 695 + void vmbus_disconnect(void); 725 696 726 697 int vmbus_post_msg(void *buffer, size_t buflen); 727 698
+122 -14
drivers/hv/vmbus_drv.c
··· 33 33 #include <linux/hyperv.h> 34 34 #include <linux/kernel_stat.h> 35 35 #include <linux/clockchips.h> 36 + #include <linux/cpu.h> 36 37 #include <asm/hyperv.h> 37 38 #include <asm/hypervisor.h> 38 39 #include <asm/mshyperv.h> 40 + #include <linux/notifier.h> 41 + #include <linux/ptrace.h> 39 42 #include "hyperv_vmbus.h" 40 43 41 44 static struct acpi_device *hv_acpi_dev; ··· 46 43 static struct tasklet_struct msg_dpc; 47 44 static struct completion probe_event; 48 45 static int irq; 46 + 47 + 48 + static int hyperv_panic_event(struct notifier_block *nb, 49 + unsigned long event, void *ptr) 50 + { 51 + struct pt_regs *regs; 52 + 53 + regs = current_pt_regs(); 54 + 55 + wrmsrl(HV_X64_MSR_CRASH_P0, regs->ip); 56 + wrmsrl(HV_X64_MSR_CRASH_P1, regs->ax); 57 + wrmsrl(HV_X64_MSR_CRASH_P2, regs->bx); 58 + wrmsrl(HV_X64_MSR_CRASH_P3, regs->cx); 59 + wrmsrl(HV_X64_MSR_CRASH_P4, regs->dx); 60 + 61 + /* 62 + * Let Hyper-V know there is crash data available 63 + */ 64 + wrmsrl(HV_X64_MSR_CRASH_CTL, HV_CRASH_CTL_CRASH_NOTIFY); 65 + return NOTIFY_DONE; 66 + } 67 + 68 + static struct notifier_block hyperv_panic_block = { 69 + .notifier_call = hyperv_panic_event, 70 + }; 49 71 50 72 struct resource hyperv_mmio = { 51 73 .name = "hyperv mmio", ··· 535 507 */ 536 508 static int vmbus_remove(struct device *child_device) 537 509 { 538 - struct hv_driver *drv = drv_to_hv_drv(child_device->driver); 510 + struct hv_driver *drv; 539 511 struct hv_device *dev = device_to_hv_device(child_device); 512 + u32 relid = dev->channel->offermsg.child_relid; 540 513 541 - if (drv->remove) 542 - drv->remove(dev); 543 - else 544 - pr_err("remove not set for driver %s\n", 545 - dev_name(child_device)); 514 + if (child_device->driver) { 515 + drv = drv_to_hv_drv(child_device->driver); 516 + if (drv->remove) 517 + drv->remove(dev); 518 + else { 519 + hv_process_channel_removal(dev->channel, relid); 520 + pr_err("remove not set for driver %s\n", 521 + dev_name(child_device)); 522 + } 523 + } else { 524 + /* 525 + * We don't have a driver for this device; deal with the 526 + * rescind message by removing the channel. 527 + */ 528 + hv_process_channel_removal(dev->channel, relid); 529 + } 546 530 547 531 return 0; 548 532 } ··· 613 573 { 614 574 struct onmessage_work_context *ctx; 615 575 576 + /* Do not process messages if we're in DISCONNECTED state */ 577 + if (vmbus_connection.conn_state == DISCONNECTED) 578 + return; 579 + 616 580 ctx = container_of(work, struct onmessage_work_context, 617 581 work); 618 582 vmbus_onmessage(&ctx->msg); ··· 657 613 void *page_addr = hv_context.synic_message_page[cpu]; 658 614 struct hv_message *msg = (struct hv_message *)page_addr + 659 615 VMBUS_MESSAGE_SINT; 616 + struct vmbus_channel_message_header *hdr; 617 + struct vmbus_channel_message_table_entry *entry; 660 618 struct onmessage_work_context *ctx; 661 619 662 620 while (1) { 663 - if (msg->header.message_type == HVMSG_NONE) { 621 + if (msg->header.message_type == HVMSG_NONE) 664 622 /* no msg */ 665 623 break; 666 - } else { 624 + 625 + hdr = (struct vmbus_channel_message_header *)msg->u.payload; 626 + 627 + if (hdr->msgtype >= CHANNELMSG_COUNT) { 628 + WARN_ONCE(1, "unknown msgtype=%d\n", hdr->msgtype); 629 + goto msg_handled; 630 + } 631 + 632 + entry = &channel_message_table[hdr->msgtype]; 633 + if (entry->handler_type == VMHT_BLOCKING) { 667 634 ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC); 668 635 if (ctx == NULL) 669 636 continue; 637 + 670 638 INIT_WORK(&ctx->work, vmbus_onmessage_work); 671 639 memcpy(&ctx->msg, msg, sizeof(*msg)); 672 - queue_work(vmbus_connection.work_queue, &ctx->work); 673 - } 674 640 641 + queue_work(vmbus_connection.work_queue, &ctx->work); 642 + } else 643 + entry->message_handler(hdr); 644 + 645 + msg_handled: 675 646 msg->header.message_type = HVMSG_NONE; 676 647 677 648 /* ··· 763 704 } 764 705 } 765 706 707 + #ifdef CONFIG_HOTPLUG_CPU 708 + static int hyperv_cpu_disable(void) 709 + { 710 + return -ENOSYS; 711 + } 712 + 713 + static void hv_cpu_hotplug_quirk(bool vmbus_loaded) 714 + { 715 + static void *previous_cpu_disable; 716 + 717 + /* 718 + * Offlining a CPU when running on newer hypervisors (WS2012R2, Win8, 719 + * ...) is not supported at this moment as channel interrupts are 720 + * distributed across all of them. 721 + */ 722 + 723 + if ((vmbus_proto_version == VERSION_WS2008) || 724 + (vmbus_proto_version == VERSION_WIN7)) 725 + return; 726 + 727 + if (vmbus_loaded) { 728 + previous_cpu_disable = smp_ops.cpu_disable; 729 + smp_ops.cpu_disable = hyperv_cpu_disable; 730 + pr_notice("CPU offlining is not supported by hypervisor\n"); 731 + } else if (previous_cpu_disable) 732 + smp_ops.cpu_disable = previous_cpu_disable; 733 + } 734 + #else 735 + static void hv_cpu_hotplug_quirk(bool vmbus_loaded) 736 + { 737 + } 738 + #endif 739 + 766 740 /* 767 741 * vmbus_bus_init -Main vmbus driver initialization routine. 768 742 * ··· 835 743 ret = vmbus_connect(); 836 744 if (ret) 837 745 goto err_alloc; 746 + 747 + hv_cpu_hotplug_quirk(true); 748 + 749 + /* 750 + * Only register if the crash MSRs are available 751 + */ 752 + if (ms_hyperv.features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) { 753 + atomic_notifier_chain_register(&panic_notifier_list, 754 + &hyperv_panic_block); 755 + } 838 756 839 757 vmbus_request_offers(); 840 758 ··· 942 840 { 943 841 int ret = 0; 944 842 945 - static atomic_t device_num = ATOMIC_INIT(0); 946 - 947 - dev_set_name(&child_device_obj->device, "vmbus_0_%d", 948 - atomic_inc_return(&device_num)); 843 + dev_set_name(&child_device_obj->device, "vmbus_%d", 844 + child_device_obj->channel->id); 949 845 950 846 child_device_obj->device.bus = &hv_bus; 951 847 child_device_obj->device.parent = &hv_acpi_dev->dev; ··· 1092 992 1093 993 static void __exit vmbus_exit(void) 1094 994 { 995 + int cpu; 996 + 997 + vmbus_connection.conn_state = DISCONNECTED; 998 + hv_synic_clockevents_cleanup(); 1095 999 hv_remove_vmbus_irq(); 1096 1000 vmbus_free_channels(); 1097 1001 bus_unregister(&hv_bus); 1098 1002 hv_cleanup(); 1003 + for_each_online_cpu(cpu) 1004 + smp_call_function_single(cpu, hv_synic_cleanup, NULL, 1); 1099 1005 acpi_bus_unregister_driver(&vmbus_acpi_driver); 1006 + hv_cpu_hotplug_quirk(false); 1007 + vmbus_disconnect(); 1100 1008 } 1101 1009 1102 1010
+61
drivers/hwtracing/coresight/Kconfig
··· 1 + # 2 + # Coresight configuration 3 + # 4 + menuconfig CORESIGHT 5 + bool "CoreSight Tracing Support" 6 + select ARM_AMBA 7 + help 8 + This framework provides a kernel interface for the CoreSight debug 9 + and trace drivers to register themselves with. It's intended to build 10 + a topological view of the CoreSight components based on a DT 11 + specification and configure the right serie of components when a 12 + trace source gets enabled. 13 + 14 + if CORESIGHT 15 + config CORESIGHT_LINKS_AND_SINKS 16 + bool "CoreSight Link and Sink drivers" 17 + help 18 + This enables support for CoreSight link and sink drivers that are 19 + responsible for transporting and collecting the trace data 20 + respectively. Link and sinks are dynamically aggregated with a trace 21 + entity at run time to form a complete trace path. 22 + 23 + config CORESIGHT_LINK_AND_SINK_TMC 24 + bool "Coresight generic TMC driver" 25 + depends on CORESIGHT_LINKS_AND_SINKS 26 + help 27 + This enables support for the Trace Memory Controller driver. 28 + Depending on its configuration the device can act as a link (embedded 29 + trace router - ETR) or sink (embedded trace FIFO). The driver 30 + complies with the generic implementation of the component without 31 + special enhancement or added features. 32 + 33 + config CORESIGHT_SINK_TPIU 34 + bool "Coresight generic TPIU driver" 35 + depends on CORESIGHT_LINKS_AND_SINKS 36 + help 37 + This enables support for the Trace Port Interface Unit driver, 38 + responsible for bridging the gap between the on-chip coresight 39 + components and a trace for bridging the gap between the on-chip 40 + coresight components and a trace port collection engine, typically 41 + connected to an external host for use case capturing more traces than 42 + the on-board coresight memory can handle. 43 + 44 + config CORESIGHT_SINK_ETBV10 45 + bool "Coresight ETBv1.0 driver" 46 + depends on CORESIGHT_LINKS_AND_SINKS 47 + help 48 + This enables support for the Embedded Trace Buffer version 1.0 driver 49 + that complies with the generic implementation of the component without 50 + special enhancement or added features. 51 + 52 + config CORESIGHT_SOURCE_ETM3X 53 + bool "CoreSight Embedded Trace Macrocell 3.x driver" 54 + depends on !ARM64 55 + select CORESIGHT_LINKS_AND_SINKS 56 + help 57 + This driver provides support for processor ETM3.x and PTM1.x modules, 58 + which allows tracing the instructions that a processor is executing 59 + This is primarily useful for instruction level tracing. Depending 60 + the ETM version data tracing may also be available. 61 + endif
+2 -2
drivers/mcb/mcb-pci.c
··· 56 56 57 57 res = request_mem_region(priv->mapbase, CHAM_HEADER_SIZE, 58 58 KBUILD_MODNAME); 59 - if (IS_ERR(res)) { 59 + if (!res) { 60 60 dev_err(&pdev->dev, "Failed to request PCI memory\n"); 61 - ret = PTR_ERR(res); 61 + ret = -EBUSY; 62 62 goto out_disable; 63 63 } 64 64
+9
drivers/memory/Kconfig
··· 83 83 bool 84 84 depends on FSL_SOC 85 85 86 + config JZ4780_NEMC 87 + bool "Ingenic JZ4780 SoC NEMC driver" 88 + default y 89 + depends on MACH_JZ4780 90 + help 91 + This driver is for the NAND/External Memory Controller (NEMC) in 92 + the Ingenic JZ4780. This controller is used to handle external 93 + memory devices such as NAND and SRAM. 94 + 86 95 source "drivers/memory/tegra/Kconfig" 87 96 88 97 endif
+1
drivers/memory/Makefile
··· 13 13 obj-$(CONFIG_FSL_IFC) += fsl_ifc.o 14 14 obj-$(CONFIG_MVEBU_DEVBUS) += mvebu-devbus.o 15 15 obj-$(CONFIG_TEGRA20_MC) += tegra20-mc.o 16 + obj-$(CONFIG_JZ4780_NEMC) += jz4780-nemc.o 16 17 17 18 obj-$(CONFIG_TEGRA_MC) += tegra/
+391
drivers/memory/jz4780-nemc.c
··· 1 + /* 2 + * JZ4780 NAND/external memory controller (NEMC) 3 + * 4 + * Copyright (c) 2015 Imagination Technologies 5 + * Author: Alex Smith <alex@alex-smith.me.uk> 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms of the GNU General Public License version 2 as published 9 + * by the Free Software Foundation. 10 + */ 11 + 12 + #include <linux/clk.h> 13 + #include <linux/init.h> 14 + #include <linux/math64.h> 15 + #include <linux/of.h> 16 + #include <linux/of_address.h> 17 + #include <linux/of_device.h> 18 + #include <linux/of_platform.h> 19 + #include <linux/platform_device.h> 20 + #include <linux/slab.h> 21 + #include <linux/spinlock.h> 22 + 23 + #include <linux/jz4780-nemc.h> 24 + 25 + #define NEMC_SMCRn(n) (0x14 + (((n) - 1) * 4)) 26 + #define NEMC_NFCSR 0x50 27 + 28 + #define NEMC_SMCR_SMT BIT(0) 29 + #define NEMC_SMCR_BW_SHIFT 6 30 + #define NEMC_SMCR_BW_MASK (0x3 << NEMC_SMCR_BW_SHIFT) 31 + #define NEMC_SMCR_BW_8 (0 << 6) 32 + #define NEMC_SMCR_TAS_SHIFT 8 33 + #define NEMC_SMCR_TAS_MASK (0xf << NEMC_SMCR_TAS_SHIFT) 34 + #define NEMC_SMCR_TAH_SHIFT 12 35 + #define NEMC_SMCR_TAH_MASK (0xf << NEMC_SMCR_TAH_SHIFT) 36 + #define NEMC_SMCR_TBP_SHIFT 16 37 + #define NEMC_SMCR_TBP_MASK (0xf << NEMC_SMCR_TBP_SHIFT) 38 + #define NEMC_SMCR_TAW_SHIFT 20 39 + #define NEMC_SMCR_TAW_MASK (0xf << NEMC_SMCR_TAW_SHIFT) 40 + #define NEMC_SMCR_TSTRV_SHIFT 24 41 + #define NEMC_SMCR_TSTRV_MASK (0x3f << NEMC_SMCR_TSTRV_SHIFT) 42 + 43 + #define NEMC_NFCSR_NFEn(n) BIT(((n) - 1) << 1) 44 + #define NEMC_NFCSR_NFCEn(n) BIT((((n) - 1) << 1) + 1) 45 + #define NEMC_NFCSR_TNFEn(n) BIT(16 + (n) - 1) 46 + 47 + struct jz4780_nemc { 48 + spinlock_t lock; 49 + struct device *dev; 50 + void __iomem *base; 51 + struct clk *clk; 52 + uint32_t clk_period; 53 + unsigned long banks_present; 54 + }; 55 + 56 + /** 57 + * jz4780_nemc_num_banks() - count the number of banks referenced by a device 58 + * @dev: device to count banks for, must be a child of the NEMC. 59 + * 60 + * Return: The number of unique NEMC banks referred to by the specified NEMC 61 + * child device. Unique here means that a device that references the same bank 62 + * multiple times in the its "reg" property will only count once. 63 + */ 64 + unsigned int jz4780_nemc_num_banks(struct device *dev) 65 + { 66 + const __be32 *prop; 67 + unsigned int bank, count = 0; 68 + unsigned long referenced = 0; 69 + int i = 0; 70 + 71 + while ((prop = of_get_address(dev->of_node, i++, NULL, NULL))) { 72 + bank = of_read_number(prop, 1); 73 + if (!(referenced & BIT(bank))) { 74 + referenced |= BIT(bank); 75 + count++; 76 + } 77 + } 78 + 79 + return count; 80 + } 81 + EXPORT_SYMBOL(jz4780_nemc_num_banks); 82 + 83 + /** 84 + * jz4780_nemc_set_type() - set the type of device connected to a bank 85 + * @dev: child device of the NEMC. 86 + * @bank: bank number to configure. 87 + * @type: type of device connected to the bank. 88 + */ 89 + void jz4780_nemc_set_type(struct device *dev, unsigned int bank, 90 + enum jz4780_nemc_bank_type type) 91 + { 92 + struct jz4780_nemc *nemc = dev_get_drvdata(dev->parent); 93 + uint32_t nfcsr; 94 + 95 + nfcsr = readl(nemc->base + NEMC_NFCSR); 96 + 97 + /* TODO: Support toggle NAND devices. */ 98 + switch (type) { 99 + case JZ4780_NEMC_BANK_SRAM: 100 + nfcsr &= ~(NEMC_NFCSR_TNFEn(bank) | NEMC_NFCSR_NFEn(bank)); 101 + break; 102 + case JZ4780_NEMC_BANK_NAND: 103 + nfcsr &= ~NEMC_NFCSR_TNFEn(bank); 104 + nfcsr |= NEMC_NFCSR_NFEn(bank); 105 + break; 106 + } 107 + 108 + writel(nfcsr, nemc->base + NEMC_NFCSR); 109 + } 110 + EXPORT_SYMBOL(jz4780_nemc_set_type); 111 + 112 + /** 113 + * jz4780_nemc_assert() - (de-)assert a NAND device's chip enable pin 114 + * @dev: child device of the NEMC. 115 + * @bank: bank number of device. 116 + * @assert: whether the chip enable pin should be asserted. 117 + * 118 + * (De-)asserts the chip enable pin for the NAND device connected to the 119 + * specified bank. 120 + */ 121 + void jz4780_nemc_assert(struct device *dev, unsigned int bank, bool assert) 122 + { 123 + struct jz4780_nemc *nemc = dev_get_drvdata(dev->parent); 124 + uint32_t nfcsr; 125 + 126 + nfcsr = readl(nemc->base + NEMC_NFCSR); 127 + 128 + if (assert) 129 + nfcsr |= NEMC_NFCSR_NFCEn(bank); 130 + else 131 + nfcsr &= ~NEMC_NFCSR_NFCEn(bank); 132 + 133 + writel(nfcsr, nemc->base + NEMC_NFCSR); 134 + } 135 + EXPORT_SYMBOL(jz4780_nemc_assert); 136 + 137 + static uint32_t jz4780_nemc_clk_period(struct jz4780_nemc *nemc) 138 + { 139 + unsigned long rate; 140 + 141 + rate = clk_get_rate(nemc->clk); 142 + if (!rate) 143 + return 0; 144 + 145 + /* Return in picoseconds. */ 146 + return div64_ul(1000000000000ull, rate); 147 + } 148 + 149 + static uint32_t jz4780_nemc_ns_to_cycles(struct jz4780_nemc *nemc, uint32_t ns) 150 + { 151 + return ((ns * 1000) + nemc->clk_period - 1) / nemc->clk_period; 152 + } 153 + 154 + static bool jz4780_nemc_configure_bank(struct jz4780_nemc *nemc, 155 + unsigned int bank, 156 + struct device_node *node) 157 + { 158 + uint32_t smcr, val, cycles; 159 + 160 + /* 161 + * Conversion of tBP and tAW cycle counts to values supported by the 162 + * hardware (round up to the next supported value). 163 + */ 164 + static const uint32_t convert_tBP_tAW[] = { 165 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 166 + 167 + /* 11 - 12 -> 12 cycles */ 168 + 11, 11, 169 + 170 + /* 13 - 15 -> 15 cycles */ 171 + 12, 12, 12, 172 + 173 + /* 16 - 20 -> 20 cycles */ 174 + 13, 13, 13, 13, 13, 175 + 176 + /* 21 - 25 -> 25 cycles */ 177 + 14, 14, 14, 14, 14, 178 + 179 + /* 26 - 31 -> 31 cycles */ 180 + 15, 15, 15, 15, 15, 15 181 + }; 182 + 183 + smcr = readl(nemc->base + NEMC_SMCRn(bank)); 184 + smcr &= ~NEMC_SMCR_SMT; 185 + 186 + if (!of_property_read_u32(node, "ingenic,nemc-bus-width", &val)) { 187 + smcr &= ~NEMC_SMCR_BW_MASK; 188 + switch (val) { 189 + case 8: 190 + smcr |= NEMC_SMCR_BW_8; 191 + break; 192 + default: 193 + /* 194 + * Earlier SoCs support a 16 bit bus width (the 4780 195 + * does not), until those are properly supported, error. 196 + */ 197 + dev_err(nemc->dev, "unsupported bus width: %u\n", val); 198 + return false; 199 + } 200 + } 201 + 202 + if (of_property_read_u32(node, "ingenic,nemc-tAS", &val) == 0) { 203 + smcr &= ~NEMC_SMCR_TAS_MASK; 204 + cycles = jz4780_nemc_ns_to_cycles(nemc, val); 205 + if (cycles > 15) { 206 + dev_err(nemc->dev, "tAS %u is too high (%u cycles)\n", 207 + val, cycles); 208 + return false; 209 + } 210 + 211 + smcr |= cycles << NEMC_SMCR_TAS_SHIFT; 212 + } 213 + 214 + if (of_property_read_u32(node, "ingenic,nemc-tAH", &val) == 0) { 215 + smcr &= ~NEMC_SMCR_TAH_MASK; 216 + cycles = jz4780_nemc_ns_to_cycles(nemc, val); 217 + if (cycles > 15) { 218 + dev_err(nemc->dev, "tAH %u is too high (%u cycles)\n", 219 + val, cycles); 220 + return false; 221 + } 222 + 223 + smcr |= cycles << NEMC_SMCR_TAH_SHIFT; 224 + } 225 + 226 + if (of_property_read_u32(node, "ingenic,nemc-tBP", &val) == 0) { 227 + smcr &= ~NEMC_SMCR_TBP_MASK; 228 + cycles = jz4780_nemc_ns_to_cycles(nemc, val); 229 + if (cycles > 31) { 230 + dev_err(nemc->dev, "tBP %u is too high (%u cycles)\n", 231 + val, cycles); 232 + return false; 233 + } 234 + 235 + smcr |= convert_tBP_tAW[cycles] << NEMC_SMCR_TBP_SHIFT; 236 + } 237 + 238 + if (of_property_read_u32(node, "ingenic,nemc-tAW", &val) == 0) { 239 + smcr &= ~NEMC_SMCR_TAW_MASK; 240 + cycles = jz4780_nemc_ns_to_cycles(nemc, val); 241 + if (cycles > 31) { 242 + dev_err(nemc->dev, "tAW %u is too high (%u cycles)\n", 243 + val, cycles); 244 + return false; 245 + } 246 + 247 + smcr |= convert_tBP_tAW[cycles] << NEMC_SMCR_TAW_SHIFT; 248 + } 249 + 250 + if (of_property_read_u32(node, "ingenic,nemc-tSTRV", &val) == 0) { 251 + smcr &= ~NEMC_SMCR_TSTRV_MASK; 252 + cycles = jz4780_nemc_ns_to_cycles(nemc, val); 253 + if (cycles > 63) { 254 + dev_err(nemc->dev, "tSTRV %u is too high (%u cycles)\n", 255 + val, cycles); 256 + return false; 257 + } 258 + 259 + smcr |= cycles << NEMC_SMCR_TSTRV_SHIFT; 260 + } 261 + 262 + writel(smcr, nemc->base + NEMC_SMCRn(bank)); 263 + return true; 264 + } 265 + 266 + static int jz4780_nemc_probe(struct platform_device *pdev) 267 + { 268 + struct device *dev = &pdev->dev; 269 + struct jz4780_nemc *nemc; 270 + struct resource *res; 271 + struct device_node *child; 272 + const __be32 *prop; 273 + unsigned int bank; 274 + unsigned long referenced; 275 + int i, ret; 276 + 277 + nemc = devm_kzalloc(dev, sizeof(*nemc), GFP_KERNEL); 278 + if (!nemc) 279 + return -ENOMEM; 280 + 281 + spin_lock_init(&nemc->lock); 282 + nemc->dev = dev; 283 + 284 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 285 + nemc->base = devm_ioremap_resource(dev, res); 286 + if (IS_ERR(nemc->base)) { 287 + dev_err(dev, "failed to get I/O memory\n"); 288 + return PTR_ERR(nemc->base); 289 + } 290 + 291 + writel(0, nemc->base + NEMC_NFCSR); 292 + 293 + nemc->clk = devm_clk_get(dev, NULL); 294 + if (IS_ERR(nemc->clk)) { 295 + dev_err(dev, "failed to get clock\n"); 296 + return PTR_ERR(nemc->clk); 297 + } 298 + 299 + ret = clk_prepare_enable(nemc->clk); 300 + if (ret) { 301 + dev_err(dev, "failed to enable clock: %d\n", ret); 302 + return ret; 303 + } 304 + 305 + nemc->clk_period = jz4780_nemc_clk_period(nemc); 306 + if (!nemc->clk_period) { 307 + dev_err(dev, "failed to calculate clock period\n"); 308 + clk_disable_unprepare(nemc->clk); 309 + return -EINVAL; 310 + } 311 + 312 + /* 313 + * Iterate over child devices, check that they do not conflict with 314 + * each other, and register child devices for them. If a child device 315 + * has invalid properties, it is ignored and no platform device is 316 + * registered for it. 317 + */ 318 + for_each_child_of_node(nemc->dev->of_node, child) { 319 + referenced = 0; 320 + i = 0; 321 + while ((prop = of_get_address(child, i++, NULL, NULL))) { 322 + bank = of_read_number(prop, 1); 323 + if (bank < 1 || bank >= JZ4780_NEMC_NUM_BANKS) { 324 + dev_err(nemc->dev, 325 + "%s requests invalid bank %u\n", 326 + child->full_name, bank); 327 + 328 + /* Will continue the outer loop below. */ 329 + referenced = 0; 330 + break; 331 + } 332 + 333 + referenced |= BIT(bank); 334 + } 335 + 336 + if (!referenced) { 337 + dev_err(nemc->dev, "%s has no addresses\n", 338 + child->full_name); 339 + continue; 340 + } else if (nemc->banks_present & referenced) { 341 + dev_err(nemc->dev, "%s conflicts with another node\n", 342 + child->full_name); 343 + continue; 344 + } 345 + 346 + /* Configure bank parameters. */ 347 + for_each_set_bit(bank, &referenced, JZ4780_NEMC_NUM_BANKS) { 348 + if (!jz4780_nemc_configure_bank(nemc, bank, child)) { 349 + referenced = 0; 350 + break; 351 + } 352 + } 353 + 354 + if (referenced) { 355 + if (of_platform_device_create(child, NULL, nemc->dev)) 356 + nemc->banks_present |= referenced; 357 + } 358 + } 359 + 360 + platform_set_drvdata(pdev, nemc); 361 + dev_info(dev, "JZ4780 NEMC initialised\n"); 362 + return 0; 363 + } 364 + 365 + static int jz4780_nemc_remove(struct platform_device *pdev) 366 + { 367 + struct jz4780_nemc *nemc = platform_get_drvdata(pdev); 368 + 369 + clk_disable_unprepare(nemc->clk); 370 + return 0; 371 + } 372 + 373 + static const struct of_device_id jz4780_nemc_dt_match[] = { 374 + { .compatible = "ingenic,jz4780-nemc" }, 375 + {}, 376 + }; 377 + 378 + static struct platform_driver jz4780_nemc_driver = { 379 + .probe = jz4780_nemc_probe, 380 + .remove = jz4780_nemc_remove, 381 + .driver = { 382 + .name = "jz4780-nemc", 383 + .of_match_table = of_match_ptr(jz4780_nemc_dt_match), 384 + }, 385 + }; 386 + 387 + static int __init jz4780_nemc_init(void) 388 + { 389 + return platform_driver_register(&jz4780_nemc_driver); 390 + } 391 + subsys_initcall(jz4780_nemc_init);
+2
drivers/misc/bh1780gli.c
··· 230 230 { }, 231 231 }; 232 232 233 + MODULE_DEVICE_TABLE(i2c, bh1780_id); 234 + 233 235 #ifdef CONFIG_OF 234 236 static const struct of_device_id of_bh1780_match[] = { 235 237 { .compatible = "rohm,bh1780gli", },
+7 -5
drivers/misc/carma/carma-fpga-program.c
··· 479 479 static noinline int fpga_program_cpu(struct fpga_dev *priv) 480 480 { 481 481 int ret; 482 + unsigned long timeout; 482 483 483 484 /* Disable the programmer */ 484 485 fpga_programmer_disable(priv); ··· 498 497 goto out_disable_controller; 499 498 500 499 /* Wait for the interrupt handler to signal that programming finished */ 501 - ret = wait_for_completion_timeout(&priv->completion, 2 * HZ); 502 - if (!ret) { 500 + timeout = wait_for_completion_timeout(&priv->completion, 2 * HZ); 501 + if (!timeout) { 503 502 dev_err(priv->dev, "Timed out waiting for completion\n"); 504 503 ret = -ETIMEDOUT; 505 504 goto out_disable_controller; ··· 537 536 struct sg_table table; 538 537 dma_cookie_t cookie; 539 538 int ret, i; 539 + unsigned long timeout; 540 540 541 541 /* Disable the programmer */ 542 542 fpga_programmer_disable(priv); ··· 625 623 dev_dbg(priv->dev, "enabled the controller\n"); 626 624 627 625 /* Wait for the interrupt handler to signal that programming finished */ 628 - ret = wait_for_completion_timeout(&priv->completion, 2 * HZ); 629 - if (!ret) { 626 + timeout = wait_for_completion_timeout(&priv->completion, 2 * HZ); 627 + if (!timeout) { 630 628 dev_err(priv->dev, "Timed out waiting for completion\n"); 631 629 ret = -ETIMEDOUT; 632 630 goto out_disable_controller; ··· 1144 1142 return ret; 1145 1143 } 1146 1144 1147 - static struct of_device_id fpga_of_match[] = { 1145 + static const struct of_device_id fpga_of_match[] = { 1148 1146 { .compatible = "carma,fpga-programmer", }, 1149 1147 {}, 1150 1148 };
+1 -1
drivers/misc/carma/carma-fpga.c
··· 1486 1486 return 0; 1487 1487 } 1488 1488 1489 - static struct of_device_id data_of_match[] = { 1489 + static const struct of_device_id data_of_match[] = { 1490 1490 { .compatible = "carma,carma-fpga", }, 1491 1491 {}, 1492 1492 };
+36 -18
drivers/misc/lis3lv02d/lis3lv02d.c
··· 950 950 struct lis3lv02d_platform_data *pdata; 951 951 struct device_node *np = lis3->of_node; 952 952 u32 val; 953 + s32 sval; 953 954 954 955 if (!lis3->of_node) 955 956 return 0; ··· 1032 1031 pdata->wakeup_flags |= LIS3_WAKEUP_Z_LO; 1033 1032 if (of_get_property(np, "st,wakeup-z-hi", NULL)) 1034 1033 pdata->wakeup_flags |= LIS3_WAKEUP_Z_HI; 1034 + if (of_get_property(np, "st,wakeup-threshold", &val)) 1035 + pdata->wakeup_thresh = val; 1036 + 1037 + if (of_get_property(np, "st,wakeup2-x-lo", NULL)) 1038 + pdata->wakeup_flags2 |= LIS3_WAKEUP_X_LO; 1039 + if (of_get_property(np, "st,wakeup2-x-hi", NULL)) 1040 + pdata->wakeup_flags2 |= LIS3_WAKEUP_X_HI; 1041 + if (of_get_property(np, "st,wakeup2-y-lo", NULL)) 1042 + pdata->wakeup_flags2 |= LIS3_WAKEUP_Y_LO; 1043 + if (of_get_property(np, "st,wakeup2-y-hi", NULL)) 1044 + pdata->wakeup_flags2 |= LIS3_WAKEUP_Y_HI; 1045 + if (of_get_property(np, "st,wakeup2-z-lo", NULL)) 1046 + pdata->wakeup_flags2 |= LIS3_WAKEUP_Z_LO; 1047 + if (of_get_property(np, "st,wakeup2-z-hi", NULL)) 1048 + pdata->wakeup_flags2 |= LIS3_WAKEUP_Z_HI; 1049 + if (of_get_property(np, "st,wakeup2-threshold", &val)) 1050 + pdata->wakeup_thresh2 = val; 1035 1051 1036 1052 if (!of_property_read_u32(np, "st,highpass-cutoff-hz", &val)) { 1037 1053 switch (val) { ··· 1072 1054 if (of_get_property(np, "st,hipass2-disable", NULL)) 1073 1055 pdata->hipass_ctrl |= LIS3_HIPASS2_DISABLE; 1074 1056 1075 - if (of_get_property(np, "st,axis-x", &val)) 1076 - pdata->axis_x = val; 1077 - if (of_get_property(np, "st,axis-y", &val)) 1078 - pdata->axis_y = val; 1079 - if (of_get_property(np, "st,axis-z", &val)) 1080 - pdata->axis_z = val; 1057 + if (of_property_read_s32(np, "st,axis-x", &sval) == 0) 1058 + pdata->axis_x = sval; 1059 + if (of_property_read_s32(np, "st,axis-y", &sval) == 0) 1060 + pdata->axis_y = sval; 1061 + if (of_property_read_s32(np, "st,axis-z", &sval) == 0) 1062 + pdata->axis_z = sval; 1081 1063 1082 1064 if (of_get_property(np, "st,default-rate", NULL)) 1083 1065 pdata->default_rate = val; 1084 1066 1085 - if (of_get_property(np, "st,min-limit-x", &val)) 1086 - pdata->st_min_limits[0] = val; 1087 - if (of_get_property(np, "st,min-limit-y", &val)) 1088 - pdata->st_min_limits[1] = val; 1089 - if (of_get_property(np, "st,min-limit-z", &val)) 1090 - pdata->st_min_limits[2] = val; 1067 + if (of_property_read_s32(np, "st,min-limit-x", &sval) == 0) 1068 + pdata->st_min_limits[0] = sval; 1069 + if (of_property_read_s32(np, "st,min-limit-y", &sval) == 0) 1070 + pdata->st_min_limits[1] = sval; 1071 + if (of_property_read_s32(np, "st,min-limit-z", &sval) == 0) 1072 + pdata->st_min_limits[2] = sval; 1091 1073 1092 - if (of_get_property(np, "st,max-limit-x", &val)) 1093 - pdata->st_max_limits[0] = val; 1094 - if (of_get_property(np, "st,max-limit-y", &val)) 1095 - pdata->st_max_limits[1] = val; 1096 - if (of_get_property(np, "st,max-limit-z", &val)) 1097 - pdata->st_max_limits[2] = val; 1074 + if (of_property_read_s32(np, "st,max-limit-x", &sval) == 0) 1075 + pdata->st_max_limits[0] = sval; 1076 + if (of_property_read_s32(np, "st,max-limit-y", &sval) == 0) 1077 + pdata->st_max_limits[1] = sval; 1078 + if (of_property_read_s32(np, "st,max-limit-z", &sval) == 0) 1079 + pdata->st_max_limits[2] = sval; 1098 1080 1099 1081 1100 1082 lis3->pdata = pdata;
+1 -1
drivers/misc/lis3lv02d/lis3lv02d_i2c.c
··· 106 106 { .as_array = { LIS3_DEV_X, LIS3_DEV_Y, LIS3_DEV_Z } }; 107 107 108 108 #ifdef CONFIG_OF 109 - static struct of_device_id lis3lv02d_i2c_dt_ids[] = { 109 + static const struct of_device_id lis3lv02d_i2c_dt_ids[] = { 110 110 { .compatible = "st,lis3lv02d" }, 111 111 {} 112 112 };
+1 -1
drivers/misc/lis3lv02d/lis3lv02d_spi.c
··· 61 61 { .as_array = { 1, 2, 3 } }; 62 62 63 63 #ifdef CONFIG_OF 64 - static struct of_device_id lis302dl_spi_dt_ids[] = { 64 + static const struct of_device_id lis302dl_spi_dt_ids[] = { 65 65 { .compatible = "st,lis302dl-spi" }, 66 66 {} 67 67 };
+3
drivers/misc/mei/Makefile
··· 21 21 obj-$(CONFIG_INTEL_MEI_TXE) += mei-txe.o 22 22 mei-txe-objs := pci-txe.o 23 23 mei-txe-objs += hw-txe.o 24 + 25 + mei-$(CONFIG_EVENT_TRACING) += mei-trace.o 26 + CFLAGS_mei-trace.o = -I$(src)
+155 -274
drivers/misc/mei/amthif.c
··· 48 48 { 49 49 /* reset iamthif parameters. */ 50 50 dev->iamthif_current_cb = NULL; 51 - dev->iamthif_msg_buf_size = 0; 52 - dev->iamthif_msg_buf_index = 0; 53 51 dev->iamthif_canceled = false; 54 - dev->iamthif_ioctl = false; 55 52 dev->iamthif_state = MEI_IAMTHIF_IDLE; 56 53 dev->iamthif_timer = 0; 57 54 dev->iamthif_stall_timer = 0; ··· 66 69 { 67 70 struct mei_cl *cl = &dev->iamthif_cl; 68 71 struct mei_me_client *me_cl; 69 - unsigned char *msg_buf; 70 72 int ret; 71 73 72 74 dev->iamthif_state = MEI_IAMTHIF_IDLE; ··· 86 90 dev->iamthif_mtu = me_cl->props.max_msg_length; 87 91 dev_dbg(dev->dev, "IAMTHIF_MTU = %d\n", dev->iamthif_mtu); 88 92 89 - kfree(dev->iamthif_msg_buf); 90 - dev->iamthif_msg_buf = NULL; 91 - 92 - /* allocate storage for ME message buffer */ 93 - msg_buf = kcalloc(dev->iamthif_mtu, 94 - sizeof(unsigned char), GFP_KERNEL); 95 - if (!msg_buf) { 96 - ret = -ENOMEM; 97 - goto out; 98 - } 99 - 100 - dev->iamthif_msg_buf = msg_buf; 101 93 102 94 ret = mei_cl_link(cl, MEI_IAMTHIF_HOST_CLIENT_ID); 103 95 if (ret < 0) { ··· 178 194 dev_dbg(dev->dev, "woke up from sleep\n"); 179 195 } 180 196 197 + if (cb->status) { 198 + rets = cb->status; 199 + dev_dbg(dev->dev, "read operation failed %d\n", rets); 200 + goto free; 201 + } 181 202 182 203 dev_dbg(dev->dev, "Got amthif data\n"); 183 204 dev->iamthif_timer = 0; 184 205 185 - if (cb) { 186 - timeout = cb->read_time + 187 - mei_secs_to_jiffies(MEI_IAMTHIF_READ_TIMER); 188 - dev_dbg(dev->dev, "amthif timeout = %lud\n", 189 - timeout); 206 + timeout = cb->read_time + 207 + mei_secs_to_jiffies(MEI_IAMTHIF_READ_TIMER); 208 + dev_dbg(dev->dev, "amthif timeout = %lud\n", 209 + timeout); 190 210 191 - if (time_after(jiffies, timeout)) { 192 - dev_dbg(dev->dev, "amthif Time out\n"); 193 - /* 15 sec for the message has expired */ 194 - list_del(&cb->list); 195 - rets = -ETIME; 196 - goto free; 197 - } 211 + if (time_after(jiffies, timeout)) { 212 + dev_dbg(dev->dev, "amthif Time out\n"); 213 + /* 15 sec for the message has expired */ 214 + list_del_init(&cb->list); 215 + rets = -ETIME; 216 + goto free; 198 217 } 199 218 /* if the whole message will fit remove it from the list */ 200 219 if (cb->buf_idx >= *offset && length >= (cb->buf_idx - *offset)) 201 - list_del(&cb->list); 220 + list_del_init(&cb->list); 202 221 else if (cb->buf_idx > 0 && cb->buf_idx <= *offset) { 203 222 /* end of the message has been reached */ 204 - list_del(&cb->list); 223 + list_del_init(&cb->list); 205 224 rets = 0; 206 225 goto free; 207 226 } ··· 212 225 * remove message from deletion list 213 226 */ 214 227 215 - dev_dbg(dev->dev, "amthif cb->response_buffer size - %d\n", 216 - cb->response_buffer.size); 228 + dev_dbg(dev->dev, "amthif cb->buf size - %d\n", 229 + cb->buf.size); 217 230 dev_dbg(dev->dev, "amthif cb->buf_idx - %lu\n", cb->buf_idx); 218 231 219 232 /* length is being truncated to PAGE_SIZE, however, 220 233 * the buf_idx may point beyond */ 221 234 length = min_t(size_t, length, (cb->buf_idx - *offset)); 222 235 223 - if (copy_to_user(ubuf, cb->response_buffer.data + *offset, length)) { 236 + if (copy_to_user(ubuf, cb->buf.data + *offset, length)) { 224 237 dev_dbg(dev->dev, "failed to copy data to userland\n"); 225 238 rets = -EFAULT; 226 239 } else { ··· 239 252 } 240 253 241 254 /** 255 + * mei_amthif_read_start - queue message for sending read credential 256 + * 257 + * @cl: host client 258 + * @file: file pointer of message recipient 259 + * 260 + * Return: 0 on success, <0 on failure. 261 + */ 262 + static int mei_amthif_read_start(struct mei_cl *cl, struct file *file) 263 + { 264 + struct mei_device *dev = cl->dev; 265 + struct mei_cl_cb *cb; 266 + size_t length = dev->iamthif_mtu; 267 + int rets; 268 + 269 + cb = mei_io_cb_init(cl, MEI_FOP_READ, file); 270 + if (!cb) { 271 + rets = -ENOMEM; 272 + goto err; 273 + } 274 + 275 + rets = mei_io_cb_alloc_buf(cb, length); 276 + if (rets) 277 + goto err; 278 + 279 + list_add_tail(&cb->list, &dev->ctrl_wr_list.list); 280 + 281 + dev->iamthif_state = MEI_IAMTHIF_READING; 282 + dev->iamthif_file_object = cb->file_object; 283 + dev->iamthif_current_cb = cb; 284 + 285 + return 0; 286 + err: 287 + mei_io_cb_free(cb); 288 + return rets; 289 + } 290 + 291 + /** 242 292 * mei_amthif_send_cmd - send amthif command to the ME 243 293 * 244 - * @dev: the device structure 294 + * @cl: the host client 245 295 * @cb: mei call back struct 246 296 * 247 297 * Return: 0 on success, <0 on failure. 248 - * 249 298 */ 250 - static int mei_amthif_send_cmd(struct mei_device *dev, struct mei_cl_cb *cb) 299 + static int mei_amthif_send_cmd(struct mei_cl *cl, struct mei_cl_cb *cb) 251 300 { 252 - struct mei_msg_hdr mei_hdr; 253 - struct mei_cl *cl; 301 + struct mei_device *dev; 254 302 int ret; 255 303 256 - if (!dev || !cb) 304 + if (!cl->dev || !cb) 257 305 return -ENODEV; 258 306 259 - dev_dbg(dev->dev, "write data to amthif client.\n"); 307 + dev = cl->dev; 260 308 261 309 dev->iamthif_state = MEI_IAMTHIF_WRITING; 262 310 dev->iamthif_current_cb = cb; 263 311 dev->iamthif_file_object = cb->file_object; 264 312 dev->iamthif_canceled = false; 265 - dev->iamthif_ioctl = true; 266 - dev->iamthif_msg_buf_size = cb->request_buffer.size; 267 - memcpy(dev->iamthif_msg_buf, cb->request_buffer.data, 268 - cb->request_buffer.size); 269 - cl = &dev->iamthif_cl; 270 313 271 - ret = mei_cl_flow_ctrl_creds(cl); 314 + ret = mei_cl_write(cl, cb, false); 272 315 if (ret < 0) 273 316 return ret; 274 317 275 - if (ret && mei_hbuf_acquire(dev)) { 276 - ret = 0; 277 - if (cb->request_buffer.size > mei_hbuf_max_len(dev)) { 278 - mei_hdr.length = mei_hbuf_max_len(dev); 279 - mei_hdr.msg_complete = 0; 280 - } else { 281 - mei_hdr.length = cb->request_buffer.size; 282 - mei_hdr.msg_complete = 1; 283 - } 318 + if (cb->completed) 319 + cb->status = mei_amthif_read_start(cl, cb->file_object); 284 320 285 - mei_hdr.host_addr = cl->host_client_id; 286 - mei_hdr.me_addr = cl->me_client_id; 287 - mei_hdr.reserved = 0; 288 - mei_hdr.internal = 0; 289 - dev->iamthif_msg_buf_index += mei_hdr.length; 290 - ret = mei_write_message(dev, &mei_hdr, dev->iamthif_msg_buf); 291 - if (ret) 292 - return ret; 293 - 294 - if (mei_hdr.msg_complete) { 295 - if (mei_cl_flow_ctrl_reduce(cl)) 296 - return -EIO; 297 - dev->iamthif_flow_control_pending = true; 298 - dev->iamthif_state = MEI_IAMTHIF_FLOW_CONTROL; 299 - dev_dbg(dev->dev, "add amthif cb to write waiting list\n"); 300 - dev->iamthif_current_cb = cb; 301 - dev->iamthif_file_object = cb->file_object; 302 - list_add_tail(&cb->list, &dev->write_waiting_list.list); 303 - } else { 304 - dev_dbg(dev->dev, "message does not complete, so add amthif cb to write list.\n"); 305 - list_add_tail(&cb->list, &dev->write_list.list); 306 - } 307 - } else { 308 - list_add_tail(&cb->list, &dev->write_list.list); 309 - } 310 321 return 0; 311 322 } 312 323 313 324 /** 314 - * mei_amthif_write - write amthif data to amthif client 315 - * 316 - * @dev: the device structure 317 - * @cb: mei call back struct 318 - * 319 - * Return: 0 on success, <0 on failure. 320 - * 321 - */ 322 - int mei_amthif_write(struct mei_device *dev, struct mei_cl_cb *cb) 323 - { 324 - int ret; 325 - 326 - if (!dev || !cb) 327 - return -ENODEV; 328 - 329 - ret = mei_io_cb_alloc_resp_buf(cb, dev->iamthif_mtu); 330 - if (ret) 331 - return ret; 332 - 333 - cb->fop_type = MEI_FOP_WRITE; 334 - 335 - if (!list_empty(&dev->amthif_cmd_list.list) || 336 - dev->iamthif_state != MEI_IAMTHIF_IDLE) { 337 - dev_dbg(dev->dev, 338 - "amthif state = %d\n", dev->iamthif_state); 339 - dev_dbg(dev->dev, "AMTHIF: add cb to the wait list\n"); 340 - list_add_tail(&cb->list, &dev->amthif_cmd_list.list); 341 - return 0; 342 - } 343 - return mei_amthif_send_cmd(dev, cb); 344 - } 345 - /** 346 325 * mei_amthif_run_next_cmd - send next amt command from queue 347 326 * 348 327 * @dev: the device structure 328 + * 329 + * Return: 0 on success, <0 on failure. 349 330 */ 350 - void mei_amthif_run_next_cmd(struct mei_device *dev) 331 + int mei_amthif_run_next_cmd(struct mei_device *dev) 351 332 { 333 + struct mei_cl *cl = &dev->iamthif_cl; 352 334 struct mei_cl_cb *cb; 353 - int ret; 354 335 355 - if (!dev) 356 - return; 357 - 358 - dev->iamthif_msg_buf_size = 0; 359 - dev->iamthif_msg_buf_index = 0; 360 336 dev->iamthif_canceled = false; 361 - dev->iamthif_ioctl = true; 362 337 dev->iamthif_state = MEI_IAMTHIF_IDLE; 363 338 dev->iamthif_timer = 0; 364 339 dev->iamthif_file_object = NULL; ··· 330 381 cb = list_first_entry_or_null(&dev->amthif_cmd_list.list, 331 382 typeof(*cb), list); 332 383 if (!cb) 333 - return; 334 - list_del(&cb->list); 335 - ret = mei_amthif_send_cmd(dev, cb); 336 - if (ret) 337 - dev_warn(dev->dev, "amthif write failed status = %d\n", ret); 384 + return 0; 385 + 386 + list_del_init(&cb->list); 387 + return mei_amthif_send_cmd(cl, cb); 338 388 } 339 389 390 + /** 391 + * mei_amthif_write - write amthif data to amthif client 392 + * 393 + * @cl: host client 394 + * @cb: mei call back struct 395 + * 396 + * Return: 0 on success, <0 on failure. 397 + */ 398 + int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb) 399 + { 400 + 401 + struct mei_device *dev; 402 + 403 + if (WARN_ON(!cl || !cl->dev)) 404 + return -ENODEV; 405 + 406 + if (WARN_ON(!cb)) 407 + return -EINVAL; 408 + 409 + dev = cl->dev; 410 + 411 + list_add_tail(&cb->list, &dev->amthif_cmd_list.list); 412 + return mei_amthif_run_next_cmd(dev); 413 + } 414 + 415 + /** 416 + * mei_amthif_poll - the amthif poll function 417 + * 418 + * @dev: the device structure 419 + * @file: pointer to file structure 420 + * @wait: pointer to poll_table structure 421 + * 422 + * Return: poll mask 423 + * 424 + * Locking: called under "dev->device_lock" lock 425 + */ 340 426 341 427 unsigned int mei_amthif_poll(struct mei_device *dev, 342 428 struct file *file, poll_table *wait) ··· 380 396 381 397 poll_wait(file, &dev->iamthif_cl.wait, wait); 382 398 383 - mutex_lock(&dev->device_lock); 384 - if (!mei_cl_is_connected(&dev->iamthif_cl)) { 399 + if (dev->iamthif_state == MEI_IAMTHIF_READ_COMPLETE && 400 + dev->iamthif_file_object == file) { 385 401 386 - mask = POLLERR; 387 - 388 - } else if (dev->iamthif_state == MEI_IAMTHIF_READ_COMPLETE && 389 - dev->iamthif_file_object == file) { 390 - 391 - mask |= (POLLIN | POLLRDNORM); 392 - dev_dbg(dev->dev, "run next amthif cb\n"); 402 + mask |= POLLIN | POLLRDNORM; 393 403 mei_amthif_run_next_cmd(dev); 394 404 } 395 - mutex_unlock(&dev->device_lock); 396 405 397 406 return mask; 398 407 } ··· 404 427 int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, 405 428 struct mei_cl_cb *cmpl_list) 406 429 { 407 - struct mei_device *dev = cl->dev; 408 - struct mei_msg_hdr mei_hdr; 409 - size_t len = dev->iamthif_msg_buf_size - dev->iamthif_msg_buf_index; 410 - u32 msg_slots = mei_data2slots(len); 411 - int slots; 412 - int rets; 430 + int ret; 413 431 414 - rets = mei_cl_flow_ctrl_creds(cl); 415 - if (rets < 0) 416 - return rets; 432 + ret = mei_cl_irq_write(cl, cb, cmpl_list); 433 + if (ret) 434 + return ret; 417 435 418 - if (rets == 0) { 419 - cl_dbg(dev, cl, "No flow control credentials: not sending.\n"); 420 - return 0; 421 - } 422 - 423 - mei_hdr.host_addr = cl->host_client_id; 424 - mei_hdr.me_addr = cl->me_client_id; 425 - mei_hdr.reserved = 0; 426 - mei_hdr.internal = 0; 427 - 428 - slots = mei_hbuf_empty_slots(dev); 429 - 430 - if (slots >= msg_slots) { 431 - mei_hdr.length = len; 432 - mei_hdr.msg_complete = 1; 433 - /* Split the message only if we can write the whole host buffer */ 434 - } else if (slots == dev->hbuf_depth) { 435 - msg_slots = slots; 436 - len = (slots * sizeof(u32)) - sizeof(struct mei_msg_hdr); 437 - mei_hdr.length = len; 438 - mei_hdr.msg_complete = 0; 439 - } else { 440 - /* wait for next time the host buffer is empty */ 441 - return 0; 442 - } 443 - 444 - dev_dbg(dev->dev, MEI_HDR_FMT, MEI_HDR_PRM(&mei_hdr)); 445 - 446 - rets = mei_write_message(dev, &mei_hdr, 447 - dev->iamthif_msg_buf + dev->iamthif_msg_buf_index); 448 - if (rets) { 449 - dev->iamthif_state = MEI_IAMTHIF_IDLE; 450 - cl->status = rets; 451 - list_del(&cb->list); 452 - return rets; 453 - } 454 - 455 - if (mei_cl_flow_ctrl_reduce(cl)) 456 - return -EIO; 457 - 458 - dev->iamthif_msg_buf_index += mei_hdr.length; 459 - cl->status = 0; 460 - 461 - if (mei_hdr.msg_complete) { 462 - dev->iamthif_state = MEI_IAMTHIF_FLOW_CONTROL; 463 - dev->iamthif_flow_control_pending = true; 464 - 465 - /* save iamthif cb sent to amthif client */ 466 - cb->buf_idx = dev->iamthif_msg_buf_index; 467 - dev->iamthif_current_cb = cb; 468 - 469 - list_move_tail(&cb->list, &dev->write_waiting_list.list); 470 - } 471 - 436 + if (cb->completed) 437 + cb->status = mei_amthif_read_start(cl, cb->file_object); 472 438 473 439 return 0; 474 440 } ··· 420 500 * mei_amthif_irq_read_msg - read routine after ISR to 421 501 * handle the read amthif message 422 502 * 423 - * @dev: the device structure 503 + * @cl: mei client 424 504 * @mei_hdr: header of amthif message 425 - * @complete_list: An instance of our list structure 505 + * @cmpl_list: completed callbacks list 426 506 * 427 - * Return: 0 on success, <0 on failure. 507 + * Return: -ENODEV if cb is NULL 0 otherwise; error message is in cb->status 428 508 */ 429 - int mei_amthif_irq_read_msg(struct mei_device *dev, 509 + int mei_amthif_irq_read_msg(struct mei_cl *cl, 430 510 struct mei_msg_hdr *mei_hdr, 431 - struct mei_cl_cb *complete_list) 511 + struct mei_cl_cb *cmpl_list) 432 512 { 433 - struct mei_cl_cb *cb; 434 - unsigned char *buffer; 513 + struct mei_device *dev; 514 + int ret; 435 515 436 - BUG_ON(mei_hdr->me_addr != dev->iamthif_cl.me_client_id); 437 - BUG_ON(dev->iamthif_state != MEI_IAMTHIF_READING); 516 + dev = cl->dev; 438 517 439 - buffer = dev->iamthif_msg_buf + dev->iamthif_msg_buf_index; 440 - BUG_ON(dev->iamthif_mtu < dev->iamthif_msg_buf_index + mei_hdr->length); 518 + if (dev->iamthif_state != MEI_IAMTHIF_READING) 519 + return 0; 441 520 442 - mei_read_slots(dev, buffer, mei_hdr->length); 443 - 444 - dev->iamthif_msg_buf_index += mei_hdr->length; 521 + ret = mei_cl_irq_read_msg(cl, mei_hdr, cmpl_list); 522 + if (ret) 523 + return ret; 445 524 446 525 if (!mei_hdr->msg_complete) 447 526 return 0; 448 527 449 - dev_dbg(dev->dev, "amthif_message_buffer_index =%d\n", 450 - mei_hdr->length); 451 - 452 528 dev_dbg(dev->dev, "completed amthif read.\n "); 453 - if (!dev->iamthif_current_cb) 454 - return -ENODEV; 455 - 456 - cb = dev->iamthif_current_cb; 457 529 dev->iamthif_current_cb = NULL; 458 - 459 530 dev->iamthif_stall_timer = 0; 460 - cb->buf_idx = dev->iamthif_msg_buf_index; 461 - cb->read_time = jiffies; 462 - if (dev->iamthif_ioctl) { 463 - /* found the iamthif cb */ 464 - dev_dbg(dev->dev, "complete the amthif read cb.\n "); 465 - dev_dbg(dev->dev, "add the amthif read cb to complete.\n "); 466 - list_add_tail(&cb->list, &complete_list->list); 467 - } 468 - return 0; 469 - } 470 531 471 - /** 472 - * mei_amthif_irq_read - prepares to read amthif data. 473 - * 474 - * @dev: the device structure. 475 - * @slots: free slots. 476 - * 477 - * Return: 0, OK; otherwise, error. 478 - */ 479 - int mei_amthif_irq_read(struct mei_device *dev, s32 *slots) 480 - { 481 - u32 msg_slots = mei_data2slots(sizeof(struct hbm_flow_control)); 482 - 483 - if (*slots < msg_slots) 484 - return -EMSGSIZE; 485 - 486 - *slots -= msg_slots; 487 - 488 - if (mei_hbm_cl_flow_control_req(dev, &dev->iamthif_cl)) { 489 - dev_dbg(dev->dev, "iamthif flow control failed\n"); 490 - return -EIO; 491 - } 492 - 493 - dev_dbg(dev->dev, "iamthif flow control success\n"); 494 - dev->iamthif_state = MEI_IAMTHIF_READING; 495 - dev->iamthif_flow_control_pending = false; 496 - dev->iamthif_msg_buf_index = 0; 497 - dev->iamthif_msg_buf_size = 0; 498 - dev->iamthif_stall_timer = MEI_IAMTHIF_STALL_TIMER; 499 - dev->hbuf_is_ready = mei_hbuf_is_ready(dev); 500 532 return 0; 501 533 } 502 534 ··· 460 588 */ 461 589 void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb) 462 590 { 591 + 592 + if (cb->fop_type == MEI_FOP_WRITE) { 593 + if (!cb->status) { 594 + dev->iamthif_stall_timer = MEI_IAMTHIF_STALL_TIMER; 595 + mei_io_cb_free(cb); 596 + return; 597 + } 598 + /* 599 + * in case of error enqueue the write cb to complete read list 600 + * so it can be propagated to the reader 601 + */ 602 + list_add_tail(&cb->list, &dev->amthif_rd_complete_list.list); 603 + wake_up_interruptible(&dev->iamthif_cl.wait); 604 + return; 605 + } 606 + 463 607 if (dev->iamthif_canceled != 1) { 464 608 dev->iamthif_state = MEI_IAMTHIF_READ_COMPLETE; 465 609 dev->iamthif_stall_timer = 0; 466 - memcpy(cb->response_buffer.data, 467 - dev->iamthif_msg_buf, 468 - dev->iamthif_msg_buf_index); 469 610 list_add_tail(&cb->list, &dev->amthif_rd_complete_list.list); 470 611 dev_dbg(dev->dev, "amthif read completed\n"); 471 612 dev->iamthif_timer = jiffies; 472 613 dev_dbg(dev->dev, "dev->iamthif_timer = %ld\n", 473 - dev->iamthif_timer); 614 + dev->iamthif_timer); 474 615 } else { 475 616 mei_amthif_run_next_cmd(dev); 476 617 } ··· 508 623 static bool mei_clear_list(struct mei_device *dev, 509 624 const struct file *file, struct list_head *mei_cb_list) 510 625 { 511 - struct mei_cl_cb *cb_pos = NULL; 512 - struct mei_cl_cb *cb_next = NULL; 626 + struct mei_cl *cl = &dev->iamthif_cl; 627 + struct mei_cl_cb *cb, *next; 513 628 bool removed = false; 514 629 515 630 /* list all list member */ 516 - list_for_each_entry_safe(cb_pos, cb_next, mei_cb_list, list) { 631 + list_for_each_entry_safe(cb, next, mei_cb_list, list) { 517 632 /* check if list member associated with a file */ 518 - if (file == cb_pos->file_object) { 519 - /* remove member from the list */ 520 - list_del(&cb_pos->list); 633 + if (file == cb->file_object) { 521 634 /* check if cb equal to current iamthif cb */ 522 - if (dev->iamthif_current_cb == cb_pos) { 635 + if (dev->iamthif_current_cb == cb) { 523 636 dev->iamthif_current_cb = NULL; 524 637 /* send flow control to iamthif client */ 525 - mei_hbm_cl_flow_control_req(dev, 526 - &dev->iamthif_cl); 638 + mei_hbm_cl_flow_control_req(dev, cl); 527 639 } 528 640 /* free all allocated buffers */ 529 - mei_io_cb_free(cb_pos); 530 - cb_pos = NULL; 641 + mei_io_cb_free(cb); 531 642 removed = true; 532 643 } 533 644 }
+45 -60
drivers/misc/mei/bus.c
··· 238 238 dev = cl->dev; 239 239 240 240 mutex_lock(&dev->device_lock); 241 - if (cl->state != MEI_FILE_CONNECTED) { 241 + if (!mei_cl_is_connected(cl)) { 242 242 rets = -ENODEV; 243 243 goto out; 244 244 } ··· 255 255 goto out; 256 256 } 257 257 258 - cb = mei_io_cb_init(cl, NULL); 258 + cb = mei_cl_alloc_cb(cl, length, MEI_FOP_WRITE, NULL); 259 259 if (!cb) { 260 260 rets = -ENOMEM; 261 261 goto out; 262 262 } 263 263 264 - rets = mei_io_cb_alloc_req_buf(cb, length); 265 - if (rets < 0) 266 - goto out; 267 - 268 - memcpy(cb->request_buffer.data, buf, length); 264 + memcpy(cb->buf.data, buf, length); 269 265 270 266 rets = mei_cl_write(cl, cb, blocking); 271 267 ··· 288 292 289 293 mutex_lock(&dev->device_lock); 290 294 291 - if (!cl->read_cb) { 292 - rets = mei_cl_read_start(cl, length); 293 - if (rets < 0) 294 - goto out; 295 - } 295 + cb = mei_cl_read_cb(cl, NULL); 296 + if (cb) 297 + goto copy; 296 298 297 - if (cl->reading_state != MEI_READ_COMPLETE && 298 - !waitqueue_active(&cl->rx_wait)) { 299 + rets = mei_cl_read_start(cl, length, NULL); 300 + if (rets && rets != -EBUSY) 301 + goto out; 302 + 303 + if (list_empty(&cl->rd_completed) && !waitqueue_active(&cl->rx_wait)) { 299 304 300 305 mutex_unlock(&dev->device_lock); 301 306 302 307 if (wait_event_interruptible(cl->rx_wait, 303 - cl->reading_state == MEI_READ_COMPLETE || 304 - mei_cl_is_transitioning(cl))) { 308 + (!list_empty(&cl->rd_completed)) || 309 + (!mei_cl_is_connected(cl)))) { 305 310 306 311 if (signal_pending(current)) 307 312 return -EINTR; ··· 310 313 } 311 314 312 315 mutex_lock(&dev->device_lock); 316 + 317 + if (!mei_cl_is_connected(cl)) { 318 + rets = -EBUSY; 319 + goto out; 320 + } 313 321 } 314 322 315 - cb = cl->read_cb; 316 - 317 - if (cl->reading_state != MEI_READ_COMPLETE) { 323 + cb = mei_cl_read_cb(cl, NULL); 324 + if (!cb) { 318 325 rets = 0; 319 326 goto out; 320 327 } 321 328 329 + copy: 330 + if (cb->status) { 331 + rets = cb->status; 332 + goto free; 333 + } 334 + 322 335 r_length = min_t(size_t, length, cb->buf_idx); 323 - memcpy(buf, cb->response_buffer.data, r_length); 336 + memcpy(buf, cb->buf.data, r_length); 324 337 rets = r_length; 325 338 339 + free: 326 340 mei_io_cb_free(cb); 327 - cl->reading_state = MEI_IDLE; 328 - cl->read_cb = NULL; 329 - 330 341 out: 331 342 mutex_unlock(&dev->device_lock); 332 343 ··· 391 386 device->events = 0; 392 387 393 388 /* Prepare for the next read */ 394 - mei_cl_read_start(device->cl, 0); 389 + mei_cl_read_start(device->cl, 0, NULL); 395 390 } 396 391 397 392 int mei_cl_register_event_cb(struct mei_cl_device *device, ··· 405 400 device->event_context = context; 406 401 INIT_WORK(&device->event_work, mei_bus_event_work); 407 402 408 - mei_cl_read_start(device->cl, 0); 403 + mei_cl_read_start(device->cl, 0, NULL); 409 404 410 405 return 0; 411 406 } ··· 446 441 447 442 mutex_unlock(&dev->device_lock); 448 443 449 - if (device->event_cb && !cl->read_cb) 450 - mei_cl_read_start(device->cl, 0); 444 + if (device->event_cb) 445 + mei_cl_read_start(device->cl, 0, NULL); 451 446 452 447 if (!device->ops || !device->ops->enable) 453 448 return 0; ··· 467 462 468 463 dev = cl->dev; 469 464 465 + if (device->ops && device->ops->disable) 466 + device->ops->disable(device); 467 + 468 + device->event_cb = NULL; 469 + 470 470 mutex_lock(&dev->device_lock); 471 471 472 - if (cl->state != MEI_FILE_CONNECTED) { 473 - mutex_unlock(&dev->device_lock); 472 + if (!mei_cl_is_connected(cl)) { 474 473 dev_err(dev->dev, "Already disconnected"); 475 - 476 - return 0; 474 + err = 0; 475 + goto out; 477 476 } 478 477 479 478 cl->state = MEI_FILE_DISCONNECTING; 480 479 481 480 err = mei_cl_disconnect(cl); 482 481 if (err < 0) { 483 - mutex_unlock(&dev->device_lock); 484 - dev_err(dev->dev, 485 - "Could not disconnect from the ME client"); 486 - 487 - return err; 482 + dev_err(dev->dev, "Could not disconnect from the ME client"); 483 + goto out; 488 484 } 489 485 490 486 /* Flush queues and remove any pending read */ 491 - mei_cl_flush_queues(cl); 487 + mei_cl_flush_queues(cl, NULL); 492 488 493 - if (cl->read_cb) { 494 - struct mei_cl_cb *cb = NULL; 495 - 496 - cb = mei_cl_find_read_cb(cl); 497 - /* Remove entry from read list */ 498 - if (cb) 499 - list_del(&cb->list); 500 - 501 - cb = cl->read_cb; 502 - cl->read_cb = NULL; 503 - 504 - if (cb) { 505 - mei_io_cb_free(cb); 506 - cb = NULL; 507 - } 508 - } 509 - 510 - device->event_cb = NULL; 511 - 489 + out: 512 490 mutex_unlock(&dev->device_lock); 491 + return err; 513 492 514 - if (!device->ops || !device->ops->disable) 515 - return 0; 516 - 517 - return device->ops->disable(device); 518 493 } 519 494 EXPORT_SYMBOL_GPL(mei_cl_disable_device); 520 495
+313 -169
drivers/misc/mei/client.c
··· 48 48 */ 49 49 struct mei_me_client *mei_me_cl_get(struct mei_me_client *me_cl) 50 50 { 51 - if (me_cl) 52 - kref_get(&me_cl->refcnt); 51 + if (me_cl && kref_get_unless_zero(&me_cl->refcnt)) 52 + return me_cl; 53 53 54 - return me_cl; 54 + return NULL; 55 55 } 56 56 57 57 /** 58 - * mei_me_cl_release - unlink and free me client 58 + * mei_me_cl_release - free me client 59 59 * 60 60 * Locking: called under "dev->device_lock" lock 61 61 * ··· 65 65 { 66 66 struct mei_me_client *me_cl = 67 67 container_of(ref, struct mei_me_client, refcnt); 68 - list_del(&me_cl->list); 68 + 69 69 kfree(me_cl); 70 70 } 71 + 71 72 /** 72 73 * mei_me_cl_put - decrease me client refcount and free client if necessary 73 74 * ··· 83 82 } 84 83 85 84 /** 85 + * __mei_me_cl_del - delete me client form the list and decrease 86 + * reference counter 87 + * 88 + * @dev: mei device 89 + * @me_cl: me client 90 + * 91 + * Locking: dev->me_clients_rwsem 92 + */ 93 + static void __mei_me_cl_del(struct mei_device *dev, struct mei_me_client *me_cl) 94 + { 95 + if (!me_cl) 96 + return; 97 + 98 + list_del(&me_cl->list); 99 + mei_me_cl_put(me_cl); 100 + } 101 + 102 + /** 103 + * mei_me_cl_add - add me client to the list 104 + * 105 + * @dev: mei device 106 + * @me_cl: me client 107 + */ 108 + void mei_me_cl_add(struct mei_device *dev, struct mei_me_client *me_cl) 109 + { 110 + down_write(&dev->me_clients_rwsem); 111 + list_add(&me_cl->list, &dev->me_clients); 112 + up_write(&dev->me_clients_rwsem); 113 + } 114 + 115 + /** 116 + * __mei_me_cl_by_uuid - locate me client by uuid 117 + * increases ref count 118 + * 119 + * @dev: mei device 120 + * @uuid: me client uuid 121 + * 122 + * Return: me client or NULL if not found 123 + * 124 + * Locking: dev->me_clients_rwsem 125 + */ 126 + static struct mei_me_client *__mei_me_cl_by_uuid(struct mei_device *dev, 127 + const uuid_le *uuid) 128 + { 129 + struct mei_me_client *me_cl; 130 + const uuid_le *pn; 131 + 132 + WARN_ON(!rwsem_is_locked(&dev->me_clients_rwsem)); 133 + 134 + list_for_each_entry(me_cl, &dev->me_clients, list) { 135 + pn = &me_cl->props.protocol_name; 136 + if (uuid_le_cmp(*uuid, *pn) == 0) 137 + return mei_me_cl_get(me_cl); 138 + } 139 + 140 + return NULL; 141 + } 142 + 143 + /** 86 144 * mei_me_cl_by_uuid - locate me client by uuid 87 145 * increases ref count 88 146 * 89 147 * @dev: mei device 90 148 * @uuid: me client uuid 91 149 * 92 - * Locking: called under "dev->device_lock" lock 93 - * 94 150 * Return: me client or NULL if not found 151 + * 152 + * Locking: dev->me_clients_rwsem 95 153 */ 96 - struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev, 154 + struct mei_me_client *mei_me_cl_by_uuid(struct mei_device *dev, 97 155 const uuid_le *uuid) 98 156 { 99 157 struct mei_me_client *me_cl; 100 158 101 - list_for_each_entry(me_cl, &dev->me_clients, list) 102 - if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0) 103 - return mei_me_cl_get(me_cl); 159 + down_read(&dev->me_clients_rwsem); 160 + me_cl = __mei_me_cl_by_uuid(dev, uuid); 161 + up_read(&dev->me_clients_rwsem); 104 162 105 - return NULL; 163 + return me_cl; 106 164 } 107 165 108 166 /** ··· 171 111 * @dev: the device structure 172 112 * @client_id: me client id 173 113 * 174 - * Locking: called under "dev->device_lock" lock 175 - * 176 114 * Return: me client or NULL if not found 115 + * 116 + * Locking: dev->me_clients_rwsem 177 117 */ 178 118 struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id) 179 119 { 180 120 181 - struct mei_me_client *me_cl; 121 + struct mei_me_client *__me_cl, *me_cl = NULL; 182 122 183 - list_for_each_entry(me_cl, &dev->me_clients, list) 184 - if (me_cl->client_id == client_id) 123 + down_read(&dev->me_clients_rwsem); 124 + list_for_each_entry(__me_cl, &dev->me_clients, list) { 125 + if (__me_cl->client_id == client_id) { 126 + me_cl = mei_me_cl_get(__me_cl); 127 + break; 128 + } 129 + } 130 + up_read(&dev->me_clients_rwsem); 131 + 132 + return me_cl; 133 + } 134 + 135 + /** 136 + * __mei_me_cl_by_uuid_id - locate me client by client id and uuid 137 + * increases ref count 138 + * 139 + * @dev: the device structure 140 + * @uuid: me client uuid 141 + * @client_id: me client id 142 + * 143 + * Return: me client or null if not found 144 + * 145 + * Locking: dev->me_clients_rwsem 146 + */ 147 + static struct mei_me_client *__mei_me_cl_by_uuid_id(struct mei_device *dev, 148 + const uuid_le *uuid, u8 client_id) 149 + { 150 + struct mei_me_client *me_cl; 151 + const uuid_le *pn; 152 + 153 + WARN_ON(!rwsem_is_locked(&dev->me_clients_rwsem)); 154 + 155 + list_for_each_entry(me_cl, &dev->me_clients, list) { 156 + pn = &me_cl->props.protocol_name; 157 + if (uuid_le_cmp(*uuid, *pn) == 0 && 158 + me_cl->client_id == client_id) 185 159 return mei_me_cl_get(me_cl); 160 + } 186 161 187 162 return NULL; 188 163 } 164 + 189 165 190 166 /** 191 167 * mei_me_cl_by_uuid_id - locate me client by client id and uuid ··· 231 135 * @uuid: me client uuid 232 136 * @client_id: me client id 233 137 * 234 - * Locking: called under "dev->device_lock" lock 235 - * 236 - * Return: me client or NULL if not found 138 + * Return: me client or null if not found 237 139 */ 238 140 struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev, 239 141 const uuid_le *uuid, u8 client_id) 240 142 { 241 143 struct mei_me_client *me_cl; 242 144 243 - list_for_each_entry(me_cl, &dev->me_clients, list) 244 - if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0 && 245 - me_cl->client_id == client_id) 246 - return mei_me_cl_get(me_cl); 145 + down_read(&dev->me_clients_rwsem); 146 + me_cl = __mei_me_cl_by_uuid_id(dev, uuid, client_id); 147 + up_read(&dev->me_clients_rwsem); 247 148 248 - return NULL; 149 + return me_cl; 249 150 } 250 151 251 152 /** ··· 255 162 */ 256 163 void mei_me_cl_rm_by_uuid(struct mei_device *dev, const uuid_le *uuid) 257 164 { 258 - struct mei_me_client *me_cl, *next; 165 + struct mei_me_client *me_cl; 259 166 260 167 dev_dbg(dev->dev, "remove %pUl\n", uuid); 261 - list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) 262 - if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0) 263 - mei_me_cl_put(me_cl); 168 + 169 + down_write(&dev->me_clients_rwsem); 170 + me_cl = __mei_me_cl_by_uuid(dev, uuid); 171 + __mei_me_cl_del(dev, me_cl); 172 + up_write(&dev->me_clients_rwsem); 264 173 } 265 174 266 175 /** ··· 276 181 */ 277 182 void mei_me_cl_rm_by_uuid_id(struct mei_device *dev, const uuid_le *uuid, u8 id) 278 183 { 279 - struct mei_me_client *me_cl, *next; 280 - const uuid_le *pn; 184 + struct mei_me_client *me_cl; 281 185 282 186 dev_dbg(dev->dev, "remove %pUl %d\n", uuid, id); 283 - list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) { 284 - pn = &me_cl->props.protocol_name; 285 - if (me_cl->client_id == id && uuid_le_cmp(*uuid, *pn) == 0) 286 - mei_me_cl_put(me_cl); 287 - } 187 + 188 + down_write(&dev->me_clients_rwsem); 189 + me_cl = __mei_me_cl_by_uuid_id(dev, uuid, id); 190 + __mei_me_cl_del(dev, me_cl); 191 + up_write(&dev->me_clients_rwsem); 288 192 } 289 193 290 194 /** ··· 297 203 { 298 204 struct mei_me_client *me_cl, *next; 299 205 206 + down_write(&dev->me_clients_rwsem); 300 207 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) 301 - mei_me_cl_put(me_cl); 208 + __mei_me_cl_del(dev, me_cl); 209 + up_write(&dev->me_clients_rwsem); 302 210 } 303 - 304 - 305 211 306 212 /** 307 213 * mei_cl_cmp_id - tells if the clients are the same ··· 321 227 } 322 228 323 229 /** 324 - * mei_io_list_flush - removes cbs belonging to cl. 230 + * mei_io_cb_free - free mei_cb_private related memory 231 + * 232 + * @cb: mei callback struct 233 + */ 234 + void mei_io_cb_free(struct mei_cl_cb *cb) 235 + { 236 + if (cb == NULL) 237 + return; 238 + 239 + list_del(&cb->list); 240 + kfree(cb->buf.data); 241 + kfree(cb); 242 + } 243 + 244 + /** 245 + * mei_io_cb_init - allocate and initialize io callback 246 + * 247 + * @cl: mei client 248 + * @type: operation type 249 + * @fp: pointer to file structure 250 + * 251 + * Return: mei_cl_cb pointer or NULL; 252 + */ 253 + struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, enum mei_cb_file_ops type, 254 + struct file *fp) 255 + { 256 + struct mei_cl_cb *cb; 257 + 258 + cb = kzalloc(sizeof(struct mei_cl_cb), GFP_KERNEL); 259 + if (!cb) 260 + return NULL; 261 + 262 + INIT_LIST_HEAD(&cb->list); 263 + cb->file_object = fp; 264 + cb->cl = cl; 265 + cb->buf_idx = 0; 266 + cb->fop_type = type; 267 + return cb; 268 + } 269 + 270 + /** 271 + * __mei_io_list_flush - removes and frees cbs belonging to cl. 325 272 * 326 273 * @list: an instance of our list structure 327 274 * @cl: host client, can be NULL for flushing the whole list ··· 371 236 static void __mei_io_list_flush(struct mei_cl_cb *list, 372 237 struct mei_cl *cl, bool free) 373 238 { 374 - struct mei_cl_cb *cb; 375 - struct mei_cl_cb *next; 239 + struct mei_cl_cb *cb, *next; 376 240 377 241 /* enable removing everything if no cl is specified */ 378 242 list_for_each_entry_safe(cb, next, &list->list, list) { 379 243 if (!cl || mei_cl_cmp_id(cl, cb->cl)) { 380 - list_del(&cb->list); 244 + list_del_init(&cb->list); 381 245 if (free) 382 246 mei_io_cb_free(cb); 383 247 } ··· 394 260 __mei_io_list_flush(list, cl, false); 395 261 } 396 262 397 - 398 263 /** 399 264 * mei_io_list_free - removes cb belonging to cl and free them 400 265 * ··· 406 273 } 407 274 408 275 /** 409 - * mei_io_cb_free - free mei_cb_private related memory 276 + * mei_io_cb_alloc_buf - allocate callback buffer 410 277 * 411 - * @cb: mei callback struct 278 + * @cb: io callback structure 279 + * @length: size of the buffer 280 + * 281 + * Return: 0 on success 282 + * -EINVAL if cb is NULL 283 + * -ENOMEM if allocation failed 412 284 */ 413 - void mei_io_cb_free(struct mei_cl_cb *cb) 285 + int mei_io_cb_alloc_buf(struct mei_cl_cb *cb, size_t length) 414 286 { 415 - if (cb == NULL) 416 - return; 287 + if (!cb) 288 + return -EINVAL; 417 289 418 - kfree(cb->request_buffer.data); 419 - kfree(cb->response_buffer.data); 420 - kfree(cb); 290 + if (length == 0) 291 + return 0; 292 + 293 + cb->buf.data = kmalloc(length, GFP_KERNEL); 294 + if (!cb->buf.data) 295 + return -ENOMEM; 296 + cb->buf.size = length; 297 + return 0; 421 298 } 422 299 423 300 /** 424 - * mei_io_cb_init - allocate and initialize io callback 301 + * mei_cl_alloc_cb - a convenient wrapper for allocating read cb 425 302 * 426 - * @cl: mei client 427 - * @fp: pointer to file structure 303 + * @cl: host client 304 + * @length: size of the buffer 305 + * @type: operation type 306 + * @fp: associated file pointer (might be NULL) 428 307 * 429 - * Return: mei_cl_cb pointer or NULL; 308 + * Return: cb on success and NULL on failure 430 309 */ 431 - struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp) 310 + struct mei_cl_cb *mei_cl_alloc_cb(struct mei_cl *cl, size_t length, 311 + enum mei_cb_file_ops type, struct file *fp) 432 312 { 433 313 struct mei_cl_cb *cb; 434 314 435 - cb = kzalloc(sizeof(struct mei_cl_cb), GFP_KERNEL); 315 + cb = mei_io_cb_init(cl, type, fp); 436 316 if (!cb) 437 317 return NULL; 438 318 439 - mei_io_list_init(cb); 319 + if (mei_io_cb_alloc_buf(cb, length)) { 320 + mei_io_cb_free(cb); 321 + return NULL; 322 + } 440 323 441 - cb->file_object = fp; 442 - cb->cl = cl; 443 - cb->buf_idx = 0; 444 324 return cb; 445 325 } 446 326 447 327 /** 448 - * mei_io_cb_alloc_req_buf - allocate request buffer 328 + * mei_cl_read_cb - find this cl's callback in the read list 329 + * for a specific file 449 330 * 450 - * @cb: io callback structure 451 - * @length: size of the buffer 331 + * @cl: host client 332 + * @fp: file pointer (matching cb file object), may be NULL 452 333 * 453 - * Return: 0 on success 454 - * -EINVAL if cb is NULL 455 - * -ENOMEM if allocation failed 334 + * Return: cb on success, NULL if cb is not found 456 335 */ 457 - int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length) 336 + struct mei_cl_cb *mei_cl_read_cb(const struct mei_cl *cl, const struct file *fp) 458 337 { 459 - if (!cb) 460 - return -EINVAL; 338 + struct mei_cl_cb *cb; 461 339 462 - if (length == 0) 463 - return 0; 340 + list_for_each_entry(cb, &cl->rd_completed, list) 341 + if (!fp || fp == cb->file_object) 342 + return cb; 464 343 465 - cb->request_buffer.data = kmalloc(length, GFP_KERNEL); 466 - if (!cb->request_buffer.data) 467 - return -ENOMEM; 468 - cb->request_buffer.size = length; 469 - return 0; 344 + return NULL; 470 345 } 346 + 471 347 /** 472 - * mei_io_cb_alloc_resp_buf - allocate response buffer 348 + * mei_cl_read_cb_flush - free client's read pending and completed cbs 349 + * for a specific file 473 350 * 474 - * @cb: io callback structure 475 - * @length: size of the buffer 476 - * 477 - * Return: 0 on success 478 - * -EINVAL if cb is NULL 479 - * -ENOMEM if allocation failed 351 + * @cl: host client 352 + * @fp: file pointer (matching cb file object), may be NULL 480 353 */ 481 - int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length) 354 + void mei_cl_read_cb_flush(const struct mei_cl *cl, const struct file *fp) 482 355 { 483 - if (!cb) 484 - return -EINVAL; 356 + struct mei_cl_cb *cb, *next; 485 357 486 - if (length == 0) 487 - return 0; 358 + list_for_each_entry_safe(cb, next, &cl->rd_completed, list) 359 + if (!fp || fp == cb->file_object) 360 + mei_io_cb_free(cb); 488 361 489 - cb->response_buffer.data = kmalloc(length, GFP_KERNEL); 490 - if (!cb->response_buffer.data) 491 - return -ENOMEM; 492 - cb->response_buffer.size = length; 493 - return 0; 362 + 363 + list_for_each_entry_safe(cb, next, &cl->rd_pending, list) 364 + if (!fp || fp == cb->file_object) 365 + mei_io_cb_free(cb); 494 366 } 495 - 496 - 497 367 498 368 /** 499 369 * mei_cl_flush_queues - flushes queue lists belonging to cl. 500 370 * 501 371 * @cl: host client 372 + * @fp: file pointer (matching cb file object), may be NULL 502 373 * 503 374 * Return: 0 on success, -EINVAL if cl or cl->dev is NULL. 504 375 */ 505 - int mei_cl_flush_queues(struct mei_cl *cl) 376 + int mei_cl_flush_queues(struct mei_cl *cl, const struct file *fp) 506 377 { 507 378 struct mei_device *dev; 508 379 ··· 516 379 dev = cl->dev; 517 380 518 381 cl_dbg(dev, cl, "remove list entry belonging to cl\n"); 519 - mei_io_list_flush(&cl->dev->read_list, cl); 520 382 mei_io_list_free(&cl->dev->write_list, cl); 521 383 mei_io_list_free(&cl->dev->write_waiting_list, cl); 522 384 mei_io_list_flush(&cl->dev->ctrl_wr_list, cl); 523 385 mei_io_list_flush(&cl->dev->ctrl_rd_list, cl); 524 386 mei_io_list_flush(&cl->dev->amthif_cmd_list, cl); 525 387 mei_io_list_flush(&cl->dev->amthif_rd_complete_list, cl); 388 + 389 + mei_cl_read_cb_flush(cl, fp); 390 + 526 391 return 0; 527 392 } 528 393 ··· 541 402 init_waitqueue_head(&cl->wait); 542 403 init_waitqueue_head(&cl->rx_wait); 543 404 init_waitqueue_head(&cl->tx_wait); 405 + INIT_LIST_HEAD(&cl->rd_completed); 406 + INIT_LIST_HEAD(&cl->rd_pending); 544 407 INIT_LIST_HEAD(&cl->link); 545 408 INIT_LIST_HEAD(&cl->device_link); 546 - cl->reading_state = MEI_IDLE; 547 409 cl->writing_state = MEI_IDLE; 548 410 cl->dev = dev; 549 411 } ··· 569 429 } 570 430 571 431 /** 572 - * mei_cl_find_read_cb - find this cl's callback in the read list 432 + * mei_cl_link - allocate host id in the host map 573 433 * 574 434 * @cl: host client 575 - * 576 - * Return: cb on success, NULL on error 577 - */ 578 - struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl) 579 - { 580 - struct mei_device *dev = cl->dev; 581 - struct mei_cl_cb *cb; 582 - 583 - list_for_each_entry(cb, &dev->read_list.list, list) 584 - if (mei_cl_cmp_id(cl, cb->cl)) 585 - return cb; 586 - return NULL; 587 - } 588 - 589 - /** mei_cl_link: allocate host id in the host map 590 - * 591 - * @cl - host client 592 - * @id - fixed host id or -1 for generic one 435 + * @id: fixed host id or MEI_HOST_CLIENT_ID_ANY (-1) for generic one 593 436 * 594 437 * Return: 0 on success 595 438 * -EINVAL on incorrect values 596 - * -ENONET if client not found 439 + * -EMFILE if open count exceeded. 597 440 */ 598 441 int mei_cl_link(struct mei_cl *cl, int id) 599 442 { ··· 658 535 659 536 void mei_host_client_init(struct work_struct *work) 660 537 { 661 - struct mei_device *dev = container_of(work, 662 - struct mei_device, init_work); 538 + struct mei_device *dev = 539 + container_of(work, struct mei_device, init_work); 663 540 struct mei_me_client *me_cl; 664 - struct mei_client_properties *props; 665 541 666 542 mutex_lock(&dev->device_lock); 667 543 668 - list_for_each_entry(me_cl, &dev->me_clients, list) { 669 - props = &me_cl->props; 670 544 671 - if (!uuid_le_cmp(props->protocol_name, mei_amthif_guid)) 672 - mei_amthif_host_init(dev); 673 - else if (!uuid_le_cmp(props->protocol_name, mei_wd_guid)) 674 - mei_wd_host_init(dev); 675 - else if (!uuid_le_cmp(props->protocol_name, mei_nfc_guid)) 676 - mei_nfc_host_init(dev); 545 + me_cl = mei_me_cl_by_uuid(dev, &mei_amthif_guid); 546 + if (me_cl) 547 + mei_amthif_host_init(dev); 548 + mei_me_cl_put(me_cl); 677 549 678 - } 550 + me_cl = mei_me_cl_by_uuid(dev, &mei_wd_guid); 551 + if (me_cl) 552 + mei_wd_host_init(dev); 553 + mei_me_cl_put(me_cl); 554 + 555 + me_cl = mei_me_cl_by_uuid(dev, &mei_nfc_guid); 556 + if (me_cl) 557 + mei_nfc_host_init(dev); 558 + mei_me_cl_put(me_cl); 559 + 679 560 680 561 dev->dev_state = MEI_DEV_ENABLED; 681 562 dev->reset_count = 0; 682 - 683 563 mutex_unlock(&dev->device_lock); 684 564 685 565 pm_runtime_mark_last_busy(dev->dev); ··· 746 620 return rets; 747 621 } 748 622 749 - cb = mei_io_cb_init(cl, NULL); 750 - if (!cb) { 751 - rets = -ENOMEM; 623 + cb = mei_io_cb_init(cl, MEI_FOP_DISCONNECT, NULL); 624 + rets = cb ? 0 : -ENOMEM; 625 + if (rets) 752 626 goto free; 753 - } 754 - 755 - cb->fop_type = MEI_FOP_DISCONNECT; 756 627 757 628 if (mei_hbuf_acquire(dev)) { 758 629 if (mei_hbm_cl_disconnect_req(dev, cl)) { ··· 850 727 return rets; 851 728 } 852 729 853 - cb = mei_io_cb_init(cl, file); 854 - if (!cb) { 855 - rets = -ENOMEM; 730 + cb = mei_io_cb_init(cl, MEI_FOP_CONNECT, file); 731 + rets = cb ? 0 : -ENOMEM; 732 + if (rets) 856 733 goto out; 857 - } 858 - 859 - cb->fop_type = MEI_FOP_CONNECT; 860 734 861 735 /* run hbuf acquire last so we don't have to undo */ 862 736 if (!mei_cl_is_other_connecting(cl) && mei_hbuf_acquire(dev)) { ··· 876 756 mei_secs_to_jiffies(MEI_CL_CONNECT_TIMEOUT)); 877 757 mutex_lock(&dev->device_lock); 878 758 879 - if (cl->state != MEI_FILE_CONNECTED) { 759 + if (!mei_cl_is_connected(cl)) { 880 760 cl->state = MEI_FILE_DISCONNECTED; 881 761 /* something went really wrong */ 882 762 if (!cl->status) ··· 896 776 mei_io_cb_free(cb); 897 777 return rets; 898 778 } 779 + 780 + /** 781 + * mei_cl_alloc_linked - allocate and link host client 782 + * 783 + * @dev: the device structure 784 + * @id: fixed host id or MEI_HOST_CLIENT_ID_ANY (-1) for generic one 785 + * 786 + * Return: cl on success ERR_PTR on failure 787 + */ 788 + struct mei_cl *mei_cl_alloc_linked(struct mei_device *dev, int id) 789 + { 790 + struct mei_cl *cl; 791 + int ret; 792 + 793 + cl = mei_cl_allocate(dev); 794 + if (!cl) { 795 + ret = -ENOMEM; 796 + goto err; 797 + } 798 + 799 + ret = mei_cl_link(cl, id); 800 + if (ret) 801 + goto err; 802 + 803 + return cl; 804 + err: 805 + kfree(cl); 806 + return ERR_PTR(ret); 807 + } 808 + 809 + 899 810 900 811 /** 901 812 * mei_cl_flow_ctrl_creds - checks flow_control credits for cl. ··· 1017 866 * 1018 867 * @cl: host client 1019 868 * @length: number of bytes to read 869 + * @fp: pointer to file structure 1020 870 * 1021 871 * Return: 0 on success, <0 on failure. 1022 872 */ 1023 - int mei_cl_read_start(struct mei_cl *cl, size_t length) 873 + int mei_cl_read_start(struct mei_cl *cl, size_t length, struct file *fp) 1024 874 { 1025 875 struct mei_device *dev; 1026 876 struct mei_cl_cb *cb; ··· 1036 884 if (!mei_cl_is_connected(cl)) 1037 885 return -ENODEV; 1038 886 1039 - if (cl->read_cb) { 1040 - cl_dbg(dev, cl, "read is pending.\n"); 887 + /* HW currently supports only one pending read */ 888 + if (!list_empty(&cl->rd_pending)) 1041 889 return -EBUSY; 1042 - } 890 + 1043 891 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id); 1044 892 if (!me_cl) { 1045 893 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id); ··· 1056 904 return rets; 1057 905 } 1058 906 1059 - cb = mei_io_cb_init(cl, NULL); 1060 - if (!cb) { 1061 - rets = -ENOMEM; 1062 - goto out; 1063 - } 1064 - 1065 - rets = mei_io_cb_alloc_resp_buf(cb, length); 907 + cb = mei_cl_alloc_cb(cl, length, MEI_FOP_READ, fp); 908 + rets = cb ? 0 : -ENOMEM; 1066 909 if (rets) 1067 910 goto out; 1068 911 1069 - cb->fop_type = MEI_FOP_READ; 1070 912 if (mei_hbuf_acquire(dev)) { 1071 913 rets = mei_hbm_cl_flow_control_req(dev, cl); 1072 914 if (rets < 0) 1073 915 goto out; 1074 916 1075 - list_add_tail(&cb->list, &dev->read_list.list); 917 + list_add_tail(&cb->list, &cl->rd_pending); 1076 918 } else { 1077 919 list_add_tail(&cb->list, &dev->ctrl_wr_list.list); 1078 920 } 1079 - 1080 - cl->read_cb = cb; 1081 921 1082 922 out: 1083 923 cl_dbg(dev, cl, "rpm: autosuspend\n"); ··· 1108 964 1109 965 dev = cl->dev; 1110 966 1111 - buf = &cb->request_buffer; 967 + buf = &cb->buf; 1112 968 1113 969 rets = mei_cl_flow_ctrl_creds(cl); 1114 970 if (rets < 0) ··· 1143 999 } 1144 1000 1145 1001 cl_dbg(dev, cl, "buf: size = %d idx = %lu\n", 1146 - cb->request_buffer.size, cb->buf_idx); 1002 + cb->buf.size, cb->buf_idx); 1147 1003 1148 1004 rets = mei_write_message(dev, &mei_hdr, buf->data + cb->buf_idx); 1149 1005 if (rets) { ··· 1155 1011 cl->status = 0; 1156 1012 cl->writing_state = MEI_WRITING; 1157 1013 cb->buf_idx += mei_hdr.length; 1014 + cb->completed = mei_hdr.msg_complete == 1; 1158 1015 1159 1016 if (mei_hdr.msg_complete) { 1160 1017 if (mei_cl_flow_ctrl_reduce(cl)) ··· 1193 1048 dev = cl->dev; 1194 1049 1195 1050 1196 - buf = &cb->request_buffer; 1051 + buf = &cb->buf; 1197 1052 1198 1053 cl_dbg(dev, cl, "size=%d\n", buf->size); 1199 1054 ··· 1204 1059 return rets; 1205 1060 } 1206 1061 1207 - cb->fop_type = MEI_FOP_WRITE; 1208 1062 cb->buf_idx = 0; 1209 1063 cl->writing_state = MEI_IDLE; 1210 1064 ··· 1243 1099 1244 1100 cl->writing_state = MEI_WRITING; 1245 1101 cb->buf_idx = mei_hdr.length; 1102 + cb->completed = mei_hdr.msg_complete == 1; 1246 1103 1247 1104 out: 1248 1105 if (mei_hdr.msg_complete) { ··· 1296 1151 if (waitqueue_active(&cl->tx_wait)) 1297 1152 wake_up_interruptible(&cl->tx_wait); 1298 1153 1299 - } else if (cb->fop_type == MEI_FOP_READ && 1300 - MEI_READING == cl->reading_state) { 1301 - cl->reading_state = MEI_READ_COMPLETE; 1154 + } else if (cb->fop_type == MEI_FOP_READ) { 1155 + list_add_tail(&cb->list, &cl->rd_completed); 1302 1156 if (waitqueue_active(&cl->rx_wait)) 1303 - wake_up_interruptible(&cl->rx_wait); 1157 + wake_up_interruptible_all(&cl->rx_wait); 1304 1158 else 1305 1159 mei_cl_bus_rx_event(cl); 1306 1160
+26 -16
drivers/misc/mei/client.h
··· 31 31 void mei_me_cl_put(struct mei_me_client *me_cl); 32 32 struct mei_me_client *mei_me_cl_get(struct mei_me_client *me_cl); 33 33 34 - struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev, 34 + void mei_me_cl_add(struct mei_device *dev, struct mei_me_client *me_cl); 35 + void mei_me_cl_del(struct mei_device *dev, struct mei_me_client *me_cl); 36 + 37 + struct mei_me_client *mei_me_cl_by_uuid(struct mei_device *dev, 35 38 const uuid_le *uuid); 36 39 struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id); 37 40 struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev, ··· 47 44 /* 48 45 * MEI IO Functions 49 46 */ 50 - struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp); 47 + struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, enum mei_cb_file_ops type, 48 + struct file *fp); 51 49 void mei_io_cb_free(struct mei_cl_cb *priv_cb); 52 - int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length); 53 - int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length); 50 + int mei_io_cb_alloc_buf(struct mei_cl_cb *cb, size_t length); 54 51 55 52 56 53 /** ··· 75 72 int mei_cl_link(struct mei_cl *cl, int id); 76 73 int mei_cl_unlink(struct mei_cl *cl); 77 74 78 - int mei_cl_flush_queues(struct mei_cl *cl); 79 - struct mei_cl_cb *mei_cl_find_read_cb(struct mei_cl *cl); 75 + struct mei_cl *mei_cl_alloc_linked(struct mei_device *dev, int id); 80 76 77 + struct mei_cl_cb *mei_cl_read_cb(const struct mei_cl *cl, 78 + const struct file *fp); 79 + void mei_cl_read_cb_flush(const struct mei_cl *cl, const struct file *fp); 80 + struct mei_cl_cb *mei_cl_alloc_cb(struct mei_cl *cl, size_t length, 81 + enum mei_cb_file_ops type, struct file *fp); 82 + int mei_cl_flush_queues(struct mei_cl *cl, const struct file *fp); 81 83 82 84 int mei_cl_flow_ctrl_creds(struct mei_cl *cl); 83 85 ··· 90 82 /* 91 83 * MEI input output function prototype 92 84 */ 85 + 86 + /** 87 + * mei_cl_is_connected - host client is connected 88 + * 89 + * @cl: host clinet 90 + * 91 + * Return: true if the host clinet is connected 92 + */ 93 93 static inline bool mei_cl_is_connected(struct mei_cl *cl) 94 94 { 95 - return cl->dev && 96 - cl->dev->dev_state == MEI_DEV_ENABLED && 97 - cl->state == MEI_FILE_CONNECTED; 98 - } 99 - static inline bool mei_cl_is_transitioning(struct mei_cl *cl) 100 - { 101 - return MEI_FILE_INITIALIZING == cl->state || 102 - MEI_FILE_DISCONNECTED == cl->state || 103 - MEI_FILE_DISCONNECTING == cl->state; 95 + return cl->state == MEI_FILE_CONNECTED; 104 96 } 105 97 106 98 bool mei_cl_is_other_connecting(struct mei_cl *cl); 107 99 int mei_cl_disconnect(struct mei_cl *cl); 108 100 int mei_cl_connect(struct mei_cl *cl, struct file *file); 109 - int mei_cl_read_start(struct mei_cl *cl, size_t length); 101 + int mei_cl_read_start(struct mei_cl *cl, size_t length, struct file *fp); 102 + int mei_cl_irq_read_msg(struct mei_cl *cl, struct mei_msg_hdr *hdr, 103 + struct mei_cl_cb *cmpl_list); 110 104 int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb, bool blocking); 111 105 int mei_cl_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, 112 106 struct mei_cl_cb *cmpl_list);
+10 -11
drivers/misc/mei/debugfs.c
··· 28 28 size_t cnt, loff_t *ppos) 29 29 { 30 30 struct mei_device *dev = fp->private_data; 31 - struct mei_me_client *me_cl, *n; 31 + struct mei_me_client *me_cl; 32 32 size_t bufsz = 1; 33 33 char *buf; 34 34 int i = 0; ··· 38 38 #define HDR \ 39 39 " |id|fix| UUID |con|msg len|sb|refc|\n" 40 40 41 - mutex_lock(&dev->device_lock); 42 - 41 + down_read(&dev->me_clients_rwsem); 43 42 list_for_each_entry(me_cl, &dev->me_clients, list) 44 43 bufsz++; 45 44 46 45 bufsz *= sizeof(HDR) + 1; 47 46 buf = kzalloc(bufsz, GFP_KERNEL); 48 47 if (!buf) { 49 - mutex_unlock(&dev->device_lock); 48 + up_read(&dev->me_clients_rwsem); 50 49 return -ENOMEM; 51 50 } 52 51 ··· 55 56 if (dev->dev_state != MEI_DEV_ENABLED) 56 57 goto out; 57 58 58 - list_for_each_entry_safe(me_cl, n, &dev->me_clients, list) { 59 + list_for_each_entry(me_cl, &dev->me_clients, list) { 59 60 60 - me_cl = mei_me_cl_get(me_cl); 61 - if (me_cl) { 61 + if (mei_me_cl_get(me_cl)) { 62 62 pos += scnprintf(buf + pos, bufsz - pos, 63 63 "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|%4d|\n", 64 64 i++, me_cl->client_id, ··· 67 69 me_cl->props.max_msg_length, 68 70 me_cl->props.single_recv_buf, 69 71 atomic_read(&me_cl->refcnt.refcount)); 70 - } 71 72 72 - mei_me_cl_put(me_cl); 73 + mei_me_cl_put(me_cl); 74 + } 73 75 } 76 + 74 77 out: 75 - mutex_unlock(&dev->device_lock); 78 + up_read(&dev->me_clients_rwsem); 76 79 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos); 77 80 kfree(buf); 78 81 return ret; ··· 117 118 pos += scnprintf(buf + pos, bufsz - pos, 118 119 "%2d|%2d|%4d|%5d|%2d|%2d|\n", 119 120 i, cl->me_client_id, cl->host_client_id, cl->state, 120 - cl->reading_state, cl->writing_state); 121 + !list_empty(&cl->rd_completed), cl->writing_state); 121 122 i++; 122 123 } 123 124 out:
+4 -4
drivers/misc/mei/hbm.c
··· 338 338 me_cl->client_id = res->me_addr; 339 339 me_cl->mei_flow_ctrl_creds = 0; 340 340 341 - list_add(&me_cl->list, &dev->me_clients); 341 + mei_me_cl_add(dev, me_cl); 342 + 342 343 return 0; 343 344 } 344 345 ··· 639 638 continue; 640 639 641 640 if (mei_hbm_cl_addr_equal(cl, rs)) { 642 - list_del(&cb->list); 641 + list_del_init(&cb->list); 643 642 break; 644 643 } 645 644 } ··· 684 683 cl->state = MEI_FILE_DISCONNECTED; 685 684 cl->timer_count = 0; 686 685 687 - cb = mei_io_cb_init(cl, NULL); 686 + cb = mei_io_cb_init(cl, MEI_FOP_DISCONNECT_RSP, NULL); 688 687 if (!cb) 689 688 return -ENOMEM; 690 - cb->fop_type = MEI_FOP_DISCONNECT_RSP; 691 689 cl_dbg(dev, cl, "add disconnect response as first\n"); 692 690 list_add(&cb->list, &dev->ctrl_wr_list.list); 693 691 }
+101 -69
drivers/misc/mei/hw-me.c
··· 25 25 #include "hw-me.h" 26 26 #include "hw-me-regs.h" 27 27 28 + #include "mei-trace.h" 29 + 28 30 /** 29 31 * mei_me_reg_read - Reads 32bit data from the mei device 30 32 * ··· 63 61 * 64 62 * Return: ME_CB_RW register value (u32) 65 63 */ 66 - static u32 mei_me_mecbrw_read(const struct mei_device *dev) 64 + static inline u32 mei_me_mecbrw_read(const struct mei_device *dev) 67 65 { 68 66 return mei_me_reg_read(to_me_hw(dev), ME_CB_RW); 69 67 } 68 + 69 + /** 70 + * mei_me_hcbww_write - write 32bit data to the host circular buffer 71 + * 72 + * @dev: the device structure 73 + * @data: 32bit data to be written to the host circular buffer 74 + */ 75 + static inline void mei_me_hcbww_write(struct mei_device *dev, u32 data) 76 + { 77 + mei_me_reg_write(to_me_hw(dev), H_CB_WW, data); 78 + } 79 + 70 80 /** 71 81 * mei_me_mecsr_read - Reads 32bit data from the ME CSR 72 82 * 73 - * @hw: the me hardware structure 83 + * @dev: the device structure 74 84 * 75 85 * Return: ME_CSR_HA register value (u32) 76 86 */ 77 - static inline u32 mei_me_mecsr_read(const struct mei_me_hw *hw) 87 + static inline u32 mei_me_mecsr_read(const struct mei_device *dev) 78 88 { 79 - return mei_me_reg_read(hw, ME_CSR_HA); 89 + u32 reg; 90 + 91 + reg = mei_me_reg_read(to_me_hw(dev), ME_CSR_HA); 92 + trace_mei_reg_read(dev->dev, "ME_CSR_HA", ME_CSR_HA, reg); 93 + 94 + return reg; 80 95 } 81 96 82 97 /** 83 98 * mei_hcsr_read - Reads 32bit data from the host CSR 84 99 * 85 - * @hw: the me hardware structure 100 + * @dev: the device structure 86 101 * 87 102 * Return: H_CSR register value (u32) 88 103 */ 89 - static inline u32 mei_hcsr_read(const struct mei_me_hw *hw) 104 + static inline u32 mei_hcsr_read(const struct mei_device *dev) 90 105 { 91 - return mei_me_reg_read(hw, H_CSR); 106 + u32 reg; 107 + 108 + reg = mei_me_reg_read(to_me_hw(dev), H_CSR); 109 + trace_mei_reg_read(dev->dev, "H_CSR", H_CSR, reg); 110 + 111 + return reg; 112 + } 113 + 114 + /** 115 + * mei_hcsr_write - writes H_CSR register to the mei device 116 + * 117 + * @dev: the device structure 118 + * @reg: new register value 119 + */ 120 + static inline void mei_hcsr_write(struct mei_device *dev, u32 reg) 121 + { 122 + trace_mei_reg_write(dev->dev, "H_CSR", H_CSR, reg); 123 + mei_me_reg_write(to_me_hw(dev), H_CSR, reg); 92 124 } 93 125 94 126 /** 95 127 * mei_hcsr_set - writes H_CSR register to the mei device, 96 128 * and ignores the H_IS bit for it is write-one-to-zero. 97 129 * 98 - * @hw: the me hardware structure 99 - * @hcsr: new register value 130 + * @dev: the device structure 131 + * @reg: new register value 100 132 */ 101 - static inline void mei_hcsr_set(struct mei_me_hw *hw, u32 hcsr) 133 + static inline void mei_hcsr_set(struct mei_device *dev, u32 reg) 102 134 { 103 - hcsr &= ~H_IS; 104 - mei_me_reg_write(hw, H_CSR, hcsr); 135 + reg &= ~H_IS; 136 + mei_hcsr_write(dev, reg); 105 137 } 106 138 107 139 /** ··· 177 141 static void mei_me_hw_config(struct mei_device *dev) 178 142 { 179 143 struct mei_me_hw *hw = to_me_hw(dev); 180 - u32 hcsr = mei_hcsr_read(to_me_hw(dev)); 144 + u32 hcsr = mei_hcsr_read(dev); 181 145 /* Doesn't change in runtime */ 182 146 dev->hbuf_depth = (hcsr & H_CBD) >> 24; 183 147 ··· 206 170 */ 207 171 static void mei_me_intr_clear(struct mei_device *dev) 208 172 { 209 - struct mei_me_hw *hw = to_me_hw(dev); 210 - u32 hcsr = mei_hcsr_read(hw); 173 + u32 hcsr = mei_hcsr_read(dev); 211 174 212 175 if ((hcsr & H_IS) == H_IS) 213 - mei_me_reg_write(hw, H_CSR, hcsr); 176 + mei_hcsr_write(dev, hcsr); 214 177 } 215 178 /** 216 179 * mei_me_intr_enable - enables mei device interrupts ··· 218 183 */ 219 184 static void mei_me_intr_enable(struct mei_device *dev) 220 185 { 221 - struct mei_me_hw *hw = to_me_hw(dev); 222 - u32 hcsr = mei_hcsr_read(hw); 186 + u32 hcsr = mei_hcsr_read(dev); 223 187 224 188 hcsr |= H_IE; 225 - mei_hcsr_set(hw, hcsr); 189 + mei_hcsr_set(dev, hcsr); 226 190 } 227 191 228 192 /** ··· 231 197 */ 232 198 static void mei_me_intr_disable(struct mei_device *dev) 233 199 { 234 - struct mei_me_hw *hw = to_me_hw(dev); 235 - u32 hcsr = mei_hcsr_read(hw); 200 + u32 hcsr = mei_hcsr_read(dev); 236 201 237 202 hcsr &= ~H_IE; 238 - mei_hcsr_set(hw, hcsr); 203 + mei_hcsr_set(dev, hcsr); 239 204 } 240 205 241 206 /** ··· 244 211 */ 245 212 static void mei_me_hw_reset_release(struct mei_device *dev) 246 213 { 247 - struct mei_me_hw *hw = to_me_hw(dev); 248 - u32 hcsr = mei_hcsr_read(hw); 214 + u32 hcsr = mei_hcsr_read(dev); 249 215 250 216 hcsr |= H_IG; 251 217 hcsr &= ~H_RST; 252 - mei_hcsr_set(hw, hcsr); 218 + mei_hcsr_set(dev, hcsr); 253 219 254 220 /* complete this write before we set host ready on another CPU */ 255 221 mmiowb(); ··· 263 231 */ 264 232 static int mei_me_hw_reset(struct mei_device *dev, bool intr_enable) 265 233 { 266 - struct mei_me_hw *hw = to_me_hw(dev); 267 - u32 hcsr = mei_hcsr_read(hw); 234 + u32 hcsr = mei_hcsr_read(dev); 268 235 269 236 /* H_RST may be found lit before reset is started, 270 237 * for example if preceding reset flow hasn't completed. ··· 273 242 if ((hcsr & H_RST) == H_RST) { 274 243 dev_warn(dev->dev, "H_RST is set = 0x%08X", hcsr); 275 244 hcsr &= ~H_RST; 276 - mei_hcsr_set(hw, hcsr); 277 - hcsr = mei_hcsr_read(hw); 245 + mei_hcsr_set(dev, hcsr); 246 + hcsr = mei_hcsr_read(dev); 278 247 } 279 248 280 249 hcsr |= H_RST | H_IG | H_IS; ··· 285 254 hcsr &= ~H_IE; 286 255 287 256 dev->recvd_hw_ready = false; 288 - mei_me_reg_write(hw, H_CSR, hcsr); 257 + mei_hcsr_write(dev, hcsr); 289 258 290 259 /* 291 260 * Host reads the H_CSR once to ensure that the 292 261 * posted write to H_CSR completes. 293 262 */ 294 - hcsr = mei_hcsr_read(hw); 263 + hcsr = mei_hcsr_read(dev); 295 264 296 265 if ((hcsr & H_RST) == 0) 297 266 dev_warn(dev->dev, "H_RST is not set = 0x%08X", hcsr); ··· 312 281 */ 313 282 static void mei_me_host_set_ready(struct mei_device *dev) 314 283 { 315 - struct mei_me_hw *hw = to_me_hw(dev); 316 - u32 hcsr = mei_hcsr_read(hw); 284 + u32 hcsr = mei_hcsr_read(dev); 317 285 318 286 hcsr |= H_IE | H_IG | H_RDY; 319 - mei_hcsr_set(hw, hcsr); 287 + mei_hcsr_set(dev, hcsr); 320 288 } 321 289 322 290 /** ··· 326 296 */ 327 297 static bool mei_me_host_is_ready(struct mei_device *dev) 328 298 { 329 - struct mei_me_hw *hw = to_me_hw(dev); 330 - u32 hcsr = mei_hcsr_read(hw); 299 + u32 hcsr = mei_hcsr_read(dev); 331 300 332 301 return (hcsr & H_RDY) == H_RDY; 333 302 } ··· 339 310 */ 340 311 static bool mei_me_hw_is_ready(struct mei_device *dev) 341 312 { 342 - struct mei_me_hw *hw = to_me_hw(dev); 343 - u32 mecsr = mei_me_mecsr_read(hw); 313 + u32 mecsr = mei_me_mecsr_read(dev); 344 314 345 315 return (mecsr & ME_RDY_HRA) == ME_RDY_HRA; 346 316 } ··· 396 368 */ 397 369 static unsigned char mei_hbuf_filled_slots(struct mei_device *dev) 398 370 { 399 - struct mei_me_hw *hw = to_me_hw(dev); 400 371 u32 hcsr; 401 372 char read_ptr, write_ptr; 402 373 403 - hcsr = mei_hcsr_read(hw); 374 + hcsr = mei_hcsr_read(dev); 404 375 405 376 read_ptr = (char) ((hcsr & H_CBRP) >> 8); 406 377 write_ptr = (char) ((hcsr & H_CBWP) >> 16); ··· 466 439 struct mei_msg_hdr *header, 467 440 unsigned char *buf) 468 441 { 469 - struct mei_me_hw *hw = to_me_hw(dev); 470 442 unsigned long rem; 471 443 unsigned long length = header->length; 472 444 u32 *reg_buf = (u32 *)buf; ··· 483 457 if (empty_slots < 0 || dw_cnt > empty_slots) 484 458 return -EMSGSIZE; 485 459 486 - mei_me_reg_write(hw, H_CB_WW, *((u32 *) header)); 460 + mei_me_hcbww_write(dev, *((u32 *) header)); 487 461 488 462 for (i = 0; i < length / 4; i++) 489 - mei_me_reg_write(hw, H_CB_WW, reg_buf[i]); 463 + mei_me_hcbww_write(dev, reg_buf[i]); 490 464 491 465 rem = length & 0x3; 492 466 if (rem > 0) { 493 467 u32 reg = 0; 494 468 495 469 memcpy(&reg, &buf[length - rem], rem); 496 - mei_me_reg_write(hw, H_CB_WW, reg); 470 + mei_me_hcbww_write(dev, reg); 497 471 } 498 472 499 - hcsr = mei_hcsr_read(hw) | H_IG; 500 - mei_hcsr_set(hw, hcsr); 473 + hcsr = mei_hcsr_read(dev) | H_IG; 474 + mei_hcsr_set(dev, hcsr); 501 475 if (!mei_me_hw_is_ready(dev)) 502 476 return -EIO; 503 477 ··· 513 487 */ 514 488 static int mei_me_count_full_read_slots(struct mei_device *dev) 515 489 { 516 - struct mei_me_hw *hw = to_me_hw(dev); 517 490 u32 me_csr; 518 491 char read_ptr, write_ptr; 519 492 unsigned char buffer_depth, filled_slots; 520 493 521 - me_csr = mei_me_mecsr_read(hw); 494 + me_csr = mei_me_mecsr_read(dev); 522 495 buffer_depth = (unsigned char)((me_csr & ME_CBD_HRA) >> 24); 523 496 read_ptr = (char) ((me_csr & ME_CBRP_HRA) >> 8); 524 497 write_ptr = (char) ((me_csr & ME_CBWP_HRA) >> 16); ··· 543 518 static int mei_me_read_slots(struct mei_device *dev, unsigned char *buffer, 544 519 unsigned long buffer_length) 545 520 { 546 - struct mei_me_hw *hw = to_me_hw(dev); 547 521 u32 *reg_buf = (u32 *)buffer; 548 522 u32 hcsr; 549 523 ··· 555 531 memcpy(reg_buf, &reg, buffer_length); 556 532 } 557 533 558 - hcsr = mei_hcsr_read(hw) | H_IG; 559 - mei_hcsr_set(hw, hcsr); 534 + hcsr = mei_hcsr_read(dev) | H_IG; 535 + mei_hcsr_set(dev, hcsr); 560 536 return 0; 561 537 } 562 538 563 539 /** 564 - * mei_me_pg_enter - write pg enter register 540 + * mei_me_pg_set - write pg enter register 565 541 * 566 542 * @dev: the device structure 567 543 */ 568 - static void mei_me_pg_enter(struct mei_device *dev) 544 + static void mei_me_pg_set(struct mei_device *dev) 569 545 { 570 546 struct mei_me_hw *hw = to_me_hw(dev); 571 - u32 reg = mei_me_reg_read(hw, H_HPG_CSR); 547 + u32 reg; 548 + 549 + reg = mei_me_reg_read(hw, H_HPG_CSR); 550 + trace_mei_reg_read(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg); 572 551 573 552 reg |= H_HPG_CSR_PGI; 553 + 554 + trace_mei_reg_write(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg); 574 555 mei_me_reg_write(hw, H_HPG_CSR, reg); 575 556 } 576 557 577 558 /** 578 - * mei_me_pg_exit - write pg exit register 559 + * mei_me_pg_unset - write pg exit register 579 560 * 580 561 * @dev: the device structure 581 562 */ 582 - static void mei_me_pg_exit(struct mei_device *dev) 563 + static void mei_me_pg_unset(struct mei_device *dev) 583 564 { 584 565 struct mei_me_hw *hw = to_me_hw(dev); 585 - u32 reg = mei_me_reg_read(hw, H_HPG_CSR); 566 + u32 reg; 567 + 568 + reg = mei_me_reg_read(hw, H_HPG_CSR); 569 + trace_mei_reg_read(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg); 586 570 587 571 WARN(!(reg & H_HPG_CSR_PGI), "PGI is not set\n"); 588 572 589 573 reg |= H_HPG_CSR_PGIHEXR; 574 + 575 + trace_mei_reg_write(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg); 590 576 mei_me_reg_write(hw, H_HPG_CSR, reg); 591 577 } 592 578 593 579 /** 594 - * mei_me_pg_set_sync - perform pg entry procedure 580 + * mei_me_pg_enter_sync - perform pg entry procedure 595 581 * 596 582 * @dev: the device structure 597 583 * 598 584 * Return: 0 on success an error code otherwise 599 585 */ 600 - int mei_me_pg_set_sync(struct mei_device *dev) 586 + int mei_me_pg_enter_sync(struct mei_device *dev) 601 587 { 602 588 struct mei_me_hw *hw = to_me_hw(dev); 603 589 unsigned long timeout = mei_secs_to_jiffies(MEI_PGI_TIMEOUT); ··· 625 591 mutex_lock(&dev->device_lock); 626 592 627 593 if (dev->pg_event == MEI_PG_EVENT_RECEIVED) { 628 - mei_me_pg_enter(dev); 594 + mei_me_pg_set(dev); 629 595 ret = 0; 630 596 } else { 631 597 ret = -ETIME; ··· 638 604 } 639 605 640 606 /** 641 - * mei_me_pg_unset_sync - perform pg exit procedure 607 + * mei_me_pg_exit_sync - perform pg exit procedure 642 608 * 643 609 * @dev: the device structure 644 610 * 645 611 * Return: 0 on success an error code otherwise 646 612 */ 647 - int mei_me_pg_unset_sync(struct mei_device *dev) 613 + int mei_me_pg_exit_sync(struct mei_device *dev) 648 614 { 649 615 struct mei_me_hw *hw = to_me_hw(dev); 650 616 unsigned long timeout = mei_secs_to_jiffies(MEI_PGI_TIMEOUT); ··· 655 621 656 622 dev->pg_event = MEI_PG_EVENT_WAIT; 657 623 658 - mei_me_pg_exit(dev); 624 + mei_me_pg_unset(dev); 659 625 660 626 mutex_unlock(&dev->device_lock); 661 627 wait_event_timeout(dev->wait_pg, ··· 683 649 */ 684 650 static bool mei_me_pg_is_enabled(struct mei_device *dev) 685 651 { 686 - struct mei_me_hw *hw = to_me_hw(dev); 687 - u32 reg = mei_me_reg_read(hw, ME_CSR_HA); 652 + u32 reg = mei_me_mecsr_read(dev); 688 653 689 654 if ((reg & ME_PGIC_HRA) == 0) 690 655 goto notsupported; ··· 716 683 irqreturn_t mei_me_irq_quick_handler(int irq, void *dev_id) 717 684 { 718 685 struct mei_device *dev = (struct mei_device *) dev_id; 719 - struct mei_me_hw *hw = to_me_hw(dev); 720 - u32 csr_reg = mei_hcsr_read(hw); 686 + u32 hcsr = mei_hcsr_read(dev); 721 687 722 - if ((csr_reg & H_IS) != H_IS) 688 + if ((hcsr & H_IS) != H_IS) 723 689 return IRQ_NONE; 724 690 725 691 /* clear H_IS bit in H_CSR */ 726 - mei_me_reg_write(hw, H_CSR, csr_reg); 692 + mei_hcsr_write(dev, hcsr); 727 693 728 694 return IRQ_WAKE_THREAD; 729 695 }
+2 -2
drivers/misc/mei/hw-me.h
··· 71 71 struct mei_device *mei_me_dev_init(struct pci_dev *pdev, 72 72 const struct mei_cfg *cfg); 73 73 74 - int mei_me_pg_set_sync(struct mei_device *dev); 75 - int mei_me_pg_unset_sync(struct mei_device *dev); 74 + int mei_me_pg_enter_sync(struct mei_device *dev); 75 + int mei_me_pg_exit_sync(struct mei_device *dev); 76 76 77 77 irqreturn_t mei_me_irq_quick_handler(int irq, void *dev_id); 78 78 irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id);
+1 -1
drivers/misc/mei/hw-txe.c
··· 412 412 mei_txe_br_reg_write(hw, HIER_REG, 0); 413 413 } 414 414 /** 415 - * mei_txe_intr_disable - enable all interrupts 415 + * mei_txe_intr_enable - enable all interrupts 416 416 * 417 417 * @dev: the device structure 418 418 */
+1 -1
drivers/misc/mei/init.c
··· 389 389 INIT_LIST_HEAD(&dev->device_list); 390 390 INIT_LIST_HEAD(&dev->me_clients); 391 391 mutex_init(&dev->device_lock); 392 + init_rwsem(&dev->me_clients_rwsem); 392 393 init_waitqueue_head(&dev->wait_hw_ready); 393 394 init_waitqueue_head(&dev->wait_pg); 394 395 init_waitqueue_head(&dev->wait_hbm_start); ··· 397 396 dev->dev_state = MEI_DEV_INITIALIZING; 398 397 dev->reset_count = 0; 399 398 400 - mei_io_list_init(&dev->read_list); 401 399 mei_io_list_init(&dev->write_list); 402 400 mei_io_list_init(&dev->write_waiting_list); 403 401 mei_io_list_init(&dev->ctrl_wr_list);
+76 -105
drivers/misc/mei/interrupt.c
··· 43 43 44 44 list_for_each_entry_safe(cb, next, &compl_list->list, list) { 45 45 cl = cb->cl; 46 - list_del(&cb->list); 46 + list_del_init(&cb->list); 47 47 48 48 dev_dbg(dev->dev, "completing call back.\n"); 49 49 if (cl == &dev->iamthif_cl) ··· 68 68 return cl->host_client_id == mei_hdr->host_addr && 69 69 cl->me_client_id == mei_hdr->me_addr; 70 70 } 71 + 71 72 /** 72 - * mei_cl_is_reading - checks if the client 73 - * is the one to read this message 73 + * mei_irq_discard_msg - discard received message 74 74 * 75 - * @cl: mei client 76 - * @mei_hdr: header of mei message 77 - * 78 - * Return: true on match and false otherwise 75 + * @dev: mei device 76 + * @hdr: message header 79 77 */ 80 - static bool mei_cl_is_reading(struct mei_cl *cl, struct mei_msg_hdr *mei_hdr) 78 + static inline 79 + void mei_irq_discard_msg(struct mei_device *dev, struct mei_msg_hdr *hdr) 81 80 { 82 - return mei_cl_hbm_equal(cl, mei_hdr) && 83 - cl->state == MEI_FILE_CONNECTED && 84 - cl->reading_state != MEI_READ_COMPLETE; 81 + /* 82 + * no need to check for size as it is guarantied 83 + * that length fits into rd_msg_buf 84 + */ 85 + mei_read_slots(dev, dev->rd_msg_buf, hdr->length); 86 + dev_dbg(dev->dev, "discarding message " MEI_HDR_FMT "\n", 87 + MEI_HDR_PRM(hdr)); 85 88 } 86 89 87 90 /** 88 91 * mei_cl_irq_read_msg - process client message 89 92 * 90 - * @dev: the device structure 93 + * @cl: reading client 91 94 * @mei_hdr: header of mei client message 92 - * @complete_list: An instance of our list structure 95 + * @complete_list: completion list 93 96 * 94 - * Return: 0 on success, <0 on failure. 97 + * Return: always 0 95 98 */ 96 - static int mei_cl_irq_read_msg(struct mei_device *dev, 97 - struct mei_msg_hdr *mei_hdr, 98 - struct mei_cl_cb *complete_list) 99 + int mei_cl_irq_read_msg(struct mei_cl *cl, 100 + struct mei_msg_hdr *mei_hdr, 101 + struct mei_cl_cb *complete_list) 99 102 { 100 - struct mei_cl *cl; 101 - struct mei_cl_cb *cb, *next; 103 + struct mei_device *dev = cl->dev; 104 + struct mei_cl_cb *cb; 102 105 unsigned char *buffer = NULL; 103 106 104 - list_for_each_entry_safe(cb, next, &dev->read_list.list, list) { 105 - cl = cb->cl; 106 - if (!mei_cl_is_reading(cl, mei_hdr)) 107 - continue; 108 - 109 - cl->reading_state = MEI_READING; 110 - 111 - if (cb->response_buffer.size == 0 || 112 - cb->response_buffer.data == NULL) { 113 - cl_err(dev, cl, "response buffer is not allocated.\n"); 114 - list_del(&cb->list); 115 - return -ENOMEM; 116 - } 117 - 118 - if (cb->response_buffer.size < mei_hdr->length + cb->buf_idx) { 119 - cl_dbg(dev, cl, "message overflow. size %d len %d idx %ld\n", 120 - cb->response_buffer.size, 121 - mei_hdr->length, cb->buf_idx); 122 - buffer = krealloc(cb->response_buffer.data, 123 - mei_hdr->length + cb->buf_idx, 124 - GFP_KERNEL); 125 - 126 - if (!buffer) { 127 - list_del(&cb->list); 128 - return -ENOMEM; 129 - } 130 - cb->response_buffer.data = buffer; 131 - cb->response_buffer.size = 132 - mei_hdr->length + cb->buf_idx; 133 - } 134 - 135 - buffer = cb->response_buffer.data + cb->buf_idx; 136 - mei_read_slots(dev, buffer, mei_hdr->length); 137 - 138 - cb->buf_idx += mei_hdr->length; 139 - if (mei_hdr->msg_complete) { 140 - cl->status = 0; 141 - list_del(&cb->list); 142 - cl_dbg(dev, cl, "completed read length = %lu\n", 143 - cb->buf_idx); 144 - list_add_tail(&cb->list, &complete_list->list); 145 - } 146 - break; 107 + cb = list_first_entry_or_null(&cl->rd_pending, struct mei_cl_cb, list); 108 + if (!cb) { 109 + cl_err(dev, cl, "pending read cb not found\n"); 110 + goto out; 147 111 } 148 112 149 - dev_dbg(dev->dev, "message read\n"); 150 - if (!buffer) { 151 - mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length); 152 - dev_dbg(dev->dev, "discarding message " MEI_HDR_FMT "\n", 153 - MEI_HDR_PRM(mei_hdr)); 113 + if (!mei_cl_is_connected(cl)) { 114 + cl_dbg(dev, cl, "not connected\n"); 115 + cb->status = -ENODEV; 116 + goto out; 154 117 } 118 + 119 + if (cb->buf.size == 0 || cb->buf.data == NULL) { 120 + cl_err(dev, cl, "response buffer is not allocated.\n"); 121 + list_move_tail(&cb->list, &complete_list->list); 122 + cb->status = -ENOMEM; 123 + goto out; 124 + } 125 + 126 + if (cb->buf.size < mei_hdr->length + cb->buf_idx) { 127 + cl_dbg(dev, cl, "message overflow. size %d len %d idx %ld\n", 128 + cb->buf.size, mei_hdr->length, cb->buf_idx); 129 + buffer = krealloc(cb->buf.data, mei_hdr->length + cb->buf_idx, 130 + GFP_KERNEL); 131 + 132 + if (!buffer) { 133 + cb->status = -ENOMEM; 134 + list_move_tail(&cb->list, &complete_list->list); 135 + goto out; 136 + } 137 + cb->buf.data = buffer; 138 + cb->buf.size = mei_hdr->length + cb->buf_idx; 139 + } 140 + 141 + buffer = cb->buf.data + cb->buf_idx; 142 + mei_read_slots(dev, buffer, mei_hdr->length); 143 + 144 + cb->buf_idx += mei_hdr->length; 145 + 146 + if (mei_hdr->msg_complete) { 147 + cb->read_time = jiffies; 148 + cl_dbg(dev, cl, "completed read length = %lu\n", cb->buf_idx); 149 + list_move_tail(&cb->list, &complete_list->list); 150 + } 151 + 152 + out: 153 + if (!buffer) 154 + mei_irq_discard_msg(dev, mei_hdr); 155 155 156 156 return 0; 157 157 } ··· 183 183 184 184 cl->state = MEI_FILE_DISCONNECTED; 185 185 cl->status = 0; 186 - list_del(&cb->list); 187 186 mei_io_cb_free(cb); 188 187 189 188 return ret; ··· 262 263 return ret; 263 264 } 264 265 265 - list_move_tail(&cb->list, &dev->read_list.list); 266 + list_move_tail(&cb->list, &cl->rd_pending); 266 267 267 268 return 0; 268 269 } ··· 300 301 if (ret) { 301 302 cl->status = ret; 302 303 cb->buf_idx = 0; 303 - list_del(&cb->list); 304 + list_del_init(&cb->list); 304 305 return ret; 305 306 } 306 307 ··· 377 378 goto end; 378 379 } 379 380 380 - if (mei_hdr->host_addr == dev->iamthif_cl.host_client_id && 381 - MEI_FILE_CONNECTED == dev->iamthif_cl.state && 382 - dev->iamthif_state == MEI_IAMTHIF_READING) { 383 - 384 - ret = mei_amthif_irq_read_msg(dev, mei_hdr, cmpl_list); 385 - if (ret) { 386 - dev_err(dev->dev, "mei_amthif_irq_read_msg failed = %d\n", 387 - ret); 388 - goto end; 389 - } 381 + if (cl == &dev->iamthif_cl) { 382 + ret = mei_amthif_irq_read_msg(cl, mei_hdr, cmpl_list); 390 383 } else { 391 - ret = mei_cl_irq_read_msg(dev, mei_hdr, cmpl_list); 392 - if (ret) { 393 - dev_err(dev->dev, "mei_cl_irq_read_msg failed = %d\n", 394 - ret); 395 - goto end; 396 - } 384 + ret = mei_cl_irq_read_msg(cl, mei_hdr, cmpl_list); 397 385 } 386 + 398 387 399 388 reset_slots: 400 389 /* reset the number of slots and header */ ··· 436 449 cl = cb->cl; 437 450 438 451 cl->status = 0; 439 - list_del(&cb->list); 440 - if (cb->fop_type == MEI_FOP_WRITE && 441 - cl != &dev->iamthif_cl) { 442 - cl_dbg(dev, cl, "MEI WRITE COMPLETE\n"); 443 - cl->writing_state = MEI_WRITE_COMPLETE; 444 - list_add_tail(&cb->list, &cmpl_list->list); 445 - } 446 - if (cl == &dev->iamthif_cl) { 447 - cl_dbg(dev, cl, "check iamthif flow control.\n"); 448 - if (dev->iamthif_flow_control_pending) { 449 - ret = mei_amthif_irq_read(dev, &slots); 450 - if (ret) 451 - return ret; 452 - } 453 - } 452 + cl_dbg(dev, cl, "MEI WRITE COMPLETE\n"); 453 + cl->writing_state = MEI_WRITE_COMPLETE; 454 + list_move_tail(&cb->list, &cmpl_list->list); 454 455 } 455 456 456 457 if (dev->wd_state == MEI_WD_STOPPING) { ··· 562 587 if (--dev->iamthif_stall_timer == 0) { 563 588 dev_err(dev->dev, "timer: amthif hanged.\n"); 564 589 mei_reset(dev); 565 - dev->iamthif_msg_buf_size = 0; 566 - dev->iamthif_msg_buf_index = 0; 567 590 dev->iamthif_canceled = false; 568 - dev->iamthif_ioctl = true; 569 591 dev->iamthif_state = MEI_IAMTHIF_IDLE; 570 592 dev->iamthif_timer = 0; 571 593 ··· 608 636 schedule_delayed_work(&dev->timer_work, 2 * HZ); 609 637 mutex_unlock(&dev->device_lock); 610 638 } 611 -
+49 -97
drivers/misc/mei/main.c
··· 58 58 59 59 mutex_lock(&dev->device_lock); 60 60 61 - cl = NULL; 62 - 63 - err = -ENODEV; 64 61 if (dev->dev_state != MEI_DEV_ENABLED) { 65 62 dev_dbg(dev->dev, "dev_state != MEI_ENABLED dev_state = %s\n", 66 63 mei_dev_state_str(dev->dev_state)); 64 + err = -ENODEV; 67 65 goto err_unlock; 68 66 } 69 67 70 - err = -ENOMEM; 71 - cl = mei_cl_allocate(dev); 72 - if (!cl) 68 + cl = mei_cl_alloc_linked(dev, MEI_HOST_CLIENT_ID_ANY); 69 + if (IS_ERR(cl)) { 70 + err = PTR_ERR(cl); 73 71 goto err_unlock; 74 - 75 - /* open_handle_count check is handled in the mei_cl_link */ 76 - err = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY); 77 - if (err) 78 - goto err_unlock; 72 + } 79 73 80 74 file->private_data = cl; 81 75 ··· 79 85 80 86 err_unlock: 81 87 mutex_unlock(&dev->device_lock); 82 - kfree(cl); 83 88 return err; 84 89 } 85 90 ··· 93 100 static int mei_release(struct inode *inode, struct file *file) 94 101 { 95 102 struct mei_cl *cl = file->private_data; 96 - struct mei_cl_cb *cb; 97 103 struct mei_device *dev; 98 104 int rets = 0; 99 105 ··· 106 114 rets = mei_amthif_release(dev, file); 107 115 goto out; 108 116 } 109 - if (cl->state == MEI_FILE_CONNECTED) { 117 + if (mei_cl_is_connected(cl)) { 110 118 cl->state = MEI_FILE_DISCONNECTING; 111 119 cl_dbg(dev, cl, "disconnecting\n"); 112 120 rets = mei_cl_disconnect(cl); 113 121 } 114 - mei_cl_flush_queues(cl); 122 + mei_cl_flush_queues(cl, file); 115 123 cl_dbg(dev, cl, "removing\n"); 116 124 117 125 mei_cl_unlink(cl); 118 126 119 - 120 - /* free read cb */ 121 - cb = NULL; 122 - if (cl->read_cb) { 123 - cb = mei_cl_find_read_cb(cl); 124 - /* Remove entry from read list */ 125 - if (cb) 126 - list_del(&cb->list); 127 - 128 - cb = cl->read_cb; 129 - cl->read_cb = NULL; 130 - } 131 - 132 127 file->private_data = NULL; 133 - 134 - mei_io_cb_free(cb); 135 128 136 129 kfree(cl); 137 130 out: ··· 139 162 size_t length, loff_t *offset) 140 163 { 141 164 struct mei_cl *cl = file->private_data; 142 - struct mei_cl_cb *cb_pos = NULL; 143 - struct mei_cl_cb *cb = NULL; 144 165 struct mei_device *dev; 166 + struct mei_cl_cb *cb = NULL; 145 167 int rets; 146 168 int err; 147 169 ··· 167 191 goto out; 168 192 } 169 193 170 - if (cl->read_cb) { 171 - cb = cl->read_cb; 194 + cb = mei_cl_read_cb(cl, file); 195 + if (cb) { 172 196 /* read what left */ 173 197 if (cb->buf_idx > *offset) 174 198 goto copy_buffer; ··· 184 208 *offset = 0; 185 209 } 186 210 187 - err = mei_cl_read_start(cl, length); 211 + err = mei_cl_read_start(cl, length, file); 188 212 if (err && err != -EBUSY) { 189 213 dev_dbg(dev->dev, 190 214 "mei start read failure with status = %d\n", err); ··· 192 216 goto out; 193 217 } 194 218 195 - if (MEI_READ_COMPLETE != cl->reading_state && 196 - !waitqueue_active(&cl->rx_wait)) { 219 + if (list_empty(&cl->rd_completed) && !waitqueue_active(&cl->rx_wait)) { 197 220 if (file->f_flags & O_NONBLOCK) { 198 221 rets = -EAGAIN; 199 222 goto out; ··· 201 226 mutex_unlock(&dev->device_lock); 202 227 203 228 if (wait_event_interruptible(cl->rx_wait, 204 - MEI_READ_COMPLETE == cl->reading_state || 205 - mei_cl_is_transitioning(cl))) { 229 + (!list_empty(&cl->rd_completed)) || 230 + (!mei_cl_is_connected(cl)))) { 206 231 207 232 if (signal_pending(current)) 208 233 return -EINTR; ··· 210 235 } 211 236 212 237 mutex_lock(&dev->device_lock); 213 - if (mei_cl_is_transitioning(cl)) { 238 + if (!mei_cl_is_connected(cl)) { 214 239 rets = -EBUSY; 215 240 goto out; 216 241 } 217 242 } 218 243 219 - cb = cl->read_cb; 220 - 244 + cb = mei_cl_read_cb(cl, file); 221 245 if (!cb) { 222 - rets = -ENODEV; 223 - goto out; 224 - } 225 - if (cl->reading_state != MEI_READ_COMPLETE) { 226 246 rets = 0; 227 247 goto out; 228 248 } 229 - /* now copy the data to user space */ 249 + 230 250 copy_buffer: 251 + /* now copy the data to user space */ 252 + if (cb->status) { 253 + rets = cb->status; 254 + dev_dbg(dev->dev, "read operation failed %d\n", rets); 255 + goto free; 256 + } 257 + 231 258 dev_dbg(dev->dev, "buf.size = %d buf.idx= %ld\n", 232 - cb->response_buffer.size, cb->buf_idx); 259 + cb->buf.size, cb->buf_idx); 233 260 if (length == 0 || ubuf == NULL || *offset > cb->buf_idx) { 234 261 rets = -EMSGSIZE; 235 262 goto free; ··· 241 264 * however buf_idx may point beyond that */ 242 265 length = min_t(size_t, length, cb->buf_idx - *offset); 243 266 244 - if (copy_to_user(ubuf, cb->response_buffer.data + *offset, length)) { 267 + if (copy_to_user(ubuf, cb->buf.data + *offset, length)) { 245 268 dev_dbg(dev->dev, "failed to copy data to userland\n"); 246 269 rets = -EFAULT; 247 270 goto free; ··· 253 276 goto out; 254 277 255 278 free: 256 - cb_pos = mei_cl_find_read_cb(cl); 257 - /* Remove entry from read list */ 258 - if (cb_pos) 259 - list_del(&cb_pos->list); 260 279 mei_io_cb_free(cb); 261 - cl->reading_state = MEI_IDLE; 262 - cl->read_cb = NULL; 280 + 263 281 out: 264 282 dev_dbg(dev->dev, "end mei read rets= %d\n", rets); 265 283 mutex_unlock(&dev->device_lock); ··· 308 336 goto out; 309 337 } 310 338 311 - if (cl->state != MEI_FILE_CONNECTED) { 312 - dev_err(dev->dev, "host client = %d, is not connected to ME client = %d", 313 - cl->host_client_id, cl->me_client_id); 339 + if (!mei_cl_is_connected(cl)) { 340 + cl_err(dev, cl, "is not connected"); 314 341 rets = -ENODEV; 315 342 goto out; 316 343 } ··· 320 349 timeout = write_cb->read_time + 321 350 mei_secs_to_jiffies(MEI_IAMTHIF_READ_TIMER); 322 351 323 - if (time_after(jiffies, timeout) || 324 - cl->reading_state == MEI_READ_COMPLETE) { 352 + if (time_after(jiffies, timeout)) { 325 353 *offset = 0; 326 - list_del(&write_cb->list); 327 354 mei_io_cb_free(write_cb); 328 355 write_cb = NULL; 329 356 } 330 357 } 331 358 } 332 359 333 - /* free entry used in read */ 334 - if (cl->reading_state == MEI_READ_COMPLETE) { 335 - *offset = 0; 336 - write_cb = mei_cl_find_read_cb(cl); 337 - if (write_cb) { 338 - list_del(&write_cb->list); 339 - mei_io_cb_free(write_cb); 340 - write_cb = NULL; 341 - cl->reading_state = MEI_IDLE; 342 - cl->read_cb = NULL; 343 - } 344 - } else if (cl->reading_state == MEI_IDLE) 345 - *offset = 0; 346 - 347 - 348 - write_cb = mei_io_cb_init(cl, file); 360 + *offset = 0; 361 + write_cb = mei_cl_alloc_cb(cl, length, MEI_FOP_WRITE, file); 349 362 if (!write_cb) { 350 363 rets = -ENOMEM; 351 364 goto out; 352 365 } 353 - rets = mei_io_cb_alloc_req_buf(write_cb, length); 354 - if (rets) 355 - goto out; 356 366 357 - rets = copy_from_user(write_cb->request_buffer.data, ubuf, length); 367 + rets = copy_from_user(write_cb->buf.data, ubuf, length); 358 368 if (rets) { 359 369 dev_dbg(dev->dev, "failed to copy data from userland\n"); 360 370 rets = -EFAULT; ··· 343 391 } 344 392 345 393 if (cl == &dev->iamthif_cl) { 346 - rets = mei_amthif_write(dev, write_cb); 394 + rets = mei_amthif_write(cl, write_cb); 347 395 348 396 if (rets) { 349 397 dev_err(dev->dev, ··· 416 464 */ 417 465 if (uuid_le_cmp(data->in_client_uuid, mei_amthif_guid) == 0) { 418 466 dev_dbg(dev->dev, "FW Client is amthi\n"); 419 - if (dev->iamthif_cl.state != MEI_FILE_CONNECTED) { 467 + if (!mei_cl_is_connected(&dev->iamthif_cl)) { 420 468 rets = -ENODEV; 421 469 goto end; 422 470 } ··· 540 588 */ 541 589 static unsigned int mei_poll(struct file *file, poll_table *wait) 542 590 { 591 + unsigned long req_events = poll_requested_events(wait); 543 592 struct mei_cl *cl = file->private_data; 544 593 struct mei_device *dev; 545 594 unsigned int mask = 0; ··· 552 599 553 600 mutex_lock(&dev->device_lock); 554 601 555 - if (!mei_cl_is_connected(cl)) { 602 + 603 + if (dev->dev_state != MEI_DEV_ENABLED || 604 + !mei_cl_is_connected(cl)) { 556 605 mask = POLLERR; 557 606 goto out; 558 607 } 559 608 560 - mutex_unlock(&dev->device_lock); 561 - 562 - 563 - if (cl == &dev->iamthif_cl) 564 - return mei_amthif_poll(dev, file, wait); 565 - 566 - poll_wait(file, &cl->tx_wait, wait); 567 - 568 - mutex_lock(&dev->device_lock); 569 - 570 - if (!mei_cl_is_connected(cl)) { 571 - mask = POLLERR; 609 + if (cl == &dev->iamthif_cl) { 610 + mask = mei_amthif_poll(dev, file, wait); 572 611 goto out; 573 612 } 574 613 575 - mask |= (POLLIN | POLLRDNORM); 614 + if (req_events & (POLLIN | POLLRDNORM)) { 615 + poll_wait(file, &cl->rx_wait, wait); 616 + 617 + if (!list_empty(&cl->rd_completed)) 618 + mask |= POLLIN | POLLRDNORM; 619 + else 620 + mei_cl_read_start(cl, 0, file); 621 + } 576 622 577 623 out: 578 624 mutex_unlock(&dev->device_lock);
+25
drivers/misc/mei/mei-trace.c
··· 1 + /* 2 + * 3 + * Intel Management Engine Interface (Intel MEI) Linux driver 4 + * Copyright (c) 2015, 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 + #include <linux/module.h> 17 + 18 + /* sparse doesn't like tracepoint macros */ 19 + #ifndef __CHECKER__ 20 + #define CREATE_TRACE_POINTS 21 + #include "mei-trace.h" 22 + 23 + EXPORT_TRACEPOINT_SYMBOL(mei_reg_read); 24 + EXPORT_TRACEPOINT_SYMBOL(mei_reg_write); 25 + #endif /* __CHECKER__ */
+74
drivers/misc/mei/mei-trace.h
··· 1 + /* 2 + * 3 + * Intel Management Engine Interface (Intel MEI) Linux driver 4 + * Copyright (c) 2015, 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 + #if !defined(_MEI_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ) 18 + #define _MEI_TRACE_H_ 19 + 20 + #include <linux/stringify.h> 21 + #include <linux/types.h> 22 + #include <linux/tracepoint.h> 23 + 24 + #include <linux/device.h> 25 + 26 + #undef TRACE_SYSTEM 27 + #define TRACE_SYSTEM mei 28 + 29 + TRACE_EVENT(mei_reg_read, 30 + TP_PROTO(const struct device *dev, const char *reg, u32 offs, u32 val), 31 + TP_ARGS(dev, reg, offs, val), 32 + TP_STRUCT__entry( 33 + __string(dev, dev_name(dev)) 34 + __field(const char *, reg) 35 + __field(u32, offs) 36 + __field(u32, val) 37 + ), 38 + TP_fast_assign( 39 + __assign_str(dev, dev_name(dev)) 40 + __entry->reg = reg; 41 + __entry->offs = offs; 42 + __entry->val = val; 43 + ), 44 + TP_printk("[%s] read %s:[%#x] = %#x", 45 + __get_str(dev), __entry->reg, __entry->offs, __entry->val) 46 + ); 47 + 48 + TRACE_EVENT(mei_reg_write, 49 + TP_PROTO(const struct device *dev, const char *reg, u32 offs, u32 val), 50 + TP_ARGS(dev, reg, offs, val), 51 + TP_STRUCT__entry( 52 + __string(dev, dev_name(dev)) 53 + __field(const char *, reg) 54 + __field(u32, offs) 55 + __field(u32, val) 56 + ), 57 + TP_fast_assign( 58 + __assign_str(dev, dev_name(dev)) 59 + __entry->reg = reg; 60 + __entry->offs = offs; 61 + __entry->val = val; 62 + ), 63 + TP_printk("[%s] write %s[%#x] = %#x)", 64 + __get_str(dev), __entry->reg, __entry->offs, __entry->val) 65 + ); 66 + 67 + #endif /* _MEI_TRACE_H_ */ 68 + 69 + /* This part must be outside protection */ 70 + #undef TRACE_INCLUDE_PATH 71 + #undef TRACE_INCLUDE_FILE 72 + #define TRACE_INCLUDE_PATH . 73 + #define TRACE_INCLUDE_FILE mei-trace 74 + #include <trace/define_trace.h>
+15 -25
drivers/misc/mei/mei_dev.h
··· 194 194 * @list: link in callback queue 195 195 * @cl: file client who is running this operation 196 196 * @fop_type: file operation type 197 - * @request_buffer: buffer to store request data 198 - * @response_buffer: buffer to store response data 197 + * @buf: buffer for data associated with the callback 199 198 * @buf_idx: last read index 200 199 * @read_time: last read operation time stamp (iamthif) 201 200 * @file_object: pointer to file structure 201 + * @status: io status of the cb 202 202 * @internal: communication between driver and FW flag 203 + * @completed: the transfer or reception has completed 203 204 */ 204 205 struct mei_cl_cb { 205 206 struct list_head list; 206 207 struct mei_cl *cl; 207 208 enum mei_cb_file_ops fop_type; 208 - struct mei_msg_data request_buffer; 209 - struct mei_msg_data response_buffer; 209 + struct mei_msg_data buf; 210 210 unsigned long buf_idx; 211 211 unsigned long read_time; 212 212 struct file *file_object; 213 + int status; 213 214 u32 internal:1; 215 + u32 completed:1; 214 216 }; 215 217 216 218 /** ··· 231 229 * @me_client_id: me/fw id 232 230 * @mei_flow_ctrl_creds: transmit flow credentials 233 231 * @timer_count: watchdog timer for operation completion 234 - * @reading_state: state of the rx 235 232 * @writing_state: state of the tx 236 - * @read_cb: current pending reading callback 233 + * @rd_pending: pending read credits 234 + * @rd_completed: completed read 237 235 * 238 236 * @device: device on the mei client bus 239 237 * @device_link: link to bus clients ··· 251 249 u8 me_client_id; 252 250 u8 mei_flow_ctrl_creds; 253 251 u8 timer_count; 254 - enum mei_file_transaction_states reading_state; 255 252 enum mei_file_transaction_states writing_state; 256 - struct mei_cl_cb *read_cb; 253 + struct list_head rd_pending; 254 + struct list_head rd_completed; 257 255 258 256 /* MEI CL bus data */ 259 257 struct mei_cl_device *device; ··· 425 423 * @cdev : character device 426 424 * @minor : minor number allocated for device 427 425 * 428 - * @read_list : read completion list 429 426 * @write_list : write pending list 430 427 * @write_waiting_list : write completion list 431 428 * @ctrl_wr_list : pending control write list ··· 461 460 * @version : HBM protocol version in use 462 461 * @hbm_f_pg_supported : hbm feature pgi protocol 463 462 * 463 + * @me_clients_rwsem: rw lock over me_clients list 464 464 * @me_clients : list of FW clients 465 465 * @me_clients_map : FW clients bit map 466 466 * @host_clients_map : host clients id pool ··· 482 480 * @iamthif_mtu : amthif client max message length 483 481 * @iamthif_timer : time stamp of current amthif command completion 484 482 * @iamthif_stall_timer : timer to detect amthif hang 485 - * @iamthif_msg_buf : amthif current message buffer 486 - * @iamthif_msg_buf_size : size of current amthif message request buffer 487 - * @iamthif_msg_buf_index : current index in amthif message request buffer 488 483 * @iamthif_state : amthif processor state 489 - * @iamthif_flow_control_pending: amthif waits for flow control 490 - * @iamthif_ioctl : wait for completion if amthif control message 491 484 * @iamthif_canceled : current amthif command is canceled 492 485 * 493 486 * @init_work : work item for the device init ··· 500 503 struct cdev cdev; 501 504 int minor; 502 505 503 - struct mei_cl_cb read_list; 504 506 struct mei_cl_cb write_list; 505 507 struct mei_cl_cb write_waiting_list; 506 508 struct mei_cl_cb ctrl_wr_list; ··· 552 556 struct hbm_version version; 553 557 unsigned int hbm_f_pg_supported:1; 554 558 559 + struct rw_semaphore me_clients_rwsem; 555 560 struct list_head me_clients; 556 561 DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX); 557 562 DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX); ··· 576 579 int iamthif_mtu; 577 580 unsigned long iamthif_timer; 578 581 u32 iamthif_stall_timer; 579 - unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */ 580 - u32 iamthif_msg_buf_size; 581 - u32 iamthif_msg_buf_index; 582 582 enum iamthif_states iamthif_state; 583 - bool iamthif_flow_control_pending; 584 - bool iamthif_ioctl; 585 583 bool iamthif_canceled; 586 584 587 585 struct work_struct init_work; ··· 654 662 655 663 int mei_amthif_host_init(struct mei_device *dev); 656 664 657 - int mei_amthif_write(struct mei_device *dev, struct mei_cl_cb *priv_cb); 658 - 659 665 int mei_amthif_read(struct mei_device *dev, struct file *file, 660 666 char __user *ubuf, size_t length, loff_t *offset); 661 667 ··· 665 675 struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev, 666 676 struct file *file); 667 677 668 - void mei_amthif_run_next_cmd(struct mei_device *dev); 669 - 678 + int mei_amthif_write(struct mei_cl *cl, struct mei_cl_cb *cb); 679 + int mei_amthif_run_next_cmd(struct mei_device *dev); 670 680 int mei_amthif_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb, 671 681 struct mei_cl_cb *cmpl_list); 672 682 673 683 void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb); 674 - int mei_amthif_irq_read_msg(struct mei_device *dev, 684 + int mei_amthif_irq_read_msg(struct mei_cl *cl, 675 685 struct mei_msg_hdr *mei_hdr, 676 686 struct mei_cl_cb *complete_list); 677 687 int mei_amthif_irq_read(struct mei_device *dev, s32 *slots);
+21 -22
drivers/misc/mei/nfc.c
··· 482 482 int mei_nfc_host_init(struct mei_device *dev) 483 483 { 484 484 struct mei_nfc_dev *ndev; 485 - struct mei_cl *cl_info, *cl = NULL; 486 - struct mei_me_client *me_cl; 485 + struct mei_cl *cl_info, *cl; 486 + struct mei_me_client *me_cl = NULL; 487 487 int ret; 488 488 489 489 ··· 500 500 goto err; 501 501 } 502 502 503 - ndev->cl_info = mei_cl_allocate(dev); 504 - ndev->cl = mei_cl_allocate(dev); 505 - 506 - cl = ndev->cl; 507 - cl_info = ndev->cl_info; 508 - 509 - if (!cl || !cl_info) { 510 - ret = -ENOMEM; 511 - goto err; 512 - } 513 - 514 503 /* check for valid client id */ 515 504 me_cl = mei_me_cl_by_uuid(dev, &mei_nfc_info_guid); 516 505 if (!me_cl) { ··· 508 519 goto err; 509 520 } 510 521 522 + cl_info = mei_cl_alloc_linked(dev, MEI_HOST_CLIENT_ID_ANY); 523 + if (IS_ERR(cl_info)) { 524 + ret = PTR_ERR(cl_info); 525 + goto err; 526 + } 527 + 511 528 cl_info->me_client_id = me_cl->client_id; 512 529 cl_info->cl_uuid = me_cl->props.protocol_name; 513 530 mei_me_cl_put(me_cl); 514 - 515 - ret = mei_cl_link(cl_info, MEI_HOST_CLIENT_ID_ANY); 516 - if (ret) 517 - goto err; 518 - 531 + me_cl = NULL; 519 532 520 533 list_add_tail(&cl_info->device_link, &dev->device_list); 534 + 535 + ndev->cl_info = cl_info; 521 536 522 537 /* check for valid client id */ 523 538 me_cl = mei_me_cl_by_uuid(dev, &mei_nfc_guid); ··· 531 538 goto err; 532 539 } 533 540 541 + cl = mei_cl_alloc_linked(dev, MEI_HOST_CLIENT_ID_ANY); 542 + if (IS_ERR(cl)) { 543 + ret = PTR_ERR(cl); 544 + goto err; 545 + } 546 + 534 547 cl->me_client_id = me_cl->client_id; 535 548 cl->cl_uuid = me_cl->props.protocol_name; 536 549 mei_me_cl_put(me_cl); 537 - 538 - ret = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY); 539 - if (ret) 540 - goto err; 550 + me_cl = NULL; 541 551 542 552 list_add_tail(&cl->device_link, &dev->device_list); 553 + 554 + ndev->cl = cl; 543 555 544 556 ndev->req_id = 1; 545 557 ··· 555 557 return 0; 556 558 557 559 err: 560 + mei_me_cl_put(me_cl); 558 561 mei_nfc_free(ndev); 559 562 560 563 return ret;
+2 -2
drivers/misc/mei/pci-me.c
··· 388 388 mutex_lock(&dev->device_lock); 389 389 390 390 if (mei_write_is_idle(dev)) 391 - ret = mei_me_pg_set_sync(dev); 391 + ret = mei_me_pg_enter_sync(dev); 392 392 else 393 393 ret = -EAGAIN; 394 394 ··· 413 413 414 414 mutex_lock(&dev->device_lock); 415 415 416 - ret = mei_me_pg_unset_sync(dev); 416 + ret = mei_me_pg_exit_sync(dev); 417 417 418 418 mutex_unlock(&dev->device_lock); 419 419
+2 -2
drivers/misc/mei/pci-txe.c
··· 63 63 } 64 64 } 65 65 /** 66 - * mei_probe - Device Initialization Routine 66 + * mei_txe_probe - Device Initialization Routine 67 67 * 68 68 * @pdev: PCI device structure 69 69 * @ent: entry in mei_txe_pci_tbl ··· 193 193 } 194 194 195 195 /** 196 - * mei_remove - Device Removal Routine 196 + * mei_txe_remove - Device Removal Routine 197 197 * 198 198 * @pdev: PCI device structure 199 199 *
+20 -16
drivers/misc/mei/wd.c
··· 160 160 */ 161 161 int mei_wd_stop(struct mei_device *dev) 162 162 { 163 + struct mei_cl *cl = &dev->wd_cl; 163 164 int ret; 164 165 165 - if (dev->wd_cl.state != MEI_FILE_CONNECTED || 166 + if (!mei_cl_is_connected(cl) || 166 167 dev->wd_state != MEI_WD_RUNNING) 167 168 return 0; 168 169 ··· 171 170 172 171 dev->wd_state = MEI_WD_STOPPING; 173 172 174 - ret = mei_cl_flow_ctrl_creds(&dev->wd_cl); 173 + ret = mei_cl_flow_ctrl_creds(cl); 175 174 if (ret < 0) 176 175 goto err; 177 176 ··· 203 202 return ret; 204 203 } 205 204 206 - /* 205 + /** 207 206 * mei_wd_ops_start - wd start command from the watchdog core. 208 207 * 209 - * @wd_dev - watchdog device struct 208 + * @wd_dev: watchdog device struct 210 209 * 211 210 * Return: 0 if success, negative errno code for failure 212 211 */ 213 212 static int mei_wd_ops_start(struct watchdog_device *wd_dev) 214 213 { 215 - int err = -ENODEV; 216 214 struct mei_device *dev; 215 + struct mei_cl *cl; 216 + int err = -ENODEV; 217 217 218 218 dev = watchdog_get_drvdata(wd_dev); 219 219 if (!dev) 220 220 return -ENODEV; 221 + 222 + cl = &dev->wd_cl; 221 223 222 224 mutex_lock(&dev->device_lock); 223 225 ··· 230 226 goto end_unlock; 231 227 } 232 228 233 - if (dev->wd_cl.state != MEI_FILE_CONNECTED) { 234 - dev_dbg(dev->dev, "MEI Driver is not connected to Watchdog Client\n"); 229 + if (!mei_cl_is_connected(cl)) { 230 + cl_dbg(dev, cl, "MEI Driver is not connected to Watchdog Client\n"); 235 231 goto end_unlock; 236 232 } 237 233 ··· 243 239 return err; 244 240 } 245 241 246 - /* 242 + /** 247 243 * mei_wd_ops_stop - wd stop command from the watchdog core. 248 244 * 249 - * @wd_dev - watchdog device struct 245 + * @wd_dev: watchdog device struct 250 246 * 251 247 * Return: 0 if success, negative errno code for failure 252 248 */ ··· 265 261 return 0; 266 262 } 267 263 268 - /* 264 + /** 269 265 * mei_wd_ops_ping - wd ping command from the watchdog core. 270 266 * 271 - * @wd_dev - watchdog device struct 267 + * @wd_dev: watchdog device struct 272 268 * 273 269 * Return: 0 if success, negative errno code for failure 274 270 */ ··· 286 282 287 283 mutex_lock(&dev->device_lock); 288 284 289 - if (cl->state != MEI_FILE_CONNECTED) { 290 - dev_err(dev->dev, "wd: not connected.\n"); 285 + if (!mei_cl_is_connected(cl)) { 286 + cl_err(dev, cl, "wd: not connected.\n"); 291 287 ret = -ENODEV; 292 288 goto end; 293 289 } ··· 315 311 return ret; 316 312 } 317 313 318 - /* 314 + /** 319 315 * mei_wd_ops_set_timeout - wd set timeout command from the watchdog core. 320 316 * 321 - * @wd_dev - watchdog device struct 322 - * @timeout - timeout value to set 317 + * @wd_dev: watchdog device struct 318 + * @timeout: timeout value to set 323 319 * 324 320 * Return: 0 if success, negative errno code for failure 325 321 */
+7 -7
drivers/misc/mic/host/mic_boot.c
··· 309 309 */ 310 310 void mic_prepare_suspend(struct mic_device *mdev) 311 311 { 312 - int rc; 312 + unsigned long timeout; 313 313 314 314 #define MIC_SUSPEND_TIMEOUT (60 * HZ) 315 315 ··· 331 331 */ 332 332 mic_set_state(mdev, MIC_SUSPENDING); 333 333 mutex_unlock(&mdev->mic_mutex); 334 - rc = wait_for_completion_timeout(&mdev->reset_wait, 335 - MIC_SUSPEND_TIMEOUT); 334 + timeout = wait_for_completion_timeout(&mdev->reset_wait, 335 + MIC_SUSPEND_TIMEOUT); 336 336 /* Force reset the card if the shutdown completion timed out */ 337 - if (!rc) { 337 + if (!timeout) { 338 338 mutex_lock(&mdev->mic_mutex); 339 339 mic_set_state(mdev, MIC_SUSPENDED); 340 340 mutex_unlock(&mdev->mic_mutex); ··· 348 348 */ 349 349 mic_set_state(mdev, MIC_SUSPENDED); 350 350 mutex_unlock(&mdev->mic_mutex); 351 - rc = wait_for_completion_timeout(&mdev->reset_wait, 352 - MIC_SUSPEND_TIMEOUT); 351 + timeout = wait_for_completion_timeout(&mdev->reset_wait, 352 + MIC_SUSPEND_TIMEOUT); 353 353 /* Force reset the card if the shutdown completion timed out */ 354 - if (!rc) 354 + if (!timeout) 355 355 mic_stop(mdev, true); 356 356 break; 357 357 default:
-2
drivers/misc/mic/host/mic_intr.c
··· 363 363 { 364 364 int rc; 365 365 366 - pci_msi_off(pdev); 367 - 368 366 /* Enable intx */ 369 367 pci_intx(pdev, 1); 370 368 rc = mic_setup_callbacks(mdev);
+15 -4
drivers/misc/sram.c
··· 69 69 INIT_LIST_HEAD(&reserve_list); 70 70 71 71 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 72 - virt_base = devm_ioremap_resource(&pdev->dev, res); 73 - if (IS_ERR(virt_base)) 74 - return PTR_ERR(virt_base); 72 + if (!res) { 73 + dev_err(&pdev->dev, "found no memory resource\n"); 74 + return -EINVAL; 75 + } 75 76 76 77 size = resource_size(res); 78 + 79 + if (!devm_request_mem_region(&pdev->dev, 80 + res->start, size, pdev->name)) { 81 + dev_err(&pdev->dev, "could not request region for resource\n"); 82 + return -EBUSY; 83 + } 84 + 85 + virt_base = devm_ioremap_wc(&pdev->dev, res->start, size); 86 + if (IS_ERR(virt_base)) 87 + return PTR_ERR(virt_base); 77 88 78 89 sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL); 79 90 if (!sram) ··· 216 205 } 217 206 218 207 #ifdef CONFIG_OF 219 - static struct of_device_id sram_dt_ids[] = { 208 + static const struct of_device_id sram_dt_ids[] = { 220 209 { .compatible = "mmio-sram" }, 221 210 {} 222 211 };
+3 -2
drivers/misc/tifm_7xx1.c
··· 236 236 { 237 237 struct tifm_adapter *fm = pci_get_drvdata(dev); 238 238 int rc; 239 + unsigned long timeout; 239 240 unsigned int good_sockets = 0, bad_sockets = 0; 240 241 unsigned long flags; 241 242 unsigned char new_ids[fm->num_sockets]; ··· 273 272 if (good_sockets) { 274 273 fm->finish_me = &finish_resume; 275 274 spin_unlock_irqrestore(&fm->lock, flags); 276 - rc = wait_for_completion_timeout(&finish_resume, HZ); 277 - dev_dbg(&dev->dev, "wait returned %d\n", rc); 275 + timeout = wait_for_completion_timeout(&finish_resume, HZ); 276 + dev_dbg(&dev->dev, "wait returned %lu\n", timeout); 278 277 writel(TIFM_IRQ_FIFOMASK(good_sockets) 279 278 | TIFM_IRQ_CARDMASK(good_sockets), 280 279 fm->addr + FM_CLEAR_INTERRUPT_ENABLE);
+1 -1
drivers/misc/vmw_vmci/vmci_driver.c
··· 113 113 114 114 MODULE_AUTHOR("VMware, Inc."); 115 115 MODULE_DESCRIPTION("VMware Virtual Machine Communication Interface."); 116 - MODULE_VERSION("1.1.1.0-k"); 116 + MODULE_VERSION("1.1.3.0-k"); 117 117 MODULE_LICENSE("GPL v2");
+6
drivers/misc/vmw_vmci/vmci_host.c
··· 395 395 return -EFAULT; 396 396 } 397 397 398 + if (VMCI_DG_SIZE(dg) != send_info.len) { 399 + vmci_ioctl_err("datagram size mismatch\n"); 400 + kfree(dg); 401 + return -EINVAL; 402 + } 403 + 398 404 pr_devel("Datagram dst (handle=0x%x:0x%x) src (handle=0x%x:0x%x), payload (size=%llu bytes)\n", 399 405 dg->dst.context, dg->dst.resource, 400 406 dg->src.context, dg->src.resource,
+26 -11
drivers/misc/vmw_vmci/vmci_queue_pair.c
··· 295 295 { 296 296 u64 i; 297 297 struct vmci_queue *queue; 298 - const size_t num_pages = DIV_ROUND_UP(size, PAGE_SIZE) + 1; 299 - const size_t pas_size = num_pages * sizeof(*queue->kernel_if->u.g.pas); 300 - const size_t vas_size = num_pages * sizeof(*queue->kernel_if->u.g.vas); 301 - const size_t queue_size = 302 - sizeof(*queue) + sizeof(*queue->kernel_if) + 303 - pas_size + vas_size; 298 + size_t pas_size; 299 + size_t vas_size; 300 + size_t queue_size = sizeof(*queue) + sizeof(*queue->kernel_if); 301 + const u64 num_pages = DIV_ROUND_UP(size, PAGE_SIZE) + 1; 302 + 303 + if (num_pages > 304 + (SIZE_MAX - queue_size) / 305 + (sizeof(*queue->kernel_if->u.g.pas) + 306 + sizeof(*queue->kernel_if->u.g.vas))) 307 + return NULL; 308 + 309 + pas_size = num_pages * sizeof(*queue->kernel_if->u.g.pas); 310 + vas_size = num_pages * sizeof(*queue->kernel_if->u.g.vas); 311 + queue_size += pas_size + vas_size; 304 312 305 313 queue = vmalloc(queue_size); 306 314 if (!queue) ··· 623 615 static struct vmci_queue *qp_host_alloc_queue(u64 size) 624 616 { 625 617 struct vmci_queue *queue; 626 - const size_t num_pages = DIV_ROUND_UP(size, PAGE_SIZE) + 1; 618 + size_t queue_page_size; 619 + const u64 num_pages = DIV_ROUND_UP(size, PAGE_SIZE) + 1; 627 620 const size_t queue_size = sizeof(*queue) + sizeof(*(queue->kernel_if)); 628 - const size_t queue_page_size = 629 - num_pages * sizeof(*queue->kernel_if->u.h.page); 621 + 622 + if (num_pages > (SIZE_MAX - queue_size) / 623 + sizeof(*queue->kernel_if->u.h.page)) 624 + return NULL; 625 + 626 + queue_page_size = num_pages * sizeof(*queue->kernel_if->u.h.page); 630 627 631 628 queue = kzalloc(queue_size + queue_page_size, GFP_KERNEL); 632 629 if (queue) { ··· 750 737 produce_q->kernel_if->num_pages, 1, 751 738 produce_q->kernel_if->u.h.header_page); 752 739 if (retval < produce_q->kernel_if->num_pages) { 753 - pr_warn("get_user_pages(produce) failed (retval=%d)", retval); 740 + pr_debug("get_user_pages_fast(produce) failed (retval=%d)", 741 + retval); 754 742 qp_release_pages(produce_q->kernel_if->u.h.header_page, 755 743 retval, false); 756 744 err = VMCI_ERROR_NO_MEM; ··· 762 748 consume_q->kernel_if->num_pages, 1, 763 749 consume_q->kernel_if->u.h.header_page); 764 750 if (retval < consume_q->kernel_if->num_pages) { 765 - pr_warn("get_user_pages(consume) failed (retval=%d)", retval); 751 + pr_debug("get_user_pages_fast(consume) failed (retval=%d)", 752 + retval); 766 753 qp_release_pages(consume_q->kernel_if->u.h.header_page, 767 754 retval, false); 768 755 qp_release_pages(produce_q->kernel_if->u.h.header_page,
+1 -3
drivers/pcmcia/omap_cf.c
··· 220 220 cf = kzalloc(sizeof *cf, GFP_KERNEL); 221 221 if (!cf) 222 222 return -ENOMEM; 223 - init_timer(&cf->timer); 224 - cf->timer.function = omap_cf_timer; 225 - cf->timer.data = (unsigned long) cf; 223 + setup_timer(&cf->timer, omap_cf_timer, (unsigned long)cf); 226 224 227 225 cf->pdev = pdev; 228 226 platform_set_drvdata(pdev, cf);
+3 -5
drivers/pcmcia/pd6729.c
··· 707 707 } 708 708 } else { 709 709 /* poll Card status change */ 710 - init_timer(&socket->poll_timer); 711 - socket->poll_timer.function = pd6729_interrupt_wrapper; 712 - socket->poll_timer.data = (unsigned long)socket; 713 - socket->poll_timer.expires = jiffies + HZ; 714 - add_timer(&socket->poll_timer); 710 + setup_timer(&socket->poll_timer, pd6729_interrupt_wrapper, 711 + (unsigned long)socket); 712 + mod_timer(&socket->poll_timer, jiffies + HZ); 715 713 } 716 714 717 715 for (i = 0; i < MAX_SOCKETS; i++) {
+2 -3
drivers/pcmcia/soc_common.c
··· 726 726 { 727 727 int ret; 728 728 729 - init_timer(&skt->poll_timer); 730 - skt->poll_timer.function = soc_common_pcmcia_poll_event; 731 - skt->poll_timer.data = (unsigned long)skt; 729 + setup_timer(&skt->poll_timer, soc_common_pcmcia_poll_event, 730 + (unsigned long)skt); 732 731 skt->poll_timer.expires = jiffies + SOC_PCMCIA_POLL_PERIOD; 733 732 734 733 ret = request_resource(&iomem_resource, &skt->res_skt);
+3 -5
drivers/pcmcia/yenta_socket.c
··· 1236 1236 if (!socket->cb_irq || request_irq(socket->cb_irq, yenta_interrupt, IRQF_SHARED, "yenta", socket)) { 1237 1237 /* No IRQ or request_irq failed. Poll */ 1238 1238 socket->cb_irq = 0; /* But zero is a valid IRQ number. */ 1239 - init_timer(&socket->poll_timer); 1240 - socket->poll_timer.function = yenta_interrupt_wrapper; 1241 - socket->poll_timer.data = (unsigned long)socket; 1242 - socket->poll_timer.expires = jiffies + HZ; 1243 - add_timer(&socket->poll_timer); 1239 + setup_timer(&socket->poll_timer, yenta_interrupt_wrapper, 1240 + (unsigned long)socket); 1241 + mod_timer(&socket->poll_timer, jiffies + HZ); 1244 1242 dev_printk(KERN_INFO, &dev->dev, 1245 1243 "no PCI IRQ, CardBus support disabled for this " 1246 1244 "socket.\n");
-1
drivers/spmi/Kconfig
··· 12 12 13 13 config SPMI_MSM_PMIC_ARB 14 14 tristate "Qualcomm MSM SPMI Controller (PMIC Arbiter)" 15 - depends on ARM 16 15 depends on IRQ_DOMAIN 17 16 depends on ARCH_QCOM || COMPILE_TEST 18 17 default ARCH_QCOM
+262 -61
drivers/spmi/spmi-pmic-arb.c
··· 1 - /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. 1 + /* 2 + * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. 2 3 * 3 4 * This program is free software; you can redistribute it and/or modify 4 5 * it under the terms of the GNU General Public License version 2 and ··· 26 25 27 26 /* PMIC Arbiter configuration registers */ 28 27 #define PMIC_ARB_VERSION 0x0000 28 + #define PMIC_ARB_VERSION_V2_MIN 0x20010000 29 29 #define PMIC_ARB_INT_EN 0x0004 30 30 31 - /* PMIC Arbiter channel registers */ 32 - #define PMIC_ARB_CMD(N) (0x0800 + (0x80 * (N))) 33 - #define PMIC_ARB_CONFIG(N) (0x0804 + (0x80 * (N))) 34 - #define PMIC_ARB_STATUS(N) (0x0808 + (0x80 * (N))) 35 - #define PMIC_ARB_WDATA0(N) (0x0810 + (0x80 * (N))) 36 - #define PMIC_ARB_WDATA1(N) (0x0814 + (0x80 * (N))) 37 - #define PMIC_ARB_RDATA0(N) (0x0818 + (0x80 * (N))) 38 - #define PMIC_ARB_RDATA1(N) (0x081C + (0x80 * (N))) 39 - 40 - /* Interrupt Controller */ 41 - #define SPMI_PIC_OWNER_ACC_STATUS(M, N) (0x0000 + ((32 * (M)) + (4 * (N)))) 42 - #define SPMI_PIC_ACC_ENABLE(N) (0x0200 + (4 * (N))) 43 - #define SPMI_PIC_IRQ_STATUS(N) (0x0600 + (4 * (N))) 44 - #define SPMI_PIC_IRQ_CLEAR(N) (0x0A00 + (4 * (N))) 31 + /* PMIC Arbiter channel registers offsets */ 32 + #define PMIC_ARB_CMD 0x00 33 + #define PMIC_ARB_CONFIG 0x04 34 + #define PMIC_ARB_STATUS 0x08 35 + #define PMIC_ARB_WDATA0 0x10 36 + #define PMIC_ARB_WDATA1 0x14 37 + #define PMIC_ARB_RDATA0 0x18 38 + #define PMIC_ARB_RDATA1 0x1C 39 + #define PMIC_ARB_REG_CHNL(N) (0x800 + 0x4 * (N)) 45 40 46 41 /* Mapping Table */ 47 42 #define SPMI_MAPPING_TABLE_REG(N) (0x0B00 + (4 * (N))) ··· 49 52 50 53 #define SPMI_MAPPING_TABLE_LEN 255 51 54 #define SPMI_MAPPING_TABLE_TREE_DEPTH 16 /* Maximum of 16-bits */ 55 + #define PPID_TO_CHAN_TABLE_SZ BIT(12) /* PPID is 12bit chan is 1byte*/ 52 56 53 57 /* Ownership Table */ 54 58 #define SPMI_OWNERSHIP_TABLE_REG(N) (0x0700 + (4 * (N))) ··· 86 88 87 89 /* Maximum number of support PMIC peripherals */ 88 90 #define PMIC_ARB_MAX_PERIPHS 256 91 + #define PMIC_ARB_MAX_CHNL 128 89 92 #define PMIC_ARB_PERIPH_ID_VALID (1 << 15) 90 93 #define PMIC_ARB_TIMEOUT_US 100 91 94 #define PMIC_ARB_MAX_TRANS_BYTES (8) ··· 97 98 /* interrupt enable bit */ 98 99 #define SPMI_PIC_ACC_ENABLE_BIT BIT(0) 99 100 101 + struct pmic_arb_ver_ops; 102 + 100 103 /** 101 104 * spmi_pmic_arb_dev - SPMI PMIC Arbiter object 102 105 * 103 - * @base: address of the PMIC Arbiter core registers. 106 + * @rd_base: on v1 "core", on v2 "observer" register base off DT. 107 + * @wr_base: on v1 "core", on v2 "chnls" register base off DT. 104 108 * @intr: address of the SPMI interrupt control registers. 105 109 * @cnfg: address of the PMIC Arbiter configuration registers. 106 110 * @lock: lock to synchronize accesses. 107 - * @channel: which channel to use for accesses. 111 + * @channel: execution environment channel to use for accesses. 108 112 * @irq: PMIC ARB interrupt. 109 113 * @ee: the current Execution Environment 110 114 * @min_apid: minimum APID (used for bounding IRQ search) ··· 115 113 * @mapping_table: in-memory copy of PPID -> APID mapping table. 116 114 * @domain: irq domain object for PMIC IRQ domain 117 115 * @spmic: SPMI controller object 118 - * @apid_to_ppid: cached mapping from APID to PPID 116 + * @apid_to_ppid: in-memory copy of APID -> PPID mapping table. 117 + * @ver_ops: version dependent operations. 118 + * @ppid_to_chan in-memory copy of PPID -> channel (APID) mapping table. 119 + * v2 only. 119 120 */ 120 121 struct spmi_pmic_arb_dev { 121 - void __iomem *base; 122 + void __iomem *rd_base; 123 + void __iomem *wr_base; 122 124 void __iomem *intr; 123 125 void __iomem *cnfg; 124 126 raw_spinlock_t lock; ··· 135 129 struct irq_domain *domain; 136 130 struct spmi_controller *spmic; 137 131 u16 apid_to_ppid[256]; 132 + const struct pmic_arb_ver_ops *ver_ops; 133 + u8 *ppid_to_chan; 134 + }; 135 + 136 + /** 137 + * pmic_arb_ver: version dependent functionality. 138 + * 139 + * @non_data_cmd: on v1 issues an spmi non-data command. 140 + * on v2 no HW support, returns -EOPNOTSUPP. 141 + * @offset: on v1 offset of per-ee channel. 142 + * on v2 offset of per-ee and per-ppid channel. 143 + * @fmt_cmd: formats a GENI/SPMI command. 144 + * @owner_acc_status: on v1 offset of PMIC_ARB_SPMI_PIC_OWNERm_ACC_STATUSn 145 + * on v2 offset of SPMI_PIC_OWNERm_ACC_STATUSn. 146 + * @acc_enable: on v1 offset of PMIC_ARB_SPMI_PIC_ACC_ENABLEn 147 + * on v2 offset of SPMI_PIC_ACC_ENABLEn. 148 + * @irq_status: on v1 offset of PMIC_ARB_SPMI_PIC_IRQ_STATUSn 149 + * on v2 offset of SPMI_PIC_IRQ_STATUSn. 150 + * @irq_clear: on v1 offset of PMIC_ARB_SPMI_PIC_IRQ_CLEARn 151 + * on v2 offset of SPMI_PIC_IRQ_CLEARn. 152 + */ 153 + struct pmic_arb_ver_ops { 154 + /* spmi commands (read_cmd, write_cmd, cmd) functionality */ 155 + u32 (*offset)(struct spmi_pmic_arb_dev *dev, u8 sid, u16 addr); 156 + u32 (*fmt_cmd)(u8 opc, u8 sid, u16 addr, u8 bc); 157 + int (*non_data_cmd)(struct spmi_controller *ctrl, u8 opc, u8 sid); 158 + /* Interrupts controller functionality (offset of PIC registers) */ 159 + u32 (*owner_acc_status)(u8 m, u8 n); 160 + u32 (*acc_enable)(u8 n); 161 + u32 (*irq_status)(u8 n); 162 + u32 (*irq_clear)(u8 n); 138 163 }; 139 164 140 165 static inline u32 pmic_arb_base_read(struct spmi_pmic_arb_dev *dev, u32 offset) 141 166 { 142 - return readl_relaxed(dev->base + offset); 167 + return readl_relaxed(dev->rd_base + offset); 143 168 } 144 169 145 170 static inline void pmic_arb_base_write(struct spmi_pmic_arb_dev *dev, 146 171 u32 offset, u32 val) 147 172 { 148 - writel_relaxed(val, dev->base + offset); 173 + writel_relaxed(val, dev->wr_base + offset); 174 + } 175 + 176 + static inline void pmic_arb_set_rd_cmd(struct spmi_pmic_arb_dev *dev, 177 + u32 offset, u32 val) 178 + { 179 + writel_relaxed(val, dev->rd_base + offset); 149 180 } 150 181 151 182 /** ··· 211 168 pmic_arb_base_write(dev, reg, data); 212 169 } 213 170 214 - static int pmic_arb_wait_for_done(struct spmi_controller *ctrl) 171 + static int pmic_arb_wait_for_done(struct spmi_controller *ctrl, 172 + void __iomem *base, u8 sid, u16 addr) 215 173 { 216 174 struct spmi_pmic_arb_dev *dev = spmi_controller_get_drvdata(ctrl); 217 175 u32 status = 0; 218 176 u32 timeout = PMIC_ARB_TIMEOUT_US; 219 - u32 offset = PMIC_ARB_STATUS(dev->channel); 177 + u32 offset = dev->ver_ops->offset(dev, sid, addr) + PMIC_ARB_STATUS; 220 178 221 179 while (timeout--) { 222 - status = pmic_arb_base_read(dev, offset); 180 + status = readl_relaxed(base + offset); 223 181 224 182 if (status & PMIC_ARB_STATUS_DONE) { 225 183 if (status & PMIC_ARB_STATUS_DENIED) { ··· 255 211 return -ETIMEDOUT; 256 212 } 257 213 258 - /* Non-data command */ 259 - static int pmic_arb_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid) 214 + static int 215 + pmic_arb_non_data_cmd_v1(struct spmi_controller *ctrl, u8 opc, u8 sid) 260 216 { 261 217 struct spmi_pmic_arb_dev *pmic_arb = spmi_controller_get_drvdata(ctrl); 262 218 unsigned long flags; 263 219 u32 cmd; 264 220 int rc; 221 + u32 offset = pmic_arb->ver_ops->offset(pmic_arb, sid, 0); 222 + 223 + cmd = ((opc | 0x40) << 27) | ((sid & 0xf) << 20); 224 + 225 + raw_spin_lock_irqsave(&pmic_arb->lock, flags); 226 + pmic_arb_base_write(pmic_arb, offset + PMIC_ARB_CMD, cmd); 227 + rc = pmic_arb_wait_for_done(ctrl, pmic_arb->wr_base, sid, 0); 228 + raw_spin_unlock_irqrestore(&pmic_arb->lock, flags); 229 + 230 + return rc; 231 + } 232 + 233 + static int 234 + pmic_arb_non_data_cmd_v2(struct spmi_controller *ctrl, u8 opc, u8 sid) 235 + { 236 + return -EOPNOTSUPP; 237 + } 238 + 239 + /* Non-data command */ 240 + static int pmic_arb_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid) 241 + { 242 + struct spmi_pmic_arb_dev *pmic_arb = spmi_controller_get_drvdata(ctrl); 243 + 244 + dev_dbg(&ctrl->dev, "cmd op:0x%x sid:%d\n", opc, sid); 265 245 266 246 /* Check for valid non-data command */ 267 247 if (opc < SPMI_CMD_RESET || opc > SPMI_CMD_WAKEUP) 268 248 return -EINVAL; 269 249 270 - cmd = ((opc | 0x40) << 27) | ((sid & 0xf) << 20); 271 - 272 - raw_spin_lock_irqsave(&pmic_arb->lock, flags); 273 - pmic_arb_base_write(pmic_arb, PMIC_ARB_CMD(pmic_arb->channel), cmd); 274 - rc = pmic_arb_wait_for_done(ctrl); 275 - raw_spin_unlock_irqrestore(&pmic_arb->lock, flags); 276 - 277 - return rc; 250 + return pmic_arb->ver_ops->non_data_cmd(ctrl, opc, sid); 278 251 } 279 252 280 253 static int pmic_arb_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid, ··· 302 241 u8 bc = len - 1; 303 242 u32 cmd; 304 243 int rc; 244 + u32 offset = pmic_arb->ver_ops->offset(pmic_arb, sid, addr); 305 245 306 246 if (bc >= PMIC_ARB_MAX_TRANS_BYTES) { 307 247 dev_err(&ctrl->dev, 308 - "pmic-arb supports 1..%d bytes per trans, but %d requested", 248 + "pmic-arb supports 1..%d bytes per trans, but:%zu requested", 309 249 PMIC_ARB_MAX_TRANS_BYTES, len); 310 250 return -EINVAL; 311 251 } ··· 321 259 else 322 260 return -EINVAL; 323 261 324 - cmd = (opc << 27) | ((sid & 0xf) << 20) | (addr << 4) | (bc & 0x7); 262 + cmd = pmic_arb->ver_ops->fmt_cmd(opc, sid, addr, bc); 325 263 326 264 raw_spin_lock_irqsave(&pmic_arb->lock, flags); 327 - pmic_arb_base_write(pmic_arb, PMIC_ARB_CMD(pmic_arb->channel), cmd); 328 - rc = pmic_arb_wait_for_done(ctrl); 265 + pmic_arb_set_rd_cmd(pmic_arb, offset + PMIC_ARB_CMD, cmd); 266 + rc = pmic_arb_wait_for_done(ctrl, pmic_arb->rd_base, sid, addr); 329 267 if (rc) 330 268 goto done; 331 269 332 - pa_read_data(pmic_arb, buf, PMIC_ARB_RDATA0(pmic_arb->channel), 270 + pa_read_data(pmic_arb, buf, offset + PMIC_ARB_RDATA0, 333 271 min_t(u8, bc, 3)); 334 272 335 273 if (bc > 3) 336 274 pa_read_data(pmic_arb, buf + 4, 337 - PMIC_ARB_RDATA1(pmic_arb->channel), bc - 4); 275 + offset + PMIC_ARB_RDATA1, bc - 4); 338 276 339 277 done: 340 278 raw_spin_unlock_irqrestore(&pmic_arb->lock, flags); ··· 349 287 u8 bc = len - 1; 350 288 u32 cmd; 351 289 int rc; 290 + u32 offset = pmic_arb->ver_ops->offset(pmic_arb, sid, addr); 352 291 353 292 if (bc >= PMIC_ARB_MAX_TRANS_BYTES) { 354 293 dev_err(&ctrl->dev, 355 - "pmic-arb supports 1..%d bytes per trans, but:%d requested", 294 + "pmic-arb supports 1..%d bytes per trans, but:%zu requested", 356 295 PMIC_ARB_MAX_TRANS_BYTES, len); 357 296 return -EINVAL; 358 297 } ··· 370 307 else 371 308 return -EINVAL; 372 309 373 - cmd = (opc << 27) | ((sid & 0xf) << 20) | (addr << 4) | (bc & 0x7); 310 + cmd = pmic_arb->ver_ops->fmt_cmd(opc, sid, addr, bc); 374 311 375 312 /* Write data to FIFOs */ 376 313 raw_spin_lock_irqsave(&pmic_arb->lock, flags); 377 - pa_write_data(pmic_arb, buf, PMIC_ARB_WDATA0(pmic_arb->channel) 378 - , min_t(u8, bc, 3)); 314 + pa_write_data(pmic_arb, buf, offset + PMIC_ARB_WDATA0, 315 + min_t(u8, bc, 3)); 379 316 if (bc > 3) 380 317 pa_write_data(pmic_arb, buf + 4, 381 - PMIC_ARB_WDATA1(pmic_arb->channel), bc - 4); 318 + offset + PMIC_ARB_WDATA1, bc - 4); 382 319 383 320 /* Start the transaction */ 384 - pmic_arb_base_write(pmic_arb, PMIC_ARB_CMD(pmic_arb->channel), cmd); 385 - rc = pmic_arb_wait_for_done(ctrl); 321 + pmic_arb_base_write(pmic_arb, offset + PMIC_ARB_CMD, cmd); 322 + rc = pmic_arb_wait_for_done(ctrl, pmic_arb->wr_base, sid, addr); 386 323 raw_spin_unlock_irqrestore(&pmic_arb->lock, flags); 387 324 388 325 return rc; ··· 439 376 u32 status; 440 377 int id; 441 378 442 - status = readl_relaxed(pa->intr + SPMI_PIC_IRQ_STATUS(apid)); 379 + status = readl_relaxed(pa->intr + pa->ver_ops->irq_status(apid)); 443 380 while (status) { 444 381 id = ffs(status) - 1; 445 382 status &= ~(1 << id); ··· 465 402 466 403 for (i = first; i <= last; ++i) { 467 404 status = readl_relaxed(intr + 468 - SPMI_PIC_OWNER_ACC_STATUS(pa->ee, i)); 405 + pa->ver_ops->owner_acc_status(pa->ee, i)); 469 406 while (status) { 470 407 id = ffs(status) - 1; 471 408 status &= ~(1 << id); ··· 485 422 u8 data; 486 423 487 424 raw_spin_lock_irqsave(&pa->lock, flags); 488 - writel_relaxed(1 << irq, pa->intr + SPMI_PIC_IRQ_CLEAR(apid)); 425 + writel_relaxed(1 << irq, pa->intr + pa->ver_ops->irq_clear(apid)); 489 426 raw_spin_unlock_irqrestore(&pa->lock, flags); 490 427 491 428 data = 1 << irq; ··· 502 439 u8 data; 503 440 504 441 raw_spin_lock_irqsave(&pa->lock, flags); 505 - status = readl_relaxed(pa->intr + SPMI_PIC_ACC_ENABLE(apid)); 442 + status = readl_relaxed(pa->intr + pa->ver_ops->acc_enable(apid)); 506 443 if (status & SPMI_PIC_ACC_ENABLE_BIT) { 507 444 status = status & ~SPMI_PIC_ACC_ENABLE_BIT; 508 - writel_relaxed(status, pa->intr + SPMI_PIC_ACC_ENABLE(apid)); 445 + writel_relaxed(status, pa->intr + 446 + pa->ver_ops->acc_enable(apid)); 509 447 } 510 448 raw_spin_unlock_irqrestore(&pa->lock, flags); 511 449 ··· 524 460 u8 data; 525 461 526 462 raw_spin_lock_irqsave(&pa->lock, flags); 527 - status = readl_relaxed(pa->intr + SPMI_PIC_ACC_ENABLE(apid)); 463 + status = readl_relaxed(pa->intr + pa->ver_ops->acc_enable(apid)); 528 464 if (!(status & SPMI_PIC_ACC_ENABLE_BIT)) { 529 465 writel_relaxed(status | SPMI_PIC_ACC_ENABLE_BIT, 530 - pa->intr + SPMI_PIC_ACC_ENABLE(apid)); 466 + pa->intr + pa->ver_ops->acc_enable(apid)); 531 467 } 532 468 raw_spin_unlock_irqrestore(&pa->lock, flags); 533 469 ··· 688 624 return 0; 689 625 } 690 626 627 + /* v1 offset per ee */ 628 + static u32 pmic_arb_offset_v1(struct spmi_pmic_arb_dev *pa, u8 sid, u16 addr) 629 + { 630 + return 0x800 + 0x80 * pa->channel; 631 + } 632 + 633 + /* v2 offset per ppid (chan) and per ee */ 634 + static u32 pmic_arb_offset_v2(struct spmi_pmic_arb_dev *pa, u8 sid, u16 addr) 635 + { 636 + u16 ppid = (sid << 8) | (addr >> 8); 637 + u8 chan = pa->ppid_to_chan[ppid]; 638 + 639 + return 0x1000 * pa->ee + 0x8000 * chan; 640 + } 641 + 642 + static u32 pmic_arb_fmt_cmd_v1(u8 opc, u8 sid, u16 addr, u8 bc) 643 + { 644 + return (opc << 27) | ((sid & 0xf) << 20) | (addr << 4) | (bc & 0x7); 645 + } 646 + 647 + static u32 pmic_arb_fmt_cmd_v2(u8 opc, u8 sid, u16 addr, u8 bc) 648 + { 649 + return (opc << 27) | ((addr & 0xff) << 4) | (bc & 0x7); 650 + } 651 + 652 + static u32 pmic_arb_owner_acc_status_v1(u8 m, u8 n) 653 + { 654 + return 0x20 * m + 0x4 * n; 655 + } 656 + 657 + static u32 pmic_arb_owner_acc_status_v2(u8 m, u8 n) 658 + { 659 + return 0x100000 + 0x1000 * m + 0x4 * n; 660 + } 661 + 662 + static u32 pmic_arb_acc_enable_v1(u8 n) 663 + { 664 + return 0x200 + 0x4 * n; 665 + } 666 + 667 + static u32 pmic_arb_acc_enable_v2(u8 n) 668 + { 669 + return 0x1000 * n; 670 + } 671 + 672 + static u32 pmic_arb_irq_status_v1(u8 n) 673 + { 674 + return 0x600 + 0x4 * n; 675 + } 676 + 677 + static u32 pmic_arb_irq_status_v2(u8 n) 678 + { 679 + return 0x4 + 0x1000 * n; 680 + } 681 + 682 + static u32 pmic_arb_irq_clear_v1(u8 n) 683 + { 684 + return 0xA00 + 0x4 * n; 685 + } 686 + 687 + static u32 pmic_arb_irq_clear_v2(u8 n) 688 + { 689 + return 0x8 + 0x1000 * n; 690 + } 691 + 692 + static const struct pmic_arb_ver_ops pmic_arb_v1 = { 693 + .non_data_cmd = pmic_arb_non_data_cmd_v1, 694 + .offset = pmic_arb_offset_v1, 695 + .fmt_cmd = pmic_arb_fmt_cmd_v1, 696 + .owner_acc_status = pmic_arb_owner_acc_status_v1, 697 + .acc_enable = pmic_arb_acc_enable_v1, 698 + .irq_status = pmic_arb_irq_status_v1, 699 + .irq_clear = pmic_arb_irq_clear_v1, 700 + }; 701 + 702 + static const struct pmic_arb_ver_ops pmic_arb_v2 = { 703 + .non_data_cmd = pmic_arb_non_data_cmd_v2, 704 + .offset = pmic_arb_offset_v2, 705 + .fmt_cmd = pmic_arb_fmt_cmd_v2, 706 + .owner_acc_status = pmic_arb_owner_acc_status_v2, 707 + .acc_enable = pmic_arb_acc_enable_v2, 708 + .irq_status = pmic_arb_irq_status_v2, 709 + .irq_clear = pmic_arb_irq_clear_v2, 710 + }; 711 + 691 712 static const struct irq_domain_ops pmic_arb_irq_domain_ops = { 692 713 .map = qpnpint_irq_domain_map, 693 714 .xlate = qpnpint_irq_domain_dt_translate, ··· 783 634 struct spmi_pmic_arb_dev *pa; 784 635 struct spmi_controller *ctrl; 785 636 struct resource *res; 786 - u32 channel, ee; 637 + void __iomem *core; 638 + u32 channel, ee, hw_ver; 787 639 int err, i; 640 + bool is_v1; 788 641 789 642 ctrl = spmi_controller_alloc(&pdev->dev, sizeof(*pa)); 790 643 if (!ctrl) ··· 796 645 pa->spmic = ctrl; 797 646 798 647 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); 799 - pa->base = devm_ioremap_resource(&ctrl->dev, res); 800 - if (IS_ERR(pa->base)) { 801 - err = PTR_ERR(pa->base); 648 + core = devm_ioremap_resource(&ctrl->dev, res); 649 + if (IS_ERR(core)) { 650 + err = PTR_ERR(core); 802 651 goto err_put_ctrl; 652 + } 653 + 654 + hw_ver = readl_relaxed(core + PMIC_ARB_VERSION); 655 + is_v1 = (hw_ver < PMIC_ARB_VERSION_V2_MIN); 656 + 657 + dev_info(&ctrl->dev, "PMIC Arb Version-%d (0x%x)\n", (is_v1 ? 1 : 2), 658 + hw_ver); 659 + 660 + if (is_v1) { 661 + pa->ver_ops = &pmic_arb_v1; 662 + pa->wr_base = core; 663 + pa->rd_base = core; 664 + } else { 665 + u8 chan; 666 + u16 ppid; 667 + u32 regval; 668 + 669 + pa->ver_ops = &pmic_arb_v2; 670 + 671 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 672 + "obsrvr"); 673 + pa->rd_base = devm_ioremap_resource(&ctrl->dev, res); 674 + if (IS_ERR(pa->rd_base)) { 675 + err = PTR_ERR(pa->rd_base); 676 + goto err_put_ctrl; 677 + } 678 + 679 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 680 + "chnls"); 681 + pa->wr_base = devm_ioremap_resource(&ctrl->dev, res); 682 + if (IS_ERR(pa->wr_base)) { 683 + err = PTR_ERR(pa->wr_base); 684 + goto err_put_ctrl; 685 + } 686 + 687 + pa->ppid_to_chan = devm_kzalloc(&ctrl->dev, 688 + PPID_TO_CHAN_TABLE_SZ, GFP_KERNEL); 689 + if (!pa->ppid_to_chan) { 690 + err = -ENOMEM; 691 + goto err_put_ctrl; 692 + } 693 + /* 694 + * PMIC_ARB_REG_CHNL is a table in HW mapping channel to ppid. 695 + * ppid_to_chan is an in-memory invert of that table. 696 + */ 697 + for (chan = 0; chan < PMIC_ARB_MAX_CHNL; ++chan) { 698 + regval = readl_relaxed(core + PMIC_ARB_REG_CHNL(chan)); 699 + if (!regval) 700 + continue; 701 + 702 + ppid = (regval >> 8) & 0xFFF; 703 + pa->ppid_to_chan[ppid] = chan; 704 + } 803 705 } 804 706 805 707 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "intr"); ··· 934 730 err = spmi_controller_add(ctrl); 935 731 if (err) 936 732 goto err_domain_remove; 937 - 938 - dev_dbg(&ctrl->dev, "PMIC Arb Version 0x%x\n", 939 - pmic_arb_base_read(pa, PMIC_ARB_VERSION)); 940 733 941 734 return 0; 942 735
+2 -7
drivers/spmi/spmi.c
··· 1 - /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. 1 + /* 2 + * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. 2 3 * 3 4 * This program is free software; you can redistribute it and/or modify 4 5 * it under the terms of the GNU General Public License version 2 and ··· 317 316 struct spmi_device *sdev = to_spmi_device(dev); 318 317 int err; 319 318 320 - /* Ensure the slave is in ACTIVE state */ 321 - err = spmi_command_wakeup(sdev); 322 - if (err) 323 - goto fail_wakeup; 324 - 325 319 pm_runtime_get_noresume(dev); 326 320 pm_runtime_set_active(dev); 327 321 pm_runtime_enable(dev); ··· 331 335 pm_runtime_disable(dev); 332 336 pm_runtime_set_suspended(dev); 333 337 pm_runtime_put_noidle(dev); 334 - fail_wakeup: 335 338 return err; 336 339 } 337 340
+11 -1
drivers/uio/uio.c
··· 835 835 info->uio_dev = idev; 836 836 837 837 if (info->irq && (info->irq != UIO_IRQ_CUSTOM)) { 838 - ret = devm_request_irq(idev->dev, info->irq, uio_interrupt, 838 + /* 839 + * Note that we deliberately don't use devm_request_irq 840 + * here. The parent module can unregister the UIO device 841 + * and call pci_disable_msi, which requires that this 842 + * irq has been freed. However, the device may have open 843 + * FDs at the time of unregister and therefore may not be 844 + * freed until they are released. 845 + */ 846 + ret = request_irq(info->irq, uio_interrupt, 839 847 info->irq_flags, info->name, idev); 840 848 if (ret) 841 849 goto err_request_irq; ··· 878 870 uio_free_minor(idev); 879 871 880 872 uio_dev_del_attributes(idev); 873 + 874 + free_irq(idev->info->irq, idev); 881 875 882 876 device_destroy(&uio_class, MKDEV(uio_major, idev->minor)); 883 877
+1 -1
drivers/w1/masters/mxc_w1.c
··· 166 166 return 0; 167 167 } 168 168 169 - static struct of_device_id mxc_w1_dt_ids[] = { 169 + static const struct of_device_id mxc_w1_dt_ids[] = { 170 170 { .compatible = "fsl,imx21-owire" }, 171 171 { /* sentinel */ } 172 172 };
+1 -1
drivers/w1/masters/omap_hdq.c
··· 72 72 static int omap_hdq_probe(struct platform_device *pdev); 73 73 static int omap_hdq_remove(struct platform_device *pdev); 74 74 75 - static struct of_device_id omap_hdq_dt_ids[] = { 75 + static const struct of_device_id omap_hdq_dt_ids[] = { 76 76 { .compatible = "ti,omap3-1w" }, 77 77 {} 78 78 };
+1 -1
drivers/w1/masters/w1-gpio.c
··· 68 68 } 69 69 70 70 #if defined(CONFIG_OF) 71 - static struct of_device_id w1_gpio_dt_ids[] = { 71 + static const struct of_device_id w1_gpio_dt_ids[] = { 72 72 { .compatible = "w1-gpio" }, 73 73 {} 74 74 };
+34 -3
include/linux/hyperv.h
··· 646 646 }; 647 647 648 648 struct vmbus_channel { 649 + /* Unique channel id */ 650 + int id; 651 + 649 652 struct list_head listentry; 650 653 651 654 struct hv_device *device_obj; 652 - 653 - struct work_struct work; 654 655 655 656 enum vmbus_channel_state state; 656 657 ··· 673 672 struct hv_ring_buffer_info outbound; /* send to parent */ 674 673 struct hv_ring_buffer_info inbound; /* receive from parent */ 675 674 spinlock_t inbound_lock; 676 - struct workqueue_struct *controlwq; 677 675 678 676 struct vmbus_close_msg close_msg; 679 677 ··· 758 758 * link up channels based on their CPU affinity. 759 759 */ 760 760 struct list_head percpu_list; 761 + 762 + int num_sc; 763 + int next_oc; 761 764 }; 762 765 763 766 static inline void set_channel_read_state(struct vmbus_channel *c, bool state) ··· 864 861 enum vmbus_packet_type type, 865 862 u32 flags); 866 863 864 + extern int vmbus_sendpacket_ctl(struct vmbus_channel *channel, 865 + void *buffer, 866 + u32 bufferLen, 867 + u64 requestid, 868 + enum vmbus_packet_type type, 869 + u32 flags, 870 + bool kick_q); 871 + 867 872 extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, 868 873 struct hv_page_buffer pagebuffers[], 869 874 u32 pagecount, 870 875 void *buffer, 871 876 u32 bufferlen, 872 877 u64 requestid); 878 + 879 + extern int vmbus_sendpacket_pagebuffer_ctl(struct vmbus_channel *channel, 880 + struct hv_page_buffer pagebuffers[], 881 + u32 pagecount, 882 + void *buffer, 883 + u32 bufferlen, 884 + u64 requestid, 885 + u32 flags, 886 + bool kick_q); 873 887 874 888 extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, 875 889 struct hv_multipage_buffer *mpb, ··· 1127 1107 } 1128 1108 1129 1109 /* 1110 + * NetworkDirect. This is the guest RDMA service. 1111 + * {8c2eaf3d-32a7-4b09-ab99-bd1f1c86b501} 1112 + */ 1113 + #define HV_ND_GUID \ 1114 + .guid = { \ 1115 + 0x3d, 0xaf, 0x2e, 0x8c, 0xa7, 0x32, 0x09, 0x4b, \ 1116 + 0xab, 0x99, 0xbd, 0x1f, 0x1c, 0x86, 0xb5, 0x01 \ 1117 + } 1118 + 1119 + /* 1130 1120 * Common header for Hyper-V ICs 1131 1121 */ 1132 1122 ··· 1243 1213 int hv_vss_init(struct hv_util_service *); 1244 1214 void hv_vss_deinit(void); 1245 1215 void hv_vss_onchannelcallback(void *); 1216 + void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid); 1246 1217 1247 1218 extern struct resource hyperv_mmio; 1248 1219
+2
include/linux/io.h
··· 72 72 resource_size_t size); 73 73 void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset, 74 74 resource_size_t size); 75 + void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset, 76 + resource_size_t size); 75 77 void devm_iounmap(struct device *dev, void __iomem *addr); 76 78 int check_signature(const volatile void __iomem *io_addr, 77 79 const unsigned char *signature, int length);
+43
include/linux/jz4780-nemc.h
··· 1 + /* 2 + * JZ4780 NAND/external memory controller (NEMC) 3 + * 4 + * Copyright (c) 2015 Imagination Technologies 5 + * Author: Alex Smith <alex@alex-smith.me.uk> 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms of the GNU General Public License as published by the 9 + * Free Software Foundation; either version 2 of the License, or (at your 10 + * option) any later version. 11 + */ 12 + 13 + #ifndef __LINUX_JZ4780_NEMC_H__ 14 + #define __LINUX_JZ4780_NEMC_H__ 15 + 16 + #include <linux/types.h> 17 + 18 + struct device; 19 + 20 + /* 21 + * Number of NEMC banks. Note that there are actually 6, but they are numbered 22 + * from 1. 23 + */ 24 + #define JZ4780_NEMC_NUM_BANKS 7 25 + 26 + /** 27 + * enum jz4780_nemc_bank_type - device types which can be connected to a bank 28 + * @JZ4780_NEMC_BANK_SRAM: SRAM 29 + * @JZ4780_NEMC_BANK_NAND: NAND 30 + */ 31 + enum jz4780_nemc_bank_type { 32 + JZ4780_NEMC_BANK_SRAM, 33 + JZ4780_NEMC_BANK_NAND, 34 + }; 35 + 36 + extern unsigned int jz4780_nemc_num_banks(struct device *dev); 37 + 38 + extern void jz4780_nemc_set_type(struct device *dev, unsigned int bank, 39 + enum jz4780_nemc_bank_type type); 40 + extern void jz4780_nemc_assert(struct device *dev, unsigned int bank, 41 + bool assert); 42 + 43 + #endif /* __LINUX_JZ4780_NEMC_H__ */
+1 -1
include/linux/mfd/arizona/core.h
··· 127 127 struct regmap_irq_chip_data *aod_irq_chip; 128 128 struct regmap_irq_chip_data *irq_chip; 129 129 130 - bool hpdet_magic; 130 + bool hpdet_clamp; 131 131 unsigned int hp_ena; 132 132 133 133 struct mutex clk_lock;
+2
include/linux/miscdevice.h
··· 52 52 #define MISC_DYNAMIC_MINOR 255 53 53 54 54 struct device; 55 + struct attribute_group; 55 56 56 57 struct miscdevice { 57 58 int minor; ··· 61 60 struct list_head list; 62 61 struct device *parent; 63 62 struct device *this_device; 63 + const struct attribute_group **groups; 64 64 const char *nodename; 65 65 umode_t mode; 66 66 };
+1 -1
kernel/time/clockevents.c
··· 440 440 mutex_unlock(&clockevents_mutex); 441 441 return ret; 442 442 } 443 - EXPORT_SYMBOL_GPL(clockevents_unbind); 443 + EXPORT_SYMBOL_GPL(clockevents_unbind_device); 444 444 445 445 /* Sanity check of state transition callbacks */ 446 446 static int clockevents_sanity_check(struct clock_event_device *dev)
+28
lib/devres.c
··· 72 72 EXPORT_SYMBOL(devm_ioremap_nocache); 73 73 74 74 /** 75 + * devm_ioremap_wc - Managed ioremap_wc() 76 + * @dev: Generic device to remap IO address for 77 + * @offset: BUS offset to map 78 + * @size: Size of map 79 + * 80 + * Managed ioremap_wc(). Map is automatically unmapped on driver detach. 81 + */ 82 + void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset, 83 + resource_size_t size) 84 + { 85 + void __iomem **ptr, *addr; 86 + 87 + ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL); 88 + if (!ptr) 89 + return NULL; 90 + 91 + addr = ioremap_wc(offset, size); 92 + if (addr) { 93 + *ptr = addr; 94 + devres_add(dev, ptr); 95 + } else 96 + devres_free(ptr); 97 + 98 + return addr; 99 + } 100 + EXPORT_SYMBOL(devm_ioremap_wc); 101 + 102 + /** 75 103 * devm_iounmap - Managed iounmap() 76 104 * @dev: Generic device to unmap for 77 105 * @addr: Address to unmap
+138 -9
scripts/checkkconfigsymbols.py
··· 1 1 #!/usr/bin/env python 2 2 3 - """Find Kconfig identifiers that are referenced but not defined.""" 3 + """Find Kconfig symbols that are referenced but not defined.""" 4 4 5 - # (c) 2014 Valentin Rothberg <valentinrothberg@gmail.com> 5 + # (c) 2014-2015 Valentin Rothberg <Valentin.Rothberg@lip6.fr> 6 6 # (c) 2014 Stefan Hengelein <stefan.hengelein@fau.de> 7 7 # 8 8 # Licensed under the terms of the GNU GPL License version 2 ··· 10 10 11 11 import os 12 12 import re 13 + import sys 13 14 from subprocess import Popen, PIPE, STDOUT 15 + from optparse import OptionParser 14 16 15 17 16 18 # regex expressions ··· 34 32 REGEX_FILTER_FEATURES = re.compile(r"[A-Za-z0-9]$") 35 33 36 34 35 + def parse_options(): 36 + """The user interface of this module.""" 37 + usage = "%prog [options]\n\n" \ 38 + "Run this tool to detect Kconfig symbols that are referenced but " \ 39 + "not defined in\nKconfig. The output of this tool has the " \ 40 + "format \'Undefined symbol\\tFile list\'\n\n" \ 41 + "If no option is specified, %prog will default to check your\n" \ 42 + "current tree. Please note that specifying commits will " \ 43 + "\'git reset --hard\'\nyour current tree! You may save " \ 44 + "uncommitted changes to avoid losing data." 45 + 46 + parser = OptionParser(usage=usage) 47 + 48 + parser.add_option('-c', '--commit', dest='commit', action='store', 49 + default="", 50 + help="Check if the specified commit (hash) introduces " 51 + "undefined Kconfig symbols.") 52 + 53 + parser.add_option('-d', '--diff', dest='diff', action='store', 54 + default="", 55 + help="Diff undefined symbols between two commits. The " 56 + "input format bases on Git log's " 57 + "\'commmit1..commit2\'.") 58 + 59 + parser.add_option('', '--force', dest='force', action='store_true', 60 + default=False, 61 + help="Reset current Git tree even when it's dirty.") 62 + 63 + (opts, _) = parser.parse_args() 64 + 65 + if opts.commit and opts.diff: 66 + sys.exit("Please specify only one option at once.") 67 + 68 + if opts.diff and not re.match(r"^[\w\-\.]+\.\.[\w\-\.]+$", opts.diff): 69 + sys.exit("Please specify valid input in the following format: " 70 + "\'commmit1..commit2\'") 71 + 72 + if opts.commit or opts.diff: 73 + if not opts.force and tree_is_dirty(): 74 + sys.exit("The current Git tree is dirty (see 'git status'). " 75 + "Running this script may\ndelete important data since it " 76 + "calls 'git reset --hard' for some performance\nreasons. " 77 + " Please run this script in a clean Git tree or pass " 78 + "'--force' if you\nwant to ignore this warning and " 79 + "continue.") 80 + 81 + return opts 82 + 83 + 37 84 def main(): 38 85 """Main function of this module.""" 86 + opts = parse_options() 87 + 88 + if opts.commit or opts.diff: 89 + head = get_head() 90 + 91 + # get commit range 92 + commit_a = None 93 + commit_b = None 94 + if opts.commit: 95 + commit_a = opts.commit + "~" 96 + commit_b = opts.commit 97 + elif opts.diff: 98 + split = opts.diff.split("..") 99 + commit_a = split[0] 100 + commit_b = split[1] 101 + undefined_a = {} 102 + undefined_b = {} 103 + 104 + # get undefined items before the commit 105 + execute("git reset --hard %s" % commit_a) 106 + undefined_a = check_symbols() 107 + 108 + # get undefined items for the commit 109 + execute("git reset --hard %s" % commit_b) 110 + undefined_b = check_symbols() 111 + 112 + # report cases that are present for the commit but not before 113 + for feature in sorted(undefined_b): 114 + # feature has not been undefined before 115 + if not feature in undefined_a: 116 + files = sorted(undefined_b.get(feature)) 117 + print "%s\t%s" % (feature, ", ".join(files)) 118 + # check if there are new files that reference the undefined feature 119 + else: 120 + files = sorted(undefined_b.get(feature) - 121 + undefined_a.get(feature)) 122 + if files: 123 + print "%s\t%s" % (feature, ", ".join(files)) 124 + 125 + # reset to head 126 + execute("git reset --hard %s" % head) 127 + 128 + # default to check the entire tree 129 + else: 130 + undefined = check_symbols() 131 + for feature in sorted(undefined): 132 + files = sorted(undefined.get(feature)) 133 + print "%s\t%s" % (feature, ", ".join(files)) 134 + 135 + 136 + def execute(cmd): 137 + """Execute %cmd and return stdout. Exit in case of error.""" 138 + pop = Popen(cmd, stdout=PIPE, stderr=STDOUT, shell=True) 139 + (stdout, _) = pop.communicate() # wait until finished 140 + if pop.returncode != 0: 141 + sys.exit(stdout) 142 + return stdout 143 + 144 + 145 + def tree_is_dirty(): 146 + """Return true if the current working tree is dirty (i.e., if any file has 147 + been added, deleted, modified, renamed or copied but not committed).""" 148 + stdout = execute("git status --porcelain") 149 + for line in stdout: 150 + if re.findall(r"[URMADC]{1}", line[:2]): 151 + return True 152 + return False 153 + 154 + 155 + def get_head(): 156 + """Return commit hash of current HEAD.""" 157 + stdout = execute("git rev-parse HEAD") 158 + return stdout.strip('\n') 159 + 160 + 161 + def check_symbols(): 162 + """Find undefined Kconfig symbols and return a dict with the symbol as key 163 + and a list of referencing files as value.""" 39 164 source_files = [] 40 165 kconfig_files = [] 41 166 defined_features = set() 42 167 referenced_features = dict() # {feature: [files]} 43 168 44 169 # use 'git ls-files' to get the worklist 45 - pop = Popen("git ls-files", stdout=PIPE, stderr=STDOUT, shell=True) 46 - (stdout, _) = pop.communicate() # wait until finished 170 + stdout = execute("git ls-files") 47 171 if len(stdout) > 0 and stdout[-1] == "\n": 48 172 stdout = stdout[:-1] 49 173 50 174 for gitfile in stdout.rsplit("\n"): 51 - if ".git" in gitfile or "ChangeLog" in gitfile or \ 52 - ".log" in gitfile or os.path.isdir(gitfile): 175 + if ".git" in gitfile or "ChangeLog" in gitfile or \ 176 + ".log" in gitfile or os.path.isdir(gitfile) or \ 177 + gitfile.startswith("tools/"): 53 178 continue 54 179 if REGEX_FILE_KCONFIG.match(gitfile): 55 180 kconfig_files.append(gitfile) ··· 190 61 for kfile in kconfig_files: 191 62 parse_kconfig_file(kfile, defined_features, referenced_features) 192 63 193 - print "Undefined symbol used\tFile list" 64 + undefined = {} # {feature: [files]} 194 65 for feature in sorted(referenced_features): 195 66 # filter some false positives 196 67 if feature == "FOO" or feature == "BAR" or \ ··· 201 72 # avoid false positives for kernel modules 202 73 if feature[:-len("_MODULE")] in defined_features: 203 74 continue 204 - files = referenced_features.get(feature) 205 - print "%s\t%s" % (feature, ", ".join(files)) 75 + undefined[feature] = referenced_features.get(feature) 76 + return undefined 206 77 207 78 208 79 def parse_source_file(sfile, referenced_features):
+2 -2
sound/soc/codecs/arizona.c
··· 840 840 priv->arizona->hp_ena &= ~mask; 841 841 priv->arizona->hp_ena |= val; 842 842 843 - /* Force off if HPDET magic is active */ 844 - if (priv->arizona->hpdet_magic) 843 + /* Force off if HPDET clamp is active */ 844 + if (priv->arizona->hpdet_clamp) 845 845 val = 0; 846 846 847 847 regmap_update_bits_async(arizona->regmap, ARIZONA_OUTPUT_ENABLES_1,
+1 -1
tools/hv/Makefile
··· 3 3 CC = $(CROSS_COMPILE)gcc 4 4 PTHREAD_LIBS = -lpthread 5 5 WARNINGS = -Wall -Wextra 6 - CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS) 6 + CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS) $(shell getconf LFS_CFLAGS) 7 7 8 8 all: hv_kvp_daemon hv_vss_daemon hv_fcopy_daemon 9 9 %: %.c
+8 -2
tools/hv/hv_vss_daemon.c
··· 81 81 char match[] = "/dev/"; 82 82 FILE *mounts; 83 83 struct mntent *ent; 84 + char errdir[1024] = {0}; 84 85 unsigned int cmd; 85 86 int error = 0, root_seen = 0, save_errno = 0; 86 87 ··· 116 115 goto err; 117 116 } 118 117 118 + endmntent(mounts); 119 + 119 120 if (root_seen) { 120 121 error |= vss_do_freeze("/", cmd); 121 122 if (error && operation == VSS_OP_FREEZE) ··· 127 124 goto out; 128 125 err: 129 126 save_errno = errno; 127 + if (ent) { 128 + strncpy(errdir, ent->mnt_dir, sizeof(errdir)-1); 129 + endmntent(mounts); 130 + } 130 131 vss_operate(VSS_OP_THAW); 131 132 /* Call syslog after we thaw all filesystems */ 132 133 if (ent) 133 134 syslog(LOG_ERR, "FREEZE of %s failed; error:%d %s", 134 - ent->mnt_dir, save_errno, strerror(save_errno)); 135 + errdir, save_errno, strerror(save_errno)); 135 136 else 136 137 syslog(LOG_ERR, "FREEZE of / failed; error:%d %s", save_errno, 137 138 strerror(save_errno)); 138 139 out: 139 - endmntent(mounts); 140 140 return error; 141 141 } 142 142