diff options
128 files changed, 6831 insertions, 3619 deletions
diff --git a/Documentation/hwmon/dme1737 b/Documentation/hwmon/dme1737 index 001d2e70bc11..fc5df7654d63 100644 --- a/Documentation/hwmon/dme1737 +++ b/Documentation/hwmon/dme1737 | |||
@@ -9,11 +9,15 @@ Supported chips: | |||
9 | * SMSC SCH3112, SCH3114, SCH3116 | 9 | * SMSC SCH3112, SCH3114, SCH3116 |
10 | Prefix: 'sch311x' | 10 | Prefix: 'sch311x' |
11 | Addresses scanned: none, address read from Super-I/O config space | 11 | Addresses scanned: none, address read from Super-I/O config space |
12 | Datasheet: http://www.nuhorizons.com/FeaturedProducts/Volume1/SMSC/311x.pdf | 12 | Datasheet: Available on the Internet |
13 | * SMSC SCH5027 | 13 | * SMSC SCH5027 |
14 | Prefix: 'sch5027' | 14 | Prefix: 'sch5027' |
15 | Addresses scanned: I2C 0x2c, 0x2d, 0x2e | 15 | Addresses scanned: I2C 0x2c, 0x2d, 0x2e |
16 | Datasheet: Provided by SMSC upon request and under NDA | 16 | Datasheet: Provided by SMSC upon request and under NDA |
17 | * SMSC SCH5127 | ||
18 | Prefix: 'sch5127' | ||
19 | Addresses scanned: none, address read from Super-I/O config space | ||
20 | Datasheet: Provided by SMSC upon request and under NDA | ||
17 | 21 | ||
18 | Authors: | 22 | Authors: |
19 | Juerg Haefliger <juergh@gmail.com> | 23 | Juerg Haefliger <juergh@gmail.com> |
@@ -36,8 +40,8 @@ Description | |||
36 | ----------- | 40 | ----------- |
37 | 41 | ||
38 | This driver implements support for the hardware monitoring capabilities of the | 42 | This driver implements support for the hardware monitoring capabilities of the |
39 | SMSC DME1737 and Asus A8000 (which are the same), SMSC SCH5027, and SMSC | 43 | SMSC DME1737 and Asus A8000 (which are the same), SMSC SCH5027, SCH311x, |
40 | SCH311x Super-I/O chips. These chips feature monitoring of 3 temp sensors | 44 | and SCH5127 Super-I/O chips. These chips feature monitoring of 3 temp sensors |
41 | temp[1-3] (2 remote diodes and 1 internal), 7 voltages in[0-6] (6 external and | 45 | temp[1-3] (2 remote diodes and 1 internal), 7 voltages in[0-6] (6 external and |
42 | 1 internal) and up to 6 fan speeds fan[1-6]. Additionally, the chips implement | 46 | 1 internal) and up to 6 fan speeds fan[1-6]. Additionally, the chips implement |
43 | up to 5 PWM outputs pwm[1-3,5-6] for controlling fan speeds both manually and | 47 | up to 5 PWM outputs pwm[1-3,5-6] for controlling fan speeds both manually and |
@@ -48,14 +52,14 @@ Fan[3-6] and pwm[3,5-6] are optional features and their availability depends on | |||
48 | the configuration of the chip. The driver will detect which features are | 52 | the configuration of the chip. The driver will detect which features are |
49 | present during initialization and create the sysfs attributes accordingly. | 53 | present during initialization and create the sysfs attributes accordingly. |
50 | 54 | ||
51 | For the SCH311x, fan[1-3] and pwm[1-3] are always present and fan[4-6] and | 55 | For the SCH311x and SCH5127, fan[1-3] and pwm[1-3] are always present and |
52 | pwm[5-6] don't exist. | 56 | fan[4-6] and pwm[5-6] don't exist. |
53 | 57 | ||
54 | The hardware monitoring features of the DME1737, A8000, and SCH5027 are only | 58 | The hardware monitoring features of the DME1737, A8000, and SCH5027 are only |
55 | accessible via SMBus, while the SCH311x only provides access via the ISA bus. | 59 | accessible via SMBus, while the SCH311x and SCH5127 only provide access via |
56 | The driver will therefore register itself as an I2C client driver if it detects | 60 | the ISA bus. The driver will therefore register itself as an I2C client driver |
57 | a DME1737, A8000, or SCH5027 and as a platform driver if it detects a SCH311x | 61 | if it detects a DME1737, A8000, or SCH5027 and as a platform driver if it |
58 | chip. | 62 | detects a SCH311x or SCH5127 chip. |
59 | 63 | ||
60 | 64 | ||
61 | Voltage Monitoring | 65 | Voltage Monitoring |
@@ -76,7 +80,7 @@ DME1737, A8000: | |||
76 | in6: Vbat (+3.0V) 0V - 4.38V | 80 | in6: Vbat (+3.0V) 0V - 4.38V |
77 | 81 | ||
78 | SCH311x: | 82 | SCH311x: |
79 | in0: +2.5V 0V - 6.64V | 83 | in0: +2.5V 0V - 3.32V |
80 | in1: Vccp (processor core) 0V - 2V | 84 | in1: Vccp (processor core) 0V - 2V |
81 | in2: VCC (internal +3.3V) 0V - 4.38V | 85 | in2: VCC (internal +3.3V) 0V - 4.38V |
82 | in3: +5V 0V - 6.64V | 86 | in3: +5V 0V - 6.64V |
@@ -93,6 +97,15 @@ SCH5027: | |||
93 | in5: VTR (+3.3V standby) 0V - 4.38V | 97 | in5: VTR (+3.3V standby) 0V - 4.38V |
94 | in6: Vbat (+3.0V) 0V - 4.38V | 98 | in6: Vbat (+3.0V) 0V - 4.38V |
95 | 99 | ||
100 | SCH5127: | ||
101 | in0: +2.5 0V - 3.32V | ||
102 | in1: Vccp (processor core) 0V - 3V | ||
103 | in2: VCC (internal +3.3V) 0V - 4.38V | ||
104 | in3: V2_IN 0V - 1.5V | ||
105 | in4: V1_IN 0V - 1.5V | ||
106 | in5: VTR (+3.3V standby) 0V - 4.38V | ||
107 | in6: Vbat (+3.0V) 0V - 4.38V | ||
108 | |||
96 | Each voltage input has associated min and max limits which trigger an alarm | 109 | Each voltage input has associated min and max limits which trigger an alarm |
97 | when crossed. | 110 | when crossed. |
98 | 111 | ||
@@ -293,3 +306,21 @@ pwm[1-3]_auto_point1_pwm RW Auto PWM pwm point. Auto_point1 is the | |||
293 | pwm[1-3]_auto_point2_pwm RO Auto PWM pwm point. Auto_point2 is the | 306 | pwm[1-3]_auto_point2_pwm RO Auto PWM pwm point. Auto_point2 is the |
294 | full-speed duty-cycle which is hard- | 307 | full-speed duty-cycle which is hard- |
295 | wired to 255 (100% duty-cycle). | 308 | wired to 255 (100% duty-cycle). |
309 | |||
310 | Chip Differences | ||
311 | ---------------- | ||
312 | |||
313 | Feature dme1737 sch311x sch5027 sch5127 | ||
314 | ------------------------------------------------------- | ||
315 | temp[1-3]_offset yes yes | ||
316 | vid yes | ||
317 | zone3 yes yes yes | ||
318 | zone[1-3]_hyst yes yes | ||
319 | pwm min/off yes yes | ||
320 | fan3 opt yes opt yes | ||
321 | pwm3 opt yes opt yes | ||
322 | fan4 opt opt | ||
323 | fan5 opt opt | ||
324 | pwm5 opt opt | ||
325 | fan6 opt opt | ||
326 | pwm6 opt opt | ||
diff --git a/Documentation/hwmon/lm63 b/Documentation/hwmon/lm63 index 31660bf97979..b9843eab1afb 100644 --- a/Documentation/hwmon/lm63 +++ b/Documentation/hwmon/lm63 | |||
@@ -7,6 +7,11 @@ Supported chips: | |||
7 | Addresses scanned: I2C 0x4c | 7 | Addresses scanned: I2C 0x4c |
8 | Datasheet: Publicly available at the National Semiconductor website | 8 | Datasheet: Publicly available at the National Semiconductor website |
9 | http://www.national.com/pf/LM/LM63.html | 9 | http://www.national.com/pf/LM/LM63.html |
10 | * National Semiconductor LM64 | ||
11 | Prefix: 'lm64' | ||
12 | Addresses scanned: I2C 0x18 and 0x4e | ||
13 | Datasheet: Publicly available at the National Semiconductor website | ||
14 | http://www.national.com/pf/LM/LM64.html | ||
10 | 15 | ||
11 | Author: Jean Delvare <khali@linux-fr.org> | 16 | Author: Jean Delvare <khali@linux-fr.org> |
12 | 17 | ||
@@ -55,3 +60,5 @@ The lm63 driver will not update its values more frequently than every | |||
55 | second; reading them more often will do no harm, but will return 'old' | 60 | second; reading them more often will do no harm, but will return 'old' |
56 | values. | 61 | values. |
57 | 62 | ||
63 | The LM64 is effectively an LM63 with GPIO lines. The driver does not | ||
64 | support these GPIO lines at present. | ||
diff --git a/Documentation/hwmon/ltc4245 b/Documentation/hwmon/ltc4245 index 02838a47d862..86b5880d8502 100644 --- a/Documentation/hwmon/ltc4245 +++ b/Documentation/hwmon/ltc4245 | |||
@@ -72,9 +72,7 @@ in6_min_alarm 5v output undervoltage alarm | |||
72 | in7_min_alarm 3v output undervoltage alarm | 72 | in7_min_alarm 3v output undervoltage alarm |
73 | in8_min_alarm Vee (-12v) output undervoltage alarm | 73 | in8_min_alarm Vee (-12v) output undervoltage alarm |
74 | 74 | ||
75 | in9_input GPIO #1 voltage data | 75 | in9_input GPIO voltage data |
76 | in10_input GPIO #2 voltage data | ||
77 | in11_input GPIO #3 voltage data | ||
78 | 76 | ||
79 | power1_input 12v power usage (mW) | 77 | power1_input 12v power usage (mW) |
80 | power2_input 5v power usage (mW) | 78 | power2_input 5v power usage (mW) |
diff --git a/Documentation/hwmon/sysfs-interface b/Documentation/hwmon/sysfs-interface index 3de6b0bcb147..d4e2917c6f18 100644 --- a/Documentation/hwmon/sysfs-interface +++ b/Documentation/hwmon/sysfs-interface | |||
@@ -80,9 +80,9 @@ All entries (except name) are optional, and should only be created in a | |||
80 | given driver if the chip has the feature. | 80 | given driver if the chip has the feature. |
81 | 81 | ||
82 | 82 | ||
83 | ******** | 83 | ********************* |
84 | * Name * | 84 | * Global attributes * |
85 | ******** | 85 | ********************* |
86 | 86 | ||
87 | name The chip name. | 87 | name The chip name. |
88 | This should be a short, lowercase string, not containing | 88 | This should be a short, lowercase string, not containing |
@@ -91,6 +91,13 @@ name The chip name. | |||
91 | I2C devices get this attribute created automatically. | 91 | I2C devices get this attribute created automatically. |
92 | RO | 92 | RO |
93 | 93 | ||
94 | update_rate The rate at which the chip will update readings. | ||
95 | Unit: millisecond | ||
96 | RW | ||
97 | Some devices have a variable update rate. This attribute | ||
98 | can be used to change the update rate to the desired | ||
99 | frequency. | ||
100 | |||
94 | 101 | ||
95 | ************ | 102 | ************ |
96 | * Voltages * | 103 | * Voltages * |
diff --git a/Documentation/hwmon/tmp102 b/Documentation/hwmon/tmp102 new file mode 100644 index 000000000000..8454a7763122 --- /dev/null +++ b/Documentation/hwmon/tmp102 | |||
@@ -0,0 +1,26 @@ | |||
1 | Kernel driver tmp102 | ||
2 | ==================== | ||
3 | |||
4 | Supported chips: | ||
5 | * Texas Instruments TMP102 | ||
6 | Prefix: 'tmp102' | ||
7 | Addresses scanned: none | ||
8 | Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp102.html | ||
9 | |||
10 | Author: | ||
11 | Steven King <sfking@fdwdc.com> | ||
12 | |||
13 | Description | ||
14 | ----------- | ||
15 | |||
16 | The Texas Instruments TMP102 implements one temperature sensor. Limits can be | ||
17 | set through the Overtemperature Shutdown register and Hysteresis register. The | ||
18 | sensor is accurate to 0.5 degree over the range of -25 to +85 C, and to 1.0 | ||
19 | degree from -40 to +125 C. Resolution of the sensor is 0.0625 degree. The | ||
20 | operating temperature has a minimum of -55 C and a maximum of +150 C. | ||
21 | |||
22 | The TMP102 has a programmable update rate that can select between 8, 4, 1, and | ||
23 | 0.5 Hz. (Currently the driver only supports the default of 4 Hz). | ||
24 | |||
25 | The driver provides the common sysfs-interface for temperatures (see | ||
26 | Documentation/hwmon/sysfs-interface under Temperatures). | ||
diff --git a/arch/arm/mach-mx3/mach-mx31moboard.c b/arch/arm/mach-mx3/mach-mx31moboard.c index 33a8d35498a7..62b5e40165df 100644 --- a/arch/arm/mach-mx3/mach-mx31moboard.c +++ b/arch/arm/mach-mx3/mach-mx31moboard.c | |||
@@ -220,11 +220,54 @@ static struct mc13783_regulator_init_data moboard_regulators[] = { | |||
220 | }, | 220 | }, |
221 | }; | 221 | }; |
222 | 222 | ||
223 | static struct mc13783_led_platform_data moboard_led[] = { | ||
224 | { | ||
225 | .id = MC13783_LED_R1, | ||
226 | .name = "coreboard-led-4:red", | ||
227 | .max_current = 2, | ||
228 | }, | ||
229 | { | ||
230 | .id = MC13783_LED_G1, | ||
231 | .name = "coreboard-led-4:green", | ||
232 | .max_current = 2, | ||
233 | }, | ||
234 | { | ||
235 | .id = MC13783_LED_B1, | ||
236 | .name = "coreboard-led-4:blue", | ||
237 | .max_current = 2, | ||
238 | }, | ||
239 | { | ||
240 | .id = MC13783_LED_R2, | ||
241 | .name = "coreboard-led-5:red", | ||
242 | .max_current = 3, | ||
243 | }, | ||
244 | { | ||
245 | .id = MC13783_LED_G2, | ||
246 | .name = "coreboard-led-5:green", | ||
247 | .max_current = 3, | ||
248 | }, | ||
249 | { | ||
250 | .id = MC13783_LED_B2, | ||
251 | .name = "coreboard-led-5:blue", | ||
252 | .max_current = 3, | ||
253 | }, | ||
254 | }; | ||
255 | |||
256 | static struct mc13783_leds_platform_data moboard_leds = { | ||
257 | .num_leds = ARRAY_SIZE(moboard_led), | ||
258 | .led = moboard_led, | ||
259 | .flags = MC13783_LED_SLEWLIMTC, | ||
260 | .abmode = MC13783_LED_AB_DISABLED, | ||
261 | .tc1_period = MC13783_LED_PERIOD_10MS, | ||
262 | .tc2_period = MC13783_LED_PERIOD_10MS, | ||
263 | }; | ||
264 | |||
223 | static struct mc13783_platform_data moboard_pmic = { | 265 | static struct mc13783_platform_data moboard_pmic = { |
224 | .regulators = moboard_regulators, | 266 | .regulators = moboard_regulators, |
225 | .num_regulators = ARRAY_SIZE(moboard_regulators), | 267 | .num_regulators = ARRAY_SIZE(moboard_regulators), |
268 | .leds = &moboard_leds, | ||
226 | .flags = MC13783_USE_REGULATOR | MC13783_USE_RTC | | 269 | .flags = MC13783_USE_REGULATOR | MC13783_USE_RTC | |
227 | MC13783_USE_ADC, | 270 | MC13783_USE_ADC | MC13783_USE_LED, |
228 | }; | 271 | }; |
229 | 272 | ||
230 | static struct spi_board_info moboard_spi_board_info[] __initdata = { | 273 | static struct spi_board_info moboard_spi_board_info[] __initdata = { |
diff --git a/arch/arm/mach-orion5x/dns323-setup.c b/arch/arm/mach-orion5x/dns323-setup.c index 685f34a9634b..fe0de1698edc 100644 --- a/arch/arm/mach-orion5x/dns323-setup.c +++ b/arch/arm/mach-orion5x/dns323-setup.c | |||
@@ -240,22 +240,23 @@ error_fail: | |||
240 | 240 | ||
241 | #define ORION_BLINK_HALF_PERIOD 100 /* ms */ | 241 | #define ORION_BLINK_HALF_PERIOD 100 /* ms */ |
242 | 242 | ||
243 | static int dns323_gpio_blink_set(unsigned gpio, | 243 | static int dns323_gpio_blink_set(unsigned gpio, int state, |
244 | unsigned long *delay_on, unsigned long *delay_off) | 244 | unsigned long *delay_on, unsigned long *delay_off) |
245 | { | 245 | { |
246 | static int value = 0; | ||
247 | 246 | ||
248 | if (!*delay_on && !*delay_off) | 247 | if (delay_on && delay_off && !*delay_on && !*delay_off) |
249 | *delay_on = *delay_off = ORION_BLINK_HALF_PERIOD; | 248 | *delay_on = *delay_off = ORION_BLINK_HALF_PERIOD; |
250 | 249 | ||
251 | if (ORION_BLINK_HALF_PERIOD == *delay_on | 250 | switch(state) { |
252 | && ORION_BLINK_HALF_PERIOD == *delay_off) { | 251 | case GPIO_LED_NO_BLINK_LOW: |
253 | value = !value; | 252 | case GPIO_LED_NO_BLINK_HIGH: |
254 | orion_gpio_set_blink(gpio, value); | 253 | orion_gpio_set_blink(gpio, 0); |
255 | return 0; | 254 | gpio_set_value(gpio, state); |
255 | break; | ||
256 | case GPIO_LED_BLINK: | ||
257 | orion_gpio_set_blink(gpio, 1); | ||
256 | } | 258 | } |
257 | 259 | return 0; | |
258 | return -EINVAL; | ||
259 | } | 260 | } |
260 | 261 | ||
261 | static struct gpio_led dns323_leds[] = { | 262 | static struct gpio_led dns323_leds[] = { |
@@ -263,6 +264,7 @@ static struct gpio_led dns323_leds[] = { | |||
263 | .name = "power:blue", | 264 | .name = "power:blue", |
264 | .gpio = DNS323_GPIO_LED_POWER2, | 265 | .gpio = DNS323_GPIO_LED_POWER2, |
265 | .default_trigger = "timer", | 266 | .default_trigger = "timer", |
267 | .active_low = 1, | ||
266 | }, { | 268 | }, { |
267 | .name = "right:amber", | 269 | .name = "right:amber", |
268 | .gpio = DNS323_GPIO_LED_RIGHT_AMBER, | 270 | .gpio = DNS323_GPIO_LED_RIGHT_AMBER, |
diff --git a/arch/arm/mach-s3c2440/mach-gta02.c b/arch/arm/mach-s3c2440/mach-gta02.c index 45799c608d8f..9e39faa283b9 100644 --- a/arch/arm/mach-s3c2440/mach-gta02.c +++ b/arch/arm/mach-s3c2440/mach-gta02.c | |||
@@ -49,7 +49,6 @@ | |||
49 | #include <linux/io.h> | 49 | #include <linux/io.h> |
50 | 50 | ||
51 | #include <linux/i2c.h> | 51 | #include <linux/i2c.h> |
52 | #include <linux/backlight.h> | ||
53 | #include <linux/regulator/machine.h> | 52 | #include <linux/regulator/machine.h> |
54 | 53 | ||
55 | #include <linux/mfd/pcf50633/core.h> | 54 | #include <linux/mfd/pcf50633/core.h> |
@@ -57,6 +56,7 @@ | |||
57 | #include <linux/mfd/pcf50633/adc.h> | 56 | #include <linux/mfd/pcf50633/adc.h> |
58 | #include <linux/mfd/pcf50633/gpio.h> | 57 | #include <linux/mfd/pcf50633/gpio.h> |
59 | #include <linux/mfd/pcf50633/pmic.h> | 58 | #include <linux/mfd/pcf50633/pmic.h> |
59 | #include <linux/mfd/pcf50633/backlight.h> | ||
60 | 60 | ||
61 | #include <asm/mach/arch.h> | 61 | #include <asm/mach/arch.h> |
62 | #include <asm/mach/map.h> | 62 | #include <asm/mach/map.h> |
@@ -254,6 +254,12 @@ static char *gta02_batteries[] = { | |||
254 | "battery", | 254 | "battery", |
255 | }; | 255 | }; |
256 | 256 | ||
257 | static struct pcf50633_bl_platform_data gta02_backlight_data = { | ||
258 | .default_brightness = 0x3f, | ||
259 | .default_brightness_limit = 0, | ||
260 | .ramp_time = 5, | ||
261 | }; | ||
262 | |||
257 | struct pcf50633_platform_data gta02_pcf_pdata = { | 263 | struct pcf50633_platform_data gta02_pcf_pdata = { |
258 | .resumers = { | 264 | .resumers = { |
259 | [0] = PCF50633_INT1_USBINS | | 265 | [0] = PCF50633_INT1_USBINS | |
@@ -271,6 +277,8 @@ struct pcf50633_platform_data gta02_pcf_pdata = { | |||
271 | 277 | ||
272 | .charger_reference_current_ma = 1000, | 278 | .charger_reference_current_ma = 1000, |
273 | 279 | ||
280 | .backlight_data = >a02_backlight_data, | ||
281 | |||
274 | .reg_init_data = { | 282 | .reg_init_data = { |
275 | [PCF50633_REGULATOR_AUTO] = { | 283 | [PCF50633_REGULATOR_AUTO] = { |
276 | .constraints = { | 284 | .constraints = { |
@@ -478,71 +486,6 @@ static struct s3c2410_udc_mach_info gta02_udc_cfg = { | |||
478 | 486 | ||
479 | }; | 487 | }; |
480 | 488 | ||
481 | |||
482 | |||
483 | static void gta02_bl_set_intensity(int intensity) | ||
484 | { | ||
485 | struct pcf50633 *pcf = gta02_pcf; | ||
486 | int old_intensity = pcf50633_reg_read(pcf, PCF50633_REG_LEDOUT); | ||
487 | |||
488 | /* We map 8-bit intensity to 6-bit intensity in hardware. */ | ||
489 | intensity >>= 2; | ||
490 | |||
491 | /* | ||
492 | * This can happen during, eg, print of panic on blanked console, | ||
493 | * but we can't service i2c without interrupts active, so abort. | ||
494 | */ | ||
495 | if (in_atomic()) { | ||
496 | printk(KERN_ERR "gta02_bl_set_intensity called while atomic\n"); | ||
497 | return; | ||
498 | } | ||
499 | |||
500 | old_intensity = pcf50633_reg_read(pcf, PCF50633_REG_LEDOUT); | ||
501 | if (intensity == old_intensity) | ||
502 | return; | ||
503 | |||
504 | /* We can't do this anywhere else. */ | ||
505 | pcf50633_reg_write(pcf, PCF50633_REG_LEDDIM, 5); | ||
506 | |||
507 | if (!(pcf50633_reg_read(pcf, PCF50633_REG_LEDENA) & 3)) | ||
508 | old_intensity = 0; | ||
509 | |||
510 | /* | ||
511 | * The PCF50633 cannot handle LEDOUT = 0 (datasheet p60) | ||
512 | * if seen, you have to re-enable the LED unit. | ||
513 | */ | ||
514 | if (!intensity || !old_intensity) | ||
515 | pcf50633_reg_write(pcf, PCF50633_REG_LEDENA, 0); | ||
516 | |||
517 | /* Illegal to set LEDOUT to 0. */ | ||
518 | if (!intensity) | ||
519 | pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_LEDOUT, 0x3f, 2); | ||
520 | else | ||
521 | pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_LEDOUT, 0x3f, | ||
522 | intensity); | ||
523 | |||
524 | if (intensity) | ||
525 | pcf50633_reg_write(pcf, PCF50633_REG_LEDENA, 2); | ||
526 | |||
527 | } | ||
528 | |||
529 | static struct generic_bl_info gta02_bl_info = { | ||
530 | .name = "gta02-bl", | ||
531 | .max_intensity = 0xff, | ||
532 | .default_intensity = 0xff, | ||
533 | .set_bl_intensity = gta02_bl_set_intensity, | ||
534 | }; | ||
535 | |||
536 | static struct platform_device gta02_bl_dev = { | ||
537 | .name = "generic-bl", | ||
538 | .id = 1, | ||
539 | .dev = { | ||
540 | .platform_data = >a02_bl_info, | ||
541 | }, | ||
542 | }; | ||
543 | |||
544 | |||
545 | |||
546 | /* USB */ | 489 | /* USB */ |
547 | static struct s3c2410_hcd_info gta02_usb_info __initdata = { | 490 | static struct s3c2410_hcd_info gta02_usb_info __initdata = { |
548 | .port[0] = { | 491 | .port[0] = { |
@@ -579,7 +522,6 @@ static struct platform_device *gta02_devices[] __initdata = { | |||
579 | /* These guys DO need to be children of PMU. */ | 522 | /* These guys DO need to be children of PMU. */ |
580 | 523 | ||
581 | static struct platform_device *gta02_devices_pmu_children[] = { | 524 | static struct platform_device *gta02_devices_pmu_children[] = { |
582 | >a02_bl_dev, | ||
583 | }; | 525 | }; |
584 | 526 | ||
585 | 527 | ||
diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c index 34ce49f80eac..0ec92c8861dd 100644 --- a/arch/sparc/kernel/perf_event.c +++ b/arch/sparc/kernel/perf_event.c | |||
@@ -92,6 +92,8 @@ struct cpu_hw_events { | |||
92 | 92 | ||
93 | /* Enabled/disable state. */ | 93 | /* Enabled/disable state. */ |
94 | int enabled; | 94 | int enabled; |
95 | |||
96 | unsigned int group_flag; | ||
95 | }; | 97 | }; |
96 | DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = { .enabled = 1, }; | 98 | DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = { .enabled = 1, }; |
97 | 99 | ||
@@ -981,53 +983,6 @@ static int collect_events(struct perf_event *group, int max_count, | |||
981 | return n; | 983 | return n; |
982 | } | 984 | } |
983 | 985 | ||
984 | static void event_sched_in(struct perf_event *event) | ||
985 | { | ||
986 | event->state = PERF_EVENT_STATE_ACTIVE; | ||
987 | event->oncpu = smp_processor_id(); | ||
988 | event->tstamp_running += event->ctx->time - event->tstamp_stopped; | ||
989 | if (is_software_event(event)) | ||
990 | event->pmu->enable(event); | ||
991 | } | ||
992 | |||
993 | int hw_perf_group_sched_in(struct perf_event *group_leader, | ||
994 | struct perf_cpu_context *cpuctx, | ||
995 | struct perf_event_context *ctx) | ||
996 | { | ||
997 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
998 | struct perf_event *sub; | ||
999 | int n0, n; | ||
1000 | |||
1001 | if (!sparc_pmu) | ||
1002 | return 0; | ||
1003 | |||
1004 | n0 = cpuc->n_events; | ||
1005 | n = collect_events(group_leader, perf_max_events - n0, | ||
1006 | &cpuc->event[n0], &cpuc->events[n0], | ||
1007 | &cpuc->current_idx[n0]); | ||
1008 | if (n < 0) | ||
1009 | return -EAGAIN; | ||
1010 | if (check_excludes(cpuc->event, n0, n)) | ||
1011 | return -EINVAL; | ||
1012 | if (sparc_check_constraints(cpuc->event, cpuc->events, n + n0)) | ||
1013 | return -EAGAIN; | ||
1014 | cpuc->n_events = n0 + n; | ||
1015 | cpuc->n_added += n; | ||
1016 | |||
1017 | cpuctx->active_oncpu += n; | ||
1018 | n = 1; | ||
1019 | event_sched_in(group_leader); | ||
1020 | list_for_each_entry(sub, &group_leader->sibling_list, group_entry) { | ||
1021 | if (sub->state != PERF_EVENT_STATE_OFF) { | ||
1022 | event_sched_in(sub); | ||
1023 | n++; | ||
1024 | } | ||
1025 | } | ||
1026 | ctx->nr_active += n; | ||
1027 | |||
1028 | return 1; | ||
1029 | } | ||
1030 | |||
1031 | static int sparc_pmu_enable(struct perf_event *event) | 986 | static int sparc_pmu_enable(struct perf_event *event) |
1032 | { | 987 | { |
1033 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 988 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
@@ -1045,11 +1000,20 @@ static int sparc_pmu_enable(struct perf_event *event) | |||
1045 | cpuc->events[n0] = event->hw.event_base; | 1000 | cpuc->events[n0] = event->hw.event_base; |
1046 | cpuc->current_idx[n0] = PIC_NO_INDEX; | 1001 | cpuc->current_idx[n0] = PIC_NO_INDEX; |
1047 | 1002 | ||
1003 | /* | ||
1004 | * If group events scheduling transaction was started, | ||
1005 | * skip the schedulability test here, it will be peformed | ||
1006 | * at commit time(->commit_txn) as a whole | ||
1007 | */ | ||
1008 | if (cpuc->group_flag & PERF_EVENT_TXN_STARTED) | ||
1009 | goto nocheck; | ||
1010 | |||
1048 | if (check_excludes(cpuc->event, n0, 1)) | 1011 | if (check_excludes(cpuc->event, n0, 1)) |
1049 | goto out; | 1012 | goto out; |
1050 | if (sparc_check_constraints(cpuc->event, cpuc->events, n0 + 1)) | 1013 | if (sparc_check_constraints(cpuc->event, cpuc->events, n0 + 1)) |
1051 | goto out; | 1014 | goto out; |
1052 | 1015 | ||
1016 | nocheck: | ||
1053 | cpuc->n_events++; | 1017 | cpuc->n_events++; |
1054 | cpuc->n_added++; | 1018 | cpuc->n_added++; |
1055 | 1019 | ||
@@ -1129,11 +1093,61 @@ static int __hw_perf_event_init(struct perf_event *event) | |||
1129 | return 0; | 1093 | return 0; |
1130 | } | 1094 | } |
1131 | 1095 | ||
1096 | /* | ||
1097 | * Start group events scheduling transaction | ||
1098 | * Set the flag to make pmu::enable() not perform the | ||
1099 | * schedulability test, it will be performed at commit time | ||
1100 | */ | ||
1101 | static void sparc_pmu_start_txn(const struct pmu *pmu) | ||
1102 | { | ||
1103 | struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events); | ||
1104 | |||
1105 | cpuhw->group_flag |= PERF_EVENT_TXN_STARTED; | ||
1106 | } | ||
1107 | |||
1108 | /* | ||
1109 | * Stop group events scheduling transaction | ||
1110 | * Clear the flag and pmu::enable() will perform the | ||
1111 | * schedulability test. | ||
1112 | */ | ||
1113 | static void sparc_pmu_cancel_txn(const struct pmu *pmu) | ||
1114 | { | ||
1115 | struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events); | ||
1116 | |||
1117 | cpuhw->group_flag &= ~PERF_EVENT_TXN_STARTED; | ||
1118 | } | ||
1119 | |||
1120 | /* | ||
1121 | * Commit group events scheduling transaction | ||
1122 | * Perform the group schedulability test as a whole | ||
1123 | * Return 0 if success | ||
1124 | */ | ||
1125 | static int sparc_pmu_commit_txn(const struct pmu *pmu) | ||
1126 | { | ||
1127 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
1128 | int n; | ||
1129 | |||
1130 | if (!sparc_pmu) | ||
1131 | return -EINVAL; | ||
1132 | |||
1133 | cpuc = &__get_cpu_var(cpu_hw_events); | ||
1134 | n = cpuc->n_events; | ||
1135 | if (check_excludes(cpuc->event, 0, n)) | ||
1136 | return -EINVAL; | ||
1137 | if (sparc_check_constraints(cpuc->event, cpuc->events, n)) | ||
1138 | return -EAGAIN; | ||
1139 | |||
1140 | return 0; | ||
1141 | } | ||
1142 | |||
1132 | static const struct pmu pmu = { | 1143 | static const struct pmu pmu = { |
1133 | .enable = sparc_pmu_enable, | 1144 | .enable = sparc_pmu_enable, |
1134 | .disable = sparc_pmu_disable, | 1145 | .disable = sparc_pmu_disable, |
1135 | .read = sparc_pmu_read, | 1146 | .read = sparc_pmu_read, |
1136 | .unthrottle = sparc_pmu_unthrottle, | 1147 | .unthrottle = sparc_pmu_unthrottle, |
1148 | .start_txn = sparc_pmu_start_txn, | ||
1149 | .cancel_txn = sparc_pmu_cancel_txn, | ||
1150 | .commit_txn = sparc_pmu_commit_txn, | ||
1137 | }; | 1151 | }; |
1138 | 1152 | ||
1139 | const struct pmu *hw_perf_event_init(struct perf_event *event) | 1153 | const struct pmu *hw_perf_event_init(struct perf_event *event) |
diff --git a/arch/x86/include/asm/perf_event_p4.h b/arch/x86/include/asm/perf_event_p4.h index b05400a542ff..64a8ebff06fc 100644 --- a/arch/x86/include/asm/perf_event_p4.h +++ b/arch/x86/include/asm/perf_event_p4.h | |||
@@ -89,7 +89,8 @@ | |||
89 | P4_CCCR_ENABLE) | 89 | P4_CCCR_ENABLE) |
90 | 90 | ||
91 | /* HT mask */ | 91 | /* HT mask */ |
92 | #define P4_CCCR_MASK_HT (P4_CCCR_MASK | P4_CCCR_THREAD_ANY) | 92 | #define P4_CCCR_MASK_HT \ |
93 | (P4_CCCR_MASK | P4_CCCR_OVF_PMI_T1 | P4_CCCR_THREAD_ANY) | ||
93 | 94 | ||
94 | #define P4_GEN_ESCR_EMASK(class, name, bit) \ | 95 | #define P4_GEN_ESCR_EMASK(class, name, bit) \ |
95 | class##__##name = ((1 << bit) << P4_ESCR_EVENTMASK_SHIFT) | 96 | class##__##name = ((1 << bit) << P4_ESCR_EVENTMASK_SHIFT) |
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c index fd4db0db3708..c77586061bcb 100644 --- a/arch/x86/kernel/cpu/perf_event.c +++ b/arch/x86/kernel/cpu/perf_event.c | |||
@@ -1717,7 +1717,11 @@ void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip, int ski | |||
1717 | */ | 1717 | */ |
1718 | regs->bp = rewind_frame_pointer(skip + 1); | 1718 | regs->bp = rewind_frame_pointer(skip + 1); |
1719 | regs->cs = __KERNEL_CS; | 1719 | regs->cs = __KERNEL_CS; |
1720 | local_save_flags(regs->flags); | 1720 | /* |
1721 | * We abuse bit 3 to pass exact information, see perf_misc_flags | ||
1722 | * and the comment with PERF_EFLAGS_EXACT. | ||
1723 | */ | ||
1724 | regs->flags = 0; | ||
1721 | } | 1725 | } |
1722 | 1726 | ||
1723 | unsigned long perf_instruction_pointer(struct pt_regs *regs) | 1727 | unsigned long perf_instruction_pointer(struct pt_regs *regs) |
diff --git a/arch/x86/kernel/cpu/perf_event_p4.c b/arch/x86/kernel/cpu/perf_event_p4.c index 424fc8de68e4..ae85d69644d1 100644 --- a/arch/x86/kernel/cpu/perf_event_p4.c +++ b/arch/x86/kernel/cpu/perf_event_p4.c | |||
@@ -465,15 +465,21 @@ out: | |||
465 | return rc; | 465 | return rc; |
466 | } | 466 | } |
467 | 467 | ||
468 | static inline void p4_pmu_clear_cccr_ovf(struct hw_perf_event *hwc) | 468 | static inline int p4_pmu_clear_cccr_ovf(struct hw_perf_event *hwc) |
469 | { | 469 | { |
470 | unsigned long dummy; | 470 | int overflow = 0; |
471 | u32 low, high; | ||
471 | 472 | ||
472 | rdmsrl(hwc->config_base + hwc->idx, dummy); | 473 | rdmsr(hwc->config_base + hwc->idx, low, high); |
473 | if (dummy & P4_CCCR_OVF) { | 474 | |
475 | /* we need to check high bit for unflagged overflows */ | ||
476 | if ((low & P4_CCCR_OVF) || !(high & (1 << 31))) { | ||
477 | overflow = 1; | ||
474 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, | 478 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, |
475 | ((u64)dummy) & ~P4_CCCR_OVF); | 479 | ((u64)low) & ~P4_CCCR_OVF); |
476 | } | 480 | } |
481 | |||
482 | return overflow; | ||
477 | } | 483 | } |
478 | 484 | ||
479 | static inline void p4_pmu_disable_event(struct perf_event *event) | 485 | static inline void p4_pmu_disable_event(struct perf_event *event) |
@@ -584,21 +590,15 @@ static int p4_pmu_handle_irq(struct pt_regs *regs) | |||
584 | 590 | ||
585 | WARN_ON_ONCE(hwc->idx != idx); | 591 | WARN_ON_ONCE(hwc->idx != idx); |
586 | 592 | ||
587 | /* | 593 | /* it might be unflagged overflow */ |
588 | * FIXME: Redundant call, actually not needed | 594 | handled = p4_pmu_clear_cccr_ovf(hwc); |
589 | * but just to check if we're screwed | ||
590 | */ | ||
591 | p4_pmu_clear_cccr_ovf(hwc); | ||
592 | 595 | ||
593 | val = x86_perf_event_update(event); | 596 | val = x86_perf_event_update(event); |
594 | if (val & (1ULL << (x86_pmu.cntval_bits - 1))) | 597 | if (!handled && (val & (1ULL << (x86_pmu.cntval_bits - 1)))) |
595 | continue; | 598 | continue; |
596 | 599 | ||
597 | /* | 600 | /* event overflow for sure */ |
598 | * event overflow | 601 | data.period = event->hw.last_period; |
599 | */ | ||
600 | handled = 1; | ||
601 | data.period = event->hw.last_period; | ||
602 | 602 | ||
603 | if (!x86_perf_event_set_period(event)) | 603 | if (!x86_perf_event_set_period(event)) |
604 | continue; | 604 | continue; |
@@ -670,7 +670,7 @@ static void p4_pmu_swap_config_ts(struct hw_perf_event *hwc, int cpu) | |||
670 | 670 | ||
671 | /* | 671 | /* |
672 | * ESCR address hashing is tricky, ESCRs are not sequential | 672 | * ESCR address hashing is tricky, ESCRs are not sequential |
673 | * in memory but all starts from MSR_P4_BSU_ESCR0 (0x03e0) and | 673 | * in memory but all starts from MSR_P4_BSU_ESCR0 (0x03a0) and |
674 | * the metric between any ESCRs is laid in range [0xa0,0xe1] | 674 | * the metric between any ESCRs is laid in range [0xa0,0xe1] |
675 | * | 675 | * |
676 | * so we make ~70% filled hashtable | 676 | * so we make ~70% filled hashtable |
@@ -735,8 +735,9 @@ static int p4_get_escr_idx(unsigned int addr) | |||
735 | { | 735 | { |
736 | unsigned int idx = P4_ESCR_MSR_IDX(addr); | 736 | unsigned int idx = P4_ESCR_MSR_IDX(addr); |
737 | 737 | ||
738 | if (unlikely(idx >= P4_ESCR_MSR_TABLE_SIZE || | 738 | if (unlikely(idx >= P4_ESCR_MSR_TABLE_SIZE || |
739 | !p4_escr_table[idx])) { | 739 | !p4_escr_table[idx] || |
740 | p4_escr_table[idx] != addr)) { | ||
740 | WARN_ONCE(1, "P4 PMU: Wrong address passed: %x\n", addr); | 741 | WARN_ONCE(1, "P4 PMU: Wrong address passed: %x\n", addr); |
741 | return -1; | 742 | return -1; |
742 | } | 743 | } |
@@ -762,7 +763,7 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign | |||
762 | { | 763 | { |
763 | unsigned long used_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; | 764 | unsigned long used_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; |
764 | unsigned long escr_mask[BITS_TO_LONGS(P4_ESCR_MSR_TABLE_SIZE)]; | 765 | unsigned long escr_mask[BITS_TO_LONGS(P4_ESCR_MSR_TABLE_SIZE)]; |
765 | int cpu = raw_smp_processor_id(); | 766 | int cpu = smp_processor_id(); |
766 | struct hw_perf_event *hwc; | 767 | struct hw_perf_event *hwc; |
767 | struct p4_event_bind *bind; | 768 | struct p4_event_bind *bind; |
768 | unsigned int i, thread, num; | 769 | unsigned int i, thread, num; |
diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c index df3d5c861cda..308e32570d84 100644 --- a/arch/x86/mm/pf_in.c +++ b/arch/x86/mm/pf_in.c | |||
@@ -34,7 +34,7 @@ | |||
34 | /* IA32 Manual 3, 2-1 */ | 34 | /* IA32 Manual 3, 2-1 */ |
35 | static unsigned char prefix_codes[] = { | 35 | static unsigned char prefix_codes[] = { |
36 | 0xF0, 0xF2, 0xF3, 0x2E, 0x36, 0x3E, 0x26, 0x64, | 36 | 0xF0, 0xF2, 0xF3, 0x2E, 0x36, 0x3E, 0x26, 0x64, |
37 | 0x65, 0x2E, 0x3E, 0x66, 0x67 | 37 | 0x65, 0x66, 0x67 |
38 | }; | 38 | }; |
39 | /* IA32 Manual 3, 3-432*/ | 39 | /* IA32 Manual 3, 3-432*/ |
40 | static unsigned int reg_rop[] = { | 40 | static unsigned int reg_rop[] = { |
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index 4bc1c4178f50..78418ce4fc78 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c | |||
@@ -1207,6 +1207,15 @@ int acpi_check_mem_region(resource_size_t start, resource_size_t n, | |||
1207 | EXPORT_SYMBOL(acpi_check_mem_region); | 1207 | EXPORT_SYMBOL(acpi_check_mem_region); |
1208 | 1208 | ||
1209 | /* | 1209 | /* |
1210 | * Let drivers know whether the resource checks are effective | ||
1211 | */ | ||
1212 | int acpi_resources_are_enforced(void) | ||
1213 | { | ||
1214 | return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT; | ||
1215 | } | ||
1216 | EXPORT_SYMBOL(acpi_resources_are_enforced); | ||
1217 | |||
1218 | /* | ||
1210 | * Acquire a spinlock. | 1219 | * Acquire a spinlock. |
1211 | * | 1220 | * |
1212 | * handle is a pointer to the spinlock_t. | 1221 | * handle is a pointer to the spinlock_t. |
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 6a9ac754ca5d..e19cf8eb6ccf 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig | |||
@@ -447,13 +447,14 @@ config SENSORS_IT87 | |||
447 | will be called it87. | 447 | will be called it87. |
448 | 448 | ||
449 | config SENSORS_LM63 | 449 | config SENSORS_LM63 |
450 | tristate "National Semiconductor LM63" | 450 | tristate "National Semiconductor LM63 and LM64" |
451 | depends on I2C | 451 | depends on I2C |
452 | help | 452 | help |
453 | If you say yes here you get support for the National Semiconductor | 453 | If you say yes here you get support for the National |
454 | LM63 remote diode digital temperature sensor with integrated fan | 454 | Semiconductor LM63 and LM64 remote diode digital temperature |
455 | control. Such chips are found on the Tyan S4882 (Thunder K8QS Pro) | 455 | sensors with integrated fan control. Such chips are found |
456 | motherboard, among others. | 456 | on the Tyan S4882 (Thunder K8QS Pro) motherboard, among |
457 | others. | ||
457 | 458 | ||
458 | This driver can also be built as a module. If so, the module | 459 | This driver can also be built as a module. If so, the module |
459 | will be called lm63. | 460 | will be called lm63. |
@@ -492,7 +493,8 @@ config SENSORS_LM75 | |||
492 | - NXP's LM75A | 493 | - NXP's LM75A |
493 | - ST Microelectronics STDS75 | 494 | - ST Microelectronics STDS75 |
494 | - TelCom (now Microchip) TCN75 | 495 | - TelCom (now Microchip) TCN75 |
495 | - Texas Instruments TMP100, TMP101, TMP75, TMP175, TMP275 | 496 | - Texas Instruments TMP100, TMP101, TMP105, TMP75, TMP175, |
497 | TMP275 | ||
496 | 498 | ||
497 | This driver supports driver model based binding through board | 499 | This driver supports driver model based binding through board |
498 | specific I2C device tables. | 500 | specific I2C device tables. |
@@ -749,6 +751,16 @@ config SENSORS_DME1737 | |||
749 | This driver can also be built as a module. If so, the module | 751 | This driver can also be built as a module. If so, the module |
750 | will be called dme1737. | 752 | will be called dme1737. |
751 | 753 | ||
754 | config SENSORS_EMC1403 | ||
755 | tristate "SMSC EMC1403 thermal sensor" | ||
756 | depends on I2C | ||
757 | help | ||
758 | If you say yes here you get support for the SMSC EMC1403 | ||
759 | temperature monitoring chip. | ||
760 | |||
761 | Threshold values can be configured using sysfs. | ||
762 | Data from the different diodes are accessible via sysfs. | ||
763 | |||
752 | config SENSORS_SMSC47M1 | 764 | config SENSORS_SMSC47M1 |
753 | tristate "SMSC LPC47M10x and compatibles" | 765 | tristate "SMSC LPC47M10x and compatibles" |
754 | help | 766 | help |
@@ -831,6 +843,16 @@ config SENSORS_THMC50 | |||
831 | This driver can also be built as a module. If so, the module | 843 | This driver can also be built as a module. If so, the module |
832 | will be called thmc50. | 844 | will be called thmc50. |
833 | 845 | ||
846 | config SENSORS_TMP102 | ||
847 | tristate "Texas Instruments TMP102" | ||
848 | depends on I2C && EXPERIMENTAL | ||
849 | help | ||
850 | If you say yes here you get support for Texas Instruments TMP102 | ||
851 | sensor chips. | ||
852 | |||
853 | This driver can also be built as a module. If so, the module | ||
854 | will be called tmp102. | ||
855 | |||
834 | config SENSORS_TMP401 | 856 | config SENSORS_TMP401 |
835 | tristate "Texas Instruments TMP401 and compatibles" | 857 | tristate "Texas Instruments TMP401 and compatibles" |
836 | depends on I2C && EXPERIMENTAL | 858 | depends on I2C && EXPERIMENTAL |
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 86920fb34118..2138ceb1a713 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile | |||
@@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o | |||
41 | obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o | 41 | obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o |
42 | obj-$(CONFIG_SENSORS_DME1737) += dme1737.o | 42 | obj-$(CONFIG_SENSORS_DME1737) += dme1737.o |
43 | obj-$(CONFIG_SENSORS_DS1621) += ds1621.o | 43 | obj-$(CONFIG_SENSORS_DS1621) += ds1621.o |
44 | obj-$(CONFIG_SENSORS_EMC1403) += emc1403.o | ||
44 | obj-$(CONFIG_SENSORS_F71805F) += f71805f.o | 45 | obj-$(CONFIG_SENSORS_F71805F) += f71805f.o |
45 | obj-$(CONFIG_SENSORS_F71882FG) += f71882fg.o | 46 | obj-$(CONFIG_SENSORS_F71882FG) += f71882fg.o |
46 | obj-$(CONFIG_SENSORS_F75375S) += f75375s.o | 47 | obj-$(CONFIG_SENSORS_F75375S) += f75375s.o |
@@ -90,6 +91,7 @@ obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o | |||
90 | obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o | 91 | obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o |
91 | obj-$(CONFIG_SENSORS_AMC6821) += amc6821.o | 92 | obj-$(CONFIG_SENSORS_AMC6821) += amc6821.o |
92 | obj-$(CONFIG_SENSORS_THMC50) += thmc50.o | 93 | obj-$(CONFIG_SENSORS_THMC50) += thmc50.o |
94 | obj-$(CONFIG_SENSORS_TMP102) += tmp102.o | ||
93 | obj-$(CONFIG_SENSORS_TMP401) += tmp401.o | 95 | obj-$(CONFIG_SENSORS_TMP401) += tmp401.o |
94 | obj-$(CONFIG_SENSORS_TMP421) += tmp421.o | 96 | obj-$(CONFIG_SENSORS_TMP421) += tmp421.o |
95 | obj-$(CONFIG_SENSORS_VIA_CPUTEMP)+= via-cputemp.o | 97 | obj-$(CONFIG_SENSORS_VIA_CPUTEMP)+= via-cputemp.o |
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c index 1644b92e7cc4..15c1a9616af3 100644 --- a/drivers/hwmon/adm1031.c +++ b/drivers/hwmon/adm1031.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #define ADM1031_REG_FAN_DIV(nr) (0x20 + (nr)) | 36 | #define ADM1031_REG_FAN_DIV(nr) (0x20 + (nr)) |
37 | #define ADM1031_REG_PWM (0x22) | 37 | #define ADM1031_REG_PWM (0x22) |
38 | #define ADM1031_REG_FAN_MIN(nr) (0x10 + (nr)) | 38 | #define ADM1031_REG_FAN_MIN(nr) (0x10 + (nr)) |
39 | #define ADM1031_REG_FAN_FILTER (0x23) | ||
39 | 40 | ||
40 | #define ADM1031_REG_TEMP_OFFSET(nr) (0x0d + (nr)) | 41 | #define ADM1031_REG_TEMP_OFFSET(nr) (0x0d + (nr)) |
41 | #define ADM1031_REG_TEMP_MAX(nr) (0x14 + 4 * (nr)) | 42 | #define ADM1031_REG_TEMP_MAX(nr) (0x14 + 4 * (nr)) |
@@ -61,6 +62,9 @@ | |||
61 | #define ADM1031_CONF2_TACH2_ENABLE 0x08 | 62 | #define ADM1031_CONF2_TACH2_ENABLE 0x08 |
62 | #define ADM1031_CONF2_TEMP_ENABLE(chan) (0x10 << (chan)) | 63 | #define ADM1031_CONF2_TEMP_ENABLE(chan) (0x10 << (chan)) |
63 | 64 | ||
65 | #define ADM1031_UPDATE_RATE_MASK 0x1c | ||
66 | #define ADM1031_UPDATE_RATE_SHIFT 2 | ||
67 | |||
64 | /* Addresses to scan */ | 68 | /* Addresses to scan */ |
65 | static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; | 69 | static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; |
66 | 70 | ||
@@ -75,6 +79,7 @@ struct adm1031_data { | |||
75 | int chip_type; | 79 | int chip_type; |
76 | char valid; /* !=0 if following fields are valid */ | 80 | char valid; /* !=0 if following fields are valid */ |
77 | unsigned long last_updated; /* In jiffies */ | 81 | unsigned long last_updated; /* In jiffies */ |
82 | unsigned int update_rate; /* In milliseconds */ | ||
78 | /* The chan_select_table contains the possible configurations for | 83 | /* The chan_select_table contains the possible configurations for |
79 | * auto fan control. | 84 | * auto fan control. |
80 | */ | 85 | */ |
@@ -738,6 +743,57 @@ static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 12); | |||
738 | static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13); | 743 | static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13); |
739 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14); | 744 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14); |
740 | 745 | ||
746 | /* Update Rate */ | ||
747 | static const unsigned int update_rates[] = { | ||
748 | 16000, 8000, 4000, 2000, 1000, 500, 250, 125, | ||
749 | }; | ||
750 | |||
751 | static ssize_t show_update_rate(struct device *dev, | ||
752 | struct device_attribute *attr, char *buf) | ||
753 | { | ||
754 | struct i2c_client *client = to_i2c_client(dev); | ||
755 | struct adm1031_data *data = i2c_get_clientdata(client); | ||
756 | |||
757 | return sprintf(buf, "%u\n", data->update_rate); | ||
758 | } | ||
759 | |||
760 | static ssize_t set_update_rate(struct device *dev, | ||
761 | struct device_attribute *attr, | ||
762 | const char *buf, size_t count) | ||
763 | { | ||
764 | struct i2c_client *client = to_i2c_client(dev); | ||
765 | struct adm1031_data *data = i2c_get_clientdata(client); | ||
766 | unsigned long val; | ||
767 | int i, err; | ||
768 | u8 reg; | ||
769 | |||
770 | err = strict_strtoul(buf, 10, &val); | ||
771 | if (err) | ||
772 | return err; | ||
773 | |||
774 | /* find the nearest update rate from the table */ | ||
775 | for (i = 0; i < ARRAY_SIZE(update_rates) - 1; i++) { | ||
776 | if (val >= update_rates[i]) | ||
777 | break; | ||
778 | } | ||
779 | /* if not found, we point to the last entry (lowest update rate) */ | ||
780 | |||
781 | /* set the new update rate while preserving other settings */ | ||
782 | reg = adm1031_read_value(client, ADM1031_REG_FAN_FILTER); | ||
783 | reg &= ~ADM1031_UPDATE_RATE_MASK; | ||
784 | reg |= i << ADM1031_UPDATE_RATE_SHIFT; | ||
785 | adm1031_write_value(client, ADM1031_REG_FAN_FILTER, reg); | ||
786 | |||
787 | mutex_lock(&data->update_lock); | ||
788 | data->update_rate = update_rates[i]; | ||
789 | mutex_unlock(&data->update_lock); | ||
790 | |||
791 | return count; | ||
792 | } | ||
793 | |||
794 | static DEVICE_ATTR(update_rate, S_IRUGO | S_IWUSR, show_update_rate, | ||
795 | set_update_rate); | ||
796 | |||
741 | static struct attribute *adm1031_attributes[] = { | 797 | static struct attribute *adm1031_attributes[] = { |
742 | &sensor_dev_attr_fan1_input.dev_attr.attr, | 798 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
743 | &sensor_dev_attr_fan1_div.dev_attr.attr, | 799 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
@@ -774,6 +830,7 @@ static struct attribute *adm1031_attributes[] = { | |||
774 | 830 | ||
775 | &sensor_dev_attr_auto_fan1_min_pwm.dev_attr.attr, | 831 | &sensor_dev_attr_auto_fan1_min_pwm.dev_attr.attr, |
776 | 832 | ||
833 | &dev_attr_update_rate.attr, | ||
777 | &dev_attr_alarms.attr, | 834 | &dev_attr_alarms.attr, |
778 | 835 | ||
779 | NULL | 836 | NULL |
@@ -900,6 +957,7 @@ static void adm1031_init_client(struct i2c_client *client) | |||
900 | { | 957 | { |
901 | unsigned int read_val; | 958 | unsigned int read_val; |
902 | unsigned int mask; | 959 | unsigned int mask; |
960 | int i; | ||
903 | struct adm1031_data *data = i2c_get_clientdata(client); | 961 | struct adm1031_data *data = i2c_get_clientdata(client); |
904 | 962 | ||
905 | mask = (ADM1031_CONF2_PWM1_ENABLE | ADM1031_CONF2_TACH1_ENABLE); | 963 | mask = (ADM1031_CONF2_PWM1_ENABLE | ADM1031_CONF2_TACH1_ENABLE); |
@@ -919,18 +977,24 @@ static void adm1031_init_client(struct i2c_client *client) | |||
919 | ADM1031_CONF1_MONITOR_ENABLE); | 977 | ADM1031_CONF1_MONITOR_ENABLE); |
920 | } | 978 | } |
921 | 979 | ||
980 | /* Read the chip's update rate */ | ||
981 | mask = ADM1031_UPDATE_RATE_MASK; | ||
982 | read_val = adm1031_read_value(client, ADM1031_REG_FAN_FILTER); | ||
983 | i = (read_val & mask) >> ADM1031_UPDATE_RATE_SHIFT; | ||
984 | data->update_rate = update_rates[i]; | ||
922 | } | 985 | } |
923 | 986 | ||
924 | static struct adm1031_data *adm1031_update_device(struct device *dev) | 987 | static struct adm1031_data *adm1031_update_device(struct device *dev) |
925 | { | 988 | { |
926 | struct i2c_client *client = to_i2c_client(dev); | 989 | struct i2c_client *client = to_i2c_client(dev); |
927 | struct adm1031_data *data = i2c_get_clientdata(client); | 990 | struct adm1031_data *data = i2c_get_clientdata(client); |
991 | unsigned long next_update; | ||
928 | int chan; | 992 | int chan; |
929 | 993 | ||
930 | mutex_lock(&data->update_lock); | 994 | mutex_lock(&data->update_lock); |
931 | 995 | ||
932 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | 996 | next_update = data->last_updated + msecs_to_jiffies(data->update_rate); |
933 | || !data->valid) { | 997 | if (time_after(jiffies, next_update) || !data->valid) { |
934 | 998 | ||
935 | dev_dbg(&client->dev, "Starting adm1031 update\n"); | 999 | dev_dbg(&client->dev, "Starting adm1031 update\n"); |
936 | for (chan = 0; | 1000 | for (chan = 0; |
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c index f085c18d2905..b6598aa557a0 100644 --- a/drivers/hwmon/applesmc.c +++ b/drivers/hwmon/applesmc.c | |||
@@ -148,6 +148,20 @@ static const char *temperature_sensors_sets[][41] = { | |||
148 | /* Set 18: MacBook Pro 2,2 */ | 148 | /* Set 18: MacBook Pro 2,2 */ |
149 | { "TB0T", "TC0D", "TC0P", "TG0H", "TG0P", "TG0T", "TM0P", "TTF0", | 149 | { "TB0T", "TC0D", "TC0P", "TG0H", "TG0P", "TG0T", "TM0P", "TTF0", |
150 | "Th0H", "Th1H", "Tm0P", "Ts0P", NULL }, | 150 | "Th0H", "Th1H", "Tm0P", "Ts0P", NULL }, |
151 | /* Set 19: Macbook Pro 5,3 */ | ||
152 | { "TB0T", "TB1T", "TB2T", "TB3T", "TC0D", "TC0F", "TC0P", "TG0D", | ||
153 | "TG0F", "TG0H", "TG0P", "TG0T", "TN0D", "TN0P", "TTF0", "Th2H", | ||
154 | "Tm0P", "Ts0P", "Ts0S", NULL }, | ||
155 | /* Set 20: MacBook Pro 5,4 */ | ||
156 | { "TB0T", "TB1T", "TB2T", "TB3T", "TC0D", "TC0F", "TC0P", "TN0D", | ||
157 | "TN0P", "TTF0", "Th2H", "Ts0P", "Ts0S", NULL }, | ||
158 | /* Set 21: MacBook Pro 6,2 */ | ||
159 | { "TB0T", "TB1T", "TB2T", "TC0C", "TC0D", "TC0P", "TC1C", "TG0D", | ||
160 | "TG0P", "TG0T", "TMCD", "TP0P", "TPCD", "Th1H", "Th2H", "Tm0P", | ||
161 | "Ts0P", "Ts0S", NULL }, | ||
162 | /* Set 22: MacBook Pro 7,1 */ | ||
163 | { "TB0T", "TB1T", "TB2T", "TC0D", "TC0P", "TN0D", "TN0P", "TN0S", | ||
164 | "TN1D", "TN1F", "TN1G", "TN1S", "Th1H", "Ts0P", "Ts0S", NULL }, | ||
151 | }; | 165 | }; |
152 | 166 | ||
153 | /* List of keys used to read/write fan speeds */ | 167 | /* List of keys used to read/write fan speeds */ |
@@ -646,6 +660,17 @@ out: | |||
646 | return snprintf(sysfsbuf, PAGE_SIZE, "(%d,%d)\n", left, right); | 660 | return snprintf(sysfsbuf, PAGE_SIZE, "(%d,%d)\n", left, right); |
647 | } | 661 | } |
648 | 662 | ||
663 | /* Displays sensor key as label */ | ||
664 | static ssize_t applesmc_show_sensor_label(struct device *dev, | ||
665 | struct device_attribute *devattr, char *sysfsbuf) | ||
666 | { | ||
667 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
668 | const char *key = | ||
669 | temperature_sensors_sets[applesmc_temperature_set][attr->index]; | ||
670 | |||
671 | return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", key); | ||
672 | } | ||
673 | |||
649 | /* Displays degree Celsius * 1000 */ | 674 | /* Displays degree Celsius * 1000 */ |
650 | static ssize_t applesmc_show_temperature(struct device *dev, | 675 | static ssize_t applesmc_show_temperature(struct device *dev, |
651 | struct device_attribute *devattr, char *sysfsbuf) | 676 | struct device_attribute *devattr, char *sysfsbuf) |
@@ -1113,6 +1138,86 @@ static const struct attribute_group fan_attribute_groups[] = { | |||
1113 | /* | 1138 | /* |
1114 | * Temperature sensors sysfs entries. | 1139 | * Temperature sensors sysfs entries. |
1115 | */ | 1140 | */ |
1141 | static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, | ||
1142 | applesmc_show_sensor_label, NULL, 0); | ||
1143 | static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, | ||
1144 | applesmc_show_sensor_label, NULL, 1); | ||
1145 | static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, | ||
1146 | applesmc_show_sensor_label, NULL, 2); | ||
1147 | static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, | ||
1148 | applesmc_show_sensor_label, NULL, 3); | ||
1149 | static SENSOR_DEVICE_ATTR(temp5_label, S_IRUGO, | ||
1150 | applesmc_show_sensor_label, NULL, 4); | ||
1151 | static SENSOR_DEVICE_ATTR(temp6_label, S_IRUGO, | ||
1152 | applesmc_show_sensor_label, NULL, 5); | ||
1153 | static SENSOR_DEVICE_ATTR(temp7_label, S_IRUGO, | ||
1154 | applesmc_show_sensor_label, NULL, 6); | ||
1155 | static SENSOR_DEVICE_ATTR(temp8_label, S_IRUGO, | ||
1156 | applesmc_show_sensor_label, NULL, 7); | ||
1157 | static SENSOR_DEVICE_ATTR(temp9_label, S_IRUGO, | ||
1158 | applesmc_show_sensor_label, NULL, 8); | ||
1159 | static SENSOR_DEVICE_ATTR(temp10_label, S_IRUGO, | ||
1160 | applesmc_show_sensor_label, NULL, 9); | ||
1161 | static SENSOR_DEVICE_ATTR(temp11_label, S_IRUGO, | ||
1162 | applesmc_show_sensor_label, NULL, 10); | ||
1163 | static SENSOR_DEVICE_ATTR(temp12_label, S_IRUGO, | ||
1164 | applesmc_show_sensor_label, NULL, 11); | ||
1165 | static SENSOR_DEVICE_ATTR(temp13_label, S_IRUGO, | ||
1166 | applesmc_show_sensor_label, NULL, 12); | ||
1167 | static SENSOR_DEVICE_ATTR(temp14_label, S_IRUGO, | ||
1168 | applesmc_show_sensor_label, NULL, 13); | ||
1169 | static SENSOR_DEVICE_ATTR(temp15_label, S_IRUGO, | ||
1170 | applesmc_show_sensor_label, NULL, 14); | ||
1171 | static SENSOR_DEVICE_ATTR(temp16_label, S_IRUGO, | ||
1172 | applesmc_show_sensor_label, NULL, 15); | ||
1173 | static SENSOR_DEVICE_ATTR(temp17_label, S_IRUGO, | ||
1174 | applesmc_show_sensor_label, NULL, 16); | ||
1175 | static SENSOR_DEVICE_ATTR(temp18_label, S_IRUGO, | ||
1176 | applesmc_show_sensor_label, NULL, 17); | ||
1177 | static SENSOR_DEVICE_ATTR(temp19_label, S_IRUGO, | ||
1178 | applesmc_show_sensor_label, NULL, 18); | ||
1179 | static SENSOR_DEVICE_ATTR(temp20_label, S_IRUGO, | ||
1180 | applesmc_show_sensor_label, NULL, 19); | ||
1181 | static SENSOR_DEVICE_ATTR(temp21_label, S_IRUGO, | ||
1182 | applesmc_show_sensor_label, NULL, 20); | ||
1183 | static SENSOR_DEVICE_ATTR(temp22_label, S_IRUGO, | ||
1184 | applesmc_show_sensor_label, NULL, 21); | ||
1185 | static SENSOR_DEVICE_ATTR(temp23_label, S_IRUGO, | ||
1186 | applesmc_show_sensor_label, NULL, 22); | ||
1187 | static SENSOR_DEVICE_ATTR(temp24_label, S_IRUGO, | ||
1188 | applesmc_show_sensor_label, NULL, 23); | ||
1189 | static SENSOR_DEVICE_ATTR(temp25_label, S_IRUGO, | ||
1190 | applesmc_show_sensor_label, NULL, 24); | ||
1191 | static SENSOR_DEVICE_ATTR(temp26_label, S_IRUGO, | ||
1192 | applesmc_show_sensor_label, NULL, 25); | ||
1193 | static SENSOR_DEVICE_ATTR(temp27_label, S_IRUGO, | ||
1194 | applesmc_show_sensor_label, NULL, 26); | ||
1195 | static SENSOR_DEVICE_ATTR(temp28_label, S_IRUGO, | ||
1196 | applesmc_show_sensor_label, NULL, 27); | ||
1197 | static SENSOR_DEVICE_ATTR(temp29_label, S_IRUGO, | ||
1198 | applesmc_show_sensor_label, NULL, 28); | ||
1199 | static SENSOR_DEVICE_ATTR(temp30_label, S_IRUGO, | ||
1200 | applesmc_show_sensor_label, NULL, 29); | ||
1201 | static SENSOR_DEVICE_ATTR(temp31_label, S_IRUGO, | ||
1202 | applesmc_show_sensor_label, NULL, 30); | ||
1203 | static SENSOR_DEVICE_ATTR(temp32_label, S_IRUGO, | ||
1204 | applesmc_show_sensor_label, NULL, 31); | ||
1205 | static SENSOR_DEVICE_ATTR(temp33_label, S_IRUGO, | ||
1206 | applesmc_show_sensor_label, NULL, 32); | ||
1207 | static SENSOR_DEVICE_ATTR(temp34_label, S_IRUGO, | ||
1208 | applesmc_show_sensor_label, NULL, 33); | ||
1209 | static SENSOR_DEVICE_ATTR(temp35_label, S_IRUGO, | ||
1210 | applesmc_show_sensor_label, NULL, 34); | ||
1211 | static SENSOR_DEVICE_ATTR(temp36_label, S_IRUGO, | ||
1212 | applesmc_show_sensor_label, NULL, 35); | ||
1213 | static SENSOR_DEVICE_ATTR(temp37_label, S_IRUGO, | ||
1214 | applesmc_show_sensor_label, NULL, 36); | ||
1215 | static SENSOR_DEVICE_ATTR(temp38_label, S_IRUGO, | ||
1216 | applesmc_show_sensor_label, NULL, 37); | ||
1217 | static SENSOR_DEVICE_ATTR(temp39_label, S_IRUGO, | ||
1218 | applesmc_show_sensor_label, NULL, 38); | ||
1219 | static SENSOR_DEVICE_ATTR(temp40_label, S_IRUGO, | ||
1220 | applesmc_show_sensor_label, NULL, 39); | ||
1116 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, | 1221 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, |
1117 | applesmc_show_temperature, NULL, 0); | 1222 | applesmc_show_temperature, NULL, 0); |
1118 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, | 1223 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, |
@@ -1194,6 +1299,50 @@ static SENSOR_DEVICE_ATTR(temp39_input, S_IRUGO, | |||
1194 | static SENSOR_DEVICE_ATTR(temp40_input, S_IRUGO, | 1299 | static SENSOR_DEVICE_ATTR(temp40_input, S_IRUGO, |
1195 | applesmc_show_temperature, NULL, 39); | 1300 | applesmc_show_temperature, NULL, 39); |
1196 | 1301 | ||
1302 | static struct attribute *label_attributes[] = { | ||
1303 | &sensor_dev_attr_temp1_label.dev_attr.attr, | ||
1304 | &sensor_dev_attr_temp2_label.dev_attr.attr, | ||
1305 | &sensor_dev_attr_temp3_label.dev_attr.attr, | ||
1306 | &sensor_dev_attr_temp4_label.dev_attr.attr, | ||
1307 | &sensor_dev_attr_temp5_label.dev_attr.attr, | ||
1308 | &sensor_dev_attr_temp6_label.dev_attr.attr, | ||
1309 | &sensor_dev_attr_temp7_label.dev_attr.attr, | ||
1310 | &sensor_dev_attr_temp8_label.dev_attr.attr, | ||
1311 | &sensor_dev_attr_temp9_label.dev_attr.attr, | ||
1312 | &sensor_dev_attr_temp10_label.dev_attr.attr, | ||
1313 | &sensor_dev_attr_temp11_label.dev_attr.attr, | ||
1314 | &sensor_dev_attr_temp12_label.dev_attr.attr, | ||
1315 | &sensor_dev_attr_temp13_label.dev_attr.attr, | ||
1316 | &sensor_dev_attr_temp14_label.dev_attr.attr, | ||
1317 | &sensor_dev_attr_temp15_label.dev_attr.attr, | ||
1318 | &sensor_dev_attr_temp16_label.dev_attr.attr, | ||
1319 | &sensor_dev_attr_temp17_label.dev_attr.attr, | ||
1320 | &sensor_dev_attr_temp18_label.dev_attr.attr, | ||
1321 | &sensor_dev_attr_temp19_label.dev_attr.attr, | ||
1322 | &sensor_dev_attr_temp20_label.dev_attr.attr, | ||
1323 | &sensor_dev_attr_temp21_label.dev_attr.attr, | ||
1324 | &sensor_dev_attr_temp22_label.dev_attr.attr, | ||
1325 | &sensor_dev_attr_temp23_label.dev_attr.attr, | ||
1326 | &sensor_dev_attr_temp24_label.dev_attr.attr, | ||
1327 | &sensor_dev_attr_temp25_label.dev_attr.attr, | ||
1328 | &sensor_dev_attr_temp26_label.dev_attr.attr, | ||
1329 | &sensor_dev_attr_temp27_label.dev_attr.attr, | ||
1330 | &sensor_dev_attr_temp28_label.dev_attr.attr, | ||
1331 | &sensor_dev_attr_temp29_label.dev_attr.attr, | ||
1332 | &sensor_dev_attr_temp30_label.dev_attr.attr, | ||
1333 | &sensor_dev_attr_temp31_label.dev_attr.attr, | ||
1334 | &sensor_dev_attr_temp32_label.dev_attr.attr, | ||
1335 | &sensor_dev_attr_temp33_label.dev_attr.attr, | ||
1336 | &sensor_dev_attr_temp34_label.dev_attr.attr, | ||
1337 | &sensor_dev_attr_temp35_label.dev_attr.attr, | ||
1338 | &sensor_dev_attr_temp36_label.dev_attr.attr, | ||
1339 | &sensor_dev_attr_temp37_label.dev_attr.attr, | ||
1340 | &sensor_dev_attr_temp38_label.dev_attr.attr, | ||
1341 | &sensor_dev_attr_temp39_label.dev_attr.attr, | ||
1342 | &sensor_dev_attr_temp40_label.dev_attr.attr, | ||
1343 | NULL | ||
1344 | }; | ||
1345 | |||
1197 | static struct attribute *temperature_attributes[] = { | 1346 | static struct attribute *temperature_attributes[] = { |
1198 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 1347 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
1199 | &sensor_dev_attr_temp2_input.dev_attr.attr, | 1348 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
@@ -1241,6 +1390,10 @@ static struct attribute *temperature_attributes[] = { | |||
1241 | static const struct attribute_group temperature_attributes_group = | 1390 | static const struct attribute_group temperature_attributes_group = |
1242 | { .attrs = temperature_attributes }; | 1391 | { .attrs = temperature_attributes }; |
1243 | 1392 | ||
1393 | static const struct attribute_group label_attributes_group = { | ||
1394 | .attrs = label_attributes | ||
1395 | }; | ||
1396 | |||
1244 | /* Module stuff */ | 1397 | /* Module stuff */ |
1245 | 1398 | ||
1246 | /* | 1399 | /* |
@@ -1363,6 +1516,14 @@ static __initdata struct dmi_match_data applesmc_dmi_data[] = { | |||
1363 | { .accelerometer = 0, .light = 0, .temperature_set = 17 }, | 1516 | { .accelerometer = 0, .light = 0, .temperature_set = 17 }, |
1364 | /* MacBook Pro 2,2: accelerometer, backlight and temperature set 18 */ | 1517 | /* MacBook Pro 2,2: accelerometer, backlight and temperature set 18 */ |
1365 | { .accelerometer = 1, .light = 1, .temperature_set = 18 }, | 1518 | { .accelerometer = 1, .light = 1, .temperature_set = 18 }, |
1519 | /* MacBook Pro 5,3: accelerometer, backlight and temperature set 19 */ | ||
1520 | { .accelerometer = 1, .light = 1, .temperature_set = 19 }, | ||
1521 | /* MacBook Pro 5,4: accelerometer, backlight and temperature set 20 */ | ||
1522 | { .accelerometer = 1, .light = 1, .temperature_set = 20 }, | ||
1523 | /* MacBook Pro 6,2: accelerometer, backlight and temperature set 21 */ | ||
1524 | { .accelerometer = 1, .light = 1, .temperature_set = 21 }, | ||
1525 | /* MacBook Pro 7,1: accelerometer, backlight and temperature set 22 */ | ||
1526 | { .accelerometer = 1, .light = 1, .temperature_set = 22 }, | ||
1366 | }; | 1527 | }; |
1367 | 1528 | ||
1368 | /* Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1". | 1529 | /* Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1". |
@@ -1376,6 +1537,22 @@ static __initdata struct dmi_system_id applesmc_whitelist[] = { | |||
1376 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | 1537 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), |
1377 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir") }, | 1538 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir") }, |
1378 | &applesmc_dmi_data[7]}, | 1539 | &applesmc_dmi_data[7]}, |
1540 | { applesmc_dmi_match, "Apple MacBook Pro 7", { | ||
1541 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1542 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro7") }, | ||
1543 | &applesmc_dmi_data[22]}, | ||
1544 | { applesmc_dmi_match, "Apple MacBook Pro 5,4", { | ||
1545 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1546 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,4") }, | ||
1547 | &applesmc_dmi_data[20]}, | ||
1548 | { applesmc_dmi_match, "Apple MacBook Pro 5,3", { | ||
1549 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1550 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,3") }, | ||
1551 | &applesmc_dmi_data[19]}, | ||
1552 | { applesmc_dmi_match, "Apple MacBook Pro 6", { | ||
1553 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1554 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro6") }, | ||
1555 | &applesmc_dmi_data[21]}, | ||
1379 | { applesmc_dmi_match, "Apple MacBook Pro 5", { | 1556 | { applesmc_dmi_match, "Apple MacBook Pro 5", { |
1380 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | 1557 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), |
1381 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5") }, | 1558 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5") }, |
@@ -1518,7 +1695,8 @@ static int __init applesmc_init(void) | |||
1518 | for (i = 0; | 1695 | for (i = 0; |
1519 | temperature_sensors_sets[applesmc_temperature_set][i] != NULL; | 1696 | temperature_sensors_sets[applesmc_temperature_set][i] != NULL; |
1520 | i++) { | 1697 | i++) { |
1521 | if (temperature_attributes[i] == NULL) { | 1698 | if (temperature_attributes[i] == NULL || |
1699 | label_attributes[i] == NULL) { | ||
1522 | printk(KERN_ERR "applesmc: More temperature sensors " | 1700 | printk(KERN_ERR "applesmc: More temperature sensors " |
1523 | "in temperature_sensors_sets (at least %i)" | 1701 | "in temperature_sensors_sets (at least %i)" |
1524 | "than available sysfs files in " | 1702 | "than available sysfs files in " |
@@ -1530,6 +1708,10 @@ static int __init applesmc_init(void) | |||
1530 | temperature_attributes[i]); | 1708 | temperature_attributes[i]); |
1531 | if (ret) | 1709 | if (ret) |
1532 | goto out_temperature; | 1710 | goto out_temperature; |
1711 | ret = sysfs_create_file(&pdev->dev.kobj, | ||
1712 | label_attributes[i]); | ||
1713 | if (ret) | ||
1714 | goto out_temperature; | ||
1533 | } | 1715 | } |
1534 | 1716 | ||
1535 | if (applesmc_accelerometer) { | 1717 | if (applesmc_accelerometer) { |
@@ -1580,6 +1762,7 @@ out_accelerometer: | |||
1580 | if (applesmc_accelerometer) | 1762 | if (applesmc_accelerometer) |
1581 | applesmc_release_accelerometer(); | 1763 | applesmc_release_accelerometer(); |
1582 | out_temperature: | 1764 | out_temperature: |
1765 | sysfs_remove_group(&pdev->dev.kobj, &label_attributes_group); | ||
1583 | sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group); | 1766 | sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group); |
1584 | out_fans: | 1767 | out_fans: |
1585 | while (fans_handled) | 1768 | while (fans_handled) |
@@ -1609,6 +1792,7 @@ static void __exit applesmc_exit(void) | |||
1609 | } | 1792 | } |
1610 | if (applesmc_accelerometer) | 1793 | if (applesmc_accelerometer) |
1611 | applesmc_release_accelerometer(); | 1794 | applesmc_release_accelerometer(); |
1795 | sysfs_remove_group(&pdev->dev.kobj, &label_attributes_group); | ||
1612 | sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group); | 1796 | sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group); |
1613 | while (fans_handled) | 1797 | while (fans_handled) |
1614 | sysfs_remove_group(&pdev->dev.kobj, | 1798 | sysfs_remove_group(&pdev->dev.kobj, |
diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c index 16c420240724..653db1bda934 100644 --- a/drivers/hwmon/asus_atk0110.c +++ b/drivers/hwmon/asus_atk0110.c | |||
@@ -1411,6 +1411,13 @@ static int __init atk0110_init(void) | |||
1411 | { | 1411 | { |
1412 | int ret; | 1412 | int ret; |
1413 | 1413 | ||
1414 | /* Make sure it's safe to access the device through ACPI */ | ||
1415 | if (!acpi_resources_are_enforced()) { | ||
1416 | pr_err("atk: Resources not safely usable due to " | ||
1417 | "acpi_enforce_resources kernel parameter\n"); | ||
1418 | return -EBUSY; | ||
1419 | } | ||
1420 | |||
1414 | ret = acpi_bus_register_driver(&atk_driver); | 1421 | ret = acpi_bus_register_driver(&atk_driver); |
1415 | if (ret) | 1422 | if (ret) |
1416 | pr_info("atk: acpi_bus_register_driver failed: %d\n", ret); | 1423 | pr_info("atk: acpi_bus_register_driver failed: %d\n", ret); |
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c index 823dd28a902c..980c17d5eeae 100644 --- a/drivers/hwmon/dme1737.c +++ b/drivers/hwmon/dme1737.c | |||
@@ -1,12 +1,14 @@ | |||
1 | /* | 1 | /* |
2 | * dme1737.c - Driver for the SMSC DME1737, Asus A8000, SMSC SCH311x and | 2 | * dme1737.c - Driver for the SMSC DME1737, Asus A8000, SMSC SCH311x, SCH5027, |
3 | * SCH5027 Super-I/O chips integrated hardware monitoring features. | 3 | * and SCH5127 Super-I/O chips integrated hardware monitoring |
4 | * Copyright (c) 2007, 2008 Juerg Haefliger <juergh@gmail.com> | 4 | * features. |
5 | * Copyright (c) 2007, 2008, 2009, 2010 Juerg Haefliger <juergh@gmail.com> | ||
5 | * | 6 | * |
6 | * This driver is an I2C/ISA hybrid, meaning that it uses the I2C bus to access | 7 | * This driver is an I2C/ISA hybrid, meaning that it uses the I2C bus to access |
7 | * the chip registers if a DME1737, A8000, or SCH5027 is found and the ISA bus | 8 | * the chip registers if a DME1737, A8000, or SCH5027 is found and the ISA bus |
8 | * if a SCH311x chip is found. Both types of chips have very similar hardware | 9 | * if a SCH311x or SCH5127 chip is found. Both types of chips have very |
9 | * monitoring capabilities but differ in the way they can be accessed. | 10 | * similar hardware monitoring capabilities but differ in the way they can be |
11 | * accessed. | ||
10 | * | 12 | * |
11 | * This program is free software; you can redistribute it and/or modify | 13 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License as published by | 14 | * it under the terms of the GNU General Public License as published by |
@@ -57,7 +59,7 @@ MODULE_PARM_DESC(probe_all_addr, "Include probing of non-standard LPC " | |||
57 | /* Addresses to scan */ | 59 | /* Addresses to scan */ |
58 | static const unsigned short normal_i2c[] = {0x2c, 0x2d, 0x2e, I2C_CLIENT_END}; | 60 | static const unsigned short normal_i2c[] = {0x2c, 0x2d, 0x2e, I2C_CLIENT_END}; |
59 | 61 | ||
60 | enum chips { dme1737, sch5027, sch311x }; | 62 | enum chips { dme1737, sch5027, sch311x, sch5127 }; |
61 | 63 | ||
62 | /* --------------------------------------------------------------------- | 64 | /* --------------------------------------------------------------------- |
63 | * Registers | 65 | * Registers |
@@ -164,10 +166,29 @@ static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23}; | |||
164 | #define DME1737_VERSTEP_MASK 0xf8 | 166 | #define DME1737_VERSTEP_MASK 0xf8 |
165 | #define SCH311X_DEVICE 0x8c | 167 | #define SCH311X_DEVICE 0x8c |
166 | #define SCH5027_VERSTEP 0x69 | 168 | #define SCH5027_VERSTEP 0x69 |
169 | #define SCH5127_DEVICE 0x8e | ||
170 | |||
171 | /* Device ID values (global configuration register index 0x20) */ | ||
172 | #define DME1737_ID_1 0x77 | ||
173 | #define DME1737_ID_2 0x78 | ||
174 | #define SCH3112_ID 0x7c | ||
175 | #define SCH3114_ID 0x7d | ||
176 | #define SCH3116_ID 0x7f | ||
177 | #define SCH5027_ID 0x89 | ||
178 | #define SCH5127_ID 0x86 | ||
167 | 179 | ||
168 | /* Length of ISA address segment */ | 180 | /* Length of ISA address segment */ |
169 | #define DME1737_EXTENT 2 | 181 | #define DME1737_EXTENT 2 |
170 | 182 | ||
183 | /* chip-dependent features */ | ||
184 | #define HAS_TEMP_OFFSET (1 << 0) /* bit 0 */ | ||
185 | #define HAS_VID (1 << 1) /* bit 1 */ | ||
186 | #define HAS_ZONE3 (1 << 2) /* bit 2 */ | ||
187 | #define HAS_ZONE_HYST (1 << 3) /* bit 3 */ | ||
188 | #define HAS_PWM_MIN (1 << 4) /* bit 4 */ | ||
189 | #define HAS_FAN(ix) (1 << ((ix) + 5)) /* bits 5-10 */ | ||
190 | #define HAS_PWM(ix) (1 << ((ix) + 11)) /* bits 11-16 */ | ||
191 | |||
171 | /* --------------------------------------------------------------------- | 192 | /* --------------------------------------------------------------------- |
172 | * Data structures and manipulation thereof | 193 | * Data structures and manipulation thereof |
173 | * --------------------------------------------------------------------- */ | 194 | * --------------------------------------------------------------------- */ |
@@ -187,8 +208,7 @@ struct dme1737_data { | |||
187 | 208 | ||
188 | u8 vid; | 209 | u8 vid; |
189 | u8 pwm_rr_en; | 210 | u8 pwm_rr_en; |
190 | u8 has_pwm; | 211 | u32 has_features; |
191 | u8 has_fan; | ||
192 | 212 | ||
193 | /* Register values */ | 213 | /* Register values */ |
194 | u16 in[7]; | 214 | u16 in[7]; |
@@ -224,8 +244,11 @@ static const int IN_NOMINAL_SCH311x[] = {2500, 1500, 3300, 5000, 12000, 3300, | |||
224 | 3300}; | 244 | 3300}; |
225 | static const int IN_NOMINAL_SCH5027[] = {5000, 2250, 3300, 1125, 1125, 3300, | 245 | static const int IN_NOMINAL_SCH5027[] = {5000, 2250, 3300, 1125, 1125, 3300, |
226 | 3300}; | 246 | 3300}; |
247 | static const int IN_NOMINAL_SCH5127[] = {2500, 2250, 3300, 1125, 1125, 3300, | ||
248 | 3300}; | ||
227 | #define IN_NOMINAL(type) ((type) == sch311x ? IN_NOMINAL_SCH311x : \ | 249 | #define IN_NOMINAL(type) ((type) == sch311x ? IN_NOMINAL_SCH311x : \ |
228 | (type) == sch5027 ? IN_NOMINAL_SCH5027 : \ | 250 | (type) == sch5027 ? IN_NOMINAL_SCH5027 : \ |
251 | (type) == sch5127 ? IN_NOMINAL_SCH5127 : \ | ||
229 | IN_NOMINAL_DME1737) | 252 | IN_NOMINAL_DME1737) |
230 | 253 | ||
231 | /* Voltage input | 254 | /* Voltage input |
@@ -568,7 +591,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev) | |||
568 | 591 | ||
569 | /* Sample register contents every 1 sec */ | 592 | /* Sample register contents every 1 sec */ |
570 | if (time_after(jiffies, data->last_update + HZ) || !data->valid) { | 593 | if (time_after(jiffies, data->last_update + HZ) || !data->valid) { |
571 | if (data->type == dme1737) { | 594 | if (data->has_features & HAS_VID) { |
572 | data->vid = dme1737_read(data, DME1737_REG_VID) & | 595 | data->vid = dme1737_read(data, DME1737_REG_VID) & |
573 | 0x3f; | 596 | 0x3f; |
574 | } | 597 | } |
@@ -599,7 +622,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev) | |||
599 | DME1737_REG_TEMP_MIN(ix)); | 622 | DME1737_REG_TEMP_MIN(ix)); |
600 | data->temp_max[ix] = dme1737_read(data, | 623 | data->temp_max[ix] = dme1737_read(data, |
601 | DME1737_REG_TEMP_MAX(ix)); | 624 | DME1737_REG_TEMP_MAX(ix)); |
602 | if (data->type != sch5027) { | 625 | if (data->has_features & HAS_TEMP_OFFSET) { |
603 | data->temp_offset[ix] = dme1737_read(data, | 626 | data->temp_offset[ix] = dme1737_read(data, |
604 | DME1737_REG_TEMP_OFFSET(ix)); | 627 | DME1737_REG_TEMP_OFFSET(ix)); |
605 | } | 628 | } |
@@ -626,7 +649,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev) | |||
626 | for (ix = 0; ix < ARRAY_SIZE(data->fan); ix++) { | 649 | for (ix = 0; ix < ARRAY_SIZE(data->fan); ix++) { |
627 | /* Skip reading registers if optional fans are not | 650 | /* Skip reading registers if optional fans are not |
628 | * present */ | 651 | * present */ |
629 | if (!(data->has_fan & (1 << ix))) { | 652 | if (!(data->has_features & HAS_FAN(ix))) { |
630 | continue; | 653 | continue; |
631 | } | 654 | } |
632 | data->fan[ix] = dme1737_read(data, | 655 | data->fan[ix] = dme1737_read(data, |
@@ -650,7 +673,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev) | |||
650 | for (ix = 0; ix < ARRAY_SIZE(data->pwm); ix++) { | 673 | for (ix = 0; ix < ARRAY_SIZE(data->pwm); ix++) { |
651 | /* Skip reading registers if optional PWMs are not | 674 | /* Skip reading registers if optional PWMs are not |
652 | * present */ | 675 | * present */ |
653 | if (!(data->has_pwm & (1 << ix))) { | 676 | if (!(data->has_features & HAS_PWM(ix))) { |
654 | continue; | 677 | continue; |
655 | } | 678 | } |
656 | data->pwm[ix] = dme1737_read(data, | 679 | data->pwm[ix] = dme1737_read(data, |
@@ -672,12 +695,24 @@ static struct dme1737_data *dme1737_update_device(struct device *dev) | |||
672 | 695 | ||
673 | /* Thermal zone registers */ | 696 | /* Thermal zone registers */ |
674 | for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) { | 697 | for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) { |
675 | data->zone_low[ix] = dme1737_read(data, | 698 | /* Skip reading registers if zone3 is not present */ |
676 | DME1737_REG_ZONE_LOW(ix)); | 699 | if ((ix == 2) && !(data->has_features & HAS_ZONE3)) { |
677 | data->zone_abs[ix] = dme1737_read(data, | 700 | continue; |
678 | DME1737_REG_ZONE_ABS(ix)); | 701 | } |
702 | /* sch5127 zone2 registers are special */ | ||
703 | if ((ix == 1) && (data->type == sch5127)) { | ||
704 | data->zone_low[1] = dme1737_read(data, | ||
705 | DME1737_REG_ZONE_LOW(2)); | ||
706 | data->zone_abs[1] = dme1737_read(data, | ||
707 | DME1737_REG_ZONE_ABS(2)); | ||
708 | } else { | ||
709 | data->zone_low[ix] = dme1737_read(data, | ||
710 | DME1737_REG_ZONE_LOW(ix)); | ||
711 | data->zone_abs[ix] = dme1737_read(data, | ||
712 | DME1737_REG_ZONE_ABS(ix)); | ||
713 | } | ||
679 | } | 714 | } |
680 | if (data->type != sch5027) { | 715 | if (data->has_features & HAS_ZONE_HYST) { |
681 | for (ix = 0; ix < ARRAY_SIZE(data->zone_hyst); ix++) { | 716 | for (ix = 0; ix < ARRAY_SIZE(data->zone_hyst); ix++) { |
682 | data->zone_hyst[ix] = dme1737_read(data, | 717 | data->zone_hyst[ix] = dme1737_read(data, |
683 | DME1737_REG_ZONE_HYST(ix)); | 718 | DME1737_REG_ZONE_HYST(ix)); |
@@ -1594,10 +1629,6 @@ static struct attribute *dme1737_attr[] ={ | |||
1594 | &sensor_dev_attr_zone2_auto_point2_temp.dev_attr.attr, | 1629 | &sensor_dev_attr_zone2_auto_point2_temp.dev_attr.attr, |
1595 | &sensor_dev_attr_zone2_auto_point3_temp.dev_attr.attr, | 1630 | &sensor_dev_attr_zone2_auto_point3_temp.dev_attr.attr, |
1596 | &sensor_dev_attr_zone2_auto_channels_temp.dev_attr.attr, | 1631 | &sensor_dev_attr_zone2_auto_channels_temp.dev_attr.attr, |
1597 | &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr, | ||
1598 | &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr, | ||
1599 | &sensor_dev_attr_zone3_auto_point3_temp.dev_attr.attr, | ||
1600 | &sensor_dev_attr_zone3_auto_channels_temp.dev_attr.attr, | ||
1601 | NULL | 1632 | NULL |
1602 | }; | 1633 | }; |
1603 | 1634 | ||
@@ -1605,27 +1636,23 @@ static const struct attribute_group dme1737_group = { | |||
1605 | .attrs = dme1737_attr, | 1636 | .attrs = dme1737_attr, |
1606 | }; | 1637 | }; |
1607 | 1638 | ||
1608 | /* The following struct holds misc attributes, which are not available in all | 1639 | /* The following struct holds temp offset attributes, which are not available |
1609 | * chips. Their creation depends on the chip type which is determined during | 1640 | * in all chips. The following chips support them: |
1610 | * module load. */ | 1641 | * DME1737, SCH311x */ |
1611 | static struct attribute *dme1737_misc_attr[] = { | 1642 | static struct attribute *dme1737_temp_offset_attr[] = { |
1612 | /* Temperatures */ | ||
1613 | &sensor_dev_attr_temp1_offset.dev_attr.attr, | 1643 | &sensor_dev_attr_temp1_offset.dev_attr.attr, |
1614 | &sensor_dev_attr_temp2_offset.dev_attr.attr, | 1644 | &sensor_dev_attr_temp2_offset.dev_attr.attr, |
1615 | &sensor_dev_attr_temp3_offset.dev_attr.attr, | 1645 | &sensor_dev_attr_temp3_offset.dev_attr.attr, |
1616 | /* Zones */ | ||
1617 | &sensor_dev_attr_zone1_auto_point1_temp_hyst.dev_attr.attr, | ||
1618 | &sensor_dev_attr_zone2_auto_point1_temp_hyst.dev_attr.attr, | ||
1619 | &sensor_dev_attr_zone3_auto_point1_temp_hyst.dev_attr.attr, | ||
1620 | NULL | 1646 | NULL |
1621 | }; | 1647 | }; |
1622 | 1648 | ||
1623 | static const struct attribute_group dme1737_misc_group = { | 1649 | static const struct attribute_group dme1737_temp_offset_group = { |
1624 | .attrs = dme1737_misc_attr, | 1650 | .attrs = dme1737_temp_offset_attr, |
1625 | }; | 1651 | }; |
1626 | 1652 | ||
1627 | /* The following struct holds VID-related attributes. Their creation | 1653 | /* The following struct holds VID related attributes, which are not available |
1628 | depends on the chip type which is determined during module load. */ | 1654 | * in all chips. The following chips support them: |
1655 | * DME1737 */ | ||
1629 | static struct attribute *dme1737_vid_attr[] = { | 1656 | static struct attribute *dme1737_vid_attr[] = { |
1630 | &dev_attr_vrm.attr, | 1657 | &dev_attr_vrm.attr, |
1631 | &dev_attr_cpu0_vid.attr, | 1658 | &dev_attr_cpu0_vid.attr, |
@@ -1636,6 +1663,36 @@ static const struct attribute_group dme1737_vid_group = { | |||
1636 | .attrs = dme1737_vid_attr, | 1663 | .attrs = dme1737_vid_attr, |
1637 | }; | 1664 | }; |
1638 | 1665 | ||
1666 | /* The following struct holds temp zone 3 related attributes, which are not | ||
1667 | * available in all chips. The following chips support them: | ||
1668 | * DME1737, SCH311x, SCH5027 */ | ||
1669 | static struct attribute *dme1737_zone3_attr[] = { | ||
1670 | &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr, | ||
1671 | &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr, | ||
1672 | &sensor_dev_attr_zone3_auto_point3_temp.dev_attr.attr, | ||
1673 | &sensor_dev_attr_zone3_auto_channels_temp.dev_attr.attr, | ||
1674 | NULL | ||
1675 | }; | ||
1676 | |||
1677 | static const struct attribute_group dme1737_zone3_group = { | ||
1678 | .attrs = dme1737_zone3_attr, | ||
1679 | }; | ||
1680 | |||
1681 | |||
1682 | /* The following struct holds temp zone hysteresis related attributes, which | ||
1683 | * are not available in all chips. The following chips support them: | ||
1684 | * DME1737, SCH311x */ | ||
1685 | static struct attribute *dme1737_zone_hyst_attr[] = { | ||
1686 | &sensor_dev_attr_zone1_auto_point1_temp_hyst.dev_attr.attr, | ||
1687 | &sensor_dev_attr_zone2_auto_point1_temp_hyst.dev_attr.attr, | ||
1688 | &sensor_dev_attr_zone3_auto_point1_temp_hyst.dev_attr.attr, | ||
1689 | NULL | ||
1690 | }; | ||
1691 | |||
1692 | static const struct attribute_group dme1737_zone_hyst_group = { | ||
1693 | .attrs = dme1737_zone_hyst_attr, | ||
1694 | }; | ||
1695 | |||
1639 | /* The following structs hold the PWM attributes, some of which are optional. | 1696 | /* The following structs hold the PWM attributes, some of which are optional. |
1640 | * Their creation depends on the chip configuration which is determined during | 1697 | * Their creation depends on the chip configuration which is determined during |
1641 | * module load. */ | 1698 | * module load. */ |
@@ -1691,10 +1748,10 @@ static const struct attribute_group dme1737_pwm_group[] = { | |||
1691 | { .attrs = dme1737_pwm6_attr }, | 1748 | { .attrs = dme1737_pwm6_attr }, |
1692 | }; | 1749 | }; |
1693 | 1750 | ||
1694 | /* The following struct holds misc PWM attributes, which are not available in | 1751 | /* The following struct holds auto PWM min attributes, which are not available |
1695 | * all chips. Their creation depends on the chip type which is determined | 1752 | * in all chips. Their creation depends on the chip type which is determined |
1696 | * during module load. */ | 1753 | * during module load. */ |
1697 | static struct attribute *dme1737_pwm_misc_attr[] = { | 1754 | static struct attribute *dme1737_auto_pwm_min_attr[] = { |
1698 | &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr, | 1755 | &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr, |
1699 | &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr, | 1756 | &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr, |
1700 | &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr, | 1757 | &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr, |
@@ -1764,14 +1821,25 @@ static struct attribute *dme1737_zone_chmod_attr[] = { | |||
1764 | &sensor_dev_attr_zone2_auto_point1_temp.dev_attr.attr, | 1821 | &sensor_dev_attr_zone2_auto_point1_temp.dev_attr.attr, |
1765 | &sensor_dev_attr_zone2_auto_point2_temp.dev_attr.attr, | 1822 | &sensor_dev_attr_zone2_auto_point2_temp.dev_attr.attr, |
1766 | &sensor_dev_attr_zone2_auto_point3_temp.dev_attr.attr, | 1823 | &sensor_dev_attr_zone2_auto_point3_temp.dev_attr.attr, |
1824 | NULL | ||
1825 | }; | ||
1826 | |||
1827 | static const struct attribute_group dme1737_zone_chmod_group = { | ||
1828 | .attrs = dme1737_zone_chmod_attr, | ||
1829 | }; | ||
1830 | |||
1831 | |||
1832 | /* The permissions of the following zone 3 attributes are changed to read- | ||
1833 | * writeable if the chip is *not* locked. Otherwise they stay read-only. */ | ||
1834 | static struct attribute *dme1737_zone3_chmod_attr[] = { | ||
1767 | &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr, | 1835 | &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr, |
1768 | &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr, | 1836 | &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr, |
1769 | &sensor_dev_attr_zone3_auto_point3_temp.dev_attr.attr, | 1837 | &sensor_dev_attr_zone3_auto_point3_temp.dev_attr.attr, |
1770 | NULL | 1838 | NULL |
1771 | }; | 1839 | }; |
1772 | 1840 | ||
1773 | static const struct attribute_group dme1737_zone_chmod_group = { | 1841 | static const struct attribute_group dme1737_zone3_chmod_group = { |
1774 | .attrs = dme1737_zone_chmod_attr, | 1842 | .attrs = dme1737_zone3_chmod_attr, |
1775 | }; | 1843 | }; |
1776 | 1844 | ||
1777 | /* The permissions of the following PWM attributes are changed to read- | 1845 | /* The permissions of the following PWM attributes are changed to read- |
@@ -1887,30 +1955,35 @@ static void dme1737_remove_files(struct device *dev) | |||
1887 | int ix; | 1955 | int ix; |
1888 | 1956 | ||
1889 | for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { | 1957 | for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { |
1890 | if (data->has_fan & (1 << ix)) { | 1958 | if (data->has_features & HAS_FAN(ix)) { |
1891 | sysfs_remove_group(&dev->kobj, | 1959 | sysfs_remove_group(&dev->kobj, |
1892 | &dme1737_fan_group[ix]); | 1960 | &dme1737_fan_group[ix]); |
1893 | } | 1961 | } |
1894 | } | 1962 | } |
1895 | 1963 | ||
1896 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { | 1964 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { |
1897 | if (data->has_pwm & (1 << ix)) { | 1965 | if (data->has_features & HAS_PWM(ix)) { |
1898 | sysfs_remove_group(&dev->kobj, | 1966 | sysfs_remove_group(&dev->kobj, |
1899 | &dme1737_pwm_group[ix]); | 1967 | &dme1737_pwm_group[ix]); |
1900 | if (data->type != sch5027 && ix < 3) { | 1968 | if ((data->has_features & HAS_PWM_MIN) && ix < 3) { |
1901 | sysfs_remove_file(&dev->kobj, | 1969 | sysfs_remove_file(&dev->kobj, |
1902 | dme1737_pwm_misc_attr[ix]); | 1970 | dme1737_auto_pwm_min_attr[ix]); |
1903 | } | 1971 | } |
1904 | } | 1972 | } |
1905 | } | 1973 | } |
1906 | 1974 | ||
1907 | if (data->type != sch5027) { | 1975 | if (data->has_features & HAS_TEMP_OFFSET) { |
1908 | sysfs_remove_group(&dev->kobj, &dme1737_misc_group); | 1976 | sysfs_remove_group(&dev->kobj, &dme1737_temp_offset_group); |
1909 | } | 1977 | } |
1910 | if (data->type == dme1737) { | 1978 | if (data->has_features & HAS_VID) { |
1911 | sysfs_remove_group(&dev->kobj, &dme1737_vid_group); | 1979 | sysfs_remove_group(&dev->kobj, &dme1737_vid_group); |
1912 | } | 1980 | } |
1913 | 1981 | if (data->has_features & HAS_ZONE3) { | |
1982 | sysfs_remove_group(&dev->kobj, &dme1737_zone3_group); | ||
1983 | } | ||
1984 | if (data->has_features & HAS_ZONE_HYST) { | ||
1985 | sysfs_remove_group(&dev->kobj, &dme1737_zone_hyst_group); | ||
1986 | } | ||
1914 | sysfs_remove_group(&dev->kobj, &dme1737_group); | 1987 | sysfs_remove_group(&dev->kobj, &dme1737_group); |
1915 | 1988 | ||
1916 | if (!data->client) { | 1989 | if (!data->client) { |
@@ -1934,23 +2007,31 @@ static int dme1737_create_files(struct device *dev) | |||
1934 | goto exit_remove; | 2007 | goto exit_remove; |
1935 | } | 2008 | } |
1936 | 2009 | ||
1937 | /* Create misc sysfs attributes */ | 2010 | /* Create chip-dependent sysfs attributes */ |
1938 | if ((data->type != sch5027) && | 2011 | if ((data->has_features & HAS_TEMP_OFFSET) && |
1939 | (err = sysfs_create_group(&dev->kobj, | 2012 | (err = sysfs_create_group(&dev->kobj, |
1940 | &dme1737_misc_group))) { | 2013 | &dme1737_temp_offset_group))) { |
1941 | goto exit_remove; | 2014 | goto exit_remove; |
1942 | } | 2015 | } |
1943 | 2016 | if ((data->has_features & HAS_VID) && | |
1944 | /* Create VID-related sysfs attributes */ | ||
1945 | if ((data->type == dme1737) && | ||
1946 | (err = sysfs_create_group(&dev->kobj, | 2017 | (err = sysfs_create_group(&dev->kobj, |
1947 | &dme1737_vid_group))) { | 2018 | &dme1737_vid_group))) { |
1948 | goto exit_remove; | 2019 | goto exit_remove; |
1949 | } | 2020 | } |
2021 | if ((data->has_features & HAS_ZONE3) && | ||
2022 | (err = sysfs_create_group(&dev->kobj, | ||
2023 | &dme1737_zone3_group))) { | ||
2024 | goto exit_remove; | ||
2025 | } | ||
2026 | if ((data->has_features & HAS_ZONE_HYST) && | ||
2027 | (err = sysfs_create_group(&dev->kobj, | ||
2028 | &dme1737_zone_hyst_group))) { | ||
2029 | goto exit_remove; | ||
2030 | } | ||
1950 | 2031 | ||
1951 | /* Create fan sysfs attributes */ | 2032 | /* Create fan sysfs attributes */ |
1952 | for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { | 2033 | for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { |
1953 | if (data->has_fan & (1 << ix)) { | 2034 | if (data->has_features & HAS_FAN(ix)) { |
1954 | if ((err = sysfs_create_group(&dev->kobj, | 2035 | if ((err = sysfs_create_group(&dev->kobj, |
1955 | &dme1737_fan_group[ix]))) { | 2036 | &dme1737_fan_group[ix]))) { |
1956 | goto exit_remove; | 2037 | goto exit_remove; |
@@ -1960,14 +2041,14 @@ static int dme1737_create_files(struct device *dev) | |||
1960 | 2041 | ||
1961 | /* Create PWM sysfs attributes */ | 2042 | /* Create PWM sysfs attributes */ |
1962 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { | 2043 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { |
1963 | if (data->has_pwm & (1 << ix)) { | 2044 | if (data->has_features & HAS_PWM(ix)) { |
1964 | if ((err = sysfs_create_group(&dev->kobj, | 2045 | if ((err = sysfs_create_group(&dev->kobj, |
1965 | &dme1737_pwm_group[ix]))) { | 2046 | &dme1737_pwm_group[ix]))) { |
1966 | goto exit_remove; | 2047 | goto exit_remove; |
1967 | } | 2048 | } |
1968 | if (data->type != sch5027 && ix < 3 && | 2049 | if ((data->has_features & HAS_PWM_MIN) && ix < 3 && |
1969 | (err = sysfs_create_file(&dev->kobj, | 2050 | (err = sysfs_create_file(&dev->kobj, |
1970 | dme1737_pwm_misc_attr[ix]))) { | 2051 | dme1737_auto_pwm_min_attr[ix]))) { |
1971 | goto exit_remove; | 2052 | goto exit_remove; |
1972 | } | 2053 | } |
1973 | } | 2054 | } |
@@ -1983,21 +2064,30 @@ static int dme1737_create_files(struct device *dev) | |||
1983 | dme1737_chmod_group(dev, &dme1737_zone_chmod_group, | 2064 | dme1737_chmod_group(dev, &dme1737_zone_chmod_group, |
1984 | S_IRUGO | S_IWUSR); | 2065 | S_IRUGO | S_IWUSR); |
1985 | 2066 | ||
1986 | /* Change permissions of misc sysfs attributes */ | 2067 | /* Change permissions of chip-dependent sysfs attributes */ |
1987 | if (data->type != sch5027) { | 2068 | if (data->has_features & HAS_TEMP_OFFSET) { |
1988 | dme1737_chmod_group(dev, &dme1737_misc_group, | 2069 | dme1737_chmod_group(dev, &dme1737_temp_offset_group, |
2070 | S_IRUGO | S_IWUSR); | ||
2071 | } | ||
2072 | if (data->has_features & HAS_ZONE3) { | ||
2073 | dme1737_chmod_group(dev, &dme1737_zone3_chmod_group, | ||
2074 | S_IRUGO | S_IWUSR); | ||
2075 | } | ||
2076 | if (data->has_features & HAS_ZONE_HYST) { | ||
2077 | dme1737_chmod_group(dev, &dme1737_zone_hyst_group, | ||
1989 | S_IRUGO | S_IWUSR); | 2078 | S_IRUGO | S_IWUSR); |
1990 | } | 2079 | } |
1991 | 2080 | ||
1992 | /* Change permissions of PWM sysfs attributes */ | 2081 | /* Change permissions of PWM sysfs attributes */ |
1993 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_chmod_group); ix++) { | 2082 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_chmod_group); ix++) { |
1994 | if (data->has_pwm & (1 << ix)) { | 2083 | if (data->has_features & HAS_PWM(ix)) { |
1995 | dme1737_chmod_group(dev, | 2084 | dme1737_chmod_group(dev, |
1996 | &dme1737_pwm_chmod_group[ix], | 2085 | &dme1737_pwm_chmod_group[ix], |
1997 | S_IRUGO | S_IWUSR); | 2086 | S_IRUGO | S_IWUSR); |
1998 | if (data->type != sch5027 && ix < 3) { | 2087 | if ((data->has_features & HAS_PWM_MIN) && |
2088 | ix < 3) { | ||
1999 | dme1737_chmod_file(dev, | 2089 | dme1737_chmod_file(dev, |
2000 | dme1737_pwm_misc_attr[ix], | 2090 | dme1737_auto_pwm_min_attr[ix], |
2001 | S_IRUGO | S_IWUSR); | 2091 | S_IRUGO | S_IWUSR); |
2002 | } | 2092 | } |
2003 | } | 2093 | } |
@@ -2005,7 +2095,7 @@ static int dme1737_create_files(struct device *dev) | |||
2005 | 2095 | ||
2006 | /* Change permissions of pwm[1-3] if in manual mode */ | 2096 | /* Change permissions of pwm[1-3] if in manual mode */ |
2007 | for (ix = 0; ix < 3; ix++) { | 2097 | for (ix = 0; ix < 3; ix++) { |
2008 | if ((data->has_pwm & (1 << ix)) && | 2098 | if ((data->has_features & HAS_PWM(ix)) && |
2009 | (PWM_EN_FROM_REG(data->pwm_config[ix]) == 1)) { | 2099 | (PWM_EN_FROM_REG(data->pwm_config[ix]) == 1)) { |
2010 | dme1737_chmod_file(dev, | 2100 | dme1737_chmod_file(dev, |
2011 | dme1737_pwm_chmod_attr[ix], | 2101 | dme1737_pwm_chmod_attr[ix], |
@@ -2052,20 +2142,20 @@ static int dme1737_init_device(struct device *dev) | |||
2052 | return -EFAULT; | 2142 | return -EFAULT; |
2053 | } | 2143 | } |
2054 | 2144 | ||
2055 | /* Determine which optional fan and pwm features are enabled/present */ | 2145 | /* Determine which optional fan and pwm features are enabled (only |
2146 | * valid for I2C devices) */ | ||
2056 | if (client) { /* I2C chip */ | 2147 | if (client) { /* I2C chip */ |
2057 | data->config2 = dme1737_read(data, DME1737_REG_CONFIG2); | 2148 | data->config2 = dme1737_read(data, DME1737_REG_CONFIG2); |
2058 | /* Check if optional fan3 input is enabled */ | 2149 | /* Check if optional fan3 input is enabled */ |
2059 | if (data->config2 & 0x04) { | 2150 | if (data->config2 & 0x04) { |
2060 | data->has_fan |= (1 << 2); | 2151 | data->has_features |= HAS_FAN(2); |
2061 | } | 2152 | } |
2062 | 2153 | ||
2063 | /* Fan4 and pwm3 are only available if the client's I2C address | 2154 | /* Fan4 and pwm3 are only available if the client's I2C address |
2064 | * is the default 0x2e. Otherwise the I/Os associated with | 2155 | * is the default 0x2e. Otherwise the I/Os associated with |
2065 | * these functions are used for addr enable/select. */ | 2156 | * these functions are used for addr enable/select. */ |
2066 | if (client->addr == 0x2e) { | 2157 | if (client->addr == 0x2e) { |
2067 | data->has_fan |= (1 << 3); | 2158 | data->has_features |= HAS_FAN(3) | HAS_PWM(2); |
2068 | data->has_pwm |= (1 << 2); | ||
2069 | } | 2159 | } |
2070 | 2160 | ||
2071 | /* Determine which of the optional fan[5-6] and pwm[5-6] | 2161 | /* Determine which of the optional fan[5-6] and pwm[5-6] |
@@ -2077,26 +2167,40 @@ static int dme1737_init_device(struct device *dev) | |||
2077 | dev_warn(dev, "Failed to query Super-IO for optional " | 2167 | dev_warn(dev, "Failed to query Super-IO for optional " |
2078 | "features.\n"); | 2168 | "features.\n"); |
2079 | } | 2169 | } |
2080 | } else { /* ISA chip */ | ||
2081 | /* Fan3 and pwm3 are always available. Fan[4-5] and pwm[5-6] | ||
2082 | * don't exist in the ISA chip. */ | ||
2083 | data->has_fan |= (1 << 2); | ||
2084 | data->has_pwm |= (1 << 2); | ||
2085 | } | 2170 | } |
2086 | 2171 | ||
2087 | /* Fan1, fan2, pwm1, and pwm2 are always present */ | 2172 | /* Fan[1-2] and pwm[1-2] are present in all chips */ |
2088 | data->has_fan |= 0x03; | 2173 | data->has_features |= HAS_FAN(0) | HAS_FAN(1) | HAS_PWM(0) | HAS_PWM(1); |
2089 | data->has_pwm |= 0x03; | 2174 | |
2175 | /* Chip-dependent features */ | ||
2176 | switch (data->type) { | ||
2177 | case dme1737: | ||
2178 | data->has_features |= HAS_TEMP_OFFSET | HAS_VID | HAS_ZONE3 | | ||
2179 | HAS_ZONE_HYST | HAS_PWM_MIN; | ||
2180 | break; | ||
2181 | case sch311x: | ||
2182 | data->has_features |= HAS_TEMP_OFFSET | HAS_ZONE3 | | ||
2183 | HAS_ZONE_HYST | HAS_PWM_MIN | HAS_FAN(2) | HAS_PWM(2); | ||
2184 | break; | ||
2185 | case sch5027: | ||
2186 | data->has_features |= HAS_ZONE3; | ||
2187 | break; | ||
2188 | case sch5127: | ||
2189 | data->has_features |= HAS_FAN(2) | HAS_PWM(2); | ||
2190 | break; | ||
2191 | default: | ||
2192 | break; | ||
2193 | } | ||
2090 | 2194 | ||
2091 | dev_info(dev, "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, " | 2195 | dev_info(dev, "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, " |
2092 | "fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n", | 2196 | "fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n", |
2093 | (data->has_pwm & (1 << 2)) ? "yes" : "no", | 2197 | (data->has_features & HAS_PWM(2)) ? "yes" : "no", |
2094 | (data->has_pwm & (1 << 4)) ? "yes" : "no", | 2198 | (data->has_features & HAS_PWM(4)) ? "yes" : "no", |
2095 | (data->has_pwm & (1 << 5)) ? "yes" : "no", | 2199 | (data->has_features & HAS_PWM(5)) ? "yes" : "no", |
2096 | (data->has_fan & (1 << 2)) ? "yes" : "no", | 2200 | (data->has_features & HAS_FAN(2)) ? "yes" : "no", |
2097 | (data->has_fan & (1 << 3)) ? "yes" : "no", | 2201 | (data->has_features & HAS_FAN(3)) ? "yes" : "no", |
2098 | (data->has_fan & (1 << 4)) ? "yes" : "no", | 2202 | (data->has_features & HAS_FAN(4)) ? "yes" : "no", |
2099 | (data->has_fan & (1 << 5)) ? "yes" : "no"); | 2203 | (data->has_features & HAS_FAN(5)) ? "yes" : "no"); |
2100 | 2204 | ||
2101 | reg = dme1737_read(data, DME1737_REG_TACH_PWM); | 2205 | reg = dme1737_read(data, DME1737_REG_TACH_PWM); |
2102 | /* Inform if fan-to-pwm mapping differs from the default */ | 2206 | /* Inform if fan-to-pwm mapping differs from the default */ |
@@ -2122,7 +2226,7 @@ static int dme1737_init_device(struct device *dev) | |||
2122 | for (ix = 0; ix < 3; ix++) { | 2226 | for (ix = 0; ix < 3; ix++) { |
2123 | data->pwm_config[ix] = dme1737_read(data, | 2227 | data->pwm_config[ix] = dme1737_read(data, |
2124 | DME1737_REG_PWM_CONFIG(ix)); | 2228 | DME1737_REG_PWM_CONFIG(ix)); |
2125 | if ((data->has_pwm & (1 << ix)) && | 2229 | if ((data->has_features & HAS_PWM(ix)) && |
2126 | (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { | 2230 | (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { |
2127 | dev_info(dev, "Switching pwm%d to " | 2231 | dev_info(dev, "Switching pwm%d to " |
2128 | "manual mode.\n", ix + 1); | 2232 | "manual mode.\n", ix + 1); |
@@ -2142,7 +2246,7 @@ static int dme1737_init_device(struct device *dev) | |||
2142 | data->pwm_acz[2] = 4; /* pwm3 -> zone3 */ | 2246 | data->pwm_acz[2] = 4; /* pwm3 -> zone3 */ |
2143 | 2247 | ||
2144 | /* Set VRM */ | 2248 | /* Set VRM */ |
2145 | if (data->type == dme1737) { | 2249 | if (data->has_features & HAS_VID) { |
2146 | data->vrm = vid_which_vrm(); | 2250 | data->vrm = vid_which_vrm(); |
2147 | } | 2251 | } |
2148 | 2252 | ||
@@ -2163,10 +2267,10 @@ static int dme1737_i2c_get_features(int sio_cip, struct dme1737_data *data) | |||
2163 | dme1737_sio_enter(sio_cip); | 2267 | dme1737_sio_enter(sio_cip); |
2164 | 2268 | ||
2165 | /* Check device ID | 2269 | /* Check device ID |
2166 | * The DME1737 can return either 0x78 or 0x77 as its device ID. | 2270 | * We currently know about two kinds of DME1737 and SCH5027. */ |
2167 | * The SCH5027 returns 0x89 as its device ID. */ | ||
2168 | reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20); | 2271 | reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20); |
2169 | if (!(reg == 0x77 || reg == 0x78 || reg == 0x89)) { | 2272 | if (!(reg == DME1737_ID_1 || reg == DME1737_ID_2 || |
2273 | reg == SCH5027_ID)) { | ||
2170 | err = -ENODEV; | 2274 | err = -ENODEV; |
2171 | goto exit; | 2275 | goto exit; |
2172 | } | 2276 | } |
@@ -2185,16 +2289,16 @@ static int dme1737_i2c_get_features(int sio_cip, struct dme1737_data *data) | |||
2185 | * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set | 2289 | * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set |
2186 | * to '10' if the respective feature is enabled. */ | 2290 | * to '10' if the respective feature is enabled. */ |
2187 | if ((inb(addr + 0x43) & 0x0c) == 0x08) { /* fan6 */ | 2291 | if ((inb(addr + 0x43) & 0x0c) == 0x08) { /* fan6 */ |
2188 | data->has_fan |= (1 << 5); | 2292 | data->has_features |= HAS_FAN(5); |
2189 | } | 2293 | } |
2190 | if ((inb(addr + 0x44) & 0x0c) == 0x08) { /* pwm6 */ | 2294 | if ((inb(addr + 0x44) & 0x0c) == 0x08) { /* pwm6 */ |
2191 | data->has_pwm |= (1 << 5); | 2295 | data->has_features |= HAS_PWM(5); |
2192 | } | 2296 | } |
2193 | if ((inb(addr + 0x45) & 0x0c) == 0x08) { /* fan5 */ | 2297 | if ((inb(addr + 0x45) & 0x0c) == 0x08) { /* fan5 */ |
2194 | data->has_fan |= (1 << 4); | 2298 | data->has_features |= HAS_FAN(4); |
2195 | } | 2299 | } |
2196 | if ((inb(addr + 0x46) & 0x0c) == 0x08) { /* pwm5 */ | 2300 | if ((inb(addr + 0x46) & 0x0c) == 0x08) { /* pwm5 */ |
2197 | data->has_pwm |= (1 << 4); | 2301 | data->has_features |= HAS_PWM(4); |
2198 | } | 2302 | } |
2199 | 2303 | ||
2200 | exit: | 2304 | exit: |
@@ -2222,7 +2326,6 @@ static int dme1737_i2c_detect(struct i2c_client *client, | |||
2222 | if (company == DME1737_COMPANY_SMSC && | 2326 | if (company == DME1737_COMPANY_SMSC && |
2223 | verstep == SCH5027_VERSTEP) { | 2327 | verstep == SCH5027_VERSTEP) { |
2224 | name = "sch5027"; | 2328 | name = "sch5027"; |
2225 | |||
2226 | } else if (company == DME1737_COMPANY_SMSC && | 2329 | } else if (company == DME1737_COMPANY_SMSC && |
2227 | (verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) { | 2330 | (verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) { |
2228 | name = "dme1737"; | 2331 | name = "dme1737"; |
@@ -2329,10 +2432,10 @@ static int __init dme1737_isa_detect(int sio_cip, unsigned short *addr) | |||
2329 | dme1737_sio_enter(sio_cip); | 2432 | dme1737_sio_enter(sio_cip); |
2330 | 2433 | ||
2331 | /* Check device ID | 2434 | /* Check device ID |
2332 | * We currently know about SCH3112 (0x7c), SCH3114 (0x7d), and | 2435 | * We currently know about SCH3112, SCH3114, SCH3116, and SCH5127 */ |
2333 | * SCH3116 (0x7f). */ | ||
2334 | reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20); | 2436 | reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20); |
2335 | if (!(reg == 0x7c || reg == 0x7d || reg == 0x7f)) { | 2437 | if (!(reg == SCH3112_ID || reg == SCH3114_ID || reg == SCH3116_ID || |
2438 | reg == SCH5127_ID)) { | ||
2336 | err = -ENODEV; | 2439 | err = -ENODEV; |
2337 | goto exit; | 2440 | goto exit; |
2338 | } | 2441 | } |
@@ -2424,23 +2527,42 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev) | |||
2424 | platform_set_drvdata(pdev, data); | 2527 | platform_set_drvdata(pdev, data); |
2425 | 2528 | ||
2426 | /* Skip chip detection if module is loaded with force_id parameter */ | 2529 | /* Skip chip detection if module is loaded with force_id parameter */ |
2427 | if (!force_id) { | 2530 | switch (force_id) { |
2531 | case SCH3112_ID: | ||
2532 | case SCH3114_ID: | ||
2533 | case SCH3116_ID: | ||
2534 | data->type = sch311x; | ||
2535 | break; | ||
2536 | case SCH5127_ID: | ||
2537 | data->type = sch5127; | ||
2538 | break; | ||
2539 | default: | ||
2428 | company = dme1737_read(data, DME1737_REG_COMPANY); | 2540 | company = dme1737_read(data, DME1737_REG_COMPANY); |
2429 | device = dme1737_read(data, DME1737_REG_DEVICE); | 2541 | device = dme1737_read(data, DME1737_REG_DEVICE); |
2430 | 2542 | ||
2431 | if (!((company == DME1737_COMPANY_SMSC) && | 2543 | if ((company == DME1737_COMPANY_SMSC) && |
2432 | (device == SCH311X_DEVICE))) { | 2544 | (device == SCH311X_DEVICE)) { |
2545 | data->type = sch311x; | ||
2546 | } else if ((company == DME1737_COMPANY_SMSC) && | ||
2547 | (device == SCH5127_DEVICE)) { | ||
2548 | data->type = sch5127; | ||
2549 | } else { | ||
2433 | err = -ENODEV; | 2550 | err = -ENODEV; |
2434 | goto exit_kfree; | 2551 | goto exit_kfree; |
2435 | } | 2552 | } |
2436 | } | 2553 | } |
2437 | data->type = sch311x; | ||
2438 | 2554 | ||
2439 | /* Fill in the remaining client fields and initialize the mutex */ | 2555 | if (data->type == sch5127) { |
2440 | data->name = "sch311x"; | 2556 | data->name = "sch5127"; |
2557 | } else { | ||
2558 | data->name = "sch311x"; | ||
2559 | } | ||
2560 | |||
2561 | /* Initialize the mutex */ | ||
2441 | mutex_init(&data->update_lock); | 2562 | mutex_init(&data->update_lock); |
2442 | 2563 | ||
2443 | dev_info(dev, "Found a SCH311x chip at 0x%04x\n", data->addr); | 2564 | dev_info(dev, "Found a %s chip at 0x%04x\n", |
2565 | data->type == sch5127 ? "SCH5127" : "SCH311x", data->addr); | ||
2444 | 2566 | ||
2445 | /* Initialize the chip */ | 2567 | /* Initialize the chip */ |
2446 | if ((err = dme1737_init_device(dev))) { | 2568 | if ((err = dme1737_init_device(dev))) { |
diff --git a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c new file mode 100644 index 000000000000..0e4b5642638d --- /dev/null +++ b/drivers/hwmon/emc1403.c | |||
@@ -0,0 +1,344 @@ | |||
1 | /* | ||
2 | * emc1403.c - SMSC Thermal Driver | ||
3 | * | ||
4 | * Copyright (C) 2008 Intel Corp | ||
5 | * | ||
6 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
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; version 2 of the License. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but | ||
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License along | ||
18 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | ||
20 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
21 | * | ||
22 | * TODO | ||
23 | * - cache alarm and critical limit registers | ||
24 | * - add emc1404 support | ||
25 | */ | ||
26 | |||
27 | #include <linux/module.h> | ||
28 | #include <linux/init.h> | ||
29 | #include <linux/slab.h> | ||
30 | #include <linux/i2c.h> | ||
31 | #include <linux/hwmon.h> | ||
32 | #include <linux/hwmon-sysfs.h> | ||
33 | #include <linux/err.h> | ||
34 | #include <linux/sysfs.h> | ||
35 | #include <linux/mutex.h> | ||
36 | |||
37 | #define THERMAL_PID_REG 0xfd | ||
38 | #define THERMAL_SMSC_ID_REG 0xfe | ||
39 | #define THERMAL_REVISION_REG 0xff | ||
40 | |||
41 | struct thermal_data { | ||
42 | struct device *hwmon_dev; | ||
43 | struct mutex mutex; | ||
44 | /* Cache the hyst value so we don't keep re-reading it. In theory | ||
45 | we could cache it forever as nobody else should be writing it. */ | ||
46 | u8 cached_hyst; | ||
47 | unsigned long hyst_valid; | ||
48 | }; | ||
49 | |||
50 | static ssize_t show_temp(struct device *dev, | ||
51 | struct device_attribute *attr, char *buf) | ||
52 | { | ||
53 | struct i2c_client *client = to_i2c_client(dev); | ||
54 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); | ||
55 | int retval = i2c_smbus_read_byte_data(client, sda->index); | ||
56 | |||
57 | if (retval < 0) | ||
58 | return retval; | ||
59 | return sprintf(buf, "%d000\n", retval); | ||
60 | } | ||
61 | |||
62 | static ssize_t show_bit(struct device *dev, | ||
63 | struct device_attribute *attr, char *buf) | ||
64 | { | ||
65 | struct i2c_client *client = to_i2c_client(dev); | ||
66 | struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr); | ||
67 | int retval = i2c_smbus_read_byte_data(client, sda->nr); | ||
68 | |||
69 | if (retval < 0) | ||
70 | return retval; | ||
71 | retval &= sda->index; | ||
72 | return sprintf(buf, "%d\n", retval ? 1 : 0); | ||
73 | } | ||
74 | |||
75 | static ssize_t store_temp(struct device *dev, | ||
76 | struct device_attribute *attr, const char *buf, size_t count) | ||
77 | { | ||
78 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); | ||
79 | struct i2c_client *client = to_i2c_client(dev); | ||
80 | unsigned long val; | ||
81 | int retval; | ||
82 | |||
83 | if (strict_strtoul(buf, 10, &val)) | ||
84 | return -EINVAL; | ||
85 | retval = i2c_smbus_write_byte_data(client, sda->index, | ||
86 | DIV_ROUND_CLOSEST(val, 1000)); | ||
87 | if (retval < 0) | ||
88 | return retval; | ||
89 | return count; | ||
90 | } | ||
91 | |||
92 | static ssize_t show_hyst(struct device *dev, | ||
93 | struct device_attribute *attr, char *buf) | ||
94 | { | ||
95 | struct i2c_client *client = to_i2c_client(dev); | ||
96 | struct thermal_data *data = i2c_get_clientdata(client); | ||
97 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); | ||
98 | int retval; | ||
99 | int hyst; | ||
100 | |||
101 | retval = i2c_smbus_read_byte_data(client, sda->index); | ||
102 | if (retval < 0) | ||
103 | return retval; | ||
104 | |||
105 | if (time_after(jiffies, data->hyst_valid)) { | ||
106 | hyst = i2c_smbus_read_byte_data(client, 0x21); | ||
107 | if (hyst < 0) | ||
108 | return retval; | ||
109 | data->cached_hyst = hyst; | ||
110 | data->hyst_valid = jiffies + HZ; | ||
111 | } | ||
112 | return sprintf(buf, "%d000\n", retval - data->cached_hyst); | ||
113 | } | ||
114 | |||
115 | static ssize_t store_hyst(struct device *dev, | ||
116 | struct device_attribute *attr, const char *buf, size_t count) | ||
117 | { | ||
118 | struct i2c_client *client = to_i2c_client(dev); | ||
119 | struct thermal_data *data = i2c_get_clientdata(client); | ||
120 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); | ||
121 | int retval; | ||
122 | int hyst; | ||
123 | unsigned long val; | ||
124 | |||
125 | if (strict_strtoul(buf, 10, &val)) | ||
126 | return -EINVAL; | ||
127 | |||
128 | mutex_lock(&data->mutex); | ||
129 | retval = i2c_smbus_read_byte_data(client, sda->index); | ||
130 | if (retval < 0) | ||
131 | goto fail; | ||
132 | |||
133 | hyst = val - retval * 1000; | ||
134 | hyst = DIV_ROUND_CLOSEST(hyst, 1000); | ||
135 | if (hyst < 0 || hyst > 255) { | ||
136 | retval = -ERANGE; | ||
137 | goto fail; | ||
138 | } | ||
139 | |||
140 | retval = i2c_smbus_write_byte_data(client, 0x21, hyst); | ||
141 | if (retval == 0) { | ||
142 | retval = count; | ||
143 | data->cached_hyst = hyst; | ||
144 | data->hyst_valid = jiffies + HZ; | ||
145 | } | ||
146 | fail: | ||
147 | mutex_unlock(&data->mutex); | ||
148 | return retval; | ||
149 | } | ||
150 | |||
151 | /* | ||
152 | * Sensors. We pass the actual i2c register to the methods. | ||
153 | */ | ||
154 | |||
155 | static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO | S_IWUSR, | ||
156 | show_temp, store_temp, 0x06); | ||
157 | static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, | ||
158 | show_temp, store_temp, 0x05); | ||
159 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO | S_IWUSR, | ||
160 | show_temp, store_temp, 0x20); | ||
161 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0x00); | ||
162 | static SENSOR_DEVICE_ATTR_2(temp1_min_alarm, S_IRUGO, | ||
163 | show_bit, NULL, 0x36, 0x01); | ||
164 | static SENSOR_DEVICE_ATTR_2(temp1_max_alarm, S_IRUGO, | ||
165 | show_bit, NULL, 0x35, 0x01); | ||
166 | static SENSOR_DEVICE_ATTR_2(temp1_crit_alarm, S_IRUGO, | ||
167 | show_bit, NULL, 0x37, 0x01); | ||
168 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO | S_IWUSR, | ||
169 | show_hyst, store_hyst, 0x20); | ||
170 | |||
171 | static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO | S_IWUSR, | ||
172 | show_temp, store_temp, 0x08); | ||
173 | static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR, | ||
174 | show_temp, store_temp, 0x07); | ||
175 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO | S_IWUSR, | ||
176 | show_temp, store_temp, 0x19); | ||
177 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 0x01); | ||
178 | static SENSOR_DEVICE_ATTR_2(temp2_min_alarm, S_IRUGO, | ||
179 | show_bit, NULL, 0x36, 0x02); | ||
180 | static SENSOR_DEVICE_ATTR_2(temp2_max_alarm, S_IRUGO, | ||
181 | show_bit, NULL, 0x35, 0x02); | ||
182 | static SENSOR_DEVICE_ATTR_2(temp2_crit_alarm, S_IRUGO, | ||
183 | show_bit, NULL, 0x37, 0x02); | ||
184 | static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO | S_IWUSR, | ||
185 | show_hyst, store_hyst, 0x19); | ||
186 | |||
187 | static SENSOR_DEVICE_ATTR(temp3_min, S_IRUGO | S_IWUSR, | ||
188 | show_temp, store_temp, 0x16); | ||
189 | static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO | S_IWUSR, | ||
190 | show_temp, store_temp, 0x15); | ||
191 | static SENSOR_DEVICE_ATTR(temp3_crit, S_IRUGO | S_IWUSR, | ||
192 | show_temp, store_temp, 0x1A); | ||
193 | static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 0x23); | ||
194 | static SENSOR_DEVICE_ATTR_2(temp3_min_alarm, S_IRUGO, | ||
195 | show_bit, NULL, 0x36, 0x04); | ||
196 | static SENSOR_DEVICE_ATTR_2(temp3_max_alarm, S_IRUGO, | ||
197 | show_bit, NULL, 0x35, 0x04); | ||
198 | static SENSOR_DEVICE_ATTR_2(temp3_crit_alarm, S_IRUGO, | ||
199 | show_bit, NULL, 0x37, 0x04); | ||
200 | static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO | S_IWUSR, | ||
201 | show_hyst, store_hyst, 0x1A); | ||
202 | |||
203 | static struct attribute *mid_att_thermal[] = { | ||
204 | &sensor_dev_attr_temp1_min.dev_attr.attr, | ||
205 | &sensor_dev_attr_temp1_max.dev_attr.attr, | ||
206 | &sensor_dev_attr_temp1_crit.dev_attr.attr, | ||
207 | &sensor_dev_attr_temp1_input.dev_attr.attr, | ||
208 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, | ||
209 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, | ||
210 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, | ||
211 | &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, | ||
212 | &sensor_dev_attr_temp2_min.dev_attr.attr, | ||
213 | &sensor_dev_attr_temp2_max.dev_attr.attr, | ||
214 | &sensor_dev_attr_temp2_crit.dev_attr.attr, | ||
215 | &sensor_dev_attr_temp2_input.dev_attr.attr, | ||
216 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, | ||
217 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, | ||
218 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, | ||
219 | &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr, | ||
220 | &sensor_dev_attr_temp3_min.dev_attr.attr, | ||
221 | &sensor_dev_attr_temp3_max.dev_attr.attr, | ||
222 | &sensor_dev_attr_temp3_crit.dev_attr.attr, | ||
223 | &sensor_dev_attr_temp3_input.dev_attr.attr, | ||
224 | &sensor_dev_attr_temp3_min_alarm.dev_attr.attr, | ||
225 | &sensor_dev_attr_temp3_max_alarm.dev_attr.attr, | ||
226 | &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr, | ||
227 | &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr, | ||
228 | NULL | ||
229 | }; | ||
230 | |||
231 | static const struct attribute_group m_thermal_gr = { | ||
232 | .attrs = mid_att_thermal | ||
233 | }; | ||
234 | |||
235 | static int emc1403_detect(struct i2c_client *client, | ||
236 | struct i2c_board_info *info) | ||
237 | { | ||
238 | int id; | ||
239 | /* Check if thermal chip is SMSC and EMC1403 */ | ||
240 | |||
241 | id = i2c_smbus_read_byte_data(client, THERMAL_SMSC_ID_REG); | ||
242 | if (id != 0x5d) | ||
243 | return -ENODEV; | ||
244 | |||
245 | /* Note: 0x25 is the 1404 which is very similar and this | ||
246 | driver could be extended */ | ||
247 | id = i2c_smbus_read_byte_data(client, THERMAL_PID_REG); | ||
248 | if (id != 0x21) | ||
249 | return -ENODEV; | ||
250 | |||
251 | id = i2c_smbus_read_byte_data(client, THERMAL_REVISION_REG); | ||
252 | if (id != 0x01) | ||
253 | return -ENODEV; | ||
254 | |||
255 | strlcpy(info->type, "emc1403", I2C_NAME_SIZE); | ||
256 | return 0; | ||
257 | } | ||
258 | |||
259 | static int emc1403_probe(struct i2c_client *client, | ||
260 | const struct i2c_device_id *id) | ||
261 | { | ||
262 | int res; | ||
263 | struct thermal_data *data; | ||
264 | |||
265 | data = kzalloc(sizeof(struct thermal_data), GFP_KERNEL); | ||
266 | if (data == NULL) { | ||
267 | dev_warn(&client->dev, "out of memory"); | ||
268 | return -ENOMEM; | ||
269 | } | ||
270 | |||
271 | i2c_set_clientdata(client, data); | ||
272 | mutex_init(&data->mutex); | ||
273 | data->hyst_valid = jiffies - 1; /* Expired */ | ||
274 | |||
275 | res = sysfs_create_group(&client->dev.kobj, &m_thermal_gr); | ||
276 | if (res) { | ||
277 | dev_warn(&client->dev, "create group failed\n"); | ||
278 | hwmon_device_unregister(data->hwmon_dev); | ||
279 | goto thermal_error1; | ||
280 | } | ||
281 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
282 | if (IS_ERR(data->hwmon_dev)) { | ||
283 | res = PTR_ERR(data->hwmon_dev); | ||
284 | dev_warn(&client->dev, "register hwmon dev failed\n"); | ||
285 | goto thermal_error2; | ||
286 | } | ||
287 | dev_info(&client->dev, "EMC1403 Thermal chip found\n"); | ||
288 | return res; | ||
289 | |||
290 | thermal_error2: | ||
291 | sysfs_remove_group(&client->dev.kobj, &m_thermal_gr); | ||
292 | thermal_error1: | ||
293 | kfree(data); | ||
294 | return res; | ||
295 | } | ||
296 | |||
297 | static int emc1403_remove(struct i2c_client *client) | ||
298 | { | ||
299 | struct thermal_data *data = i2c_get_clientdata(client); | ||
300 | |||
301 | hwmon_device_unregister(data->hwmon_dev); | ||
302 | sysfs_remove_group(&client->dev.kobj, &m_thermal_gr); | ||
303 | kfree(data); | ||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | static const unsigned short emc1403_address_list[] = { | ||
308 | 0x18, 0x2a, 0x4c, 0x4d, I2C_CLIENT_END | ||
309 | }; | ||
310 | |||
311 | static const struct i2c_device_id emc1403_idtable[] = { | ||
312 | { "emc1403", 0 }, | ||
313 | { } | ||
314 | }; | ||
315 | MODULE_DEVICE_TABLE(i2c, emc1403_idtable); | ||
316 | |||
317 | static struct i2c_driver sensor_emc1403 = { | ||
318 | .class = I2C_CLASS_HWMON, | ||
319 | .driver = { | ||
320 | .name = "emc1403", | ||
321 | }, | ||
322 | .detect = emc1403_detect, | ||
323 | .probe = emc1403_probe, | ||
324 | .remove = emc1403_remove, | ||
325 | .id_table = emc1403_idtable, | ||
326 | .address_list = emc1403_address_list, | ||
327 | }; | ||
328 | |||
329 | static int __init sensor_emc1403_init(void) | ||
330 | { | ||
331 | return i2c_add_driver(&sensor_emc1403); | ||
332 | } | ||
333 | |||
334 | static void __exit sensor_emc1403_exit(void) | ||
335 | { | ||
336 | i2c_del_driver(&sensor_emc1403); | ||
337 | } | ||
338 | |||
339 | module_init(sensor_emc1403_init); | ||
340 | module_exit(sensor_emc1403_exit); | ||
341 | |||
342 | MODULE_AUTHOR("Kalhan Trisal <kalhan.trisal@intel.com"); | ||
343 | MODULE_DESCRIPTION("emc1403 Thermal Driver"); | ||
344 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c index a95fa4256caa..537841ef44b9 100644 --- a/drivers/hwmon/f71882fg.c +++ b/drivers/hwmon/f71882fg.c | |||
@@ -856,21 +856,19 @@ static inline int superio_inb(int base, int reg) | |||
856 | static int superio_inw(int base, int reg) | 856 | static int superio_inw(int base, int reg) |
857 | { | 857 | { |
858 | int val; | 858 | int val; |
859 | outb(reg++, base); | 859 | val = superio_inb(base, reg) << 8; |
860 | val = inb(base + 1) << 8; | 860 | val |= superio_inb(base, reg + 1); |
861 | outb(reg, base); | ||
862 | val |= inb(base + 1); | ||
863 | return val; | 861 | return val; |
864 | } | 862 | } |
865 | 863 | ||
866 | static inline void superio_enter(int base) | 864 | static inline void superio_enter(int base) |
867 | { | 865 | { |
868 | /* according to the datasheet the key must be send twice! */ | 866 | /* according to the datasheet the key must be send twice! */ |
869 | outb( SIO_UNLOCK_KEY, base); | 867 | outb(SIO_UNLOCK_KEY, base); |
870 | outb( SIO_UNLOCK_KEY, base); | 868 | outb(SIO_UNLOCK_KEY, base); |
871 | } | 869 | } |
872 | 870 | ||
873 | static inline void superio_select( int base, int ld) | 871 | static inline void superio_select(int base, int ld) |
874 | { | 872 | { |
875 | outb(SIO_REG_LDSEL, base); | 873 | outb(SIO_REG_LDSEL, base); |
876 | outb(ld, base + 1); | 874 | outb(ld, base + 1); |
@@ -905,10 +903,8 @@ static u16 f71882fg_read16(struct f71882fg_data *data, u8 reg) | |||
905 | { | 903 | { |
906 | u16 val; | 904 | u16 val; |
907 | 905 | ||
908 | outb(reg++, data->addr + ADDR_REG_OFFSET); | 906 | val = f71882fg_read8(data, reg) << 8; |
909 | val = inb(data->addr + DATA_REG_OFFSET) << 8; | 907 | val |= f71882fg_read8(data, reg + 1); |
910 | outb(reg, data->addr + ADDR_REG_OFFSET); | ||
911 | val |= inb(data->addr + DATA_REG_OFFSET); | ||
912 | 908 | ||
913 | return val; | 909 | return val; |
914 | } | 910 | } |
@@ -921,10 +917,8 @@ static void f71882fg_write8(struct f71882fg_data *data, u8 reg, u8 val) | |||
921 | 917 | ||
922 | static void f71882fg_write16(struct f71882fg_data *data, u8 reg, u16 val) | 918 | static void f71882fg_write16(struct f71882fg_data *data, u8 reg, u16 val) |
923 | { | 919 | { |
924 | outb(reg++, data->addr + ADDR_REG_OFFSET); | 920 | f71882fg_write8(data, reg, val >> 8); |
925 | outb(val >> 8, data->addr + DATA_REG_OFFSET); | 921 | f71882fg_write8(data, reg + 1, val & 0xff); |
926 | outb(reg, data->addr + ADDR_REG_OFFSET); | ||
927 | outb(val & 255, data->addr + DATA_REG_OFFSET); | ||
928 | } | 922 | } |
929 | 923 | ||
930 | static u16 f71882fg_read_temp(struct f71882fg_data *data, int nr) | 924 | static u16 f71882fg_read_temp(struct f71882fg_data *data, int nr) |
@@ -945,7 +939,7 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev) | |||
945 | mutex_lock(&data->update_lock); | 939 | mutex_lock(&data->update_lock); |
946 | 940 | ||
947 | /* Update once every 60 seconds */ | 941 | /* Update once every 60 seconds */ |
948 | if ( time_after(jiffies, data->last_limits + 60 * HZ ) || | 942 | if (time_after(jiffies, data->last_limits + 60 * HZ) || |
949 | !data->valid) { | 943 | !data->valid) { |
950 | if (data->type == f71882fg || data->type == f71889fg) { | 944 | if (data->type == f71882fg || data->type == f71889fg) { |
951 | data->in1_max = | 945 | data->in1_max = |
@@ -1127,8 +1121,12 @@ static ssize_t store_fan_full_speed(struct device *dev, | |||
1127 | const char *buf, size_t count) | 1121 | const char *buf, size_t count) |
1128 | { | 1122 | { |
1129 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1123 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1130 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1124 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
1131 | long val = simple_strtol(buf, NULL, 10); | 1125 | long val; |
1126 | |||
1127 | err = strict_strtol(buf, 10, &val); | ||
1128 | if (err) | ||
1129 | return err; | ||
1132 | 1130 | ||
1133 | val = SENSORS_LIMIT(val, 23, 1500000); | 1131 | val = SENSORS_LIMIT(val, 23, 1500000); |
1134 | val = fan_to_reg(val); | 1132 | val = fan_to_reg(val); |
@@ -1157,8 +1155,12 @@ static ssize_t store_fan_beep(struct device *dev, struct device_attribute | |||
1157 | *devattr, const char *buf, size_t count) | 1155 | *devattr, const char *buf, size_t count) |
1158 | { | 1156 | { |
1159 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1157 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1160 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1158 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
1161 | unsigned long val = simple_strtoul(buf, NULL, 10); | 1159 | unsigned long val; |
1160 | |||
1161 | err = strict_strtoul(buf, 10, &val); | ||
1162 | if (err) | ||
1163 | return err; | ||
1162 | 1164 | ||
1163 | mutex_lock(&data->update_lock); | 1165 | mutex_lock(&data->update_lock); |
1164 | data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP); | 1166 | data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP); |
@@ -1206,7 +1208,14 @@ static ssize_t store_in_max(struct device *dev, struct device_attribute | |||
1206 | *devattr, const char *buf, size_t count) | 1208 | *devattr, const char *buf, size_t count) |
1207 | { | 1209 | { |
1208 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1210 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1209 | long val = simple_strtol(buf, NULL, 10) / 8; | 1211 | int err; |
1212 | long val; | ||
1213 | |||
1214 | err = strict_strtol(buf, 10, &val); | ||
1215 | if (err) | ||
1216 | return err; | ||
1217 | |||
1218 | val /= 8; | ||
1210 | val = SENSORS_LIMIT(val, 0, 255); | 1219 | val = SENSORS_LIMIT(val, 0, 255); |
1211 | 1220 | ||
1212 | mutex_lock(&data->update_lock); | 1221 | mutex_lock(&data->update_lock); |
@@ -1233,8 +1242,12 @@ static ssize_t store_in_beep(struct device *dev, struct device_attribute | |||
1233 | *devattr, const char *buf, size_t count) | 1242 | *devattr, const char *buf, size_t count) |
1234 | { | 1243 | { |
1235 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1244 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1236 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1245 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
1237 | unsigned long val = simple_strtoul(buf, NULL, 10); | 1246 | unsigned long val; |
1247 | |||
1248 | err = strict_strtoul(buf, 10, &val); | ||
1249 | if (err) | ||
1250 | return err; | ||
1238 | 1251 | ||
1239 | mutex_lock(&data->update_lock); | 1252 | mutex_lock(&data->update_lock); |
1240 | data->in_beep = f71882fg_read8(data, F71882FG_REG_IN_BEEP); | 1253 | data->in_beep = f71882fg_read8(data, F71882FG_REG_IN_BEEP); |
@@ -1299,8 +1312,14 @@ static ssize_t store_temp_max(struct device *dev, struct device_attribute | |||
1299 | *devattr, const char *buf, size_t count) | 1312 | *devattr, const char *buf, size_t count) |
1300 | { | 1313 | { |
1301 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1314 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1302 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1315 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
1303 | long val = simple_strtol(buf, NULL, 10) / 1000; | 1316 | long val; |
1317 | |||
1318 | err = strict_strtol(buf, 10, &val); | ||
1319 | if (err) | ||
1320 | return err; | ||
1321 | |||
1322 | val /= 1000; | ||
1304 | val = SENSORS_LIMIT(val, 0, 255); | 1323 | val = SENSORS_LIMIT(val, 0, 255); |
1305 | 1324 | ||
1306 | mutex_lock(&data->update_lock); | 1325 | mutex_lock(&data->update_lock); |
@@ -1333,10 +1352,16 @@ static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute | |||
1333 | *devattr, const char *buf, size_t count) | 1352 | *devattr, const char *buf, size_t count) |
1334 | { | 1353 | { |
1335 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1354 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1336 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1355 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
1337 | long val = simple_strtol(buf, NULL, 10) / 1000; | ||
1338 | ssize_t ret = count; | 1356 | ssize_t ret = count; |
1339 | u8 reg; | 1357 | u8 reg; |
1358 | long val; | ||
1359 | |||
1360 | err = strict_strtol(buf, 10, &val); | ||
1361 | if (err) | ||
1362 | return err; | ||
1363 | |||
1364 | val /= 1000; | ||
1340 | 1365 | ||
1341 | mutex_lock(&data->update_lock); | 1366 | mutex_lock(&data->update_lock); |
1342 | 1367 | ||
@@ -1372,8 +1397,14 @@ static ssize_t store_temp_crit(struct device *dev, struct device_attribute | |||
1372 | *devattr, const char *buf, size_t count) | 1397 | *devattr, const char *buf, size_t count) |
1373 | { | 1398 | { |
1374 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1399 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1375 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1400 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
1376 | long val = simple_strtol(buf, NULL, 10) / 1000; | 1401 | long val; |
1402 | |||
1403 | err = strict_strtol(buf, 10, &val); | ||
1404 | if (err) | ||
1405 | return err; | ||
1406 | |||
1407 | val /= 1000; | ||
1377 | val = SENSORS_LIMIT(val, 0, 255); | 1408 | val = SENSORS_LIMIT(val, 0, 255); |
1378 | 1409 | ||
1379 | mutex_lock(&data->update_lock); | 1410 | mutex_lock(&data->update_lock); |
@@ -1427,8 +1458,12 @@ static ssize_t store_temp_beep(struct device *dev, struct device_attribute | |||
1427 | *devattr, const char *buf, size_t count) | 1458 | *devattr, const char *buf, size_t count) |
1428 | { | 1459 | { |
1429 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1460 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1430 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1461 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
1431 | unsigned long val = simple_strtoul(buf, NULL, 10); | 1462 | unsigned long val; |
1463 | |||
1464 | err = strict_strtoul(buf, 10, &val); | ||
1465 | if (err) | ||
1466 | return err; | ||
1432 | 1467 | ||
1433 | mutex_lock(&data->update_lock); | 1468 | mutex_lock(&data->update_lock); |
1434 | data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP); | 1469 | data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP); |
@@ -1490,8 +1525,13 @@ static ssize_t store_pwm(struct device *dev, | |||
1490 | size_t count) | 1525 | size_t count) |
1491 | { | 1526 | { |
1492 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1527 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1493 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1528 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
1494 | long val = simple_strtol(buf, NULL, 10); | 1529 | long val; |
1530 | |||
1531 | err = strict_strtol(buf, 10, &val); | ||
1532 | if (err) | ||
1533 | return err; | ||
1534 | |||
1495 | val = SENSORS_LIMIT(val, 0, 255); | 1535 | val = SENSORS_LIMIT(val, 0, 255); |
1496 | 1536 | ||
1497 | mutex_lock(&data->update_lock); | 1537 | mutex_lock(&data->update_lock); |
@@ -1551,8 +1591,12 @@ static ssize_t store_pwm_enable(struct device *dev, struct device_attribute | |||
1551 | *devattr, const char *buf, size_t count) | 1591 | *devattr, const char *buf, size_t count) |
1552 | { | 1592 | { |
1553 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1593 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1554 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1594 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
1555 | long val = simple_strtol(buf, NULL, 10); | 1595 | long val; |
1596 | |||
1597 | err = strict_strtol(buf, 10, &val); | ||
1598 | if (err) | ||
1599 | return err; | ||
1556 | 1600 | ||
1557 | /* Special case for F8000 pwm channel 3 which only does auto mode */ | 1601 | /* Special case for F8000 pwm channel 3 which only does auto mode */ |
1558 | if (data->type == f8000 && nr == 2 && val != 2) | 1602 | if (data->type == f8000 && nr == 2 && val != 2) |
@@ -1626,9 +1670,14 @@ static ssize_t store_pwm_auto_point_pwm(struct device *dev, | |||
1626 | const char *buf, size_t count) | 1670 | const char *buf, size_t count) |
1627 | { | 1671 | { |
1628 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1672 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1629 | int pwm = to_sensor_dev_attr_2(devattr)->index; | 1673 | int err, pwm = to_sensor_dev_attr_2(devattr)->index; |
1630 | int point = to_sensor_dev_attr_2(devattr)->nr; | 1674 | int point = to_sensor_dev_attr_2(devattr)->nr; |
1631 | long val = simple_strtol(buf, NULL, 10); | 1675 | long val; |
1676 | |||
1677 | err = strict_strtol(buf, 10, &val); | ||
1678 | if (err) | ||
1679 | return err; | ||
1680 | |||
1632 | val = SENSORS_LIMIT(val, 0, 255); | 1681 | val = SENSORS_LIMIT(val, 0, 255); |
1633 | 1682 | ||
1634 | mutex_lock(&data->update_lock); | 1683 | mutex_lock(&data->update_lock); |
@@ -1674,10 +1723,16 @@ static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev, | |||
1674 | const char *buf, size_t count) | 1723 | const char *buf, size_t count) |
1675 | { | 1724 | { |
1676 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1725 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1677 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1726 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
1678 | int point = to_sensor_dev_attr_2(devattr)->nr; | 1727 | int point = to_sensor_dev_attr_2(devattr)->nr; |
1679 | long val = simple_strtol(buf, NULL, 10) / 1000; | ||
1680 | u8 reg; | 1728 | u8 reg; |
1729 | long val; | ||
1730 | |||
1731 | err = strict_strtol(buf, 10, &val); | ||
1732 | if (err) | ||
1733 | return err; | ||
1734 | |||
1735 | val /= 1000; | ||
1681 | 1736 | ||
1682 | mutex_lock(&data->update_lock); | 1737 | mutex_lock(&data->update_lock); |
1683 | data->pwm_auto_point_temp[nr][point] = | 1738 | data->pwm_auto_point_temp[nr][point] = |
@@ -1716,8 +1771,12 @@ static ssize_t store_pwm_interpolate(struct device *dev, | |||
1716 | const char *buf, size_t count) | 1771 | const char *buf, size_t count) |
1717 | { | 1772 | { |
1718 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1773 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1719 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1774 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
1720 | unsigned long val = simple_strtoul(buf, NULL, 10); | 1775 | unsigned long val; |
1776 | |||
1777 | err = strict_strtoul(buf, 10, &val); | ||
1778 | if (err) | ||
1779 | return err; | ||
1721 | 1780 | ||
1722 | mutex_lock(&data->update_lock); | 1781 | mutex_lock(&data->update_lock); |
1723 | data->pwm_auto_point_mapping[nr] = | 1782 | data->pwm_auto_point_mapping[nr] = |
@@ -1752,8 +1811,12 @@ static ssize_t store_pwm_auto_point_channel(struct device *dev, | |||
1752 | const char *buf, size_t count) | 1811 | const char *buf, size_t count) |
1753 | { | 1812 | { |
1754 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1813 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1755 | int nr = to_sensor_dev_attr_2(devattr)->index; | 1814 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
1756 | long val = simple_strtol(buf, NULL, 10); | 1815 | long val; |
1816 | |||
1817 | err = strict_strtol(buf, 10, &val); | ||
1818 | if (err) | ||
1819 | return err; | ||
1757 | 1820 | ||
1758 | switch (val) { | 1821 | switch (val) { |
1759 | case 1: | 1822 | case 1: |
@@ -1798,9 +1861,15 @@ static ssize_t store_pwm_auto_point_temp(struct device *dev, | |||
1798 | const char *buf, size_t count) | 1861 | const char *buf, size_t count) |
1799 | { | 1862 | { |
1800 | struct f71882fg_data *data = dev_get_drvdata(dev); | 1863 | struct f71882fg_data *data = dev_get_drvdata(dev); |
1801 | int pwm = to_sensor_dev_attr_2(devattr)->index; | 1864 | int err, pwm = to_sensor_dev_attr_2(devattr)->index; |
1802 | int point = to_sensor_dev_attr_2(devattr)->nr; | 1865 | int point = to_sensor_dev_attr_2(devattr)->nr; |
1803 | long val = simple_strtol(buf, NULL, 10) / 1000; | 1866 | long val; |
1867 | |||
1868 | err = strict_strtol(buf, 10, &val); | ||
1869 | if (err) | ||
1870 | return err; | ||
1871 | |||
1872 | val /= 1000; | ||
1804 | 1873 | ||
1805 | if (data->type == f71889fg) | 1874 | if (data->type == f71889fg) |
1806 | val = SENSORS_LIMIT(val, -128, 127); | 1875 | val = SENSORS_LIMIT(val, -128, 127); |
@@ -2109,6 +2178,13 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address, | |||
2109 | int err = -ENODEV; | 2178 | int err = -ENODEV; |
2110 | u16 devid; | 2179 | u16 devid; |
2111 | 2180 | ||
2181 | /* Don't step on other drivers' I/O space by accident */ | ||
2182 | if (!request_region(sioaddr, 2, DRVNAME)) { | ||
2183 | printk(KERN_ERR DRVNAME ": I/O address 0x%04x already in use\n", | ||
2184 | (int)sioaddr); | ||
2185 | return -EBUSY; | ||
2186 | } | ||
2187 | |||
2112 | superio_enter(sioaddr); | 2188 | superio_enter(sioaddr); |
2113 | 2189 | ||
2114 | devid = superio_inw(sioaddr, SIO_REG_MANID); | 2190 | devid = superio_inw(sioaddr, SIO_REG_MANID); |
@@ -2151,8 +2227,7 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address, | |||
2151 | } | 2227 | } |
2152 | 2228 | ||
2153 | *address = superio_inw(sioaddr, SIO_REG_ADDR); | 2229 | *address = superio_inw(sioaddr, SIO_REG_ADDR); |
2154 | if (*address == 0) | 2230 | if (*address == 0) { |
2155 | { | ||
2156 | printk(KERN_WARNING DRVNAME ": Base address not set\n"); | 2231 | printk(KERN_WARNING DRVNAME ": Base address not set\n"); |
2157 | goto exit; | 2232 | goto exit; |
2158 | } | 2233 | } |
@@ -2164,6 +2239,7 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address, | |||
2164 | (int)superio_inb(sioaddr, SIO_REG_DEVREV)); | 2239 | (int)superio_inb(sioaddr, SIO_REG_DEVREV)); |
2165 | exit: | 2240 | exit: |
2166 | superio_exit(sioaddr); | 2241 | superio_exit(sioaddr); |
2242 | release_region(sioaddr, 2); | ||
2167 | return err; | 2243 | return err; |
2168 | } | 2244 | } |
2169 | 2245 | ||
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c index bf81aff7051d..776aeb3019d2 100644 --- a/drivers/hwmon/lm63.c +++ b/drivers/hwmon/lm63.c | |||
@@ -53,7 +53,7 @@ | |||
53 | * Address is fully defined internally and cannot be changed. | 53 | * Address is fully defined internally and cannot be changed. |
54 | */ | 54 | */ |
55 | 55 | ||
56 | static const unsigned short normal_i2c[] = { 0x4c, I2C_CLIENT_END }; | 56 | static const unsigned short normal_i2c[] = { 0x18, 0x4c, 0x4e, I2C_CLIENT_END }; |
57 | 57 | ||
58 | /* | 58 | /* |
59 | * The LM63 registers | 59 | * The LM63 registers |
@@ -131,12 +131,15 @@ static struct lm63_data *lm63_update_device(struct device *dev); | |||
131 | static int lm63_detect(struct i2c_client *client, struct i2c_board_info *info); | 131 | static int lm63_detect(struct i2c_client *client, struct i2c_board_info *info); |
132 | static void lm63_init_client(struct i2c_client *client); | 132 | static void lm63_init_client(struct i2c_client *client); |
133 | 133 | ||
134 | enum chips { lm63, lm64 }; | ||
135 | |||
134 | /* | 136 | /* |
135 | * Driver data (common to all clients) | 137 | * Driver data (common to all clients) |
136 | */ | 138 | */ |
137 | 139 | ||
138 | static const struct i2c_device_id lm63_id[] = { | 140 | static const struct i2c_device_id lm63_id[] = { |
139 | { "lm63", 0 }, | 141 | { "lm63", lm63 }, |
142 | { "lm64", lm64 }, | ||
140 | { } | 143 | { } |
141 | }; | 144 | }; |
142 | MODULE_DEVICE_TABLE(i2c, lm63_id); | 145 | MODULE_DEVICE_TABLE(i2c, lm63_id); |
@@ -422,6 +425,7 @@ static int lm63_detect(struct i2c_client *new_client, | |||
422 | struct i2c_adapter *adapter = new_client->adapter; | 425 | struct i2c_adapter *adapter = new_client->adapter; |
423 | u8 man_id, chip_id, reg_config1, reg_config2; | 426 | u8 man_id, chip_id, reg_config1, reg_config2; |
424 | u8 reg_alert_status, reg_alert_mask; | 427 | u8 reg_alert_status, reg_alert_mask; |
428 | int address = new_client->addr; | ||
425 | 429 | ||
426 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 430 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
427 | return -ENODEV; | 431 | return -ENODEV; |
@@ -439,7 +443,6 @@ static int lm63_detect(struct i2c_client *new_client, | |||
439 | LM63_REG_ALERT_MASK); | 443 | LM63_REG_ALERT_MASK); |
440 | 444 | ||
441 | if (man_id != 0x01 /* National Semiconductor */ | 445 | if (man_id != 0x01 /* National Semiconductor */ |
442 | || chip_id != 0x41 /* LM63 */ | ||
443 | || (reg_config1 & 0x18) != 0x00 | 446 | || (reg_config1 & 0x18) != 0x00 |
444 | || (reg_config2 & 0xF8) != 0x00 | 447 | || (reg_config2 & 0xF8) != 0x00 |
445 | || (reg_alert_status & 0x20) != 0x00 | 448 | || (reg_alert_status & 0x20) != 0x00 |
@@ -450,7 +453,12 @@ static int lm63_detect(struct i2c_client *new_client, | |||
450 | return -ENODEV; | 453 | return -ENODEV; |
451 | } | 454 | } |
452 | 455 | ||
453 | strlcpy(info->type, "lm63", I2C_NAME_SIZE); | 456 | if (chip_id == 0x41 && address == 0x4c) |
457 | strlcpy(info->type, "lm63", I2C_NAME_SIZE); | ||
458 | else if (chip_id == 0x51 && (address == 0x18 || address == 0x4e)) | ||
459 | strlcpy(info->type, "lm64", I2C_NAME_SIZE); | ||
460 | else | ||
461 | return -ENODEV; | ||
454 | 462 | ||
455 | return 0; | 463 | return 0; |
456 | } | 464 | } |
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index 8ae2cfe2d827..56463428a419 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c | |||
@@ -46,6 +46,7 @@ enum lm75_type { /* keep sorted in alphabetical order */ | |||
46 | tcn75, | 46 | tcn75, |
47 | tmp100, | 47 | tmp100, |
48 | tmp101, | 48 | tmp101, |
49 | tmp105, | ||
49 | tmp175, | 50 | tmp175, |
50 | tmp275, | 51 | tmp275, |
51 | tmp75, | 52 | tmp75, |
@@ -220,6 +221,7 @@ static const struct i2c_device_id lm75_ids[] = { | |||
220 | { "tcn75", tcn75, }, | 221 | { "tcn75", tcn75, }, |
221 | { "tmp100", tmp100, }, | 222 | { "tmp100", tmp100, }, |
222 | { "tmp101", tmp101, }, | 223 | { "tmp101", tmp101, }, |
224 | { "tmp105", tmp105, }, | ||
223 | { "tmp175", tmp175, }, | 225 | { "tmp175", tmp175, }, |
224 | { "tmp275", tmp275, }, | 226 | { "tmp275", tmp275, }, |
225 | { "tmp75", tmp75, }, | 227 | { "tmp75", tmp75, }, |
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 7cc2708871ab..760ef72eea56 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -982,7 +982,8 @@ static struct lm90_data *lm90_update_device(struct device *dev) | |||
982 | 982 | ||
983 | mutex_lock(&data->update_lock); | 983 | mutex_lock(&data->update_lock); |
984 | 984 | ||
985 | if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { | 985 | if (time_after(jiffies, data->last_updated + HZ / 2 + HZ / 10) |
986 | || !data->valid) { | ||
986 | u8 h, l; | 987 | u8 h, l; |
987 | 988 | ||
988 | dev_dbg(&client->dev, "Updating lm90 data.\n"); | 989 | dev_dbg(&client->dev, "Updating lm90 data.\n"); |
diff --git a/drivers/hwmon/ltc4245.c b/drivers/hwmon/ltc4245.c index 65c232a9d0c5..21d201befc2c 100644 --- a/drivers/hwmon/ltc4245.c +++ b/drivers/hwmon/ltc4245.c | |||
@@ -45,9 +45,7 @@ enum ltc4245_cmd { | |||
45 | LTC4245_VEEIN = 0x19, | 45 | LTC4245_VEEIN = 0x19, |
46 | LTC4245_VEESENSE = 0x1a, | 46 | LTC4245_VEESENSE = 0x1a, |
47 | LTC4245_VEEOUT = 0x1b, | 47 | LTC4245_VEEOUT = 0x1b, |
48 | LTC4245_GPIOADC1 = 0x1c, | 48 | LTC4245_GPIOADC = 0x1c, |
49 | LTC4245_GPIOADC2 = 0x1d, | ||
50 | LTC4245_GPIOADC3 = 0x1e, | ||
51 | }; | 49 | }; |
52 | 50 | ||
53 | struct ltc4245_data { | 51 | struct ltc4245_data { |
@@ -61,7 +59,7 @@ struct ltc4245_data { | |||
61 | u8 cregs[0x08]; | 59 | u8 cregs[0x08]; |
62 | 60 | ||
63 | /* Voltage registers */ | 61 | /* Voltage registers */ |
64 | u8 vregs[0x0f]; | 62 | u8 vregs[0x0d]; |
65 | }; | 63 | }; |
66 | 64 | ||
67 | static struct ltc4245_data *ltc4245_update_device(struct device *dev) | 65 | static struct ltc4245_data *ltc4245_update_device(struct device *dev) |
@@ -86,7 +84,7 @@ static struct ltc4245_data *ltc4245_update_device(struct device *dev) | |||
86 | data->cregs[i] = val; | 84 | data->cregs[i] = val; |
87 | } | 85 | } |
88 | 86 | ||
89 | /* Read voltage registers -- 0x10 to 0x1f */ | 87 | /* Read voltage registers -- 0x10 to 0x1c */ |
90 | for (i = 0; i < ARRAY_SIZE(data->vregs); i++) { | 88 | for (i = 0; i < ARRAY_SIZE(data->vregs); i++) { |
91 | val = i2c_smbus_read_byte_data(client, i+0x10); | 89 | val = i2c_smbus_read_byte_data(client, i+0x10); |
92 | if (unlikely(val < 0)) | 90 | if (unlikely(val < 0)) |
@@ -128,9 +126,7 @@ static int ltc4245_get_voltage(struct device *dev, u8 reg) | |||
128 | case LTC4245_VEEOUT: | 126 | case LTC4245_VEEOUT: |
129 | voltage = regval * -55; | 127 | voltage = regval * -55; |
130 | break; | 128 | break; |
131 | case LTC4245_GPIOADC1: | 129 | case LTC4245_GPIOADC: |
132 | case LTC4245_GPIOADC2: | ||
133 | case LTC4245_GPIOADC3: | ||
134 | voltage = regval * 10; | 130 | voltage = regval * 10; |
135 | break; | 131 | break; |
136 | default: | 132 | default: |
@@ -297,9 +293,7 @@ LTC4245_ALARM(in7_min_alarm, (1 << 2), LTC4245_FAULT2); | |||
297 | LTC4245_ALARM(in8_min_alarm, (1 << 3), LTC4245_FAULT2); | 293 | LTC4245_ALARM(in8_min_alarm, (1 << 3), LTC4245_FAULT2); |
298 | 294 | ||
299 | /* GPIO voltages */ | 295 | /* GPIO voltages */ |
300 | LTC4245_VOLTAGE(in9_input, LTC4245_GPIOADC1); | 296 | LTC4245_VOLTAGE(in9_input, LTC4245_GPIOADC); |
301 | LTC4245_VOLTAGE(in10_input, LTC4245_GPIOADC2); | ||
302 | LTC4245_VOLTAGE(in11_input, LTC4245_GPIOADC3); | ||
303 | 297 | ||
304 | /* Power Consumption (virtual) */ | 298 | /* Power Consumption (virtual) */ |
305 | LTC4245_POWER(power1_input, LTC4245_12VSENSE); | 299 | LTC4245_POWER(power1_input, LTC4245_12VSENSE); |
@@ -342,8 +336,6 @@ static struct attribute *ltc4245_attributes[] = { | |||
342 | &sensor_dev_attr_in8_min_alarm.dev_attr.attr, | 336 | &sensor_dev_attr_in8_min_alarm.dev_attr.attr, |
343 | 337 | ||
344 | &sensor_dev_attr_in9_input.dev_attr.attr, | 338 | &sensor_dev_attr_in9_input.dev_attr.attr, |
345 | &sensor_dev_attr_in10_input.dev_attr.attr, | ||
346 | &sensor_dev_attr_in11_input.dev_attr.attr, | ||
347 | 339 | ||
348 | &sensor_dev_attr_power1_input.dev_attr.attr, | 340 | &sensor_dev_attr_power1_input.dev_attr.attr, |
349 | &sensor_dev_attr_power2_input.dev_attr.attr, | 341 | &sensor_dev_attr_power2_input.dev_attr.attr, |
diff --git a/drivers/hwmon/tmp102.c b/drivers/hwmon/tmp102.c new file mode 100644 index 000000000000..8013895a1faf --- /dev/null +++ b/drivers/hwmon/tmp102.c | |||
@@ -0,0 +1,321 @@ | |||
1 | /* Texas Instruments TMP102 SMBus temperature sensor driver | ||
2 | * | ||
3 | * Copyright (C) 2010 Steven King <sfking@fdwdc.com> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | */ | ||
19 | |||
20 | #include <linux/module.h> | ||
21 | #include <linux/init.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/i2c.h> | ||
24 | #include <linux/hwmon.h> | ||
25 | #include <linux/hwmon-sysfs.h> | ||
26 | #include <linux/err.h> | ||
27 | #include <linux/mutex.h> | ||
28 | #include <linux/device.h> | ||
29 | |||
30 | #define DRIVER_NAME "tmp102" | ||
31 | |||
32 | #define TMP102_TEMP_REG 0x00 | ||
33 | #define TMP102_CONF_REG 0x01 | ||
34 | /* note: these bit definitions are byte swapped */ | ||
35 | #define TMP102_CONF_SD 0x0100 | ||
36 | #define TMP102_CONF_TM 0x0200 | ||
37 | #define TMP102_CONF_POL 0x0400 | ||
38 | #define TMP102_CONF_F0 0x0800 | ||
39 | #define TMP102_CONF_F1 0x1000 | ||
40 | #define TMP102_CONF_R0 0x2000 | ||
41 | #define TMP102_CONF_R1 0x4000 | ||
42 | #define TMP102_CONF_OS 0x8000 | ||
43 | #define TMP102_CONF_EM 0x0010 | ||
44 | #define TMP102_CONF_AL 0x0020 | ||
45 | #define TMP102_CONF_CR0 0x0040 | ||
46 | #define TMP102_CONF_CR1 0x0080 | ||
47 | #define TMP102_TLOW_REG 0x02 | ||
48 | #define TMP102_THIGH_REG 0x03 | ||
49 | |||
50 | struct tmp102 { | ||
51 | struct device *hwmon_dev; | ||
52 | struct mutex lock; | ||
53 | u16 config_orig; | ||
54 | unsigned long last_update; | ||
55 | int temp[3]; | ||
56 | }; | ||
57 | |||
58 | /* SMBus specifies low byte first, but the TMP102 returns high byte first, | ||
59 | * so we have to swab16 the values */ | ||
60 | static inline int tmp102_read_reg(struct i2c_client *client, u8 reg) | ||
61 | { | ||
62 | int result = i2c_smbus_read_word_data(client, reg); | ||
63 | return result < 0 ? result : swab16(result); | ||
64 | } | ||
65 | |||
66 | static inline int tmp102_write_reg(struct i2c_client *client, u8 reg, u16 val) | ||
67 | { | ||
68 | return i2c_smbus_write_word_data(client, reg, swab16(val)); | ||
69 | } | ||
70 | |||
71 | /* convert left adjusted 13-bit TMP102 register value to milliCelsius */ | ||
72 | static inline int tmp102_reg_to_mC(s16 val) | ||
73 | { | ||
74 | return ((val & ~0x01) * 1000) / 128; | ||
75 | } | ||
76 | |||
77 | /* convert milliCelsius to left adjusted 13-bit TMP102 register value */ | ||
78 | static inline u16 tmp102_mC_to_reg(int val) | ||
79 | { | ||
80 | return (val * 128) / 1000; | ||
81 | } | ||
82 | |||
83 | static const u8 tmp102_reg[] = { | ||
84 | TMP102_TEMP_REG, | ||
85 | TMP102_TLOW_REG, | ||
86 | TMP102_THIGH_REG, | ||
87 | }; | ||
88 | |||
89 | static struct tmp102 *tmp102_update_device(struct i2c_client *client) | ||
90 | { | ||
91 | struct tmp102 *tmp102 = i2c_get_clientdata(client); | ||
92 | |||
93 | mutex_lock(&tmp102->lock); | ||
94 | if (time_after(jiffies, tmp102->last_update + HZ / 3)) { | ||
95 | int i; | ||
96 | for (i = 0; i < ARRAY_SIZE(tmp102->temp); ++i) { | ||
97 | int status = tmp102_read_reg(client, tmp102_reg[i]); | ||
98 | if (status > -1) | ||
99 | tmp102->temp[i] = tmp102_reg_to_mC(status); | ||
100 | } | ||
101 | tmp102->last_update = jiffies; | ||
102 | } | ||
103 | mutex_unlock(&tmp102->lock); | ||
104 | return tmp102; | ||
105 | } | ||
106 | |||
107 | static ssize_t tmp102_show_temp(struct device *dev, | ||
108 | struct device_attribute *attr, | ||
109 | char *buf) | ||
110 | { | ||
111 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); | ||
112 | struct tmp102 *tmp102 = tmp102_update_device(to_i2c_client(dev)); | ||
113 | |||
114 | return sprintf(buf, "%d\n", tmp102->temp[sda->index]); | ||
115 | } | ||
116 | |||
117 | static ssize_t tmp102_set_temp(struct device *dev, | ||
118 | struct device_attribute *attr, | ||
119 | const char *buf, size_t count) | ||
120 | { | ||
121 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); | ||
122 | struct i2c_client *client = to_i2c_client(dev); | ||
123 | struct tmp102 *tmp102 = i2c_get_clientdata(client); | ||
124 | long val; | ||
125 | int status; | ||
126 | |||
127 | if (strict_strtol(buf, 10, &val) < 0) | ||
128 | return -EINVAL; | ||
129 | val = SENSORS_LIMIT(val, -256000, 255000); | ||
130 | |||
131 | mutex_lock(&tmp102->lock); | ||
132 | tmp102->temp[sda->index] = val; | ||
133 | status = tmp102_write_reg(client, tmp102_reg[sda->index], | ||
134 | tmp102_mC_to_reg(val)); | ||
135 | mutex_unlock(&tmp102->lock); | ||
136 | return status ? : count; | ||
137 | } | ||
138 | |||
139 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, tmp102_show_temp, NULL , 0); | ||
140 | |||
141 | static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, tmp102_show_temp, | ||
142 | tmp102_set_temp, 1); | ||
143 | |||
144 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, tmp102_show_temp, | ||
145 | tmp102_set_temp, 2); | ||
146 | |||
147 | static struct attribute *tmp102_attributes[] = { | ||
148 | &sensor_dev_attr_temp1_input.dev_attr.attr, | ||
149 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, | ||
150 | &sensor_dev_attr_temp1_max.dev_attr.attr, | ||
151 | NULL | ||
152 | }; | ||
153 | |||
154 | static const struct attribute_group tmp102_attr_group = { | ||
155 | .attrs = tmp102_attributes, | ||
156 | }; | ||
157 | |||
158 | #define TMP102_CONFIG (TMP102_CONF_TM | TMP102_CONF_EM | TMP102_CONF_CR1) | ||
159 | #define TMP102_CONFIG_RD_ONLY (TMP102_CONF_R0 | TMP102_CONF_R1 | TMP102_CONF_AL) | ||
160 | |||
161 | static int __devinit tmp102_probe(struct i2c_client *client, | ||
162 | const struct i2c_device_id *id) | ||
163 | { | ||
164 | struct tmp102 *tmp102; | ||
165 | int status; | ||
166 | |||
167 | if (!i2c_check_functionality(client->adapter, | ||
168 | I2C_FUNC_SMBUS_WORD_DATA)) { | ||
169 | dev_err(&client->dev, "adapter doesnt support SMBus word " | ||
170 | "transactions\n"); | ||
171 | return -ENODEV; | ||
172 | } | ||
173 | |||
174 | tmp102 = kzalloc(sizeof(*tmp102), GFP_KERNEL); | ||
175 | if (!tmp102) { | ||
176 | dev_dbg(&client->dev, "kzalloc failed\n"); | ||
177 | return -ENOMEM; | ||
178 | } | ||
179 | i2c_set_clientdata(client, tmp102); | ||
180 | |||
181 | status = tmp102_read_reg(client, TMP102_CONF_REG); | ||
182 | if (status < 0) { | ||
183 | dev_err(&client->dev, "error reading config register\n"); | ||
184 | goto fail_free; | ||
185 | } | ||
186 | tmp102->config_orig = status; | ||
187 | status = tmp102_write_reg(client, TMP102_CONF_REG, TMP102_CONFIG); | ||
188 | if (status < 0) { | ||
189 | dev_err(&client->dev, "error writing config register\n"); | ||
190 | goto fail_restore_config; | ||
191 | } | ||
192 | status = tmp102_read_reg(client, TMP102_CONF_REG); | ||
193 | if (status < 0) { | ||
194 | dev_err(&client->dev, "error reading config register\n"); | ||
195 | goto fail_restore_config; | ||
196 | } | ||
197 | status &= ~TMP102_CONFIG_RD_ONLY; | ||
198 | if (status != TMP102_CONFIG) { | ||
199 | dev_err(&client->dev, "config settings did not stick\n"); | ||
200 | status = -ENODEV; | ||
201 | goto fail_restore_config; | ||
202 | } | ||
203 | tmp102->last_update = jiffies - HZ; | ||
204 | mutex_init(&tmp102->lock); | ||
205 | |||
206 | status = sysfs_create_group(&client->dev.kobj, &tmp102_attr_group); | ||
207 | if (status) { | ||
208 | dev_dbg(&client->dev, "could not create sysfs files\n"); | ||
209 | goto fail_restore_config; | ||
210 | } | ||
211 | tmp102->hwmon_dev = hwmon_device_register(&client->dev); | ||
212 | if (IS_ERR(tmp102->hwmon_dev)) { | ||
213 | dev_dbg(&client->dev, "unable to register hwmon device\n"); | ||
214 | status = PTR_ERR(tmp102->hwmon_dev); | ||
215 | goto fail_remove_sysfs; | ||
216 | } | ||
217 | |||
218 | dev_info(&client->dev, "initialized\n"); | ||
219 | |||
220 | return 0; | ||
221 | |||
222 | fail_remove_sysfs: | ||
223 | sysfs_remove_group(&client->dev.kobj, &tmp102_attr_group); | ||
224 | fail_restore_config: | ||
225 | tmp102_write_reg(client, TMP102_CONF_REG, tmp102->config_orig); | ||
226 | fail_free: | ||
227 | i2c_set_clientdata(client, NULL); | ||
228 | kfree(tmp102); | ||
229 | |||
230 | return status; | ||
231 | } | ||
232 | |||
233 | static int __devexit tmp102_remove(struct i2c_client *client) | ||
234 | { | ||
235 | struct tmp102 *tmp102 = i2c_get_clientdata(client); | ||
236 | |||
237 | hwmon_device_unregister(tmp102->hwmon_dev); | ||
238 | sysfs_remove_group(&client->dev.kobj, &tmp102_attr_group); | ||
239 | |||
240 | /* Stop monitoring if device was stopped originally */ | ||
241 | if (tmp102->config_orig & TMP102_CONF_SD) { | ||
242 | int config; | ||
243 | |||
244 | config = tmp102_read_reg(client, TMP102_CONF_REG); | ||
245 | if (config >= 0) | ||
246 | tmp102_write_reg(client, TMP102_CONF_REG, | ||
247 | config | TMP102_CONF_SD); | ||
248 | } | ||
249 | |||
250 | i2c_set_clientdata(client, NULL); | ||
251 | kfree(tmp102); | ||
252 | |||
253 | return 0; | ||
254 | } | ||
255 | |||
256 | #ifdef CONFIG_PM | ||
257 | static int tmp102_suspend(struct device *dev) | ||
258 | { | ||
259 | struct i2c_client *client = to_i2c_client(dev); | ||
260 | int config; | ||
261 | |||
262 | config = tmp102_read_reg(client, TMP102_CONF_REG); | ||
263 | if (config < 0) | ||
264 | return config; | ||
265 | |||
266 | config |= TMP102_CONF_SD; | ||
267 | return tmp102_write_reg(client, TMP102_CONF_REG, config); | ||
268 | } | ||
269 | |||
270 | static int tmp102_resume(struct device *dev) | ||
271 | { | ||
272 | struct i2c_client *client = to_i2c_client(dev); | ||
273 | int config; | ||
274 | |||
275 | config = tmp102_read_reg(client, TMP102_CONF_REG); | ||
276 | if (config < 0) | ||
277 | return config; | ||
278 | |||
279 | config &= ~TMP102_CONF_SD; | ||
280 | return tmp102_write_reg(client, TMP102_CONF_REG, config); | ||
281 | } | ||
282 | |||
283 | static const struct dev_pm_ops tmp102_dev_pm_ops = { | ||
284 | .suspend = tmp102_suspend, | ||
285 | .resume = tmp102_resume, | ||
286 | }; | ||
287 | |||
288 | #define TMP102_DEV_PM_OPS (&tmp102_dev_pm_ops) | ||
289 | #else | ||
290 | #define TMP102_DEV_PM_OPS NULL | ||
291 | #endif /* CONFIG_PM */ | ||
292 | |||
293 | static const struct i2c_device_id tmp102_id[] = { | ||
294 | { "tmp102", 0 }, | ||
295 | { } | ||
296 | }; | ||
297 | MODULE_DEVICE_TABLE(i2c, tmp102_id); | ||
298 | |||
299 | static struct i2c_driver tmp102_driver = { | ||
300 | .driver.name = DRIVER_NAME, | ||
301 | .driver.pm = TMP102_DEV_PM_OPS, | ||
302 | .probe = tmp102_probe, | ||
303 | .remove = __devexit_p(tmp102_remove), | ||
304 | .id_table = tmp102_id, | ||
305 | }; | ||
306 | |||
307 | static int __init tmp102_init(void) | ||
308 | { | ||
309 | return i2c_add_driver(&tmp102_driver); | ||
310 | } | ||
311 | module_init(tmp102_init); | ||
312 | |||
313 | static void __exit tmp102_exit(void) | ||
314 | { | ||
315 | i2c_del_driver(&tmp102_driver); | ||
316 | } | ||
317 | module_exit(tmp102_exit); | ||
318 | |||
319 | MODULE_AUTHOR("Steven King <sfking@fdwdc.com>"); | ||
320 | MODULE_DESCRIPTION("Texas Instruments TMP102 temperature sensor driver"); | ||
321 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c index d14a1af9f550..ad8d535235c5 100644 --- a/drivers/hwmon/tmp401.c +++ b/drivers/hwmon/tmp401.c | |||
@@ -92,17 +92,6 @@ static const u8 TMP411_TEMP_HIGHEST_LSB[2] = { 0x33, 0x37 }; | |||
92 | #define TMP411_DEVICE_ID 0x12 | 92 | #define TMP411_DEVICE_ID 0x12 |
93 | 93 | ||
94 | /* | 94 | /* |
95 | * Functions declarations | ||
96 | */ | ||
97 | |||
98 | static int tmp401_probe(struct i2c_client *client, | ||
99 | const struct i2c_device_id *id); | ||
100 | static int tmp401_detect(struct i2c_client *client, | ||
101 | struct i2c_board_info *info); | ||
102 | static int tmp401_remove(struct i2c_client *client); | ||
103 | static struct tmp401_data *tmp401_update_device(struct device *dev); | ||
104 | |||
105 | /* | ||
106 | * Driver data (common to all clients) | 95 | * Driver data (common to all clients) |
107 | */ | 96 | */ |
108 | 97 | ||
@@ -113,18 +102,6 @@ static const struct i2c_device_id tmp401_id[] = { | |||
113 | }; | 102 | }; |
114 | MODULE_DEVICE_TABLE(i2c, tmp401_id); | 103 | MODULE_DEVICE_TABLE(i2c, tmp401_id); |
115 | 104 | ||
116 | static struct i2c_driver tmp401_driver = { | ||
117 | .class = I2C_CLASS_HWMON, | ||
118 | .driver = { | ||
119 | .name = "tmp401", | ||
120 | }, | ||
121 | .probe = tmp401_probe, | ||
122 | .remove = tmp401_remove, | ||
123 | .id_table = tmp401_id, | ||
124 | .detect = tmp401_detect, | ||
125 | .address_list = normal_i2c, | ||
126 | }; | ||
127 | |||
128 | /* | 105 | /* |
129 | * Client data (each client gets its own) | 106 | * Client data (each client gets its own) |
130 | */ | 107 | */ |
@@ -194,6 +171,71 @@ static u8 tmp401_crit_temp_to_register(long temp, u8 config) | |||
194 | return (temp + 500) / 1000; | 171 | return (temp + 500) / 1000; |
195 | } | 172 | } |
196 | 173 | ||
174 | static struct tmp401_data *tmp401_update_device_reg16( | ||
175 | struct i2c_client *client, struct tmp401_data *data) | ||
176 | { | ||
177 | int i; | ||
178 | |||
179 | for (i = 0; i < 2; i++) { | ||
180 | /* | ||
181 | * High byte must be read first immediately followed | ||
182 | * by the low byte | ||
183 | */ | ||
184 | data->temp[i] = i2c_smbus_read_byte_data(client, | ||
185 | TMP401_TEMP_MSB[i]) << 8; | ||
186 | data->temp[i] |= i2c_smbus_read_byte_data(client, | ||
187 | TMP401_TEMP_LSB[i]); | ||
188 | data->temp_low[i] = i2c_smbus_read_byte_data(client, | ||
189 | TMP401_TEMP_LOW_LIMIT_MSB_READ[i]) << 8; | ||
190 | data->temp_low[i] |= i2c_smbus_read_byte_data(client, | ||
191 | TMP401_TEMP_LOW_LIMIT_LSB[i]); | ||
192 | data->temp_high[i] = i2c_smbus_read_byte_data(client, | ||
193 | TMP401_TEMP_HIGH_LIMIT_MSB_READ[i]) << 8; | ||
194 | data->temp_high[i] |= i2c_smbus_read_byte_data(client, | ||
195 | TMP401_TEMP_HIGH_LIMIT_LSB[i]); | ||
196 | data->temp_crit[i] = i2c_smbus_read_byte_data(client, | ||
197 | TMP401_TEMP_CRIT_LIMIT[i]); | ||
198 | |||
199 | if (data->kind == tmp411) { | ||
200 | data->temp_lowest[i] = i2c_smbus_read_byte_data(client, | ||
201 | TMP411_TEMP_LOWEST_MSB[i]) << 8; | ||
202 | data->temp_lowest[i] |= i2c_smbus_read_byte_data( | ||
203 | client, TMP411_TEMP_LOWEST_LSB[i]); | ||
204 | |||
205 | data->temp_highest[i] = i2c_smbus_read_byte_data( | ||
206 | client, TMP411_TEMP_HIGHEST_MSB[i]) << 8; | ||
207 | data->temp_highest[i] |= i2c_smbus_read_byte_data( | ||
208 | client, TMP411_TEMP_HIGHEST_LSB[i]); | ||
209 | } | ||
210 | } | ||
211 | return data; | ||
212 | } | ||
213 | |||
214 | static struct tmp401_data *tmp401_update_device(struct device *dev) | ||
215 | { | ||
216 | struct i2c_client *client = to_i2c_client(dev); | ||
217 | struct tmp401_data *data = i2c_get_clientdata(client); | ||
218 | |||
219 | mutex_lock(&data->update_lock); | ||
220 | |||
221 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { | ||
222 | data->status = i2c_smbus_read_byte_data(client, TMP401_STATUS); | ||
223 | data->config = i2c_smbus_read_byte_data(client, | ||
224 | TMP401_CONFIG_READ); | ||
225 | tmp401_update_device_reg16(client, data); | ||
226 | |||
227 | data->temp_crit_hyst = i2c_smbus_read_byte_data(client, | ||
228 | TMP401_TEMP_CRIT_HYST); | ||
229 | |||
230 | data->last_updated = jiffies; | ||
231 | data->valid = 1; | ||
232 | } | ||
233 | |||
234 | mutex_unlock(&data->update_lock); | ||
235 | |||
236 | return data; | ||
237 | } | ||
238 | |||
197 | static ssize_t show_temp_value(struct device *dev, | 239 | static ssize_t show_temp_value(struct device *dev, |
198 | struct device_attribute *devattr, char *buf) | 240 | struct device_attribute *devattr, char *buf) |
199 | { | 241 | { |
@@ -420,30 +462,36 @@ static ssize_t reset_temp_history(struct device *dev, | |||
420 | } | 462 | } |
421 | 463 | ||
422 | static struct sensor_device_attribute tmp401_attr[] = { | 464 | static struct sensor_device_attribute tmp401_attr[] = { |
423 | SENSOR_ATTR(temp1_input, 0444, show_temp_value, NULL, 0), | 465 | SENSOR_ATTR(temp1_input, S_IRUGO, show_temp_value, NULL, 0), |
424 | SENSOR_ATTR(temp1_min, 0644, show_temp_min, store_temp_min, 0), | 466 | SENSOR_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min, |
425 | SENSOR_ATTR(temp1_max, 0644, show_temp_max, store_temp_max, 0), | 467 | store_temp_min, 0), |
426 | SENSOR_ATTR(temp1_crit, 0644, show_temp_crit, store_temp_crit, 0), | 468 | SENSOR_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, |
427 | SENSOR_ATTR(temp1_crit_hyst, 0644, show_temp_crit_hyst, | 469 | store_temp_max, 0), |
470 | SENSOR_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp_crit, | ||
471 | store_temp_crit, 0), | ||
472 | SENSOR_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp_crit_hyst, | ||
428 | store_temp_crit_hyst, 0), | 473 | store_temp_crit_hyst, 0), |
429 | SENSOR_ATTR(temp1_min_alarm, 0444, show_status, NULL, | 474 | SENSOR_ATTR(temp1_min_alarm, S_IRUGO, show_status, NULL, |
430 | TMP401_STATUS_LOCAL_LOW), | 475 | TMP401_STATUS_LOCAL_LOW), |
431 | SENSOR_ATTR(temp1_max_alarm, 0444, show_status, NULL, | 476 | SENSOR_ATTR(temp1_max_alarm, S_IRUGO, show_status, NULL, |
432 | TMP401_STATUS_LOCAL_HIGH), | 477 | TMP401_STATUS_LOCAL_HIGH), |
433 | SENSOR_ATTR(temp1_crit_alarm, 0444, show_status, NULL, | 478 | SENSOR_ATTR(temp1_crit_alarm, S_IRUGO, show_status, NULL, |
434 | TMP401_STATUS_LOCAL_CRIT), | 479 | TMP401_STATUS_LOCAL_CRIT), |
435 | SENSOR_ATTR(temp2_input, 0444, show_temp_value, NULL, 1), | 480 | SENSOR_ATTR(temp2_input, S_IRUGO, show_temp_value, NULL, 1), |
436 | SENSOR_ATTR(temp2_min, 0644, show_temp_min, store_temp_min, 1), | 481 | SENSOR_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min, |
437 | SENSOR_ATTR(temp2_max, 0644, show_temp_max, store_temp_max, 1), | 482 | store_temp_min, 1), |
438 | SENSOR_ATTR(temp2_crit, 0644, show_temp_crit, store_temp_crit, 1), | 483 | SENSOR_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, |
439 | SENSOR_ATTR(temp2_crit_hyst, 0444, show_temp_crit_hyst, NULL, 1), | 484 | store_temp_max, 1), |
440 | SENSOR_ATTR(temp2_fault, 0444, show_status, NULL, | 485 | SENSOR_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp_crit, |
486 | store_temp_crit, 1), | ||
487 | SENSOR_ATTR(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL, 1), | ||
488 | SENSOR_ATTR(temp2_fault, S_IRUGO, show_status, NULL, | ||
441 | TMP401_STATUS_REMOTE_OPEN), | 489 | TMP401_STATUS_REMOTE_OPEN), |
442 | SENSOR_ATTR(temp2_min_alarm, 0444, show_status, NULL, | 490 | SENSOR_ATTR(temp2_min_alarm, S_IRUGO, show_status, NULL, |
443 | TMP401_STATUS_REMOTE_LOW), | 491 | TMP401_STATUS_REMOTE_LOW), |
444 | SENSOR_ATTR(temp2_max_alarm, 0444, show_status, NULL, | 492 | SENSOR_ATTR(temp2_max_alarm, S_IRUGO, show_status, NULL, |
445 | TMP401_STATUS_REMOTE_HIGH), | 493 | TMP401_STATUS_REMOTE_HIGH), |
446 | SENSOR_ATTR(temp2_crit_alarm, 0444, show_status, NULL, | 494 | SENSOR_ATTR(temp2_crit_alarm, S_IRUGO, show_status, NULL, |
447 | TMP401_STATUS_REMOTE_CRIT), | 495 | TMP401_STATUS_REMOTE_CRIT), |
448 | }; | 496 | }; |
449 | 497 | ||
@@ -455,11 +503,11 @@ static struct sensor_device_attribute tmp401_attr[] = { | |||
455 | * and remote channels. | 503 | * and remote channels. |
456 | */ | 504 | */ |
457 | static struct sensor_device_attribute tmp411_attr[] = { | 505 | static struct sensor_device_attribute tmp411_attr[] = { |
458 | SENSOR_ATTR(temp1_highest, 0444, show_temp_highest, NULL, 0), | 506 | SENSOR_ATTR(temp1_highest, S_IRUGO, show_temp_highest, NULL, 0), |
459 | SENSOR_ATTR(temp1_lowest, 0444, show_temp_lowest, NULL, 0), | 507 | SENSOR_ATTR(temp1_lowest, S_IRUGO, show_temp_lowest, NULL, 0), |
460 | SENSOR_ATTR(temp2_highest, 0444, show_temp_highest, NULL, 1), | 508 | SENSOR_ATTR(temp2_highest, S_IRUGO, show_temp_highest, NULL, 1), |
461 | SENSOR_ATTR(temp2_lowest, 0444, show_temp_lowest, NULL, 1), | 509 | SENSOR_ATTR(temp2_lowest, S_IRUGO, show_temp_lowest, NULL, 1), |
462 | SENSOR_ATTR(temp_reset_history, 0200, NULL, reset_temp_history, 0), | 510 | SENSOR_ATTR(temp_reset_history, S_IWUSR, NULL, reset_temp_history, 0), |
463 | }; | 511 | }; |
464 | 512 | ||
465 | /* | 513 | /* |
@@ -529,6 +577,27 @@ static int tmp401_detect(struct i2c_client *client, | |||
529 | return 0; | 577 | return 0; |
530 | } | 578 | } |
531 | 579 | ||
580 | static int tmp401_remove(struct i2c_client *client) | ||
581 | { | ||
582 | struct tmp401_data *data = i2c_get_clientdata(client); | ||
583 | int i; | ||
584 | |||
585 | if (data->hwmon_dev) | ||
586 | hwmon_device_unregister(data->hwmon_dev); | ||
587 | |||
588 | for (i = 0; i < ARRAY_SIZE(tmp401_attr); i++) | ||
589 | device_remove_file(&client->dev, &tmp401_attr[i].dev_attr); | ||
590 | |||
591 | if (data->kind == tmp411) { | ||
592 | for (i = 0; i < ARRAY_SIZE(tmp411_attr); i++) | ||
593 | device_remove_file(&client->dev, | ||
594 | &tmp411_attr[i].dev_attr); | ||
595 | } | ||
596 | |||
597 | kfree(data); | ||
598 | return 0; | ||
599 | } | ||
600 | |||
532 | static int tmp401_probe(struct i2c_client *client, | 601 | static int tmp401_probe(struct i2c_client *client, |
533 | const struct i2c_device_id *id) | 602 | const struct i2c_device_id *id) |
534 | { | 603 | { |
@@ -581,91 +650,17 @@ exit_remove: | |||
581 | return err; | 650 | return err; |
582 | } | 651 | } |
583 | 652 | ||
584 | static int tmp401_remove(struct i2c_client *client) | 653 | static struct i2c_driver tmp401_driver = { |
585 | { | 654 | .class = I2C_CLASS_HWMON, |
586 | struct tmp401_data *data = i2c_get_clientdata(client); | 655 | .driver = { |
587 | int i; | 656 | .name = "tmp401", |
588 | 657 | }, | |
589 | if (data->hwmon_dev) | 658 | .probe = tmp401_probe, |
590 | hwmon_device_unregister(data->hwmon_dev); | 659 | .remove = tmp401_remove, |
591 | 660 | .id_table = tmp401_id, | |
592 | for (i = 0; i < ARRAY_SIZE(tmp401_attr); i++) | 661 | .detect = tmp401_detect, |
593 | device_remove_file(&client->dev, &tmp401_attr[i].dev_attr); | 662 | .address_list = normal_i2c, |
594 | 663 | }; | |
595 | if (data->kind == tmp411) { | ||
596 | for (i = 0; i < ARRAY_SIZE(tmp411_attr); i++) | ||
597 | device_remove_file(&client->dev, | ||
598 | &tmp411_attr[i].dev_attr); | ||
599 | } | ||
600 | |||
601 | kfree(data); | ||
602 | return 0; | ||
603 | } | ||
604 | |||
605 | static struct tmp401_data *tmp401_update_device_reg16( | ||
606 | struct i2c_client *client, struct tmp401_data *data) | ||
607 | { | ||
608 | int i; | ||
609 | |||
610 | for (i = 0; i < 2; i++) { | ||
611 | /* | ||
612 | * High byte must be read first immediately followed | ||
613 | * by the low byte | ||
614 | */ | ||
615 | data->temp[i] = i2c_smbus_read_byte_data(client, | ||
616 | TMP401_TEMP_MSB[i]) << 8; | ||
617 | data->temp[i] |= i2c_smbus_read_byte_data(client, | ||
618 | TMP401_TEMP_LSB[i]); | ||
619 | data->temp_low[i] = i2c_smbus_read_byte_data(client, | ||
620 | TMP401_TEMP_LOW_LIMIT_MSB_READ[i]) << 8; | ||
621 | data->temp_low[i] |= i2c_smbus_read_byte_data(client, | ||
622 | TMP401_TEMP_LOW_LIMIT_LSB[i]); | ||
623 | data->temp_high[i] = i2c_smbus_read_byte_data(client, | ||
624 | TMP401_TEMP_HIGH_LIMIT_MSB_READ[i]) << 8; | ||
625 | data->temp_high[i] |= i2c_smbus_read_byte_data(client, | ||
626 | TMP401_TEMP_HIGH_LIMIT_LSB[i]); | ||
627 | data->temp_crit[i] = i2c_smbus_read_byte_data(client, | ||
628 | TMP401_TEMP_CRIT_LIMIT[i]); | ||
629 | |||
630 | if (data->kind == tmp411) { | ||
631 | data->temp_lowest[i] = i2c_smbus_read_byte_data(client, | ||
632 | TMP411_TEMP_LOWEST_MSB[i]) << 8; | ||
633 | data->temp_lowest[i] |= i2c_smbus_read_byte_data( | ||
634 | client, TMP411_TEMP_LOWEST_LSB[i]); | ||
635 | |||
636 | data->temp_highest[i] = i2c_smbus_read_byte_data( | ||
637 | client, TMP411_TEMP_HIGHEST_MSB[i]) << 8; | ||
638 | data->temp_highest[i] |= i2c_smbus_read_byte_data( | ||
639 | client, TMP411_TEMP_HIGHEST_LSB[i]); | ||
640 | } | ||
641 | } | ||
642 | return data; | ||
643 | } | ||
644 | |||
645 | static struct tmp401_data *tmp401_update_device(struct device *dev) | ||
646 | { | ||
647 | struct i2c_client *client = to_i2c_client(dev); | ||
648 | struct tmp401_data *data = i2c_get_clientdata(client); | ||
649 | |||
650 | mutex_lock(&data->update_lock); | ||
651 | |||
652 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { | ||
653 | data->status = i2c_smbus_read_byte_data(client, TMP401_STATUS); | ||
654 | data->config = i2c_smbus_read_byte_data(client, | ||
655 | TMP401_CONFIG_READ); | ||
656 | tmp401_update_device_reg16(client, data); | ||
657 | |||
658 | data->temp_crit_hyst = i2c_smbus_read_byte_data(client, | ||
659 | TMP401_TEMP_CRIT_HYST); | ||
660 | |||
661 | data->last_updated = jiffies; | ||
662 | data->valid = 1; | ||
663 | } | ||
664 | |||
665 | mutex_unlock(&data->update_lock); | ||
666 | |||
667 | return data; | ||
668 | } | ||
669 | 664 | ||
670 | static int __init tmp401_init(void) | 665 | static int __init tmp401_init(void) |
671 | { | 666 | { |
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 505eb64c329c..f98d17a7108b 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig | |||
@@ -67,6 +67,16 @@ config LEDS_NET48XX | |||
67 | This option enables support for the Soekris net4801 and net4826 error | 67 | This option enables support for the Soekris net4801 and net4826 error |
68 | LED. | 68 | LED. |
69 | 69 | ||
70 | config LEDS_NET5501 | ||
71 | tristate "LED Support for Soekris net5501 series Error LED" | ||
72 | depends on LEDS_CLASS && LEDS_TRIGGERS | ||
73 | depends on LEDS_GPIO_PLATFORM && GPIO_CS5535 | ||
74 | select LEDS_TRIGGER_DEFAULT_ON | ||
75 | default n | ||
76 | help | ||
77 | Add support for the Soekris net5501 board (detection, error led | ||
78 | and GPIO). | ||
79 | |||
70 | config LEDS_FSG | 80 | config LEDS_FSG |
71 | tristate "LED Support for the Freecom FSG-3" | 81 | tristate "LED Support for the Freecom FSG-3" |
72 | depends on MACH_FSG | 82 | depends on MACH_FSG |
@@ -285,6 +295,13 @@ config LEDS_DELL_NETBOOKS | |||
285 | This adds support for the Latitude 2100 and similar | 295 | This adds support for the Latitude 2100 and similar |
286 | notebooks that have an external LED. | 296 | notebooks that have an external LED. |
287 | 297 | ||
298 | config LEDS_MC13783 | ||
299 | tristate "LED Support for MC13783 PMIC" | ||
300 | depends on MFD_MC13783 | ||
301 | help | ||
302 | This option enable support for on-chip LED drivers found | ||
303 | on Freescale Semiconductor MC13783 PMIC. | ||
304 | |||
288 | config LEDS_TRIGGERS | 305 | config LEDS_TRIGGERS |
289 | bool "LED Trigger support" | 306 | bool "LED Trigger support" |
290 | help | 307 | help |
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 0cd8b9957380..2493de499374 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile | |||
@@ -13,6 +13,7 @@ obj-$(CONFIG_LEDS_MIKROTIK_RB532) += leds-rb532.o | |||
13 | obj-$(CONFIG_LEDS_S3C24XX) += leds-s3c24xx.o | 13 | obj-$(CONFIG_LEDS_S3C24XX) += leds-s3c24xx.o |
14 | obj-$(CONFIG_LEDS_AMS_DELTA) += leds-ams-delta.o | 14 | obj-$(CONFIG_LEDS_AMS_DELTA) += leds-ams-delta.o |
15 | obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o | 15 | obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o |
16 | obj-$(CONFIG_LEDS_NET5501) += leds-net5501.o | ||
16 | obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o | 17 | obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o |
17 | obj-$(CONFIG_LEDS_ALIX2) += leds-alix2.o | 18 | obj-$(CONFIG_LEDS_ALIX2) += leds-alix2.o |
18 | obj-$(CONFIG_LEDS_H1940) += leds-h1940.o | 19 | obj-$(CONFIG_LEDS_H1940) += leds-h1940.o |
@@ -35,6 +36,7 @@ obj-$(CONFIG_LEDS_INTEL_SS4200) += leds-ss4200.o | |||
35 | obj-$(CONFIG_LEDS_LT3593) += leds-lt3593.o | 36 | obj-$(CONFIG_LEDS_LT3593) += leds-lt3593.o |
36 | obj-$(CONFIG_LEDS_ADP5520) += leds-adp5520.o | 37 | obj-$(CONFIG_LEDS_ADP5520) += leds-adp5520.o |
37 | obj-$(CONFIG_LEDS_DELL_NETBOOKS) += dell-led.o | 38 | obj-$(CONFIG_LEDS_DELL_NETBOOKS) += dell-led.o |
39 | obj-$(CONFIG_LEDS_MC13783) += leds-mc13783.o | ||
38 | 40 | ||
39 | # LED SPI Drivers | 41 | # LED SPI Drivers |
40 | obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o | 42 | obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o |
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 69e7d86a5143..260660076507 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c | |||
@@ -74,7 +74,7 @@ static ssize_t led_max_brightness_show(struct device *dev, | |||
74 | 74 | ||
75 | static struct device_attribute led_class_attrs[] = { | 75 | static struct device_attribute led_class_attrs[] = { |
76 | __ATTR(brightness, 0644, led_brightness_show, led_brightness_store), | 76 | __ATTR(brightness, 0644, led_brightness_show, led_brightness_store), |
77 | __ATTR(max_brightness, 0644, led_max_brightness_show, NULL), | 77 | __ATTR(max_brightness, 0444, led_max_brightness_show, NULL), |
78 | #ifdef CONFIG_LEDS_TRIGGERS | 78 | #ifdef CONFIG_LEDS_TRIGGERS |
79 | __ATTR(trigger, 0644, led_trigger_show, led_trigger_store), | 79 | __ATTR(trigger, 0644, led_trigger_show, led_trigger_store), |
80 | #endif | 80 | #endif |
diff --git a/drivers/leds/leds-88pm860x.c b/drivers/leds/leds-88pm860x.c index 16a60c06c96c..b7677106cff8 100644 --- a/drivers/leds/leds-88pm860x.c +++ b/drivers/leds/leds-88pm860x.c | |||
@@ -256,8 +256,10 @@ static int pm860x_led_probe(struct platform_device *pdev) | |||
256 | if (pdev->dev.parent->platform_data) { | 256 | if (pdev->dev.parent->platform_data) { |
257 | pm860x_pdata = pdev->dev.parent->platform_data; | 257 | pm860x_pdata = pdev->dev.parent->platform_data; |
258 | pdata = pm860x_pdata->led; | 258 | pdata = pm860x_pdata->led; |
259 | } else | 259 | } else { |
260 | pdata = NULL; | 260 | dev_err(&pdev->dev, "missing platform data\n"); |
261 | return -EINVAL; | ||
262 | } | ||
261 | 263 | ||
262 | data = kzalloc(sizeof(struct pm860x_led), GFP_KERNEL); | 264 | data = kzalloc(sizeof(struct pm860x_led), GFP_KERNEL); |
263 | if (data == NULL) | 265 | if (data == NULL) |
@@ -268,8 +270,11 @@ static int pm860x_led_probe(struct platform_device *pdev) | |||
268 | data->i2c = (chip->id == CHIP_PM8606) ? chip->client : chip->companion; | 270 | data->i2c = (chip->id == CHIP_PM8606) ? chip->client : chip->companion; |
269 | data->iset = pdata->iset; | 271 | data->iset = pdata->iset; |
270 | data->port = __check_device(pdata, data->name); | 272 | data->port = __check_device(pdata, data->name); |
271 | if (data->port < 0) | 273 | if (data->port < 0) { |
274 | dev_err(&pdev->dev, "check device failed\n"); | ||
275 | kfree(data); | ||
272 | return -EINVAL; | 276 | return -EINVAL; |
277 | } | ||
273 | 278 | ||
274 | data->current_brightness = 0; | 279 | data->current_brightness = 0; |
275 | data->cdev.name = data->name; | 280 | data->cdev.name = data->name; |
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index 6d94b0b9979c..26843dd6b859 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c | |||
@@ -26,7 +26,8 @@ struct gpio_led_data { | |||
26 | u8 new_level; | 26 | u8 new_level; |
27 | u8 can_sleep; | 27 | u8 can_sleep; |
28 | u8 active_low; | 28 | u8 active_low; |
29 | int (*platform_gpio_blink_set)(unsigned gpio, | 29 | u8 blinking; |
30 | int (*platform_gpio_blink_set)(unsigned gpio, int state, | ||
30 | unsigned long *delay_on, unsigned long *delay_off); | 31 | unsigned long *delay_on, unsigned long *delay_off); |
31 | }; | 32 | }; |
32 | 33 | ||
@@ -35,7 +36,13 @@ static void gpio_led_work(struct work_struct *work) | |||
35 | struct gpio_led_data *led_dat = | 36 | struct gpio_led_data *led_dat = |
36 | container_of(work, struct gpio_led_data, work); | 37 | container_of(work, struct gpio_led_data, work); |
37 | 38 | ||
38 | gpio_set_value_cansleep(led_dat->gpio, led_dat->new_level); | 39 | if (led_dat->blinking) { |
40 | led_dat->platform_gpio_blink_set(led_dat->gpio, | ||
41 | led_dat->new_level, | ||
42 | NULL, NULL); | ||
43 | led_dat->blinking = 0; | ||
44 | } else | ||
45 | gpio_set_value_cansleep(led_dat->gpio, led_dat->new_level); | ||
39 | } | 46 | } |
40 | 47 | ||
41 | static void gpio_led_set(struct led_classdev *led_cdev, | 48 | static void gpio_led_set(struct led_classdev *led_cdev, |
@@ -60,8 +67,14 @@ static void gpio_led_set(struct led_classdev *led_cdev, | |||
60 | if (led_dat->can_sleep) { | 67 | if (led_dat->can_sleep) { |
61 | led_dat->new_level = level; | 68 | led_dat->new_level = level; |
62 | schedule_work(&led_dat->work); | 69 | schedule_work(&led_dat->work); |
63 | } else | 70 | } else { |
64 | gpio_set_value(led_dat->gpio, level); | 71 | if (led_dat->blinking) { |
72 | led_dat->platform_gpio_blink_set(led_dat->gpio, level, | ||
73 | NULL, NULL); | ||
74 | led_dat->blinking = 0; | ||
75 | } else | ||
76 | gpio_set_value(led_dat->gpio, level); | ||
77 | } | ||
65 | } | 78 | } |
66 | 79 | ||
67 | static int gpio_blink_set(struct led_classdev *led_cdev, | 80 | static int gpio_blink_set(struct led_classdev *led_cdev, |
@@ -70,12 +83,14 @@ static int gpio_blink_set(struct led_classdev *led_cdev, | |||
70 | struct gpio_led_data *led_dat = | 83 | struct gpio_led_data *led_dat = |
71 | container_of(led_cdev, struct gpio_led_data, cdev); | 84 | container_of(led_cdev, struct gpio_led_data, cdev); |
72 | 85 | ||
73 | return led_dat->platform_gpio_blink_set(led_dat->gpio, delay_on, delay_off); | 86 | led_dat->blinking = 1; |
87 | return led_dat->platform_gpio_blink_set(led_dat->gpio, GPIO_LED_BLINK, | ||
88 | delay_on, delay_off); | ||
74 | } | 89 | } |
75 | 90 | ||
76 | static int __devinit create_gpio_led(const struct gpio_led *template, | 91 | static int __devinit create_gpio_led(const struct gpio_led *template, |
77 | struct gpio_led_data *led_dat, struct device *parent, | 92 | struct gpio_led_data *led_dat, struct device *parent, |
78 | int (*blink_set)(unsigned, unsigned long *, unsigned long *)) | 93 | int (*blink_set)(unsigned, int, unsigned long *, unsigned long *)) |
79 | { | 94 | { |
80 | int ret, state; | 95 | int ret, state; |
81 | 96 | ||
@@ -97,6 +112,7 @@ static int __devinit create_gpio_led(const struct gpio_led *template, | |||
97 | led_dat->gpio = template->gpio; | 112 | led_dat->gpio = template->gpio; |
98 | led_dat->can_sleep = gpio_cansleep(template->gpio); | 113 | led_dat->can_sleep = gpio_cansleep(template->gpio); |
99 | led_dat->active_low = template->active_low; | 114 | led_dat->active_low = template->active_low; |
115 | led_dat->blinking = 0; | ||
100 | if (blink_set) { | 116 | if (blink_set) { |
101 | led_dat->platform_gpio_blink_set = blink_set; | 117 | led_dat->platform_gpio_blink_set = blink_set; |
102 | led_dat->cdev.blink_set = gpio_blink_set; | 118 | led_dat->cdev.blink_set = gpio_blink_set; |
@@ -113,7 +129,7 @@ static int __devinit create_gpio_led(const struct gpio_led *template, | |||
113 | ret = gpio_direction_output(led_dat->gpio, led_dat->active_low ^ state); | 129 | ret = gpio_direction_output(led_dat->gpio, led_dat->active_low ^ state); |
114 | if (ret < 0) | 130 | if (ret < 0) |
115 | goto err; | 131 | goto err; |
116 | 132 | ||
117 | INIT_WORK(&led_dat->work, gpio_led_work); | 133 | INIT_WORK(&led_dat->work, gpio_led_work); |
118 | 134 | ||
119 | ret = led_classdev_register(parent, &led_dat->cdev); | 135 | ret = led_classdev_register(parent, &led_dat->cdev); |
@@ -234,6 +250,7 @@ static int __devinit of_gpio_leds_probe(struct of_device *ofdev, | |||
234 | led.gpio = of_get_gpio_flags(child, 0, &flags); | 250 | led.gpio = of_get_gpio_flags(child, 0, &flags); |
235 | led.active_low = flags & OF_GPIO_ACTIVE_LOW; | 251 | led.active_low = flags & OF_GPIO_ACTIVE_LOW; |
236 | led.name = of_get_property(child, "label", NULL) ? : child->name; | 252 | led.name = of_get_property(child, "label", NULL) ? : child->name; |
253 | led.blinking = 0; | ||
237 | led.default_trigger = | 254 | led.default_trigger = |
238 | of_get_property(child, "linux,default-trigger", NULL); | 255 | of_get_property(child, "linux,default-trigger", NULL); |
239 | state = of_get_property(child, "default-state", NULL); | 256 | state = of_get_property(child, "default-state", NULL); |
diff --git a/drivers/leds/leds-lp3944.c b/drivers/leds/leds-lp3944.c index 8d5ecceba181..932a58da76c4 100644 --- a/drivers/leds/leds-lp3944.c +++ b/drivers/leds/leds-lp3944.c | |||
@@ -379,6 +379,7 @@ static int __devinit lp3944_probe(struct i2c_client *client, | |||
379 | { | 379 | { |
380 | struct lp3944_platform_data *lp3944_pdata = client->dev.platform_data; | 380 | struct lp3944_platform_data *lp3944_pdata = client->dev.platform_data; |
381 | struct lp3944_data *data; | 381 | struct lp3944_data *data; |
382 | int err; | ||
382 | 383 | ||
383 | if (lp3944_pdata == NULL) { | 384 | if (lp3944_pdata == NULL) { |
384 | dev_err(&client->dev, "no platform data\n"); | 385 | dev_err(&client->dev, "no platform data\n"); |
@@ -401,9 +402,13 @@ static int __devinit lp3944_probe(struct i2c_client *client, | |||
401 | 402 | ||
402 | mutex_init(&data->lock); | 403 | mutex_init(&data->lock); |
403 | 404 | ||
404 | dev_info(&client->dev, "lp3944 enabled\n"); | 405 | err = lp3944_configure(client, data, lp3944_pdata); |
406 | if (err < 0) { | ||
407 | kfree(data); | ||
408 | return err; | ||
409 | } | ||
405 | 410 | ||
406 | lp3944_configure(client, data, lp3944_pdata); | 411 | dev_info(&client->dev, "lp3944 enabled\n"); |
407 | return 0; | 412 | return 0; |
408 | } | 413 | } |
409 | 414 | ||
diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c new file mode 100644 index 000000000000..f05bb08d0f09 --- /dev/null +++ b/drivers/leds/leds-mc13783.c | |||
@@ -0,0 +1,403 @@ | |||
1 | /* | ||
2 | * LEDs driver for Freescale MC13783 | ||
3 | * | ||
4 | * Copyright (C) 2010 Philippe Rétornaz | ||
5 | * | ||
6 | * Based on leds-da903x: | ||
7 | * Copyright (C) 2008 Compulab, Ltd. | ||
8 | * Mike Rapoport <mike@compulab.co.il> | ||
9 | * | ||
10 | * Copyright (C) 2006-2008 Marvell International Ltd. | ||
11 | * Eric Miao <eric.miao@marvell.com> | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License version 2 as | ||
15 | * published by the Free Software Foundation. | ||
16 | */ | ||
17 | |||
18 | #include <linux/module.h> | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | #include <linux/leds.h> | ||
23 | #include <linux/workqueue.h> | ||
24 | #include <linux/mfd/mc13783.h> | ||
25 | #include <linux/slab.h> | ||
26 | |||
27 | struct mc13783_led { | ||
28 | struct led_classdev cdev; | ||
29 | struct work_struct work; | ||
30 | struct mc13783 *master; | ||
31 | enum led_brightness new_brightness; | ||
32 | int id; | ||
33 | }; | ||
34 | |||
35 | #define MC13783_REG_LED_CONTROL_0 51 | ||
36 | #define MC13783_LED_C0_ENABLE_BIT (1 << 0) | ||
37 | #define MC13783_LED_C0_TRIODE_MD_BIT (1 << 7) | ||
38 | #define MC13783_LED_C0_TRIODE_AD_BIT (1 << 8) | ||
39 | #define MC13783_LED_C0_TRIODE_KP_BIT (1 << 9) | ||
40 | #define MC13783_LED_C0_BOOST_BIT (1 << 10) | ||
41 | #define MC13783_LED_C0_ABMODE_MASK 0x7 | ||
42 | #define MC13783_LED_C0_ABMODE 11 | ||
43 | #define MC13783_LED_C0_ABREF_MASK 0x3 | ||
44 | #define MC13783_LED_C0_ABREF 14 | ||
45 | |||
46 | #define MC13783_REG_LED_CONTROL_1 52 | ||
47 | #define MC13783_LED_C1_TC1HALF_BIT (1 << 18) | ||
48 | |||
49 | #define MC13783_REG_LED_CONTROL_2 53 | ||
50 | #define MC13783_LED_C2_BL_P_MASK 0xf | ||
51 | #define MC13783_LED_C2_MD_P 9 | ||
52 | #define MC13783_LED_C2_AD_P 13 | ||
53 | #define MC13783_LED_C2_KP_P 17 | ||
54 | #define MC13783_LED_C2_BL_C_MASK 0x7 | ||
55 | #define MC13783_LED_C2_MD_C 0 | ||
56 | #define MC13783_LED_C2_AD_C 3 | ||
57 | #define MC13783_LED_C2_KP_C 6 | ||
58 | |||
59 | #define MC13783_REG_LED_CONTROL_3 54 | ||
60 | #define MC13783_LED_C3_TC_P 6 | ||
61 | #define MC13783_LED_C3_TC_P_MASK 0x1f | ||
62 | |||
63 | #define MC13783_REG_LED_CONTROL_4 55 | ||
64 | #define MC13783_REG_LED_CONTROL_5 56 | ||
65 | |||
66 | #define MC13783_LED_Cx_PERIOD 21 | ||
67 | #define MC13783_LED_Cx_PERIOD_MASK 0x3 | ||
68 | #define MC13783_LED_Cx_SLEWLIM_BIT (1 << 23) | ||
69 | #define MC13783_LED_Cx_TRIODE_TC_BIT (1 << 23) | ||
70 | #define MC13783_LED_Cx_TC_C_MASK 0x3 | ||
71 | |||
72 | static void mc13783_led_work(struct work_struct *work) | ||
73 | { | ||
74 | struct mc13783_led *led = container_of(work, struct mc13783_led, work); | ||
75 | int reg = 0; | ||
76 | int mask = 0; | ||
77 | int value = 0; | ||
78 | int bank, off, shift; | ||
79 | |||
80 | switch (led->id) { | ||
81 | case MC13783_LED_MD: | ||
82 | reg = MC13783_REG_LED_CONTROL_2; | ||
83 | mask = MC13783_LED_C2_BL_P_MASK << MC13783_LED_C2_MD_P; | ||
84 | value = (led->new_brightness >> 4) << MC13783_LED_C2_MD_P; | ||
85 | break; | ||
86 | case MC13783_LED_AD: | ||
87 | reg = MC13783_REG_LED_CONTROL_2; | ||
88 | mask = MC13783_LED_C2_BL_P_MASK << MC13783_LED_C2_AD_P; | ||
89 | value = (led->new_brightness >> 4) << MC13783_LED_C2_AD_P; | ||
90 | break; | ||
91 | case MC13783_LED_KP: | ||
92 | reg = MC13783_REG_LED_CONTROL_2; | ||
93 | mask = MC13783_LED_C2_BL_P_MASK << MC13783_LED_C2_KP_P; | ||
94 | value = (led->new_brightness >> 4) << MC13783_LED_C2_KP_P; | ||
95 | break; | ||
96 | case MC13783_LED_R1: | ||
97 | case MC13783_LED_G1: | ||
98 | case MC13783_LED_B1: | ||
99 | case MC13783_LED_R2: | ||
100 | case MC13783_LED_G2: | ||
101 | case MC13783_LED_B2: | ||
102 | case MC13783_LED_R3: | ||
103 | case MC13783_LED_G3: | ||
104 | case MC13783_LED_B3: | ||
105 | off = led->id - MC13783_LED_R1; | ||
106 | bank = off/3; | ||
107 | reg = MC13783_REG_LED_CONTROL_3 + off/3; | ||
108 | shift = (off - bank * 3) * 5 + MC13783_LED_C3_TC_P; | ||
109 | value = (led->new_brightness >> 3) << shift; | ||
110 | mask = MC13783_LED_C3_TC_P_MASK << shift; | ||
111 | break; | ||
112 | } | ||
113 | |||
114 | mc13783_lock(led->master); | ||
115 | |||
116 | mc13783_reg_rmw(led->master, reg, mask, value); | ||
117 | |||
118 | mc13783_unlock(led->master); | ||
119 | } | ||
120 | |||
121 | static void mc13783_led_set(struct led_classdev *led_cdev, | ||
122 | enum led_brightness value) | ||
123 | { | ||
124 | struct mc13783_led *led; | ||
125 | |||
126 | led = container_of(led_cdev, struct mc13783_led, cdev); | ||
127 | led->new_brightness = value; | ||
128 | schedule_work(&led->work); | ||
129 | } | ||
130 | |||
131 | static int __devinit mc13783_led_setup(struct mc13783_led *led, int max_current) | ||
132 | { | ||
133 | int shift = 0; | ||
134 | int mask = 0; | ||
135 | int value = 0; | ||
136 | int reg = 0; | ||
137 | int ret, bank; | ||
138 | |||
139 | switch (led->id) { | ||
140 | case MC13783_LED_MD: | ||
141 | shift = MC13783_LED_C2_MD_C; | ||
142 | mask = MC13783_LED_C2_BL_C_MASK; | ||
143 | value = max_current & MC13783_LED_C2_BL_C_MASK; | ||
144 | reg = MC13783_REG_LED_CONTROL_2; | ||
145 | break; | ||
146 | case MC13783_LED_AD: | ||
147 | shift = MC13783_LED_C2_AD_C; | ||
148 | mask = MC13783_LED_C2_BL_C_MASK; | ||
149 | value = max_current & MC13783_LED_C2_BL_C_MASK; | ||
150 | reg = MC13783_REG_LED_CONTROL_2; | ||
151 | break; | ||
152 | case MC13783_LED_KP: | ||
153 | shift = MC13783_LED_C2_KP_C; | ||
154 | mask = MC13783_LED_C2_BL_C_MASK; | ||
155 | value = max_current & MC13783_LED_C2_BL_C_MASK; | ||
156 | reg = MC13783_REG_LED_CONTROL_2; | ||
157 | break; | ||
158 | case MC13783_LED_R1: | ||
159 | case MC13783_LED_G1: | ||
160 | case MC13783_LED_B1: | ||
161 | case MC13783_LED_R2: | ||
162 | case MC13783_LED_G2: | ||
163 | case MC13783_LED_B2: | ||
164 | case MC13783_LED_R3: | ||
165 | case MC13783_LED_G3: | ||
166 | case MC13783_LED_B3: | ||
167 | bank = (led->id - MC13783_LED_R1)/3; | ||
168 | reg = MC13783_REG_LED_CONTROL_3 + bank; | ||
169 | shift = ((led->id - MC13783_LED_R1) - bank * 3) * 2; | ||
170 | mask = MC13783_LED_Cx_TC_C_MASK; | ||
171 | value = max_current & MC13783_LED_Cx_TC_C_MASK; | ||
172 | break; | ||
173 | } | ||
174 | |||
175 | mc13783_lock(led->master); | ||
176 | |||
177 | ret = mc13783_reg_rmw(led->master, reg, mask << shift, | ||
178 | value << shift); | ||
179 | |||
180 | mc13783_unlock(led->master); | ||
181 | return ret; | ||
182 | } | ||
183 | |||
184 | static int __devinit mc13783_leds_prepare(struct platform_device *pdev) | ||
185 | { | ||
186 | struct mc13783_leds_platform_data *pdata = dev_get_platdata(&pdev->dev); | ||
187 | struct mc13783 *dev = dev_get_drvdata(pdev->dev.parent); | ||
188 | int ret = 0; | ||
189 | int reg = 0; | ||
190 | |||
191 | mc13783_lock(dev); | ||
192 | |||
193 | if (pdata->flags & MC13783_LED_TC1HALF) | ||
194 | reg |= MC13783_LED_C1_TC1HALF_BIT; | ||
195 | |||
196 | if (pdata->flags & MC13783_LED_SLEWLIMTC) | ||
197 | reg |= MC13783_LED_Cx_SLEWLIM_BIT; | ||
198 | |||
199 | ret = mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_1, reg); | ||
200 | if (ret) | ||
201 | goto out; | ||
202 | |||
203 | reg = (pdata->bl_period & MC13783_LED_Cx_PERIOD_MASK) << | ||
204 | MC13783_LED_Cx_PERIOD; | ||
205 | |||
206 | if (pdata->flags & MC13783_LED_SLEWLIMBL) | ||
207 | reg |= MC13783_LED_Cx_SLEWLIM_BIT; | ||
208 | |||
209 | ret = mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_2, reg); | ||
210 | if (ret) | ||
211 | goto out; | ||
212 | |||
213 | reg = (pdata->tc1_period & MC13783_LED_Cx_PERIOD_MASK) << | ||
214 | MC13783_LED_Cx_PERIOD; | ||
215 | |||
216 | if (pdata->flags & MC13783_LED_TRIODE_TC1) | ||
217 | reg |= MC13783_LED_Cx_TRIODE_TC_BIT; | ||
218 | |||
219 | ret = mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_3, reg); | ||
220 | if (ret) | ||
221 | goto out; | ||
222 | |||
223 | reg = (pdata->tc2_period & MC13783_LED_Cx_PERIOD_MASK) << | ||
224 | MC13783_LED_Cx_PERIOD; | ||
225 | |||
226 | if (pdata->flags & MC13783_LED_TRIODE_TC2) | ||
227 | reg |= MC13783_LED_Cx_TRIODE_TC_BIT; | ||
228 | |||
229 | ret = mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_4, reg); | ||
230 | if (ret) | ||
231 | goto out; | ||
232 | |||
233 | reg = (pdata->tc3_period & MC13783_LED_Cx_PERIOD_MASK) << | ||
234 | MC13783_LED_Cx_PERIOD; | ||
235 | |||
236 | if (pdata->flags & MC13783_LED_TRIODE_TC3) | ||
237 | reg |= MC13783_LED_Cx_TRIODE_TC_BIT;; | ||
238 | |||
239 | ret = mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_5, reg); | ||
240 | if (ret) | ||
241 | goto out; | ||
242 | |||
243 | reg = MC13783_LED_C0_ENABLE_BIT; | ||
244 | if (pdata->flags & MC13783_LED_TRIODE_MD) | ||
245 | reg |= MC13783_LED_C0_TRIODE_MD_BIT; | ||
246 | if (pdata->flags & MC13783_LED_TRIODE_AD) | ||
247 | reg |= MC13783_LED_C0_TRIODE_AD_BIT; | ||
248 | if (pdata->flags & MC13783_LED_TRIODE_KP) | ||
249 | reg |= MC13783_LED_C0_TRIODE_KP_BIT; | ||
250 | if (pdata->flags & MC13783_LED_BOOST_EN) | ||
251 | reg |= MC13783_LED_C0_BOOST_BIT; | ||
252 | |||
253 | reg |= (pdata->abmode & MC13783_LED_C0_ABMODE_MASK) << | ||
254 | MC13783_LED_C0_ABMODE; | ||
255 | reg |= (pdata->abref & MC13783_LED_C0_ABREF_MASK) << | ||
256 | MC13783_LED_C0_ABREF; | ||
257 | |||
258 | ret = mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_0, reg); | ||
259 | |||
260 | out: | ||
261 | mc13783_unlock(dev); | ||
262 | return ret; | ||
263 | } | ||
264 | |||
265 | static int __devinit mc13783_led_probe(struct platform_device *pdev) | ||
266 | { | ||
267 | struct mc13783_leds_platform_data *pdata = dev_get_platdata(&pdev->dev); | ||
268 | struct mc13783_led_platform_data *led_cur; | ||
269 | struct mc13783_led *led, *led_dat; | ||
270 | int ret, i; | ||
271 | int init_led = 0; | ||
272 | |||
273 | if (pdata == NULL) { | ||
274 | dev_err(&pdev->dev, "missing platform data\n"); | ||
275 | return -ENODEV; | ||
276 | } | ||
277 | |||
278 | if (pdata->num_leds < 1 || pdata->num_leds > MC13783_LED_MAX) { | ||
279 | dev_err(&pdev->dev, "Invalid led count %d\n", pdata->num_leds); | ||
280 | return -EINVAL; | ||
281 | } | ||
282 | |||
283 | led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL); | ||
284 | if (led == NULL) { | ||
285 | dev_err(&pdev->dev, "failed to alloc memory\n"); | ||
286 | return -ENOMEM; | ||
287 | } | ||
288 | |||
289 | ret = mc13783_leds_prepare(pdev); | ||
290 | if (ret) { | ||
291 | dev_err(&pdev->dev, "unable to init led driver\n"); | ||
292 | goto err_free; | ||
293 | } | ||
294 | |||
295 | for (i = 0; i < pdata->num_leds; i++) { | ||
296 | led_dat = &led[i]; | ||
297 | led_cur = &pdata->led[i]; | ||
298 | |||
299 | if (led_cur->id > MC13783_LED_MAX || led_cur->id < 0) { | ||
300 | dev_err(&pdev->dev, "invalid id %d\n", led_cur->id); | ||
301 | ret = -EINVAL; | ||
302 | goto err_register; | ||
303 | } | ||
304 | |||
305 | if (init_led & (1 << led_cur->id)) { | ||
306 | dev_err(&pdev->dev, "led %d already initialized\n", | ||
307 | led_cur->id); | ||
308 | ret = -EINVAL; | ||
309 | goto err_register; | ||
310 | } | ||
311 | |||
312 | init_led |= 1 << led_cur->id; | ||
313 | led_dat->cdev.name = led_cur->name; | ||
314 | led_dat->cdev.default_trigger = led_cur->default_trigger; | ||
315 | led_dat->cdev.brightness_set = mc13783_led_set; | ||
316 | led_dat->cdev.brightness = LED_OFF; | ||
317 | led_dat->id = led_cur->id; | ||
318 | led_dat->master = dev_get_drvdata(pdev->dev.parent); | ||
319 | |||
320 | INIT_WORK(&led_dat->work, mc13783_led_work); | ||
321 | |||
322 | ret = led_classdev_register(pdev->dev.parent, &led_dat->cdev); | ||
323 | if (ret) { | ||
324 | dev_err(&pdev->dev, "failed to register led %d\n", | ||
325 | led_dat->id); | ||
326 | goto err_register; | ||
327 | } | ||
328 | |||
329 | ret = mc13783_led_setup(led_dat, led_cur->max_current); | ||
330 | if (ret) { | ||
331 | dev_err(&pdev->dev, "unable to init led %d\n", | ||
332 | led_dat->id); | ||
333 | i++; | ||
334 | goto err_register; | ||
335 | } | ||
336 | } | ||
337 | |||
338 | platform_set_drvdata(pdev, led); | ||
339 | return 0; | ||
340 | |||
341 | err_register: | ||
342 | for (i = i - 1; i >= 0; i--) { | ||
343 | led_classdev_unregister(&led[i].cdev); | ||
344 | cancel_work_sync(&led[i].work); | ||
345 | } | ||
346 | |||
347 | err_free: | ||
348 | kfree(led); | ||
349 | return ret; | ||
350 | } | ||
351 | |||
352 | static int __devexit mc13783_led_remove(struct platform_device *pdev) | ||
353 | { | ||
354 | struct mc13783_leds_platform_data *pdata = dev_get_platdata(&pdev->dev); | ||
355 | struct mc13783_led *led = platform_get_drvdata(pdev); | ||
356 | struct mc13783 *dev = dev_get_drvdata(pdev->dev.parent); | ||
357 | int i; | ||
358 | |||
359 | for (i = 0; i < pdata->num_leds; i++) { | ||
360 | led_classdev_unregister(&led[i].cdev); | ||
361 | cancel_work_sync(&led[i].work); | ||
362 | } | ||
363 | |||
364 | mc13783_lock(dev); | ||
365 | |||
366 | mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_0, 0); | ||
367 | mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_1, 0); | ||
368 | mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_2, 0); | ||
369 | mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_3, 0); | ||
370 | mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_4, 0); | ||
371 | mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_5, 0); | ||
372 | |||
373 | mc13783_unlock(dev); | ||
374 | |||
375 | kfree(led); | ||
376 | return 0; | ||
377 | } | ||
378 | |||
379 | static struct platform_driver mc13783_led_driver = { | ||
380 | .driver = { | ||
381 | .name = "mc13783-led", | ||
382 | .owner = THIS_MODULE, | ||
383 | }, | ||
384 | .probe = mc13783_led_probe, | ||
385 | .remove = __devexit_p(mc13783_led_remove), | ||
386 | }; | ||
387 | |||
388 | static int __init mc13783_led_init(void) | ||
389 | { | ||
390 | return platform_driver_register(&mc13783_led_driver); | ||
391 | } | ||
392 | module_init(mc13783_led_init); | ||
393 | |||
394 | static void __exit mc13783_led_exit(void) | ||
395 | { | ||
396 | platform_driver_unregister(&mc13783_led_driver); | ||
397 | } | ||
398 | module_exit(mc13783_led_exit); | ||
399 | |||
400 | MODULE_DESCRIPTION("LEDs driver for Freescale MC13783 PMIC"); | ||
401 | MODULE_AUTHOR("Philippe Retornaz <philippe.retornaz@epfl.ch>"); | ||
402 | MODULE_LICENSE("GPL"); | ||
403 | MODULE_ALIAS("platform:mc13783-led"); | ||
diff --git a/drivers/leds/leds-net5501.c b/drivers/leds/leds-net5501.c new file mode 100644 index 000000000000..3063f591f0dc --- /dev/null +++ b/drivers/leds/leds-net5501.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | * Soekris board support code | ||
3 | * | ||
4 | * Copyright (C) 2008-2009 Tower Technologies | ||
5 | * Written by Alessandro Zummo <a.zummo@towertech.it> | ||
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 | ||
9 | * as published by the Free Software Foundation. | ||
10 | */ | ||
11 | |||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/io.h> | ||
15 | #include <linux/string.h> | ||
16 | #include <linux/leds.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/gpio.h> | ||
19 | |||
20 | #include <asm/geode.h> | ||
21 | |||
22 | static struct gpio_led net5501_leds[] = { | ||
23 | { | ||
24 | .name = "error", | ||
25 | .gpio = 6, | ||
26 | .default_trigger = "default-on", | ||
27 | }, | ||
28 | }; | ||
29 | |||
30 | static struct gpio_led_platform_data net5501_leds_data = { | ||
31 | .num_leds = ARRAY_SIZE(net5501_leds), | ||
32 | .leds = net5501_leds, | ||
33 | }; | ||
34 | |||
35 | static struct platform_device net5501_leds_dev = { | ||
36 | .name = "leds-gpio", | ||
37 | .id = -1, | ||
38 | .dev.platform_data = &net5501_leds_data, | ||
39 | }; | ||
40 | |||
41 | static void __init init_net5501(void) | ||
42 | { | ||
43 | platform_device_register(&net5501_leds_dev); | ||
44 | } | ||
45 | |||
46 | struct soekris_board { | ||
47 | u16 offset; | ||
48 | char *sig; | ||
49 | u8 len; | ||
50 | void (*init)(void); | ||
51 | }; | ||
52 | |||
53 | static struct soekris_board __initdata boards[] = { | ||
54 | { 0xb7b, "net5501", 7, init_net5501 }, /* net5501 v1.33/1.33c */ | ||
55 | { 0xb1f, "net5501", 7, init_net5501 }, /* net5501 v1.32i */ | ||
56 | }; | ||
57 | |||
58 | static int __init soekris_init(void) | ||
59 | { | ||
60 | int i; | ||
61 | unsigned char *rombase, *bios; | ||
62 | |||
63 | if (!is_geode()) | ||
64 | return 0; | ||
65 | |||
66 | rombase = ioremap(0xffff0000, 0xffff); | ||
67 | if (!rombase) { | ||
68 | printk(KERN_INFO "Soekris net5501 LED driver failed to get rombase"); | ||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | bios = rombase + 0x20; /* null terminated */ | ||
73 | |||
74 | if (strncmp(bios, "comBIOS", 7)) | ||
75 | goto unmap; | ||
76 | |||
77 | for (i = 0; i < ARRAY_SIZE(boards); i++) { | ||
78 | unsigned char *model = rombase + boards[i].offset; | ||
79 | |||
80 | if (strncmp(model, boards[i].sig, boards[i].len) == 0) { | ||
81 | printk(KERN_INFO "Soekris %s: %s\n", model, bios); | ||
82 | |||
83 | if (boards[i].init) | ||
84 | boards[i].init(); | ||
85 | break; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | unmap: | ||
90 | iounmap(rombase); | ||
91 | return 0; | ||
92 | } | ||
93 | |||
94 | arch_initcall(soekris_init); | ||
diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c index 51477ec71391..a688293abd0b 100644 --- a/drivers/leds/leds-ss4200.c +++ b/drivers/leds/leds-ss4200.c | |||
@@ -534,7 +534,7 @@ static int __init nas_gpio_init(void) | |||
534 | set_power_light_amber_noblink(); | 534 | set_power_light_amber_noblink(); |
535 | return 0; | 535 | return 0; |
536 | out_err: | 536 | out_err: |
537 | for (; i >= 0; i--) | 537 | for (i--; i >= 0; i--) |
538 | unregister_nasgpio_led(i); | 538 | unregister_nasgpio_led(i); |
539 | pci_unregister_driver(&nas_gpio_pci_driver); | 539 | pci_unregister_driver(&nas_gpio_pci_driver); |
540 | return ret; | 540 | return ret; |
diff --git a/drivers/mfd/mc13783-core.c b/drivers/mfd/mc13783-core.c index 1f68ecadddc2..fecf38a4f025 100644 --- a/drivers/mfd/mc13783-core.c +++ b/drivers/mfd/mc13783-core.c | |||
@@ -679,6 +679,10 @@ err_revision: | |||
679 | if (pdata->flags & MC13783_USE_TOUCHSCREEN) | 679 | if (pdata->flags & MC13783_USE_TOUCHSCREEN) |
680 | mc13783_add_subdevice(mc13783, "mc13783-ts"); | 680 | mc13783_add_subdevice(mc13783, "mc13783-ts"); |
681 | 681 | ||
682 | if (pdata->flags & MC13783_USE_LED) | ||
683 | mc13783_add_subdevice_pdata(mc13783, "mc13783-led", | ||
684 | pdata->leds, sizeof(*pdata->leds)); | ||
685 | |||
682 | return 0; | 686 | return 0; |
683 | } | 687 | } |
684 | 688 | ||
diff --git a/drivers/mfd/pcf50633-core.c b/drivers/mfd/pcf50633-core.c index 63a614d696c1..dc95ddb708f1 100644 --- a/drivers/mfd/pcf50633-core.c +++ b/drivers/mfd/pcf50633-core.c | |||
@@ -620,6 +620,9 @@ static int __devinit pcf50633_probe(struct i2c_client *client, | |||
620 | &pcf->mbc_pdev); | 620 | &pcf->mbc_pdev); |
621 | pcf50633_client_dev_register(pcf, "pcf50633-adc", | 621 | pcf50633_client_dev_register(pcf, "pcf50633-adc", |
622 | &pcf->adc_pdev); | 622 | &pcf->adc_pdev); |
623 | pcf50633_client_dev_register(pcf, "pcf50633-backlight", | ||
624 | &pcf->bl_pdev); | ||
625 | |||
623 | 626 | ||
624 | for (i = 0; i < PCF50633_NUM_REGULATORS; i++) { | 627 | for (i = 0; i < PCF50633_NUM_REGULATORS; i++) { |
625 | struct platform_device *pdev; | 628 | struct platform_device *pdev; |
diff --git a/drivers/video/backlight/88pm860x_bl.c b/drivers/video/backlight/88pm860x_bl.c index 68d2518fadaa..38ffc3fbcbe4 100644 --- a/drivers/video/backlight/88pm860x_bl.c +++ b/drivers/video/backlight/88pm860x_bl.c | |||
@@ -222,6 +222,7 @@ static int pm860x_backlight_probe(struct platform_device *pdev) | |||
222 | data->port = __check_device(pdata, name); | 222 | data->port = __check_device(pdata, name); |
223 | if (data->port < 0) { | 223 | if (data->port < 0) { |
224 | dev_err(&pdev->dev, "wrong platform data is assigned"); | 224 | dev_err(&pdev->dev, "wrong platform data is assigned"); |
225 | kfree(data); | ||
225 | return -EINVAL; | 226 | return -EINVAL; |
226 | } | 227 | } |
227 | 228 | ||
@@ -266,6 +267,7 @@ static int pm860x_backlight_probe(struct platform_device *pdev) | |||
266 | backlight_update_status(bl); | 267 | backlight_update_status(bl); |
267 | return 0; | 268 | return 0; |
268 | out: | 269 | out: |
270 | backlight_device_unregister(bl); | ||
269 | kfree(data); | 271 | kfree(data); |
270 | return ret; | 272 | return ret; |
271 | } | 273 | } |
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig index c025c84601b0..e54a337227ea 100644 --- a/drivers/video/backlight/Kconfig +++ b/drivers/video/backlight/Kconfig | |||
@@ -8,12 +8,13 @@ menuconfig BACKLIGHT_LCD_SUPPORT | |||
8 | Enable this to be able to choose the drivers for controlling the | 8 | Enable this to be able to choose the drivers for controlling the |
9 | backlight and the LCD panel on some platforms, for example on PDAs. | 9 | backlight and the LCD panel on some platforms, for example on PDAs. |
10 | 10 | ||
11 | if BACKLIGHT_LCD_SUPPORT | ||
12 | |||
11 | # | 13 | # |
12 | # LCD | 14 | # LCD |
13 | # | 15 | # |
14 | config LCD_CLASS_DEVICE | 16 | config LCD_CLASS_DEVICE |
15 | tristate "Lowlevel LCD controls" | 17 | tristate "Lowlevel LCD controls" |
16 | depends on BACKLIGHT_LCD_SUPPORT | ||
17 | default m | 18 | default m |
18 | help | 19 | help |
19 | This framework adds support for low-level control of LCD. | 20 | This framework adds support for low-level control of LCD. |
@@ -24,31 +25,32 @@ config LCD_CLASS_DEVICE | |||
24 | To have support for your specific LCD panel you will have to | 25 | To have support for your specific LCD panel you will have to |
25 | select the proper drivers which depend on this option. | 26 | select the proper drivers which depend on this option. |
26 | 27 | ||
28 | if LCD_CLASS_DEVICE | ||
29 | |||
27 | config LCD_CORGI | 30 | config LCD_CORGI |
28 | tristate "LCD Panel support for SHARP corgi/spitz model" | 31 | tristate "LCD Panel support for SHARP corgi/spitz model" |
29 | depends on LCD_CLASS_DEVICE && SPI_MASTER && PXA_SHARPSL | 32 | depends on SPI_MASTER && PXA_SHARPSL |
30 | help | 33 | help |
31 | Say y here to support the LCD panels usually found on SHARP | 34 | Say y here to support the LCD panels usually found on SHARP |
32 | corgi (C7x0) and spitz (Cxx00) models. | 35 | corgi (C7x0) and spitz (Cxx00) models. |
33 | 36 | ||
34 | config LCD_L4F00242T03 | 37 | config LCD_L4F00242T03 |
35 | tristate "Epson L4F00242T03 LCD" | 38 | tristate "Epson L4F00242T03 LCD" |
36 | depends on LCD_CLASS_DEVICE && SPI_MASTER && GENERIC_GPIO | 39 | depends on SPI_MASTER && GENERIC_GPIO |
37 | help | 40 | help |
38 | SPI driver for Epson L4F00242T03. This provides basic support | 41 | SPI driver for Epson L4F00242T03. This provides basic support |
39 | for init and powering the LCD up/down through a sysfs interface. | 42 | for init and powering the LCD up/down through a sysfs interface. |
40 | 43 | ||
41 | config LCD_LMS283GF05 | 44 | config LCD_LMS283GF05 |
42 | tristate "Samsung LMS283GF05 LCD" | 45 | tristate "Samsung LMS283GF05 LCD" |
43 | depends on LCD_CLASS_DEVICE && SPI_MASTER && GENERIC_GPIO | 46 | depends on SPI_MASTER && GENERIC_GPIO |
44 | help | 47 | help |
45 | SPI driver for Samsung LMS283GF05. This provides basic support | 48 | SPI driver for Samsung LMS283GF05. This provides basic support |
46 | for powering the LCD up/down through a sysfs interface. | 49 | for powering the LCD up/down through a sysfs interface. |
47 | 50 | ||
48 | config LCD_LTV350QV | 51 | config LCD_LTV350QV |
49 | tristate "Samsung LTV350QV LCD Panel" | 52 | tristate "Samsung LTV350QV LCD Panel" |
50 | depends on LCD_CLASS_DEVICE && SPI_MASTER | 53 | depends on SPI_MASTER |
51 | default n | ||
52 | help | 54 | help |
53 | If you have a Samsung LTV350QV LCD panel, say y to include a | 55 | If you have a Samsung LTV350QV LCD panel, say y to include a |
54 | power control driver for it. The panel starts up in power | 56 | power control driver for it. The panel starts up in power |
@@ -59,60 +61,61 @@ config LCD_LTV350QV | |||
59 | 61 | ||
60 | config LCD_ILI9320 | 62 | config LCD_ILI9320 |
61 | tristate | 63 | tristate |
62 | depends on LCD_CLASS_DEVICE && BACKLIGHT_LCD_SUPPORT | ||
63 | default n | ||
64 | help | 64 | help |
65 | If you have a panel based on the ILI9320 controller chip | 65 | If you have a panel based on the ILI9320 controller chip |
66 | then say y to include a power driver for it. | 66 | then say y to include a power driver for it. |
67 | 67 | ||
68 | config LCD_TDO24M | 68 | config LCD_TDO24M |
69 | tristate "Toppoly TDO24M and TDO35S LCD Panels support" | 69 | tristate "Toppoly TDO24M and TDO35S LCD Panels support" |
70 | depends on LCD_CLASS_DEVICE && SPI_MASTER | 70 | depends on SPI_MASTER |
71 | default n | ||
72 | help | 71 | help |
73 | If you have a Toppoly TDO24M/TDO35S series LCD panel, say y here to | 72 | If you have a Toppoly TDO24M/TDO35S series LCD panel, say y here to |
74 | include the support for it. | 73 | include the support for it. |
75 | 74 | ||
76 | config LCD_VGG2432A4 | 75 | config LCD_VGG2432A4 |
77 | tristate "VGG2432A4 LCM device support" | 76 | tristate "VGG2432A4 LCM device support" |
78 | depends on BACKLIGHT_LCD_SUPPORT && LCD_CLASS_DEVICE && SPI_MASTER | 77 | depends on SPI_MASTER |
79 | select LCD_ILI9320 | 78 | select LCD_ILI9320 |
80 | default n | ||
81 | help | 79 | help |
82 | If you have a VGG2432A4 panel based on the ILI9320 controller chip | 80 | If you have a VGG2432A4 panel based on the ILI9320 controller chip |
83 | then say y to include a power driver for it. | 81 | then say y to include a power driver for it. |
84 | 82 | ||
85 | config LCD_PLATFORM | 83 | config LCD_PLATFORM |
86 | tristate "Platform LCD controls" | 84 | tristate "Platform LCD controls" |
87 | depends on LCD_CLASS_DEVICE | ||
88 | help | 85 | help |
89 | This driver provides a platform-device registered LCD power | 86 | This driver provides a platform-device registered LCD power |
90 | control interface. | 87 | control interface. |
91 | 88 | ||
92 | config LCD_TOSA | 89 | config LCD_TOSA |
93 | tristate "Sharp SL-6000 LCD Driver" | 90 | tristate "Sharp SL-6000 LCD Driver" |
94 | depends on LCD_CLASS_DEVICE && SPI | 91 | depends on SPI && MACH_TOSA |
95 | depends on MACH_TOSA | ||
96 | default n | ||
97 | help | 92 | help |
98 | If you have an Sharp SL-6000 Zaurus say Y to enable a driver | 93 | If you have an Sharp SL-6000 Zaurus say Y to enable a driver |
99 | for its LCD. | 94 | for its LCD. |
100 | 95 | ||
101 | config LCD_HP700 | 96 | config LCD_HP700 |
102 | tristate "HP Jornada 700 series LCD Driver" | 97 | tristate "HP Jornada 700 series LCD Driver" |
103 | depends on LCD_CLASS_DEVICE | ||
104 | depends on SA1100_JORNADA720_SSP && !PREEMPT | 98 | depends on SA1100_JORNADA720_SSP && !PREEMPT |
105 | default y | 99 | default y |
106 | help | 100 | help |
107 | If you have an HP Jornada 700 series handheld (710/720/728) | 101 | If you have an HP Jornada 700 series handheld (710/720/728) |
108 | say Y to enable LCD control driver. | 102 | say Y to enable LCD control driver. |
109 | 103 | ||
104 | config LCD_S6E63M0 | ||
105 | tristate "S6E63M0 AMOLED LCD Driver" | ||
106 | depends on SPI && BACKLIGHT_CLASS_DEVICE | ||
107 | default n | ||
108 | help | ||
109 | If you have an S6E63M0 LCD Panel, say Y to enable its | ||
110 | LCD control driver. | ||
111 | |||
112 | endif # LCD_CLASS_DEVICE | ||
113 | |||
110 | # | 114 | # |
111 | # Backlight | 115 | # Backlight |
112 | # | 116 | # |
113 | config BACKLIGHT_CLASS_DEVICE | 117 | config BACKLIGHT_CLASS_DEVICE |
114 | tristate "Lowlevel Backlight controls" | 118 | tristate "Lowlevel Backlight controls" |
115 | depends on BACKLIGHT_LCD_SUPPORT | ||
116 | default m | 119 | default m |
117 | help | 120 | help |
118 | This framework adds support for low-level control of the LCD | 121 | This framework adds support for low-level control of the LCD |
@@ -121,9 +124,11 @@ config BACKLIGHT_CLASS_DEVICE | |||
121 | To have support for your specific LCD panel you will have to | 124 | To have support for your specific LCD panel you will have to |
122 | select the proper drivers which depend on this option. | 125 | select the proper drivers which depend on this option. |
123 | 126 | ||
127 | if BACKLIGHT_CLASS_DEVICE | ||
128 | |||
124 | config BACKLIGHT_ATMEL_LCDC | 129 | config BACKLIGHT_ATMEL_LCDC |
125 | bool "Atmel LCDC Contrast-as-Backlight control" | 130 | bool "Atmel LCDC Contrast-as-Backlight control" |
126 | depends on BACKLIGHT_CLASS_DEVICE && FB_ATMEL | 131 | depends on FB_ATMEL |
127 | default y if MACH_SAM9261EK || MACH_SAM9G10EK || MACH_SAM9263EK | 132 | default y if MACH_SAM9261EK || MACH_SAM9G10EK || MACH_SAM9263EK |
128 | help | 133 | help |
129 | This provides a backlight control internal to the Atmel LCDC | 134 | This provides a backlight control internal to the Atmel LCDC |
@@ -136,8 +141,7 @@ config BACKLIGHT_ATMEL_LCDC | |||
136 | 141 | ||
137 | config BACKLIGHT_ATMEL_PWM | 142 | config BACKLIGHT_ATMEL_PWM |
138 | tristate "Atmel PWM backlight control" | 143 | tristate "Atmel PWM backlight control" |
139 | depends on BACKLIGHT_CLASS_DEVICE && ATMEL_PWM | 144 | depends on ATMEL_PWM |
140 | default n | ||
141 | help | 145 | help |
142 | Say Y here if you want to use the PWM peripheral in Atmel AT91 and | 146 | Say Y here if you want to use the PWM peripheral in Atmel AT91 and |
143 | AVR32 devices. This driver will need additional platform data to know | 147 | AVR32 devices. This driver will need additional platform data to know |
@@ -146,9 +150,18 @@ config BACKLIGHT_ATMEL_PWM | |||
146 | To compile this driver as a module, choose M here: the module will be | 150 | To compile this driver as a module, choose M here: the module will be |
147 | called atmel-pwm-bl. | 151 | called atmel-pwm-bl. |
148 | 152 | ||
153 | config BACKLIGHT_EP93XX | ||
154 | tristate "Cirrus EP93xx Backlight Driver" | ||
155 | depends on FB_EP93XX | ||
156 | help | ||
157 | If you have a LCD backlight connected to the BRIGHT output of | ||
158 | the EP93xx, say Y here to enable this driver. | ||
159 | |||
160 | To compile this driver as a module, choose M here: the module will | ||
161 | be called ep93xx_bl. | ||
162 | |||
149 | config BACKLIGHT_GENERIC | 163 | config BACKLIGHT_GENERIC |
150 | tristate "Generic (aka Sharp Corgi) Backlight Driver" | 164 | tristate "Generic (aka Sharp Corgi) Backlight Driver" |
151 | depends on BACKLIGHT_CLASS_DEVICE | ||
152 | default y | 165 | default y |
153 | help | 166 | help |
154 | Say y to enable the generic platform backlight driver previously | 167 | Say y to enable the generic platform backlight driver previously |
@@ -157,7 +170,7 @@ config BACKLIGHT_GENERIC | |||
157 | 170 | ||
158 | config BACKLIGHT_LOCOMO | 171 | config BACKLIGHT_LOCOMO |
159 | tristate "Sharp LOCOMO LCD/Backlight Driver" | 172 | tristate "Sharp LOCOMO LCD/Backlight Driver" |
160 | depends on BACKLIGHT_CLASS_DEVICE && SHARP_LOCOMO | 173 | depends on SHARP_LOCOMO |
161 | default y | 174 | default y |
162 | help | 175 | help |
163 | If you have a Sharp Zaurus SL-5500 (Collie) or SL-5600 (Poodle) say y to | 176 | If you have a Sharp Zaurus SL-5500 (Collie) or SL-5600 (Poodle) say y to |
@@ -165,7 +178,7 @@ config BACKLIGHT_LOCOMO | |||
165 | 178 | ||
166 | config BACKLIGHT_OMAP1 | 179 | config BACKLIGHT_OMAP1 |
167 | tristate "OMAP1 PWL-based LCD Backlight" | 180 | tristate "OMAP1 PWL-based LCD Backlight" |
168 | depends on BACKLIGHT_CLASS_DEVICE && ARCH_OMAP1 | 181 | depends on ARCH_OMAP1 |
169 | default y | 182 | default y |
170 | help | 183 | help |
171 | This driver controls the LCD backlight level and power for | 184 | This driver controls the LCD backlight level and power for |
@@ -174,7 +187,7 @@ config BACKLIGHT_OMAP1 | |||
174 | 187 | ||
175 | config BACKLIGHT_HP680 | 188 | config BACKLIGHT_HP680 |
176 | tristate "HP Jornada 680 Backlight Driver" | 189 | tristate "HP Jornada 680 Backlight Driver" |
177 | depends on BACKLIGHT_CLASS_DEVICE && SH_HP6XX | 190 | depends on SH_HP6XX |
178 | default y | 191 | default y |
179 | help | 192 | help |
180 | If you have a HP Jornada 680, say y to enable the | 193 | If you have a HP Jornada 680, say y to enable the |
@@ -182,7 +195,6 @@ config BACKLIGHT_HP680 | |||
182 | 195 | ||
183 | config BACKLIGHT_HP700 | 196 | config BACKLIGHT_HP700 |
184 | tristate "HP Jornada 700 series Backlight Driver" | 197 | tristate "HP Jornada 700 series Backlight Driver" |
185 | depends on BACKLIGHT_CLASS_DEVICE | ||
186 | depends on SA1100_JORNADA720_SSP && !PREEMPT | 198 | depends on SA1100_JORNADA720_SSP && !PREEMPT |
187 | default y | 199 | default y |
188 | help | 200 | help |
@@ -191,76 +203,70 @@ config BACKLIGHT_HP700 | |||
191 | 203 | ||
192 | config BACKLIGHT_PROGEAR | 204 | config BACKLIGHT_PROGEAR |
193 | tristate "Frontpath ProGear Backlight Driver" | 205 | tristate "Frontpath ProGear Backlight Driver" |
194 | depends on BACKLIGHT_CLASS_DEVICE && PCI && X86 | 206 | depends on PCI && X86 |
195 | default n | ||
196 | help | 207 | help |
197 | If you have a Frontpath ProGear say Y to enable the | 208 | If you have a Frontpath ProGear say Y to enable the |
198 | backlight driver. | 209 | backlight driver. |
199 | 210 | ||
200 | config BACKLIGHT_CARILLO_RANCH | 211 | config BACKLIGHT_CARILLO_RANCH |
201 | tristate "Intel Carillo Ranch Backlight Driver" | 212 | tristate "Intel Carillo Ranch Backlight Driver" |
202 | depends on BACKLIGHT_CLASS_DEVICE && LCD_CLASS_DEVICE && PCI && X86 && FB_LE80578 | 213 | depends on LCD_CLASS_DEVICE && PCI && X86 && FB_LE80578 |
203 | default n | ||
204 | help | 214 | help |
205 | If you have a Intel LE80578 (Carillo Ranch) say Y to enable the | 215 | If you have a Intel LE80578 (Carillo Ranch) say Y to enable the |
206 | backlight driver. | 216 | backlight driver. |
207 | 217 | ||
208 | config BACKLIGHT_PWM | 218 | config BACKLIGHT_PWM |
209 | tristate "Generic PWM based Backlight Driver" | 219 | tristate "Generic PWM based Backlight Driver" |
210 | depends on BACKLIGHT_CLASS_DEVICE && HAVE_PWM | 220 | depends on HAVE_PWM |
211 | help | 221 | help |
212 | If you have a LCD backlight adjustable by PWM, say Y to enable | 222 | If you have a LCD backlight adjustable by PWM, say Y to enable |
213 | this driver. | 223 | this driver. |
214 | 224 | ||
215 | config BACKLIGHT_DA903X | 225 | config BACKLIGHT_DA903X |
216 | tristate "Backlight Driver for DA9030/DA9034 using WLED" | 226 | tristate "Backlight Driver for DA9030/DA9034 using WLED" |
217 | depends on BACKLIGHT_CLASS_DEVICE && PMIC_DA903X | 227 | depends on PMIC_DA903X |
218 | help | 228 | help |
219 | If you have a LCD backlight connected to the WLED output of DA9030 | 229 | If you have a LCD backlight connected to the WLED output of DA9030 |
220 | or DA9034 WLED output, say Y here to enable this driver. | 230 | or DA9034 WLED output, say Y here to enable this driver. |
221 | 231 | ||
222 | config BACKLIGHT_MAX8925 | 232 | config BACKLIGHT_MAX8925 |
223 | tristate "Backlight driver for MAX8925" | 233 | tristate "Backlight driver for MAX8925" |
224 | depends on BACKLIGHT_CLASS_DEVICE && MFD_MAX8925 | 234 | depends on MFD_MAX8925 |
225 | help | 235 | help |
226 | If you have a LCD backlight connected to the WLED output of MAX8925 | 236 | If you have a LCD backlight connected to the WLED output of MAX8925 |
227 | WLED output, say Y here to enable this driver. | 237 | WLED output, say Y here to enable this driver. |
228 | 238 | ||
229 | config BACKLIGHT_MBP_NVIDIA | 239 | config BACKLIGHT_MBP_NVIDIA |
230 | tristate "MacBook Pro Nvidia Backlight Driver" | 240 | tristate "MacBook Pro Nvidia Backlight Driver" |
231 | depends on BACKLIGHT_CLASS_DEVICE && X86 | 241 | depends on X86 |
232 | default n | ||
233 | help | 242 | help |
234 | If you have an Apple Macbook Pro with Nvidia graphics hardware say Y | 243 | If you have an Apple Macbook Pro with Nvidia graphics hardware say Y |
235 | to enable a driver for its backlight | 244 | to enable a driver for its backlight |
236 | 245 | ||
237 | config BACKLIGHT_TOSA | 246 | config BACKLIGHT_TOSA |
238 | tristate "Sharp SL-6000 Backlight Driver" | 247 | tristate "Sharp SL-6000 Backlight Driver" |
239 | depends on BACKLIGHT_CLASS_DEVICE && I2C | 248 | depends on I2C && MACH_TOSA && LCD_TOSA |
240 | depends on MACH_TOSA && LCD_TOSA | ||
241 | default n | ||
242 | help | 249 | help |
243 | If you have an Sharp SL-6000 Zaurus say Y to enable a driver | 250 | If you have an Sharp SL-6000 Zaurus say Y to enable a driver |
244 | for its backlight | 251 | for its backlight |
245 | 252 | ||
246 | config BACKLIGHT_SAHARA | 253 | config BACKLIGHT_SAHARA |
247 | tristate "Tabletkiosk Sahara Touch-iT Backlight Driver" | 254 | tristate "Tabletkiosk Sahara Touch-iT Backlight Driver" |
248 | depends on BACKLIGHT_CLASS_DEVICE && X86 | 255 | depends on X86 |
249 | default n | ||
250 | help | 256 | help |
251 | If you have a Tabletkiosk Sahara Touch-iT, say y to enable the | 257 | If you have a Tabletkiosk Sahara Touch-iT, say y to enable the |
252 | backlight driver. | 258 | backlight driver. |
253 | 259 | ||
254 | config BACKLIGHT_WM831X | 260 | config BACKLIGHT_WM831X |
255 | tristate "WM831x PMIC Backlight Driver" | 261 | tristate "WM831x PMIC Backlight Driver" |
256 | depends on BACKLIGHT_CLASS_DEVICE && MFD_WM831X | 262 | depends on MFD_WM831X |
257 | help | 263 | help |
258 | If you have a backlight driven by the ISINK and DCDC of a | 264 | If you have a backlight driven by the ISINK and DCDC of a |
259 | WM831x PMIC say y to enable the backlight driver for it. | 265 | WM831x PMIC say y to enable the backlight driver for it. |
260 | 266 | ||
261 | config BACKLIGHT_ADX | 267 | config BACKLIGHT_ADX |
262 | tristate "Avionic Design Xanthos Backlight Driver" | 268 | tristate "Avionic Design Xanthos Backlight Driver" |
263 | depends on BACKLIGHT_CLASS_DEVICE && ARCH_PXA_ADX | 269 | depends on ARCH_PXA_ADX |
264 | default y | 270 | default y |
265 | help | 271 | help |
266 | Say Y to enable the backlight driver on Avionic Design Xanthos-based | 272 | Say Y to enable the backlight driver on Avionic Design Xanthos-based |
@@ -268,7 +274,7 @@ config BACKLIGHT_ADX | |||
268 | 274 | ||
269 | config BACKLIGHT_ADP5520 | 275 | config BACKLIGHT_ADP5520 |
270 | tristate "Backlight Driver for ADP5520/ADP5501 using WLED" | 276 | tristate "Backlight Driver for ADP5520/ADP5501 using WLED" |
271 | depends on BACKLIGHT_CLASS_DEVICE && PMIC_ADP5520 | 277 | depends on PMIC_ADP5520 |
272 | help | 278 | help |
273 | If you have a LCD backlight connected to the BST/BL_SNK output of | 279 | If you have a LCD backlight connected to the BST/BL_SNK output of |
274 | ADP5520 or ADP5501, say Y here to enable this driver. | 280 | ADP5520 or ADP5501, say Y here to enable this driver. |
@@ -276,9 +282,31 @@ config BACKLIGHT_ADP5520 | |||
276 | To compile this driver as a module, choose M here: the module will | 282 | To compile this driver as a module, choose M here: the module will |
277 | be called adp5520_bl. | 283 | be called adp5520_bl. |
278 | 284 | ||
285 | config BACKLIGHT_ADP8860 | ||
286 | tristate "Backlight Driver for ADP8860/ADP8861/ADP8863 using WLED" | ||
287 | depends on BACKLIGHT_CLASS_DEVICE && I2C | ||
288 | select NEW_LEDS | ||
289 | select LEDS_CLASS | ||
290 | help | ||
291 | If you have a LCD backlight connected to the ADP8860, ADP8861 or | ||
292 | ADP8863 say Y here to enable this driver. | ||
293 | |||
294 | To compile this driver as a module, choose M here: the module will | ||
295 | be called adp8860_bl. | ||
296 | |||
279 | config BACKLIGHT_88PM860X | 297 | config BACKLIGHT_88PM860X |
280 | tristate "Backlight Driver for 88PM8606 using WLED" | 298 | tristate "Backlight Driver for 88PM8606 using WLED" |
281 | depends on BACKLIGHT_CLASS_DEVICE && MFD_88PM860X | 299 | depends on MFD_88PM860X |
282 | help | 300 | help |
283 | Say Y to enable the backlight driver for Marvell 88PM8606. | 301 | Say Y to enable the backlight driver for Marvell 88PM8606. |
284 | 302 | ||
303 | config BACKLIGHT_PCF50633 | ||
304 | tristate "Backlight driver for NXP PCF50633 MFD" | ||
305 | depends on BACKLIGHT_CLASS_DEVICE && MFD_PCF50633 | ||
306 | help | ||
307 | If you have a backlight driven by a NXP PCF50633 MFD, say Y here to | ||
308 | enable its driver. | ||
309 | |||
310 | endif # BACKLIGHT_CLASS_DEVICE | ||
311 | |||
312 | endif # BACKLIGHT_LCD_SUPPORT | ||
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile index 09d1f14d6257..44c0f81ad85d 100644 --- a/drivers/video/backlight/Makefile +++ b/drivers/video/backlight/Makefile | |||
@@ -11,9 +11,11 @@ obj-$(CONFIG_LCD_PLATFORM) += platform_lcd.o | |||
11 | obj-$(CONFIG_LCD_VGG2432A4) += vgg2432a4.o | 11 | obj-$(CONFIG_LCD_VGG2432A4) += vgg2432a4.o |
12 | obj-$(CONFIG_LCD_TDO24M) += tdo24m.o | 12 | obj-$(CONFIG_LCD_TDO24M) += tdo24m.o |
13 | obj-$(CONFIG_LCD_TOSA) += tosa_lcd.o | 13 | obj-$(CONFIG_LCD_TOSA) += tosa_lcd.o |
14 | obj-$(CONFIG_LCD_S6E63M0) += s6e63m0.o | ||
14 | 15 | ||
15 | obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o | 16 | obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o |
16 | obj-$(CONFIG_BACKLIGHT_ATMEL_PWM) += atmel-pwm-bl.o | 17 | obj-$(CONFIG_BACKLIGHT_ATMEL_PWM) += atmel-pwm-bl.o |
18 | obj-$(CONFIG_BACKLIGHT_EP93XX) += ep93xx_bl.o | ||
17 | obj-$(CONFIG_BACKLIGHT_GENERIC) += generic_bl.o | 19 | obj-$(CONFIG_BACKLIGHT_GENERIC) += generic_bl.o |
18 | obj-$(CONFIG_BACKLIGHT_HP700) += jornada720_bl.o | 20 | obj-$(CONFIG_BACKLIGHT_HP700) += jornada720_bl.o |
19 | obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o | 21 | obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o |
@@ -30,5 +32,7 @@ obj-$(CONFIG_BACKLIGHT_SAHARA) += kb3886_bl.o | |||
30 | obj-$(CONFIG_BACKLIGHT_WM831X) += wm831x_bl.o | 32 | obj-$(CONFIG_BACKLIGHT_WM831X) += wm831x_bl.o |
31 | obj-$(CONFIG_BACKLIGHT_ADX) += adx_bl.o | 33 | obj-$(CONFIG_BACKLIGHT_ADX) += adx_bl.o |
32 | obj-$(CONFIG_BACKLIGHT_ADP5520) += adp5520_bl.o | 34 | obj-$(CONFIG_BACKLIGHT_ADP5520) += adp5520_bl.o |
35 | obj-$(CONFIG_BACKLIGHT_ADP8860) += adp8860_bl.o | ||
33 | obj-$(CONFIG_BACKLIGHT_88PM860X) += 88pm860x_bl.o | 36 | obj-$(CONFIG_BACKLIGHT_88PM860X) += 88pm860x_bl.o |
37 | obj-$(CONFIG_BACKLIGHT_PCF50633) += pcf50633-backlight.o | ||
34 | 38 | ||
diff --git a/drivers/video/backlight/adp8860_bl.c b/drivers/video/backlight/adp8860_bl.c new file mode 100644 index 000000000000..921ca37398f3 --- /dev/null +++ b/drivers/video/backlight/adp8860_bl.c | |||
@@ -0,0 +1,838 @@ | |||
1 | /* | ||
2 | * Backlight driver for Analog Devices ADP8860 Backlight Devices | ||
3 | * | ||
4 | * Copyright 2009-2010 Analog Devices Inc. | ||
5 | * | ||
6 | * Licensed under the GPL-2 or later. | ||
7 | */ | ||
8 | |||
9 | #include <linux/module.h> | ||
10 | #include <linux/version.h> | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/errno.h> | ||
13 | #include <linux/pm.h> | ||
14 | #include <linux/platform_device.h> | ||
15 | #include <linux/i2c.h> | ||
16 | #include <linux/fb.h> | ||
17 | #include <linux/backlight.h> | ||
18 | #include <linux/leds.h> | ||
19 | #include <linux/slab.h> | ||
20 | #include <linux/workqueue.h> | ||
21 | |||
22 | #include <linux/i2c/adp8860.h> | ||
23 | #define ADP8860_EXT_FEATURES | ||
24 | #define ADP8860_USE_LEDS | ||
25 | |||
26 | #define ADP8860_MFDVID 0x00 /* Manufacturer and device ID */ | ||
27 | #define ADP8860_MDCR 0x01 /* Device mode and status */ | ||
28 | #define ADP8860_MDCR2 0x02 /* Device mode and Status Register 2 */ | ||
29 | #define ADP8860_INTR_EN 0x03 /* Interrupts enable */ | ||
30 | #define ADP8860_CFGR 0x04 /* Configuration register */ | ||
31 | #define ADP8860_BLSEN 0x05 /* Sink enable backlight or independent */ | ||
32 | #define ADP8860_BLOFF 0x06 /* Backlight off timeout */ | ||
33 | #define ADP8860_BLDIM 0x07 /* Backlight dim timeout */ | ||
34 | #define ADP8860_BLFR 0x08 /* Backlight fade in and out rates */ | ||
35 | #define ADP8860_BLMX1 0x09 /* Backlight (Brightness Level 1-daylight) maximum current */ | ||
36 | #define ADP8860_BLDM1 0x0A /* Backlight (Brightness Level 1-daylight) dim current */ | ||
37 | #define ADP8860_BLMX2 0x0B /* Backlight (Brightness Level 2-office) maximum current */ | ||
38 | #define ADP8860_BLDM2 0x0C /* Backlight (Brightness Level 2-office) dim current */ | ||
39 | #define ADP8860_BLMX3 0x0D /* Backlight (Brightness Level 3-dark) maximum current */ | ||
40 | #define ADP8860_BLDM3 0x0E /* Backlight (Brightness Level 3-dark) dim current */ | ||
41 | #define ADP8860_ISCFR 0x0F /* Independent sink current fade control register */ | ||
42 | #define ADP8860_ISCC 0x10 /* Independent sink current control register */ | ||
43 | #define ADP8860_ISCT1 0x11 /* Independent Sink Current Timer Register LED[7:5] */ | ||
44 | #define ADP8860_ISCT2 0x12 /* Independent Sink Current Timer Register LED[4:1] */ | ||
45 | #define ADP8860_ISCF 0x13 /* Independent sink current fade register */ | ||
46 | #define ADP8860_ISC7 0x14 /* Independent Sink Current LED7 */ | ||
47 | #define ADP8860_ISC6 0x15 /* Independent Sink Current LED6 */ | ||
48 | #define ADP8860_ISC5 0x16 /* Independent Sink Current LED5 */ | ||
49 | #define ADP8860_ISC4 0x17 /* Independent Sink Current LED4 */ | ||
50 | #define ADP8860_ISC3 0x18 /* Independent Sink Current LED3 */ | ||
51 | #define ADP8860_ISC2 0x19 /* Independent Sink Current LED2 */ | ||
52 | #define ADP8860_ISC1 0x1A /* Independent Sink Current LED1 */ | ||
53 | #define ADP8860_CCFG 0x1B /* Comparator configuration */ | ||
54 | #define ADP8860_CCFG2 0x1C /* Second comparator configuration */ | ||
55 | #define ADP8860_L2_TRP 0x1D /* L2 comparator reference */ | ||
56 | #define ADP8860_L2_HYS 0x1E /* L2 hysteresis */ | ||
57 | #define ADP8860_L3_TRP 0x1F /* L3 comparator reference */ | ||
58 | #define ADP8860_L3_HYS 0x20 /* L3 hysteresis */ | ||
59 | #define ADP8860_PH1LEVL 0x21 /* First phototransistor ambient light level-low byte register */ | ||
60 | #define ADP8860_PH1LEVH 0x22 /* First phototransistor ambient light level-high byte register */ | ||
61 | #define ADP8860_PH2LEVL 0x23 /* Second phototransistor ambient light level-low byte register */ | ||
62 | #define ADP8860_PH2LEVH 0x24 /* Second phototransistor ambient light level-high byte register */ | ||
63 | |||
64 | #define ADP8860_MANUFID 0x0 /* Analog Devices ADP8860 Manufacturer ID */ | ||
65 | #define ADP8861_MANUFID 0x4 /* Analog Devices ADP8861 Manufacturer ID */ | ||
66 | #define ADP8863_MANUFID 0x2 /* Analog Devices ADP8863 Manufacturer ID */ | ||
67 | |||
68 | #define ADP8860_DEVID(x) ((x) & 0xF) | ||
69 | #define ADP8860_MANID(x) ((x) >> 4) | ||
70 | |||
71 | /* MDCR Device mode and status */ | ||
72 | #define INT_CFG (1 << 6) | ||
73 | #define NSTBY (1 << 5) | ||
74 | #define DIM_EN (1 << 4) | ||
75 | #define GDWN_DIS (1 << 3) | ||
76 | #define SIS_EN (1 << 2) | ||
77 | #define CMP_AUTOEN (1 << 1) | ||
78 | #define BLEN (1 << 0) | ||
79 | |||
80 | /* ADP8860_CCFG Main ALS comparator level enable */ | ||
81 | #define L3_EN (1 << 1) | ||
82 | #define L2_EN (1 << 0) | ||
83 | |||
84 | #define CFGR_BLV_SHIFT 3 | ||
85 | #define CFGR_BLV_MASK 0x3 | ||
86 | #define ADP8860_FLAG_LED_MASK 0xFF | ||
87 | |||
88 | #define FADE_VAL(in, out) ((0xF & (in)) | ((0xF & (out)) << 4)) | ||
89 | #define BL_CFGR_VAL(law, blv) ((((blv) & CFGR_BLV_MASK) << CFGR_BLV_SHIFT) | ((0x3 & (law)) << 1)) | ||
90 | #define ALS_CCFG_VAL(filt) ((0x7 & filt) << 5) | ||
91 | |||
92 | enum { | ||
93 | adp8860, | ||
94 | adp8861, | ||
95 | adp8863 | ||
96 | }; | ||
97 | |||
98 | struct adp8860_led { | ||
99 | struct led_classdev cdev; | ||
100 | struct work_struct work; | ||
101 | struct i2c_client *client; | ||
102 | enum led_brightness new_brightness; | ||
103 | int id; | ||
104 | int flags; | ||
105 | }; | ||
106 | |||
107 | struct adp8860_bl { | ||
108 | struct i2c_client *client; | ||
109 | struct backlight_device *bl; | ||
110 | struct adp8860_led *led; | ||
111 | struct adp8860_backlight_platform_data *pdata; | ||
112 | struct mutex lock; | ||
113 | unsigned long cached_daylight_max; | ||
114 | int id; | ||
115 | int revid; | ||
116 | int current_brightness; | ||
117 | unsigned en_ambl_sens:1; | ||
118 | unsigned gdwn_dis:1; | ||
119 | }; | ||
120 | |||
121 | static int adp8860_read(struct i2c_client *client, int reg, uint8_t *val) | ||
122 | { | ||
123 | int ret; | ||
124 | |||
125 | ret = i2c_smbus_read_byte_data(client, reg); | ||
126 | if (ret < 0) { | ||
127 | dev_err(&client->dev, "failed reading at 0x%02x\n", reg); | ||
128 | return ret; | ||
129 | } | ||
130 | |||
131 | *val = (uint8_t)ret; | ||
132 | return 0; | ||
133 | } | ||
134 | |||
135 | static int adp8860_write(struct i2c_client *client, u8 reg, u8 val) | ||
136 | { | ||
137 | return i2c_smbus_write_byte_data(client, reg, val); | ||
138 | } | ||
139 | |||
140 | static int adp8860_set_bits(struct i2c_client *client, int reg, uint8_t bit_mask) | ||
141 | { | ||
142 | struct adp8860_bl *data = i2c_get_clientdata(client); | ||
143 | uint8_t reg_val; | ||
144 | int ret; | ||
145 | |||
146 | mutex_lock(&data->lock); | ||
147 | |||
148 | ret = adp8860_read(client, reg, ®_val); | ||
149 | |||
150 | if (!ret && ((reg_val & bit_mask) == 0)) { | ||
151 | reg_val |= bit_mask; | ||
152 | ret = adp8860_write(client, reg, reg_val); | ||
153 | } | ||
154 | |||
155 | mutex_unlock(&data->lock); | ||
156 | return ret; | ||
157 | } | ||
158 | |||
159 | static int adp8860_clr_bits(struct i2c_client *client, int reg, uint8_t bit_mask) | ||
160 | { | ||
161 | struct adp8860_bl *data = i2c_get_clientdata(client); | ||
162 | uint8_t reg_val; | ||
163 | int ret; | ||
164 | |||
165 | mutex_lock(&data->lock); | ||
166 | |||
167 | ret = adp8860_read(client, reg, ®_val); | ||
168 | |||
169 | if (!ret && (reg_val & bit_mask)) { | ||
170 | reg_val &= ~bit_mask; | ||
171 | ret = adp8860_write(client, reg, reg_val); | ||
172 | } | ||
173 | |||
174 | mutex_unlock(&data->lock); | ||
175 | return ret; | ||
176 | } | ||
177 | |||
178 | /* | ||
179 | * Independent sink / LED | ||
180 | */ | ||
181 | #if defined(ADP8860_USE_LEDS) | ||
182 | static void adp8860_led_work(struct work_struct *work) | ||
183 | { | ||
184 | struct adp8860_led *led = container_of(work, struct adp8860_led, work); | ||
185 | adp8860_write(led->client, ADP8860_ISC1 - led->id + 1, | ||
186 | led->new_brightness >> 1); | ||
187 | } | ||
188 | |||
189 | static void adp8860_led_set(struct led_classdev *led_cdev, | ||
190 | enum led_brightness value) | ||
191 | { | ||
192 | struct adp8860_led *led; | ||
193 | |||
194 | led = container_of(led_cdev, struct adp8860_led, cdev); | ||
195 | led->new_brightness = value; | ||
196 | schedule_work(&led->work); | ||
197 | } | ||
198 | |||
199 | static int adp8860_led_setup(struct adp8860_led *led) | ||
200 | { | ||
201 | struct i2c_client *client = led->client; | ||
202 | int ret = 0; | ||
203 | |||
204 | ret = adp8860_write(client, ADP8860_ISC1 - led->id + 1, 0); | ||
205 | ret |= adp8860_set_bits(client, ADP8860_ISCC, 1 << (led->id - 1)); | ||
206 | |||
207 | if (led->id > 4) | ||
208 | ret |= adp8860_set_bits(client, ADP8860_ISCT1, | ||
209 | (led->flags & 0x3) << ((led->id - 5) * 2)); | ||
210 | else | ||
211 | ret |= adp8860_set_bits(client, ADP8860_ISCT2, | ||
212 | (led->flags & 0x3) << ((led->id - 1) * 2)); | ||
213 | |||
214 | return ret; | ||
215 | } | ||
216 | |||
217 | static int __devinit adp8860_led_probe(struct i2c_client *client) | ||
218 | { | ||
219 | struct adp8860_backlight_platform_data *pdata = | ||
220 | client->dev.platform_data; | ||
221 | struct adp8860_bl *data = i2c_get_clientdata(client); | ||
222 | struct adp8860_led *led, *led_dat; | ||
223 | struct led_info *cur_led; | ||
224 | int ret, i; | ||
225 | |||
226 | led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL); | ||
227 | if (led == NULL) { | ||
228 | dev_err(&client->dev, "failed to alloc memory\n"); | ||
229 | return -ENOMEM; | ||
230 | } | ||
231 | |||
232 | ret = adp8860_write(client, ADP8860_ISCFR, pdata->led_fade_law); | ||
233 | ret = adp8860_write(client, ADP8860_ISCT1, | ||
234 | (pdata->led_on_time & 0x3) << 6); | ||
235 | ret |= adp8860_write(client, ADP8860_ISCF, | ||
236 | FADE_VAL(pdata->led_fade_in, pdata->led_fade_out)); | ||
237 | |||
238 | if (ret) { | ||
239 | dev_err(&client->dev, "failed to write\n"); | ||
240 | goto err_free; | ||
241 | } | ||
242 | |||
243 | for (i = 0; i < pdata->num_leds; ++i) { | ||
244 | cur_led = &pdata->leds[i]; | ||
245 | led_dat = &led[i]; | ||
246 | |||
247 | led_dat->id = cur_led->flags & ADP8860_FLAG_LED_MASK; | ||
248 | |||
249 | if (led_dat->id > 7 || led_dat->id < 1) { | ||
250 | dev_err(&client->dev, "Invalid LED ID %d\n", | ||
251 | led_dat->id); | ||
252 | goto err; | ||
253 | } | ||
254 | |||
255 | if (pdata->bl_led_assign & (1 << (led_dat->id - 1))) { | ||
256 | dev_err(&client->dev, "LED %d used by Backlight\n", | ||
257 | led_dat->id); | ||
258 | goto err; | ||
259 | } | ||
260 | |||
261 | led_dat->cdev.name = cur_led->name; | ||
262 | led_dat->cdev.default_trigger = cur_led->default_trigger; | ||
263 | led_dat->cdev.brightness_set = adp8860_led_set; | ||
264 | led_dat->cdev.brightness = LED_OFF; | ||
265 | led_dat->flags = cur_led->flags >> FLAG_OFFT_SHIFT; | ||
266 | led_dat->client = client; | ||
267 | led_dat->new_brightness = LED_OFF; | ||
268 | INIT_WORK(&led_dat->work, adp8860_led_work); | ||
269 | |||
270 | ret = led_classdev_register(&client->dev, &led_dat->cdev); | ||
271 | if (ret) { | ||
272 | dev_err(&client->dev, "failed to register LED %d\n", | ||
273 | led_dat->id); | ||
274 | goto err; | ||
275 | } | ||
276 | |||
277 | ret = adp8860_led_setup(led_dat); | ||
278 | if (ret) { | ||
279 | dev_err(&client->dev, "failed to write\n"); | ||
280 | i++; | ||
281 | goto err; | ||
282 | } | ||
283 | } | ||
284 | |||
285 | data->led = led; | ||
286 | |||
287 | return 0; | ||
288 | |||
289 | err: | ||
290 | for (i = i - 1; i >= 0; --i) { | ||
291 | led_classdev_unregister(&led[i].cdev); | ||
292 | cancel_work_sync(&led[i].work); | ||
293 | } | ||
294 | |||
295 | err_free: | ||
296 | kfree(led); | ||
297 | |||
298 | return ret; | ||
299 | } | ||
300 | |||
301 | static int __devexit adp8860_led_remove(struct i2c_client *client) | ||
302 | { | ||
303 | struct adp8860_backlight_platform_data *pdata = | ||
304 | client->dev.platform_data; | ||
305 | struct adp8860_bl *data = i2c_get_clientdata(client); | ||
306 | int i; | ||
307 | |||
308 | for (i = 0; i < pdata->num_leds; i++) { | ||
309 | led_classdev_unregister(&data->led[i].cdev); | ||
310 | cancel_work_sync(&data->led[i].work); | ||
311 | } | ||
312 | |||
313 | kfree(data->led); | ||
314 | return 0; | ||
315 | } | ||
316 | #else | ||
317 | static int __devinit adp8860_led_probe(struct i2c_client *client) | ||
318 | { | ||
319 | return 0; | ||
320 | } | ||
321 | |||
322 | static int __devexit adp8860_led_remove(struct i2c_client *client) | ||
323 | { | ||
324 | return 0; | ||
325 | } | ||
326 | #endif | ||
327 | |||
328 | static int adp8860_bl_set(struct backlight_device *bl, int brightness) | ||
329 | { | ||
330 | struct adp8860_bl *data = bl_get_data(bl); | ||
331 | struct i2c_client *client = data->client; | ||
332 | int ret = 0; | ||
333 | |||
334 | if (data->en_ambl_sens) { | ||
335 | if ((brightness > 0) && (brightness < ADP8860_MAX_BRIGHTNESS)) { | ||
336 | /* Disable Ambient Light auto adjust */ | ||
337 | ret |= adp8860_clr_bits(client, ADP8860_MDCR, | ||
338 | CMP_AUTOEN); | ||
339 | ret |= adp8860_write(client, ADP8860_BLMX1, brightness); | ||
340 | } else { | ||
341 | /* | ||
342 | * MAX_BRIGHTNESS -> Enable Ambient Light auto adjust | ||
343 | * restore daylight l1 sysfs brightness | ||
344 | */ | ||
345 | ret |= adp8860_write(client, ADP8860_BLMX1, | ||
346 | data->cached_daylight_max); | ||
347 | ret |= adp8860_set_bits(client, ADP8860_MDCR, | ||
348 | CMP_AUTOEN); | ||
349 | } | ||
350 | } else | ||
351 | ret |= adp8860_write(client, ADP8860_BLMX1, brightness); | ||
352 | |||
353 | if (data->current_brightness && brightness == 0) | ||
354 | ret |= adp8860_set_bits(client, | ||
355 | ADP8860_MDCR, DIM_EN); | ||
356 | else if (data->current_brightness == 0 && brightness) | ||
357 | ret |= adp8860_clr_bits(client, | ||
358 | ADP8860_MDCR, DIM_EN); | ||
359 | |||
360 | if (!ret) | ||
361 | data->current_brightness = brightness; | ||
362 | |||
363 | return ret; | ||
364 | } | ||
365 | |||
366 | static int adp8860_bl_update_status(struct backlight_device *bl) | ||
367 | { | ||
368 | int brightness = bl->props.brightness; | ||
369 | if (bl->props.power != FB_BLANK_UNBLANK) | ||
370 | brightness = 0; | ||
371 | |||
372 | if (bl->props.fb_blank != FB_BLANK_UNBLANK) | ||
373 | brightness = 0; | ||
374 | |||
375 | return adp8860_bl_set(bl, brightness); | ||
376 | } | ||
377 | |||
378 | static int adp8860_bl_get_brightness(struct backlight_device *bl) | ||
379 | { | ||
380 | struct adp8860_bl *data = bl_get_data(bl); | ||
381 | |||
382 | return data->current_brightness; | ||
383 | } | ||
384 | |||
385 | static const struct backlight_ops adp8860_bl_ops = { | ||
386 | .update_status = adp8860_bl_update_status, | ||
387 | .get_brightness = adp8860_bl_get_brightness, | ||
388 | }; | ||
389 | |||
390 | static int adp8860_bl_setup(struct backlight_device *bl) | ||
391 | { | ||
392 | struct adp8860_bl *data = bl_get_data(bl); | ||
393 | struct i2c_client *client = data->client; | ||
394 | struct adp8860_backlight_platform_data *pdata = data->pdata; | ||
395 | int ret = 0; | ||
396 | |||
397 | ret |= adp8860_write(client, ADP8860_BLSEN, ~pdata->bl_led_assign); | ||
398 | ret |= adp8860_write(client, ADP8860_BLMX1, pdata->l1_daylight_max); | ||
399 | ret |= adp8860_write(client, ADP8860_BLDM1, pdata->l1_daylight_dim); | ||
400 | |||
401 | if (data->en_ambl_sens) { | ||
402 | data->cached_daylight_max = pdata->l1_daylight_max; | ||
403 | ret |= adp8860_write(client, ADP8860_BLMX2, | ||
404 | pdata->l2_office_max); | ||
405 | ret |= adp8860_write(client, ADP8860_BLDM2, | ||
406 | pdata->l2_office_dim); | ||
407 | ret |= adp8860_write(client, ADP8860_BLMX3, | ||
408 | pdata->l3_dark_max); | ||
409 | ret |= adp8860_write(client, ADP8860_BLDM3, | ||
410 | pdata->l3_dark_dim); | ||
411 | |||
412 | ret |= adp8860_write(client, ADP8860_L2_TRP, pdata->l2_trip); | ||
413 | ret |= adp8860_write(client, ADP8860_L2_HYS, pdata->l2_hyst); | ||
414 | ret |= adp8860_write(client, ADP8860_L3_TRP, pdata->l3_trip); | ||
415 | ret |= adp8860_write(client, ADP8860_L3_HYS, pdata->l3_hyst); | ||
416 | ret |= adp8860_write(client, ADP8860_CCFG, L2_EN | L3_EN | | ||
417 | ALS_CCFG_VAL(pdata->abml_filt)); | ||
418 | } | ||
419 | |||
420 | ret |= adp8860_write(client, ADP8860_CFGR, | ||
421 | BL_CFGR_VAL(pdata->bl_fade_law, 0)); | ||
422 | |||
423 | ret |= adp8860_write(client, ADP8860_BLFR, FADE_VAL(pdata->bl_fade_in, | ||
424 | pdata->bl_fade_out)); | ||
425 | |||
426 | ret |= adp8860_set_bits(client, ADP8860_MDCR, BLEN | DIM_EN | NSTBY | | ||
427 | (data->gdwn_dis ? GDWN_DIS : 0)); | ||
428 | |||
429 | return ret; | ||
430 | } | ||
431 | |||
432 | static ssize_t adp8860_show(struct device *dev, char *buf, int reg) | ||
433 | { | ||
434 | struct adp8860_bl *data = dev_get_drvdata(dev); | ||
435 | int error; | ||
436 | uint8_t reg_val; | ||
437 | |||
438 | mutex_lock(&data->lock); | ||
439 | error = adp8860_read(data->client, reg, ®_val); | ||
440 | mutex_unlock(&data->lock); | ||
441 | |||
442 | if (error < 0) | ||
443 | return error; | ||
444 | |||
445 | return sprintf(buf, "%u\n", reg_val); | ||
446 | } | ||
447 | |||
448 | static ssize_t adp8860_store(struct device *dev, const char *buf, | ||
449 | size_t count, int reg) | ||
450 | { | ||
451 | struct adp8860_bl *data = dev_get_drvdata(dev); | ||
452 | unsigned long val; | ||
453 | int ret; | ||
454 | |||
455 | ret = strict_strtoul(buf, 10, &val); | ||
456 | if (ret) | ||
457 | return ret; | ||
458 | |||
459 | mutex_lock(&data->lock); | ||
460 | adp8860_write(data->client, reg, val); | ||
461 | mutex_unlock(&data->lock); | ||
462 | |||
463 | return count; | ||
464 | } | ||
465 | |||
466 | static ssize_t adp8860_bl_l3_dark_max_show(struct device *dev, | ||
467 | struct device_attribute *attr, char *buf) | ||
468 | { | ||
469 | return adp8860_show(dev, buf, ADP8860_BLMX3); | ||
470 | } | ||
471 | |||
472 | static ssize_t adp8860_bl_l3_dark_max_store(struct device *dev, | ||
473 | struct device_attribute *attr, const char *buf, size_t count) | ||
474 | { | ||
475 | return adp8860_store(dev, buf, count, ADP8860_BLMX3); | ||
476 | } | ||
477 | |||
478 | static DEVICE_ATTR(l3_dark_max, 0664, adp8860_bl_l3_dark_max_show, | ||
479 | adp8860_bl_l3_dark_max_store); | ||
480 | |||
481 | static ssize_t adp8860_bl_l2_office_max_show(struct device *dev, | ||
482 | struct device_attribute *attr, char *buf) | ||
483 | { | ||
484 | return adp8860_show(dev, buf, ADP8860_BLMX2); | ||
485 | } | ||
486 | |||
487 | static ssize_t adp8860_bl_l2_office_max_store(struct device *dev, | ||
488 | struct device_attribute *attr, const char *buf, size_t count) | ||
489 | { | ||
490 | return adp8860_store(dev, buf, count, ADP8860_BLMX2); | ||
491 | } | ||
492 | static DEVICE_ATTR(l2_office_max, 0664, adp8860_bl_l2_office_max_show, | ||
493 | adp8860_bl_l2_office_max_store); | ||
494 | |||
495 | static ssize_t adp8860_bl_l1_daylight_max_show(struct device *dev, | ||
496 | struct device_attribute *attr, char *buf) | ||
497 | { | ||
498 | return adp8860_show(dev, buf, ADP8860_BLMX1); | ||
499 | } | ||
500 | |||
501 | static ssize_t adp8860_bl_l1_daylight_max_store(struct device *dev, | ||
502 | struct device_attribute *attr, const char *buf, size_t count) | ||
503 | { | ||
504 | struct adp8860_bl *data = dev_get_drvdata(dev); | ||
505 | |||
506 | strict_strtoul(buf, 10, &data->cached_daylight_max); | ||
507 | return adp8860_store(dev, buf, count, ADP8860_BLMX1); | ||
508 | } | ||
509 | static DEVICE_ATTR(l1_daylight_max, 0664, adp8860_bl_l1_daylight_max_show, | ||
510 | adp8860_bl_l1_daylight_max_store); | ||
511 | |||
512 | static ssize_t adp8860_bl_l3_dark_dim_show(struct device *dev, | ||
513 | struct device_attribute *attr, char *buf) | ||
514 | { | ||
515 | return adp8860_show(dev, buf, ADP8860_BLDM3); | ||
516 | } | ||
517 | |||
518 | static ssize_t adp8860_bl_l3_dark_dim_store(struct device *dev, | ||
519 | struct device_attribute *attr, | ||
520 | const char *buf, size_t count) | ||
521 | { | ||
522 | return adp8860_store(dev, buf, count, ADP8860_BLDM3); | ||
523 | } | ||
524 | static DEVICE_ATTR(l3_dark_dim, 0664, adp8860_bl_l3_dark_dim_show, | ||
525 | adp8860_bl_l3_dark_dim_store); | ||
526 | |||
527 | static ssize_t adp8860_bl_l2_office_dim_show(struct device *dev, | ||
528 | struct device_attribute *attr, char *buf) | ||
529 | { | ||
530 | return adp8860_show(dev, buf, ADP8860_BLDM2); | ||
531 | } | ||
532 | |||
533 | static ssize_t adp8860_bl_l2_office_dim_store(struct device *dev, | ||
534 | struct device_attribute *attr, | ||
535 | const char *buf, size_t count) | ||
536 | { | ||
537 | return adp8860_store(dev, buf, count, ADP8860_BLDM2); | ||
538 | } | ||
539 | static DEVICE_ATTR(l2_office_dim, 0664, adp8860_bl_l2_office_dim_show, | ||
540 | adp8860_bl_l2_office_dim_store); | ||
541 | |||
542 | static ssize_t adp8860_bl_l1_daylight_dim_show(struct device *dev, | ||
543 | struct device_attribute *attr, char *buf) | ||
544 | { | ||
545 | return adp8860_show(dev, buf, ADP8860_BLDM1); | ||
546 | } | ||
547 | |||
548 | static ssize_t adp8860_bl_l1_daylight_dim_store(struct device *dev, | ||
549 | struct device_attribute *attr, | ||
550 | const char *buf, size_t count) | ||
551 | { | ||
552 | return adp8860_store(dev, buf, count, ADP8860_BLDM1); | ||
553 | } | ||
554 | static DEVICE_ATTR(l1_daylight_dim, 0664, adp8860_bl_l1_daylight_dim_show, | ||
555 | adp8860_bl_l1_daylight_dim_store); | ||
556 | |||
557 | #ifdef ADP8860_EXT_FEATURES | ||
558 | static ssize_t adp8860_bl_ambient_light_level_show(struct device *dev, | ||
559 | struct device_attribute *attr, char *buf) | ||
560 | { | ||
561 | struct adp8860_bl *data = dev_get_drvdata(dev); | ||
562 | int error; | ||
563 | uint8_t reg_val; | ||
564 | uint16_t ret_val; | ||
565 | |||
566 | mutex_lock(&data->lock); | ||
567 | error = adp8860_read(data->client, ADP8860_PH1LEVL, ®_val); | ||
568 | ret_val = reg_val; | ||
569 | error |= adp8860_read(data->client, ADP8860_PH1LEVH, ®_val); | ||
570 | mutex_unlock(&data->lock); | ||
571 | |||
572 | if (error < 0) | ||
573 | return error; | ||
574 | |||
575 | /* Return 13-bit conversion value for the first light sensor */ | ||
576 | ret_val += (reg_val & 0x1F) << 8; | ||
577 | |||
578 | return sprintf(buf, "%u\n", ret_val); | ||
579 | } | ||
580 | static DEVICE_ATTR(ambient_light_level, 0444, | ||
581 | adp8860_bl_ambient_light_level_show, NULL); | ||
582 | |||
583 | static ssize_t adp8860_bl_ambient_light_zone_show(struct device *dev, | ||
584 | struct device_attribute *attr, char *buf) | ||
585 | { | ||
586 | struct adp8860_bl *data = dev_get_drvdata(dev); | ||
587 | int error; | ||
588 | uint8_t reg_val; | ||
589 | |||
590 | mutex_lock(&data->lock); | ||
591 | error = adp8860_read(data->client, ADP8860_CFGR, ®_val); | ||
592 | mutex_unlock(&data->lock); | ||
593 | |||
594 | if (error < 0) | ||
595 | return error; | ||
596 | |||
597 | return sprintf(buf, "%u\n", | ||
598 | ((reg_val >> CFGR_BLV_SHIFT) & CFGR_BLV_MASK) + 1); | ||
599 | } | ||
600 | |||
601 | static ssize_t adp8860_bl_ambient_light_zone_store(struct device *dev, | ||
602 | struct device_attribute *attr, | ||
603 | const char *buf, size_t count) | ||
604 | { | ||
605 | struct adp8860_bl *data = dev_get_drvdata(dev); | ||
606 | unsigned long val; | ||
607 | uint8_t reg_val; | ||
608 | int ret; | ||
609 | |||
610 | ret = strict_strtoul(buf, 10, &val); | ||
611 | if (ret) | ||
612 | return ret; | ||
613 | |||
614 | if (val == 0) { | ||
615 | /* Enable automatic ambient light sensing */ | ||
616 | adp8860_set_bits(data->client, ADP8860_MDCR, CMP_AUTOEN); | ||
617 | } else if ((val > 0) && (val < 6)) { | ||
618 | /* Disable automatic ambient light sensing */ | ||
619 | adp8860_clr_bits(data->client, ADP8860_MDCR, CMP_AUTOEN); | ||
620 | |||
621 | /* Set user supplied ambient light zone */ | ||
622 | mutex_lock(&data->lock); | ||
623 | adp8860_read(data->client, ADP8860_CFGR, ®_val); | ||
624 | reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT); | ||
625 | reg_val |= val << CFGR_BLV_SHIFT; | ||
626 | adp8860_write(data->client, ADP8860_CFGR, reg_val); | ||
627 | mutex_unlock(&data->lock); | ||
628 | } | ||
629 | |||
630 | return count; | ||
631 | } | ||
632 | static DEVICE_ATTR(ambient_light_zone, 0664, | ||
633 | adp8860_bl_ambient_light_zone_show, | ||
634 | adp8860_bl_ambient_light_zone_store); | ||
635 | #endif | ||
636 | |||
637 | static struct attribute *adp8860_bl_attributes[] = { | ||
638 | &dev_attr_l3_dark_max.attr, | ||
639 | &dev_attr_l3_dark_dim.attr, | ||
640 | &dev_attr_l2_office_max.attr, | ||
641 | &dev_attr_l2_office_dim.attr, | ||
642 | &dev_attr_l1_daylight_max.attr, | ||
643 | &dev_attr_l1_daylight_dim.attr, | ||
644 | #ifdef ADP8860_EXT_FEATURES | ||
645 | &dev_attr_ambient_light_level.attr, | ||
646 | &dev_attr_ambient_light_zone.attr, | ||
647 | #endif | ||
648 | NULL | ||
649 | }; | ||
650 | |||
651 | static const struct attribute_group adp8860_bl_attr_group = { | ||
652 | .attrs = adp8860_bl_attributes, | ||
653 | }; | ||
654 | |||
655 | static int __devinit adp8860_probe(struct i2c_client *client, | ||
656 | const struct i2c_device_id *id) | ||
657 | { | ||
658 | struct backlight_device *bl; | ||
659 | struct adp8860_bl *data; | ||
660 | struct adp8860_backlight_platform_data *pdata = | ||
661 | client->dev.platform_data; | ||
662 | struct backlight_properties props; | ||
663 | uint8_t reg_val; | ||
664 | int ret; | ||
665 | |||
666 | if (!i2c_check_functionality(client->adapter, | ||
667 | I2C_FUNC_SMBUS_BYTE_DATA)) { | ||
668 | dev_err(&client->dev, "SMBUS Byte Data not Supported\n"); | ||
669 | return -EIO; | ||
670 | } | ||
671 | |||
672 | if (!pdata) { | ||
673 | dev_err(&client->dev, "no platform data?\n"); | ||
674 | return -EINVAL; | ||
675 | } | ||
676 | |||
677 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
678 | if (data == NULL) | ||
679 | return -ENOMEM; | ||
680 | |||
681 | ret = adp8860_read(client, ADP8860_MFDVID, ®_val); | ||
682 | if (ret < 0) | ||
683 | goto out2; | ||
684 | |||
685 | switch (ADP8860_MANID(reg_val)) { | ||
686 | case ADP8863_MANUFID: | ||
687 | data->gdwn_dis = !!pdata->gdwn_dis; | ||
688 | case ADP8860_MANUFID: | ||
689 | data->en_ambl_sens = !!pdata->en_ambl_sens; | ||
690 | break; | ||
691 | case ADP8861_MANUFID: | ||
692 | data->gdwn_dis = !!pdata->gdwn_dis; | ||
693 | break; | ||
694 | default: | ||
695 | dev_err(&client->dev, "failed to probe\n"); | ||
696 | ret = -ENODEV; | ||
697 | goto out2; | ||
698 | } | ||
699 | |||
700 | /* It's confirmed that the DEVID field is actually a REVID */ | ||
701 | |||
702 | data->revid = ADP8860_DEVID(reg_val); | ||
703 | data->client = client; | ||
704 | data->pdata = pdata; | ||
705 | data->id = id->driver_data; | ||
706 | data->current_brightness = 0; | ||
707 | i2c_set_clientdata(client, data); | ||
708 | |||
709 | memset(&props, 0, sizeof(props)); | ||
710 | props.max_brightness = ADP8860_MAX_BRIGHTNESS; | ||
711 | |||
712 | mutex_init(&data->lock); | ||
713 | |||
714 | bl = backlight_device_register(dev_driver_string(&client->dev), | ||
715 | &client->dev, data, &adp8860_bl_ops, &props); | ||
716 | if (IS_ERR(bl)) { | ||
717 | dev_err(&client->dev, "failed to register backlight\n"); | ||
718 | ret = PTR_ERR(bl); | ||
719 | goto out2; | ||
720 | } | ||
721 | |||
722 | bl->props.max_brightness = | ||
723 | bl->props.brightness = ADP8860_MAX_BRIGHTNESS; | ||
724 | |||
725 | data->bl = bl; | ||
726 | |||
727 | if (data->en_ambl_sens) | ||
728 | ret = sysfs_create_group(&bl->dev.kobj, | ||
729 | &adp8860_bl_attr_group); | ||
730 | |||
731 | if (ret) { | ||
732 | dev_err(&client->dev, "failed to register sysfs\n"); | ||
733 | goto out1; | ||
734 | } | ||
735 | |||
736 | ret = adp8860_bl_setup(bl); | ||
737 | if (ret) { | ||
738 | ret = -EIO; | ||
739 | goto out; | ||
740 | } | ||
741 | |||
742 | backlight_update_status(bl); | ||
743 | |||
744 | dev_info(&client->dev, "%s Rev.%d Backlight\n", | ||
745 | client->name, data->revid); | ||
746 | |||
747 | if (pdata->num_leds) | ||
748 | adp8860_led_probe(client); | ||
749 | |||
750 | return 0; | ||
751 | |||
752 | out: | ||
753 | if (data->en_ambl_sens) | ||
754 | sysfs_remove_group(&data->bl->dev.kobj, | ||
755 | &adp8860_bl_attr_group); | ||
756 | out1: | ||
757 | backlight_device_unregister(bl); | ||
758 | out2: | ||
759 | i2c_set_clientdata(client, NULL); | ||
760 | kfree(data); | ||
761 | |||
762 | return ret; | ||
763 | } | ||
764 | |||
765 | static int __devexit adp8860_remove(struct i2c_client *client) | ||
766 | { | ||
767 | struct adp8860_bl *data = i2c_get_clientdata(client); | ||
768 | |||
769 | adp8860_clr_bits(client, ADP8860_MDCR, NSTBY); | ||
770 | |||
771 | if (data->led) | ||
772 | adp8860_led_remove(client); | ||
773 | |||
774 | if (data->en_ambl_sens) | ||
775 | sysfs_remove_group(&data->bl->dev.kobj, | ||
776 | &adp8860_bl_attr_group); | ||
777 | |||
778 | backlight_device_unregister(data->bl); | ||
779 | i2c_set_clientdata(client, NULL); | ||
780 | kfree(data); | ||
781 | |||
782 | return 0; | ||
783 | } | ||
784 | |||
785 | #ifdef CONFIG_PM | ||
786 | static int adp8860_i2c_suspend(struct i2c_client *client, pm_message_t message) | ||
787 | { | ||
788 | adp8860_clr_bits(client, ADP8860_MDCR, NSTBY); | ||
789 | |||
790 | return 0; | ||
791 | } | ||
792 | |||
793 | static int adp8860_i2c_resume(struct i2c_client *client) | ||
794 | { | ||
795 | adp8860_set_bits(client, ADP8860_MDCR, NSTBY); | ||
796 | |||
797 | return 0; | ||
798 | } | ||
799 | #else | ||
800 | #define adp8860_i2c_suspend NULL | ||
801 | #define adp8860_i2c_resume NULL | ||
802 | #endif | ||
803 | |||
804 | static const struct i2c_device_id adp8860_id[] = { | ||
805 | { "adp8860", adp8860 }, | ||
806 | { "adp8861", adp8861 }, | ||
807 | { "adp8863", adp8863 }, | ||
808 | { } | ||
809 | }; | ||
810 | MODULE_DEVICE_TABLE(i2c, adp8860_id); | ||
811 | |||
812 | static struct i2c_driver adp8860_driver = { | ||
813 | .driver = { | ||
814 | .name = KBUILD_MODNAME, | ||
815 | }, | ||
816 | .probe = adp8860_probe, | ||
817 | .remove = __devexit_p(adp8860_remove), | ||
818 | .suspend = adp8860_i2c_suspend, | ||
819 | .resume = adp8860_i2c_resume, | ||
820 | .id_table = adp8860_id, | ||
821 | }; | ||
822 | |||
823 | static int __init adp8860_init(void) | ||
824 | { | ||
825 | return i2c_add_driver(&adp8860_driver); | ||
826 | } | ||
827 | module_init(adp8860_init); | ||
828 | |||
829 | static void __exit adp8860_exit(void) | ||
830 | { | ||
831 | i2c_del_driver(&adp8860_driver); | ||
832 | } | ||
833 | module_exit(adp8860_exit); | ||
834 | |||
835 | MODULE_LICENSE("GPL v2"); | ||
836 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); | ||
837 | MODULE_DESCRIPTION("ADP8860 Backlight driver"); | ||
838 | MODULE_ALIAS("i2c:adp8860-backlight"); | ||
diff --git a/drivers/video/backlight/adx_bl.c b/drivers/video/backlight/adx_bl.c index 7f4a7c30a98b..fe9af129c5dd 100644 --- a/drivers/video/backlight/adx_bl.c +++ b/drivers/video/backlight/adx_bl.c | |||
@@ -107,8 +107,8 @@ static int __devinit adx_backlight_probe(struct platform_device *pdev) | |||
107 | props.max_brightness = 0xff; | 107 | props.max_brightness = 0xff; |
108 | bldev = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, | 108 | bldev = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, |
109 | bl, &adx_backlight_ops, &props); | 109 | bl, &adx_backlight_ops, &props); |
110 | if (!bldev) { | 110 | if (IS_ERR(bldev)) { |
111 | ret = -ENOMEM; | 111 | ret = PTR_ERR(bldev); |
112 | goto out; | 112 | goto out; |
113 | } | 113 | } |
114 | 114 | ||
diff --git a/drivers/video/backlight/ep93xx_bl.c b/drivers/video/backlight/ep93xx_bl.c new file mode 100644 index 000000000000..b0cc49184803 --- /dev/null +++ b/drivers/video/backlight/ep93xx_bl.c | |||
@@ -0,0 +1,160 @@ | |||
1 | /* | ||
2 | * Driver for the Cirrus EP93xx lcd backlight | ||
3 | * | ||
4 | * Copyright (c) 2010 H Hartley Sweeten <hsweeten@visionengravers.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This driver controls the pulse width modulated brightness control output, | ||
11 | * BRIGHT, on the Cirrus EP9307, EP9312, and EP9315 processors. | ||
12 | */ | ||
13 | |||
14 | |||
15 | #include <linux/platform_device.h> | ||
16 | #include <linux/io.h> | ||
17 | #include <linux/fb.h> | ||
18 | #include <linux/backlight.h> | ||
19 | |||
20 | #include <mach/hardware.h> | ||
21 | |||
22 | #define EP93XX_RASTER_REG(x) (EP93XX_RASTER_BASE + (x)) | ||
23 | #define EP93XX_RASTER_BRIGHTNESS EP93XX_RASTER_REG(0x20) | ||
24 | |||
25 | #define EP93XX_MAX_COUNT 255 | ||
26 | #define EP93XX_MAX_BRIGHT 255 | ||
27 | #define EP93XX_DEF_BRIGHT 128 | ||
28 | |||
29 | struct ep93xxbl { | ||
30 | void __iomem *mmio; | ||
31 | int brightness; | ||
32 | }; | ||
33 | |||
34 | static int ep93xxbl_set(struct backlight_device *bl, int brightness) | ||
35 | { | ||
36 | struct ep93xxbl *ep93xxbl = bl_get_data(bl); | ||
37 | |||
38 | __raw_writel((brightness << 8) | EP93XX_MAX_COUNT, ep93xxbl->mmio); | ||
39 | |||
40 | ep93xxbl->brightness = brightness; | ||
41 | |||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | static int ep93xxbl_update_status(struct backlight_device *bl) | ||
46 | { | ||
47 | int brightness = bl->props.brightness; | ||
48 | |||
49 | if (bl->props.power != FB_BLANK_UNBLANK || | ||
50 | bl->props.fb_blank != FB_BLANK_UNBLANK) | ||
51 | brightness = 0; | ||
52 | |||
53 | return ep93xxbl_set(bl, brightness); | ||
54 | } | ||
55 | |||
56 | static int ep93xxbl_get_brightness(struct backlight_device *bl) | ||
57 | { | ||
58 | struct ep93xxbl *ep93xxbl = bl_get_data(bl); | ||
59 | |||
60 | return ep93xxbl->brightness; | ||
61 | } | ||
62 | |||
63 | static const struct backlight_ops ep93xxbl_ops = { | ||
64 | .update_status = ep93xxbl_update_status, | ||
65 | .get_brightness = ep93xxbl_get_brightness, | ||
66 | }; | ||
67 | |||
68 | static int __init ep93xxbl_probe(struct platform_device *dev) | ||
69 | { | ||
70 | struct ep93xxbl *ep93xxbl; | ||
71 | struct backlight_device *bl; | ||
72 | struct backlight_properties props; | ||
73 | |||
74 | ep93xxbl = devm_kzalloc(&dev->dev, sizeof(*ep93xxbl), GFP_KERNEL); | ||
75 | if (!ep93xxbl) | ||
76 | return -ENOMEM; | ||
77 | |||
78 | /* | ||
79 | * This register is located in the range already ioremap'ed by | ||
80 | * the framebuffer driver. A MFD driver seems a bit of overkill | ||
81 | * to handle this so use the static I/O mapping; this address | ||
82 | * is already virtual. | ||
83 | * | ||
84 | * NOTE: No locking is required; the framebuffer does not touch | ||
85 | * this register. | ||
86 | */ | ||
87 | ep93xxbl->mmio = EP93XX_RASTER_BRIGHTNESS; | ||
88 | |||
89 | memset(&props, 0, sizeof(struct backlight_properties)); | ||
90 | props.max_brightness = EP93XX_MAX_BRIGHT; | ||
91 | bl = backlight_device_register(dev->name, &dev->dev, ep93xxbl, | ||
92 | &ep93xxbl_ops, &props); | ||
93 | if (IS_ERR(bl)) | ||
94 | return PTR_ERR(bl); | ||
95 | |||
96 | bl->props.brightness = EP93XX_DEF_BRIGHT; | ||
97 | |||
98 | platform_set_drvdata(dev, bl); | ||
99 | |||
100 | ep93xxbl_update_status(bl); | ||
101 | |||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | static int ep93xxbl_remove(struct platform_device *dev) | ||
106 | { | ||
107 | struct backlight_device *bl = platform_get_drvdata(dev); | ||
108 | |||
109 | backlight_device_unregister(bl); | ||
110 | platform_set_drvdata(dev, NULL); | ||
111 | return 0; | ||
112 | } | ||
113 | |||
114 | #ifdef CONFIG_PM | ||
115 | static int ep93xxbl_suspend(struct platform_device *dev, pm_message_t state) | ||
116 | { | ||
117 | struct backlight_device *bl = platform_get_drvdata(dev); | ||
118 | |||
119 | return ep93xxbl_set(bl, 0); | ||
120 | } | ||
121 | |||
122 | static int ep93xxbl_resume(struct platform_device *dev) | ||
123 | { | ||
124 | struct backlight_device *bl = platform_get_drvdata(dev); | ||
125 | |||
126 | backlight_update_status(bl); | ||
127 | return 0; | ||
128 | } | ||
129 | #else | ||
130 | #define ep93xxbl_suspend NULL | ||
131 | #define ep93xxbl_resume NULL | ||
132 | #endif | ||
133 | |||
134 | static struct platform_driver ep93xxbl_driver = { | ||
135 | .driver = { | ||
136 | .name = "ep93xx-bl", | ||
137 | .owner = THIS_MODULE, | ||
138 | }, | ||
139 | .probe = ep93xxbl_probe, | ||
140 | .remove = __devexit_p(ep93xxbl_remove), | ||
141 | .suspend = ep93xxbl_suspend, | ||
142 | .resume = ep93xxbl_resume, | ||
143 | }; | ||
144 | |||
145 | static int __init ep93xxbl_init(void) | ||
146 | { | ||
147 | return platform_driver_register(&ep93xxbl_driver); | ||
148 | } | ||
149 | module_init(ep93xxbl_init); | ||
150 | |||
151 | static void __exit ep93xxbl_exit(void) | ||
152 | { | ||
153 | platform_driver_unregister(&ep93xxbl_driver); | ||
154 | } | ||
155 | module_exit(ep93xxbl_exit); | ||
156 | |||
157 | MODULE_DESCRIPTION("EP93xx Backlight Driver"); | ||
158 | MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>"); | ||
159 | MODULE_LICENSE("GPL"); | ||
160 | MODULE_ALIAS("platform:ep93xx-bl"); | ||
diff --git a/drivers/video/backlight/l4f00242t03.c b/drivers/video/backlight/l4f00242t03.c index bcdb12c93efd..9093ef0fa869 100644 --- a/drivers/video/backlight/l4f00242t03.c +++ b/drivers/video/backlight/l4f00242t03.c | |||
@@ -125,8 +125,7 @@ static int __devinit l4f00242t03_probe(struct spi_device *spi) | |||
125 | 125 | ||
126 | if (priv == NULL) { | 126 | if (priv == NULL) { |
127 | dev_err(&spi->dev, "No memory for this device.\n"); | 127 | dev_err(&spi->dev, "No memory for this device.\n"); |
128 | ret = -ENOMEM; | 128 | return -ENOMEM; |
129 | goto err; | ||
130 | } | 129 | } |
131 | 130 | ||
132 | dev_set_drvdata(&spi->dev, priv); | 131 | dev_set_drvdata(&spi->dev, priv); |
@@ -139,7 +138,7 @@ static int __devinit l4f00242t03_probe(struct spi_device *spi) | |||
139 | if (ret) { | 138 | if (ret) { |
140 | dev_err(&spi->dev, | 139 | dev_err(&spi->dev, |
141 | "Unable to get the lcd l4f00242t03 reset gpio.\n"); | 140 | "Unable to get the lcd l4f00242t03 reset gpio.\n"); |
142 | return ret; | 141 | goto err; |
143 | } | 142 | } |
144 | 143 | ||
145 | ret = gpio_direction_output(pdata->reset_gpio, 1); | 144 | ret = gpio_direction_output(pdata->reset_gpio, 1); |
@@ -151,7 +150,7 @@ static int __devinit l4f00242t03_probe(struct spi_device *spi) | |||
151 | if (ret) { | 150 | if (ret) { |
152 | dev_err(&spi->dev, | 151 | dev_err(&spi->dev, |
153 | "Unable to get the lcd l4f00242t03 data en gpio.\n"); | 152 | "Unable to get the lcd l4f00242t03 data en gpio.\n"); |
154 | return ret; | 153 | goto err2; |
155 | } | 154 | } |
156 | 155 | ||
157 | ret = gpio_direction_output(pdata->data_enable_gpio, 0); | 156 | ret = gpio_direction_output(pdata->data_enable_gpio, 0); |
@@ -222,9 +221,9 @@ static int __devexit l4f00242t03_remove(struct spi_device *spi) | |||
222 | gpio_free(pdata->reset_gpio); | 221 | gpio_free(pdata->reset_gpio); |
223 | 222 | ||
224 | if (priv->io_reg) | 223 | if (priv->io_reg) |
225 | regulator_put(priv->core_reg); | ||
226 | if (priv->core_reg) | ||
227 | regulator_put(priv->io_reg); | 224 | regulator_put(priv->io_reg); |
225 | if (priv->core_reg) | ||
226 | regulator_put(priv->core_reg); | ||
228 | 227 | ||
229 | kfree(priv); | 228 | kfree(priv); |
230 | 229 | ||
diff --git a/drivers/video/backlight/max8925_bl.c b/drivers/video/backlight/max8925_bl.c index b5accc957ad3..b2b2c7ba1f63 100644 --- a/drivers/video/backlight/max8925_bl.c +++ b/drivers/video/backlight/max8925_bl.c | |||
@@ -162,6 +162,7 @@ static int __devinit max8925_backlight_probe(struct platform_device *pdev) | |||
162 | backlight_update_status(bl); | 162 | backlight_update_status(bl); |
163 | return 0; | 163 | return 0; |
164 | out: | 164 | out: |
165 | backlight_device_unregister(bl); | ||
165 | kfree(data); | 166 | kfree(data); |
166 | return ret; | 167 | return ret; |
167 | } | 168 | } |
diff --git a/drivers/video/backlight/mbp_nvidia_bl.c b/drivers/video/backlight/mbp_nvidia_bl.c index 1b5d3fe6bbbc..9fb533f6373e 100644 --- a/drivers/video/backlight/mbp_nvidia_bl.c +++ b/drivers/video/backlight/mbp_nvidia_bl.c | |||
@@ -141,7 +141,7 @@ static const struct dmi_system_id __initdata mbp_device_table[] = { | |||
141 | .callback = mbp_dmi_match, | 141 | .callback = mbp_dmi_match, |
142 | .ident = "MacBook 1,1", | 142 | .ident = "MacBook 1,1", |
143 | .matches = { | 143 | .matches = { |
144 | DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), | 144 | DMI_MATCH(DMI_SYS_VENDOR, "Apple Computer, Inc."), |
145 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBook1,1"), | 145 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBook1,1"), |
146 | }, | 146 | }, |
147 | .driver_data = (void *)&intel_chipset_data, | 147 | .driver_data = (void *)&intel_chipset_data, |
@@ -184,6 +184,42 @@ static const struct dmi_system_id __initdata mbp_device_table[] = { | |||
184 | }, | 184 | }, |
185 | { | 185 | { |
186 | .callback = mbp_dmi_match, | 186 | .callback = mbp_dmi_match, |
187 | .ident = "MacBookPro 1,1", | ||
188 | .matches = { | ||
189 | DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), | ||
190 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro1,1"), | ||
191 | }, | ||
192 | .driver_data = (void *)&intel_chipset_data, | ||
193 | }, | ||
194 | { | ||
195 | .callback = mbp_dmi_match, | ||
196 | .ident = "MacBookPro 1,2", | ||
197 | .matches = { | ||
198 | DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), | ||
199 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro1,2"), | ||
200 | }, | ||
201 | .driver_data = (void *)&intel_chipset_data, | ||
202 | }, | ||
203 | { | ||
204 | .callback = mbp_dmi_match, | ||
205 | .ident = "MacBookPro 2,1", | ||
206 | .matches = { | ||
207 | DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), | ||
208 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro2,1"), | ||
209 | }, | ||
210 | .driver_data = (void *)&intel_chipset_data, | ||
211 | }, | ||
212 | { | ||
213 | .callback = mbp_dmi_match, | ||
214 | .ident = "MacBookPro 2,2", | ||
215 | .matches = { | ||
216 | DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), | ||
217 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro2,2"), | ||
218 | }, | ||
219 | .driver_data = (void *)&intel_chipset_data, | ||
220 | }, | ||
221 | { | ||
222 | .callback = mbp_dmi_match, | ||
187 | .ident = "MacBookPro 3,1", | 223 | .ident = "MacBookPro 3,1", |
188 | .matches = { | 224 | .matches = { |
189 | DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), | 225 | DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), |
@@ -238,6 +274,15 @@ static const struct dmi_system_id __initdata mbp_device_table[] = { | |||
238 | }, | 274 | }, |
239 | { | 275 | { |
240 | .callback = mbp_dmi_match, | 276 | .callback = mbp_dmi_match, |
277 | .ident = "MacBook 6,1", | ||
278 | .matches = { | ||
279 | DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), | ||
280 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBook6,1"), | ||
281 | }, | ||
282 | .driver_data = (void *)&nvidia_chipset_data, | ||
283 | }, | ||
284 | { | ||
285 | .callback = mbp_dmi_match, | ||
241 | .ident = "MacBookAir 2,1", | 286 | .ident = "MacBookAir 2,1", |
242 | .matches = { | 287 | .matches = { |
243 | DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), | 288 | DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), |
diff --git a/drivers/video/backlight/pcf50633-backlight.c b/drivers/video/backlight/pcf50633-backlight.c new file mode 100644 index 000000000000..3c424f7efdcc --- /dev/null +++ b/drivers/video/backlight/pcf50633-backlight.c | |||
@@ -0,0 +1,190 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de> | ||
3 | * PCF50633 backlight device driver | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of the GNU General Public License as published by the | ||
7 | * Free Software Foundation; either version 2 of the License, or (at your | ||
8 | * option) any later version. | ||
9 | * | ||
10 | * You should have received a copy of the GNU General Public License along | ||
11 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
12 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/slab.h> | ||
19 | #include <linux/platform_device.h> | ||
20 | |||
21 | #include <linux/backlight.h> | ||
22 | #include <linux/fb.h> | ||
23 | |||
24 | #include <linux/mfd/pcf50633/core.h> | ||
25 | #include <linux/mfd/pcf50633/backlight.h> | ||
26 | |||
27 | struct pcf50633_bl { | ||
28 | struct pcf50633 *pcf; | ||
29 | struct backlight_device *bl; | ||
30 | |||
31 | unsigned int brightness; | ||
32 | unsigned int brightness_limit; | ||
33 | }; | ||
34 | |||
35 | /* | ||
36 | * pcf50633_bl_set_brightness_limit | ||
37 | * | ||
38 | * Update the brightness limit for the pc50633 backlight. The actual brightness | ||
39 | * will not go above the limit. This is useful to limit power drain for example | ||
40 | * on low battery. | ||
41 | * | ||
42 | * @dev: Pointer to a pcf50633 device | ||
43 | * @limit: The brightness limit. Valid values are 0-63 | ||
44 | */ | ||
45 | int pcf50633_bl_set_brightness_limit(struct pcf50633 *pcf, unsigned int limit) | ||
46 | { | ||
47 | struct pcf50633_bl *pcf_bl = platform_get_drvdata(pcf->bl_pdev); | ||
48 | |||
49 | if (!pcf_bl) | ||
50 | return -ENODEV; | ||
51 | |||
52 | pcf_bl->brightness_limit = limit & 0x3f; | ||
53 | backlight_update_status(pcf_bl->bl); | ||
54 | |||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | static int pcf50633_bl_update_status(struct backlight_device *bl) | ||
59 | { | ||
60 | struct pcf50633_bl *pcf_bl = bl_get_data(bl); | ||
61 | unsigned int new_brightness; | ||
62 | |||
63 | |||
64 | if (bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK) || | ||
65 | bl->props.power != FB_BLANK_UNBLANK) | ||
66 | new_brightness = 0; | ||
67 | else if (bl->props.brightness < pcf_bl->brightness_limit) | ||
68 | new_brightness = bl->props.brightness; | ||
69 | else | ||
70 | new_brightness = pcf_bl->brightness_limit; | ||
71 | |||
72 | |||
73 | if (pcf_bl->brightness == new_brightness) | ||
74 | return 0; | ||
75 | |||
76 | if (new_brightness) { | ||
77 | pcf50633_reg_write(pcf_bl->pcf, PCF50633_REG_LEDOUT, | ||
78 | new_brightness); | ||
79 | if (!pcf_bl->brightness) | ||
80 | pcf50633_reg_write(pcf_bl->pcf, PCF50633_REG_LEDENA, 1); | ||
81 | } else { | ||
82 | pcf50633_reg_write(pcf_bl->pcf, PCF50633_REG_LEDENA, 0); | ||
83 | } | ||
84 | |||
85 | pcf_bl->brightness = new_brightness; | ||
86 | |||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | static int pcf50633_bl_get_brightness(struct backlight_device *bl) | ||
91 | { | ||
92 | struct pcf50633_bl *pcf_bl = bl_get_data(bl); | ||
93 | return pcf_bl->brightness; | ||
94 | } | ||
95 | |||
96 | static const struct backlight_ops pcf50633_bl_ops = { | ||
97 | .get_brightness = pcf50633_bl_get_brightness, | ||
98 | .update_status = pcf50633_bl_update_status, | ||
99 | .options = BL_CORE_SUSPENDRESUME, | ||
100 | }; | ||
101 | |||
102 | static int __devinit pcf50633_bl_probe(struct platform_device *pdev) | ||
103 | { | ||
104 | int ret; | ||
105 | struct pcf50633_bl *pcf_bl; | ||
106 | struct device *parent = pdev->dev.parent; | ||
107 | struct pcf50633_platform_data *pcf50633_data = parent->platform_data; | ||
108 | struct pcf50633_bl_platform_data *pdata = pcf50633_data->backlight_data; | ||
109 | struct backlight_properties bl_props; | ||
110 | |||
111 | pcf_bl = kzalloc(sizeof(*pcf_bl), GFP_KERNEL); | ||
112 | if (!pcf_bl) | ||
113 | return -ENOMEM; | ||
114 | |||
115 | bl_props.max_brightness = 0x3f; | ||
116 | bl_props.power = FB_BLANK_UNBLANK; | ||
117 | |||
118 | if (pdata) { | ||
119 | bl_props.brightness = pdata->default_brightness; | ||
120 | pcf_bl->brightness_limit = pdata->default_brightness_limit; | ||
121 | } else { | ||
122 | bl_props.brightness = 0x3f; | ||
123 | pcf_bl->brightness_limit = 0x3f; | ||
124 | } | ||
125 | |||
126 | pcf_bl->pcf = dev_to_pcf50633(pdev->dev.parent); | ||
127 | |||
128 | pcf_bl->bl = backlight_device_register(pdev->name, &pdev->dev, pcf_bl, | ||
129 | &pcf50633_bl_ops, &bl_props); | ||
130 | |||
131 | if (IS_ERR(pcf_bl->bl)) { | ||
132 | ret = PTR_ERR(pcf_bl->bl); | ||
133 | goto err_free; | ||
134 | } | ||
135 | |||
136 | platform_set_drvdata(pdev, pcf_bl); | ||
137 | |||
138 | pcf50633_reg_write(pcf_bl->pcf, PCF50633_REG_LEDDIM, pdata->ramp_time); | ||
139 | |||
140 | /* Should be different from bl_props.brightness, so we do not exit | ||
141 | * update_status early the first time it's called */ | ||
142 | pcf_bl->brightness = pcf_bl->bl->props.brightness + 1; | ||
143 | |||
144 | backlight_update_status(pcf_bl->bl); | ||
145 | |||
146 | return 0; | ||
147 | |||
148 | err_free: | ||
149 | kfree(pcf_bl); | ||
150 | |||
151 | return ret; | ||
152 | } | ||
153 | |||
154 | static int __devexit pcf50633_bl_remove(struct platform_device *pdev) | ||
155 | { | ||
156 | struct pcf50633_bl *pcf_bl = platform_get_drvdata(pdev); | ||
157 | |||
158 | backlight_device_unregister(pcf_bl->bl); | ||
159 | |||
160 | platform_set_drvdata(pdev, NULL); | ||
161 | |||
162 | kfree(pcf_bl); | ||
163 | |||
164 | return 0; | ||
165 | } | ||
166 | |||
167 | static struct platform_driver pcf50633_bl_driver = { | ||
168 | .probe = pcf50633_bl_probe, | ||
169 | .remove = __devexit_p(pcf50633_bl_remove), | ||
170 | .driver = { | ||
171 | .name = "pcf50633-backlight", | ||
172 | }, | ||
173 | }; | ||
174 | |||
175 | static int __init pcf50633_bl_init(void) | ||
176 | { | ||
177 | return platform_driver_register(&pcf50633_bl_driver); | ||
178 | } | ||
179 | module_init(pcf50633_bl_init); | ||
180 | |||
181 | static void __exit pcf50633_bl_exit(void) | ||
182 | { | ||
183 | platform_driver_unregister(&pcf50633_bl_driver); | ||
184 | } | ||
185 | module_exit(pcf50633_bl_exit); | ||
186 | |||
187 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); | ||
188 | MODULE_DESCRIPTION("PCF50633 backlight driver"); | ||
189 | MODULE_LICENSE("GPL"); | ||
190 | MODULE_ALIAS("platform:pcf50633-backlight"); | ||
diff --git a/drivers/video/backlight/s6e63m0.c b/drivers/video/backlight/s6e63m0.c new file mode 100644 index 000000000000..a3128c9cb7ad --- /dev/null +++ b/drivers/video/backlight/s6e63m0.c | |||
@@ -0,0 +1,920 @@ | |||
1 | /* | ||
2 | * S6E63M0 AMOLED LCD panel driver. | ||
3 | * | ||
4 | * Author: InKi Dae <inki.dae@samsung.com> | ||
5 | * | ||
6 | * Derived from drivers/video/omap/lcd-apollon.c | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, but | ||
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License along | ||
19 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
20 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
21 | */ | ||
22 | |||
23 | #include <linux/wait.h> | ||
24 | #include <linux/fb.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/gpio.h> | ||
27 | #include <linux/spi/spi.h> | ||
28 | #include <linux/irq.h> | ||
29 | #include <linux/interrupt.h> | ||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/lcd.h> | ||
32 | #include <linux/backlight.h> | ||
33 | |||
34 | #include "s6e63m0_gamma.h" | ||
35 | |||
36 | #define SLEEPMSEC 0x1000 | ||
37 | #define ENDDEF 0x2000 | ||
38 | #define DEFMASK 0xFF00 | ||
39 | #define COMMAND_ONLY 0xFE | ||
40 | #define DATA_ONLY 0xFF | ||
41 | |||
42 | #define MIN_BRIGHTNESS 0 | ||
43 | #define MAX_BRIGHTNESS 10 | ||
44 | |||
45 | #define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL) | ||
46 | |||
47 | struct s6e63m0 { | ||
48 | struct device *dev; | ||
49 | struct spi_device *spi; | ||
50 | unsigned int power; | ||
51 | unsigned int current_brightness; | ||
52 | unsigned int gamma_mode; | ||
53 | unsigned int gamma_table_count; | ||
54 | struct lcd_device *ld; | ||
55 | struct backlight_device *bd; | ||
56 | struct lcd_platform_data *lcd_pd; | ||
57 | }; | ||
58 | |||
59 | static const unsigned short SEQ_PANEL_CONDITION_SET[] = { | ||
60 | 0xF8, 0x01, | ||
61 | DATA_ONLY, 0x27, | ||
62 | DATA_ONLY, 0x27, | ||
63 | DATA_ONLY, 0x07, | ||
64 | DATA_ONLY, 0x07, | ||
65 | DATA_ONLY, 0x54, | ||
66 | DATA_ONLY, 0x9f, | ||
67 | DATA_ONLY, 0x63, | ||
68 | DATA_ONLY, 0x86, | ||
69 | DATA_ONLY, 0x1a, | ||
70 | DATA_ONLY, 0x33, | ||
71 | DATA_ONLY, 0x0d, | ||
72 | DATA_ONLY, 0x00, | ||
73 | DATA_ONLY, 0x00, | ||
74 | |||
75 | ENDDEF, 0x0000 | ||
76 | }; | ||
77 | |||
78 | static const unsigned short SEQ_DISPLAY_CONDITION_SET[] = { | ||
79 | 0xf2, 0x02, | ||
80 | DATA_ONLY, 0x03, | ||
81 | DATA_ONLY, 0x1c, | ||
82 | DATA_ONLY, 0x10, | ||
83 | DATA_ONLY, 0x10, | ||
84 | |||
85 | 0xf7, 0x03, | ||
86 | DATA_ONLY, 0x00, | ||
87 | DATA_ONLY, 0x00, | ||
88 | |||
89 | ENDDEF, 0x0000 | ||
90 | }; | ||
91 | |||
92 | static const unsigned short SEQ_GAMMA_SETTING[] = { | ||
93 | 0xfa, 0x00, | ||
94 | DATA_ONLY, 0x18, | ||
95 | DATA_ONLY, 0x08, | ||
96 | DATA_ONLY, 0x24, | ||
97 | DATA_ONLY, 0x64, | ||
98 | DATA_ONLY, 0x56, | ||
99 | DATA_ONLY, 0x33, | ||
100 | DATA_ONLY, 0xb6, | ||
101 | DATA_ONLY, 0xba, | ||
102 | DATA_ONLY, 0xa8, | ||
103 | DATA_ONLY, 0xac, | ||
104 | DATA_ONLY, 0xb1, | ||
105 | DATA_ONLY, 0x9d, | ||
106 | DATA_ONLY, 0xc1, | ||
107 | DATA_ONLY, 0xc1, | ||
108 | DATA_ONLY, 0xb7, | ||
109 | DATA_ONLY, 0x00, | ||
110 | DATA_ONLY, 0x9c, | ||
111 | DATA_ONLY, 0x00, | ||
112 | DATA_ONLY, 0x9f, | ||
113 | DATA_ONLY, 0x00, | ||
114 | DATA_ONLY, 0xd6, | ||
115 | |||
116 | 0xfa, 0x01, | ||
117 | |||
118 | ENDDEF, 0x0000 | ||
119 | }; | ||
120 | |||
121 | static const unsigned short SEQ_ETC_CONDITION_SET[] = { | ||
122 | 0xf6, 0x00, | ||
123 | DATA_ONLY, 0x8c, | ||
124 | DATA_ONLY, 0x07, | ||
125 | |||
126 | 0xb3, 0xc, | ||
127 | |||
128 | 0xb5, 0x2c, | ||
129 | DATA_ONLY, 0x12, | ||
130 | DATA_ONLY, 0x0c, | ||
131 | DATA_ONLY, 0x0a, | ||
132 | DATA_ONLY, 0x10, | ||
133 | DATA_ONLY, 0x0e, | ||
134 | DATA_ONLY, 0x17, | ||
135 | DATA_ONLY, 0x13, | ||
136 | DATA_ONLY, 0x1f, | ||
137 | DATA_ONLY, 0x1a, | ||
138 | DATA_ONLY, 0x2a, | ||
139 | DATA_ONLY, 0x24, | ||
140 | DATA_ONLY, 0x1f, | ||
141 | DATA_ONLY, 0x1b, | ||
142 | DATA_ONLY, 0x1a, | ||
143 | DATA_ONLY, 0x17, | ||
144 | |||
145 | DATA_ONLY, 0x2b, | ||
146 | DATA_ONLY, 0x26, | ||
147 | DATA_ONLY, 0x22, | ||
148 | DATA_ONLY, 0x20, | ||
149 | DATA_ONLY, 0x3a, | ||
150 | DATA_ONLY, 0x34, | ||
151 | DATA_ONLY, 0x30, | ||
152 | DATA_ONLY, 0x2c, | ||
153 | DATA_ONLY, 0x29, | ||
154 | DATA_ONLY, 0x26, | ||
155 | DATA_ONLY, 0x25, | ||
156 | DATA_ONLY, 0x23, | ||
157 | DATA_ONLY, 0x21, | ||
158 | DATA_ONLY, 0x20, | ||
159 | DATA_ONLY, 0x1e, | ||
160 | DATA_ONLY, 0x1e, | ||
161 | |||
162 | 0xb6, 0x00, | ||
163 | DATA_ONLY, 0x00, | ||
164 | DATA_ONLY, 0x11, | ||
165 | DATA_ONLY, 0x22, | ||
166 | DATA_ONLY, 0x33, | ||
167 | DATA_ONLY, 0x44, | ||
168 | DATA_ONLY, 0x44, | ||
169 | DATA_ONLY, 0x44, | ||
170 | |||
171 | DATA_ONLY, 0x55, | ||
172 | DATA_ONLY, 0x55, | ||
173 | DATA_ONLY, 0x66, | ||
174 | DATA_ONLY, 0x66, | ||
175 | DATA_ONLY, 0x66, | ||
176 | DATA_ONLY, 0x66, | ||
177 | DATA_ONLY, 0x66, | ||
178 | DATA_ONLY, 0x66, | ||
179 | |||
180 | 0xb7, 0x2c, | ||
181 | DATA_ONLY, 0x12, | ||
182 | DATA_ONLY, 0x0c, | ||
183 | DATA_ONLY, 0x0a, | ||
184 | DATA_ONLY, 0x10, | ||
185 | DATA_ONLY, 0x0e, | ||
186 | DATA_ONLY, 0x17, | ||
187 | DATA_ONLY, 0x13, | ||
188 | DATA_ONLY, 0x1f, | ||
189 | DATA_ONLY, 0x1a, | ||
190 | DATA_ONLY, 0x2a, | ||
191 | DATA_ONLY, 0x24, | ||
192 | DATA_ONLY, 0x1f, | ||
193 | DATA_ONLY, 0x1b, | ||
194 | DATA_ONLY, 0x1a, | ||
195 | DATA_ONLY, 0x17, | ||
196 | |||
197 | DATA_ONLY, 0x2b, | ||
198 | DATA_ONLY, 0x26, | ||
199 | DATA_ONLY, 0x22, | ||
200 | DATA_ONLY, 0x20, | ||
201 | DATA_ONLY, 0x3a, | ||
202 | DATA_ONLY, 0x34, | ||
203 | DATA_ONLY, 0x30, | ||
204 | DATA_ONLY, 0x2c, | ||
205 | DATA_ONLY, 0x29, | ||
206 | DATA_ONLY, 0x26, | ||
207 | DATA_ONLY, 0x25, | ||
208 | DATA_ONLY, 0x23, | ||
209 | DATA_ONLY, 0x21, | ||
210 | DATA_ONLY, 0x20, | ||
211 | DATA_ONLY, 0x1e, | ||
212 | DATA_ONLY, 0x1e, | ||
213 | |||
214 | 0xb8, 0x00, | ||
215 | DATA_ONLY, 0x00, | ||
216 | DATA_ONLY, 0x11, | ||
217 | DATA_ONLY, 0x22, | ||
218 | DATA_ONLY, 0x33, | ||
219 | DATA_ONLY, 0x44, | ||
220 | DATA_ONLY, 0x44, | ||
221 | DATA_ONLY, 0x44, | ||
222 | |||
223 | DATA_ONLY, 0x55, | ||
224 | DATA_ONLY, 0x55, | ||
225 | DATA_ONLY, 0x66, | ||
226 | DATA_ONLY, 0x66, | ||
227 | DATA_ONLY, 0x66, | ||
228 | DATA_ONLY, 0x66, | ||
229 | DATA_ONLY, 0x66, | ||
230 | DATA_ONLY, 0x66, | ||
231 | |||
232 | 0xb9, 0x2c, | ||
233 | DATA_ONLY, 0x12, | ||
234 | DATA_ONLY, 0x0c, | ||
235 | DATA_ONLY, 0x0a, | ||
236 | DATA_ONLY, 0x10, | ||
237 | DATA_ONLY, 0x0e, | ||
238 | DATA_ONLY, 0x17, | ||
239 | DATA_ONLY, 0x13, | ||
240 | DATA_ONLY, 0x1f, | ||
241 | DATA_ONLY, 0x1a, | ||
242 | DATA_ONLY, 0x2a, | ||
243 | DATA_ONLY, 0x24, | ||
244 | DATA_ONLY, 0x1f, | ||
245 | DATA_ONLY, 0x1b, | ||
246 | DATA_ONLY, 0x1a, | ||
247 | DATA_ONLY, 0x17, | ||
248 | |||
249 | DATA_ONLY, 0x2b, | ||
250 | DATA_ONLY, 0x26, | ||
251 | DATA_ONLY, 0x22, | ||
252 | DATA_ONLY, 0x20, | ||
253 | DATA_ONLY, 0x3a, | ||
254 | DATA_ONLY, 0x34, | ||
255 | DATA_ONLY, 0x30, | ||
256 | DATA_ONLY, 0x2c, | ||
257 | DATA_ONLY, 0x29, | ||
258 | DATA_ONLY, 0x26, | ||
259 | DATA_ONLY, 0x25, | ||
260 | DATA_ONLY, 0x23, | ||
261 | DATA_ONLY, 0x21, | ||
262 | DATA_ONLY, 0x20, | ||
263 | DATA_ONLY, 0x1e, | ||
264 | DATA_ONLY, 0x1e, | ||
265 | |||
266 | 0xba, 0x00, | ||
267 | DATA_ONLY, 0x00, | ||
268 | DATA_ONLY, 0x11, | ||
269 | DATA_ONLY, 0x22, | ||
270 | DATA_ONLY, 0x33, | ||
271 | DATA_ONLY, 0x44, | ||
272 | DATA_ONLY, 0x44, | ||
273 | DATA_ONLY, 0x44, | ||
274 | |||
275 | DATA_ONLY, 0x55, | ||
276 | DATA_ONLY, 0x55, | ||
277 | DATA_ONLY, 0x66, | ||
278 | DATA_ONLY, 0x66, | ||
279 | DATA_ONLY, 0x66, | ||
280 | DATA_ONLY, 0x66, | ||
281 | DATA_ONLY, 0x66, | ||
282 | DATA_ONLY, 0x66, | ||
283 | |||
284 | 0xc1, 0x4d, | ||
285 | DATA_ONLY, 0x96, | ||
286 | DATA_ONLY, 0x1d, | ||
287 | DATA_ONLY, 0x00, | ||
288 | DATA_ONLY, 0x00, | ||
289 | DATA_ONLY, 0x01, | ||
290 | DATA_ONLY, 0xdf, | ||
291 | DATA_ONLY, 0x00, | ||
292 | DATA_ONLY, 0x00, | ||
293 | DATA_ONLY, 0x03, | ||
294 | DATA_ONLY, 0x1f, | ||
295 | DATA_ONLY, 0x00, | ||
296 | DATA_ONLY, 0x00, | ||
297 | DATA_ONLY, 0x00, | ||
298 | DATA_ONLY, 0x00, | ||
299 | DATA_ONLY, 0x00, | ||
300 | DATA_ONLY, 0x00, | ||
301 | DATA_ONLY, 0x00, | ||
302 | DATA_ONLY, 0x00, | ||
303 | DATA_ONLY, 0x03, | ||
304 | DATA_ONLY, 0x06, | ||
305 | DATA_ONLY, 0x09, | ||
306 | DATA_ONLY, 0x0d, | ||
307 | DATA_ONLY, 0x0f, | ||
308 | DATA_ONLY, 0x12, | ||
309 | DATA_ONLY, 0x15, | ||
310 | DATA_ONLY, 0x18, | ||
311 | |||
312 | 0xb2, 0x10, | ||
313 | DATA_ONLY, 0x10, | ||
314 | DATA_ONLY, 0x0b, | ||
315 | DATA_ONLY, 0x05, | ||
316 | |||
317 | ENDDEF, 0x0000 | ||
318 | }; | ||
319 | |||
320 | static const unsigned short SEQ_ACL_ON[] = { | ||
321 | /* ACL on */ | ||
322 | 0xc0, 0x01, | ||
323 | |||
324 | ENDDEF, 0x0000 | ||
325 | }; | ||
326 | |||
327 | static const unsigned short SEQ_ACL_OFF[] = { | ||
328 | /* ACL off */ | ||
329 | 0xc0, 0x00, | ||
330 | |||
331 | ENDDEF, 0x0000 | ||
332 | }; | ||
333 | |||
334 | static const unsigned short SEQ_ELVSS_ON[] = { | ||
335 | /* ELVSS on */ | ||
336 | 0xb1, 0x0b, | ||
337 | |||
338 | ENDDEF, 0x0000 | ||
339 | }; | ||
340 | |||
341 | static const unsigned short SEQ_ELVSS_OFF[] = { | ||
342 | /* ELVSS off */ | ||
343 | 0xb1, 0x0a, | ||
344 | |||
345 | ENDDEF, 0x0000 | ||
346 | }; | ||
347 | |||
348 | static const unsigned short SEQ_STAND_BY_OFF[] = { | ||
349 | 0x11, COMMAND_ONLY, | ||
350 | |||
351 | ENDDEF, 0x0000 | ||
352 | }; | ||
353 | |||
354 | static const unsigned short SEQ_STAND_BY_ON[] = { | ||
355 | 0x10, COMMAND_ONLY, | ||
356 | |||
357 | ENDDEF, 0x0000 | ||
358 | }; | ||
359 | |||
360 | static const unsigned short SEQ_DISPLAY_ON[] = { | ||
361 | 0x29, COMMAND_ONLY, | ||
362 | |||
363 | ENDDEF, 0x0000 | ||
364 | }; | ||
365 | |||
366 | |||
367 | static int s6e63m0_spi_write_byte(struct s6e63m0 *lcd, int addr, int data) | ||
368 | { | ||
369 | u16 buf[1]; | ||
370 | struct spi_message msg; | ||
371 | |||
372 | struct spi_transfer xfer = { | ||
373 | .len = 2, | ||
374 | .tx_buf = buf, | ||
375 | }; | ||
376 | |||
377 | buf[0] = (addr << 8) | data; | ||
378 | |||
379 | spi_message_init(&msg); | ||
380 | spi_message_add_tail(&xfer, &msg); | ||
381 | |||
382 | return spi_sync(lcd->spi, &msg); | ||
383 | } | ||
384 | |||
385 | static int s6e63m0_spi_write(struct s6e63m0 *lcd, unsigned char address, | ||
386 | unsigned char command) | ||
387 | { | ||
388 | int ret = 0; | ||
389 | |||
390 | if (address != DATA_ONLY) | ||
391 | ret = s6e63m0_spi_write_byte(lcd, 0x0, address); | ||
392 | if (command != COMMAND_ONLY) | ||
393 | ret = s6e63m0_spi_write_byte(lcd, 0x1, command); | ||
394 | |||
395 | return ret; | ||
396 | } | ||
397 | |||
398 | static int s6e63m0_panel_send_sequence(struct s6e63m0 *lcd, | ||
399 | const unsigned short *wbuf) | ||
400 | { | ||
401 | int ret = 0, i = 0; | ||
402 | |||
403 | while ((wbuf[i] & DEFMASK) != ENDDEF) { | ||
404 | if ((wbuf[i] & DEFMASK) != SLEEPMSEC) { | ||
405 | ret = s6e63m0_spi_write(lcd, wbuf[i], wbuf[i+1]); | ||
406 | if (ret) | ||
407 | break; | ||
408 | } else | ||
409 | udelay(wbuf[i+1]*1000); | ||
410 | i += 2; | ||
411 | } | ||
412 | |||
413 | return ret; | ||
414 | } | ||
415 | |||
416 | static int _s6e63m0_gamma_ctl(struct s6e63m0 *lcd, const unsigned int *gamma) | ||
417 | { | ||
418 | unsigned int i = 0; | ||
419 | int ret = 0; | ||
420 | |||
421 | /* disable gamma table updating. */ | ||
422 | ret = s6e63m0_spi_write(lcd, 0xfa, 0x00); | ||
423 | if (ret) { | ||
424 | dev_err(lcd->dev, "failed to disable gamma table updating.\n"); | ||
425 | goto gamma_err; | ||
426 | } | ||
427 | |||
428 | for (i = 0 ; i < GAMMA_TABLE_COUNT; i++) { | ||
429 | ret = s6e63m0_spi_write(lcd, DATA_ONLY, gamma[i]); | ||
430 | if (ret) { | ||
431 | dev_err(lcd->dev, "failed to set gamma table.\n"); | ||
432 | goto gamma_err; | ||
433 | } | ||
434 | } | ||
435 | |||
436 | /* update gamma table. */ | ||
437 | ret = s6e63m0_spi_write(lcd, 0xfa, 0x01); | ||
438 | if (ret) | ||
439 | dev_err(lcd->dev, "failed to update gamma table.\n"); | ||
440 | |||
441 | gamma_err: | ||
442 | return ret; | ||
443 | } | ||
444 | |||
445 | static int s6e63m0_gamma_ctl(struct s6e63m0 *lcd, int gamma) | ||
446 | { | ||
447 | int ret = 0; | ||
448 | |||
449 | ret = _s6e63m0_gamma_ctl(lcd, gamma_table.gamma_22_table[gamma]); | ||
450 | |||
451 | return ret; | ||
452 | } | ||
453 | |||
454 | |||
455 | static int s6e63m0_ldi_init(struct s6e63m0 *lcd) | ||
456 | { | ||
457 | int ret, i; | ||
458 | const unsigned short *init_seq[] = { | ||
459 | SEQ_PANEL_CONDITION_SET, | ||
460 | SEQ_DISPLAY_CONDITION_SET, | ||
461 | SEQ_GAMMA_SETTING, | ||
462 | SEQ_ETC_CONDITION_SET, | ||
463 | SEQ_ACL_ON, | ||
464 | SEQ_ELVSS_ON, | ||
465 | }; | ||
466 | |||
467 | for (i = 0; i < ARRAY_SIZE(init_seq); i++) { | ||
468 | ret = s6e63m0_panel_send_sequence(lcd, init_seq[i]); | ||
469 | if (ret) | ||
470 | break; | ||
471 | } | ||
472 | |||
473 | return ret; | ||
474 | } | ||
475 | |||
476 | static int s6e63m0_ldi_enable(struct s6e63m0 *lcd) | ||
477 | { | ||
478 | int ret = 0, i; | ||
479 | const unsigned short *enable_seq[] = { | ||
480 | SEQ_STAND_BY_OFF, | ||
481 | SEQ_DISPLAY_ON, | ||
482 | }; | ||
483 | |||
484 | for (i = 0; i < ARRAY_SIZE(enable_seq); i++) { | ||
485 | ret = s6e63m0_panel_send_sequence(lcd, enable_seq[i]); | ||
486 | if (ret) | ||
487 | break; | ||
488 | } | ||
489 | |||
490 | return ret; | ||
491 | } | ||
492 | |||
493 | static int s6e63m0_ldi_disable(struct s6e63m0 *lcd) | ||
494 | { | ||
495 | int ret; | ||
496 | |||
497 | ret = s6e63m0_panel_send_sequence(lcd, SEQ_STAND_BY_ON); | ||
498 | |||
499 | return ret; | ||
500 | } | ||
501 | |||
502 | static int s6e63m0_power_on(struct s6e63m0 *lcd) | ||
503 | { | ||
504 | int ret = 0; | ||
505 | struct lcd_platform_data *pd = NULL; | ||
506 | struct backlight_device *bd = NULL; | ||
507 | |||
508 | pd = lcd->lcd_pd; | ||
509 | if (!pd) { | ||
510 | dev_err(lcd->dev, "platform data is NULL.\n"); | ||
511 | return -EFAULT; | ||
512 | } | ||
513 | |||
514 | bd = lcd->bd; | ||
515 | if (!bd) { | ||
516 | dev_err(lcd->dev, "backlight device is NULL.\n"); | ||
517 | return -EFAULT; | ||
518 | } | ||
519 | |||
520 | if (!pd->power_on) { | ||
521 | dev_err(lcd->dev, "power_on is NULL.\n"); | ||
522 | return -EFAULT; | ||
523 | } else { | ||
524 | pd->power_on(lcd->ld, 1); | ||
525 | mdelay(pd->power_on_delay); | ||
526 | } | ||
527 | |||
528 | if (!pd->reset) { | ||
529 | dev_err(lcd->dev, "reset is NULL.\n"); | ||
530 | return -EFAULT; | ||
531 | } else { | ||
532 | pd->reset(lcd->ld); | ||
533 | mdelay(pd->reset_delay); | ||
534 | } | ||
535 | |||
536 | ret = s6e63m0_ldi_init(lcd); | ||
537 | if (ret) { | ||
538 | dev_err(lcd->dev, "failed to initialize ldi.\n"); | ||
539 | return ret; | ||
540 | } | ||
541 | |||
542 | ret = s6e63m0_ldi_enable(lcd); | ||
543 | if (ret) { | ||
544 | dev_err(lcd->dev, "failed to enable ldi.\n"); | ||
545 | return ret; | ||
546 | } | ||
547 | |||
548 | /* set brightness to current value after power on or resume. */ | ||
549 | ret = s6e63m0_gamma_ctl(lcd, bd->props.brightness); | ||
550 | if (ret) { | ||
551 | dev_err(lcd->dev, "lcd gamma setting failed.\n"); | ||
552 | return ret; | ||
553 | } | ||
554 | |||
555 | return 0; | ||
556 | } | ||
557 | |||
558 | static int s6e63m0_power_off(struct s6e63m0 *lcd) | ||
559 | { | ||
560 | int ret = 0; | ||
561 | struct lcd_platform_data *pd = NULL; | ||
562 | |||
563 | pd = lcd->lcd_pd; | ||
564 | if (!pd) { | ||
565 | dev_err(lcd->dev, "platform data is NULL.\n"); | ||
566 | return -EFAULT; | ||
567 | } | ||
568 | |||
569 | ret = s6e63m0_ldi_disable(lcd); | ||
570 | if (ret) { | ||
571 | dev_err(lcd->dev, "lcd setting failed.\n"); | ||
572 | return -EIO; | ||
573 | } | ||
574 | |||
575 | mdelay(pd->power_off_delay); | ||
576 | |||
577 | if (!pd->power_on) { | ||
578 | dev_err(lcd->dev, "power_on is NULL.\n"); | ||
579 | return -EFAULT; | ||
580 | } else | ||
581 | pd->power_on(lcd->ld, 0); | ||
582 | |||
583 | return 0; | ||
584 | } | ||
585 | |||
586 | static int s6e63m0_power(struct s6e63m0 *lcd, int power) | ||
587 | { | ||
588 | int ret = 0; | ||
589 | |||
590 | if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power)) | ||
591 | ret = s6e63m0_power_on(lcd); | ||
592 | else if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power)) | ||
593 | ret = s6e63m0_power_off(lcd); | ||
594 | |||
595 | if (!ret) | ||
596 | lcd->power = power; | ||
597 | |||
598 | return ret; | ||
599 | } | ||
600 | |||
601 | static int s6e63m0_set_power(struct lcd_device *ld, int power) | ||
602 | { | ||
603 | struct s6e63m0 *lcd = lcd_get_data(ld); | ||
604 | |||
605 | if (power != FB_BLANK_UNBLANK && power != FB_BLANK_POWERDOWN && | ||
606 | power != FB_BLANK_NORMAL) { | ||
607 | dev_err(lcd->dev, "power value should be 0, 1 or 4.\n"); | ||
608 | return -EINVAL; | ||
609 | } | ||
610 | |||
611 | return s6e63m0_power(lcd, power); | ||
612 | } | ||
613 | |||
614 | static int s6e63m0_get_power(struct lcd_device *ld) | ||
615 | { | ||
616 | struct s6e63m0 *lcd = lcd_get_data(ld); | ||
617 | |||
618 | return lcd->power; | ||
619 | } | ||
620 | |||
621 | static int s6e63m0_get_brightness(struct backlight_device *bd) | ||
622 | { | ||
623 | return bd->props.brightness; | ||
624 | } | ||
625 | |||
626 | static int s6e63m0_set_brightness(struct backlight_device *bd) | ||
627 | { | ||
628 | int ret = 0, brightness = bd->props.brightness; | ||
629 | struct s6e63m0 *lcd = bl_get_data(bd); | ||
630 | |||
631 | if (brightness < MIN_BRIGHTNESS || | ||
632 | brightness > bd->props.max_brightness) { | ||
633 | dev_err(&bd->dev, "lcd brightness should be %d to %d.\n", | ||
634 | MIN_BRIGHTNESS, MAX_BRIGHTNESS); | ||
635 | return -EINVAL; | ||
636 | } | ||
637 | |||
638 | ret = s6e63m0_gamma_ctl(lcd, bd->props.brightness); | ||
639 | if (ret) { | ||
640 | dev_err(&bd->dev, "lcd brightness setting failed.\n"); | ||
641 | return -EIO; | ||
642 | } | ||
643 | |||
644 | return ret; | ||
645 | } | ||
646 | |||
647 | static struct lcd_ops s6e63m0_lcd_ops = { | ||
648 | .set_power = s6e63m0_set_power, | ||
649 | .get_power = s6e63m0_get_power, | ||
650 | }; | ||
651 | |||
652 | static const struct backlight_ops s6e63m0_backlight_ops = { | ||
653 | .get_brightness = s6e63m0_get_brightness, | ||
654 | .update_status = s6e63m0_set_brightness, | ||
655 | }; | ||
656 | |||
657 | static ssize_t s6e63m0_sysfs_show_gamma_mode(struct device *dev, | ||
658 | struct device_attribute *attr, char *buf) | ||
659 | { | ||
660 | struct s6e63m0 *lcd = dev_get_drvdata(dev); | ||
661 | char temp[10]; | ||
662 | |||
663 | switch (lcd->gamma_mode) { | ||
664 | case 0: | ||
665 | sprintf(temp, "2.2 mode\n"); | ||
666 | strcat(buf, temp); | ||
667 | break; | ||
668 | case 1: | ||
669 | sprintf(temp, "1.9 mode\n"); | ||
670 | strcat(buf, temp); | ||
671 | break; | ||
672 | case 2: | ||
673 | sprintf(temp, "1.7 mode\n"); | ||
674 | strcat(buf, temp); | ||
675 | break; | ||
676 | default: | ||
677 | dev_info(dev, "gamma mode could be 0:2.2, 1:1.9 or 2:1.7)n"); | ||
678 | break; | ||
679 | } | ||
680 | |||
681 | return strlen(buf); | ||
682 | } | ||
683 | |||
684 | static ssize_t s6e63m0_sysfs_store_gamma_mode(struct device *dev, | ||
685 | struct device_attribute *attr, | ||
686 | const char *buf, size_t len) | ||
687 | { | ||
688 | struct s6e63m0 *lcd = dev_get_drvdata(dev); | ||
689 | struct backlight_device *bd = NULL; | ||
690 | int brightness, rc; | ||
691 | |||
692 | rc = strict_strtoul(buf, 0, (unsigned long *)&lcd->gamma_mode); | ||
693 | if (rc < 0) | ||
694 | return rc; | ||
695 | |||
696 | bd = lcd->bd; | ||
697 | |||
698 | brightness = bd->props.brightness; | ||
699 | |||
700 | switch (lcd->gamma_mode) { | ||
701 | case 0: | ||
702 | _s6e63m0_gamma_ctl(lcd, gamma_table.gamma_22_table[brightness]); | ||
703 | break; | ||
704 | case 1: | ||
705 | _s6e63m0_gamma_ctl(lcd, gamma_table.gamma_19_table[brightness]); | ||
706 | break; | ||
707 | case 2: | ||
708 | _s6e63m0_gamma_ctl(lcd, gamma_table.gamma_17_table[brightness]); | ||
709 | break; | ||
710 | default: | ||
711 | dev_info(dev, "gamma mode could be 0:2.2, 1:1.9 or 2:1.7\n"); | ||
712 | _s6e63m0_gamma_ctl(lcd, gamma_table.gamma_22_table[brightness]); | ||
713 | break; | ||
714 | } | ||
715 | return len; | ||
716 | } | ||
717 | |||
718 | static DEVICE_ATTR(gamma_mode, 0644, | ||
719 | s6e63m0_sysfs_show_gamma_mode, s6e63m0_sysfs_store_gamma_mode); | ||
720 | |||
721 | static ssize_t s6e63m0_sysfs_show_gamma_table(struct device *dev, | ||
722 | struct device_attribute *attr, char *buf) | ||
723 | { | ||
724 | struct s6e63m0 *lcd = dev_get_drvdata(dev); | ||
725 | char temp[3]; | ||
726 | |||
727 | sprintf(temp, "%d\n", lcd->gamma_table_count); | ||
728 | strcpy(buf, temp); | ||
729 | |||
730 | return strlen(buf); | ||
731 | } | ||
732 | static DEVICE_ATTR(gamma_table, 0644, | ||
733 | s6e63m0_sysfs_show_gamma_table, NULL); | ||
734 | |||
735 | static int __init s6e63m0_probe(struct spi_device *spi) | ||
736 | { | ||
737 | int ret = 0; | ||
738 | struct s6e63m0 *lcd = NULL; | ||
739 | struct lcd_device *ld = NULL; | ||
740 | struct backlight_device *bd = NULL; | ||
741 | |||
742 | lcd = kzalloc(sizeof(struct s6e63m0), GFP_KERNEL); | ||
743 | if (!lcd) | ||
744 | return -ENOMEM; | ||
745 | |||
746 | /* s6e63m0 lcd panel uses 3-wire 9bits SPI Mode. */ | ||
747 | spi->bits_per_word = 9; | ||
748 | |||
749 | ret = spi_setup(spi); | ||
750 | if (ret < 0) { | ||
751 | dev_err(&spi->dev, "spi setup failed.\n"); | ||
752 | goto out_free_lcd; | ||
753 | } | ||
754 | |||
755 | lcd->spi = spi; | ||
756 | lcd->dev = &spi->dev; | ||
757 | |||
758 | lcd->lcd_pd = (struct lcd_platform_data *)spi->dev.platform_data; | ||
759 | if (!lcd->lcd_pd) { | ||
760 | dev_err(&spi->dev, "platform data is NULL.\n"); | ||
761 | goto out_free_lcd; | ||
762 | } | ||
763 | |||
764 | ld = lcd_device_register("s6e63m0", &spi->dev, lcd, &s6e63m0_lcd_ops); | ||
765 | if (IS_ERR(ld)) { | ||
766 | ret = PTR_ERR(ld); | ||
767 | goto out_free_lcd; | ||
768 | } | ||
769 | |||
770 | lcd->ld = ld; | ||
771 | |||
772 | bd = backlight_device_register("s6e63m0bl-bl", &spi->dev, lcd, | ||
773 | &s6e63m0_backlight_ops, NULL); | ||
774 | if (IS_ERR(bd)) { | ||
775 | ret = PTR_ERR(bd); | ||
776 | goto out_lcd_unregister; | ||
777 | } | ||
778 | |||
779 | bd->props.max_brightness = MAX_BRIGHTNESS; | ||
780 | bd->props.brightness = MAX_BRIGHTNESS; | ||
781 | lcd->bd = bd; | ||
782 | |||
783 | /* | ||
784 | * it gets gamma table count available so it gets user | ||
785 | * know that. | ||
786 | */ | ||
787 | lcd->gamma_table_count = | ||
788 | sizeof(gamma_table) / (MAX_GAMMA_LEVEL * sizeof(int)); | ||
789 | |||
790 | ret = device_create_file(&(spi->dev), &dev_attr_gamma_mode); | ||
791 | if (ret < 0) | ||
792 | dev_err(&(spi->dev), "failed to add sysfs entries\n"); | ||
793 | |||
794 | ret = device_create_file(&(spi->dev), &dev_attr_gamma_table); | ||
795 | if (ret < 0) | ||
796 | dev_err(&(spi->dev), "failed to add sysfs entries\n"); | ||
797 | |||
798 | /* | ||
799 | * if lcd panel was on from bootloader like u-boot then | ||
800 | * do not lcd on. | ||
801 | */ | ||
802 | if (!lcd->lcd_pd->lcd_enabled) { | ||
803 | /* | ||
804 | * if lcd panel was off from bootloader then | ||
805 | * current lcd status is powerdown and then | ||
806 | * it enables lcd panel. | ||
807 | */ | ||
808 | lcd->power = FB_BLANK_POWERDOWN; | ||
809 | |||
810 | s6e63m0_power(lcd, FB_BLANK_UNBLANK); | ||
811 | } else | ||
812 | lcd->power = FB_BLANK_UNBLANK; | ||
813 | |||
814 | dev_set_drvdata(&spi->dev, lcd); | ||
815 | |||
816 | dev_info(&spi->dev, "s6e63m0 panel driver has been probed.\n"); | ||
817 | |||
818 | return 0; | ||
819 | |||
820 | out_lcd_unregister: | ||
821 | lcd_device_unregister(ld); | ||
822 | out_free_lcd: | ||
823 | kfree(lcd); | ||
824 | return ret; | ||
825 | } | ||
826 | |||
827 | static int __devexit s6e63m0_remove(struct spi_device *spi) | ||
828 | { | ||
829 | struct s6e63m0 *lcd = dev_get_drvdata(&spi->dev); | ||
830 | |||
831 | s6e63m0_power(lcd, FB_BLANK_POWERDOWN); | ||
832 | lcd_device_unregister(lcd->ld); | ||
833 | kfree(lcd); | ||
834 | |||
835 | return 0; | ||
836 | } | ||
837 | |||
838 | #if defined(CONFIG_PM) | ||
839 | unsigned int before_power; | ||
840 | |||
841 | static int s6e63m0_suspend(struct spi_device *spi, pm_message_t mesg) | ||
842 | { | ||
843 | int ret = 0; | ||
844 | struct s6e63m0 *lcd = dev_get_drvdata(&spi->dev); | ||
845 | |||
846 | dev_dbg(&spi->dev, "lcd->power = %d\n", lcd->power); | ||
847 | |||
848 | before_power = lcd->power; | ||
849 | |||
850 | /* | ||
851 | * when lcd panel is suspend, lcd panel becomes off | ||
852 | * regardless of status. | ||
853 | */ | ||
854 | ret = s6e63m0_power(lcd, FB_BLANK_POWERDOWN); | ||
855 | |||
856 | return ret; | ||
857 | } | ||
858 | |||
859 | static int s6e63m0_resume(struct spi_device *spi) | ||
860 | { | ||
861 | int ret = 0; | ||
862 | struct s6e63m0 *lcd = dev_get_drvdata(&spi->dev); | ||
863 | |||
864 | /* | ||
865 | * after suspended, if lcd panel status is FB_BLANK_UNBLANK | ||
866 | * (at that time, before_power is FB_BLANK_UNBLANK) then | ||
867 | * it changes that status to FB_BLANK_POWERDOWN to get lcd on. | ||
868 | */ | ||
869 | if (before_power == FB_BLANK_UNBLANK) | ||
870 | lcd->power = FB_BLANK_POWERDOWN; | ||
871 | |||
872 | dev_dbg(&spi->dev, "before_power = %d\n", before_power); | ||
873 | |||
874 | ret = s6e63m0_power(lcd, before_power); | ||
875 | |||
876 | return ret; | ||
877 | } | ||
878 | #else | ||
879 | #define s6e63m0_suspend NULL | ||
880 | #define s6e63m0_resume NULL | ||
881 | #endif | ||
882 | |||
883 | /* Power down all displays on reboot, poweroff or halt. */ | ||
884 | static void s6e63m0_shutdown(struct spi_device *spi) | ||
885 | { | ||
886 | struct s6e63m0 *lcd = dev_get_drvdata(&spi->dev); | ||
887 | |||
888 | s6e63m0_power(lcd, FB_BLANK_POWERDOWN); | ||
889 | } | ||
890 | |||
891 | static struct spi_driver s6e63m0_driver = { | ||
892 | .driver = { | ||
893 | .name = "s6e63m0", | ||
894 | .bus = &spi_bus_type, | ||
895 | .owner = THIS_MODULE, | ||
896 | }, | ||
897 | .probe = s6e63m0_probe, | ||
898 | .remove = __devexit_p(s6e63m0_remove), | ||
899 | .shutdown = s6e63m0_shutdown, | ||
900 | .suspend = s6e63m0_suspend, | ||
901 | .resume = s6e63m0_resume, | ||
902 | }; | ||
903 | |||
904 | static int __init s6e63m0_init(void) | ||
905 | { | ||
906 | return spi_register_driver(&s6e63m0_driver); | ||
907 | } | ||
908 | |||
909 | static void __exit s6e63m0_exit(void) | ||
910 | { | ||
911 | spi_unregister_driver(&s6e63m0_driver); | ||
912 | } | ||
913 | |||
914 | module_init(s6e63m0_init); | ||
915 | module_exit(s6e63m0_exit); | ||
916 | |||
917 | MODULE_AUTHOR("InKi Dae <inki.dae@samsung.com>"); | ||
918 | MODULE_DESCRIPTION("S6E63M0 LCD Driver"); | ||
919 | MODULE_LICENSE("GPL"); | ||
920 | |||
diff --git a/drivers/video/backlight/s6e63m0_gamma.h b/drivers/video/backlight/s6e63m0_gamma.h new file mode 100644 index 000000000000..2c44bdb0696b --- /dev/null +++ b/drivers/video/backlight/s6e63m0_gamma.h | |||
@@ -0,0 +1,266 @@ | |||
1 | /* linux/drivers/video/samsung/s6e63m0_brightness.h | ||
2 | * | ||
3 | * Gamma level definitions. | ||
4 | * | ||
5 | * Copyright (c) 2009 Samsung Electronics | ||
6 | * InKi Dae <inki.dae@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 version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | #ifndef _S6E63M0_BRIGHTNESS_H | ||
14 | #define _S6E63M0_BRIGHTNESS_H | ||
15 | |||
16 | #define MAX_GAMMA_LEVEL 11 | ||
17 | #define GAMMA_TABLE_COUNT 21 | ||
18 | |||
19 | /* gamma value: 2.2 */ | ||
20 | static const unsigned int s6e63m0_22_300[] = { | ||
21 | 0x18, 0x08, 0x24, 0x5f, 0x50, 0x2d, 0xB6, | ||
22 | 0xB9, 0xA7, 0xAd, 0xB1, 0x9f, 0xbe, 0xC0, | ||
23 | 0xB5, 0x00, 0xa0, 0x00, 0xa4, 0x00, 0xdb | ||
24 | }; | ||
25 | |||
26 | static const unsigned int s6e63m0_22_280[] = { | ||
27 | 0x18, 0x08, 0x24, 0x64, 0x56, 0x33, 0xB6, | ||
28 | 0xBA, 0xA8, 0xAC, 0xB1, 0x9D, 0xC1, 0xC1, | ||
29 | 0xB7, 0x00, 0x9C, 0x00, 0x9F, 0x00, 0xD6 | ||
30 | }; | ||
31 | |||
32 | static const unsigned int s6e63m0_22_260[] = { | ||
33 | 0x18, 0x08, 0x24, 0x66, 0x58, 0x34, 0xB6, | ||
34 | 0xBA, 0xA7, 0xAF, 0xB3, 0xA0, 0xC1, 0xC2, | ||
35 | 0xB7, 0x00, 0x97, 0x00, 0x9A, 0x00, 0xD1 | ||
36 | |||
37 | }; | ||
38 | |||
39 | static const unsigned int s6e63m0_22_240[] = { | ||
40 | 0x18, 0x08, 0x24, 0x62, 0x54, 0x30, 0xB9, | ||
41 | 0xBB, 0xA9, 0xB0, 0xB3, 0xA1, 0xC1, 0xC3, | ||
42 | 0xB7, 0x00, 0x91, 0x00, 0x95, 0x00, 0xDA | ||
43 | |||
44 | }; | ||
45 | static const unsigned int s6e63m0_22_220[] = { | ||
46 | 0x18, 0x08, 0x24, 0x63, 0x53, 0x31, 0xB8, | ||
47 | 0xBC, 0xA9, 0xB0, 0xB5, 0xA2, 0xC4, 0xC4, | ||
48 | 0xB8, 0x00, 0x8B, 0x00, 0x8E, 0x00, 0xC2 | ||
49 | }; | ||
50 | |||
51 | static const unsigned int s6e63m0_22_200[] = { | ||
52 | 0x18, 0x08, 0x24, 0x66, 0x55, 0x34, 0xBA, | ||
53 | 0xBD, 0xAB, 0xB1, 0xB5, 0xA3, 0xC5, 0xC6, | ||
54 | 0xB9, 0x00, 0x85, 0x00, 0x88, 0x00, 0xBA | ||
55 | }; | ||
56 | |||
57 | static const unsigned int s6e63m0_22_170[] = { | ||
58 | 0x18, 0x08, 0x24, 0x69, 0x54, 0x37, 0xBB, | ||
59 | 0xBE, 0xAC, 0xB4, 0xB7, 0xA6, 0xC7, 0xC8, | ||
60 | 0xBC, 0x00, 0x7B, 0x00, 0x7E, 0x00, 0xAB | ||
61 | }; | ||
62 | |||
63 | static const unsigned int s6e63m0_22_140[] = { | ||
64 | 0x18, 0x08, 0x24, 0x6C, 0x54, 0x3A, 0xBC, | ||
65 | 0xBF, 0xAC, 0xB7, 0xBB, 0xA9, 0xC9, 0xC9, | ||
66 | 0xBE, 0x00, 0x71, 0x00, 0x73, 0x00, 0x9E | ||
67 | }; | ||
68 | |||
69 | static const unsigned int s6e63m0_22_110[] = { | ||
70 | 0x18, 0x08, 0x24, 0x70, 0x51, 0x3E, 0xBF, | ||
71 | 0xC1, 0xAF, 0xB9, 0xBC, 0xAB, 0xCC, 0xCC, | ||
72 | 0xC2, 0x00, 0x65, 0x00, 0x67, 0x00, 0x8D | ||
73 | }; | ||
74 | |||
75 | static const unsigned int s6e63m0_22_90[] = { | ||
76 | 0x18, 0x08, 0x24, 0x73, 0x4A, 0x3D, 0xC0, | ||
77 | 0xC2, 0xB1, 0xBB, 0xBE, 0xAC, 0xCE, 0xCF, | ||
78 | 0xC5, 0x00, 0x5D, 0x00, 0x5E, 0x00, 0x82 | ||
79 | }; | ||
80 | |||
81 | static const unsigned int s6e63m0_22_30[] = { | ||
82 | 0x18, 0x08, 0x24, 0x78, 0xEC, 0x3D, 0xC8, | ||
83 | 0xC2, 0xB6, 0xC4, 0xC7, 0xB6, 0xD5, 0xD7, | ||
84 | 0xCC, 0x00, 0x39, 0x00, 0x36, 0x00, 0x51 | ||
85 | }; | ||
86 | |||
87 | /* gamma value: 1.9 */ | ||
88 | static const unsigned int s6e63m0_19_300[] = { | ||
89 | 0x18, 0x08, 0x24, 0x61, 0x5F, 0x39, 0xBA, | ||
90 | 0xBD, 0xAD, 0xB1, 0xB6, 0xA5, 0xC4, 0xC5, | ||
91 | 0xBC, 0x00, 0xA0, 0x00, 0xA4, 0x00, 0xDB | ||
92 | }; | ||
93 | |||
94 | static const unsigned int s6e63m0_19_280[] = { | ||
95 | 0x18, 0x08, 0x24, 0x61, 0x60, 0x39, 0xBB, | ||
96 | 0xBE, 0xAD, 0xB2, 0xB6, 0xA6, 0xC5, 0xC7, | ||
97 | 0xBD, 0x00, 0x9B, 0x00, 0x9E, 0x00, 0xD5 | ||
98 | }; | ||
99 | |||
100 | static const unsigned int s6e63m0_19_260[] = { | ||
101 | 0x18, 0x08, 0x24, 0x63, 0x61, 0x3B, 0xBA, | ||
102 | 0xBE, 0xAC, 0xB3, 0xB8, 0xA7, 0xC6, 0xC8, | ||
103 | 0xBD, 0x00, 0x96, 0x00, 0x98, 0x00, 0xCF | ||
104 | }; | ||
105 | |||
106 | static const unsigned int s6e63m0_19_240[] = { | ||
107 | 0x18, 0x08, 0x24, 0x67, 0x64, 0x3F, 0xBB, | ||
108 | 0xBE, 0xAD, 0xB3, 0xB9, 0xA7, 0xC8, 0xC9, | ||
109 | 0xBE, 0x00, 0x90, 0x00, 0x92, 0x00, 0xC8 | ||
110 | }; | ||
111 | |||
112 | static const unsigned int s6e63m0_19_220[] = { | ||
113 | 0x18, 0x08, 0x24, 0x68, 0x64, 0x40, 0xBC, | ||
114 | 0xBF, 0xAF, 0xB4, 0xBA, 0xA9, 0xC8, 0xCA, | ||
115 | 0xBE, 0x00, 0x8B, 0x00, 0x8C, 0x00, 0xC0 | ||
116 | }; | ||
117 | |||
118 | static const unsigned int s6e63m0_19_200[] = { | ||
119 | 0x18, 0x08, 0x24, 0x68, 0x64, 0x3F, 0xBE, | ||
120 | 0xC0, 0xB0, 0xB6, 0xBB, 0xAB, 0xC8, 0xCB, | ||
121 | 0xBF, 0x00, 0x85, 0x00, 0x86, 0x00, 0xB8 | ||
122 | }; | ||
123 | |||
124 | static const unsigned int s6e63m0_19_170[] = { | ||
125 | 0x18, 0x08, 0x24, 0x69, 0x64, 0x40, 0xBF, | ||
126 | 0xC1, 0xB0, 0xB9, 0xBE, 0xAD, 0xCB, 0xCD, | ||
127 | 0xC2, 0x00, 0x7A, 0x00, 0x7B, 0x00, 0xAA | ||
128 | }; | ||
129 | |||
130 | static const unsigned int s6e63m0_19_140[] = { | ||
131 | 0x18, 0x08, 0x24, 0x6E, 0x65, 0x45, 0xC0, | ||
132 | 0xC3, 0xB2, 0xBA, 0xBE, 0xAE, 0xCD, 0xD0, | ||
133 | 0xC4, 0x00, 0x70, 0x00, 0x70, 0x00, 0x9C | ||
134 | }; | ||
135 | |||
136 | static const unsigned int s6e63m0_19_110[] = { | ||
137 | 0x18, 0x08, 0x24, 0x6F, 0x65, 0x46, 0xC2, | ||
138 | 0xC4, 0xB3, 0xBF, 0xC2, 0xB2, 0xCF, 0xD1, | ||
139 | 0xC6, 0x00, 0x64, 0x00, 0x64, 0x00, 0x8D | ||
140 | }; | ||
141 | |||
142 | static const unsigned int s6e63m0_19_90[] = { | ||
143 | 0x18, 0x08, 0x24, 0x74, 0x60, 0x4A, 0xC3, | ||
144 | 0xC6, 0xB5, 0xBF, 0xC3, 0xB2, 0xD2, 0xD3, | ||
145 | 0xC8, 0x00, 0x5B, 0x00, 0x5B, 0x00, 0x81 | ||
146 | }; | ||
147 | |||
148 | static const unsigned int s6e63m0_19_30[] = { | ||
149 | 0x18, 0x08, 0x24, 0x84, 0x45, 0x4F, 0xCA, | ||
150 | 0xCB, 0xBC, 0xC9, 0xCB, 0xBC, 0xDA, 0xDA, | ||
151 | 0xD0, 0x00, 0x35, 0x00, 0x34, 0x00, 0x4E | ||
152 | }; | ||
153 | |||
154 | /* gamma value: 1.7 */ | ||
155 | static const unsigned int s6e63m0_17_300[] = { | ||
156 | 0x18, 0x08, 0x24, 0x70, 0x70, 0x4F, 0xBF, | ||
157 | 0xC2, 0xB2, 0xB8, 0xBC, 0xAC, 0xCB, 0xCD, | ||
158 | 0xC3, 0x00, 0xA0, 0x00, 0xA4, 0x00, 0xDB | ||
159 | }; | ||
160 | |||
161 | static const unsigned int s6e63m0_17_280[] = { | ||
162 | 0x18, 0x08, 0x24, 0x71, 0x71, 0x50, 0xBF, | ||
163 | 0xC2, 0xB2, 0xBA, 0xBE, 0xAE, 0xCB, 0xCD, | ||
164 | 0xC3, 0x00, 0x9C, 0x00, 0x9F, 0x00, 0xD6 | ||
165 | }; | ||
166 | |||
167 | static const unsigned int s6e63m0_17_260[] = { | ||
168 | 0x18, 0x08, 0x24, 0x72, 0x72, 0x50, 0xC0, | ||
169 | 0xC3, 0xB4, 0xB9, 0xBE, 0xAE, 0xCC, 0xCF, | ||
170 | 0xC4, 0x00, 0x97, 0x00, 0x9A, 0x00, 0xD1 | ||
171 | }; | ||
172 | |||
173 | static const unsigned int s6e63m0_17_240[] = { | ||
174 | 0x18, 0x08, 0x24, 0x71, 0x72, 0x4F, 0xC2, | ||
175 | 0xC4, 0xB5, 0xBB, 0xBF, 0xB0, 0xCC, 0xCF, | ||
176 | 0xC3, 0x00, 0x91, 0x00, 0x95, 0x00, 0xCA | ||
177 | }; | ||
178 | |||
179 | static const unsigned int s6e63m0_17_220[] = { | ||
180 | 0x18, 0x08, 0x24, 0x71, 0x73, 0x4F, 0xC2, | ||
181 | 0xC5, 0xB5, 0xBD, 0xC0, 0xB2, 0xCD, 0xD1, | ||
182 | 0xC5, 0x00, 0x8B, 0x00, 0x8E, 0x00, 0xC2 | ||
183 | }; | ||
184 | |||
185 | static const unsigned int s6e63m0_17_200[] = { | ||
186 | 0x18, 0x08, 0x24, 0x72, 0x75, 0x51, 0xC2, | ||
187 | 0xC6, 0xB5, 0xBF, 0xC1, 0xB3, 0xCE, 0xD1, | ||
188 | 0xC6, 0x00, 0x85, 0x00, 0x88, 0x00, 0xBA | ||
189 | }; | ||
190 | |||
191 | static const unsigned int s6e63m0_17_170[] = { | ||
192 | 0x18, 0x08, 0x24, 0x75, 0x77, 0x54, 0xC3, | ||
193 | 0xC7, 0xB7, 0xC0, 0xC3, 0xB4, 0xD1, 0xD3, | ||
194 | 0xC9, 0x00, 0x7B, 0x00, 0x7E, 0x00, 0xAB | ||
195 | }; | ||
196 | |||
197 | static const unsigned int s6e63m0_17_140[] = { | ||
198 | 0x18, 0x08, 0x24, 0x7B, 0x77, 0x58, 0xC3, | ||
199 | 0xC8, 0xB8, 0xC2, 0xC6, 0xB6, 0xD3, 0xD4, | ||
200 | 0xCA, 0x00, 0x71, 0x00, 0x73, 0x00, 0x9E | ||
201 | }; | ||
202 | |||
203 | static const unsigned int s6e63m0_17_110[] = { | ||
204 | 0x18, 0x08, 0x24, 0x81, 0x7B, 0x5D, 0xC6, | ||
205 | 0xCA, 0xBB, 0xC3, 0xC7, 0xB8, 0xD6, 0xD8, | ||
206 | 0xCD, 0x00, 0x65, 0x00, 0x67, 0x00, 0x8D | ||
207 | }; | ||
208 | |||
209 | static const unsigned int s6e63m0_17_90[] = { | ||
210 | 0x18, 0x08, 0x24, 0x82, 0x7A, 0x5B, 0xC8, | ||
211 | 0xCB, 0xBD, 0xC5, 0xCA, 0xBA, 0xD6, 0xD8, | ||
212 | 0xCE, 0x00, 0x5D, 0x00, 0x5E, 0x00, 0x82 | ||
213 | }; | ||
214 | |||
215 | static const unsigned int s6e63m0_17_30[] = { | ||
216 | 0x18, 0x08, 0x24, 0x8F, 0x73, 0x63, 0xD1, | ||
217 | 0xD0, 0xC5, 0xCC, 0xD1, 0xC2, 0xDE, 0xE0, | ||
218 | 0xD6, 0x00, 0x39, 0x00, 0x36, 0x00, 0x51 | ||
219 | }; | ||
220 | |||
221 | struct s6e63m0_gamma { | ||
222 | unsigned int *gamma_22_table[MAX_GAMMA_LEVEL]; | ||
223 | unsigned int *gamma_19_table[MAX_GAMMA_LEVEL]; | ||
224 | unsigned int *gamma_17_table[MAX_GAMMA_LEVEL]; | ||
225 | }; | ||
226 | |||
227 | static struct s6e63m0_gamma gamma_table = { | ||
228 | .gamma_22_table[0] = (unsigned int *)&s6e63m0_22_30, | ||
229 | .gamma_22_table[1] = (unsigned int *)&s6e63m0_22_90, | ||
230 | .gamma_22_table[2] = (unsigned int *)&s6e63m0_22_110, | ||
231 | .gamma_22_table[3] = (unsigned int *)&s6e63m0_22_140, | ||
232 | .gamma_22_table[4] = (unsigned int *)&s6e63m0_22_170, | ||
233 | .gamma_22_table[5] = (unsigned int *)&s6e63m0_22_200, | ||
234 | .gamma_22_table[6] = (unsigned int *)&s6e63m0_22_220, | ||
235 | .gamma_22_table[7] = (unsigned int *)&s6e63m0_22_240, | ||
236 | .gamma_22_table[8] = (unsigned int *)&s6e63m0_22_260, | ||
237 | .gamma_22_table[9] = (unsigned int *)&s6e63m0_22_280, | ||
238 | .gamma_22_table[10] = (unsigned int *)&s6e63m0_22_300, | ||
239 | |||
240 | .gamma_19_table[0] = (unsigned int *)&s6e63m0_19_30, | ||
241 | .gamma_19_table[1] = (unsigned int *)&s6e63m0_19_90, | ||
242 | .gamma_19_table[2] = (unsigned int *)&s6e63m0_19_110, | ||
243 | .gamma_19_table[3] = (unsigned int *)&s6e63m0_19_140, | ||
244 | .gamma_19_table[4] = (unsigned int *)&s6e63m0_19_170, | ||
245 | .gamma_19_table[5] = (unsigned int *)&s6e63m0_19_200, | ||
246 | .gamma_19_table[6] = (unsigned int *)&s6e63m0_19_220, | ||
247 | .gamma_19_table[7] = (unsigned int *)&s6e63m0_19_240, | ||
248 | .gamma_19_table[8] = (unsigned int *)&s6e63m0_19_260, | ||
249 | .gamma_19_table[9] = (unsigned int *)&s6e63m0_19_280, | ||
250 | .gamma_19_table[10] = (unsigned int *)&s6e63m0_19_300, | ||
251 | |||
252 | .gamma_17_table[0] = (unsigned int *)&s6e63m0_17_30, | ||
253 | .gamma_17_table[1] = (unsigned int *)&s6e63m0_17_90, | ||
254 | .gamma_17_table[2] = (unsigned int *)&s6e63m0_17_110, | ||
255 | .gamma_17_table[3] = (unsigned int *)&s6e63m0_17_140, | ||
256 | .gamma_17_table[4] = (unsigned int *)&s6e63m0_17_170, | ||
257 | .gamma_17_table[5] = (unsigned int *)&s6e63m0_17_200, | ||
258 | .gamma_17_table[6] = (unsigned int *)&s6e63m0_17_220, | ||
259 | .gamma_17_table[7] = (unsigned int *)&s6e63m0_17_240, | ||
260 | .gamma_17_table[8] = (unsigned int *)&s6e63m0_17_260, | ||
261 | .gamma_17_table[9] = (unsigned int *)&s6e63m0_17_280, | ||
262 | .gamma_17_table[10] = (unsigned int *)&s6e63m0_17_300, | ||
263 | }; | ||
264 | |||
265 | #endif | ||
266 | |||
diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 3da73f5f0ae9..2c60f1f70b38 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h | |||
@@ -248,6 +248,8 @@ int acpi_check_region(resource_size_t start, resource_size_t n, | |||
248 | int acpi_check_mem_region(resource_size_t start, resource_size_t n, | 248 | int acpi_check_mem_region(resource_size_t start, resource_size_t n, |
249 | const char *name); | 249 | const char *name); |
250 | 250 | ||
251 | int acpi_resources_are_enforced(void); | ||
252 | |||
251 | #ifdef CONFIG_PM_SLEEP | 253 | #ifdef CONFIG_PM_SLEEP |
252 | void __init acpi_no_s4_hw_signature(void); | 254 | void __init acpi_no_s4_hw_signature(void); |
253 | void __init acpi_old_suspend_ordering(void); | 255 | void __init acpi_old_suspend_ordering(void); |
diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h index c082f223e2fe..3167f2df4126 100644 --- a/include/linux/ftrace_event.h +++ b/include/linux/ftrace_event.h | |||
@@ -73,18 +73,25 @@ struct trace_iterator { | |||
73 | }; | 73 | }; |
74 | 74 | ||
75 | 75 | ||
76 | struct trace_event; | ||
77 | |||
76 | typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter, | 78 | typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter, |
77 | int flags); | 79 | int flags, struct trace_event *event); |
78 | struct trace_event { | 80 | |
79 | struct hlist_node node; | 81 | struct trace_event_functions { |
80 | struct list_head list; | ||
81 | int type; | ||
82 | trace_print_func trace; | 82 | trace_print_func trace; |
83 | trace_print_func raw; | 83 | trace_print_func raw; |
84 | trace_print_func hex; | 84 | trace_print_func hex; |
85 | trace_print_func binary; | 85 | trace_print_func binary; |
86 | }; | 86 | }; |
87 | 87 | ||
88 | struct trace_event { | ||
89 | struct hlist_node node; | ||
90 | struct list_head list; | ||
91 | int type; | ||
92 | struct trace_event_functions *funcs; | ||
93 | }; | ||
94 | |||
88 | extern int register_ftrace_event(struct trace_event *event); | 95 | extern int register_ftrace_event(struct trace_event *event); |
89 | extern int unregister_ftrace_event(struct trace_event *event); | 96 | extern int unregister_ftrace_event(struct trace_event *event); |
90 | 97 | ||
@@ -116,28 +123,70 @@ void tracing_record_cmdline(struct task_struct *tsk); | |||
116 | 123 | ||
117 | struct event_filter; | 124 | struct event_filter; |
118 | 125 | ||
126 | enum trace_reg { | ||
127 | TRACE_REG_REGISTER, | ||
128 | TRACE_REG_UNREGISTER, | ||
129 | TRACE_REG_PERF_REGISTER, | ||
130 | TRACE_REG_PERF_UNREGISTER, | ||
131 | }; | ||
132 | |||
133 | struct ftrace_event_call; | ||
134 | |||
135 | struct ftrace_event_class { | ||
136 | char *system; | ||
137 | void *probe; | ||
138 | #ifdef CONFIG_PERF_EVENTS | ||
139 | void *perf_probe; | ||
140 | #endif | ||
141 | int (*reg)(struct ftrace_event_call *event, | ||
142 | enum trace_reg type); | ||
143 | int (*define_fields)(struct ftrace_event_call *); | ||
144 | struct list_head *(*get_fields)(struct ftrace_event_call *); | ||
145 | struct list_head fields; | ||
146 | int (*raw_init)(struct ftrace_event_call *); | ||
147 | }; | ||
148 | |||
149 | enum { | ||
150 | TRACE_EVENT_FL_ENABLED_BIT, | ||
151 | TRACE_EVENT_FL_FILTERED_BIT, | ||
152 | }; | ||
153 | |||
154 | enum { | ||
155 | TRACE_EVENT_FL_ENABLED = (1 << TRACE_EVENT_FL_ENABLED_BIT), | ||
156 | TRACE_EVENT_FL_FILTERED = (1 << TRACE_EVENT_FL_FILTERED_BIT), | ||
157 | }; | ||
158 | |||
119 | struct ftrace_event_call { | 159 | struct ftrace_event_call { |
120 | struct list_head list; | 160 | struct list_head list; |
161 | struct ftrace_event_class *class; | ||
121 | char *name; | 162 | char *name; |
122 | char *system; | ||
123 | struct dentry *dir; | 163 | struct dentry *dir; |
124 | struct trace_event *event; | 164 | struct trace_event event; |
125 | int enabled; | ||
126 | int (*regfunc)(struct ftrace_event_call *); | ||
127 | void (*unregfunc)(struct ftrace_event_call *); | ||
128 | int id; | ||
129 | const char *print_fmt; | 165 | const char *print_fmt; |
130 | int (*raw_init)(struct ftrace_event_call *); | ||
131 | int (*define_fields)(struct ftrace_event_call *); | ||
132 | struct list_head fields; | ||
133 | int filter_active; | ||
134 | struct event_filter *filter; | 166 | struct event_filter *filter; |
135 | void *mod; | 167 | void *mod; |
136 | void *data; | 168 | void *data; |
137 | 169 | ||
170 | /* | ||
171 | * 32 bit flags: | ||
172 | * bit 1: enabled | ||
173 | * bit 2: filter_active | ||
174 | * | ||
175 | * Changes to flags must hold the event_mutex. | ||
176 | * | ||
177 | * Note: Reads of flags do not hold the event_mutex since | ||
178 | * they occur in critical sections. But the way flags | ||
179 | * is currently used, these changes do no affect the code | ||
180 | * except that when a change is made, it may have a slight | ||
181 | * delay in propagating the changes to other CPUs due to | ||
182 | * caching and such. | ||
183 | */ | ||
184 | unsigned int flags; | ||
185 | |||
186 | #ifdef CONFIG_PERF_EVENTS | ||
138 | int perf_refcount; | 187 | int perf_refcount; |
139 | int (*perf_event_enable)(struct ftrace_event_call *); | 188 | struct hlist_head *perf_events; |
140 | void (*perf_event_disable)(struct ftrace_event_call *); | 189 | #endif |
141 | }; | 190 | }; |
142 | 191 | ||
143 | #define PERF_MAX_TRACE_SIZE 2048 | 192 | #define PERF_MAX_TRACE_SIZE 2048 |
@@ -194,24 +243,22 @@ struct perf_event; | |||
194 | 243 | ||
195 | DECLARE_PER_CPU(struct pt_regs, perf_trace_regs); | 244 | DECLARE_PER_CPU(struct pt_regs, perf_trace_regs); |
196 | 245 | ||
197 | extern int perf_trace_enable(int event_id); | 246 | extern int perf_trace_init(struct perf_event *event); |
198 | extern void perf_trace_disable(int event_id); | 247 | extern void perf_trace_destroy(struct perf_event *event); |
199 | extern int ftrace_profile_set_filter(struct perf_event *event, int event_id, | 248 | extern int perf_trace_enable(struct perf_event *event); |
249 | extern void perf_trace_disable(struct perf_event *event); | ||
250 | extern int ftrace_profile_set_filter(struct perf_event *event, int event_id, | ||
200 | char *filter_str); | 251 | char *filter_str); |
201 | extern void ftrace_profile_free_filter(struct perf_event *event); | 252 | extern void ftrace_profile_free_filter(struct perf_event *event); |
202 | extern void * | 253 | extern void *perf_trace_buf_prepare(int size, unsigned short type, |
203 | perf_trace_buf_prepare(int size, unsigned short type, int *rctxp, | 254 | struct pt_regs *regs, int *rctxp); |
204 | unsigned long *irq_flags); | ||
205 | 255 | ||
206 | static inline void | 256 | static inline void |
207 | perf_trace_buf_submit(void *raw_data, int size, int rctx, u64 addr, | 257 | perf_trace_buf_submit(void *raw_data, int size, int rctx, u64 addr, |
208 | u64 count, unsigned long irq_flags, struct pt_regs *regs) | 258 | u64 count, struct pt_regs *regs, void *head) |
209 | { | 259 | { |
210 | struct trace_entry *entry = raw_data; | 260 | perf_tp_event(addr, count, raw_data, size, regs, head); |
211 | |||
212 | perf_tp_event(entry->type, addr, count, raw_data, size, regs); | ||
213 | perf_swevent_put_recursion_context(rctx); | 261 | perf_swevent_put_recursion_context(rctx); |
214 | local_irq_restore(irq_flags); | ||
215 | } | 262 | } |
216 | #endif | 263 | #endif |
217 | 264 | ||
diff --git a/include/linux/i2c/adp8860.h b/include/linux/i2c/adp8860.h new file mode 100644 index 000000000000..0b4d39855c91 --- /dev/null +++ b/include/linux/i2c/adp8860.h | |||
@@ -0,0 +1,154 @@ | |||
1 | /* | ||
2 | * Definitions and platform data for Analog Devices | ||
3 | * Backlight drivers ADP8860 | ||
4 | * | ||
5 | * Copyright 2009-2010 Analog Devices Inc. | ||
6 | * | ||
7 | * Licensed under the GPL-2 or later. | ||
8 | */ | ||
9 | |||
10 | #ifndef __LINUX_I2C_ADP8860_H | ||
11 | #define __LINUX_I2C_ADP8860_H | ||
12 | |||
13 | #include <linux/leds.h> | ||
14 | #include <linux/types.h> | ||
15 | |||
16 | #define ID_ADP8860 8860 | ||
17 | |||
18 | #define ADP8860_MAX_BRIGHTNESS 0x7F | ||
19 | #define FLAG_OFFT_SHIFT 8 | ||
20 | |||
21 | /* | ||
22 | * LEDs subdevice platform data | ||
23 | */ | ||
24 | |||
25 | #define ADP8860_LED_DIS_BLINK (0 << FLAG_OFFT_SHIFT) | ||
26 | #define ADP8860_LED_OFFT_600ms (1 << FLAG_OFFT_SHIFT) | ||
27 | #define ADP8860_LED_OFFT_1200ms (2 << FLAG_OFFT_SHIFT) | ||
28 | #define ADP8860_LED_OFFT_1800ms (3 << FLAG_OFFT_SHIFT) | ||
29 | |||
30 | #define ADP8860_LED_ONT_200ms 0 | ||
31 | #define ADP8860_LED_ONT_600ms 1 | ||
32 | #define ADP8860_LED_ONT_800ms 2 | ||
33 | #define ADP8860_LED_ONT_1200ms 3 | ||
34 | |||
35 | #define ADP8860_LED_D7 (7) | ||
36 | #define ADP8860_LED_D6 (6) | ||
37 | #define ADP8860_LED_D5 (5) | ||
38 | #define ADP8860_LED_D4 (4) | ||
39 | #define ADP8860_LED_D3 (3) | ||
40 | #define ADP8860_LED_D2 (2) | ||
41 | #define ADP8860_LED_D1 (1) | ||
42 | |||
43 | /* | ||
44 | * Backlight subdevice platform data | ||
45 | */ | ||
46 | |||
47 | #define ADP8860_BL_D7 (1 << 6) | ||
48 | #define ADP8860_BL_D6 (1 << 5) | ||
49 | #define ADP8860_BL_D5 (1 << 4) | ||
50 | #define ADP8860_BL_D4 (1 << 3) | ||
51 | #define ADP8860_BL_D3 (1 << 2) | ||
52 | #define ADP8860_BL_D2 (1 << 1) | ||
53 | #define ADP8860_BL_D1 (1 << 0) | ||
54 | |||
55 | #define ADP8860_FADE_T_DIS 0 /* Fade Timer Disabled */ | ||
56 | #define ADP8860_FADE_T_300ms 1 /* 0.3 Sec */ | ||
57 | #define ADP8860_FADE_T_600ms 2 | ||
58 | #define ADP8860_FADE_T_900ms 3 | ||
59 | #define ADP8860_FADE_T_1200ms 4 | ||
60 | #define ADP8860_FADE_T_1500ms 5 | ||
61 | #define ADP8860_FADE_T_1800ms 6 | ||
62 | #define ADP8860_FADE_T_2100ms 7 | ||
63 | #define ADP8860_FADE_T_2400ms 8 | ||
64 | #define ADP8860_FADE_T_2700ms 9 | ||
65 | #define ADP8860_FADE_T_3000ms 10 | ||
66 | #define ADP8860_FADE_T_3500ms 11 | ||
67 | #define ADP8860_FADE_T_4000ms 12 | ||
68 | #define ADP8860_FADE_T_4500ms 13 | ||
69 | #define ADP8860_FADE_T_5000ms 14 | ||
70 | #define ADP8860_FADE_T_5500ms 15 /* 5.5 Sec */ | ||
71 | |||
72 | #define ADP8860_FADE_LAW_LINEAR 0 | ||
73 | #define ADP8860_FADE_LAW_SQUARE 1 | ||
74 | #define ADP8860_FADE_LAW_CUBIC1 2 | ||
75 | #define ADP8860_FADE_LAW_CUBIC2 3 | ||
76 | |||
77 | #define ADP8860_BL_AMBL_FILT_80ms 0 /* Light sensor filter time */ | ||
78 | #define ADP8860_BL_AMBL_FILT_160ms 1 | ||
79 | #define ADP8860_BL_AMBL_FILT_320ms 2 | ||
80 | #define ADP8860_BL_AMBL_FILT_640ms 3 | ||
81 | #define ADP8860_BL_AMBL_FILT_1280ms 4 | ||
82 | #define ADP8860_BL_AMBL_FILT_2560ms 5 | ||
83 | #define ADP8860_BL_AMBL_FILT_5120ms 6 | ||
84 | #define ADP8860_BL_AMBL_FILT_10240ms 7 /* 10.24 sec */ | ||
85 | |||
86 | /* | ||
87 | * Blacklight current 0..30mA | ||
88 | */ | ||
89 | #define ADP8860_BL_CUR_mA(I) ((I * 127) / 30) | ||
90 | |||
91 | /* | ||
92 | * L2 comparator current 0..1106uA | ||
93 | */ | ||
94 | #define ADP8860_L2_COMP_CURR_uA(I) ((I * 255) / 1106) | ||
95 | |||
96 | /* | ||
97 | * L3 comparator current 0..138uA | ||
98 | */ | ||
99 | #define ADP8860_L3_COMP_CURR_uA(I) ((I * 255) / 138) | ||
100 | |||
101 | struct adp8860_backlight_platform_data { | ||
102 | u8 bl_led_assign; /* 1 = Backlight 0 = Individual LED */ | ||
103 | |||
104 | u8 bl_fade_in; /* Backlight Fade-In Timer */ | ||
105 | u8 bl_fade_out; /* Backlight Fade-Out Timer */ | ||
106 | u8 bl_fade_law; /* fade-on/fade-off transfer characteristic */ | ||
107 | |||
108 | u8 en_ambl_sens; /* 1 = enable ambient light sensor */ | ||
109 | u8 abml_filt; /* Light sensor filter time */ | ||
110 | |||
111 | u8 l1_daylight_max; /* use BL_CUR_mA(I) 0 <= I <= 30 mA */ | ||
112 | u8 l1_daylight_dim; /* typ = 0, use BL_CUR_mA(I) 0 <= I <= 30 mA */ | ||
113 | u8 l2_office_max; /* use BL_CUR_mA(I) 0 <= I <= 30 mA */ | ||
114 | u8 l2_office_dim; /* typ = 0, use BL_CUR_mA(I) 0 <= I <= 30 mA */ | ||
115 | u8 l3_dark_max; /* use BL_CUR_mA(I) 0 <= I <= 30 mA */ | ||
116 | u8 l3_dark_dim; /* typ = 0, use BL_CUR_mA(I) 0 <= I <= 30 mA */ | ||
117 | |||
118 | u8 l2_trip; /* use L2_COMP_CURR_uA(I) 0 <= I <= 1106 uA */ | ||
119 | u8 l2_hyst; /* use L2_COMP_CURR_uA(I) 0 <= I <= 1106 uA */ | ||
120 | u8 l3_trip; /* use L3_COMP_CURR_uA(I) 0 <= I <= 551 uA */ | ||
121 | u8 l3_hyst; /* use L3_COMP_CURR_uA(I) 0 <= I <= 551 uA */ | ||
122 | |||
123 | /** | ||
124 | * Independent Current Sinks / LEDS | ||
125 | * Sinks not assigned to the Backlight can be exposed to | ||
126 | * user space using the LEDS CLASS interface | ||
127 | */ | ||
128 | |||
129 | int num_leds; | ||
130 | struct led_info *leds; | ||
131 | u8 led_fade_in; /* LED Fade-In Timer */ | ||
132 | u8 led_fade_out; /* LED Fade-Out Timer */ | ||
133 | u8 led_fade_law; /* fade-on/fade-off transfer characteristic */ | ||
134 | u8 led_on_time; | ||
135 | |||
136 | /** | ||
137 | * Gain down disable. Setting this option does not allow the | ||
138 | * charge pump to switch to lower gains. NOT AVAILABLE on ADP8860 | ||
139 | * 1 = the charge pump doesn't switch down in gain until all LEDs are 0. | ||
140 | * The charge pump switches up in gain as needed. This feature is | ||
141 | * useful if the ADP8863 charge pump is used to drive an external load. | ||
142 | * This feature must be used when utilizing small fly capacitors | ||
143 | * (0402 or smaller). | ||
144 | * 0 = the charge pump automatically switches up and down in gain. | ||
145 | * This provides optimal efficiency, but is not suitable for driving | ||
146 | * loads that are not connected through the ADP8863 diode drivers. | ||
147 | * Additionally, the charge pump fly capacitors should be low ESR | ||
148 | * and sized 0603 or greater. | ||
149 | */ | ||
150 | |||
151 | u8 gdwn_dis; | ||
152 | }; | ||
153 | |||
154 | #endif /* __LINUX_I2C_ADP8860_H */ | ||
diff --git a/include/linux/lcd.h b/include/linux/lcd.h index c67fecafff90..8877123f2d6e 100644 --- a/include/linux/lcd.h +++ b/include/linux/lcd.h | |||
@@ -69,6 +69,29 @@ struct lcd_device { | |||
69 | struct device dev; | 69 | struct device dev; |
70 | }; | 70 | }; |
71 | 71 | ||
72 | struct lcd_platform_data { | ||
73 | /* reset lcd panel device. */ | ||
74 | int (*reset)(struct lcd_device *ld); | ||
75 | /* on or off to lcd panel. if 'enable' is 0 then | ||
76 | lcd power off and 1, lcd power on. */ | ||
77 | int (*power_on)(struct lcd_device *ld, int enable); | ||
78 | |||
79 | /* it indicates whether lcd panel was enabled | ||
80 | from bootloader or not. */ | ||
81 | int lcd_enabled; | ||
82 | /* it means delay for stable time when it becomes low to high | ||
83 | or high to low that is dependent on whether reset gpio is | ||
84 | low active or high active. */ | ||
85 | unsigned int reset_delay; | ||
86 | /* stable time needing to become lcd power on. */ | ||
87 | unsigned int power_on_delay; | ||
88 | /* stable time needing to become lcd power off. */ | ||
89 | unsigned int power_off_delay; | ||
90 | |||
91 | /* it could be used for any purpose. */ | ||
92 | void *pdata; | ||
93 | }; | ||
94 | |||
72 | static inline void lcd_set_power(struct lcd_device *ld, int power) | 95 | static inline void lcd_set_power(struct lcd_device *ld, int power) |
73 | { | 96 | { |
74 | mutex_lock(&ld->update_lock); | 97 | mutex_lock(&ld->update_lock); |
diff --git a/include/linux/leds.h b/include/linux/leds.h index d8bf9665e70c..ba6986a11663 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h | |||
@@ -149,14 +149,18 @@ struct gpio_led { | |||
149 | unsigned default_state : 2; | 149 | unsigned default_state : 2; |
150 | /* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */ | 150 | /* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */ |
151 | }; | 151 | }; |
152 | #define LEDS_GPIO_DEFSTATE_OFF 0 | 152 | #define LEDS_GPIO_DEFSTATE_OFF 0 |
153 | #define LEDS_GPIO_DEFSTATE_ON 1 | 153 | #define LEDS_GPIO_DEFSTATE_ON 1 |
154 | #define LEDS_GPIO_DEFSTATE_KEEP 2 | 154 | #define LEDS_GPIO_DEFSTATE_KEEP 2 |
155 | 155 | ||
156 | struct gpio_led_platform_data { | 156 | struct gpio_led_platform_data { |
157 | int num_leds; | 157 | int num_leds; |
158 | struct gpio_led *leds; | 158 | struct gpio_led *leds; |
159 | int (*gpio_blink_set)(unsigned gpio, | 159 | |
160 | #define GPIO_LED_NO_BLINK_LOW 0 /* No blink GPIO state low */ | ||
161 | #define GPIO_LED_NO_BLINK_HIGH 1 /* No blink GPIO state high */ | ||
162 | #define GPIO_LED_BLINK 2 /* Plase, blink */ | ||
163 | int (*gpio_blink_set)(unsigned gpio, int state, | ||
160 | unsigned long *delay_on, | 164 | unsigned long *delay_on, |
161 | unsigned long *delay_off); | 165 | unsigned long *delay_off); |
162 | }; | 166 | }; |
diff --git a/include/linux/mfd/mc13783.h b/include/linux/mfd/mc13783.h index 8895d9d8879c..4a894f688549 100644 --- a/include/linux/mfd/mc13783.h +++ b/include/linux/mfd/mc13783.h | |||
@@ -64,6 +64,70 @@ static inline int mc13783_ackirq(struct mc13783 *mc13783, int irq) | |||
64 | MC13783_ADC0_TSMOD1 | \ | 64 | MC13783_ADC0_TSMOD1 | \ |
65 | MC13783_ADC0_TSMOD2) | 65 | MC13783_ADC0_TSMOD2) |
66 | 66 | ||
67 | struct mc13783_led_platform_data { | ||
68 | #define MC13783_LED_MD 0 | ||
69 | #define MC13783_LED_AD 1 | ||
70 | #define MC13783_LED_KP 2 | ||
71 | #define MC13783_LED_R1 3 | ||
72 | #define MC13783_LED_G1 4 | ||
73 | #define MC13783_LED_B1 5 | ||
74 | #define MC13783_LED_R2 6 | ||
75 | #define MC13783_LED_G2 7 | ||
76 | #define MC13783_LED_B2 8 | ||
77 | #define MC13783_LED_R3 9 | ||
78 | #define MC13783_LED_G3 10 | ||
79 | #define MC13783_LED_B3 11 | ||
80 | #define MC13783_LED_MAX MC13783_LED_B3 | ||
81 | int id; | ||
82 | const char *name; | ||
83 | const char *default_trigger; | ||
84 | |||
85 | /* Three or two bits current selection depending on the led */ | ||
86 | char max_current; | ||
87 | }; | ||
88 | |||
89 | struct mc13783_leds_platform_data { | ||
90 | int num_leds; | ||
91 | struct mc13783_led_platform_data *led; | ||
92 | |||
93 | #define MC13783_LED_TRIODE_MD (1 << 0) | ||
94 | #define MC13783_LED_TRIODE_AD (1 << 1) | ||
95 | #define MC13783_LED_TRIODE_KP (1 << 2) | ||
96 | #define MC13783_LED_BOOST_EN (1 << 3) | ||
97 | #define MC13783_LED_TC1HALF (1 << 4) | ||
98 | #define MC13783_LED_SLEWLIMTC (1 << 5) | ||
99 | #define MC13783_LED_SLEWLIMBL (1 << 6) | ||
100 | #define MC13783_LED_TRIODE_TC1 (1 << 7) | ||
101 | #define MC13783_LED_TRIODE_TC2 (1 << 8) | ||
102 | #define MC13783_LED_TRIODE_TC3 (1 << 9) | ||
103 | int flags; | ||
104 | |||
105 | #define MC13783_LED_AB_DISABLED 0 | ||
106 | #define MC13783_LED_AB_MD1 1 | ||
107 | #define MC13783_LED_AB_MD12 2 | ||
108 | #define MC13783_LED_AB_MD123 3 | ||
109 | #define MC13783_LED_AB_MD1234 4 | ||
110 | #define MC13783_LED_AB_MD1234_AD1 5 | ||
111 | #define MC13783_LED_AB_MD1234_AD12 6 | ||
112 | #define MC13783_LED_AB_MD1_AD 7 | ||
113 | char abmode; | ||
114 | |||
115 | #define MC13783_LED_ABREF_200MV 0 | ||
116 | #define MC13783_LED_ABREF_400MV 1 | ||
117 | #define MC13783_LED_ABREF_600MV 2 | ||
118 | #define MC13783_LED_ABREF_800MV 3 | ||
119 | char abref; | ||
120 | |||
121 | #define MC13783_LED_PERIOD_10MS 0 | ||
122 | #define MC13783_LED_PERIOD_100MS 1 | ||
123 | #define MC13783_LED_PERIOD_500MS 2 | ||
124 | #define MC13783_LED_PERIOD_2S 3 | ||
125 | char bl_period; | ||
126 | char tc1_period; | ||
127 | char tc2_period; | ||
128 | char tc3_period; | ||
129 | }; | ||
130 | |||
67 | /* to be cleaned up */ | 131 | /* to be cleaned up */ |
68 | struct regulator_init_data; | 132 | struct regulator_init_data; |
69 | 133 | ||
@@ -80,12 +144,14 @@ struct mc13783_regulator_platform_data { | |||
80 | struct mc13783_platform_data { | 144 | struct mc13783_platform_data { |
81 | int num_regulators; | 145 | int num_regulators; |
82 | struct mc13783_regulator_init_data *regulators; | 146 | struct mc13783_regulator_init_data *regulators; |
147 | struct mc13783_leds_platform_data *leds; | ||
83 | 148 | ||
84 | #define MC13783_USE_TOUCHSCREEN (1 << 0) | 149 | #define MC13783_USE_TOUCHSCREEN (1 << 0) |
85 | #define MC13783_USE_CODEC (1 << 1) | 150 | #define MC13783_USE_CODEC (1 << 1) |
86 | #define MC13783_USE_ADC (1 << 2) | 151 | #define MC13783_USE_ADC (1 << 2) |
87 | #define MC13783_USE_RTC (1 << 3) | 152 | #define MC13783_USE_RTC (1 << 3) |
88 | #define MC13783_USE_REGULATOR (1 << 4) | 153 | #define MC13783_USE_REGULATOR (1 << 4) |
154 | #define MC13783_USE_LED (1 << 5) | ||
89 | unsigned int flags; | 155 | unsigned int flags; |
90 | }; | 156 | }; |
91 | 157 | ||
diff --git a/include/linux/mfd/pcf50633/backlight.h b/include/linux/mfd/pcf50633/backlight.h new file mode 100644 index 000000000000..83747e217b27 --- /dev/null +++ b/include/linux/mfd/pcf50633/backlight.h | |||
@@ -0,0 +1,51 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de> | ||
3 | * PCF50633 backlight device driver | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of the GNU General Public License as published by the | ||
7 | * Free Software Foundation; either version 2 of the License, or (at your | ||
8 | * option) any later version. | ||
9 | * | ||
10 | * You should have received a copy of the GNU General Public License along | ||
11 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
12 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | #ifndef __LINUX_MFD_PCF50633_BACKLIGHT | ||
17 | #define __LINUX_MFD_PCF50633_BACKLIGHT | ||
18 | |||
19 | /* | ||
20 | * @default_brightness: Backlight brightness is initialized to this value | ||
21 | * | ||
22 | * Brightness to be used after the driver has been probed. | ||
23 | * Valid range 0-63. | ||
24 | * | ||
25 | * @default_brightness_limit: The actual brightness is limited by this value | ||
26 | * | ||
27 | * Brightness limit to be used after the driver has been probed. This is useful | ||
28 | * when it is not known how much power is available for the backlight during | ||
29 | * probe. | ||
30 | * Valid range 0-63. Can be changed later with pcf50633_bl_set_brightness_limit. | ||
31 | * | ||
32 | * @ramp_time: Display ramp time when changing brightness | ||
33 | * | ||
34 | * When changing the backlights brightness the change is not instant, instead | ||
35 | * it fades smooth from one state to another. This value specifies how long | ||
36 | * the fade should take. The lower the value the higher the fade time. | ||
37 | * Valid range 0-255 | ||
38 | */ | ||
39 | struct pcf50633_bl_platform_data { | ||
40 | unsigned int default_brightness; | ||
41 | unsigned int default_brightness_limit; | ||
42 | uint8_t ramp_time; | ||
43 | }; | ||
44 | |||
45 | |||
46 | struct pcf50633; | ||
47 | |||
48 | int pcf50633_bl_set_brightness_limit(struct pcf50633 *pcf, unsigned int limit); | ||
49 | |||
50 | #endif | ||
51 | |||
diff --git a/include/linux/mfd/pcf50633/core.h b/include/linux/mfd/pcf50633/core.h index 3398bd9aab11..ad411a78870c 100644 --- a/include/linux/mfd/pcf50633/core.h +++ b/include/linux/mfd/pcf50633/core.h | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/regulator/driver.h> | 18 | #include <linux/regulator/driver.h> |
19 | #include <linux/regulator/machine.h> | 19 | #include <linux/regulator/machine.h> |
20 | #include <linux/power_supply.h> | 20 | #include <linux/power_supply.h> |
21 | #include <linux/mfd/pcf50633/backlight.h> | ||
21 | 22 | ||
22 | struct pcf50633; | 23 | struct pcf50633; |
23 | 24 | ||
@@ -43,6 +44,8 @@ struct pcf50633_platform_data { | |||
43 | void (*force_shutdown)(struct pcf50633 *); | 44 | void (*force_shutdown)(struct pcf50633 *); |
44 | 45 | ||
45 | u8 resumers[5]; | 46 | u8 resumers[5]; |
47 | |||
48 | struct pcf50633_bl_platform_data *backlight_data; | ||
46 | }; | 49 | }; |
47 | 50 | ||
48 | struct pcf50633_irq { | 51 | struct pcf50633_irq { |
@@ -152,6 +155,7 @@ struct pcf50633 { | |||
152 | struct platform_device *mbc_pdev; | 155 | struct platform_device *mbc_pdev; |
153 | struct platform_device *adc_pdev; | 156 | struct platform_device *adc_pdev; |
154 | struct platform_device *input_pdev; | 157 | struct platform_device *input_pdev; |
158 | struct platform_device *bl_pdev; | ||
155 | struct platform_device *regulator_pdev[PCF50633_NUM_REGULATORS]; | 159 | struct platform_device *regulator_pdev[PCF50633_NUM_REGULATORS]; |
156 | }; | 160 | }; |
157 | 161 | ||
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 3fd5c82e0e18..fb6c91eac7e3 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h | |||
@@ -485,6 +485,7 @@ struct perf_guest_info_callbacks { | |||
485 | #include <linux/ftrace.h> | 485 | #include <linux/ftrace.h> |
486 | #include <linux/cpu.h> | 486 | #include <linux/cpu.h> |
487 | #include <asm/atomic.h> | 487 | #include <asm/atomic.h> |
488 | #include <asm/local.h> | ||
488 | 489 | ||
489 | #define PERF_MAX_STACK_DEPTH 255 | 490 | #define PERF_MAX_STACK_DEPTH 255 |
490 | 491 | ||
@@ -587,21 +588,19 @@ struct perf_mmap_data { | |||
587 | struct rcu_head rcu_head; | 588 | struct rcu_head rcu_head; |
588 | #ifdef CONFIG_PERF_USE_VMALLOC | 589 | #ifdef CONFIG_PERF_USE_VMALLOC |
589 | struct work_struct work; | 590 | struct work_struct work; |
591 | int page_order; /* allocation order */ | ||
590 | #endif | 592 | #endif |
591 | int data_order; | ||
592 | int nr_pages; /* nr of data pages */ | 593 | int nr_pages; /* nr of data pages */ |
593 | int writable; /* are we writable */ | 594 | int writable; /* are we writable */ |
594 | int nr_locked; /* nr pages mlocked */ | 595 | int nr_locked; /* nr pages mlocked */ |
595 | 596 | ||
596 | atomic_t poll; /* POLL_ for wakeups */ | 597 | atomic_t poll; /* POLL_ for wakeups */ |
597 | atomic_t events; /* event_id limit */ | ||
598 | 598 | ||
599 | atomic_long_t head; /* write position */ | 599 | local_t head; /* write position */ |
600 | atomic_long_t done_head; /* completed head */ | 600 | local_t nest; /* nested writers */ |
601 | 601 | local_t events; /* event limit */ | |
602 | atomic_t lock; /* concurrent writes */ | 602 | local_t wakeup; /* wakeup stamp */ |
603 | atomic_t wakeup; /* needs a wakeup */ | 603 | local_t lost; /* nr records lost */ |
604 | atomic_t lost; /* nr records lost */ | ||
605 | 604 | ||
606 | long watermark; /* wakeup watermark */ | 605 | long watermark; /* wakeup watermark */ |
607 | 606 | ||
@@ -728,6 +727,7 @@ struct perf_event { | |||
728 | perf_overflow_handler_t overflow_handler; | 727 | perf_overflow_handler_t overflow_handler; |
729 | 728 | ||
730 | #ifdef CONFIG_EVENT_TRACING | 729 | #ifdef CONFIG_EVENT_TRACING |
730 | struct ftrace_event_call *tp_event; | ||
731 | struct event_filter *filter; | 731 | struct event_filter *filter; |
732 | #endif | 732 | #endif |
733 | 733 | ||
@@ -803,11 +803,12 @@ struct perf_cpu_context { | |||
803 | struct perf_output_handle { | 803 | struct perf_output_handle { |
804 | struct perf_event *event; | 804 | struct perf_event *event; |
805 | struct perf_mmap_data *data; | 805 | struct perf_mmap_data *data; |
806 | unsigned long head; | 806 | unsigned long wakeup; |
807 | unsigned long offset; | 807 | unsigned long size; |
808 | void *addr; | ||
809 | int page; | ||
808 | int nmi; | 810 | int nmi; |
809 | int sample; | 811 | int sample; |
810 | int locked; | ||
811 | }; | 812 | }; |
812 | 813 | ||
813 | #ifdef CONFIG_PERF_EVENTS | 814 | #ifdef CONFIG_PERF_EVENTS |
@@ -993,8 +994,9 @@ static inline bool perf_paranoid_kernel(void) | |||
993 | } | 994 | } |
994 | 995 | ||
995 | extern void perf_event_init(void); | 996 | extern void perf_event_init(void); |
996 | extern void perf_tp_event(int event_id, u64 addr, u64 count, void *record, | 997 | extern void perf_tp_event(u64 addr, u64 count, void *record, |
997 | int entry_size, struct pt_regs *regs); | 998 | int entry_size, struct pt_regs *regs, |
999 | struct hlist_head *head); | ||
998 | extern void perf_bp_event(struct perf_event *event, void *data); | 1000 | extern void perf_bp_event(struct perf_event *event, void *data); |
999 | 1001 | ||
1000 | #ifndef perf_misc_flags | 1002 | #ifndef perf_misc_flags |
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 057929b0a651..a1a86a53bc73 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h | |||
@@ -103,22 +103,6 @@ struct perf_event_attr; | |||
103 | #define __SC_TEST5(t5, a5, ...) __SC_TEST(t5); __SC_TEST4(__VA_ARGS__) | 103 | #define __SC_TEST5(t5, a5, ...) __SC_TEST(t5); __SC_TEST4(__VA_ARGS__) |
104 | #define __SC_TEST6(t6, a6, ...) __SC_TEST(t6); __SC_TEST5(__VA_ARGS__) | 104 | #define __SC_TEST6(t6, a6, ...) __SC_TEST(t6); __SC_TEST5(__VA_ARGS__) |
105 | 105 | ||
106 | #ifdef CONFIG_PERF_EVENTS | ||
107 | |||
108 | #define TRACE_SYS_ENTER_PERF_INIT(sname) \ | ||
109 | .perf_event_enable = perf_sysenter_enable, \ | ||
110 | .perf_event_disable = perf_sysenter_disable, | ||
111 | |||
112 | #define TRACE_SYS_EXIT_PERF_INIT(sname) \ | ||
113 | .perf_event_enable = perf_sysexit_enable, \ | ||
114 | .perf_event_disable = perf_sysexit_disable, | ||
115 | #else | ||
116 | #define TRACE_SYS_ENTER_PERF(sname) | ||
117 | #define TRACE_SYS_ENTER_PERF_INIT(sname) | ||
118 | #define TRACE_SYS_EXIT_PERF(sname) | ||
119 | #define TRACE_SYS_EXIT_PERF_INIT(sname) | ||
120 | #endif /* CONFIG_PERF_EVENTS */ | ||
121 | |||
122 | #ifdef CONFIG_FTRACE_SYSCALLS | 106 | #ifdef CONFIG_FTRACE_SYSCALLS |
123 | #define __SC_STR_ADECL1(t, a) #a | 107 | #define __SC_STR_ADECL1(t, a) #a |
124 | #define __SC_STR_ADECL2(t, a, ...) #a, __SC_STR_ADECL1(__VA_ARGS__) | 108 | #define __SC_STR_ADECL2(t, a, ...) #a, __SC_STR_ADECL1(__VA_ARGS__) |
@@ -134,54 +118,43 @@ struct perf_event_attr; | |||
134 | #define __SC_STR_TDECL5(t, a, ...) #t, __SC_STR_TDECL4(__VA_ARGS__) | 118 | #define __SC_STR_TDECL5(t, a, ...) #t, __SC_STR_TDECL4(__VA_ARGS__) |
135 | #define __SC_STR_TDECL6(t, a, ...) #t, __SC_STR_TDECL5(__VA_ARGS__) | 119 | #define __SC_STR_TDECL6(t, a, ...) #t, __SC_STR_TDECL5(__VA_ARGS__) |
136 | 120 | ||
121 | extern struct ftrace_event_class event_class_syscall_enter; | ||
122 | extern struct ftrace_event_class event_class_syscall_exit; | ||
123 | extern struct trace_event_functions enter_syscall_print_funcs; | ||
124 | extern struct trace_event_functions exit_syscall_print_funcs; | ||
125 | |||
137 | #define SYSCALL_TRACE_ENTER_EVENT(sname) \ | 126 | #define SYSCALL_TRACE_ENTER_EVENT(sname) \ |
138 | static const struct syscall_metadata __syscall_meta_##sname; \ | 127 | static struct syscall_metadata __syscall_meta_##sname; \ |
139 | static struct ftrace_event_call \ | 128 | static struct ftrace_event_call \ |
140 | __attribute__((__aligned__(4))) event_enter_##sname; \ | 129 | __attribute__((__aligned__(4))) event_enter_##sname; \ |
141 | static struct trace_event enter_syscall_print_##sname = { \ | ||
142 | .trace = print_syscall_enter, \ | ||
143 | }; \ | ||
144 | static struct ftrace_event_call __used \ | 130 | static struct ftrace_event_call __used \ |
145 | __attribute__((__aligned__(4))) \ | 131 | __attribute__((__aligned__(4))) \ |
146 | __attribute__((section("_ftrace_events"))) \ | 132 | __attribute__((section("_ftrace_events"))) \ |
147 | event_enter_##sname = { \ | 133 | event_enter_##sname = { \ |
148 | .name = "sys_enter"#sname, \ | 134 | .name = "sys_enter"#sname, \ |
149 | .system = "syscalls", \ | 135 | .class = &event_class_syscall_enter, \ |
150 | .event = &enter_syscall_print_##sname, \ | 136 | .event.funcs = &enter_syscall_print_funcs, \ |
151 | .raw_init = init_syscall_trace, \ | ||
152 | .define_fields = syscall_enter_define_fields, \ | ||
153 | .regfunc = reg_event_syscall_enter, \ | ||
154 | .unregfunc = unreg_event_syscall_enter, \ | ||
155 | .data = (void *)&__syscall_meta_##sname,\ | 137 | .data = (void *)&__syscall_meta_##sname,\ |
156 | TRACE_SYS_ENTER_PERF_INIT(sname) \ | ||
157 | } | 138 | } |
158 | 139 | ||
159 | #define SYSCALL_TRACE_EXIT_EVENT(sname) \ | 140 | #define SYSCALL_TRACE_EXIT_EVENT(sname) \ |
160 | static const struct syscall_metadata __syscall_meta_##sname; \ | 141 | static struct syscall_metadata __syscall_meta_##sname; \ |
161 | static struct ftrace_event_call \ | 142 | static struct ftrace_event_call \ |
162 | __attribute__((__aligned__(4))) event_exit_##sname; \ | 143 | __attribute__((__aligned__(4))) event_exit_##sname; \ |
163 | static struct trace_event exit_syscall_print_##sname = { \ | ||
164 | .trace = print_syscall_exit, \ | ||
165 | }; \ | ||
166 | static struct ftrace_event_call __used \ | 144 | static struct ftrace_event_call __used \ |
167 | __attribute__((__aligned__(4))) \ | 145 | __attribute__((__aligned__(4))) \ |
168 | __attribute__((section("_ftrace_events"))) \ | 146 | __attribute__((section("_ftrace_events"))) \ |
169 | event_exit_##sname = { \ | 147 | event_exit_##sname = { \ |
170 | .name = "sys_exit"#sname, \ | 148 | .name = "sys_exit"#sname, \ |
171 | .system = "syscalls", \ | 149 | .class = &event_class_syscall_exit, \ |
172 | .event = &exit_syscall_print_##sname, \ | 150 | .event.funcs = &exit_syscall_print_funcs, \ |
173 | .raw_init = init_syscall_trace, \ | ||
174 | .define_fields = syscall_exit_define_fields, \ | ||
175 | .regfunc = reg_event_syscall_exit, \ | ||
176 | .unregfunc = unreg_event_syscall_exit, \ | ||
177 | .data = (void *)&__syscall_meta_##sname,\ | 151 | .data = (void *)&__syscall_meta_##sname,\ |
178 | TRACE_SYS_EXIT_PERF_INIT(sname) \ | ||
179 | } | 152 | } |
180 | 153 | ||
181 | #define SYSCALL_METADATA(sname, nb) \ | 154 | #define SYSCALL_METADATA(sname, nb) \ |
182 | SYSCALL_TRACE_ENTER_EVENT(sname); \ | 155 | SYSCALL_TRACE_ENTER_EVENT(sname); \ |
183 | SYSCALL_TRACE_EXIT_EVENT(sname); \ | 156 | SYSCALL_TRACE_EXIT_EVENT(sname); \ |
184 | static const struct syscall_metadata __used \ | 157 | static struct syscall_metadata __used \ |
185 | __attribute__((__aligned__(4))) \ | 158 | __attribute__((__aligned__(4))) \ |
186 | __attribute__((section("__syscalls_metadata"))) \ | 159 | __attribute__((section("__syscalls_metadata"))) \ |
187 | __syscall_meta_##sname = { \ | 160 | __syscall_meta_##sname = { \ |
@@ -191,12 +164,14 @@ struct perf_event_attr; | |||
191 | .args = args_##sname, \ | 164 | .args = args_##sname, \ |
192 | .enter_event = &event_enter_##sname, \ | 165 | .enter_event = &event_enter_##sname, \ |
193 | .exit_event = &event_exit_##sname, \ | 166 | .exit_event = &event_exit_##sname, \ |
167 | .enter_fields = LIST_HEAD_INIT(__syscall_meta_##sname.enter_fields), \ | ||
168 | .exit_fields = LIST_HEAD_INIT(__syscall_meta_##sname.exit_fields), \ | ||
194 | }; | 169 | }; |
195 | 170 | ||
196 | #define SYSCALL_DEFINE0(sname) \ | 171 | #define SYSCALL_DEFINE0(sname) \ |
197 | SYSCALL_TRACE_ENTER_EVENT(_##sname); \ | 172 | SYSCALL_TRACE_ENTER_EVENT(_##sname); \ |
198 | SYSCALL_TRACE_EXIT_EVENT(_##sname); \ | 173 | SYSCALL_TRACE_EXIT_EVENT(_##sname); \ |
199 | static const struct syscall_metadata __used \ | 174 | static struct syscall_metadata __used \ |
200 | __attribute__((__aligned__(4))) \ | 175 | __attribute__((__aligned__(4))) \ |
201 | __attribute__((section("__syscalls_metadata"))) \ | 176 | __attribute__((section("__syscalls_metadata"))) \ |
202 | __syscall_meta__##sname = { \ | 177 | __syscall_meta__##sname = { \ |
@@ -204,6 +179,8 @@ struct perf_event_attr; | |||
204 | .nb_args = 0, \ | 179 | .nb_args = 0, \ |
205 | .enter_event = &event_enter__##sname, \ | 180 | .enter_event = &event_enter__##sname, \ |
206 | .exit_event = &event_exit__##sname, \ | 181 | .exit_event = &event_exit__##sname, \ |
182 | .enter_fields = LIST_HEAD_INIT(__syscall_meta__##sname.enter_fields), \ | ||
183 | .exit_fields = LIST_HEAD_INIT(__syscall_meta__##sname.exit_fields), \ | ||
207 | }; \ | 184 | }; \ |
208 | asmlinkage long sys_##sname(void) | 185 | asmlinkage long sys_##sname(void) |
209 | #else | 186 | #else |
diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 1d85f9a6a199..9a59d1f98cd4 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h | |||
@@ -20,12 +20,17 @@ | |||
20 | struct module; | 20 | struct module; |
21 | struct tracepoint; | 21 | struct tracepoint; |
22 | 22 | ||
23 | struct tracepoint_func { | ||
24 | void *func; | ||
25 | void *data; | ||
26 | }; | ||
27 | |||
23 | struct tracepoint { | 28 | struct tracepoint { |
24 | const char *name; /* Tracepoint name */ | 29 | const char *name; /* Tracepoint name */ |
25 | int state; /* State. */ | 30 | int state; /* State. */ |
26 | void (*regfunc)(void); | 31 | void (*regfunc)(void); |
27 | void (*unregfunc)(void); | 32 | void (*unregfunc)(void); |
28 | void **funcs; | 33 | struct tracepoint_func *funcs; |
29 | } __attribute__((aligned(32))); /* | 34 | } __attribute__((aligned(32))); /* |
30 | * Aligned on 32 bytes because it is | 35 | * Aligned on 32 bytes because it is |
31 | * globally visible and gcc happily | 36 | * globally visible and gcc happily |
@@ -37,16 +42,19 @@ struct tracepoint { | |||
37 | * Connect a probe to a tracepoint. | 42 | * Connect a probe to a tracepoint. |
38 | * Internal API, should not be used directly. | 43 | * Internal API, should not be used directly. |
39 | */ | 44 | */ |
40 | extern int tracepoint_probe_register(const char *name, void *probe); | 45 | extern int tracepoint_probe_register(const char *name, void *probe, void *data); |
41 | 46 | ||
42 | /* | 47 | /* |
43 | * Disconnect a probe from a tracepoint. | 48 | * Disconnect a probe from a tracepoint. |
44 | * Internal API, should not be used directly. | 49 | * Internal API, should not be used directly. |
45 | */ | 50 | */ |
46 | extern int tracepoint_probe_unregister(const char *name, void *probe); | 51 | extern int |
52 | tracepoint_probe_unregister(const char *name, void *probe, void *data); | ||
47 | 53 | ||
48 | extern int tracepoint_probe_register_noupdate(const char *name, void *probe); | 54 | extern int tracepoint_probe_register_noupdate(const char *name, void *probe, |
49 | extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe); | 55 | void *data); |
56 | extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe, | ||
57 | void *data); | ||
50 | extern void tracepoint_probe_update_all(void); | 58 | extern void tracepoint_probe_update_all(void); |
51 | 59 | ||
52 | struct tracepoint_iter { | 60 | struct tracepoint_iter { |
@@ -102,17 +110,27 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin, | |||
102 | /* | 110 | /* |
103 | * it_func[0] is never NULL because there is at least one element in the array | 111 | * it_func[0] is never NULL because there is at least one element in the array |
104 | * when the array itself is non NULL. | 112 | * when the array itself is non NULL. |
113 | * | ||
114 | * Note, the proto and args passed in includes "__data" as the first parameter. | ||
115 | * The reason for this is to handle the "void" prototype. If a tracepoint | ||
116 | * has a "void" prototype, then it is invalid to declare a function | ||
117 | * as "(void *, void)". The DECLARE_TRACE_NOARGS() will pass in just | ||
118 | * "void *data", where as the DECLARE_TRACE() will pass in "void *data, proto". | ||
105 | */ | 119 | */ |
106 | #define __DO_TRACE(tp, proto, args) \ | 120 | #define __DO_TRACE(tp, proto, args) \ |
107 | do { \ | 121 | do { \ |
108 | void **it_func; \ | 122 | struct tracepoint_func *it_func_ptr; \ |
123 | void *it_func; \ | ||
124 | void *__data; \ | ||
109 | \ | 125 | \ |
110 | rcu_read_lock_sched_notrace(); \ | 126 | rcu_read_lock_sched_notrace(); \ |
111 | it_func = rcu_dereference_sched((tp)->funcs); \ | 127 | it_func_ptr = rcu_dereference_sched((tp)->funcs); \ |
112 | if (it_func) { \ | 128 | if (it_func_ptr) { \ |
113 | do { \ | 129 | do { \ |
114 | ((void(*)(proto))(*it_func))(args); \ | 130 | it_func = (it_func_ptr)->func; \ |
115 | } while (*(++it_func)); \ | 131 | __data = (it_func_ptr)->data; \ |
132 | ((void(*)(proto))(it_func))(args); \ | ||
133 | } while ((++it_func_ptr)->func); \ | ||
116 | } \ | 134 | } \ |
117 | rcu_read_unlock_sched_notrace(); \ | 135 | rcu_read_unlock_sched_notrace(); \ |
118 | } while (0) | 136 | } while (0) |
@@ -122,24 +140,32 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin, | |||
122 | * not add unwanted padding between the beginning of the section and the | 140 | * not add unwanted padding between the beginning of the section and the |
123 | * structure. Force alignment to the same alignment as the section start. | 141 | * structure. Force alignment to the same alignment as the section start. |
124 | */ | 142 | */ |
125 | #define DECLARE_TRACE(name, proto, args) \ | 143 | #define __DECLARE_TRACE(name, proto, args, data_proto, data_args) \ |
126 | extern struct tracepoint __tracepoint_##name; \ | 144 | extern struct tracepoint __tracepoint_##name; \ |
127 | static inline void trace_##name(proto) \ | 145 | static inline void trace_##name(proto) \ |
128 | { \ | 146 | { \ |
129 | if (unlikely(__tracepoint_##name.state)) \ | 147 | if (unlikely(__tracepoint_##name.state)) \ |
130 | __DO_TRACE(&__tracepoint_##name, \ | 148 | __DO_TRACE(&__tracepoint_##name, \ |
131 | TP_PROTO(proto), TP_ARGS(args)); \ | 149 | TP_PROTO(data_proto), \ |
150 | TP_ARGS(data_args)); \ | ||
151 | } \ | ||
152 | static inline int \ | ||
153 | register_trace_##name(void (*probe)(data_proto), void *data) \ | ||
154 | { \ | ||
155 | return tracepoint_probe_register(#name, (void *)probe, \ | ||
156 | data); \ | ||
132 | } \ | 157 | } \ |
133 | static inline int register_trace_##name(void (*probe)(proto)) \ | 158 | static inline int \ |
159 | unregister_trace_##name(void (*probe)(data_proto), void *data) \ | ||
134 | { \ | 160 | { \ |
135 | return tracepoint_probe_register(#name, (void *)probe); \ | 161 | return tracepoint_probe_unregister(#name, (void *)probe, \ |
162 | data); \ | ||
136 | } \ | 163 | } \ |
137 | static inline int unregister_trace_##name(void (*probe)(proto)) \ | 164 | static inline void \ |
165 | check_trace_callback_type_##name(void (*cb)(data_proto)) \ | ||
138 | { \ | 166 | { \ |
139 | return tracepoint_probe_unregister(#name, (void *)probe);\ | ||
140 | } | 167 | } |
141 | 168 | ||
142 | |||
143 | #define DEFINE_TRACE_FN(name, reg, unreg) \ | 169 | #define DEFINE_TRACE_FN(name, reg, unreg) \ |
144 | static const char __tpstrtab_##name[] \ | 170 | static const char __tpstrtab_##name[] \ |
145 | __attribute__((section("__tracepoints_strings"))) = #name; \ | 171 | __attribute__((section("__tracepoints_strings"))) = #name; \ |
@@ -156,18 +182,23 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin, | |||
156 | EXPORT_SYMBOL(__tracepoint_##name) | 182 | EXPORT_SYMBOL(__tracepoint_##name) |
157 | 183 | ||
158 | #else /* !CONFIG_TRACEPOINTS */ | 184 | #else /* !CONFIG_TRACEPOINTS */ |
159 | #define DECLARE_TRACE(name, proto, args) \ | 185 | #define __DECLARE_TRACE(name, proto, args, data_proto, data_args) \ |
160 | static inline void _do_trace_##name(struct tracepoint *tp, proto) \ | ||
161 | { } \ | ||
162 | static inline void trace_##name(proto) \ | 186 | static inline void trace_##name(proto) \ |
163 | { } \ | 187 | { } \ |
164 | static inline int register_trace_##name(void (*probe)(proto)) \ | 188 | static inline int \ |
189 | register_trace_##name(void (*probe)(data_proto), \ | ||
190 | void *data) \ | ||
165 | { \ | 191 | { \ |
166 | return -ENOSYS; \ | 192 | return -ENOSYS; \ |
167 | } \ | 193 | } \ |
168 | static inline int unregister_trace_##name(void (*probe)(proto)) \ | 194 | static inline int \ |
195 | unregister_trace_##name(void (*probe)(data_proto), \ | ||
196 | void *data) \ | ||
169 | { \ | 197 | { \ |
170 | return -ENOSYS; \ | 198 | return -ENOSYS; \ |
199 | } \ | ||
200 | static inline void check_trace_callback_type_##name(void (*cb)(data_proto)) \ | ||
201 | { \ | ||
171 | } | 202 | } |
172 | 203 | ||
173 | #define DEFINE_TRACE_FN(name, reg, unreg) | 204 | #define DEFINE_TRACE_FN(name, reg, unreg) |
@@ -176,6 +207,29 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin, | |||
176 | #define EXPORT_TRACEPOINT_SYMBOL(name) | 207 | #define EXPORT_TRACEPOINT_SYMBOL(name) |
177 | 208 | ||
178 | #endif /* CONFIG_TRACEPOINTS */ | 209 | #endif /* CONFIG_TRACEPOINTS */ |
210 | |||
211 | /* | ||
212 | * The need for the DECLARE_TRACE_NOARGS() is to handle the prototype | ||
213 | * (void). "void" is a special value in a function prototype and can | ||
214 | * not be combined with other arguments. Since the DECLARE_TRACE() | ||
215 | * macro adds a data element at the beginning of the prototype, | ||
216 | * we need a way to differentiate "(void *data, proto)" from | ||
217 | * "(void *data, void)". The second prototype is invalid. | ||
218 | * | ||
219 | * DECLARE_TRACE_NOARGS() passes "void" as the tracepoint prototype | ||
220 | * and "void *__data" as the callback prototype. | ||
221 | * | ||
222 | * DECLARE_TRACE() passes "proto" as the tracepoint protoype and | ||
223 | * "void *__data, proto" as the callback prototype. | ||
224 | */ | ||
225 | #define DECLARE_TRACE_NOARGS(name) \ | ||
226 | __DECLARE_TRACE(name, void, , void *__data, __data) | ||
227 | |||
228 | #define DECLARE_TRACE(name, proto, args) \ | ||
229 | __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \ | ||
230 | PARAMS(void *__data, proto), \ | ||
231 | PARAMS(__data, args)) | ||
232 | |||
179 | #endif /* DECLARE_TRACE */ | 233 | #endif /* DECLARE_TRACE */ |
180 | 234 | ||
181 | #ifndef TRACE_EVENT | 235 | #ifndef TRACE_EVENT |
diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h index 88c59c13ea7b..3d685d1f2a03 100644 --- a/include/trace/ftrace.h +++ b/include/trace/ftrace.h | |||
@@ -62,10 +62,13 @@ | |||
62 | struct trace_entry ent; \ | 62 | struct trace_entry ent; \ |
63 | tstruct \ | 63 | tstruct \ |
64 | char __data[0]; \ | 64 | char __data[0]; \ |
65 | }; | 65 | }; \ |
66 | \ | ||
67 | static struct ftrace_event_class event_class_##name; | ||
68 | |||
66 | #undef DEFINE_EVENT | 69 | #undef DEFINE_EVENT |
67 | #define DEFINE_EVENT(template, name, proto, args) \ | 70 | #define DEFINE_EVENT(template, name, proto, args) \ |
68 | static struct ftrace_event_call \ | 71 | static struct ftrace_event_call __used \ |
69 | __attribute__((__aligned__(4))) event_##name | 72 | __attribute__((__aligned__(4))) event_##name |
70 | 73 | ||
71 | #undef DEFINE_EVENT_PRINT | 74 | #undef DEFINE_EVENT_PRINT |
@@ -147,7 +150,7 @@ | |||
147 | * | 150 | * |
148 | * entry = iter->ent; | 151 | * entry = iter->ent; |
149 | * | 152 | * |
150 | * if (entry->type != event_<call>.id) { | 153 | * if (entry->type != event_<call>->event.type) { |
151 | * WARN_ON_ONCE(1); | 154 | * WARN_ON_ONCE(1); |
152 | * return TRACE_TYPE_UNHANDLED; | 155 | * return TRACE_TYPE_UNHANDLED; |
153 | * } | 156 | * } |
@@ -206,18 +209,22 @@ | |||
206 | #undef DECLARE_EVENT_CLASS | 209 | #undef DECLARE_EVENT_CLASS |
207 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | 210 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
208 | static notrace enum print_line_t \ | 211 | static notrace enum print_line_t \ |
209 | ftrace_raw_output_id_##call(int event_id, const char *name, \ | 212 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \ |
210 | struct trace_iterator *iter, int flags) \ | 213 | struct trace_event *trace_event) \ |
211 | { \ | 214 | { \ |
215 | struct ftrace_event_call *event; \ | ||
212 | struct trace_seq *s = &iter->seq; \ | 216 | struct trace_seq *s = &iter->seq; \ |
213 | struct ftrace_raw_##call *field; \ | 217 | struct ftrace_raw_##call *field; \ |
214 | struct trace_entry *entry; \ | 218 | struct trace_entry *entry; \ |
215 | struct trace_seq *p; \ | 219 | struct trace_seq *p; \ |
216 | int ret; \ | 220 | int ret; \ |
217 | \ | 221 | \ |
222 | event = container_of(trace_event, struct ftrace_event_call, \ | ||
223 | event); \ | ||
224 | \ | ||
218 | entry = iter->ent; \ | 225 | entry = iter->ent; \ |
219 | \ | 226 | \ |
220 | if (entry->type != event_id) { \ | 227 | if (entry->type != event->event.type) { \ |
221 | WARN_ON_ONCE(1); \ | 228 | WARN_ON_ONCE(1); \ |
222 | return TRACE_TYPE_UNHANDLED; \ | 229 | return TRACE_TYPE_UNHANDLED; \ |
223 | } \ | 230 | } \ |
@@ -226,7 +233,7 @@ ftrace_raw_output_id_##call(int event_id, const char *name, \ | |||
226 | \ | 233 | \ |
227 | p = &get_cpu_var(ftrace_event_seq); \ | 234 | p = &get_cpu_var(ftrace_event_seq); \ |
228 | trace_seq_init(p); \ | 235 | trace_seq_init(p); \ |
229 | ret = trace_seq_printf(s, "%s: ", name); \ | 236 | ret = trace_seq_printf(s, "%s: ", event->name); \ |
230 | if (ret) \ | 237 | if (ret) \ |
231 | ret = trace_seq_printf(s, print); \ | 238 | ret = trace_seq_printf(s, print); \ |
232 | put_cpu(); \ | 239 | put_cpu(); \ |
@@ -234,21 +241,16 @@ ftrace_raw_output_id_##call(int event_id, const char *name, \ | |||
234 | return TRACE_TYPE_PARTIAL_LINE; \ | 241 | return TRACE_TYPE_PARTIAL_LINE; \ |
235 | \ | 242 | \ |
236 | return TRACE_TYPE_HANDLED; \ | 243 | return TRACE_TYPE_HANDLED; \ |
237 | } | 244 | } \ |
238 | 245 | static struct trace_event_functions ftrace_event_type_funcs_##call = { \ | |
239 | #undef DEFINE_EVENT | 246 | .trace = ftrace_raw_output_##call, \ |
240 | #define DEFINE_EVENT(template, name, proto, args) \ | 247 | }; |
241 | static notrace enum print_line_t \ | ||
242 | ftrace_raw_output_##name(struct trace_iterator *iter, int flags) \ | ||
243 | { \ | ||
244 | return ftrace_raw_output_id_##template(event_##name.id, \ | ||
245 | #name, iter, flags); \ | ||
246 | } | ||
247 | 248 | ||
248 | #undef DEFINE_EVENT_PRINT | 249 | #undef DEFINE_EVENT_PRINT |
249 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ | 250 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ |
250 | static notrace enum print_line_t \ | 251 | static notrace enum print_line_t \ |
251 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ | 252 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \ |
253 | struct trace_event *event) \ | ||
252 | { \ | 254 | { \ |
253 | struct trace_seq *s = &iter->seq; \ | 255 | struct trace_seq *s = &iter->seq; \ |
254 | struct ftrace_raw_##template *field; \ | 256 | struct ftrace_raw_##template *field; \ |
@@ -258,7 +260,7 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ | |||
258 | \ | 260 | \ |
259 | entry = iter->ent; \ | 261 | entry = iter->ent; \ |
260 | \ | 262 | \ |
261 | if (entry->type != event_##call.id) { \ | 263 | if (entry->type != event_##call.event.type) { \ |
262 | WARN_ON_ONCE(1); \ | 264 | WARN_ON_ONCE(1); \ |
263 | return TRACE_TYPE_UNHANDLED; \ | 265 | return TRACE_TYPE_UNHANDLED; \ |
264 | } \ | 266 | } \ |
@@ -275,7 +277,10 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ | |||
275 | return TRACE_TYPE_PARTIAL_LINE; \ | 277 | return TRACE_TYPE_PARTIAL_LINE; \ |
276 | \ | 278 | \ |
277 | return TRACE_TYPE_HANDLED; \ | 279 | return TRACE_TYPE_HANDLED; \ |
278 | } | 280 | } \ |
281 | static struct trace_event_functions ftrace_event_type_funcs_##call = { \ | ||
282 | .trace = ftrace_raw_output_##call, \ | ||
283 | }; | ||
279 | 284 | ||
280 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | 285 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
281 | 286 | ||
@@ -381,80 +386,18 @@ static inline notrace int ftrace_get_offsets_##call( \ | |||
381 | 386 | ||
382 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | 387 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
383 | 388 | ||
384 | #ifdef CONFIG_PERF_EVENTS | ||
385 | |||
386 | /* | ||
387 | * Generate the functions needed for tracepoint perf_event support. | ||
388 | * | ||
389 | * NOTE: The insertion profile callback (ftrace_profile_<call>) is defined later | ||
390 | * | ||
391 | * static int ftrace_profile_enable_<call>(void) | ||
392 | * { | ||
393 | * return register_trace_<call>(ftrace_profile_<call>); | ||
394 | * } | ||
395 | * | ||
396 | * static void ftrace_profile_disable_<call>(void) | ||
397 | * { | ||
398 | * unregister_trace_<call>(ftrace_profile_<call>); | ||
399 | * } | ||
400 | * | ||
401 | */ | ||
402 | |||
403 | #undef DECLARE_EVENT_CLASS | ||
404 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) | ||
405 | |||
406 | #undef DEFINE_EVENT | ||
407 | #define DEFINE_EVENT(template, name, proto, args) \ | ||
408 | \ | ||
409 | static void perf_trace_##name(proto); \ | ||
410 | \ | ||
411 | static notrace int \ | ||
412 | perf_trace_enable_##name(struct ftrace_event_call *unused) \ | ||
413 | { \ | ||
414 | return register_trace_##name(perf_trace_##name); \ | ||
415 | } \ | ||
416 | \ | ||
417 | static notrace void \ | ||
418 | perf_trace_disable_##name(struct ftrace_event_call *unused) \ | ||
419 | { \ | ||
420 | unregister_trace_##name(perf_trace_##name); \ | ||
421 | } | ||
422 | |||
423 | #undef DEFINE_EVENT_PRINT | ||
424 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | ||
425 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | ||
426 | |||
427 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | ||
428 | |||
429 | #endif /* CONFIG_PERF_EVENTS */ | ||
430 | |||
431 | /* | 389 | /* |
432 | * Stage 4 of the trace events. | 390 | * Stage 4 of the trace events. |
433 | * | 391 | * |
434 | * Override the macros in <trace/trace_events.h> to include the following: | 392 | * Override the macros in <trace/trace_events.h> to include the following: |
435 | * | 393 | * |
436 | * static void ftrace_event_<call>(proto) | ||
437 | * { | ||
438 | * event_trace_printk(_RET_IP_, "<call>: " <fmt>); | ||
439 | * } | ||
440 | * | ||
441 | * static int ftrace_reg_event_<call>(struct ftrace_event_call *unused) | ||
442 | * { | ||
443 | * return register_trace_<call>(ftrace_event_<call>); | ||
444 | * } | ||
445 | * | ||
446 | * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused) | ||
447 | * { | ||
448 | * unregister_trace_<call>(ftrace_event_<call>); | ||
449 | * } | ||
450 | * | ||
451 | * | ||
452 | * For those macros defined with TRACE_EVENT: | 394 | * For those macros defined with TRACE_EVENT: |
453 | * | 395 | * |
454 | * static struct ftrace_event_call event_<call>; | 396 | * static struct ftrace_event_call event_<call>; |
455 | * | 397 | * |
456 | * static void ftrace_raw_event_<call>(proto) | 398 | * static void ftrace_raw_event_<call>(void *__data, proto) |
457 | * { | 399 | * { |
400 | * struct ftrace_event_call *event_call = __data; | ||
458 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; | 401 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; |
459 | * struct ring_buffer_event *event; | 402 | * struct ring_buffer_event *event; |
460 | * struct ftrace_raw_<call> *entry; <-- defined in stage 1 | 403 | * struct ftrace_raw_<call> *entry; <-- defined in stage 1 |
@@ -469,7 +412,7 @@ perf_trace_disable_##name(struct ftrace_event_call *unused) \ | |||
469 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); | 412 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); |
470 | * | 413 | * |
471 | * event = trace_current_buffer_lock_reserve(&buffer, | 414 | * event = trace_current_buffer_lock_reserve(&buffer, |
472 | * event_<call>.id, | 415 | * event_<call>->event.type, |
473 | * sizeof(*entry) + __data_size, | 416 | * sizeof(*entry) + __data_size, |
474 | * irq_flags, pc); | 417 | * irq_flags, pc); |
475 | * if (!event) | 418 | * if (!event) |
@@ -484,43 +427,42 @@ perf_trace_disable_##name(struct ftrace_event_call *unused) \ | |||
484 | * event, irq_flags, pc); | 427 | * event, irq_flags, pc); |
485 | * } | 428 | * } |
486 | * | 429 | * |
487 | * static int ftrace_raw_reg_event_<call>(struct ftrace_event_call *unused) | ||
488 | * { | ||
489 | * return register_trace_<call>(ftrace_raw_event_<call>); | ||
490 | * } | ||
491 | * | ||
492 | * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused) | ||
493 | * { | ||
494 | * unregister_trace_<call>(ftrace_raw_event_<call>); | ||
495 | * } | ||
496 | * | ||
497 | * static struct trace_event ftrace_event_type_<call> = { | 430 | * static struct trace_event ftrace_event_type_<call> = { |
498 | * .trace = ftrace_raw_output_<call>, <-- stage 2 | 431 | * .trace = ftrace_raw_output_<call>, <-- stage 2 |
499 | * }; | 432 | * }; |
500 | * | 433 | * |
501 | * static const char print_fmt_<call>[] = <TP_printk>; | 434 | * static const char print_fmt_<call>[] = <TP_printk>; |
502 | * | 435 | * |
436 | * static struct ftrace_event_class __used event_class_<template> = { | ||
437 | * .system = "<system>", | ||
438 | * .define_fields = ftrace_define_fields_<call>, | ||
439 | * .fields = LIST_HEAD_INIT(event_class_##call.fields), | ||
440 | * .raw_init = trace_event_raw_init, | ||
441 | * .probe = ftrace_raw_event_##call, | ||
442 | * }; | ||
443 | * | ||
503 | * static struct ftrace_event_call __used | 444 | * static struct ftrace_event_call __used |
504 | * __attribute__((__aligned__(4))) | 445 | * __attribute__((__aligned__(4))) |
505 | * __attribute__((section("_ftrace_events"))) event_<call> = { | 446 | * __attribute__((section("_ftrace_events"))) event_<call> = { |
506 | * .name = "<call>", | 447 | * .name = "<call>", |
507 | * .system = "<system>", | 448 | * .class = event_class_<template>, |
508 | * .raw_init = trace_event_raw_init, | 449 | * .event = &ftrace_event_type_<call>, |
509 | * .regfunc = ftrace_reg_event_<call>, | ||
510 | * .unregfunc = ftrace_unreg_event_<call>, | ||
511 | * .print_fmt = print_fmt_<call>, | 450 | * .print_fmt = print_fmt_<call>, |
512 | * .define_fields = ftrace_define_fields_<call>, | 451 | * }; |
513 | * } | ||
514 | * | 452 | * |
515 | */ | 453 | */ |
516 | 454 | ||
517 | #ifdef CONFIG_PERF_EVENTS | 455 | #ifdef CONFIG_PERF_EVENTS |
518 | 456 | ||
457 | #define _TRACE_PERF_PROTO(call, proto) \ | ||
458 | static notrace void \ | ||
459 | perf_trace_##call(void *__data, proto); | ||
460 | |||
519 | #define _TRACE_PERF_INIT(call) \ | 461 | #define _TRACE_PERF_INIT(call) \ |
520 | .perf_event_enable = perf_trace_enable_##call, \ | 462 | .perf_probe = perf_trace_##call, |
521 | .perf_event_disable = perf_trace_disable_##call, | ||
522 | 463 | ||
523 | #else | 464 | #else |
465 | #define _TRACE_PERF_PROTO(call, proto) | ||
524 | #define _TRACE_PERF_INIT(call) | 466 | #define _TRACE_PERF_INIT(call) |
525 | #endif /* CONFIG_PERF_EVENTS */ | 467 | #endif /* CONFIG_PERF_EVENTS */ |
526 | 468 | ||
@@ -554,9 +496,9 @@ perf_trace_disable_##name(struct ftrace_event_call *unused) \ | |||
554 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | 496 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
555 | \ | 497 | \ |
556 | static notrace void \ | 498 | static notrace void \ |
557 | ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \ | 499 | ftrace_raw_event_##call(void *__data, proto) \ |
558 | proto) \ | ||
559 | { \ | 500 | { \ |
501 | struct ftrace_event_call *event_call = __data; \ | ||
560 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ | 502 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
561 | struct ring_buffer_event *event; \ | 503 | struct ring_buffer_event *event; \ |
562 | struct ftrace_raw_##call *entry; \ | 504 | struct ftrace_raw_##call *entry; \ |
@@ -571,7 +513,7 @@ ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \ | |||
571 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ | 513 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ |
572 | \ | 514 | \ |
573 | event = trace_current_buffer_lock_reserve(&buffer, \ | 515 | event = trace_current_buffer_lock_reserve(&buffer, \ |
574 | event_call->id, \ | 516 | event_call->event.type, \ |
575 | sizeof(*entry) + __data_size, \ | 517 | sizeof(*entry) + __data_size, \ |
576 | irq_flags, pc); \ | 518 | irq_flags, pc); \ |
577 | if (!event) \ | 519 | if (!event) \ |
@@ -586,34 +528,21 @@ ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \ | |||
586 | trace_nowake_buffer_unlock_commit(buffer, \ | 528 | trace_nowake_buffer_unlock_commit(buffer, \ |
587 | event, irq_flags, pc); \ | 529 | event, irq_flags, pc); \ |
588 | } | 530 | } |
531 | /* | ||
532 | * The ftrace_test_probe is compiled out, it is only here as a build time check | ||
533 | * to make sure that if the tracepoint handling changes, the ftrace probe will | ||
534 | * fail to compile unless it too is updated. | ||
535 | */ | ||
589 | 536 | ||
590 | #undef DEFINE_EVENT | 537 | #undef DEFINE_EVENT |
591 | #define DEFINE_EVENT(template, call, proto, args) \ | 538 | #define DEFINE_EVENT(template, call, proto, args) \ |
592 | \ | 539 | static inline void ftrace_test_probe_##call(void) \ |
593 | static notrace void ftrace_raw_event_##call(proto) \ | ||
594 | { \ | ||
595 | ftrace_raw_event_id_##template(&event_##call, args); \ | ||
596 | } \ | ||
597 | \ | ||
598 | static notrace int \ | ||
599 | ftrace_raw_reg_event_##call(struct ftrace_event_call *unused) \ | ||
600 | { \ | 540 | { \ |
601 | return register_trace_##call(ftrace_raw_event_##call); \ | 541 | check_trace_callback_type_##call(ftrace_raw_event_##template); \ |
602 | } \ | 542 | } |
603 | \ | ||
604 | static notrace void \ | ||
605 | ftrace_raw_unreg_event_##call(struct ftrace_event_call *unused) \ | ||
606 | { \ | ||
607 | unregister_trace_##call(ftrace_raw_event_##call); \ | ||
608 | } \ | ||
609 | \ | ||
610 | static struct trace_event ftrace_event_type_##call = { \ | ||
611 | .trace = ftrace_raw_output_##call, \ | ||
612 | }; | ||
613 | 543 | ||
614 | #undef DEFINE_EVENT_PRINT | 544 | #undef DEFINE_EVENT_PRINT |
615 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | 545 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) |
616 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | ||
617 | 546 | ||
618 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | 547 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
619 | 548 | ||
@@ -630,7 +559,16 @@ static struct trace_event ftrace_event_type_##call = { \ | |||
630 | 559 | ||
631 | #undef DECLARE_EVENT_CLASS | 560 | #undef DECLARE_EVENT_CLASS |
632 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | 561 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
633 | static const char print_fmt_##call[] = print; | 562 | _TRACE_PERF_PROTO(call, PARAMS(proto)); \ |
563 | static const char print_fmt_##call[] = print; \ | ||
564 | static struct ftrace_event_class __used event_class_##call = { \ | ||
565 | .system = __stringify(TRACE_SYSTEM), \ | ||
566 | .define_fields = ftrace_define_fields_##call, \ | ||
567 | .fields = LIST_HEAD_INIT(event_class_##call.fields),\ | ||
568 | .raw_init = trace_event_raw_init, \ | ||
569 | .probe = ftrace_raw_event_##call, \ | ||
570 | _TRACE_PERF_INIT(call) \ | ||
571 | }; | ||
634 | 572 | ||
635 | #undef DEFINE_EVENT | 573 | #undef DEFINE_EVENT |
636 | #define DEFINE_EVENT(template, call, proto, args) \ | 574 | #define DEFINE_EVENT(template, call, proto, args) \ |
@@ -639,15 +577,10 @@ static struct ftrace_event_call __used \ | |||
639 | __attribute__((__aligned__(4))) \ | 577 | __attribute__((__aligned__(4))) \ |
640 | __attribute__((section("_ftrace_events"))) event_##call = { \ | 578 | __attribute__((section("_ftrace_events"))) event_##call = { \ |
641 | .name = #call, \ | 579 | .name = #call, \ |
642 | .system = __stringify(TRACE_SYSTEM), \ | 580 | .class = &event_class_##template, \ |
643 | .event = &ftrace_event_type_##call, \ | 581 | .event.funcs = &ftrace_event_type_funcs_##template, \ |
644 | .raw_init = trace_event_raw_init, \ | ||
645 | .regfunc = ftrace_raw_reg_event_##call, \ | ||
646 | .unregfunc = ftrace_raw_unreg_event_##call, \ | ||
647 | .print_fmt = print_fmt_##template, \ | 582 | .print_fmt = print_fmt_##template, \ |
648 | .define_fields = ftrace_define_fields_##template, \ | 583 | }; |
649 | _TRACE_PERF_INIT(call) \ | ||
650 | } | ||
651 | 584 | ||
652 | #undef DEFINE_EVENT_PRINT | 585 | #undef DEFINE_EVENT_PRINT |
653 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ | 586 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ |
@@ -658,14 +591,9 @@ static struct ftrace_event_call __used \ | |||
658 | __attribute__((__aligned__(4))) \ | 591 | __attribute__((__aligned__(4))) \ |
659 | __attribute__((section("_ftrace_events"))) event_##call = { \ | 592 | __attribute__((section("_ftrace_events"))) event_##call = { \ |
660 | .name = #call, \ | 593 | .name = #call, \ |
661 | .system = __stringify(TRACE_SYSTEM), \ | 594 | .class = &event_class_##template, \ |
662 | .event = &ftrace_event_type_##call, \ | 595 | .event.funcs = &ftrace_event_type_funcs_##call, \ |
663 | .raw_init = trace_event_raw_init, \ | ||
664 | .regfunc = ftrace_raw_reg_event_##call, \ | ||
665 | .unregfunc = ftrace_raw_unreg_event_##call, \ | ||
666 | .print_fmt = print_fmt_##call, \ | 596 | .print_fmt = print_fmt_##call, \ |
667 | .define_fields = ftrace_define_fields_##template, \ | ||
668 | _TRACE_PERF_INIT(call) \ | ||
669 | } | 597 | } |
670 | 598 | ||
671 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | 599 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
@@ -765,17 +693,20 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ | |||
765 | #undef DECLARE_EVENT_CLASS | 693 | #undef DECLARE_EVENT_CLASS |
766 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | 694 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
767 | static notrace void \ | 695 | static notrace void \ |
768 | perf_trace_templ_##call(struct ftrace_event_call *event_call, \ | 696 | perf_trace_##call(void *__data, proto) \ |
769 | struct pt_regs *__regs, proto) \ | ||
770 | { \ | 697 | { \ |
698 | struct ftrace_event_call *event_call = __data; \ | ||
771 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ | 699 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
772 | struct ftrace_raw_##call *entry; \ | 700 | struct ftrace_raw_##call *entry; \ |
701 | struct pt_regs __regs; \ | ||
773 | u64 __addr = 0, __count = 1; \ | 702 | u64 __addr = 0, __count = 1; \ |
774 | unsigned long irq_flags; \ | 703 | struct hlist_head *head; \ |
775 | int __entry_size; \ | 704 | int __entry_size; \ |
776 | int __data_size; \ | 705 | int __data_size; \ |
777 | int rctx; \ | 706 | int rctx; \ |
778 | \ | 707 | \ |
708 | perf_fetch_caller_regs(&__regs, 1); \ | ||
709 | \ | ||
779 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ | 710 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ |
780 | __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ | 711 | __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ |
781 | sizeof(u64)); \ | 712 | sizeof(u64)); \ |
@@ -784,32 +715,34 @@ perf_trace_templ_##call(struct ftrace_event_call *event_call, \ | |||
784 | if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \ | 715 | if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \ |
785 | "profile buffer not large enough")) \ | 716 | "profile buffer not large enough")) \ |
786 | return; \ | 717 | return; \ |
718 | \ | ||
787 | entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \ | 719 | entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \ |
788 | __entry_size, event_call->id, &rctx, &irq_flags); \ | 720 | __entry_size, event_call->event.type, &__regs, &rctx); \ |
789 | if (!entry) \ | 721 | if (!entry) \ |
790 | return; \ | 722 | return; \ |
723 | \ | ||
791 | tstruct \ | 724 | tstruct \ |
792 | \ | 725 | \ |
793 | { assign; } \ | 726 | { assign; } \ |
794 | \ | 727 | \ |
728 | head = per_cpu_ptr(event_call->perf_events, smp_processor_id());\ | ||
795 | perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \ | 729 | perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \ |
796 | __count, irq_flags, __regs); \ | 730 | __count, &__regs, head); \ |
797 | } | 731 | } |
798 | 732 | ||
733 | /* | ||
734 | * This part is compiled out, it is only here as a build time check | ||
735 | * to make sure that if the tracepoint handling changes, the | ||
736 | * perf probe will fail to compile unless it too is updated. | ||
737 | */ | ||
799 | #undef DEFINE_EVENT | 738 | #undef DEFINE_EVENT |
800 | #define DEFINE_EVENT(template, call, proto, args) \ | 739 | #define DEFINE_EVENT(template, call, proto, args) \ |
801 | static notrace void perf_trace_##call(proto) \ | 740 | static inline void perf_test_probe_##call(void) \ |
802 | { \ | 741 | { \ |
803 | struct ftrace_event_call *event_call = &event_##call; \ | 742 | check_trace_callback_type_##call(perf_trace_##template); \ |
804 | struct pt_regs *__regs = &get_cpu_var(perf_trace_regs); \ | ||
805 | \ | ||
806 | perf_fetch_caller_regs(__regs, 1); \ | ||
807 | \ | ||
808 | perf_trace_templ_##template(event_call, __regs, args); \ | ||
809 | \ | ||
810 | put_cpu_var(perf_trace_regs); \ | ||
811 | } | 743 | } |
812 | 744 | ||
745 | |||
813 | #undef DEFINE_EVENT_PRINT | 746 | #undef DEFINE_EVENT_PRINT |
814 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ | 747 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
815 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) | 748 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
diff --git a/include/trace/syscall.h b/include/trace/syscall.h index e5e5f48dbfb3..257e08960d7b 100644 --- a/include/trace/syscall.h +++ b/include/trace/syscall.h | |||
@@ -25,6 +25,8 @@ struct syscall_metadata { | |||
25 | int nb_args; | 25 | int nb_args; |
26 | const char **types; | 26 | const char **types; |
27 | const char **args; | 27 | const char **args; |
28 | struct list_head enter_fields; | ||
29 | struct list_head exit_fields; | ||
28 | 30 | ||
29 | struct ftrace_event_call *enter_event; | 31 | struct ftrace_event_call *enter_event; |
30 | struct ftrace_event_call *exit_event; | 32 | struct ftrace_event_call *exit_event; |
@@ -34,16 +36,16 @@ struct syscall_metadata { | |||
34 | extern unsigned long arch_syscall_addr(int nr); | 36 | extern unsigned long arch_syscall_addr(int nr); |
35 | extern int init_syscall_trace(struct ftrace_event_call *call); | 37 | extern int init_syscall_trace(struct ftrace_event_call *call); |
36 | 38 | ||
37 | extern int syscall_enter_define_fields(struct ftrace_event_call *call); | ||
38 | extern int syscall_exit_define_fields(struct ftrace_event_call *call); | ||
39 | extern int reg_event_syscall_enter(struct ftrace_event_call *call); | 39 | extern int reg_event_syscall_enter(struct ftrace_event_call *call); |
40 | extern void unreg_event_syscall_enter(struct ftrace_event_call *call); | 40 | extern void unreg_event_syscall_enter(struct ftrace_event_call *call); |
41 | extern int reg_event_syscall_exit(struct ftrace_event_call *call); | 41 | extern int reg_event_syscall_exit(struct ftrace_event_call *call); |
42 | extern void unreg_event_syscall_exit(struct ftrace_event_call *call); | 42 | extern void unreg_event_syscall_exit(struct ftrace_event_call *call); |
43 | extern int | 43 | extern int |
44 | ftrace_format_syscall(struct ftrace_event_call *call, struct trace_seq *s); | 44 | ftrace_format_syscall(struct ftrace_event_call *call, struct trace_seq *s); |
45 | enum print_line_t print_syscall_enter(struct trace_iterator *iter, int flags); | 45 | enum print_line_t print_syscall_enter(struct trace_iterator *iter, int flags, |
46 | enum print_line_t print_syscall_exit(struct trace_iterator *iter, int flags); | 46 | struct trace_event *event); |
47 | enum print_line_t print_syscall_exit(struct trace_iterator *iter, int flags, | ||
48 | struct trace_event *event); | ||
47 | #endif | 49 | #endif |
48 | 50 | ||
49 | #ifdef CONFIG_PERF_EVENTS | 51 | #ifdef CONFIG_PERF_EVENTS |
diff --git a/kernel/perf_event.c b/kernel/perf_event.c index a4fa381db3c2..e099650cd249 100644 --- a/kernel/perf_event.c +++ b/kernel/perf_event.c | |||
@@ -2297,11 +2297,6 @@ unlock: | |||
2297 | rcu_read_unlock(); | 2297 | rcu_read_unlock(); |
2298 | } | 2298 | } |
2299 | 2299 | ||
2300 | static unsigned long perf_data_size(struct perf_mmap_data *data) | ||
2301 | { | ||
2302 | return data->nr_pages << (PAGE_SHIFT + data->data_order); | ||
2303 | } | ||
2304 | |||
2305 | #ifndef CONFIG_PERF_USE_VMALLOC | 2300 | #ifndef CONFIG_PERF_USE_VMALLOC |
2306 | 2301 | ||
2307 | /* | 2302 | /* |
@@ -2320,6 +2315,19 @@ perf_mmap_to_page(struct perf_mmap_data *data, unsigned long pgoff) | |||
2320 | return virt_to_page(data->data_pages[pgoff - 1]); | 2315 | return virt_to_page(data->data_pages[pgoff - 1]); |
2321 | } | 2316 | } |
2322 | 2317 | ||
2318 | static void *perf_mmap_alloc_page(int cpu) | ||
2319 | { | ||
2320 | struct page *page; | ||
2321 | int node; | ||
2322 | |||
2323 | node = (cpu == -1) ? cpu : cpu_to_node(cpu); | ||
2324 | page = alloc_pages_node(node, GFP_KERNEL | __GFP_ZERO, 0); | ||
2325 | if (!page) | ||
2326 | return NULL; | ||
2327 | |||
2328 | return page_address(page); | ||
2329 | } | ||
2330 | |||
2323 | static struct perf_mmap_data * | 2331 | static struct perf_mmap_data * |
2324 | perf_mmap_data_alloc(struct perf_event *event, int nr_pages) | 2332 | perf_mmap_data_alloc(struct perf_event *event, int nr_pages) |
2325 | { | 2333 | { |
@@ -2336,17 +2344,16 @@ perf_mmap_data_alloc(struct perf_event *event, int nr_pages) | |||
2336 | if (!data) | 2344 | if (!data) |
2337 | goto fail; | 2345 | goto fail; |
2338 | 2346 | ||
2339 | data->user_page = (void *)get_zeroed_page(GFP_KERNEL); | 2347 | data->user_page = perf_mmap_alloc_page(event->cpu); |
2340 | if (!data->user_page) | 2348 | if (!data->user_page) |
2341 | goto fail_user_page; | 2349 | goto fail_user_page; |
2342 | 2350 | ||
2343 | for (i = 0; i < nr_pages; i++) { | 2351 | for (i = 0; i < nr_pages; i++) { |
2344 | data->data_pages[i] = (void *)get_zeroed_page(GFP_KERNEL); | 2352 | data->data_pages[i] = perf_mmap_alloc_page(event->cpu); |
2345 | if (!data->data_pages[i]) | 2353 | if (!data->data_pages[i]) |
2346 | goto fail_data_pages; | 2354 | goto fail_data_pages; |
2347 | } | 2355 | } |
2348 | 2356 | ||
2349 | data->data_order = 0; | ||
2350 | data->nr_pages = nr_pages; | 2357 | data->nr_pages = nr_pages; |
2351 | 2358 | ||
2352 | return data; | 2359 | return data; |
@@ -2382,6 +2389,11 @@ static void perf_mmap_data_free(struct perf_mmap_data *data) | |||
2382 | kfree(data); | 2389 | kfree(data); |
2383 | } | 2390 | } |
2384 | 2391 | ||
2392 | static inline int page_order(struct perf_mmap_data *data) | ||
2393 | { | ||
2394 | return 0; | ||
2395 | } | ||
2396 | |||
2385 | #else | 2397 | #else |
2386 | 2398 | ||
2387 | /* | 2399 | /* |
@@ -2390,10 +2402,15 @@ static void perf_mmap_data_free(struct perf_mmap_data *data) | |||
2390 | * Required for architectures that have d-cache aliasing issues. | 2402 | * Required for architectures that have d-cache aliasing issues. |
2391 | */ | 2403 | */ |
2392 | 2404 | ||
2405 | static inline int page_order(struct perf_mmap_data *data) | ||
2406 | { | ||
2407 | return data->page_order; | ||
2408 | } | ||
2409 | |||
2393 | static struct page * | 2410 | static struct page * |
2394 | perf_mmap_to_page(struct perf_mmap_data *data, unsigned long pgoff) | 2411 | perf_mmap_to_page(struct perf_mmap_data *data, unsigned long pgoff) |
2395 | { | 2412 | { |
2396 | if (pgoff > (1UL << data->data_order)) | 2413 | if (pgoff > (1UL << page_order(data))) |
2397 | return NULL; | 2414 | return NULL; |
2398 | 2415 | ||
2399 | return vmalloc_to_page((void *)data->user_page + pgoff * PAGE_SIZE); | 2416 | return vmalloc_to_page((void *)data->user_page + pgoff * PAGE_SIZE); |
@@ -2413,7 +2430,7 @@ static void perf_mmap_data_free_work(struct work_struct *work) | |||
2413 | int i, nr; | 2430 | int i, nr; |
2414 | 2431 | ||
2415 | data = container_of(work, struct perf_mmap_data, work); | 2432 | data = container_of(work, struct perf_mmap_data, work); |
2416 | nr = 1 << data->data_order; | 2433 | nr = 1 << page_order(data); |
2417 | 2434 | ||
2418 | base = data->user_page; | 2435 | base = data->user_page; |
2419 | for (i = 0; i < nr + 1; i++) | 2436 | for (i = 0; i < nr + 1; i++) |
@@ -2452,7 +2469,7 @@ perf_mmap_data_alloc(struct perf_event *event, int nr_pages) | |||
2452 | 2469 | ||
2453 | data->user_page = all_buf; | 2470 | data->user_page = all_buf; |
2454 | data->data_pages[0] = all_buf + PAGE_SIZE; | 2471 | data->data_pages[0] = all_buf + PAGE_SIZE; |
2455 | data->data_order = ilog2(nr_pages); | 2472 | data->page_order = ilog2(nr_pages); |
2456 | data->nr_pages = 1; | 2473 | data->nr_pages = 1; |
2457 | 2474 | ||
2458 | return data; | 2475 | return data; |
@@ -2466,6 +2483,11 @@ fail: | |||
2466 | 2483 | ||
2467 | #endif | 2484 | #endif |
2468 | 2485 | ||
2486 | static unsigned long perf_data_size(struct perf_mmap_data *data) | ||
2487 | { | ||
2488 | return data->nr_pages << (PAGE_SHIFT + page_order(data)); | ||
2489 | } | ||
2490 | |||
2469 | static int perf_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | 2491 | static int perf_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
2470 | { | 2492 | { |
2471 | struct perf_event *event = vma->vm_file->private_data; | 2493 | struct perf_event *event = vma->vm_file->private_data; |
@@ -2506,8 +2528,6 @@ perf_mmap_data_init(struct perf_event *event, struct perf_mmap_data *data) | |||
2506 | { | 2528 | { |
2507 | long max_size = perf_data_size(data); | 2529 | long max_size = perf_data_size(data); |
2508 | 2530 | ||
2509 | atomic_set(&data->lock, -1); | ||
2510 | |||
2511 | if (event->attr.watermark) { | 2531 | if (event->attr.watermark) { |
2512 | data->watermark = min_t(long, max_size, | 2532 | data->watermark = min_t(long, max_size, |
2513 | event->attr.wakeup_watermark); | 2533 | event->attr.wakeup_watermark); |
@@ -2580,6 +2600,14 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma) | |||
2580 | long user_extra, extra; | 2600 | long user_extra, extra; |
2581 | int ret = 0; | 2601 | int ret = 0; |
2582 | 2602 | ||
2603 | /* | ||
2604 | * Don't allow mmap() of inherited per-task counters. This would | ||
2605 | * create a performance issue due to all children writing to the | ||
2606 | * same buffer. | ||
2607 | */ | ||
2608 | if (event->cpu == -1 && event->attr.inherit) | ||
2609 | return -EINVAL; | ||
2610 | |||
2583 | if (!(vma->vm_flags & VM_SHARED)) | 2611 | if (!(vma->vm_flags & VM_SHARED)) |
2584 | return -EINVAL; | 2612 | return -EINVAL; |
2585 | 2613 | ||
@@ -2885,120 +2913,80 @@ static void perf_output_wakeup(struct perf_output_handle *handle) | |||
2885 | } | 2913 | } |
2886 | 2914 | ||
2887 | /* | 2915 | /* |
2888 | * Curious locking construct. | ||
2889 | * | ||
2890 | * We need to ensure a later event_id doesn't publish a head when a former | 2916 | * We need to ensure a later event_id doesn't publish a head when a former |
2891 | * event_id isn't done writing. However since we need to deal with NMIs we | 2917 | * event isn't done writing. However since we need to deal with NMIs we |
2892 | * cannot fully serialize things. | 2918 | * cannot fully serialize things. |
2893 | * | 2919 | * |
2894 | * What we do is serialize between CPUs so we only have to deal with NMI | ||
2895 | * nesting on a single CPU. | ||
2896 | * | ||
2897 | * We only publish the head (and generate a wakeup) when the outer-most | 2920 | * We only publish the head (and generate a wakeup) when the outer-most |
2898 | * event_id completes. | 2921 | * event completes. |
2899 | */ | 2922 | */ |
2900 | static void perf_output_lock(struct perf_output_handle *handle) | 2923 | static void perf_output_get_handle(struct perf_output_handle *handle) |
2901 | { | 2924 | { |
2902 | struct perf_mmap_data *data = handle->data; | 2925 | struct perf_mmap_data *data = handle->data; |
2903 | int cur, cpu = get_cpu(); | ||
2904 | |||
2905 | handle->locked = 0; | ||
2906 | |||
2907 | for (;;) { | ||
2908 | cur = atomic_cmpxchg(&data->lock, -1, cpu); | ||
2909 | if (cur == -1) { | ||
2910 | handle->locked = 1; | ||
2911 | break; | ||
2912 | } | ||
2913 | if (cur == cpu) | ||
2914 | break; | ||
2915 | 2926 | ||
2916 | cpu_relax(); | 2927 | preempt_disable(); |
2917 | } | 2928 | local_inc(&data->nest); |
2929 | handle->wakeup = local_read(&data->wakeup); | ||
2918 | } | 2930 | } |
2919 | 2931 | ||
2920 | static void perf_output_unlock(struct perf_output_handle *handle) | 2932 | static void perf_output_put_handle(struct perf_output_handle *handle) |
2921 | { | 2933 | { |
2922 | struct perf_mmap_data *data = handle->data; | 2934 | struct perf_mmap_data *data = handle->data; |
2923 | unsigned long head; | 2935 | unsigned long head; |
2924 | int cpu; | ||
2925 | |||
2926 | data->done_head = data->head; | ||
2927 | |||
2928 | if (!handle->locked) | ||
2929 | goto out; | ||
2930 | 2936 | ||
2931 | again: | 2937 | again: |
2932 | /* | 2938 | head = local_read(&data->head); |
2933 | * The xchg implies a full barrier that ensures all writes are done | ||
2934 | * before we publish the new head, matched by a rmb() in userspace when | ||
2935 | * reading this position. | ||
2936 | */ | ||
2937 | while ((head = atomic_long_xchg(&data->done_head, 0))) | ||
2938 | data->user_page->data_head = head; | ||
2939 | 2939 | ||
2940 | /* | 2940 | /* |
2941 | * NMI can happen here, which means we can miss a done_head update. | 2941 | * IRQ/NMI can happen here, which means we can miss a head update. |
2942 | */ | 2942 | */ |
2943 | 2943 | ||
2944 | cpu = atomic_xchg(&data->lock, -1); | 2944 | if (!local_dec_and_test(&data->nest)) |
2945 | WARN_ON_ONCE(cpu != smp_processor_id()); | 2945 | goto out; |
2946 | 2946 | ||
2947 | /* | 2947 | /* |
2948 | * Therefore we have to validate we did not indeed do so. | 2948 | * Publish the known good head. Rely on the full barrier implied |
2949 | * by atomic_dec_and_test() order the data->head read and this | ||
2950 | * write. | ||
2949 | */ | 2951 | */ |
2950 | if (unlikely(atomic_long_read(&data->done_head))) { | 2952 | data->user_page->data_head = head; |
2951 | /* | ||
2952 | * Since we had it locked, we can lock it again. | ||
2953 | */ | ||
2954 | while (atomic_cmpxchg(&data->lock, -1, cpu) != -1) | ||
2955 | cpu_relax(); | ||
2956 | 2953 | ||
2954 | /* | ||
2955 | * Now check if we missed an update, rely on the (compiler) | ||
2956 | * barrier in atomic_dec_and_test() to re-read data->head. | ||
2957 | */ | ||
2958 | if (unlikely(head != local_read(&data->head))) { | ||
2959 | local_inc(&data->nest); | ||
2957 | goto again; | 2960 | goto again; |
2958 | } | 2961 | } |
2959 | 2962 | ||
2960 | if (atomic_xchg(&data->wakeup, 0)) | 2963 | if (handle->wakeup != local_read(&data->wakeup)) |
2961 | perf_output_wakeup(handle); | 2964 | perf_output_wakeup(handle); |
2962 | out: | 2965 | |
2963 | put_cpu(); | 2966 | out: |
2967 | preempt_enable(); | ||
2964 | } | 2968 | } |
2965 | 2969 | ||
2966 | void perf_output_copy(struct perf_output_handle *handle, | 2970 | __always_inline void perf_output_copy(struct perf_output_handle *handle, |
2967 | const void *buf, unsigned int len) | 2971 | const void *buf, unsigned int len) |
2968 | { | 2972 | { |
2969 | unsigned int pages_mask; | ||
2970 | unsigned long offset; | ||
2971 | unsigned int size; | ||
2972 | void **pages; | ||
2973 | |||
2974 | offset = handle->offset; | ||
2975 | pages_mask = handle->data->nr_pages - 1; | ||
2976 | pages = handle->data->data_pages; | ||
2977 | |||
2978 | do { | 2973 | do { |
2979 | unsigned long page_offset; | 2974 | unsigned long size = min_t(unsigned long, handle->size, len); |
2980 | unsigned long page_size; | ||
2981 | int nr; | ||
2982 | 2975 | ||
2983 | nr = (offset >> PAGE_SHIFT) & pages_mask; | 2976 | memcpy(handle->addr, buf, size); |
2984 | page_size = 1UL << (handle->data->data_order + PAGE_SHIFT); | ||
2985 | page_offset = offset & (page_size - 1); | ||
2986 | size = min_t(unsigned int, page_size - page_offset, len); | ||
2987 | 2977 | ||
2988 | memcpy(pages[nr] + page_offset, buf, size); | 2978 | len -= size; |
2979 | handle->addr += size; | ||
2980 | handle->size -= size; | ||
2981 | if (!handle->size) { | ||
2982 | struct perf_mmap_data *data = handle->data; | ||
2989 | 2983 | ||
2990 | len -= size; | 2984 | handle->page++; |
2991 | buf += size; | 2985 | handle->page &= data->nr_pages - 1; |
2992 | offset += size; | 2986 | handle->addr = data->data_pages[handle->page]; |
2987 | handle->size = PAGE_SIZE << page_order(data); | ||
2988 | } | ||
2993 | } while (len); | 2989 | } while (len); |
2994 | |||
2995 | handle->offset = offset; | ||
2996 | |||
2997 | /* | ||
2998 | * Check we didn't copy past our reservation window, taking the | ||
2999 | * possible unsigned int wrap into account. | ||
3000 | */ | ||
3001 | WARN_ON_ONCE(((long)(handle->head - handle->offset)) < 0); | ||
3002 | } | 2990 | } |
3003 | 2991 | ||
3004 | int perf_output_begin(struct perf_output_handle *handle, | 2992 | int perf_output_begin(struct perf_output_handle *handle, |
@@ -3036,13 +3024,13 @@ int perf_output_begin(struct perf_output_handle *handle, | |||
3036 | handle->sample = sample; | 3024 | handle->sample = sample; |
3037 | 3025 | ||
3038 | if (!data->nr_pages) | 3026 | if (!data->nr_pages) |
3039 | goto fail; | 3027 | goto out; |
3040 | 3028 | ||
3041 | have_lost = atomic_read(&data->lost); | 3029 | have_lost = local_read(&data->lost); |
3042 | if (have_lost) | 3030 | if (have_lost) |
3043 | size += sizeof(lost_event); | 3031 | size += sizeof(lost_event); |
3044 | 3032 | ||
3045 | perf_output_lock(handle); | 3033 | perf_output_get_handle(handle); |
3046 | 3034 | ||
3047 | do { | 3035 | do { |
3048 | /* | 3036 | /* |
@@ -3052,24 +3040,28 @@ int perf_output_begin(struct perf_output_handle *handle, | |||
3052 | */ | 3040 | */ |
3053 | tail = ACCESS_ONCE(data->user_page->data_tail); | 3041 | tail = ACCESS_ONCE(data->user_page->data_tail); |
3054 | smp_rmb(); | 3042 | smp_rmb(); |
3055 | offset = head = atomic_long_read(&data->head); | 3043 | offset = head = local_read(&data->head); |
3056 | head += size; | 3044 | head += size; |
3057 | if (unlikely(!perf_output_space(data, tail, offset, head))) | 3045 | if (unlikely(!perf_output_space(data, tail, offset, head))) |
3058 | goto fail; | 3046 | goto fail; |
3059 | } while (atomic_long_cmpxchg(&data->head, offset, head) != offset); | 3047 | } while (local_cmpxchg(&data->head, offset, head) != offset); |
3060 | 3048 | ||
3061 | handle->offset = offset; | 3049 | if (head - local_read(&data->wakeup) > data->watermark) |
3062 | handle->head = head; | 3050 | local_add(data->watermark, &data->wakeup); |
3063 | 3051 | ||
3064 | if (head - tail > data->watermark) | 3052 | handle->page = offset >> (PAGE_SHIFT + page_order(data)); |
3065 | atomic_set(&data->wakeup, 1); | 3053 | handle->page &= data->nr_pages - 1; |
3054 | handle->size = offset & ((PAGE_SIZE << page_order(data)) - 1); | ||
3055 | handle->addr = data->data_pages[handle->page]; | ||
3056 | handle->addr += handle->size; | ||
3057 | handle->size = (PAGE_SIZE << page_order(data)) - handle->size; | ||
3066 | 3058 | ||
3067 | if (have_lost) { | 3059 | if (have_lost) { |
3068 | lost_event.header.type = PERF_RECORD_LOST; | 3060 | lost_event.header.type = PERF_RECORD_LOST; |
3069 | lost_event.header.misc = 0; | 3061 | lost_event.header.misc = 0; |
3070 | lost_event.header.size = sizeof(lost_event); | 3062 | lost_event.header.size = sizeof(lost_event); |
3071 | lost_event.id = event->id; | 3063 | lost_event.id = event->id; |
3072 | lost_event.lost = atomic_xchg(&data->lost, 0); | 3064 | lost_event.lost = local_xchg(&data->lost, 0); |
3073 | 3065 | ||
3074 | perf_output_put(handle, lost_event); | 3066 | perf_output_put(handle, lost_event); |
3075 | } | 3067 | } |
@@ -3077,8 +3069,8 @@ int perf_output_begin(struct perf_output_handle *handle, | |||
3077 | return 0; | 3069 | return 0; |
3078 | 3070 | ||
3079 | fail: | 3071 | fail: |
3080 | atomic_inc(&data->lost); | 3072 | local_inc(&data->lost); |
3081 | perf_output_unlock(handle); | 3073 | perf_output_put_handle(handle); |
3082 | out: | 3074 | out: |
3083 | rcu_read_unlock(); | 3075 | rcu_read_unlock(); |
3084 | 3076 | ||
@@ -3093,14 +3085,14 @@ void perf_output_end(struct perf_output_handle *handle) | |||
3093 | int wakeup_events = event->attr.wakeup_events; | 3085 | int wakeup_events = event->attr.wakeup_events; |
3094 | 3086 | ||
3095 | if (handle->sample && wakeup_events) { | 3087 | if (handle->sample && wakeup_events) { |
3096 | int events = atomic_inc_return(&data->events); | 3088 | int events = local_inc_return(&data->events); |
3097 | if (events >= wakeup_events) { | 3089 | if (events >= wakeup_events) { |
3098 | atomic_sub(wakeup_events, &data->events); | 3090 | local_sub(wakeup_events, &data->events); |
3099 | atomic_set(&data->wakeup, 1); | 3091 | local_inc(&data->wakeup); |
3100 | } | 3092 | } |
3101 | } | 3093 | } |
3102 | 3094 | ||
3103 | perf_output_unlock(handle); | 3095 | perf_output_put_handle(handle); |
3104 | rcu_read_unlock(); | 3096 | rcu_read_unlock(); |
3105 | } | 3097 | } |
3106 | 3098 | ||
@@ -3436,22 +3428,13 @@ static void perf_event_task_output(struct perf_event *event, | |||
3436 | { | 3428 | { |
3437 | struct perf_output_handle handle; | 3429 | struct perf_output_handle handle; |
3438 | struct task_struct *task = task_event->task; | 3430 | struct task_struct *task = task_event->task; |
3439 | unsigned long flags; | ||
3440 | int size, ret; | 3431 | int size, ret; |
3441 | 3432 | ||
3442 | /* | ||
3443 | * If this CPU attempts to acquire an rq lock held by a CPU spinning | ||
3444 | * in perf_output_lock() from interrupt context, it's game over. | ||
3445 | */ | ||
3446 | local_irq_save(flags); | ||
3447 | |||
3448 | size = task_event->event_id.header.size; | 3433 | size = task_event->event_id.header.size; |
3449 | ret = perf_output_begin(&handle, event, size, 0, 0); | 3434 | ret = perf_output_begin(&handle, event, size, 0, 0); |
3450 | 3435 | ||
3451 | if (ret) { | 3436 | if (ret) |
3452 | local_irq_restore(flags); | ||
3453 | return; | 3437 | return; |
3454 | } | ||
3455 | 3438 | ||
3456 | task_event->event_id.pid = perf_event_pid(event, task); | 3439 | task_event->event_id.pid = perf_event_pid(event, task); |
3457 | task_event->event_id.ppid = perf_event_pid(event, current); | 3440 | task_event->event_id.ppid = perf_event_pid(event, current); |
@@ -3462,7 +3445,6 @@ static void perf_event_task_output(struct perf_event *event, | |||
3462 | perf_output_put(&handle, task_event->event_id); | 3445 | perf_output_put(&handle, task_event->event_id); |
3463 | 3446 | ||
3464 | perf_output_end(&handle); | 3447 | perf_output_end(&handle); |
3465 | local_irq_restore(flags); | ||
3466 | } | 3448 | } |
3467 | 3449 | ||
3468 | static int perf_event_task_match(struct perf_event *event) | 3450 | static int perf_event_task_match(struct perf_event *event) |
@@ -4020,9 +4002,6 @@ static void perf_swevent_add(struct perf_event *event, u64 nr, | |||
4020 | perf_swevent_overflow(event, 0, nmi, data, regs); | 4002 | perf_swevent_overflow(event, 0, nmi, data, regs); |
4021 | } | 4003 | } |
4022 | 4004 | ||
4023 | static int perf_tp_event_match(struct perf_event *event, | ||
4024 | struct perf_sample_data *data); | ||
4025 | |||
4026 | static int perf_exclude_event(struct perf_event *event, | 4005 | static int perf_exclude_event(struct perf_event *event, |
4027 | struct pt_regs *regs) | 4006 | struct pt_regs *regs) |
4028 | { | 4007 | { |
@@ -4052,10 +4031,6 @@ static int perf_swevent_match(struct perf_event *event, | |||
4052 | if (perf_exclude_event(event, regs)) | 4031 | if (perf_exclude_event(event, regs)) |
4053 | return 0; | 4032 | return 0; |
4054 | 4033 | ||
4055 | if (event->attr.type == PERF_TYPE_TRACEPOINT && | ||
4056 | !perf_tp_event_match(event, data)) | ||
4057 | return 0; | ||
4058 | |||
4059 | return 1; | 4034 | return 1; |
4060 | } | 4035 | } |
4061 | 4036 | ||
@@ -4066,19 +4041,46 @@ static inline u64 swevent_hash(u64 type, u32 event_id) | |||
4066 | return hash_64(val, SWEVENT_HLIST_BITS); | 4041 | return hash_64(val, SWEVENT_HLIST_BITS); |
4067 | } | 4042 | } |
4068 | 4043 | ||
4069 | static struct hlist_head * | 4044 | static inline struct hlist_head * |
4070 | find_swevent_head(struct perf_cpu_context *ctx, u64 type, u32 event_id) | 4045 | __find_swevent_head(struct swevent_hlist *hlist, u64 type, u32 event_id) |
4071 | { | 4046 | { |
4072 | u64 hash; | 4047 | u64 hash = swevent_hash(type, event_id); |
4073 | struct swevent_hlist *hlist; | 4048 | |
4049 | return &hlist->heads[hash]; | ||
4050 | } | ||
4074 | 4051 | ||
4075 | hash = swevent_hash(type, event_id); | 4052 | /* For the read side: events when they trigger */ |
4053 | static inline struct hlist_head * | ||
4054 | find_swevent_head_rcu(struct perf_cpu_context *ctx, u64 type, u32 event_id) | ||
4055 | { | ||
4056 | struct swevent_hlist *hlist; | ||
4076 | 4057 | ||
4077 | hlist = rcu_dereference(ctx->swevent_hlist); | 4058 | hlist = rcu_dereference(ctx->swevent_hlist); |
4078 | if (!hlist) | 4059 | if (!hlist) |
4079 | return NULL; | 4060 | return NULL; |
4080 | 4061 | ||
4081 | return &hlist->heads[hash]; | 4062 | return __find_swevent_head(hlist, type, event_id); |
4063 | } | ||
4064 | |||
4065 | /* For the event head insertion and removal in the hlist */ | ||
4066 | static inline struct hlist_head * | ||
4067 | find_swevent_head(struct perf_cpu_context *ctx, struct perf_event *event) | ||
4068 | { | ||
4069 | struct swevent_hlist *hlist; | ||
4070 | u32 event_id = event->attr.config; | ||
4071 | u64 type = event->attr.type; | ||
4072 | |||
4073 | /* | ||
4074 | * Event scheduling is always serialized against hlist allocation | ||
4075 | * and release. Which makes the protected version suitable here. | ||
4076 | * The context lock guarantees that. | ||
4077 | */ | ||
4078 | hlist = rcu_dereference_protected(ctx->swevent_hlist, | ||
4079 | lockdep_is_held(&event->ctx->lock)); | ||
4080 | if (!hlist) | ||
4081 | return NULL; | ||
4082 | |||
4083 | return __find_swevent_head(hlist, type, event_id); | ||
4082 | } | 4084 | } |
4083 | 4085 | ||
4084 | static void do_perf_sw_event(enum perf_type_id type, u32 event_id, | 4086 | static void do_perf_sw_event(enum perf_type_id type, u32 event_id, |
@@ -4095,7 +4097,7 @@ static void do_perf_sw_event(enum perf_type_id type, u32 event_id, | |||
4095 | 4097 | ||
4096 | rcu_read_lock(); | 4098 | rcu_read_lock(); |
4097 | 4099 | ||
4098 | head = find_swevent_head(cpuctx, type, event_id); | 4100 | head = find_swevent_head_rcu(cpuctx, type, event_id); |
4099 | 4101 | ||
4100 | if (!head) | 4102 | if (!head) |
4101 | goto end; | 4103 | goto end; |
@@ -4110,7 +4112,7 @@ end: | |||
4110 | 4112 | ||
4111 | int perf_swevent_get_recursion_context(void) | 4113 | int perf_swevent_get_recursion_context(void) |
4112 | { | 4114 | { |
4113 | struct perf_cpu_context *cpuctx = &get_cpu_var(perf_cpu_context); | 4115 | struct perf_cpu_context *cpuctx = &__get_cpu_var(perf_cpu_context); |
4114 | int rctx; | 4116 | int rctx; |
4115 | 4117 | ||
4116 | if (in_nmi()) | 4118 | if (in_nmi()) |
@@ -4122,10 +4124,8 @@ int perf_swevent_get_recursion_context(void) | |||
4122 | else | 4124 | else |
4123 | rctx = 0; | 4125 | rctx = 0; |
4124 | 4126 | ||
4125 | if (cpuctx->recursion[rctx]) { | 4127 | if (cpuctx->recursion[rctx]) |
4126 | put_cpu_var(perf_cpu_context); | ||
4127 | return -1; | 4128 | return -1; |
4128 | } | ||
4129 | 4129 | ||
4130 | cpuctx->recursion[rctx]++; | 4130 | cpuctx->recursion[rctx]++; |
4131 | barrier(); | 4131 | barrier(); |
@@ -4139,7 +4139,6 @@ void perf_swevent_put_recursion_context(int rctx) | |||
4139 | struct perf_cpu_context *cpuctx = &__get_cpu_var(perf_cpu_context); | 4139 | struct perf_cpu_context *cpuctx = &__get_cpu_var(perf_cpu_context); |
4140 | barrier(); | 4140 | barrier(); |
4141 | cpuctx->recursion[rctx]--; | 4141 | cpuctx->recursion[rctx]--; |
4142 | put_cpu_var(perf_cpu_context); | ||
4143 | } | 4142 | } |
4144 | EXPORT_SYMBOL_GPL(perf_swevent_put_recursion_context); | 4143 | EXPORT_SYMBOL_GPL(perf_swevent_put_recursion_context); |
4145 | 4144 | ||
@@ -4150,6 +4149,7 @@ void __perf_sw_event(u32 event_id, u64 nr, int nmi, | |||
4150 | struct perf_sample_data data; | 4149 | struct perf_sample_data data; |
4151 | int rctx; | 4150 | int rctx; |
4152 | 4151 | ||
4152 | preempt_disable_notrace(); | ||
4153 | rctx = perf_swevent_get_recursion_context(); | 4153 | rctx = perf_swevent_get_recursion_context(); |
4154 | if (rctx < 0) | 4154 | if (rctx < 0) |
4155 | return; | 4155 | return; |
@@ -4159,6 +4159,7 @@ void __perf_sw_event(u32 event_id, u64 nr, int nmi, | |||
4159 | do_perf_sw_event(PERF_TYPE_SOFTWARE, event_id, nr, nmi, &data, regs); | 4159 | do_perf_sw_event(PERF_TYPE_SOFTWARE, event_id, nr, nmi, &data, regs); |
4160 | 4160 | ||
4161 | perf_swevent_put_recursion_context(rctx); | 4161 | perf_swevent_put_recursion_context(rctx); |
4162 | preempt_enable_notrace(); | ||
4162 | } | 4163 | } |
4163 | 4164 | ||
4164 | static void perf_swevent_read(struct perf_event *event) | 4165 | static void perf_swevent_read(struct perf_event *event) |
@@ -4178,7 +4179,7 @@ static int perf_swevent_enable(struct perf_event *event) | |||
4178 | perf_swevent_set_period(event); | 4179 | perf_swevent_set_period(event); |
4179 | } | 4180 | } |
4180 | 4181 | ||
4181 | head = find_swevent_head(cpuctx, event->attr.type, event->attr.config); | 4182 | head = find_swevent_head(cpuctx, event); |
4182 | if (WARN_ON_ONCE(!head)) | 4183 | if (WARN_ON_ONCE(!head)) |
4183 | return -EINVAL; | 4184 | return -EINVAL; |
4184 | 4185 | ||
@@ -4366,6 +4367,14 @@ static const struct pmu perf_ops_task_clock = { | |||
4366 | .read = task_clock_perf_event_read, | 4367 | .read = task_clock_perf_event_read, |
4367 | }; | 4368 | }; |
4368 | 4369 | ||
4370 | /* Deref the hlist from the update side */ | ||
4371 | static inline struct swevent_hlist * | ||
4372 | swevent_hlist_deref(struct perf_cpu_context *cpuctx) | ||
4373 | { | ||
4374 | return rcu_dereference_protected(cpuctx->swevent_hlist, | ||
4375 | lockdep_is_held(&cpuctx->hlist_mutex)); | ||
4376 | } | ||
4377 | |||
4369 | static void swevent_hlist_release_rcu(struct rcu_head *rcu_head) | 4378 | static void swevent_hlist_release_rcu(struct rcu_head *rcu_head) |
4370 | { | 4379 | { |
4371 | struct swevent_hlist *hlist; | 4380 | struct swevent_hlist *hlist; |
@@ -4376,12 +4385,11 @@ static void swevent_hlist_release_rcu(struct rcu_head *rcu_head) | |||
4376 | 4385 | ||
4377 | static void swevent_hlist_release(struct perf_cpu_context *cpuctx) | 4386 | static void swevent_hlist_release(struct perf_cpu_context *cpuctx) |
4378 | { | 4387 | { |
4379 | struct swevent_hlist *hlist; | 4388 | struct swevent_hlist *hlist = swevent_hlist_deref(cpuctx); |
4380 | 4389 | ||
4381 | if (!cpuctx->swevent_hlist) | 4390 | if (!hlist) |
4382 | return; | 4391 | return; |
4383 | 4392 | ||
4384 | hlist = cpuctx->swevent_hlist; | ||
4385 | rcu_assign_pointer(cpuctx->swevent_hlist, NULL); | 4393 | rcu_assign_pointer(cpuctx->swevent_hlist, NULL); |
4386 | call_rcu(&hlist->rcu_head, swevent_hlist_release_rcu); | 4394 | call_rcu(&hlist->rcu_head, swevent_hlist_release_rcu); |
4387 | } | 4395 | } |
@@ -4418,7 +4426,7 @@ static int swevent_hlist_get_cpu(struct perf_event *event, int cpu) | |||
4418 | 4426 | ||
4419 | mutex_lock(&cpuctx->hlist_mutex); | 4427 | mutex_lock(&cpuctx->hlist_mutex); |
4420 | 4428 | ||
4421 | if (!cpuctx->swevent_hlist && cpu_online(cpu)) { | 4429 | if (!swevent_hlist_deref(cpuctx) && cpu_online(cpu)) { |
4422 | struct swevent_hlist *hlist; | 4430 | struct swevent_hlist *hlist; |
4423 | 4431 | ||
4424 | hlist = kzalloc(sizeof(*hlist), GFP_KERNEL); | 4432 | hlist = kzalloc(sizeof(*hlist), GFP_KERNEL); |
@@ -4467,10 +4475,46 @@ static int swevent_hlist_get(struct perf_event *event) | |||
4467 | 4475 | ||
4468 | #ifdef CONFIG_EVENT_TRACING | 4476 | #ifdef CONFIG_EVENT_TRACING |
4469 | 4477 | ||
4470 | void perf_tp_event(int event_id, u64 addr, u64 count, void *record, | 4478 | static const struct pmu perf_ops_tracepoint = { |
4471 | int entry_size, struct pt_regs *regs) | 4479 | .enable = perf_trace_enable, |
4480 | .disable = perf_trace_disable, | ||
4481 | .read = perf_swevent_read, | ||
4482 | .unthrottle = perf_swevent_unthrottle, | ||
4483 | }; | ||
4484 | |||
4485 | static int perf_tp_filter_match(struct perf_event *event, | ||
4486 | struct perf_sample_data *data) | ||
4487 | { | ||
4488 | void *record = data->raw->data; | ||
4489 | |||
4490 | if (likely(!event->filter) || filter_match_preds(event->filter, record)) | ||
4491 | return 1; | ||
4492 | return 0; | ||
4493 | } | ||
4494 | |||
4495 | static int perf_tp_event_match(struct perf_event *event, | ||
4496 | struct perf_sample_data *data, | ||
4497 | struct pt_regs *regs) | ||
4498 | { | ||
4499 | /* | ||
4500 | * All tracepoints are from kernel-space. | ||
4501 | */ | ||
4502 | if (event->attr.exclude_kernel) | ||
4503 | return 0; | ||
4504 | |||
4505 | if (!perf_tp_filter_match(event, data)) | ||
4506 | return 0; | ||
4507 | |||
4508 | return 1; | ||
4509 | } | ||
4510 | |||
4511 | void perf_tp_event(u64 addr, u64 count, void *record, int entry_size, | ||
4512 | struct pt_regs *regs, struct hlist_head *head) | ||
4472 | { | 4513 | { |
4473 | struct perf_sample_data data; | 4514 | struct perf_sample_data data; |
4515 | struct perf_event *event; | ||
4516 | struct hlist_node *node; | ||
4517 | |||
4474 | struct perf_raw_record raw = { | 4518 | struct perf_raw_record raw = { |
4475 | .size = entry_size, | 4519 | .size = entry_size, |
4476 | .data = record, | 4520 | .data = record, |
@@ -4479,26 +4523,18 @@ void perf_tp_event(int event_id, u64 addr, u64 count, void *record, | |||
4479 | perf_sample_data_init(&data, addr); | 4523 | perf_sample_data_init(&data, addr); |
4480 | data.raw = &raw; | 4524 | data.raw = &raw; |
4481 | 4525 | ||
4482 | /* Trace events already protected against recursion */ | 4526 | rcu_read_lock(); |
4483 | do_perf_sw_event(PERF_TYPE_TRACEPOINT, event_id, count, 1, | 4527 | hlist_for_each_entry_rcu(event, node, head, hlist_entry) { |
4484 | &data, regs); | 4528 | if (perf_tp_event_match(event, &data, regs)) |
4529 | perf_swevent_add(event, count, 1, &data, regs); | ||
4530 | } | ||
4531 | rcu_read_unlock(); | ||
4485 | } | 4532 | } |
4486 | EXPORT_SYMBOL_GPL(perf_tp_event); | 4533 | EXPORT_SYMBOL_GPL(perf_tp_event); |
4487 | 4534 | ||
4488 | static int perf_tp_event_match(struct perf_event *event, | ||
4489 | struct perf_sample_data *data) | ||
4490 | { | ||
4491 | void *record = data->raw->data; | ||
4492 | |||
4493 | if (likely(!event->filter) || filter_match_preds(event->filter, record)) | ||
4494 | return 1; | ||
4495 | return 0; | ||
4496 | } | ||
4497 | |||
4498 | static void tp_perf_event_destroy(struct perf_event *event) | 4535 | static void tp_perf_event_destroy(struct perf_event *event) |
4499 | { | 4536 | { |
4500 | perf_trace_disable(event->attr.config); | 4537 | perf_trace_destroy(event); |
4501 | swevent_hlist_put(event); | ||
4502 | } | 4538 | } |
4503 | 4539 | ||
4504 | static const struct pmu *tp_perf_event_init(struct perf_event *event) | 4540 | static const struct pmu *tp_perf_event_init(struct perf_event *event) |
@@ -4514,17 +4550,13 @@ static const struct pmu *tp_perf_event_init(struct perf_event *event) | |||
4514 | !capable(CAP_SYS_ADMIN)) | 4550 | !capable(CAP_SYS_ADMIN)) |
4515 | return ERR_PTR(-EPERM); | 4551 | return ERR_PTR(-EPERM); |
4516 | 4552 | ||
4517 | if (perf_trace_enable(event->attr.config)) | 4553 | err = perf_trace_init(event); |
4554 | if (err) | ||
4518 | return NULL; | 4555 | return NULL; |
4519 | 4556 | ||
4520 | event->destroy = tp_perf_event_destroy; | 4557 | event->destroy = tp_perf_event_destroy; |
4521 | err = swevent_hlist_get(event); | ||
4522 | if (err) { | ||
4523 | perf_trace_disable(event->attr.config); | ||
4524 | return ERR_PTR(err); | ||
4525 | } | ||
4526 | 4558 | ||
4527 | return &perf_ops_generic; | 4559 | return &perf_ops_tracepoint; |
4528 | } | 4560 | } |
4529 | 4561 | ||
4530 | static int perf_event_set_filter(struct perf_event *event, void __user *arg) | 4562 | static int perf_event_set_filter(struct perf_event *event, void __user *arg) |
@@ -4552,12 +4584,6 @@ static void perf_event_free_filter(struct perf_event *event) | |||
4552 | 4584 | ||
4553 | #else | 4585 | #else |
4554 | 4586 | ||
4555 | static int perf_tp_event_match(struct perf_event *event, | ||
4556 | struct perf_sample_data *data) | ||
4557 | { | ||
4558 | return 1; | ||
4559 | } | ||
4560 | |||
4561 | static const struct pmu *tp_perf_event_init(struct perf_event *event) | 4587 | static const struct pmu *tp_perf_event_init(struct perf_event *event) |
4562 | { | 4588 | { |
4563 | return NULL; | 4589 | return NULL; |
@@ -4894,6 +4920,13 @@ static int perf_event_set_output(struct perf_event *event, int output_fd) | |||
4894 | int fput_needed = 0; | 4920 | int fput_needed = 0; |
4895 | int ret = -EINVAL; | 4921 | int ret = -EINVAL; |
4896 | 4922 | ||
4923 | /* | ||
4924 | * Don't allow output of inherited per-task events. This would | ||
4925 | * create performance issues due to cross cpu access. | ||
4926 | */ | ||
4927 | if (event->cpu == -1 && event->attr.inherit) | ||
4928 | return -EINVAL; | ||
4929 | |||
4897 | if (!output_fd) | 4930 | if (!output_fd) |
4898 | goto set; | 4931 | goto set; |
4899 | 4932 | ||
@@ -4914,6 +4947,18 @@ static int perf_event_set_output(struct perf_event *event, int output_fd) | |||
4914 | if (event->data) | 4947 | if (event->data) |
4915 | goto out; | 4948 | goto out; |
4916 | 4949 | ||
4950 | /* | ||
4951 | * Don't allow cross-cpu buffers | ||
4952 | */ | ||
4953 | if (output_event->cpu != event->cpu) | ||
4954 | goto out; | ||
4955 | |||
4956 | /* | ||
4957 | * If its not a per-cpu buffer, it must be the same task. | ||
4958 | */ | ||
4959 | if (output_event->cpu == -1 && output_event->ctx != event->ctx) | ||
4960 | goto out; | ||
4961 | |||
4917 | atomic_long_inc(&output_file->f_count); | 4962 | atomic_long_inc(&output_file->f_count); |
4918 | 4963 | ||
4919 | set: | 4964 | set: |
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index b3bc91a3f510..36ea2b65dcdc 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c | |||
@@ -675,28 +675,33 @@ static void blk_add_trace_rq(struct request_queue *q, struct request *rq, | |||
675 | } | 675 | } |
676 | } | 676 | } |
677 | 677 | ||
678 | static void blk_add_trace_rq_abort(struct request_queue *q, struct request *rq) | 678 | static void blk_add_trace_rq_abort(void *ignore, |
679 | struct request_queue *q, struct request *rq) | ||
679 | { | 680 | { |
680 | blk_add_trace_rq(q, rq, BLK_TA_ABORT); | 681 | blk_add_trace_rq(q, rq, BLK_TA_ABORT); |
681 | } | 682 | } |
682 | 683 | ||
683 | static void blk_add_trace_rq_insert(struct request_queue *q, struct request *rq) | 684 | static void blk_add_trace_rq_insert(void *ignore, |
685 | struct request_queue *q, struct request *rq) | ||
684 | { | 686 | { |
685 | blk_add_trace_rq(q, rq, BLK_TA_INSERT); | 687 | blk_add_trace_rq(q, rq, BLK_TA_INSERT); |
686 | } | 688 | } |
687 | 689 | ||
688 | static void blk_add_trace_rq_issue(struct request_queue *q, struct request *rq) | 690 | static void blk_add_trace_rq_issue(void *ignore, |
691 | struct request_queue *q, struct request *rq) | ||
689 | { | 692 | { |
690 | blk_add_trace_rq(q, rq, BLK_TA_ISSUE); | 693 | blk_add_trace_rq(q, rq, BLK_TA_ISSUE); |
691 | } | 694 | } |
692 | 695 | ||
693 | static void blk_add_trace_rq_requeue(struct request_queue *q, | 696 | static void blk_add_trace_rq_requeue(void *ignore, |
697 | struct request_queue *q, | ||
694 | struct request *rq) | 698 | struct request *rq) |
695 | { | 699 | { |
696 | blk_add_trace_rq(q, rq, BLK_TA_REQUEUE); | 700 | blk_add_trace_rq(q, rq, BLK_TA_REQUEUE); |
697 | } | 701 | } |
698 | 702 | ||
699 | static void blk_add_trace_rq_complete(struct request_queue *q, | 703 | static void blk_add_trace_rq_complete(void *ignore, |
704 | struct request_queue *q, | ||
700 | struct request *rq) | 705 | struct request *rq) |
701 | { | 706 | { |
702 | blk_add_trace_rq(q, rq, BLK_TA_COMPLETE); | 707 | blk_add_trace_rq(q, rq, BLK_TA_COMPLETE); |
@@ -724,34 +729,40 @@ static void blk_add_trace_bio(struct request_queue *q, struct bio *bio, | |||
724 | !bio_flagged(bio, BIO_UPTODATE), 0, NULL); | 729 | !bio_flagged(bio, BIO_UPTODATE), 0, NULL); |
725 | } | 730 | } |
726 | 731 | ||
727 | static void blk_add_trace_bio_bounce(struct request_queue *q, struct bio *bio) | 732 | static void blk_add_trace_bio_bounce(void *ignore, |
733 | struct request_queue *q, struct bio *bio) | ||
728 | { | 734 | { |
729 | blk_add_trace_bio(q, bio, BLK_TA_BOUNCE); | 735 | blk_add_trace_bio(q, bio, BLK_TA_BOUNCE); |
730 | } | 736 | } |
731 | 737 | ||
732 | static void blk_add_trace_bio_complete(struct request_queue *q, struct bio *bio) | 738 | static void blk_add_trace_bio_complete(void *ignore, |
739 | struct request_queue *q, struct bio *bio) | ||
733 | { | 740 | { |
734 | blk_add_trace_bio(q, bio, BLK_TA_COMPLETE); | 741 | blk_add_trace_bio(q, bio, BLK_TA_COMPLETE); |
735 | } | 742 | } |
736 | 743 | ||
737 | static void blk_add_trace_bio_backmerge(struct request_queue *q, | 744 | static void blk_add_trace_bio_backmerge(void *ignore, |
745 | struct request_queue *q, | ||
738 | struct bio *bio) | 746 | struct bio *bio) |
739 | { | 747 | { |
740 | blk_add_trace_bio(q, bio, BLK_TA_BACKMERGE); | 748 | blk_add_trace_bio(q, bio, BLK_TA_BACKMERGE); |
741 | } | 749 | } |
742 | 750 | ||
743 | static void blk_add_trace_bio_frontmerge(struct request_queue *q, | 751 | static void blk_add_trace_bio_frontmerge(void *ignore, |
752 | struct request_queue *q, | ||
744 | struct bio *bio) | 753 | struct bio *bio) |
745 | { | 754 | { |
746 | blk_add_trace_bio(q, bio, BLK_TA_FRONTMERGE); | 755 | blk_add_trace_bio(q, bio, BLK_TA_FRONTMERGE); |
747 | } | 756 | } |
748 | 757 | ||
749 | static void blk_add_trace_bio_queue(struct request_queue *q, struct bio *bio) | 758 | static void blk_add_trace_bio_queue(void *ignore, |
759 | struct request_queue *q, struct bio *bio) | ||
750 | { | 760 | { |
751 | blk_add_trace_bio(q, bio, BLK_TA_QUEUE); | 761 | blk_add_trace_bio(q, bio, BLK_TA_QUEUE); |
752 | } | 762 | } |
753 | 763 | ||
754 | static void blk_add_trace_getrq(struct request_queue *q, | 764 | static void blk_add_trace_getrq(void *ignore, |
765 | struct request_queue *q, | ||
755 | struct bio *bio, int rw) | 766 | struct bio *bio, int rw) |
756 | { | 767 | { |
757 | if (bio) | 768 | if (bio) |
@@ -765,7 +776,8 @@ static void blk_add_trace_getrq(struct request_queue *q, | |||
765 | } | 776 | } |
766 | 777 | ||
767 | 778 | ||
768 | static void blk_add_trace_sleeprq(struct request_queue *q, | 779 | static void blk_add_trace_sleeprq(void *ignore, |
780 | struct request_queue *q, | ||
769 | struct bio *bio, int rw) | 781 | struct bio *bio, int rw) |
770 | { | 782 | { |
771 | if (bio) | 783 | if (bio) |
@@ -779,7 +791,7 @@ static void blk_add_trace_sleeprq(struct request_queue *q, | |||
779 | } | 791 | } |
780 | } | 792 | } |
781 | 793 | ||
782 | static void blk_add_trace_plug(struct request_queue *q) | 794 | static void blk_add_trace_plug(void *ignore, struct request_queue *q) |
783 | { | 795 | { |
784 | struct blk_trace *bt = q->blk_trace; | 796 | struct blk_trace *bt = q->blk_trace; |
785 | 797 | ||
@@ -787,7 +799,7 @@ static void blk_add_trace_plug(struct request_queue *q) | |||
787 | __blk_add_trace(bt, 0, 0, 0, BLK_TA_PLUG, 0, 0, NULL); | 799 | __blk_add_trace(bt, 0, 0, 0, BLK_TA_PLUG, 0, 0, NULL); |
788 | } | 800 | } |
789 | 801 | ||
790 | static void blk_add_trace_unplug_io(struct request_queue *q) | 802 | static void blk_add_trace_unplug_io(void *ignore, struct request_queue *q) |
791 | { | 803 | { |
792 | struct blk_trace *bt = q->blk_trace; | 804 | struct blk_trace *bt = q->blk_trace; |
793 | 805 | ||
@@ -800,7 +812,7 @@ static void blk_add_trace_unplug_io(struct request_queue *q) | |||
800 | } | 812 | } |
801 | } | 813 | } |
802 | 814 | ||
803 | static void blk_add_trace_unplug_timer(struct request_queue *q) | 815 | static void blk_add_trace_unplug_timer(void *ignore, struct request_queue *q) |
804 | { | 816 | { |
805 | struct blk_trace *bt = q->blk_trace; | 817 | struct blk_trace *bt = q->blk_trace; |
806 | 818 | ||
@@ -813,7 +825,8 @@ static void blk_add_trace_unplug_timer(struct request_queue *q) | |||
813 | } | 825 | } |
814 | } | 826 | } |
815 | 827 | ||
816 | static void blk_add_trace_split(struct request_queue *q, struct bio *bio, | 828 | static void blk_add_trace_split(void *ignore, |
829 | struct request_queue *q, struct bio *bio, | ||
817 | unsigned int pdu) | 830 | unsigned int pdu) |
818 | { | 831 | { |
819 | struct blk_trace *bt = q->blk_trace; | 832 | struct blk_trace *bt = q->blk_trace; |
@@ -839,8 +852,9 @@ static void blk_add_trace_split(struct request_queue *q, struct bio *bio, | |||
839 | * it spans a stripe (or similar). Add a trace for that action. | 852 | * it spans a stripe (or similar). Add a trace for that action. |
840 | * | 853 | * |
841 | **/ | 854 | **/ |
842 | static void blk_add_trace_remap(struct request_queue *q, struct bio *bio, | 855 | static void blk_add_trace_remap(void *ignore, |
843 | dev_t dev, sector_t from) | 856 | struct request_queue *q, struct bio *bio, |
857 | dev_t dev, sector_t from) | ||
844 | { | 858 | { |
845 | struct blk_trace *bt = q->blk_trace; | 859 | struct blk_trace *bt = q->blk_trace; |
846 | struct blk_io_trace_remap r; | 860 | struct blk_io_trace_remap r; |
@@ -869,7 +883,8 @@ static void blk_add_trace_remap(struct request_queue *q, struct bio *bio, | |||
869 | * Add a trace for that action. | 883 | * Add a trace for that action. |
870 | * | 884 | * |
871 | **/ | 885 | **/ |
872 | static void blk_add_trace_rq_remap(struct request_queue *q, | 886 | static void blk_add_trace_rq_remap(void *ignore, |
887 | struct request_queue *q, | ||
873 | struct request *rq, dev_t dev, | 888 | struct request *rq, dev_t dev, |
874 | sector_t from) | 889 | sector_t from) |
875 | { | 890 | { |
@@ -921,64 +936,64 @@ static void blk_register_tracepoints(void) | |||
921 | { | 936 | { |
922 | int ret; | 937 | int ret; |
923 | 938 | ||
924 | ret = register_trace_block_rq_abort(blk_add_trace_rq_abort); | 939 | ret = register_trace_block_rq_abort(blk_add_trace_rq_abort, NULL); |
925 | WARN_ON(ret); | 940 | WARN_ON(ret); |
926 | ret = register_trace_block_rq_insert(blk_add_trace_rq_insert); | 941 | ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL); |
927 | WARN_ON(ret); | 942 | WARN_ON(ret); |
928 | ret = register_trace_block_rq_issue(blk_add_trace_rq_issue); | 943 | ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL); |
929 | WARN_ON(ret); | 944 | WARN_ON(ret); |
930 | ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue); | 945 | ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL); |
931 | WARN_ON(ret); | 946 | WARN_ON(ret); |
932 | ret = register_trace_block_rq_complete(blk_add_trace_rq_complete); | 947 | ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL); |
933 | WARN_ON(ret); | 948 | WARN_ON(ret); |
934 | ret = register_trace_block_bio_bounce(blk_add_trace_bio_bounce); | 949 | ret = register_trace_block_bio_bounce(blk_add_trace_bio_bounce, NULL); |
935 | WARN_ON(ret); | 950 | WARN_ON(ret); |
936 | ret = register_trace_block_bio_complete(blk_add_trace_bio_complete); | 951 | ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL); |
937 | WARN_ON(ret); | 952 | WARN_ON(ret); |
938 | ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge); | 953 | ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL); |
939 | WARN_ON(ret); | 954 | WARN_ON(ret); |
940 | ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge); | 955 | ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL); |
941 | WARN_ON(ret); | 956 | WARN_ON(ret); |
942 | ret = register_trace_block_bio_queue(blk_add_trace_bio_queue); | 957 | ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL); |
943 | WARN_ON(ret); | 958 | WARN_ON(ret); |
944 | ret = register_trace_block_getrq(blk_add_trace_getrq); | 959 | ret = register_trace_block_getrq(blk_add_trace_getrq, NULL); |
945 | WARN_ON(ret); | 960 | WARN_ON(ret); |
946 | ret = register_trace_block_sleeprq(blk_add_trace_sleeprq); | 961 | ret = register_trace_block_sleeprq(blk_add_trace_sleeprq, NULL); |
947 | WARN_ON(ret); | 962 | WARN_ON(ret); |
948 | ret = register_trace_block_plug(blk_add_trace_plug); | 963 | ret = register_trace_block_plug(blk_add_trace_plug, NULL); |
949 | WARN_ON(ret); | 964 | WARN_ON(ret); |
950 | ret = register_trace_block_unplug_timer(blk_add_trace_unplug_timer); | 965 | ret = register_trace_block_unplug_timer(blk_add_trace_unplug_timer, NULL); |
951 | WARN_ON(ret); | 966 | WARN_ON(ret); |
952 | ret = register_trace_block_unplug_io(blk_add_trace_unplug_io); | 967 | ret = register_trace_block_unplug_io(blk_add_trace_unplug_io, NULL); |
953 | WARN_ON(ret); | 968 | WARN_ON(ret); |
954 | ret = register_trace_block_split(blk_add_trace_split); | 969 | ret = register_trace_block_split(blk_add_trace_split, NULL); |
955 | WARN_ON(ret); | 970 | WARN_ON(ret); |
956 | ret = register_trace_block_remap(blk_add_trace_remap); | 971 | ret = register_trace_block_remap(blk_add_trace_remap, NULL); |
957 | WARN_ON(ret); | 972 | WARN_ON(ret); |
958 | ret = register_trace_block_rq_remap(blk_add_trace_rq_remap); | 973 | ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL); |
959 | WARN_ON(ret); | 974 | WARN_ON(ret); |
960 | } | 975 | } |
961 | 976 | ||
962 | static void blk_unregister_tracepoints(void) | 977 | static void blk_unregister_tracepoints(void) |
963 | { | 978 | { |
964 | unregister_trace_block_rq_remap(blk_add_trace_rq_remap); | 979 | unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL); |
965 | unregister_trace_block_remap(blk_add_trace_remap); | 980 | unregister_trace_block_remap(blk_add_trace_remap, NULL); |
966 | unregister_trace_block_split(blk_add_trace_split); | 981 | unregister_trace_block_split(blk_add_trace_split, NULL); |
967 | unregister_trace_block_unplug_io(blk_add_trace_unplug_io); | 982 | unregister_trace_block_unplug_io(blk_add_trace_unplug_io, NULL); |
968 | unregister_trace_block_unplug_timer(blk_add_trace_unplug_timer); | 983 | unregister_trace_block_unplug_timer(blk_add_trace_unplug_timer, NULL); |
969 | unregister_trace_block_plug(blk_add_trace_plug); | 984 | unregister_trace_block_plug(blk_add_trace_plug, NULL); |
970 | unregister_trace_block_sleeprq(blk_add_trace_sleeprq); | 985 | unregister_trace_block_sleeprq(blk_add_trace_sleeprq, NULL); |
971 | unregister_trace_block_getrq(blk_add_trace_getrq); | 986 | unregister_trace_block_getrq(blk_add_trace_getrq, NULL); |
972 | unregister_trace_block_bio_queue(blk_add_trace_bio_queue); | 987 | unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL); |
973 | unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge); | 988 | unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL); |
974 | unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge); | 989 | unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL); |
975 | unregister_trace_block_bio_complete(blk_add_trace_bio_complete); | 990 | unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL); |
976 | unregister_trace_block_bio_bounce(blk_add_trace_bio_bounce); | 991 | unregister_trace_block_bio_bounce(blk_add_trace_bio_bounce, NULL); |
977 | unregister_trace_block_rq_complete(blk_add_trace_rq_complete); | 992 | unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL); |
978 | unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue); | 993 | unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL); |
979 | unregister_trace_block_rq_issue(blk_add_trace_rq_issue); | 994 | unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL); |
980 | unregister_trace_block_rq_insert(blk_add_trace_rq_insert); | 995 | unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL); |
981 | unregister_trace_block_rq_abort(blk_add_trace_rq_abort); | 996 | unregister_trace_block_rq_abort(blk_add_trace_rq_abort, NULL); |
982 | 997 | ||
983 | tracepoint_synchronize_unregister(); | 998 | tracepoint_synchronize_unregister(); |
984 | } | 999 | } |
@@ -1321,7 +1336,7 @@ out: | |||
1321 | } | 1336 | } |
1322 | 1337 | ||
1323 | static enum print_line_t blk_trace_event_print(struct trace_iterator *iter, | 1338 | static enum print_line_t blk_trace_event_print(struct trace_iterator *iter, |
1324 | int flags) | 1339 | int flags, struct trace_event *event) |
1325 | { | 1340 | { |
1326 | return print_one_line(iter, false); | 1341 | return print_one_line(iter, false); |
1327 | } | 1342 | } |
@@ -1343,7 +1358,8 @@ static int blk_trace_synthesize_old_trace(struct trace_iterator *iter) | |||
1343 | } | 1358 | } |
1344 | 1359 | ||
1345 | static enum print_line_t | 1360 | static enum print_line_t |
1346 | blk_trace_event_print_binary(struct trace_iterator *iter, int flags) | 1361 | blk_trace_event_print_binary(struct trace_iterator *iter, int flags, |
1362 | struct trace_event *event) | ||
1347 | { | 1363 | { |
1348 | return blk_trace_synthesize_old_trace(iter) ? | 1364 | return blk_trace_synthesize_old_trace(iter) ? |
1349 | TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; | 1365 | TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; |
@@ -1381,12 +1397,16 @@ static struct tracer blk_tracer __read_mostly = { | |||
1381 | .set_flag = blk_tracer_set_flag, | 1397 | .set_flag = blk_tracer_set_flag, |
1382 | }; | 1398 | }; |
1383 | 1399 | ||
1384 | static struct trace_event trace_blk_event = { | 1400 | static struct trace_event_functions trace_blk_event_funcs = { |
1385 | .type = TRACE_BLK, | ||
1386 | .trace = blk_trace_event_print, | 1401 | .trace = blk_trace_event_print, |
1387 | .binary = blk_trace_event_print_binary, | 1402 | .binary = blk_trace_event_print_binary, |
1388 | }; | 1403 | }; |
1389 | 1404 | ||
1405 | static struct trace_event trace_blk_event = { | ||
1406 | .type = TRACE_BLK, | ||
1407 | .funcs = &trace_blk_event_funcs, | ||
1408 | }; | ||
1409 | |||
1390 | static int __init init_blk_tracer(void) | 1410 | static int __init init_blk_tracer(void) |
1391 | { | 1411 | { |
1392 | if (!register_ftrace_event(&trace_blk_event)) { | 1412 | if (!register_ftrace_event(&trace_blk_event)) { |
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 32837e19e3bd..6d2cb14f9449 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
@@ -3234,7 +3234,8 @@ free: | |||
3234 | } | 3234 | } |
3235 | 3235 | ||
3236 | static void | 3236 | static void |
3237 | ftrace_graph_probe_sched_switch(struct task_struct *prev, struct task_struct *next) | 3237 | ftrace_graph_probe_sched_switch(void *ignore, |
3238 | struct task_struct *prev, struct task_struct *next) | ||
3238 | { | 3239 | { |
3239 | unsigned long long timestamp; | 3240 | unsigned long long timestamp; |
3240 | int index; | 3241 | int index; |
@@ -3288,7 +3289,7 @@ static int start_graph_tracing(void) | |||
3288 | } while (ret == -EAGAIN); | 3289 | } while (ret == -EAGAIN); |
3289 | 3290 | ||
3290 | if (!ret) { | 3291 | if (!ret) { |
3291 | ret = register_trace_sched_switch(ftrace_graph_probe_sched_switch); | 3292 | ret = register_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL); |
3292 | if (ret) | 3293 | if (ret) |
3293 | pr_info("ftrace_graph: Couldn't activate tracepoint" | 3294 | pr_info("ftrace_graph: Couldn't activate tracepoint" |
3294 | " probe to kernel_sched_switch\n"); | 3295 | " probe to kernel_sched_switch\n"); |
@@ -3364,7 +3365,7 @@ void unregister_ftrace_graph(void) | |||
3364 | ftrace_graph_entry = ftrace_graph_entry_stub; | 3365 | ftrace_graph_entry = ftrace_graph_entry_stub; |
3365 | ftrace_shutdown(FTRACE_STOP_FUNC_RET); | 3366 | ftrace_shutdown(FTRACE_STOP_FUNC_RET); |
3366 | unregister_pm_notifier(&ftrace_suspend_notifier); | 3367 | unregister_pm_notifier(&ftrace_suspend_notifier); |
3367 | unregister_trace_sched_switch(ftrace_graph_probe_sched_switch); | 3368 | unregister_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL); |
3368 | 3369 | ||
3369 | out: | 3370 | out: |
3370 | mutex_unlock(&ftrace_lock); | 3371 | mutex_unlock(&ftrace_lock); |
diff --git a/kernel/trace/kmemtrace.c b/kernel/trace/kmemtrace.c index a91da69f153a..bbfc1bb1660b 100644 --- a/kernel/trace/kmemtrace.c +++ b/kernel/trace/kmemtrace.c | |||
@@ -95,7 +95,8 @@ static inline void kmemtrace_free(enum kmemtrace_type_id type_id, | |||
95 | trace_wake_up(); | 95 | trace_wake_up(); |
96 | } | 96 | } |
97 | 97 | ||
98 | static void kmemtrace_kmalloc(unsigned long call_site, | 98 | static void kmemtrace_kmalloc(void *ignore, |
99 | unsigned long call_site, | ||
99 | const void *ptr, | 100 | const void *ptr, |
100 | size_t bytes_req, | 101 | size_t bytes_req, |
101 | size_t bytes_alloc, | 102 | size_t bytes_alloc, |
@@ -105,7 +106,8 @@ static void kmemtrace_kmalloc(unsigned long call_site, | |||
105 | bytes_req, bytes_alloc, gfp_flags, -1); | 106 | bytes_req, bytes_alloc, gfp_flags, -1); |
106 | } | 107 | } |
107 | 108 | ||
108 | static void kmemtrace_kmem_cache_alloc(unsigned long call_site, | 109 | static void kmemtrace_kmem_cache_alloc(void *ignore, |
110 | unsigned long call_site, | ||
109 | const void *ptr, | 111 | const void *ptr, |
110 | size_t bytes_req, | 112 | size_t bytes_req, |
111 | size_t bytes_alloc, | 113 | size_t bytes_alloc, |
@@ -115,7 +117,8 @@ static void kmemtrace_kmem_cache_alloc(unsigned long call_site, | |||
115 | bytes_req, bytes_alloc, gfp_flags, -1); | 117 | bytes_req, bytes_alloc, gfp_flags, -1); |
116 | } | 118 | } |
117 | 119 | ||
118 | static void kmemtrace_kmalloc_node(unsigned long call_site, | 120 | static void kmemtrace_kmalloc_node(void *ignore, |
121 | unsigned long call_site, | ||
119 | const void *ptr, | 122 | const void *ptr, |
120 | size_t bytes_req, | 123 | size_t bytes_req, |
121 | size_t bytes_alloc, | 124 | size_t bytes_alloc, |
@@ -126,7 +129,8 @@ static void kmemtrace_kmalloc_node(unsigned long call_site, | |||
126 | bytes_req, bytes_alloc, gfp_flags, node); | 129 | bytes_req, bytes_alloc, gfp_flags, node); |
127 | } | 130 | } |
128 | 131 | ||
129 | static void kmemtrace_kmem_cache_alloc_node(unsigned long call_site, | 132 | static void kmemtrace_kmem_cache_alloc_node(void *ignore, |
133 | unsigned long call_site, | ||
130 | const void *ptr, | 134 | const void *ptr, |
131 | size_t bytes_req, | 135 | size_t bytes_req, |
132 | size_t bytes_alloc, | 136 | size_t bytes_alloc, |
@@ -137,12 +141,14 @@ static void kmemtrace_kmem_cache_alloc_node(unsigned long call_site, | |||
137 | bytes_req, bytes_alloc, gfp_flags, node); | 141 | bytes_req, bytes_alloc, gfp_flags, node); |
138 | } | 142 | } |
139 | 143 | ||
140 | static void kmemtrace_kfree(unsigned long call_site, const void *ptr) | 144 | static void |
145 | kmemtrace_kfree(void *ignore, unsigned long call_site, const void *ptr) | ||
141 | { | 146 | { |
142 | kmemtrace_free(KMEMTRACE_TYPE_KMALLOC, call_site, ptr); | 147 | kmemtrace_free(KMEMTRACE_TYPE_KMALLOC, call_site, ptr); |
143 | } | 148 | } |
144 | 149 | ||
145 | static void kmemtrace_kmem_cache_free(unsigned long call_site, const void *ptr) | 150 | static void kmemtrace_kmem_cache_free(void *ignore, |
151 | unsigned long call_site, const void *ptr) | ||
146 | { | 152 | { |
147 | kmemtrace_free(KMEMTRACE_TYPE_CACHE, call_site, ptr); | 153 | kmemtrace_free(KMEMTRACE_TYPE_CACHE, call_site, ptr); |
148 | } | 154 | } |
@@ -151,34 +157,34 @@ static int kmemtrace_start_probes(void) | |||
151 | { | 157 | { |
152 | int err; | 158 | int err; |
153 | 159 | ||
154 | err = register_trace_kmalloc(kmemtrace_kmalloc); | 160 | err = register_trace_kmalloc(kmemtrace_kmalloc, NULL); |
155 | if (err) | 161 | if (err) |
156 | return err; | 162 | return err; |
157 | err = register_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc); | 163 | err = register_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc, NULL); |
158 | if (err) | 164 | if (err) |
159 | return err; | 165 | return err; |
160 | err = register_trace_kmalloc_node(kmemtrace_kmalloc_node); | 166 | err = register_trace_kmalloc_node(kmemtrace_kmalloc_node, NULL); |
161 | if (err) | 167 | if (err) |
162 | return err; | 168 | return err; |
163 | err = register_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node); | 169 | err = register_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node, NULL); |
164 | if (err) | 170 | if (err) |
165 | return err; | 171 | return err; |
166 | err = register_trace_kfree(kmemtrace_kfree); | 172 | err = register_trace_kfree(kmemtrace_kfree, NULL); |
167 | if (err) | 173 | if (err) |
168 | return err; | 174 | return err; |
169 | err = register_trace_kmem_cache_free(kmemtrace_kmem_cache_free); | 175 | err = register_trace_kmem_cache_free(kmemtrace_kmem_cache_free, NULL); |
170 | 176 | ||
171 | return err; | 177 | return err; |
172 | } | 178 | } |
173 | 179 | ||
174 | static void kmemtrace_stop_probes(void) | 180 | static void kmemtrace_stop_probes(void) |
175 | { | 181 | { |
176 | unregister_trace_kmalloc(kmemtrace_kmalloc); | 182 | unregister_trace_kmalloc(kmemtrace_kmalloc, NULL); |
177 | unregister_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc); | 183 | unregister_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc, NULL); |
178 | unregister_trace_kmalloc_node(kmemtrace_kmalloc_node); | 184 | unregister_trace_kmalloc_node(kmemtrace_kmalloc_node, NULL); |
179 | unregister_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node); | 185 | unregister_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node, NULL); |
180 | unregister_trace_kfree(kmemtrace_kfree); | 186 | unregister_trace_kfree(kmemtrace_kfree, NULL); |
181 | unregister_trace_kmem_cache_free(kmemtrace_kmem_cache_free); | 187 | unregister_trace_kmem_cache_free(kmemtrace_kmem_cache_free, NULL); |
182 | } | 188 | } |
183 | 189 | ||
184 | static int kmem_trace_init(struct trace_array *tr) | 190 | static int kmem_trace_init(struct trace_array *tr) |
@@ -237,7 +243,8 @@ struct kmemtrace_user_event_alloc { | |||
237 | }; | 243 | }; |
238 | 244 | ||
239 | static enum print_line_t | 245 | static enum print_line_t |
240 | kmemtrace_print_alloc(struct trace_iterator *iter, int flags) | 246 | kmemtrace_print_alloc(struct trace_iterator *iter, int flags, |
247 | struct trace_event *event) | ||
241 | { | 248 | { |
242 | struct trace_seq *s = &iter->seq; | 249 | struct trace_seq *s = &iter->seq; |
243 | struct kmemtrace_alloc_entry *entry; | 250 | struct kmemtrace_alloc_entry *entry; |
@@ -257,7 +264,8 @@ kmemtrace_print_alloc(struct trace_iterator *iter, int flags) | |||
257 | } | 264 | } |
258 | 265 | ||
259 | static enum print_line_t | 266 | static enum print_line_t |
260 | kmemtrace_print_free(struct trace_iterator *iter, int flags) | 267 | kmemtrace_print_free(struct trace_iterator *iter, int flags, |
268 | struct trace_event *event) | ||
261 | { | 269 | { |
262 | struct trace_seq *s = &iter->seq; | 270 | struct trace_seq *s = &iter->seq; |
263 | struct kmemtrace_free_entry *entry; | 271 | struct kmemtrace_free_entry *entry; |
@@ -275,7 +283,8 @@ kmemtrace_print_free(struct trace_iterator *iter, int flags) | |||
275 | } | 283 | } |
276 | 284 | ||
277 | static enum print_line_t | 285 | static enum print_line_t |
278 | kmemtrace_print_alloc_user(struct trace_iterator *iter, int flags) | 286 | kmemtrace_print_alloc_user(struct trace_iterator *iter, int flags, |
287 | struct trace_event *event) | ||
279 | { | 288 | { |
280 | struct trace_seq *s = &iter->seq; | 289 | struct trace_seq *s = &iter->seq; |
281 | struct kmemtrace_alloc_entry *entry; | 290 | struct kmemtrace_alloc_entry *entry; |
@@ -309,7 +318,8 @@ kmemtrace_print_alloc_user(struct trace_iterator *iter, int flags) | |||
309 | } | 318 | } |
310 | 319 | ||
311 | static enum print_line_t | 320 | static enum print_line_t |
312 | kmemtrace_print_free_user(struct trace_iterator *iter, int flags) | 321 | kmemtrace_print_free_user(struct trace_iterator *iter, int flags, |
322 | struct trace_event *event) | ||
313 | { | 323 | { |
314 | struct trace_seq *s = &iter->seq; | 324 | struct trace_seq *s = &iter->seq; |
315 | struct kmemtrace_free_entry *entry; | 325 | struct kmemtrace_free_entry *entry; |
@@ -463,18 +473,26 @@ static enum print_line_t kmemtrace_print_line(struct trace_iterator *iter) | |||
463 | } | 473 | } |
464 | } | 474 | } |
465 | 475 | ||
466 | static struct trace_event kmem_trace_alloc = { | 476 | static struct trace_event_functions kmem_trace_alloc_funcs = { |
467 | .type = TRACE_KMEM_ALLOC, | ||
468 | .trace = kmemtrace_print_alloc, | 477 | .trace = kmemtrace_print_alloc, |
469 | .binary = kmemtrace_print_alloc_user, | 478 | .binary = kmemtrace_print_alloc_user, |
470 | }; | 479 | }; |
471 | 480 | ||
472 | static struct trace_event kmem_trace_free = { | 481 | static struct trace_event kmem_trace_alloc = { |
473 | .type = TRACE_KMEM_FREE, | 482 | .type = TRACE_KMEM_ALLOC, |
483 | .funcs = &kmem_trace_alloc_funcs, | ||
484 | }; | ||
485 | |||
486 | static struct trace_event_functions kmem_trace_free_funcs = { | ||
474 | .trace = kmemtrace_print_free, | 487 | .trace = kmemtrace_print_free, |
475 | .binary = kmemtrace_print_free_user, | 488 | .binary = kmemtrace_print_free_user, |
476 | }; | 489 | }; |
477 | 490 | ||
491 | static struct trace_event kmem_trace_free = { | ||
492 | .type = TRACE_KMEM_FREE, | ||
493 | .funcs = &kmem_trace_free_funcs, | ||
494 | }; | ||
495 | |||
478 | static struct tracer kmem_tracer __read_mostly = { | 496 | static struct tracer kmem_tracer __read_mostly = { |
479 | .name = "kmemtrace", | 497 | .name = "kmemtrace", |
480 | .init = kmem_trace_init, | 498 | .init = kmem_trace_init, |
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 8a76339a9e65..55e48511d7c8 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -1936,7 +1936,7 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter) | |||
1936 | } | 1936 | } |
1937 | 1937 | ||
1938 | if (event) | 1938 | if (event) |
1939 | return event->trace(iter, sym_flags); | 1939 | return event->funcs->trace(iter, sym_flags, event); |
1940 | 1940 | ||
1941 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) | 1941 | if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) |
1942 | goto partial; | 1942 | goto partial; |
@@ -1962,7 +1962,7 @@ static enum print_line_t print_raw_fmt(struct trace_iterator *iter) | |||
1962 | 1962 | ||
1963 | event = ftrace_find_event(entry->type); | 1963 | event = ftrace_find_event(entry->type); |
1964 | if (event) | 1964 | if (event) |
1965 | return event->raw(iter, 0); | 1965 | return event->funcs->raw(iter, 0, event); |
1966 | 1966 | ||
1967 | if (!trace_seq_printf(s, "%d ?\n", entry->type)) | 1967 | if (!trace_seq_printf(s, "%d ?\n", entry->type)) |
1968 | goto partial; | 1968 | goto partial; |
@@ -1989,7 +1989,7 @@ static enum print_line_t print_hex_fmt(struct trace_iterator *iter) | |||
1989 | 1989 | ||
1990 | event = ftrace_find_event(entry->type); | 1990 | event = ftrace_find_event(entry->type); |
1991 | if (event) { | 1991 | if (event) { |
1992 | enum print_line_t ret = event->hex(iter, 0); | 1992 | enum print_line_t ret = event->funcs->hex(iter, 0, event); |
1993 | if (ret != TRACE_TYPE_HANDLED) | 1993 | if (ret != TRACE_TYPE_HANDLED) |
1994 | return ret; | 1994 | return ret; |
1995 | } | 1995 | } |
@@ -2014,7 +2014,8 @@ static enum print_line_t print_bin_fmt(struct trace_iterator *iter) | |||
2014 | } | 2014 | } |
2015 | 2015 | ||
2016 | event = ftrace_find_event(entry->type); | 2016 | event = ftrace_find_event(entry->type); |
2017 | return event ? event->binary(iter, 0) : TRACE_TYPE_HANDLED; | 2017 | return event ? event->funcs->binary(iter, 0, event) : |
2018 | TRACE_TYPE_HANDLED; | ||
2018 | } | 2019 | } |
2019 | 2020 | ||
2020 | int trace_empty(struct trace_iterator *iter) | 2021 | int trace_empty(struct trace_iterator *iter) |
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index d1ce0bec1b3f..2cd96399463f 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h | |||
@@ -405,12 +405,12 @@ void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, | |||
405 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, | 405 | void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, |
406 | int pc); | 406 | int pc); |
407 | #else | 407 | #else |
408 | static inline void ftrace_trace_stack(struct trace_array *tr, | 408 | static inline void ftrace_trace_stack(struct ring_buffer *buffer, |
409 | unsigned long flags, int skip, int pc) | 409 | unsigned long flags, int skip, int pc) |
410 | { | 410 | { |
411 | } | 411 | } |
412 | 412 | ||
413 | static inline void ftrace_trace_userstack(struct trace_array *tr, | 413 | static inline void ftrace_trace_userstack(struct ring_buffer *buffer, |
414 | unsigned long flags, int pc) | 414 | unsigned long flags, int pc) |
415 | { | 415 | { |
416 | } | 416 | } |
@@ -778,12 +778,15 @@ extern void print_subsystem_event_filter(struct event_subsystem *system, | |||
778 | struct trace_seq *s); | 778 | struct trace_seq *s); |
779 | extern int filter_assign_type(const char *type); | 779 | extern int filter_assign_type(const char *type); |
780 | 780 | ||
781 | struct list_head * | ||
782 | trace_get_fields(struct ftrace_event_call *event_call); | ||
783 | |||
781 | static inline int | 784 | static inline int |
782 | filter_check_discard(struct ftrace_event_call *call, void *rec, | 785 | filter_check_discard(struct ftrace_event_call *call, void *rec, |
783 | struct ring_buffer *buffer, | 786 | struct ring_buffer *buffer, |
784 | struct ring_buffer_event *event) | 787 | struct ring_buffer_event *event) |
785 | { | 788 | { |
786 | if (unlikely(call->filter_active) && | 789 | if (unlikely(call->flags & TRACE_EVENT_FL_FILTERED) && |
787 | !filter_match_preds(call->filter, rec)) { | 790 | !filter_match_preds(call->filter, rec)) { |
788 | ring_buffer_discard_commit(buffer, event); | 791 | ring_buffer_discard_commit(buffer, event); |
789 | return 1; | 792 | return 1; |
diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c index b9bc4d470177..8d3538b4ea5f 100644 --- a/kernel/trace/trace_branch.c +++ b/kernel/trace/trace_branch.c | |||
@@ -143,7 +143,7 @@ static void branch_trace_reset(struct trace_array *tr) | |||
143 | } | 143 | } |
144 | 144 | ||
145 | static enum print_line_t trace_branch_print(struct trace_iterator *iter, | 145 | static enum print_line_t trace_branch_print(struct trace_iterator *iter, |
146 | int flags) | 146 | int flags, struct trace_event *event) |
147 | { | 147 | { |
148 | struct trace_branch *field; | 148 | struct trace_branch *field; |
149 | 149 | ||
@@ -167,9 +167,13 @@ static void branch_print_header(struct seq_file *s) | |||
167 | " |\n"); | 167 | " |\n"); |
168 | } | 168 | } |
169 | 169 | ||
170 | static struct trace_event_functions trace_branch_funcs = { | ||
171 | .trace = trace_branch_print, | ||
172 | }; | ||
173 | |||
170 | static struct trace_event trace_branch_event = { | 174 | static struct trace_event trace_branch_event = { |
171 | .type = TRACE_BRANCH, | 175 | .type = TRACE_BRANCH, |
172 | .trace = trace_branch_print, | 176 | .funcs = &trace_branch_funcs, |
173 | }; | 177 | }; |
174 | 178 | ||
175 | static struct tracer branch_trace __read_mostly = | 179 | static struct tracer branch_trace __read_mostly = |
diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c index 0565bb42566f..cb6f365016e4 100644 --- a/kernel/trace/trace_event_perf.c +++ b/kernel/trace/trace_event_perf.c | |||
@@ -9,13 +9,9 @@ | |||
9 | #include <linux/kprobes.h> | 9 | #include <linux/kprobes.h> |
10 | #include "trace.h" | 10 | #include "trace.h" |
11 | 11 | ||
12 | DEFINE_PER_CPU(struct pt_regs, perf_trace_regs); | ||
13 | EXPORT_PER_CPU_SYMBOL_GPL(perf_trace_regs); | ||
14 | |||
15 | EXPORT_SYMBOL_GPL(perf_arch_fetch_caller_regs); | 12 | EXPORT_SYMBOL_GPL(perf_arch_fetch_caller_regs); |
16 | 13 | ||
17 | static char *perf_trace_buf; | 14 | static char *perf_trace_buf[4]; |
18 | static char *perf_trace_buf_nmi; | ||
19 | 15 | ||
20 | /* | 16 | /* |
21 | * Force it to be aligned to unsigned long to avoid misaligned accesses | 17 | * Force it to be aligned to unsigned long to avoid misaligned accesses |
@@ -27,57 +23,82 @@ typedef typeof(unsigned long [PERF_MAX_TRACE_SIZE / sizeof(unsigned long)]) | |||
27 | /* Count the events in use (per event id, not per instance) */ | 23 | /* Count the events in use (per event id, not per instance) */ |
28 | static int total_ref_count; | 24 | static int total_ref_count; |
29 | 25 | ||
30 | static int perf_trace_event_enable(struct ftrace_event_call *event) | 26 | static int perf_trace_event_init(struct ftrace_event_call *tp_event, |
27 | struct perf_event *p_event) | ||
31 | { | 28 | { |
32 | char *buf; | 29 | struct hlist_head *list; |
33 | int ret = -ENOMEM; | 30 | int ret = -ENOMEM; |
31 | int cpu; | ||
34 | 32 | ||
35 | if (event->perf_refcount++ > 0) | 33 | p_event->tp_event = tp_event; |
34 | if (tp_event->perf_refcount++ > 0) | ||
36 | return 0; | 35 | return 0; |
37 | 36 | ||
38 | if (!total_ref_count) { | 37 | list = alloc_percpu(struct hlist_head); |
39 | buf = (char *)alloc_percpu(perf_trace_t); | 38 | if (!list) |
40 | if (!buf) | 39 | goto fail; |
41 | goto fail_buf; | ||
42 | 40 | ||
43 | rcu_assign_pointer(perf_trace_buf, buf); | 41 | for_each_possible_cpu(cpu) |
42 | INIT_HLIST_HEAD(per_cpu_ptr(list, cpu)); | ||
44 | 43 | ||
45 | buf = (char *)alloc_percpu(perf_trace_t); | 44 | tp_event->perf_events = list; |
46 | if (!buf) | ||
47 | goto fail_buf_nmi; | ||
48 | 45 | ||
49 | rcu_assign_pointer(perf_trace_buf_nmi, buf); | 46 | if (!total_ref_count) { |
50 | } | 47 | char *buf; |
48 | int i; | ||
51 | 49 | ||
52 | ret = event->perf_event_enable(event); | 50 | for (i = 0; i < 4; i++) { |
53 | if (!ret) { | 51 | buf = (char *)alloc_percpu(perf_trace_t); |
54 | total_ref_count++; | 52 | if (!buf) |
55 | return 0; | 53 | goto fail; |
54 | |||
55 | perf_trace_buf[i] = buf; | ||
56 | } | ||
56 | } | 57 | } |
57 | 58 | ||
58 | fail_buf_nmi: | 59 | if (tp_event->class->reg) |
60 | ret = tp_event->class->reg(tp_event, TRACE_REG_PERF_REGISTER); | ||
61 | else | ||
62 | ret = tracepoint_probe_register(tp_event->name, | ||
63 | tp_event->class->perf_probe, | ||
64 | tp_event); | ||
65 | |||
66 | if (ret) | ||
67 | goto fail; | ||
68 | |||
69 | total_ref_count++; | ||
70 | return 0; | ||
71 | |||
72 | fail: | ||
59 | if (!total_ref_count) { | 73 | if (!total_ref_count) { |
60 | free_percpu(perf_trace_buf_nmi); | 74 | int i; |
61 | free_percpu(perf_trace_buf); | 75 | |
62 | perf_trace_buf_nmi = NULL; | 76 | for (i = 0; i < 4; i++) { |
63 | perf_trace_buf = NULL; | 77 | free_percpu(perf_trace_buf[i]); |
78 | perf_trace_buf[i] = NULL; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | if (!--tp_event->perf_refcount) { | ||
83 | free_percpu(tp_event->perf_events); | ||
84 | tp_event->perf_events = NULL; | ||
64 | } | 85 | } |
65 | fail_buf: | ||
66 | event->perf_refcount--; | ||
67 | 86 | ||
68 | return ret; | 87 | return ret; |
69 | } | 88 | } |
70 | 89 | ||
71 | int perf_trace_enable(int event_id) | 90 | int perf_trace_init(struct perf_event *p_event) |
72 | { | 91 | { |
73 | struct ftrace_event_call *event; | 92 | struct ftrace_event_call *tp_event; |
93 | int event_id = p_event->attr.config; | ||
74 | int ret = -EINVAL; | 94 | int ret = -EINVAL; |
75 | 95 | ||
76 | mutex_lock(&event_mutex); | 96 | mutex_lock(&event_mutex); |
77 | list_for_each_entry(event, &ftrace_events, list) { | 97 | list_for_each_entry(tp_event, &ftrace_events, list) { |
78 | if (event->id == event_id && event->perf_event_enable && | 98 | if (tp_event->event.type == event_id && |
79 | try_module_get(event->mod)) { | 99 | tp_event->class && tp_event->class->perf_probe && |
80 | ret = perf_trace_event_enable(event); | 100 | try_module_get(tp_event->mod)) { |
101 | ret = perf_trace_event_init(tp_event, p_event); | ||
81 | break; | 102 | break; |
82 | } | 103 | } |
83 | } | 104 | } |
@@ -86,90 +107,78 @@ int perf_trace_enable(int event_id) | |||
86 | return ret; | 107 | return ret; |
87 | } | 108 | } |
88 | 109 | ||
89 | static void perf_trace_event_disable(struct ftrace_event_call *event) | 110 | int perf_trace_enable(struct perf_event *p_event) |
90 | { | 111 | { |
91 | char *buf, *nmi_buf; | 112 | struct ftrace_event_call *tp_event = p_event->tp_event; |
92 | 113 | struct hlist_head *list; | |
93 | if (--event->perf_refcount > 0) | ||
94 | return; | ||
95 | |||
96 | event->perf_event_disable(event); | ||
97 | 114 | ||
98 | if (!--total_ref_count) { | 115 | list = tp_event->perf_events; |
99 | buf = perf_trace_buf; | 116 | if (WARN_ON_ONCE(!list)) |
100 | rcu_assign_pointer(perf_trace_buf, NULL); | 117 | return -EINVAL; |
101 | 118 | ||
102 | nmi_buf = perf_trace_buf_nmi; | 119 | list = per_cpu_ptr(list, smp_processor_id()); |
103 | rcu_assign_pointer(perf_trace_buf_nmi, NULL); | 120 | hlist_add_head_rcu(&p_event->hlist_entry, list); |
104 | 121 | ||
105 | /* | 122 | return 0; |
106 | * Ensure every events in profiling have finished before | 123 | } |
107 | * releasing the buffers | ||
108 | */ | ||
109 | synchronize_sched(); | ||
110 | 124 | ||
111 | free_percpu(buf); | 125 | void perf_trace_disable(struct perf_event *p_event) |
112 | free_percpu(nmi_buf); | 126 | { |
113 | } | 127 | hlist_del_rcu(&p_event->hlist_entry); |
114 | } | 128 | } |
115 | 129 | ||
116 | void perf_trace_disable(int event_id) | 130 | void perf_trace_destroy(struct perf_event *p_event) |
117 | { | 131 | { |
118 | struct ftrace_event_call *event; | 132 | struct ftrace_event_call *tp_event = p_event->tp_event; |
133 | int i; | ||
119 | 134 | ||
120 | mutex_lock(&event_mutex); | 135 | if (--tp_event->perf_refcount > 0) |
121 | list_for_each_entry(event, &ftrace_events, list) { | 136 | return; |
122 | if (event->id == event_id) { | 137 | |
123 | perf_trace_event_disable(event); | 138 | if (tp_event->class->reg) |
124 | module_put(event->mod); | 139 | tp_event->class->reg(tp_event, TRACE_REG_PERF_UNREGISTER); |
125 | break; | 140 | else |
141 | tracepoint_probe_unregister(tp_event->name, | ||
142 | tp_event->class->perf_probe, | ||
143 | tp_event); | ||
144 | |||
145 | free_percpu(tp_event->perf_events); | ||
146 | tp_event->perf_events = NULL; | ||
147 | |||
148 | if (!--total_ref_count) { | ||
149 | for (i = 0; i < 4; i++) { | ||
150 | free_percpu(perf_trace_buf[i]); | ||
151 | perf_trace_buf[i] = NULL; | ||
126 | } | 152 | } |
127 | } | 153 | } |
128 | mutex_unlock(&event_mutex); | ||
129 | } | 154 | } |
130 | 155 | ||
131 | __kprobes void *perf_trace_buf_prepare(int size, unsigned short type, | 156 | __kprobes void *perf_trace_buf_prepare(int size, unsigned short type, |
132 | int *rctxp, unsigned long *irq_flags) | 157 | struct pt_regs *regs, int *rctxp) |
133 | { | 158 | { |
134 | struct trace_entry *entry; | 159 | struct trace_entry *entry; |
135 | char *trace_buf, *raw_data; | 160 | unsigned long flags; |
136 | int pc, cpu; | 161 | char *raw_data; |
162 | int pc; | ||
137 | 163 | ||
138 | BUILD_BUG_ON(PERF_MAX_TRACE_SIZE % sizeof(unsigned long)); | 164 | BUILD_BUG_ON(PERF_MAX_TRACE_SIZE % sizeof(unsigned long)); |
139 | 165 | ||
140 | pc = preempt_count(); | 166 | pc = preempt_count(); |
141 | 167 | ||
142 | /* Protect the per cpu buffer, begin the rcu read side */ | ||
143 | local_irq_save(*irq_flags); | ||
144 | |||
145 | *rctxp = perf_swevent_get_recursion_context(); | 168 | *rctxp = perf_swevent_get_recursion_context(); |
146 | if (*rctxp < 0) | 169 | if (*rctxp < 0) |
147 | goto err_recursion; | 170 | return NULL; |
148 | |||
149 | cpu = smp_processor_id(); | ||
150 | |||
151 | if (in_nmi()) | ||
152 | trace_buf = rcu_dereference_sched(perf_trace_buf_nmi); | ||
153 | else | ||
154 | trace_buf = rcu_dereference_sched(perf_trace_buf); | ||
155 | |||
156 | if (!trace_buf) | ||
157 | goto err; | ||
158 | 171 | ||
159 | raw_data = per_cpu_ptr(trace_buf, cpu); | 172 | raw_data = per_cpu_ptr(perf_trace_buf[*rctxp], smp_processor_id()); |
160 | 173 | ||
161 | /* zero the dead bytes from align to not leak stack to user */ | 174 | /* zero the dead bytes from align to not leak stack to user */ |
162 | memset(&raw_data[size - sizeof(u64)], 0, sizeof(u64)); | 175 | memset(&raw_data[size - sizeof(u64)], 0, sizeof(u64)); |
163 | 176 | ||
164 | entry = (struct trace_entry *)raw_data; | 177 | entry = (struct trace_entry *)raw_data; |
165 | tracing_generic_entry_update(entry, *irq_flags, pc); | 178 | local_save_flags(flags); |
179 | tracing_generic_entry_update(entry, flags, pc); | ||
166 | entry->type = type; | 180 | entry->type = type; |
167 | 181 | ||
168 | return raw_data; | 182 | return raw_data; |
169 | err: | ||
170 | perf_swevent_put_recursion_context(*rctxp); | ||
171 | err_recursion: | ||
172 | local_irq_restore(*irq_flags); | ||
173 | return NULL; | ||
174 | } | 183 | } |
175 | EXPORT_SYMBOL_GPL(perf_trace_buf_prepare); | 184 | EXPORT_SYMBOL_GPL(perf_trace_buf_prepare); |
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index c697c7043349..53cffc0b0801 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c | |||
@@ -29,11 +29,23 @@ DEFINE_MUTEX(event_mutex); | |||
29 | 29 | ||
30 | LIST_HEAD(ftrace_events); | 30 | LIST_HEAD(ftrace_events); |
31 | 31 | ||
32 | struct list_head * | ||
33 | trace_get_fields(struct ftrace_event_call *event_call) | ||
34 | { | ||
35 | if (!event_call->class->get_fields) | ||
36 | return &event_call->class->fields; | ||
37 | return event_call->class->get_fields(event_call); | ||
38 | } | ||
39 | |||
32 | int trace_define_field(struct ftrace_event_call *call, const char *type, | 40 | int trace_define_field(struct ftrace_event_call *call, const char *type, |
33 | const char *name, int offset, int size, int is_signed, | 41 | const char *name, int offset, int size, int is_signed, |
34 | int filter_type) | 42 | int filter_type) |
35 | { | 43 | { |
36 | struct ftrace_event_field *field; | 44 | struct ftrace_event_field *field; |
45 | struct list_head *head; | ||
46 | |||
47 | if (WARN_ON(!call->class)) | ||
48 | return 0; | ||
37 | 49 | ||
38 | field = kzalloc(sizeof(*field), GFP_KERNEL); | 50 | field = kzalloc(sizeof(*field), GFP_KERNEL); |
39 | if (!field) | 51 | if (!field) |
@@ -56,7 +68,8 @@ int trace_define_field(struct ftrace_event_call *call, const char *type, | |||
56 | field->size = size; | 68 | field->size = size; |
57 | field->is_signed = is_signed; | 69 | field->is_signed = is_signed; |
58 | 70 | ||
59 | list_add(&field->link, &call->fields); | 71 | head = trace_get_fields(call); |
72 | list_add(&field->link, head); | ||
60 | 73 | ||
61 | return 0; | 74 | return 0; |
62 | 75 | ||
@@ -94,8 +107,10 @@ static int trace_define_common_fields(struct ftrace_event_call *call) | |||
94 | void trace_destroy_fields(struct ftrace_event_call *call) | 107 | void trace_destroy_fields(struct ftrace_event_call *call) |
95 | { | 108 | { |
96 | struct ftrace_event_field *field, *next; | 109 | struct ftrace_event_field *field, *next; |
110 | struct list_head *head; | ||
97 | 111 | ||
98 | list_for_each_entry_safe(field, next, &call->fields, link) { | 112 | head = trace_get_fields(call); |
113 | list_for_each_entry_safe(field, next, head, link) { | ||
99 | list_del(&field->link); | 114 | list_del(&field->link); |
100 | kfree(field->type); | 115 | kfree(field->type); |
101 | kfree(field->name); | 116 | kfree(field->name); |
@@ -107,11 +122,9 @@ int trace_event_raw_init(struct ftrace_event_call *call) | |||
107 | { | 122 | { |
108 | int id; | 123 | int id; |
109 | 124 | ||
110 | id = register_ftrace_event(call->event); | 125 | id = register_ftrace_event(&call->event); |
111 | if (!id) | 126 | if (!id) |
112 | return -ENODEV; | 127 | return -ENODEV; |
113 | call->id = id; | ||
114 | INIT_LIST_HEAD(&call->fields); | ||
115 | 128 | ||
116 | return 0; | 129 | return 0; |
117 | } | 130 | } |
@@ -124,23 +137,33 @@ static int ftrace_event_enable_disable(struct ftrace_event_call *call, | |||
124 | 137 | ||
125 | switch (enable) { | 138 | switch (enable) { |
126 | case 0: | 139 | case 0: |
127 | if (call->enabled) { | 140 | if (call->flags & TRACE_EVENT_FL_ENABLED) { |
128 | call->enabled = 0; | 141 | call->flags &= ~TRACE_EVENT_FL_ENABLED; |
129 | tracing_stop_cmdline_record(); | 142 | tracing_stop_cmdline_record(); |
130 | call->unregfunc(call); | 143 | if (call->class->reg) |
144 | call->class->reg(call, TRACE_REG_UNREGISTER); | ||
145 | else | ||
146 | tracepoint_probe_unregister(call->name, | ||
147 | call->class->probe, | ||
148 | call); | ||
131 | } | 149 | } |
132 | break; | 150 | break; |
133 | case 1: | 151 | case 1: |
134 | if (!call->enabled) { | 152 | if (!(call->flags & TRACE_EVENT_FL_ENABLED)) { |
135 | tracing_start_cmdline_record(); | 153 | tracing_start_cmdline_record(); |
136 | ret = call->regfunc(call); | 154 | if (call->class->reg) |
155 | ret = call->class->reg(call, TRACE_REG_REGISTER); | ||
156 | else | ||
157 | ret = tracepoint_probe_register(call->name, | ||
158 | call->class->probe, | ||
159 | call); | ||
137 | if (ret) { | 160 | if (ret) { |
138 | tracing_stop_cmdline_record(); | 161 | tracing_stop_cmdline_record(); |
139 | pr_info("event trace: Could not enable event " | 162 | pr_info("event trace: Could not enable event " |
140 | "%s\n", call->name); | 163 | "%s\n", call->name); |
141 | break; | 164 | break; |
142 | } | 165 | } |
143 | call->enabled = 1; | 166 | call->flags |= TRACE_EVENT_FL_ENABLED; |
144 | } | 167 | } |
145 | break; | 168 | break; |
146 | } | 169 | } |
@@ -171,15 +194,16 @@ static int __ftrace_set_clr_event(const char *match, const char *sub, | |||
171 | mutex_lock(&event_mutex); | 194 | mutex_lock(&event_mutex); |
172 | list_for_each_entry(call, &ftrace_events, list) { | 195 | list_for_each_entry(call, &ftrace_events, list) { |
173 | 196 | ||
174 | if (!call->name || !call->regfunc) | 197 | if (!call->name || !call->class || |
198 | (!call->class->probe && !call->class->reg)) | ||
175 | continue; | 199 | continue; |
176 | 200 | ||
177 | if (match && | 201 | if (match && |
178 | strcmp(match, call->name) != 0 && | 202 | strcmp(match, call->name) != 0 && |
179 | strcmp(match, call->system) != 0) | 203 | strcmp(match, call->class->system) != 0) |
180 | continue; | 204 | continue; |
181 | 205 | ||
182 | if (sub && strcmp(sub, call->system) != 0) | 206 | if (sub && strcmp(sub, call->class->system) != 0) |
183 | continue; | 207 | continue; |
184 | 208 | ||
185 | if (event && strcmp(event, call->name) != 0) | 209 | if (event && strcmp(event, call->name) != 0) |
@@ -297,7 +321,7 @@ t_next(struct seq_file *m, void *v, loff_t *pos) | |||
297 | * The ftrace subsystem is for showing formats only. | 321 | * The ftrace subsystem is for showing formats only. |
298 | * They can not be enabled or disabled via the event files. | 322 | * They can not be enabled or disabled via the event files. |
299 | */ | 323 | */ |
300 | if (call->regfunc) | 324 | if (call->class && (call->class->probe || call->class->reg)) |
301 | return call; | 325 | return call; |
302 | } | 326 | } |
303 | 327 | ||
@@ -328,7 +352,7 @@ s_next(struct seq_file *m, void *v, loff_t *pos) | |||
328 | (*pos)++; | 352 | (*pos)++; |
329 | 353 | ||
330 | list_for_each_entry_continue(call, &ftrace_events, list) { | 354 | list_for_each_entry_continue(call, &ftrace_events, list) { |
331 | if (call->enabled) | 355 | if (call->flags & TRACE_EVENT_FL_ENABLED) |
332 | return call; | 356 | return call; |
333 | } | 357 | } |
334 | 358 | ||
@@ -355,8 +379,8 @@ static int t_show(struct seq_file *m, void *v) | |||
355 | { | 379 | { |
356 | struct ftrace_event_call *call = v; | 380 | struct ftrace_event_call *call = v; |
357 | 381 | ||
358 | if (strcmp(call->system, TRACE_SYSTEM) != 0) | 382 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) |
359 | seq_printf(m, "%s:", call->system); | 383 | seq_printf(m, "%s:", call->class->system); |
360 | seq_printf(m, "%s\n", call->name); | 384 | seq_printf(m, "%s\n", call->name); |
361 | 385 | ||
362 | return 0; | 386 | return 0; |
@@ -387,7 +411,7 @@ event_enable_read(struct file *filp, char __user *ubuf, size_t cnt, | |||
387 | struct ftrace_event_call *call = filp->private_data; | 411 | struct ftrace_event_call *call = filp->private_data; |
388 | char *buf; | 412 | char *buf; |
389 | 413 | ||
390 | if (call->enabled) | 414 | if (call->flags & TRACE_EVENT_FL_ENABLED) |
391 | buf = "1\n"; | 415 | buf = "1\n"; |
392 | else | 416 | else |
393 | buf = "0\n"; | 417 | buf = "0\n"; |
@@ -450,10 +474,11 @@ system_enable_read(struct file *filp, char __user *ubuf, size_t cnt, | |||
450 | 474 | ||
451 | mutex_lock(&event_mutex); | 475 | mutex_lock(&event_mutex); |
452 | list_for_each_entry(call, &ftrace_events, list) { | 476 | list_for_each_entry(call, &ftrace_events, list) { |
453 | if (!call->name || !call->regfunc) | 477 | if (!call->name || !call->class || |
478 | (!call->class->probe && !call->class->reg)) | ||
454 | continue; | 479 | continue; |
455 | 480 | ||
456 | if (system && strcmp(call->system, system) != 0) | 481 | if (system && strcmp(call->class->system, system) != 0) |
457 | continue; | 482 | continue; |
458 | 483 | ||
459 | /* | 484 | /* |
@@ -461,7 +486,7 @@ system_enable_read(struct file *filp, char __user *ubuf, size_t cnt, | |||
461 | * or if all events or cleared, or if we have | 486 | * or if all events or cleared, or if we have |
462 | * a mixture. | 487 | * a mixture. |
463 | */ | 488 | */ |
464 | set |= (1 << !!call->enabled); | 489 | set |= (1 << !!(call->flags & TRACE_EVENT_FL_ENABLED)); |
465 | 490 | ||
466 | /* | 491 | /* |
467 | * If we have a mixture, no need to look further. | 492 | * If we have a mixture, no need to look further. |
@@ -525,6 +550,7 @@ event_format_read(struct file *filp, char __user *ubuf, size_t cnt, | |||
525 | { | 550 | { |
526 | struct ftrace_event_call *call = filp->private_data; | 551 | struct ftrace_event_call *call = filp->private_data; |
527 | struct ftrace_event_field *field; | 552 | struct ftrace_event_field *field; |
553 | struct list_head *head; | ||
528 | struct trace_seq *s; | 554 | struct trace_seq *s; |
529 | int common_field_count = 5; | 555 | int common_field_count = 5; |
530 | char *buf; | 556 | char *buf; |
@@ -540,10 +566,11 @@ event_format_read(struct file *filp, char __user *ubuf, size_t cnt, | |||
540 | trace_seq_init(s); | 566 | trace_seq_init(s); |
541 | 567 | ||
542 | trace_seq_printf(s, "name: %s\n", call->name); | 568 | trace_seq_printf(s, "name: %s\n", call->name); |
543 | trace_seq_printf(s, "ID: %d\n", call->id); | 569 | trace_seq_printf(s, "ID: %d\n", call->event.type); |
544 | trace_seq_printf(s, "format:\n"); | 570 | trace_seq_printf(s, "format:\n"); |
545 | 571 | ||
546 | list_for_each_entry_reverse(field, &call->fields, link) { | 572 | head = trace_get_fields(call); |
573 | list_for_each_entry_reverse(field, head, link) { | ||
547 | /* | 574 | /* |
548 | * Smartly shows the array type(except dynamic array). | 575 | * Smartly shows the array type(except dynamic array). |
549 | * Normal: | 576 | * Normal: |
@@ -613,7 +640,7 @@ event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) | |||
613 | return -ENOMEM; | 640 | return -ENOMEM; |
614 | 641 | ||
615 | trace_seq_init(s); | 642 | trace_seq_init(s); |
616 | trace_seq_printf(s, "%d\n", call->id); | 643 | trace_seq_printf(s, "%d\n", call->event.type); |
617 | 644 | ||
618 | r = simple_read_from_buffer(ubuf, cnt, ppos, | 645 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
619 | s->buffer, s->len); | 646 | s->buffer, s->len); |
@@ -919,14 +946,15 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events, | |||
919 | const struct file_operations *filter, | 946 | const struct file_operations *filter, |
920 | const struct file_operations *format) | 947 | const struct file_operations *format) |
921 | { | 948 | { |
949 | struct list_head *head; | ||
922 | int ret; | 950 | int ret; |
923 | 951 | ||
924 | /* | 952 | /* |
925 | * If the trace point header did not define TRACE_SYSTEM | 953 | * If the trace point header did not define TRACE_SYSTEM |
926 | * then the system would be called "TRACE_SYSTEM". | 954 | * then the system would be called "TRACE_SYSTEM". |
927 | */ | 955 | */ |
928 | if (strcmp(call->system, TRACE_SYSTEM) != 0) | 956 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) |
929 | d_events = event_subsystem_dir(call->system, d_events); | 957 | d_events = event_subsystem_dir(call->class->system, d_events); |
930 | 958 | ||
931 | call->dir = debugfs_create_dir(call->name, d_events); | 959 | call->dir = debugfs_create_dir(call->name, d_events); |
932 | if (!call->dir) { | 960 | if (!call->dir) { |
@@ -935,22 +963,31 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events, | |||
935 | return -1; | 963 | return -1; |
936 | } | 964 | } |
937 | 965 | ||
938 | if (call->regfunc) | 966 | if (call->class->probe || call->class->reg) |
939 | trace_create_file("enable", 0644, call->dir, call, | 967 | trace_create_file("enable", 0644, call->dir, call, |
940 | enable); | 968 | enable); |
941 | 969 | ||
942 | if (call->id && call->perf_event_enable) | 970 | #ifdef CONFIG_PERF_EVENTS |
971 | if (call->event.type && (call->class->perf_probe || call->class->reg)) | ||
943 | trace_create_file("id", 0444, call->dir, call, | 972 | trace_create_file("id", 0444, call->dir, call, |
944 | id); | 973 | id); |
974 | #endif | ||
945 | 975 | ||
946 | if (call->define_fields) { | 976 | if (call->class->define_fields) { |
947 | ret = trace_define_common_fields(call); | 977 | /* |
948 | if (!ret) | 978 | * Other events may have the same class. Only update |
949 | ret = call->define_fields(call); | 979 | * the fields if they are not already defined. |
950 | if (ret < 0) { | 980 | */ |
951 | pr_warning("Could not initialize trace point" | 981 | head = trace_get_fields(call); |
952 | " events/%s\n", call->name); | 982 | if (list_empty(head)) { |
953 | return ret; | 983 | ret = trace_define_common_fields(call); |
984 | if (!ret) | ||
985 | ret = call->class->define_fields(call); | ||
986 | if (ret < 0) { | ||
987 | pr_warning("Could not initialize trace point" | ||
988 | " events/%s\n", call->name); | ||
989 | return ret; | ||
990 | } | ||
954 | } | 991 | } |
955 | trace_create_file("filter", 0644, call->dir, call, | 992 | trace_create_file("filter", 0644, call->dir, call, |
956 | filter); | 993 | filter); |
@@ -970,8 +1007,8 @@ static int __trace_add_event_call(struct ftrace_event_call *call) | |||
970 | if (!call->name) | 1007 | if (!call->name) |
971 | return -EINVAL; | 1008 | return -EINVAL; |
972 | 1009 | ||
973 | if (call->raw_init) { | 1010 | if (call->class->raw_init) { |
974 | ret = call->raw_init(call); | 1011 | ret = call->class->raw_init(call); |
975 | if (ret < 0) { | 1012 | if (ret < 0) { |
976 | if (ret != -ENOSYS) | 1013 | if (ret != -ENOSYS) |
977 | pr_warning("Could not initialize trace " | 1014 | pr_warning("Could not initialize trace " |
@@ -1035,13 +1072,13 @@ static void remove_subsystem_dir(const char *name) | |||
1035 | static void __trace_remove_event_call(struct ftrace_event_call *call) | 1072 | static void __trace_remove_event_call(struct ftrace_event_call *call) |
1036 | { | 1073 | { |
1037 | ftrace_event_enable_disable(call, 0); | 1074 | ftrace_event_enable_disable(call, 0); |
1038 | if (call->event) | 1075 | if (call->event.funcs) |
1039 | __unregister_ftrace_event(call->event); | 1076 | __unregister_ftrace_event(&call->event); |
1040 | debugfs_remove_recursive(call->dir); | 1077 | debugfs_remove_recursive(call->dir); |
1041 | list_del(&call->list); | 1078 | list_del(&call->list); |
1042 | trace_destroy_fields(call); | 1079 | trace_destroy_fields(call); |
1043 | destroy_preds(call); | 1080 | destroy_preds(call); |
1044 | remove_subsystem_dir(call->system); | 1081 | remove_subsystem_dir(call->class->system); |
1045 | } | 1082 | } |
1046 | 1083 | ||
1047 | /* Remove an event_call */ | 1084 | /* Remove an event_call */ |
@@ -1132,8 +1169,8 @@ static void trace_module_add_events(struct module *mod) | |||
1132 | /* The linker may leave blanks */ | 1169 | /* The linker may leave blanks */ |
1133 | if (!call->name) | 1170 | if (!call->name) |
1134 | continue; | 1171 | continue; |
1135 | if (call->raw_init) { | 1172 | if (call->class->raw_init) { |
1136 | ret = call->raw_init(call); | 1173 | ret = call->class->raw_init(call); |
1137 | if (ret < 0) { | 1174 | if (ret < 0) { |
1138 | if (ret != -ENOSYS) | 1175 | if (ret != -ENOSYS) |
1139 | pr_warning("Could not initialize trace " | 1176 | pr_warning("Could not initialize trace " |
@@ -1286,8 +1323,8 @@ static __init int event_trace_init(void) | |||
1286 | /* The linker may leave blanks */ | 1323 | /* The linker may leave blanks */ |
1287 | if (!call->name) | 1324 | if (!call->name) |
1288 | continue; | 1325 | continue; |
1289 | if (call->raw_init) { | 1326 | if (call->class->raw_init) { |
1290 | ret = call->raw_init(call); | 1327 | ret = call->class->raw_init(call); |
1291 | if (ret < 0) { | 1328 | if (ret < 0) { |
1292 | if (ret != -ENOSYS) | 1329 | if (ret != -ENOSYS) |
1293 | pr_warning("Could not initialize trace " | 1330 | pr_warning("Could not initialize trace " |
@@ -1388,8 +1425,8 @@ static __init void event_trace_self_tests(void) | |||
1388 | 1425 | ||
1389 | list_for_each_entry(call, &ftrace_events, list) { | 1426 | list_for_each_entry(call, &ftrace_events, list) { |
1390 | 1427 | ||
1391 | /* Only test those that have a regfunc */ | 1428 | /* Only test those that have a probe */ |
1392 | if (!call->regfunc) | 1429 | if (!call->class || !call->class->probe) |
1393 | continue; | 1430 | continue; |
1394 | 1431 | ||
1395 | /* | 1432 | /* |
@@ -1399,8 +1436,8 @@ static __init void event_trace_self_tests(void) | |||
1399 | * syscalls as we test. | 1436 | * syscalls as we test. |
1400 | */ | 1437 | */ |
1401 | #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS | 1438 | #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS |
1402 | if (call->system && | 1439 | if (call->class->system && |
1403 | strcmp(call->system, "syscalls") == 0) | 1440 | strcmp(call->class->system, "syscalls") == 0) |
1404 | continue; | 1441 | continue; |
1405 | #endif | 1442 | #endif |
1406 | 1443 | ||
@@ -1410,7 +1447,7 @@ static __init void event_trace_self_tests(void) | |||
1410 | * If an event is already enabled, someone is using | 1447 | * If an event is already enabled, someone is using |
1411 | * it and the self test should not be on. | 1448 | * it and the self test should not be on. |
1412 | */ | 1449 | */ |
1413 | if (call->enabled) { | 1450 | if (call->flags & TRACE_EVENT_FL_ENABLED) { |
1414 | pr_warning("Enabled event during self test!\n"); | 1451 | pr_warning("Enabled event during self test!\n"); |
1415 | WARN_ON_ONCE(1); | 1452 | WARN_ON_ONCE(1); |
1416 | continue; | 1453 | continue; |
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index 58092d844a1f..57bb1bb32999 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c | |||
@@ -500,8 +500,10 @@ static struct ftrace_event_field * | |||
500 | find_event_field(struct ftrace_event_call *call, char *name) | 500 | find_event_field(struct ftrace_event_call *call, char *name) |
501 | { | 501 | { |
502 | struct ftrace_event_field *field; | 502 | struct ftrace_event_field *field; |
503 | struct list_head *head; | ||
503 | 504 | ||
504 | list_for_each_entry(field, &call->fields, link) { | 505 | head = trace_get_fields(call); |
506 | list_for_each_entry(field, head, link) { | ||
505 | if (!strcmp(field->name, name)) | 507 | if (!strcmp(field->name, name)) |
506 | return field; | 508 | return field; |
507 | } | 509 | } |
@@ -545,7 +547,7 @@ static void filter_disable_preds(struct ftrace_event_call *call) | |||
545 | struct event_filter *filter = call->filter; | 547 | struct event_filter *filter = call->filter; |
546 | int i; | 548 | int i; |
547 | 549 | ||
548 | call->filter_active = 0; | 550 | call->flags &= ~TRACE_EVENT_FL_FILTERED; |
549 | filter->n_preds = 0; | 551 | filter->n_preds = 0; |
550 | 552 | ||
551 | for (i = 0; i < MAX_FILTER_PRED; i++) | 553 | for (i = 0; i < MAX_FILTER_PRED; i++) |
@@ -572,7 +574,7 @@ void destroy_preds(struct ftrace_event_call *call) | |||
572 | { | 574 | { |
573 | __free_preds(call->filter); | 575 | __free_preds(call->filter); |
574 | call->filter = NULL; | 576 | call->filter = NULL; |
575 | call->filter_active = 0; | 577 | call->flags &= ~TRACE_EVENT_FL_FILTERED; |
576 | } | 578 | } |
577 | 579 | ||
578 | static struct event_filter *__alloc_preds(void) | 580 | static struct event_filter *__alloc_preds(void) |
@@ -611,7 +613,7 @@ static int init_preds(struct ftrace_event_call *call) | |||
611 | if (call->filter) | 613 | if (call->filter) |
612 | return 0; | 614 | return 0; |
613 | 615 | ||
614 | call->filter_active = 0; | 616 | call->flags &= ~TRACE_EVENT_FL_FILTERED; |
615 | call->filter = __alloc_preds(); | 617 | call->filter = __alloc_preds(); |
616 | if (IS_ERR(call->filter)) | 618 | if (IS_ERR(call->filter)) |
617 | return PTR_ERR(call->filter); | 619 | return PTR_ERR(call->filter); |
@@ -625,10 +627,10 @@ static int init_subsystem_preds(struct event_subsystem *system) | |||
625 | int err; | 627 | int err; |
626 | 628 | ||
627 | list_for_each_entry(call, &ftrace_events, list) { | 629 | list_for_each_entry(call, &ftrace_events, list) { |
628 | if (!call->define_fields) | 630 | if (!call->class || !call->class->define_fields) |
629 | continue; | 631 | continue; |
630 | 632 | ||
631 | if (strcmp(call->system, system->name) != 0) | 633 | if (strcmp(call->class->system, system->name) != 0) |
632 | continue; | 634 | continue; |
633 | 635 | ||
634 | err = init_preds(call); | 636 | err = init_preds(call); |
@@ -644,10 +646,10 @@ static void filter_free_subsystem_preds(struct event_subsystem *system) | |||
644 | struct ftrace_event_call *call; | 646 | struct ftrace_event_call *call; |
645 | 647 | ||
646 | list_for_each_entry(call, &ftrace_events, list) { | 648 | list_for_each_entry(call, &ftrace_events, list) { |
647 | if (!call->define_fields) | 649 | if (!call->class || !call->class->define_fields) |
648 | continue; | 650 | continue; |
649 | 651 | ||
650 | if (strcmp(call->system, system->name) != 0) | 652 | if (strcmp(call->class->system, system->name) != 0) |
651 | continue; | 653 | continue; |
652 | 654 | ||
653 | filter_disable_preds(call); | 655 | filter_disable_preds(call); |
@@ -1249,10 +1251,10 @@ static int replace_system_preds(struct event_subsystem *system, | |||
1249 | list_for_each_entry(call, &ftrace_events, list) { | 1251 | list_for_each_entry(call, &ftrace_events, list) { |
1250 | struct event_filter *filter = call->filter; | 1252 | struct event_filter *filter = call->filter; |
1251 | 1253 | ||
1252 | if (!call->define_fields) | 1254 | if (!call->class || !call->class->define_fields) |
1253 | continue; | 1255 | continue; |
1254 | 1256 | ||
1255 | if (strcmp(call->system, system->name) != 0) | 1257 | if (strcmp(call->class->system, system->name) != 0) |
1256 | continue; | 1258 | continue; |
1257 | 1259 | ||
1258 | /* try to see if the filter can be applied */ | 1260 | /* try to see if the filter can be applied */ |
@@ -1266,7 +1268,7 @@ static int replace_system_preds(struct event_subsystem *system, | |||
1266 | if (err) | 1268 | if (err) |
1267 | filter_disable_preds(call); | 1269 | filter_disable_preds(call); |
1268 | else { | 1270 | else { |
1269 | call->filter_active = 1; | 1271 | call->flags |= TRACE_EVENT_FL_FILTERED; |
1270 | replace_filter_string(filter, filter_string); | 1272 | replace_filter_string(filter, filter_string); |
1271 | } | 1273 | } |
1272 | fail = false; | 1274 | fail = false; |
@@ -1315,7 +1317,7 @@ int apply_event_filter(struct ftrace_event_call *call, char *filter_string) | |||
1315 | if (err) | 1317 | if (err) |
1316 | append_filter_err(ps, call->filter); | 1318 | append_filter_err(ps, call->filter); |
1317 | else | 1319 | else |
1318 | call->filter_active = 1; | 1320 | call->flags |= TRACE_EVENT_FL_FILTERED; |
1319 | out: | 1321 | out: |
1320 | filter_opstack_clear(ps); | 1322 | filter_opstack_clear(ps); |
1321 | postfix_clear(ps); | 1323 | postfix_clear(ps); |
@@ -1393,7 +1395,7 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id, | |||
1393 | mutex_lock(&event_mutex); | 1395 | mutex_lock(&event_mutex); |
1394 | 1396 | ||
1395 | list_for_each_entry(call, &ftrace_events, list) { | 1397 | list_for_each_entry(call, &ftrace_events, list) { |
1396 | if (call->id == event_id) | 1398 | if (call->event.type == event_id) |
1397 | break; | 1399 | break; |
1398 | } | 1400 | } |
1399 | 1401 | ||
diff --git a/kernel/trace/trace_export.c b/kernel/trace/trace_export.c index e091f64ba6ce..8536e2a65969 100644 --- a/kernel/trace/trace_export.c +++ b/kernel/trace/trace_export.c | |||
@@ -127,7 +127,7 @@ ftrace_define_fields_##name(struct ftrace_event_call *event_call) \ | |||
127 | 127 | ||
128 | static int ftrace_raw_init_event(struct ftrace_event_call *call) | 128 | static int ftrace_raw_init_event(struct ftrace_event_call *call) |
129 | { | 129 | { |
130 | INIT_LIST_HEAD(&call->fields); | 130 | INIT_LIST_HEAD(&call->class->fields); |
131 | return 0; | 131 | return 0; |
132 | } | 132 | } |
133 | 133 | ||
@@ -153,17 +153,21 @@ static int ftrace_raw_init_event(struct ftrace_event_call *call) | |||
153 | #define F_printk(fmt, args...) #fmt ", " __stringify(args) | 153 | #define F_printk(fmt, args...) #fmt ", " __stringify(args) |
154 | 154 | ||
155 | #undef FTRACE_ENTRY | 155 | #undef FTRACE_ENTRY |
156 | #define FTRACE_ENTRY(call, struct_name, type, tstruct, print) \ | 156 | #define FTRACE_ENTRY(call, struct_name, etype, tstruct, print) \ |
157 | \ | ||
158 | struct ftrace_event_class event_class_ftrace_##call = { \ | ||
159 | .system = __stringify(TRACE_SYSTEM), \ | ||
160 | .define_fields = ftrace_define_fields_##call, \ | ||
161 | .raw_init = ftrace_raw_init_event, \ | ||
162 | }; \ | ||
157 | \ | 163 | \ |
158 | struct ftrace_event_call __used \ | 164 | struct ftrace_event_call __used \ |
159 | __attribute__((__aligned__(4))) \ | 165 | __attribute__((__aligned__(4))) \ |
160 | __attribute__((section("_ftrace_events"))) event_##call = { \ | 166 | __attribute__((section("_ftrace_events"))) event_##call = { \ |
161 | .name = #call, \ | 167 | .name = #call, \ |
162 | .id = type, \ | 168 | .event.type = etype, \ |
163 | .system = __stringify(TRACE_SYSTEM), \ | 169 | .class = &event_class_ftrace_##call, \ |
164 | .raw_init = ftrace_raw_init_event, \ | ||
165 | .print_fmt = print, \ | 170 | .print_fmt = print, \ |
166 | .define_fields = ftrace_define_fields_##call, \ | ||
167 | }; \ | 171 | }; \ |
168 | 172 | ||
169 | #include "trace_entries.h" | 173 | #include "trace_entries.h" |
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c index dd11c830eb84..79f4bac99a94 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c | |||
@@ -1025,7 +1025,7 @@ print_graph_comment(struct trace_seq *s, struct trace_entry *ent, | |||
1025 | if (!event) | 1025 | if (!event) |
1026 | return TRACE_TYPE_UNHANDLED; | 1026 | return TRACE_TYPE_UNHANDLED; |
1027 | 1027 | ||
1028 | ret = event->trace(iter, sym_flags); | 1028 | ret = event->funcs->trace(iter, sym_flags, event); |
1029 | if (ret != TRACE_TYPE_HANDLED) | 1029 | if (ret != TRACE_TYPE_HANDLED) |
1030 | return ret; | 1030 | return ret; |
1031 | } | 1031 | } |
@@ -1112,7 +1112,8 @@ print_graph_function(struct trace_iterator *iter) | |||
1112 | } | 1112 | } |
1113 | 1113 | ||
1114 | static enum print_line_t | 1114 | static enum print_line_t |
1115 | print_graph_function_event(struct trace_iterator *iter, int flags) | 1115 | print_graph_function_event(struct trace_iterator *iter, int flags, |
1116 | struct trace_event *event) | ||
1116 | { | 1117 | { |
1117 | return print_graph_function(iter); | 1118 | return print_graph_function(iter); |
1118 | } | 1119 | } |
@@ -1225,14 +1226,18 @@ void graph_trace_close(struct trace_iterator *iter) | |||
1225 | } | 1226 | } |
1226 | } | 1227 | } |
1227 | 1228 | ||
1229 | static struct trace_event_functions graph_functions = { | ||
1230 | .trace = print_graph_function_event, | ||
1231 | }; | ||
1232 | |||
1228 | static struct trace_event graph_trace_entry_event = { | 1233 | static struct trace_event graph_trace_entry_event = { |
1229 | .type = TRACE_GRAPH_ENT, | 1234 | .type = TRACE_GRAPH_ENT, |
1230 | .trace = print_graph_function_event, | 1235 | .funcs = &graph_functions, |
1231 | }; | 1236 | }; |
1232 | 1237 | ||
1233 | static struct trace_event graph_trace_ret_event = { | 1238 | static struct trace_event graph_trace_ret_event = { |
1234 | .type = TRACE_GRAPH_RET, | 1239 | .type = TRACE_GRAPH_RET, |
1235 | .trace = print_graph_function_event, | 1240 | .funcs = &graph_functions |
1236 | }; | 1241 | }; |
1237 | 1242 | ||
1238 | static struct tracer graph_trace __read_mostly = { | 1243 | static struct tracer graph_trace __read_mostly = { |
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index a7514326052b..faf7cefd15da 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c | |||
@@ -324,8 +324,8 @@ struct trace_probe { | |||
324 | unsigned long nhit; | 324 | unsigned long nhit; |
325 | unsigned int flags; /* For TP_FLAG_* */ | 325 | unsigned int flags; /* For TP_FLAG_* */ |
326 | const char *symbol; /* symbol name */ | 326 | const char *symbol; /* symbol name */ |
327 | struct ftrace_event_class class; | ||
327 | struct ftrace_event_call call; | 328 | struct ftrace_event_call call; |
328 | struct trace_event event; | ||
329 | ssize_t size; /* trace entry size */ | 329 | ssize_t size; /* trace entry size */ |
330 | unsigned int nr_args; | 330 | unsigned int nr_args; |
331 | struct probe_arg args[]; | 331 | struct probe_arg args[]; |
@@ -404,6 +404,7 @@ static struct trace_probe *alloc_trace_probe(const char *group, | |||
404 | goto error; | 404 | goto error; |
405 | } | 405 | } |
406 | 406 | ||
407 | tp->call.class = &tp->class; | ||
407 | tp->call.name = kstrdup(event, GFP_KERNEL); | 408 | tp->call.name = kstrdup(event, GFP_KERNEL); |
408 | if (!tp->call.name) | 409 | if (!tp->call.name) |
409 | goto error; | 410 | goto error; |
@@ -413,8 +414,8 @@ static struct trace_probe *alloc_trace_probe(const char *group, | |||
413 | goto error; | 414 | goto error; |
414 | } | 415 | } |
415 | 416 | ||
416 | tp->call.system = kstrdup(group, GFP_KERNEL); | 417 | tp->class.system = kstrdup(group, GFP_KERNEL); |
417 | if (!tp->call.system) | 418 | if (!tp->class.system) |
418 | goto error; | 419 | goto error; |
419 | 420 | ||
420 | INIT_LIST_HEAD(&tp->list); | 421 | INIT_LIST_HEAD(&tp->list); |
@@ -443,7 +444,7 @@ static void free_trace_probe(struct trace_probe *tp) | |||
443 | for (i = 0; i < tp->nr_args; i++) | 444 | for (i = 0; i < tp->nr_args; i++) |
444 | free_probe_arg(&tp->args[i]); | 445 | free_probe_arg(&tp->args[i]); |
445 | 446 | ||
446 | kfree(tp->call.system); | 447 | kfree(tp->call.class->system); |
447 | kfree(tp->call.name); | 448 | kfree(tp->call.name); |
448 | kfree(tp->symbol); | 449 | kfree(tp->symbol); |
449 | kfree(tp); | 450 | kfree(tp); |
@@ -456,7 +457,7 @@ static struct trace_probe *find_probe_event(const char *event, | |||
456 | 457 | ||
457 | list_for_each_entry(tp, &probe_list, list) | 458 | list_for_each_entry(tp, &probe_list, list) |
458 | if (strcmp(tp->call.name, event) == 0 && | 459 | if (strcmp(tp->call.name, event) == 0 && |
459 | strcmp(tp->call.system, group) == 0) | 460 | strcmp(tp->call.class->system, group) == 0) |
460 | return tp; | 461 | return tp; |
461 | return NULL; | 462 | return NULL; |
462 | } | 463 | } |
@@ -481,7 +482,7 @@ static int register_trace_probe(struct trace_probe *tp) | |||
481 | mutex_lock(&probe_lock); | 482 | mutex_lock(&probe_lock); |
482 | 483 | ||
483 | /* register as an event */ | 484 | /* register as an event */ |
484 | old_tp = find_probe_event(tp->call.name, tp->call.system); | 485 | old_tp = find_probe_event(tp->call.name, tp->call.class->system); |
485 | if (old_tp) { | 486 | if (old_tp) { |
486 | /* delete old event */ | 487 | /* delete old event */ |
487 | unregister_trace_probe(old_tp); | 488 | unregister_trace_probe(old_tp); |
@@ -904,7 +905,7 @@ static int probes_seq_show(struct seq_file *m, void *v) | |||
904 | int i; | 905 | int i; |
905 | 906 | ||
906 | seq_printf(m, "%c", probe_is_return(tp) ? 'r' : 'p'); | 907 | seq_printf(m, "%c", probe_is_return(tp) ? 'r' : 'p'); |
907 | seq_printf(m, ":%s/%s", tp->call.system, tp->call.name); | 908 | seq_printf(m, ":%s/%s", tp->call.class->system, tp->call.name); |
908 | 909 | ||
909 | if (!tp->symbol) | 910 | if (!tp->symbol) |
910 | seq_printf(m, " 0x%p", tp->rp.kp.addr); | 911 | seq_printf(m, " 0x%p", tp->rp.kp.addr); |
@@ -1061,8 +1062,8 @@ static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs) | |||
1061 | 1062 | ||
1062 | size = sizeof(*entry) + tp->size; | 1063 | size = sizeof(*entry) + tp->size; |
1063 | 1064 | ||
1064 | event = trace_current_buffer_lock_reserve(&buffer, call->id, size, | 1065 | event = trace_current_buffer_lock_reserve(&buffer, call->event.type, |
1065 | irq_flags, pc); | 1066 | size, irq_flags, pc); |
1066 | if (!event) | 1067 | if (!event) |
1067 | return; | 1068 | return; |
1068 | 1069 | ||
@@ -1094,8 +1095,8 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri, | |||
1094 | 1095 | ||
1095 | size = sizeof(*entry) + tp->size; | 1096 | size = sizeof(*entry) + tp->size; |
1096 | 1097 | ||
1097 | event = trace_current_buffer_lock_reserve(&buffer, call->id, size, | 1098 | event = trace_current_buffer_lock_reserve(&buffer, call->event.type, |
1098 | irq_flags, pc); | 1099 | size, irq_flags, pc); |
1099 | if (!event) | 1100 | if (!event) |
1100 | return; | 1101 | return; |
1101 | 1102 | ||
@@ -1112,18 +1113,17 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri, | |||
1112 | 1113 | ||
1113 | /* Event entry printers */ | 1114 | /* Event entry printers */ |
1114 | enum print_line_t | 1115 | enum print_line_t |
1115 | print_kprobe_event(struct trace_iterator *iter, int flags) | 1116 | print_kprobe_event(struct trace_iterator *iter, int flags, |
1117 | struct trace_event *event) | ||
1116 | { | 1118 | { |
1117 | struct kprobe_trace_entry_head *field; | 1119 | struct kprobe_trace_entry_head *field; |
1118 | struct trace_seq *s = &iter->seq; | 1120 | struct trace_seq *s = &iter->seq; |
1119 | struct trace_event *event; | ||
1120 | struct trace_probe *tp; | 1121 | struct trace_probe *tp; |
1121 | u8 *data; | 1122 | u8 *data; |
1122 | int i; | 1123 | int i; |
1123 | 1124 | ||
1124 | field = (struct kprobe_trace_entry_head *)iter->ent; | 1125 | field = (struct kprobe_trace_entry_head *)iter->ent; |
1125 | event = ftrace_find_event(field->ent.type); | 1126 | tp = container_of(event, struct trace_probe, call.event); |
1126 | tp = container_of(event, struct trace_probe, event); | ||
1127 | 1127 | ||
1128 | if (!trace_seq_printf(s, "%s: (", tp->call.name)) | 1128 | if (!trace_seq_printf(s, "%s: (", tp->call.name)) |
1129 | goto partial; | 1129 | goto partial; |
@@ -1149,18 +1149,17 @@ partial: | |||
1149 | } | 1149 | } |
1150 | 1150 | ||
1151 | enum print_line_t | 1151 | enum print_line_t |
1152 | print_kretprobe_event(struct trace_iterator *iter, int flags) | 1152 | print_kretprobe_event(struct trace_iterator *iter, int flags, |
1153 | struct trace_event *event) | ||
1153 | { | 1154 | { |
1154 | struct kretprobe_trace_entry_head *field; | 1155 | struct kretprobe_trace_entry_head *field; |
1155 | struct trace_seq *s = &iter->seq; | 1156 | struct trace_seq *s = &iter->seq; |
1156 | struct trace_event *event; | ||
1157 | struct trace_probe *tp; | 1157 | struct trace_probe *tp; |
1158 | u8 *data; | 1158 | u8 *data; |
1159 | int i; | 1159 | int i; |
1160 | 1160 | ||
1161 | field = (struct kretprobe_trace_entry_head *)iter->ent; | 1161 | field = (struct kretprobe_trace_entry_head *)iter->ent; |
1162 | event = ftrace_find_event(field->ent.type); | 1162 | tp = container_of(event, struct trace_probe, call.event); |
1163 | tp = container_of(event, struct trace_probe, event); | ||
1164 | 1163 | ||
1165 | if (!trace_seq_printf(s, "%s: (", tp->call.name)) | 1164 | if (!trace_seq_printf(s, "%s: (", tp->call.name)) |
1166 | goto partial; | 1165 | goto partial; |
@@ -1217,8 +1216,6 @@ static void probe_event_disable(struct ftrace_event_call *call) | |||
1217 | 1216 | ||
1218 | static int probe_event_raw_init(struct ftrace_event_call *event_call) | 1217 | static int probe_event_raw_init(struct ftrace_event_call *event_call) |
1219 | { | 1218 | { |
1220 | INIT_LIST_HEAD(&event_call->fields); | ||
1221 | |||
1222 | return 0; | 1219 | return 0; |
1223 | } | 1220 | } |
1224 | 1221 | ||
@@ -1341,9 +1338,9 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp, | |||
1341 | struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp); | 1338 | struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp); |
1342 | struct ftrace_event_call *call = &tp->call; | 1339 | struct ftrace_event_call *call = &tp->call; |
1343 | struct kprobe_trace_entry_head *entry; | 1340 | struct kprobe_trace_entry_head *entry; |
1341 | struct hlist_head *head; | ||
1344 | u8 *data; | 1342 | u8 *data; |
1345 | int size, __size, i; | 1343 | int size, __size, i; |
1346 | unsigned long irq_flags; | ||
1347 | int rctx; | 1344 | int rctx; |
1348 | 1345 | ||
1349 | __size = sizeof(*entry) + tp->size; | 1346 | __size = sizeof(*entry) + tp->size; |
@@ -1353,7 +1350,7 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp, | |||
1353 | "profile buffer not large enough")) | 1350 | "profile buffer not large enough")) |
1354 | return; | 1351 | return; |
1355 | 1352 | ||
1356 | entry = perf_trace_buf_prepare(size, call->id, &rctx, &irq_flags); | 1353 | entry = perf_trace_buf_prepare(size, call->event.type, regs, &rctx); |
1357 | if (!entry) | 1354 | if (!entry) |
1358 | return; | 1355 | return; |
1359 | 1356 | ||
@@ -1362,7 +1359,8 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp, | |||
1362 | for (i = 0; i < tp->nr_args; i++) | 1359 | for (i = 0; i < tp->nr_args; i++) |
1363 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); | 1360 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); |
1364 | 1361 | ||
1365 | perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, irq_flags, regs); | 1362 | head = per_cpu_ptr(call->perf_events, smp_processor_id()); |
1363 | perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, regs, head); | ||
1366 | } | 1364 | } |
1367 | 1365 | ||
1368 | /* Kretprobe profile handler */ | 1366 | /* Kretprobe profile handler */ |
@@ -1372,9 +1370,9 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, | |||
1372 | struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp); | 1370 | struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp); |
1373 | struct ftrace_event_call *call = &tp->call; | 1371 | struct ftrace_event_call *call = &tp->call; |
1374 | struct kretprobe_trace_entry_head *entry; | 1372 | struct kretprobe_trace_entry_head *entry; |
1373 | struct hlist_head *head; | ||
1375 | u8 *data; | 1374 | u8 *data; |
1376 | int size, __size, i; | 1375 | int size, __size, i; |
1377 | unsigned long irq_flags; | ||
1378 | int rctx; | 1376 | int rctx; |
1379 | 1377 | ||
1380 | __size = sizeof(*entry) + tp->size; | 1378 | __size = sizeof(*entry) + tp->size; |
@@ -1384,7 +1382,7 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, | |||
1384 | "profile buffer not large enough")) | 1382 | "profile buffer not large enough")) |
1385 | return; | 1383 | return; |
1386 | 1384 | ||
1387 | entry = perf_trace_buf_prepare(size, call->id, &rctx, &irq_flags); | 1385 | entry = perf_trace_buf_prepare(size, call->event.type, regs, &rctx); |
1388 | if (!entry) | 1386 | if (!entry) |
1389 | return; | 1387 | return; |
1390 | 1388 | ||
@@ -1394,8 +1392,8 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, | |||
1394 | for (i = 0; i < tp->nr_args; i++) | 1392 | for (i = 0; i < tp->nr_args; i++) |
1395 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); | 1393 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); |
1396 | 1394 | ||
1397 | perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, | 1395 | head = per_cpu_ptr(call->perf_events, smp_processor_id()); |
1398 | irq_flags, regs); | 1396 | perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, regs, head); |
1399 | } | 1397 | } |
1400 | 1398 | ||
1401 | static int probe_perf_enable(struct ftrace_event_call *call) | 1399 | static int probe_perf_enable(struct ftrace_event_call *call) |
@@ -1425,6 +1423,26 @@ static void probe_perf_disable(struct ftrace_event_call *call) | |||
1425 | } | 1423 | } |
1426 | #endif /* CONFIG_PERF_EVENTS */ | 1424 | #endif /* CONFIG_PERF_EVENTS */ |
1427 | 1425 | ||
1426 | static __kprobes | ||
1427 | int kprobe_register(struct ftrace_event_call *event, enum trace_reg type) | ||
1428 | { | ||
1429 | switch (type) { | ||
1430 | case TRACE_REG_REGISTER: | ||
1431 | return probe_event_enable(event); | ||
1432 | case TRACE_REG_UNREGISTER: | ||
1433 | probe_event_disable(event); | ||
1434 | return 0; | ||
1435 | |||
1436 | #ifdef CONFIG_PERF_EVENTS | ||
1437 | case TRACE_REG_PERF_REGISTER: | ||
1438 | return probe_perf_enable(event); | ||
1439 | case TRACE_REG_PERF_UNREGISTER: | ||
1440 | probe_perf_disable(event); | ||
1441 | return 0; | ||
1442 | #endif | ||
1443 | } | ||
1444 | return 0; | ||
1445 | } | ||
1428 | 1446 | ||
1429 | static __kprobes | 1447 | static __kprobes |
1430 | int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs) | 1448 | int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs) |
@@ -1454,6 +1472,14 @@ int kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs) | |||
1454 | return 0; /* We don't tweek kernel, so just return 0 */ | 1472 | return 0; /* We don't tweek kernel, so just return 0 */ |
1455 | } | 1473 | } |
1456 | 1474 | ||
1475 | static struct trace_event_functions kretprobe_funcs = { | ||
1476 | .trace = print_kretprobe_event | ||
1477 | }; | ||
1478 | |||
1479 | static struct trace_event_functions kprobe_funcs = { | ||
1480 | .trace = print_kprobe_event | ||
1481 | }; | ||
1482 | |||
1457 | static int register_probe_event(struct trace_probe *tp) | 1483 | static int register_probe_event(struct trace_probe *tp) |
1458 | { | 1484 | { |
1459 | struct ftrace_event_call *call = &tp->call; | 1485 | struct ftrace_event_call *call = &tp->call; |
@@ -1461,36 +1487,31 @@ static int register_probe_event(struct trace_probe *tp) | |||
1461 | 1487 | ||
1462 | /* Initialize ftrace_event_call */ | 1488 | /* Initialize ftrace_event_call */ |
1463 | if (probe_is_return(tp)) { | 1489 | if (probe_is_return(tp)) { |
1464 | tp->event.trace = print_kretprobe_event; | 1490 | INIT_LIST_HEAD(&call->class->fields); |
1465 | call->raw_init = probe_event_raw_init; | 1491 | call->event.funcs = &kretprobe_funcs; |
1466 | call->define_fields = kretprobe_event_define_fields; | 1492 | call->class->raw_init = probe_event_raw_init; |
1493 | call->class->define_fields = kretprobe_event_define_fields; | ||
1467 | } else { | 1494 | } else { |
1468 | tp->event.trace = print_kprobe_event; | 1495 | INIT_LIST_HEAD(&call->class->fields); |
1469 | call->raw_init = probe_event_raw_init; | 1496 | call->event.funcs = &kprobe_funcs; |
1470 | call->define_fields = kprobe_event_define_fields; | 1497 | call->class->raw_init = probe_event_raw_init; |
1498 | call->class->define_fields = kprobe_event_define_fields; | ||
1471 | } | 1499 | } |
1472 | if (set_print_fmt(tp) < 0) | 1500 | if (set_print_fmt(tp) < 0) |
1473 | return -ENOMEM; | 1501 | return -ENOMEM; |
1474 | call->event = &tp->event; | 1502 | ret = register_ftrace_event(&call->event); |
1475 | call->id = register_ftrace_event(&tp->event); | 1503 | if (!ret) { |
1476 | if (!call->id) { | ||
1477 | kfree(call->print_fmt); | 1504 | kfree(call->print_fmt); |
1478 | return -ENODEV; | 1505 | return -ENODEV; |
1479 | } | 1506 | } |
1480 | call->enabled = 0; | 1507 | call->flags = 0; |
1481 | call->regfunc = probe_event_enable; | 1508 | call->class->reg = kprobe_register; |
1482 | call->unregfunc = probe_event_disable; | ||
1483 | |||
1484 | #ifdef CONFIG_PERF_EVENTS | ||
1485 | call->perf_event_enable = probe_perf_enable; | ||
1486 | call->perf_event_disable = probe_perf_disable; | ||
1487 | #endif | ||
1488 | call->data = tp; | 1509 | call->data = tp; |
1489 | ret = trace_add_event_call(call); | 1510 | ret = trace_add_event_call(call); |
1490 | if (ret) { | 1511 | if (ret) { |
1491 | pr_info("Failed to register kprobe event: %s\n", call->name); | 1512 | pr_info("Failed to register kprobe event: %s\n", call->name); |
1492 | kfree(call->print_fmt); | 1513 | kfree(call->print_fmt); |
1493 | unregister_ftrace_event(&tp->event); | 1514 | unregister_ftrace_event(&call->event); |
1494 | } | 1515 | } |
1495 | return ret; | 1516 | return ret; |
1496 | } | 1517 | } |
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index ab13d7008061..57c1b4596470 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c | |||
@@ -742,6 +742,9 @@ int register_ftrace_event(struct trace_event *event) | |||
742 | if (WARN_ON(!event)) | 742 | if (WARN_ON(!event)) |
743 | goto out; | 743 | goto out; |
744 | 744 | ||
745 | if (WARN_ON(!event->funcs)) | ||
746 | goto out; | ||
747 | |||
745 | INIT_LIST_HEAD(&event->list); | 748 | INIT_LIST_HEAD(&event->list); |
746 | 749 | ||
747 | if (!event->type) { | 750 | if (!event->type) { |
@@ -774,14 +777,14 @@ int register_ftrace_event(struct trace_event *event) | |||
774 | goto out; | 777 | goto out; |
775 | } | 778 | } |
776 | 779 | ||
777 | if (event->trace == NULL) | 780 | if (event->funcs->trace == NULL) |
778 | event->trace = trace_nop_print; | 781 | event->funcs->trace = trace_nop_print; |
779 | if (event->raw == NULL) | 782 | if (event->funcs->raw == NULL) |
780 | event->raw = trace_nop_print; | 783 | event->funcs->raw = trace_nop_print; |
781 | if (event->hex == NULL) | 784 | if (event->funcs->hex == NULL) |
782 | event->hex = trace_nop_print; | 785 | event->funcs->hex = trace_nop_print; |
783 | if (event->binary == NULL) | 786 | if (event->funcs->binary == NULL) |
784 | event->binary = trace_nop_print; | 787 | event->funcs->binary = trace_nop_print; |
785 | 788 | ||
786 | key = event->type & (EVENT_HASHSIZE - 1); | 789 | key = event->type & (EVENT_HASHSIZE - 1); |
787 | 790 | ||
@@ -823,13 +826,15 @@ EXPORT_SYMBOL_GPL(unregister_ftrace_event); | |||
823 | * Standard events | 826 | * Standard events |
824 | */ | 827 | */ |
825 | 828 | ||
826 | enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags) | 829 | enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags, |
830 | struct trace_event *event) | ||
827 | { | 831 | { |
828 | return TRACE_TYPE_HANDLED; | 832 | return TRACE_TYPE_HANDLED; |
829 | } | 833 | } |
830 | 834 | ||
831 | /* TRACE_FN */ | 835 | /* TRACE_FN */ |
832 | static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags) | 836 | static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags, |
837 | struct trace_event *event) | ||
833 | { | 838 | { |
834 | struct ftrace_entry *field; | 839 | struct ftrace_entry *field; |
835 | struct trace_seq *s = &iter->seq; | 840 | struct trace_seq *s = &iter->seq; |
@@ -856,7 +861,8 @@ static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags) | |||
856 | return TRACE_TYPE_PARTIAL_LINE; | 861 | return TRACE_TYPE_PARTIAL_LINE; |
857 | } | 862 | } |
858 | 863 | ||
859 | static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags) | 864 | static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags, |
865 | struct trace_event *event) | ||
860 | { | 866 | { |
861 | struct ftrace_entry *field; | 867 | struct ftrace_entry *field; |
862 | 868 | ||
@@ -870,7 +876,8 @@ static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags) | |||
870 | return TRACE_TYPE_HANDLED; | 876 | return TRACE_TYPE_HANDLED; |
871 | } | 877 | } |
872 | 878 | ||
873 | static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags) | 879 | static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags, |
880 | struct trace_event *event) | ||
874 | { | 881 | { |
875 | struct ftrace_entry *field; | 882 | struct ftrace_entry *field; |
876 | struct trace_seq *s = &iter->seq; | 883 | struct trace_seq *s = &iter->seq; |
@@ -883,7 +890,8 @@ static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags) | |||
883 | return TRACE_TYPE_HANDLED; | 890 | return TRACE_TYPE_HANDLED; |
884 | } | 891 | } |
885 | 892 | ||
886 | static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags) | 893 | static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags, |
894 | struct trace_event *event) | ||
887 | { | 895 | { |
888 | struct ftrace_entry *field; | 896 | struct ftrace_entry *field; |
889 | struct trace_seq *s = &iter->seq; | 897 | struct trace_seq *s = &iter->seq; |
@@ -896,14 +904,18 @@ static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags) | |||
896 | return TRACE_TYPE_HANDLED; | 904 | return TRACE_TYPE_HANDLED; |
897 | } | 905 | } |
898 | 906 | ||
899 | static struct trace_event trace_fn_event = { | 907 | static struct trace_event_functions trace_fn_funcs = { |
900 | .type = TRACE_FN, | ||
901 | .trace = trace_fn_trace, | 908 | .trace = trace_fn_trace, |
902 | .raw = trace_fn_raw, | 909 | .raw = trace_fn_raw, |
903 | .hex = trace_fn_hex, | 910 | .hex = trace_fn_hex, |
904 | .binary = trace_fn_bin, | 911 | .binary = trace_fn_bin, |
905 | }; | 912 | }; |
906 | 913 | ||
914 | static struct trace_event trace_fn_event = { | ||
915 | .type = TRACE_FN, | ||
916 | .funcs = &trace_fn_funcs, | ||
917 | }; | ||
918 | |||
907 | /* TRACE_CTX an TRACE_WAKE */ | 919 | /* TRACE_CTX an TRACE_WAKE */ |
908 | static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter, | 920 | static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter, |
909 | char *delim) | 921 | char *delim) |
@@ -932,13 +944,14 @@ static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter, | |||
932 | return TRACE_TYPE_HANDLED; | 944 | return TRACE_TYPE_HANDLED; |
933 | } | 945 | } |
934 | 946 | ||
935 | static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags) | 947 | static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags, |
948 | struct trace_event *event) | ||
936 | { | 949 | { |
937 | return trace_ctxwake_print(iter, "==>"); | 950 | return trace_ctxwake_print(iter, "==>"); |
938 | } | 951 | } |
939 | 952 | ||
940 | static enum print_line_t trace_wake_print(struct trace_iterator *iter, | 953 | static enum print_line_t trace_wake_print(struct trace_iterator *iter, |
941 | int flags) | 954 | int flags, struct trace_event *event) |
942 | { | 955 | { |
943 | return trace_ctxwake_print(iter, " +"); | 956 | return trace_ctxwake_print(iter, " +"); |
944 | } | 957 | } |
@@ -966,12 +979,14 @@ static int trace_ctxwake_raw(struct trace_iterator *iter, char S) | |||
966 | return TRACE_TYPE_HANDLED; | 979 | return TRACE_TYPE_HANDLED; |
967 | } | 980 | } |
968 | 981 | ||
969 | static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags) | 982 | static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags, |
983 | struct trace_event *event) | ||
970 | { | 984 | { |
971 | return trace_ctxwake_raw(iter, 0); | 985 | return trace_ctxwake_raw(iter, 0); |
972 | } | 986 | } |
973 | 987 | ||
974 | static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags) | 988 | static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags, |
989 | struct trace_event *event) | ||
975 | { | 990 | { |
976 | return trace_ctxwake_raw(iter, '+'); | 991 | return trace_ctxwake_raw(iter, '+'); |
977 | } | 992 | } |
@@ -1000,18 +1015,20 @@ static int trace_ctxwake_hex(struct trace_iterator *iter, char S) | |||
1000 | return TRACE_TYPE_HANDLED; | 1015 | return TRACE_TYPE_HANDLED; |
1001 | } | 1016 | } |
1002 | 1017 | ||
1003 | static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags) | 1018 | static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags, |
1019 | struct trace_event *event) | ||
1004 | { | 1020 | { |
1005 | return trace_ctxwake_hex(iter, 0); | 1021 | return trace_ctxwake_hex(iter, 0); |
1006 | } | 1022 | } |
1007 | 1023 | ||
1008 | static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags) | 1024 | static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags, |
1025 | struct trace_event *event) | ||
1009 | { | 1026 | { |
1010 | return trace_ctxwake_hex(iter, '+'); | 1027 | return trace_ctxwake_hex(iter, '+'); |
1011 | } | 1028 | } |
1012 | 1029 | ||
1013 | static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter, | 1030 | static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter, |
1014 | int flags) | 1031 | int flags, struct trace_event *event) |
1015 | { | 1032 | { |
1016 | struct ctx_switch_entry *field; | 1033 | struct ctx_switch_entry *field; |
1017 | struct trace_seq *s = &iter->seq; | 1034 | struct trace_seq *s = &iter->seq; |
@@ -1028,25 +1045,33 @@ static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter, | |||
1028 | return TRACE_TYPE_HANDLED; | 1045 | return TRACE_TYPE_HANDLED; |
1029 | } | 1046 | } |
1030 | 1047 | ||
1031 | static struct trace_event trace_ctx_event = { | 1048 | static struct trace_event_functions trace_ctx_funcs = { |
1032 | .type = TRACE_CTX, | ||
1033 | .trace = trace_ctx_print, | 1049 | .trace = trace_ctx_print, |
1034 | .raw = trace_ctx_raw, | 1050 | .raw = trace_ctx_raw, |
1035 | .hex = trace_ctx_hex, | 1051 | .hex = trace_ctx_hex, |
1036 | .binary = trace_ctxwake_bin, | 1052 | .binary = trace_ctxwake_bin, |
1037 | }; | 1053 | }; |
1038 | 1054 | ||
1039 | static struct trace_event trace_wake_event = { | 1055 | static struct trace_event trace_ctx_event = { |
1040 | .type = TRACE_WAKE, | 1056 | .type = TRACE_CTX, |
1057 | .funcs = &trace_ctx_funcs, | ||
1058 | }; | ||
1059 | |||
1060 | static struct trace_event_functions trace_wake_funcs = { | ||
1041 | .trace = trace_wake_print, | 1061 | .trace = trace_wake_print, |
1042 | .raw = trace_wake_raw, | 1062 | .raw = trace_wake_raw, |
1043 | .hex = trace_wake_hex, | 1063 | .hex = trace_wake_hex, |
1044 | .binary = trace_ctxwake_bin, | 1064 | .binary = trace_ctxwake_bin, |
1045 | }; | 1065 | }; |
1046 | 1066 | ||
1067 | static struct trace_event trace_wake_event = { | ||
1068 | .type = TRACE_WAKE, | ||
1069 | .funcs = &trace_wake_funcs, | ||
1070 | }; | ||
1071 | |||
1047 | /* TRACE_SPECIAL */ | 1072 | /* TRACE_SPECIAL */ |
1048 | static enum print_line_t trace_special_print(struct trace_iterator *iter, | 1073 | static enum print_line_t trace_special_print(struct trace_iterator *iter, |
1049 | int flags) | 1074 | int flags, struct trace_event *event) |
1050 | { | 1075 | { |
1051 | struct special_entry *field; | 1076 | struct special_entry *field; |
1052 | 1077 | ||
@@ -1062,7 +1087,7 @@ static enum print_line_t trace_special_print(struct trace_iterator *iter, | |||
1062 | } | 1087 | } |
1063 | 1088 | ||
1064 | static enum print_line_t trace_special_hex(struct trace_iterator *iter, | 1089 | static enum print_line_t trace_special_hex(struct trace_iterator *iter, |
1065 | int flags) | 1090 | int flags, struct trace_event *event) |
1066 | { | 1091 | { |
1067 | struct special_entry *field; | 1092 | struct special_entry *field; |
1068 | struct trace_seq *s = &iter->seq; | 1093 | struct trace_seq *s = &iter->seq; |
@@ -1077,7 +1102,7 @@ static enum print_line_t trace_special_hex(struct trace_iterator *iter, | |||
1077 | } | 1102 | } |
1078 | 1103 | ||
1079 | static enum print_line_t trace_special_bin(struct trace_iterator *iter, | 1104 | static enum print_line_t trace_special_bin(struct trace_iterator *iter, |
1080 | int flags) | 1105 | int flags, struct trace_event *event) |
1081 | { | 1106 | { |
1082 | struct special_entry *field; | 1107 | struct special_entry *field; |
1083 | struct trace_seq *s = &iter->seq; | 1108 | struct trace_seq *s = &iter->seq; |
@@ -1091,18 +1116,22 @@ static enum print_line_t trace_special_bin(struct trace_iterator *iter, | |||
1091 | return TRACE_TYPE_HANDLED; | 1116 | return TRACE_TYPE_HANDLED; |
1092 | } | 1117 | } |
1093 | 1118 | ||
1094 | static struct trace_event trace_special_event = { | 1119 | static struct trace_event_functions trace_special_funcs = { |
1095 | .type = TRACE_SPECIAL, | ||
1096 | .trace = trace_special_print, | 1120 | .trace = trace_special_print, |
1097 | .raw = trace_special_print, | 1121 | .raw = trace_special_print, |
1098 | .hex = trace_special_hex, | 1122 | .hex = trace_special_hex, |
1099 | .binary = trace_special_bin, | 1123 | .binary = trace_special_bin, |
1100 | }; | 1124 | }; |
1101 | 1125 | ||
1126 | static struct trace_event trace_special_event = { | ||
1127 | .type = TRACE_SPECIAL, | ||
1128 | .funcs = &trace_special_funcs, | ||
1129 | }; | ||
1130 | |||
1102 | /* TRACE_STACK */ | 1131 | /* TRACE_STACK */ |
1103 | 1132 | ||
1104 | static enum print_line_t trace_stack_print(struct trace_iterator *iter, | 1133 | static enum print_line_t trace_stack_print(struct trace_iterator *iter, |
1105 | int flags) | 1134 | int flags, struct trace_event *event) |
1106 | { | 1135 | { |
1107 | struct stack_entry *field; | 1136 | struct stack_entry *field; |
1108 | struct trace_seq *s = &iter->seq; | 1137 | struct trace_seq *s = &iter->seq; |
@@ -1130,17 +1159,21 @@ static enum print_line_t trace_stack_print(struct trace_iterator *iter, | |||
1130 | return TRACE_TYPE_PARTIAL_LINE; | 1159 | return TRACE_TYPE_PARTIAL_LINE; |
1131 | } | 1160 | } |
1132 | 1161 | ||
1133 | static struct trace_event trace_stack_event = { | 1162 | static struct trace_event_functions trace_stack_funcs = { |
1134 | .type = TRACE_STACK, | ||
1135 | .trace = trace_stack_print, | 1163 | .trace = trace_stack_print, |
1136 | .raw = trace_special_print, | 1164 | .raw = trace_special_print, |
1137 | .hex = trace_special_hex, | 1165 | .hex = trace_special_hex, |
1138 | .binary = trace_special_bin, | 1166 | .binary = trace_special_bin, |
1139 | }; | 1167 | }; |
1140 | 1168 | ||
1169 | static struct trace_event trace_stack_event = { | ||
1170 | .type = TRACE_STACK, | ||
1171 | .funcs = &trace_stack_funcs, | ||
1172 | }; | ||
1173 | |||
1141 | /* TRACE_USER_STACK */ | 1174 | /* TRACE_USER_STACK */ |
1142 | static enum print_line_t trace_user_stack_print(struct trace_iterator *iter, | 1175 | static enum print_line_t trace_user_stack_print(struct trace_iterator *iter, |
1143 | int flags) | 1176 | int flags, struct trace_event *event) |
1144 | { | 1177 | { |
1145 | struct userstack_entry *field; | 1178 | struct userstack_entry *field; |
1146 | struct trace_seq *s = &iter->seq; | 1179 | struct trace_seq *s = &iter->seq; |
@@ -1159,17 +1192,22 @@ static enum print_line_t trace_user_stack_print(struct trace_iterator *iter, | |||
1159 | return TRACE_TYPE_PARTIAL_LINE; | 1192 | return TRACE_TYPE_PARTIAL_LINE; |
1160 | } | 1193 | } |
1161 | 1194 | ||
1162 | static struct trace_event trace_user_stack_event = { | 1195 | static struct trace_event_functions trace_user_stack_funcs = { |
1163 | .type = TRACE_USER_STACK, | ||
1164 | .trace = trace_user_stack_print, | 1196 | .trace = trace_user_stack_print, |
1165 | .raw = trace_special_print, | 1197 | .raw = trace_special_print, |
1166 | .hex = trace_special_hex, | 1198 | .hex = trace_special_hex, |
1167 | .binary = trace_special_bin, | 1199 | .binary = trace_special_bin, |
1168 | }; | 1200 | }; |
1169 | 1201 | ||
1202 | static struct trace_event trace_user_stack_event = { | ||
1203 | .type = TRACE_USER_STACK, | ||
1204 | .funcs = &trace_user_stack_funcs, | ||
1205 | }; | ||
1206 | |||
1170 | /* TRACE_BPRINT */ | 1207 | /* TRACE_BPRINT */ |
1171 | static enum print_line_t | 1208 | static enum print_line_t |
1172 | trace_bprint_print(struct trace_iterator *iter, int flags) | 1209 | trace_bprint_print(struct trace_iterator *iter, int flags, |
1210 | struct trace_event *event) | ||
1173 | { | 1211 | { |
1174 | struct trace_entry *entry = iter->ent; | 1212 | struct trace_entry *entry = iter->ent; |
1175 | struct trace_seq *s = &iter->seq; | 1213 | struct trace_seq *s = &iter->seq; |
@@ -1194,7 +1232,8 @@ trace_bprint_print(struct trace_iterator *iter, int flags) | |||
1194 | 1232 | ||
1195 | 1233 | ||
1196 | static enum print_line_t | 1234 | static enum print_line_t |
1197 | trace_bprint_raw(struct trace_iterator *iter, int flags) | 1235 | trace_bprint_raw(struct trace_iterator *iter, int flags, |
1236 | struct trace_event *event) | ||
1198 | { | 1237 | { |
1199 | struct bprint_entry *field; | 1238 | struct bprint_entry *field; |
1200 | struct trace_seq *s = &iter->seq; | 1239 | struct trace_seq *s = &iter->seq; |
@@ -1213,16 +1252,19 @@ trace_bprint_raw(struct trace_iterator *iter, int flags) | |||
1213 | return TRACE_TYPE_PARTIAL_LINE; | 1252 | return TRACE_TYPE_PARTIAL_LINE; |
1214 | } | 1253 | } |
1215 | 1254 | ||
1255 | static struct trace_event_functions trace_bprint_funcs = { | ||
1256 | .trace = trace_bprint_print, | ||
1257 | .raw = trace_bprint_raw, | ||
1258 | }; | ||
1216 | 1259 | ||
1217 | static struct trace_event trace_bprint_event = { | 1260 | static struct trace_event trace_bprint_event = { |
1218 | .type = TRACE_BPRINT, | 1261 | .type = TRACE_BPRINT, |
1219 | .trace = trace_bprint_print, | 1262 | .funcs = &trace_bprint_funcs, |
1220 | .raw = trace_bprint_raw, | ||
1221 | }; | 1263 | }; |
1222 | 1264 | ||
1223 | /* TRACE_PRINT */ | 1265 | /* TRACE_PRINT */ |
1224 | static enum print_line_t trace_print_print(struct trace_iterator *iter, | 1266 | static enum print_line_t trace_print_print(struct trace_iterator *iter, |
1225 | int flags) | 1267 | int flags, struct trace_event *event) |
1226 | { | 1268 | { |
1227 | struct print_entry *field; | 1269 | struct print_entry *field; |
1228 | struct trace_seq *s = &iter->seq; | 1270 | struct trace_seq *s = &iter->seq; |
@@ -1241,7 +1283,8 @@ static enum print_line_t trace_print_print(struct trace_iterator *iter, | |||
1241 | return TRACE_TYPE_PARTIAL_LINE; | 1283 | return TRACE_TYPE_PARTIAL_LINE; |
1242 | } | 1284 | } |
1243 | 1285 | ||
1244 | static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags) | 1286 | static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags, |
1287 | struct trace_event *event) | ||
1245 | { | 1288 | { |
1246 | struct print_entry *field; | 1289 | struct print_entry *field; |
1247 | 1290 | ||
@@ -1256,12 +1299,16 @@ static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags) | |||
1256 | return TRACE_TYPE_PARTIAL_LINE; | 1299 | return TRACE_TYPE_PARTIAL_LINE; |
1257 | } | 1300 | } |
1258 | 1301 | ||
1259 | static struct trace_event trace_print_event = { | 1302 | static struct trace_event_functions trace_print_funcs = { |
1260 | .type = TRACE_PRINT, | ||
1261 | .trace = trace_print_print, | 1303 | .trace = trace_print_print, |
1262 | .raw = trace_print_raw, | 1304 | .raw = trace_print_raw, |
1263 | }; | 1305 | }; |
1264 | 1306 | ||
1307 | static struct trace_event trace_print_event = { | ||
1308 | .type = TRACE_PRINT, | ||
1309 | .funcs = &trace_print_funcs, | ||
1310 | }; | ||
1311 | |||
1265 | 1312 | ||
1266 | static struct trace_event *events[] __initdata = { | 1313 | static struct trace_event *events[] __initdata = { |
1267 | &trace_fn_event, | 1314 | &trace_fn_event, |
diff --git a/kernel/trace/trace_output.h b/kernel/trace/trace_output.h index 9d91c72ba38b..c038eba0492b 100644 --- a/kernel/trace/trace_output.h +++ b/kernel/trace/trace_output.h | |||
@@ -25,7 +25,7 @@ extern void trace_event_read_unlock(void); | |||
25 | extern struct trace_event *ftrace_find_event(int type); | 25 | extern struct trace_event *ftrace_find_event(int type); |
26 | 26 | ||
27 | extern enum print_line_t trace_nop_print(struct trace_iterator *iter, | 27 | extern enum print_line_t trace_nop_print(struct trace_iterator *iter, |
28 | int flags); | 28 | int flags, struct trace_event *event); |
29 | extern int | 29 | extern int |
30 | trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry); | 30 | trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry); |
31 | 31 | ||
diff --git a/kernel/trace/trace_sched_switch.c b/kernel/trace/trace_sched_switch.c index a55fccfede5d..8f758d070c43 100644 --- a/kernel/trace/trace_sched_switch.c +++ b/kernel/trace/trace_sched_switch.c | |||
@@ -50,7 +50,7 @@ tracing_sched_switch_trace(struct trace_array *tr, | |||
50 | } | 50 | } |
51 | 51 | ||
52 | static void | 52 | static void |
53 | probe_sched_switch(struct task_struct *prev, struct task_struct *next) | 53 | probe_sched_switch(void *ignore, struct task_struct *prev, struct task_struct *next) |
54 | { | 54 | { |
55 | struct trace_array_cpu *data; | 55 | struct trace_array_cpu *data; |
56 | unsigned long flags; | 56 | unsigned long flags; |
@@ -108,7 +108,7 @@ tracing_sched_wakeup_trace(struct trace_array *tr, | |||
108 | } | 108 | } |
109 | 109 | ||
110 | static void | 110 | static void |
111 | probe_sched_wakeup(struct task_struct *wakee, int success) | 111 | probe_sched_wakeup(void *ignore, struct task_struct *wakee, int success) |
112 | { | 112 | { |
113 | struct trace_array_cpu *data; | 113 | struct trace_array_cpu *data; |
114 | unsigned long flags; | 114 | unsigned long flags; |
@@ -138,21 +138,21 @@ static int tracing_sched_register(void) | |||
138 | { | 138 | { |
139 | int ret; | 139 | int ret; |
140 | 140 | ||
141 | ret = register_trace_sched_wakeup(probe_sched_wakeup); | 141 | ret = register_trace_sched_wakeup(probe_sched_wakeup, NULL); |
142 | if (ret) { | 142 | if (ret) { |
143 | pr_info("wakeup trace: Couldn't activate tracepoint" | 143 | pr_info("wakeup trace: Couldn't activate tracepoint" |
144 | " probe to kernel_sched_wakeup\n"); | 144 | " probe to kernel_sched_wakeup\n"); |
145 | return ret; | 145 | return ret; |
146 | } | 146 | } |
147 | 147 | ||
148 | ret = register_trace_sched_wakeup_new(probe_sched_wakeup); | 148 | ret = register_trace_sched_wakeup_new(probe_sched_wakeup, NULL); |
149 | if (ret) { | 149 | if (ret) { |
150 | pr_info("wakeup trace: Couldn't activate tracepoint" | 150 | pr_info("wakeup trace: Couldn't activate tracepoint" |
151 | " probe to kernel_sched_wakeup_new\n"); | 151 | " probe to kernel_sched_wakeup_new\n"); |
152 | goto fail_deprobe; | 152 | goto fail_deprobe; |
153 | } | 153 | } |
154 | 154 | ||
155 | ret = register_trace_sched_switch(probe_sched_switch); | 155 | ret = register_trace_sched_switch(probe_sched_switch, NULL); |
156 | if (ret) { | 156 | if (ret) { |
157 | pr_info("sched trace: Couldn't activate tracepoint" | 157 | pr_info("sched trace: Couldn't activate tracepoint" |
158 | " probe to kernel_sched_switch\n"); | 158 | " probe to kernel_sched_switch\n"); |
@@ -161,17 +161,17 @@ static int tracing_sched_register(void) | |||
161 | 161 | ||
162 | return ret; | 162 | return ret; |
163 | fail_deprobe_wake_new: | 163 | fail_deprobe_wake_new: |
164 | unregister_trace_sched_wakeup_new(probe_sched_wakeup); | 164 | unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL); |
165 | fail_deprobe: | 165 | fail_deprobe: |
166 | unregister_trace_sched_wakeup(probe_sched_wakeup); | 166 | unregister_trace_sched_wakeup(probe_sched_wakeup, NULL); |
167 | return ret; | 167 | return ret; |
168 | } | 168 | } |
169 | 169 | ||
170 | static void tracing_sched_unregister(void) | 170 | static void tracing_sched_unregister(void) |
171 | { | 171 | { |
172 | unregister_trace_sched_switch(probe_sched_switch); | 172 | unregister_trace_sched_switch(probe_sched_switch, NULL); |
173 | unregister_trace_sched_wakeup_new(probe_sched_wakeup); | 173 | unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL); |
174 | unregister_trace_sched_wakeup(probe_sched_wakeup); | 174 | unregister_trace_sched_wakeup(probe_sched_wakeup, NULL); |
175 | } | 175 | } |
176 | 176 | ||
177 | static void tracing_start_sched_switch(void) | 177 | static void tracing_start_sched_switch(void) |
diff --git a/kernel/trace/trace_sched_wakeup.c b/kernel/trace/trace_sched_wakeup.c index 8052446ceeaa..0e73bc2ef8c5 100644 --- a/kernel/trace/trace_sched_wakeup.c +++ b/kernel/trace/trace_sched_wakeup.c | |||
@@ -98,7 +98,8 @@ static int report_latency(cycle_t delta) | |||
98 | return 1; | 98 | return 1; |
99 | } | 99 | } |
100 | 100 | ||
101 | static void probe_wakeup_migrate_task(struct task_struct *task, int cpu) | 101 | static void |
102 | probe_wakeup_migrate_task(void *ignore, struct task_struct *task, int cpu) | ||
102 | { | 103 | { |
103 | if (task != wakeup_task) | 104 | if (task != wakeup_task) |
104 | return; | 105 | return; |
@@ -107,7 +108,8 @@ static void probe_wakeup_migrate_task(struct task_struct *task, int cpu) | |||
107 | } | 108 | } |
108 | 109 | ||
109 | static void notrace | 110 | static void notrace |
110 | probe_wakeup_sched_switch(struct task_struct *prev, struct task_struct *next) | 111 | probe_wakeup_sched_switch(void *ignore, |
112 | struct task_struct *prev, struct task_struct *next) | ||
111 | { | 113 | { |
112 | struct trace_array_cpu *data; | 114 | struct trace_array_cpu *data; |
113 | cycle_t T0, T1, delta; | 115 | cycle_t T0, T1, delta; |
@@ -199,7 +201,7 @@ static void wakeup_reset(struct trace_array *tr) | |||
199 | } | 201 | } |
200 | 202 | ||
201 | static void | 203 | static void |
202 | probe_wakeup(struct task_struct *p, int success) | 204 | probe_wakeup(void *ignore, struct task_struct *p, int success) |
203 | { | 205 | { |
204 | struct trace_array_cpu *data; | 206 | struct trace_array_cpu *data; |
205 | int cpu = smp_processor_id(); | 207 | int cpu = smp_processor_id(); |
@@ -263,28 +265,28 @@ static void start_wakeup_tracer(struct trace_array *tr) | |||
263 | { | 265 | { |
264 | int ret; | 266 | int ret; |
265 | 267 | ||
266 | ret = register_trace_sched_wakeup(probe_wakeup); | 268 | ret = register_trace_sched_wakeup(probe_wakeup, NULL); |
267 | if (ret) { | 269 | if (ret) { |
268 | pr_info("wakeup trace: Couldn't activate tracepoint" | 270 | pr_info("wakeup trace: Couldn't activate tracepoint" |
269 | " probe to kernel_sched_wakeup\n"); | 271 | " probe to kernel_sched_wakeup\n"); |
270 | return; | 272 | return; |
271 | } | 273 | } |
272 | 274 | ||
273 | ret = register_trace_sched_wakeup_new(probe_wakeup); | 275 | ret = register_trace_sched_wakeup_new(probe_wakeup, NULL); |
274 | if (ret) { | 276 | if (ret) { |
275 | pr_info("wakeup trace: Couldn't activate tracepoint" | 277 | pr_info("wakeup trace: Couldn't activate tracepoint" |
276 | " probe to kernel_sched_wakeup_new\n"); | 278 | " probe to kernel_sched_wakeup_new\n"); |
277 | goto fail_deprobe; | 279 | goto fail_deprobe; |
278 | } | 280 | } |
279 | 281 | ||
280 | ret = register_trace_sched_switch(probe_wakeup_sched_switch); | 282 | ret = register_trace_sched_switch(probe_wakeup_sched_switch, NULL); |
281 | if (ret) { | 283 | if (ret) { |
282 | pr_info("sched trace: Couldn't activate tracepoint" | 284 | pr_info("sched trace: Couldn't activate tracepoint" |
283 | " probe to kernel_sched_switch\n"); | 285 | " probe to kernel_sched_switch\n"); |
284 | goto fail_deprobe_wake_new; | 286 | goto fail_deprobe_wake_new; |
285 | } | 287 | } |
286 | 288 | ||
287 | ret = register_trace_sched_migrate_task(probe_wakeup_migrate_task); | 289 | ret = register_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL); |
288 | if (ret) { | 290 | if (ret) { |
289 | pr_info("wakeup trace: Couldn't activate tracepoint" | 291 | pr_info("wakeup trace: Couldn't activate tracepoint" |
290 | " probe to kernel_sched_migrate_task\n"); | 292 | " probe to kernel_sched_migrate_task\n"); |
@@ -311,19 +313,19 @@ static void start_wakeup_tracer(struct trace_array *tr) | |||
311 | 313 | ||
312 | return; | 314 | return; |
313 | fail_deprobe_wake_new: | 315 | fail_deprobe_wake_new: |
314 | unregister_trace_sched_wakeup_new(probe_wakeup); | 316 | unregister_trace_sched_wakeup_new(probe_wakeup, NULL); |
315 | fail_deprobe: | 317 | fail_deprobe: |
316 | unregister_trace_sched_wakeup(probe_wakeup); | 318 | unregister_trace_sched_wakeup(probe_wakeup, NULL); |
317 | } | 319 | } |
318 | 320 | ||
319 | static void stop_wakeup_tracer(struct trace_array *tr) | 321 | static void stop_wakeup_tracer(struct trace_array *tr) |
320 | { | 322 | { |
321 | tracer_enabled = 0; | 323 | tracer_enabled = 0; |
322 | unregister_ftrace_function(&trace_ops); | 324 | unregister_ftrace_function(&trace_ops); |
323 | unregister_trace_sched_switch(probe_wakeup_sched_switch); | 325 | unregister_trace_sched_switch(probe_wakeup_sched_switch, NULL); |
324 | unregister_trace_sched_wakeup_new(probe_wakeup); | 326 | unregister_trace_sched_wakeup_new(probe_wakeup, NULL); |
325 | unregister_trace_sched_wakeup(probe_wakeup); | 327 | unregister_trace_sched_wakeup(probe_wakeup, NULL); |
326 | unregister_trace_sched_migrate_task(probe_wakeup_migrate_task); | 328 | unregister_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL); |
327 | } | 329 | } |
328 | 330 | ||
329 | static int __wakeup_tracer_init(struct trace_array *tr) | 331 | static int __wakeup_tracer_init(struct trace_array *tr) |
diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c index 4d6d711717f2..d2c859cec9ea 100644 --- a/kernel/trace/trace_syscalls.c +++ b/kernel/trace/trace_syscalls.c | |||
@@ -15,6 +15,54 @@ static int sys_refcount_exit; | |||
15 | static DECLARE_BITMAP(enabled_enter_syscalls, NR_syscalls); | 15 | static DECLARE_BITMAP(enabled_enter_syscalls, NR_syscalls); |
16 | static DECLARE_BITMAP(enabled_exit_syscalls, NR_syscalls); | 16 | static DECLARE_BITMAP(enabled_exit_syscalls, NR_syscalls); |
17 | 17 | ||
18 | static int syscall_enter_register(struct ftrace_event_call *event, | ||
19 | enum trace_reg type); | ||
20 | static int syscall_exit_register(struct ftrace_event_call *event, | ||
21 | enum trace_reg type); | ||
22 | |||
23 | static int syscall_enter_define_fields(struct ftrace_event_call *call); | ||
24 | static int syscall_exit_define_fields(struct ftrace_event_call *call); | ||
25 | |||
26 | static struct list_head * | ||
27 | syscall_get_enter_fields(struct ftrace_event_call *call) | ||
28 | { | ||
29 | struct syscall_metadata *entry = call->data; | ||
30 | |||
31 | return &entry->enter_fields; | ||
32 | } | ||
33 | |||
34 | static struct list_head * | ||
35 | syscall_get_exit_fields(struct ftrace_event_call *call) | ||
36 | { | ||
37 | struct syscall_metadata *entry = call->data; | ||
38 | |||
39 | return &entry->exit_fields; | ||
40 | } | ||
41 | |||
42 | struct trace_event_functions enter_syscall_print_funcs = { | ||
43 | .trace = print_syscall_enter, | ||
44 | }; | ||
45 | |||
46 | struct trace_event_functions exit_syscall_print_funcs = { | ||
47 | .trace = print_syscall_exit, | ||
48 | }; | ||
49 | |||
50 | struct ftrace_event_class event_class_syscall_enter = { | ||
51 | .system = "syscalls", | ||
52 | .reg = syscall_enter_register, | ||
53 | .define_fields = syscall_enter_define_fields, | ||
54 | .get_fields = syscall_get_enter_fields, | ||
55 | .raw_init = init_syscall_trace, | ||
56 | }; | ||
57 | |||
58 | struct ftrace_event_class event_class_syscall_exit = { | ||
59 | .system = "syscalls", | ||
60 | .reg = syscall_exit_register, | ||
61 | .define_fields = syscall_exit_define_fields, | ||
62 | .get_fields = syscall_get_exit_fields, | ||
63 | .raw_init = init_syscall_trace, | ||
64 | }; | ||
65 | |||
18 | extern unsigned long __start_syscalls_metadata[]; | 66 | extern unsigned long __start_syscalls_metadata[]; |
19 | extern unsigned long __stop_syscalls_metadata[]; | 67 | extern unsigned long __stop_syscalls_metadata[]; |
20 | 68 | ||
@@ -53,7 +101,8 @@ static struct syscall_metadata *syscall_nr_to_meta(int nr) | |||
53 | } | 101 | } |
54 | 102 | ||
55 | enum print_line_t | 103 | enum print_line_t |
56 | print_syscall_enter(struct trace_iterator *iter, int flags) | 104 | print_syscall_enter(struct trace_iterator *iter, int flags, |
105 | struct trace_event *event) | ||
57 | { | 106 | { |
58 | struct trace_seq *s = &iter->seq; | 107 | struct trace_seq *s = &iter->seq; |
59 | struct trace_entry *ent = iter->ent; | 108 | struct trace_entry *ent = iter->ent; |
@@ -68,7 +117,7 @@ print_syscall_enter(struct trace_iterator *iter, int flags) | |||
68 | if (!entry) | 117 | if (!entry) |
69 | goto end; | 118 | goto end; |
70 | 119 | ||
71 | if (entry->enter_event->id != ent->type) { | 120 | if (entry->enter_event->event.type != ent->type) { |
72 | WARN_ON_ONCE(1); | 121 | WARN_ON_ONCE(1); |
73 | goto end; | 122 | goto end; |
74 | } | 123 | } |
@@ -105,7 +154,8 @@ end: | |||
105 | } | 154 | } |
106 | 155 | ||
107 | enum print_line_t | 156 | enum print_line_t |
108 | print_syscall_exit(struct trace_iterator *iter, int flags) | 157 | print_syscall_exit(struct trace_iterator *iter, int flags, |
158 | struct trace_event *event) | ||
109 | { | 159 | { |
110 | struct trace_seq *s = &iter->seq; | 160 | struct trace_seq *s = &iter->seq; |
111 | struct trace_entry *ent = iter->ent; | 161 | struct trace_entry *ent = iter->ent; |
@@ -123,7 +173,7 @@ print_syscall_exit(struct trace_iterator *iter, int flags) | |||
123 | return TRACE_TYPE_HANDLED; | 173 | return TRACE_TYPE_HANDLED; |
124 | } | 174 | } |
125 | 175 | ||
126 | if (entry->exit_event->id != ent->type) { | 176 | if (entry->exit_event->event.type != ent->type) { |
127 | WARN_ON_ONCE(1); | 177 | WARN_ON_ONCE(1); |
128 | return TRACE_TYPE_UNHANDLED; | 178 | return TRACE_TYPE_UNHANDLED; |
129 | } | 179 | } |
@@ -205,7 +255,7 @@ static void free_syscall_print_fmt(struct ftrace_event_call *call) | |||
205 | kfree(call->print_fmt); | 255 | kfree(call->print_fmt); |
206 | } | 256 | } |
207 | 257 | ||
208 | int syscall_enter_define_fields(struct ftrace_event_call *call) | 258 | static int syscall_enter_define_fields(struct ftrace_event_call *call) |
209 | { | 259 | { |
210 | struct syscall_trace_enter trace; | 260 | struct syscall_trace_enter trace; |
211 | struct syscall_metadata *meta = call->data; | 261 | struct syscall_metadata *meta = call->data; |
@@ -228,7 +278,7 @@ int syscall_enter_define_fields(struct ftrace_event_call *call) | |||
228 | return ret; | 278 | return ret; |
229 | } | 279 | } |
230 | 280 | ||
231 | int syscall_exit_define_fields(struct ftrace_event_call *call) | 281 | static int syscall_exit_define_fields(struct ftrace_event_call *call) |
232 | { | 282 | { |
233 | struct syscall_trace_exit trace; | 283 | struct syscall_trace_exit trace; |
234 | int ret; | 284 | int ret; |
@@ -243,7 +293,7 @@ int syscall_exit_define_fields(struct ftrace_event_call *call) | |||
243 | return ret; | 293 | return ret; |
244 | } | 294 | } |
245 | 295 | ||
246 | void ftrace_syscall_enter(struct pt_regs *regs, long id) | 296 | void ftrace_syscall_enter(void *ignore, struct pt_regs *regs, long id) |
247 | { | 297 | { |
248 | struct syscall_trace_enter *entry; | 298 | struct syscall_trace_enter *entry; |
249 | struct syscall_metadata *sys_data; | 299 | struct syscall_metadata *sys_data; |
@@ -265,7 +315,7 @@ void ftrace_syscall_enter(struct pt_regs *regs, long id) | |||
265 | size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args; | 315 | size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args; |
266 | 316 | ||
267 | event = trace_current_buffer_lock_reserve(&buffer, | 317 | event = trace_current_buffer_lock_reserve(&buffer, |
268 | sys_data->enter_event->id, size, 0, 0); | 318 | sys_data->enter_event->event.type, size, 0, 0); |
269 | if (!event) | 319 | if (!event) |
270 | return; | 320 | return; |
271 | 321 | ||
@@ -278,7 +328,7 @@ void ftrace_syscall_enter(struct pt_regs *regs, long id) | |||
278 | trace_current_buffer_unlock_commit(buffer, event, 0, 0); | 328 | trace_current_buffer_unlock_commit(buffer, event, 0, 0); |
279 | } | 329 | } |
280 | 330 | ||
281 | void ftrace_syscall_exit(struct pt_regs *regs, long ret) | 331 | void ftrace_syscall_exit(void *ignore, struct pt_regs *regs, long ret) |
282 | { | 332 | { |
283 | struct syscall_trace_exit *entry; | 333 | struct syscall_trace_exit *entry; |
284 | struct syscall_metadata *sys_data; | 334 | struct syscall_metadata *sys_data; |
@@ -297,7 +347,7 @@ void ftrace_syscall_exit(struct pt_regs *regs, long ret) | |||
297 | return; | 347 | return; |
298 | 348 | ||
299 | event = trace_current_buffer_lock_reserve(&buffer, | 349 | event = trace_current_buffer_lock_reserve(&buffer, |
300 | sys_data->exit_event->id, sizeof(*entry), 0, 0); | 350 | sys_data->exit_event->event.type, sizeof(*entry), 0, 0); |
301 | if (!event) | 351 | if (!event) |
302 | return; | 352 | return; |
303 | 353 | ||
@@ -320,7 +370,7 @@ int reg_event_syscall_enter(struct ftrace_event_call *call) | |||
320 | return -ENOSYS; | 370 | return -ENOSYS; |
321 | mutex_lock(&syscall_trace_lock); | 371 | mutex_lock(&syscall_trace_lock); |
322 | if (!sys_refcount_enter) | 372 | if (!sys_refcount_enter) |
323 | ret = register_trace_sys_enter(ftrace_syscall_enter); | 373 | ret = register_trace_sys_enter(ftrace_syscall_enter, NULL); |
324 | if (!ret) { | 374 | if (!ret) { |
325 | set_bit(num, enabled_enter_syscalls); | 375 | set_bit(num, enabled_enter_syscalls); |
326 | sys_refcount_enter++; | 376 | sys_refcount_enter++; |
@@ -340,7 +390,7 @@ void unreg_event_syscall_enter(struct ftrace_event_call *call) | |||
340 | sys_refcount_enter--; | 390 | sys_refcount_enter--; |
341 | clear_bit(num, enabled_enter_syscalls); | 391 | clear_bit(num, enabled_enter_syscalls); |
342 | if (!sys_refcount_enter) | 392 | if (!sys_refcount_enter) |
343 | unregister_trace_sys_enter(ftrace_syscall_enter); | 393 | unregister_trace_sys_enter(ftrace_syscall_enter, NULL); |
344 | mutex_unlock(&syscall_trace_lock); | 394 | mutex_unlock(&syscall_trace_lock); |
345 | } | 395 | } |
346 | 396 | ||
@@ -354,7 +404,7 @@ int reg_event_syscall_exit(struct ftrace_event_call *call) | |||
354 | return -ENOSYS; | 404 | return -ENOSYS; |
355 | mutex_lock(&syscall_trace_lock); | 405 | mutex_lock(&syscall_trace_lock); |
356 | if (!sys_refcount_exit) | 406 | if (!sys_refcount_exit) |
357 | ret = register_trace_sys_exit(ftrace_syscall_exit); | 407 | ret = register_trace_sys_exit(ftrace_syscall_exit, NULL); |
358 | if (!ret) { | 408 | if (!ret) { |
359 | set_bit(num, enabled_exit_syscalls); | 409 | set_bit(num, enabled_exit_syscalls); |
360 | sys_refcount_exit++; | 410 | sys_refcount_exit++; |
@@ -374,7 +424,7 @@ void unreg_event_syscall_exit(struct ftrace_event_call *call) | |||
374 | sys_refcount_exit--; | 424 | sys_refcount_exit--; |
375 | clear_bit(num, enabled_exit_syscalls); | 425 | clear_bit(num, enabled_exit_syscalls); |
376 | if (!sys_refcount_exit) | 426 | if (!sys_refcount_exit) |
377 | unregister_trace_sys_exit(ftrace_syscall_exit); | 427 | unregister_trace_sys_exit(ftrace_syscall_exit, NULL); |
378 | mutex_unlock(&syscall_trace_lock); | 428 | mutex_unlock(&syscall_trace_lock); |
379 | } | 429 | } |
380 | 430 | ||
@@ -434,11 +484,11 @@ static DECLARE_BITMAP(enabled_perf_exit_syscalls, NR_syscalls); | |||
434 | static int sys_perf_refcount_enter; | 484 | static int sys_perf_refcount_enter; |
435 | static int sys_perf_refcount_exit; | 485 | static int sys_perf_refcount_exit; |
436 | 486 | ||
437 | static void perf_syscall_enter(struct pt_regs *regs, long id) | 487 | static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id) |
438 | { | 488 | { |
439 | struct syscall_metadata *sys_data; | 489 | struct syscall_metadata *sys_data; |
440 | struct syscall_trace_enter *rec; | 490 | struct syscall_trace_enter *rec; |
441 | unsigned long flags; | 491 | struct hlist_head *head; |
442 | int syscall_nr; | 492 | int syscall_nr; |
443 | int rctx; | 493 | int rctx; |
444 | int size; | 494 | int size; |
@@ -461,14 +511,16 @@ static void perf_syscall_enter(struct pt_regs *regs, long id) | |||
461 | return; | 511 | return; |
462 | 512 | ||
463 | rec = (struct syscall_trace_enter *)perf_trace_buf_prepare(size, | 513 | rec = (struct syscall_trace_enter *)perf_trace_buf_prepare(size, |
464 | sys_data->enter_event->id, &rctx, &flags); | 514 | sys_data->enter_event->event.type, regs, &rctx); |
465 | if (!rec) | 515 | if (!rec) |
466 | return; | 516 | return; |
467 | 517 | ||
468 | rec->nr = syscall_nr; | 518 | rec->nr = syscall_nr; |
469 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, | 519 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, |
470 | (unsigned long *)&rec->args); | 520 | (unsigned long *)&rec->args); |
471 | perf_trace_buf_submit(rec, size, rctx, 0, 1, flags, regs); | 521 | |
522 | head = per_cpu_ptr(sys_data->enter_event->perf_events, smp_processor_id()); | ||
523 | perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head); | ||
472 | } | 524 | } |
473 | 525 | ||
474 | int perf_sysenter_enable(struct ftrace_event_call *call) | 526 | int perf_sysenter_enable(struct ftrace_event_call *call) |
@@ -480,7 +532,7 @@ int perf_sysenter_enable(struct ftrace_event_call *call) | |||
480 | 532 | ||
481 | mutex_lock(&syscall_trace_lock); | 533 | mutex_lock(&syscall_trace_lock); |
482 | if (!sys_perf_refcount_enter) | 534 | if (!sys_perf_refcount_enter) |
483 | ret = register_trace_sys_enter(perf_syscall_enter); | 535 | ret = register_trace_sys_enter(perf_syscall_enter, NULL); |
484 | if (ret) { | 536 | if (ret) { |
485 | pr_info("event trace: Could not activate" | 537 | pr_info("event trace: Could not activate" |
486 | "syscall entry trace point"); | 538 | "syscall entry trace point"); |
@@ -502,15 +554,15 @@ void perf_sysenter_disable(struct ftrace_event_call *call) | |||
502 | sys_perf_refcount_enter--; | 554 | sys_perf_refcount_enter--; |
503 | clear_bit(num, enabled_perf_enter_syscalls); | 555 | clear_bit(num, enabled_perf_enter_syscalls); |
504 | if (!sys_perf_refcount_enter) | 556 | if (!sys_perf_refcount_enter) |
505 | unregister_trace_sys_enter(perf_syscall_enter); | 557 | unregister_trace_sys_enter(perf_syscall_enter, NULL); |
506 | mutex_unlock(&syscall_trace_lock); | 558 | mutex_unlock(&syscall_trace_lock); |
507 | } | 559 | } |
508 | 560 | ||
509 | static void perf_syscall_exit(struct pt_regs *regs, long ret) | 561 | static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret) |
510 | { | 562 | { |
511 | struct syscall_metadata *sys_data; | 563 | struct syscall_metadata *sys_data; |
512 | struct syscall_trace_exit *rec; | 564 | struct syscall_trace_exit *rec; |
513 | unsigned long flags; | 565 | struct hlist_head *head; |
514 | int syscall_nr; | 566 | int syscall_nr; |
515 | int rctx; | 567 | int rctx; |
516 | int size; | 568 | int size; |
@@ -536,14 +588,15 @@ static void perf_syscall_exit(struct pt_regs *regs, long ret) | |||
536 | return; | 588 | return; |
537 | 589 | ||
538 | rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, | 590 | rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, |
539 | sys_data->exit_event->id, &rctx, &flags); | 591 | sys_data->exit_event->event.type, regs, &rctx); |
540 | if (!rec) | 592 | if (!rec) |
541 | return; | 593 | return; |
542 | 594 | ||
543 | rec->nr = syscall_nr; | 595 | rec->nr = syscall_nr; |
544 | rec->ret = syscall_get_return_value(current, regs); | 596 | rec->ret = syscall_get_return_value(current, regs); |
545 | 597 | ||
546 | perf_trace_buf_submit(rec, size, rctx, 0, 1, flags, regs); | 598 | head = per_cpu_ptr(sys_data->exit_event->perf_events, smp_processor_id()); |
599 | perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head); | ||
547 | } | 600 | } |
548 | 601 | ||
549 | int perf_sysexit_enable(struct ftrace_event_call *call) | 602 | int perf_sysexit_enable(struct ftrace_event_call *call) |
@@ -555,7 +608,7 @@ int perf_sysexit_enable(struct ftrace_event_call *call) | |||
555 | 608 | ||
556 | mutex_lock(&syscall_trace_lock); | 609 | mutex_lock(&syscall_trace_lock); |
557 | if (!sys_perf_refcount_exit) | 610 | if (!sys_perf_refcount_exit) |
558 | ret = register_trace_sys_exit(perf_syscall_exit); | 611 | ret = register_trace_sys_exit(perf_syscall_exit, NULL); |
559 | if (ret) { | 612 | if (ret) { |
560 | pr_info("event trace: Could not activate" | 613 | pr_info("event trace: Could not activate" |
561 | "syscall exit trace point"); | 614 | "syscall exit trace point"); |
@@ -577,9 +630,50 @@ void perf_sysexit_disable(struct ftrace_event_call *call) | |||
577 | sys_perf_refcount_exit--; | 630 | sys_perf_refcount_exit--; |
578 | clear_bit(num, enabled_perf_exit_syscalls); | 631 | clear_bit(num, enabled_perf_exit_syscalls); |
579 | if (!sys_perf_refcount_exit) | 632 | if (!sys_perf_refcount_exit) |
580 | unregister_trace_sys_exit(perf_syscall_exit); | 633 | unregister_trace_sys_exit(perf_syscall_exit, NULL); |
581 | mutex_unlock(&syscall_trace_lock); | 634 | mutex_unlock(&syscall_trace_lock); |
582 | } | 635 | } |
583 | 636 | ||
584 | #endif /* CONFIG_PERF_EVENTS */ | 637 | #endif /* CONFIG_PERF_EVENTS */ |
585 | 638 | ||
639 | static int syscall_enter_register(struct ftrace_event_call *event, | ||
640 | enum trace_reg type) | ||
641 | { | ||
642 | switch (type) { | ||
643 | case TRACE_REG_REGISTER: | ||
644 | return reg_event_syscall_enter(event); | ||
645 | case TRACE_REG_UNREGISTER: | ||
646 | unreg_event_syscall_enter(event); | ||
647 | return 0; | ||
648 | |||
649 | #ifdef CONFIG_PERF_EVENTS | ||
650 | case TRACE_REG_PERF_REGISTER: | ||
651 | return perf_sysenter_enable(event); | ||
652 | case TRACE_REG_PERF_UNREGISTER: | ||
653 | perf_sysenter_disable(event); | ||
654 | return 0; | ||
655 | #endif | ||
656 | } | ||
657 | return 0; | ||
658 | } | ||
659 | |||
660 | static int syscall_exit_register(struct ftrace_event_call *event, | ||
661 | enum trace_reg type) | ||
662 | { | ||
663 | switch (type) { | ||
664 | case TRACE_REG_REGISTER: | ||
665 | return reg_event_syscall_exit(event); | ||
666 | case TRACE_REG_UNREGISTER: | ||
667 | unreg_event_syscall_exit(event); | ||
668 | return 0; | ||
669 | |||
670 | #ifdef CONFIG_PERF_EVENTS | ||
671 | case TRACE_REG_PERF_REGISTER: | ||
672 | return perf_sysexit_enable(event); | ||
673 | case TRACE_REG_PERF_UNREGISTER: | ||
674 | perf_sysexit_disable(event); | ||
675 | return 0; | ||
676 | #endif | ||
677 | } | ||
678 | return 0; | ||
679 | } | ||
diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c index cc2d2faa7d9e..a7cc3793baf6 100644 --- a/kernel/trace/trace_workqueue.c +++ b/kernel/trace/trace_workqueue.c | |||
@@ -49,7 +49,8 @@ static void cpu_workqueue_stat_free(struct kref *kref) | |||
49 | 49 | ||
50 | /* Insertion of a work */ | 50 | /* Insertion of a work */ |
51 | static void | 51 | static void |
52 | probe_workqueue_insertion(struct task_struct *wq_thread, | 52 | probe_workqueue_insertion(void *ignore, |
53 | struct task_struct *wq_thread, | ||
53 | struct work_struct *work) | 54 | struct work_struct *work) |
54 | { | 55 | { |
55 | int cpu = cpumask_first(&wq_thread->cpus_allowed); | 56 | int cpu = cpumask_first(&wq_thread->cpus_allowed); |
@@ -70,7 +71,8 @@ found: | |||
70 | 71 | ||
71 | /* Execution of a work */ | 72 | /* Execution of a work */ |
72 | static void | 73 | static void |
73 | probe_workqueue_execution(struct task_struct *wq_thread, | 74 | probe_workqueue_execution(void *ignore, |
75 | struct task_struct *wq_thread, | ||
74 | struct work_struct *work) | 76 | struct work_struct *work) |
75 | { | 77 | { |
76 | int cpu = cpumask_first(&wq_thread->cpus_allowed); | 78 | int cpu = cpumask_first(&wq_thread->cpus_allowed); |
@@ -90,7 +92,8 @@ found: | |||
90 | } | 92 | } |
91 | 93 | ||
92 | /* Creation of a cpu workqueue thread */ | 94 | /* Creation of a cpu workqueue thread */ |
93 | static void probe_workqueue_creation(struct task_struct *wq_thread, int cpu) | 95 | static void probe_workqueue_creation(void *ignore, |
96 | struct task_struct *wq_thread, int cpu) | ||
94 | { | 97 | { |
95 | struct cpu_workqueue_stats *cws; | 98 | struct cpu_workqueue_stats *cws; |
96 | unsigned long flags; | 99 | unsigned long flags; |
@@ -114,7 +117,8 @@ static void probe_workqueue_creation(struct task_struct *wq_thread, int cpu) | |||
114 | } | 117 | } |
115 | 118 | ||
116 | /* Destruction of a cpu workqueue thread */ | 119 | /* Destruction of a cpu workqueue thread */ |
117 | static void probe_workqueue_destruction(struct task_struct *wq_thread) | 120 | static void |
121 | probe_workqueue_destruction(void *ignore, struct task_struct *wq_thread) | ||
118 | { | 122 | { |
119 | /* Workqueue only execute on one cpu */ | 123 | /* Workqueue only execute on one cpu */ |
120 | int cpu = cpumask_first(&wq_thread->cpus_allowed); | 124 | int cpu = cpumask_first(&wq_thread->cpus_allowed); |
@@ -259,19 +263,19 @@ int __init trace_workqueue_early_init(void) | |||
259 | { | 263 | { |
260 | int ret, cpu; | 264 | int ret, cpu; |
261 | 265 | ||
262 | ret = register_trace_workqueue_insertion(probe_workqueue_insertion); | 266 | ret = register_trace_workqueue_insertion(probe_workqueue_insertion, NULL); |
263 | if (ret) | 267 | if (ret) |
264 | goto out; | 268 | goto out; |
265 | 269 | ||
266 | ret = register_trace_workqueue_execution(probe_workqueue_execution); | 270 | ret = register_trace_workqueue_execution(probe_workqueue_execution, NULL); |
267 | if (ret) | 271 | if (ret) |
268 | goto no_insertion; | 272 | goto no_insertion; |
269 | 273 | ||
270 | ret = register_trace_workqueue_creation(probe_workqueue_creation); | 274 | ret = register_trace_workqueue_creation(probe_workqueue_creation, NULL); |
271 | if (ret) | 275 | if (ret) |
272 | goto no_execution; | 276 | goto no_execution; |
273 | 277 | ||
274 | ret = register_trace_workqueue_destruction(probe_workqueue_destruction); | 278 | ret = register_trace_workqueue_destruction(probe_workqueue_destruction, NULL); |
275 | if (ret) | 279 | if (ret) |
276 | goto no_creation; | 280 | goto no_creation; |
277 | 281 | ||
@@ -283,11 +287,11 @@ int __init trace_workqueue_early_init(void) | |||
283 | return 0; | 287 | return 0; |
284 | 288 | ||
285 | no_creation: | 289 | no_creation: |
286 | unregister_trace_workqueue_creation(probe_workqueue_creation); | 290 | unregister_trace_workqueue_creation(probe_workqueue_creation, NULL); |
287 | no_execution: | 291 | no_execution: |
288 | unregister_trace_workqueue_execution(probe_workqueue_execution); | 292 | unregister_trace_workqueue_execution(probe_workqueue_execution, NULL); |
289 | no_insertion: | 293 | no_insertion: |
290 | unregister_trace_workqueue_insertion(probe_workqueue_insertion); | 294 | unregister_trace_workqueue_insertion(probe_workqueue_insertion, NULL); |
291 | out: | 295 | out: |
292 | pr_warning("trace_workqueue: unable to trace workqueues\n"); | 296 | pr_warning("trace_workqueue: unable to trace workqueues\n"); |
293 | 297 | ||
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c index cc89be5bc0f8..c77f3eceea25 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c | |||
@@ -54,7 +54,7 @@ static struct hlist_head tracepoint_table[TRACEPOINT_TABLE_SIZE]; | |||
54 | */ | 54 | */ |
55 | struct tracepoint_entry { | 55 | struct tracepoint_entry { |
56 | struct hlist_node hlist; | 56 | struct hlist_node hlist; |
57 | void **funcs; | 57 | struct tracepoint_func *funcs; |
58 | int refcount; /* Number of times armed. 0 if disarmed. */ | 58 | int refcount; /* Number of times armed. 0 if disarmed. */ |
59 | char name[0]; | 59 | char name[0]; |
60 | }; | 60 | }; |
@@ -64,12 +64,12 @@ struct tp_probes { | |||
64 | struct rcu_head rcu; | 64 | struct rcu_head rcu; |
65 | struct list_head list; | 65 | struct list_head list; |
66 | } u; | 66 | } u; |
67 | void *probes[0]; | 67 | struct tracepoint_func probes[0]; |
68 | }; | 68 | }; |
69 | 69 | ||
70 | static inline void *allocate_probes(int count) | 70 | static inline void *allocate_probes(int count) |
71 | { | 71 | { |
72 | struct tp_probes *p = kmalloc(count * sizeof(void *) | 72 | struct tp_probes *p = kmalloc(count * sizeof(struct tracepoint_func) |
73 | + sizeof(struct tp_probes), GFP_KERNEL); | 73 | + sizeof(struct tp_probes), GFP_KERNEL); |
74 | return p == NULL ? NULL : p->probes; | 74 | return p == NULL ? NULL : p->probes; |
75 | } | 75 | } |
@@ -79,7 +79,7 @@ static void rcu_free_old_probes(struct rcu_head *head) | |||
79 | kfree(container_of(head, struct tp_probes, u.rcu)); | 79 | kfree(container_of(head, struct tp_probes, u.rcu)); |
80 | } | 80 | } |
81 | 81 | ||
82 | static inline void release_probes(void *old) | 82 | static inline void release_probes(struct tracepoint_func *old) |
83 | { | 83 | { |
84 | if (old) { | 84 | if (old) { |
85 | struct tp_probes *tp_probes = container_of(old, | 85 | struct tp_probes *tp_probes = container_of(old, |
@@ -95,15 +95,16 @@ static void debug_print_probes(struct tracepoint_entry *entry) | |||
95 | if (!tracepoint_debug || !entry->funcs) | 95 | if (!tracepoint_debug || !entry->funcs) |
96 | return; | 96 | return; |
97 | 97 | ||
98 | for (i = 0; entry->funcs[i]; i++) | 98 | for (i = 0; entry->funcs[i].func; i++) |
99 | printk(KERN_DEBUG "Probe %d : %p\n", i, entry->funcs[i]); | 99 | printk(KERN_DEBUG "Probe %d : %p\n", i, entry->funcs[i].func); |
100 | } | 100 | } |
101 | 101 | ||
102 | static void * | 102 | static struct tracepoint_func * |
103 | tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe) | 103 | tracepoint_entry_add_probe(struct tracepoint_entry *entry, |
104 | void *probe, void *data) | ||
104 | { | 105 | { |
105 | int nr_probes = 0; | 106 | int nr_probes = 0; |
106 | void **old, **new; | 107 | struct tracepoint_func *old, *new; |
107 | 108 | ||
108 | WARN_ON(!probe); | 109 | WARN_ON(!probe); |
109 | 110 | ||
@@ -111,8 +112,9 @@ tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe) | |||
111 | old = entry->funcs; | 112 | old = entry->funcs; |
112 | if (old) { | 113 | if (old) { |
113 | /* (N -> N+1), (N != 0, 1) probes */ | 114 | /* (N -> N+1), (N != 0, 1) probes */ |
114 | for (nr_probes = 0; old[nr_probes]; nr_probes++) | 115 | for (nr_probes = 0; old[nr_probes].func; nr_probes++) |
115 | if (old[nr_probes] == probe) | 116 | if (old[nr_probes].func == probe && |
117 | old[nr_probes].data == data) | ||
116 | return ERR_PTR(-EEXIST); | 118 | return ERR_PTR(-EEXIST); |
117 | } | 119 | } |
118 | /* + 2 : one for new probe, one for NULL func */ | 120 | /* + 2 : one for new probe, one for NULL func */ |
@@ -120,9 +122,10 @@ tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe) | |||
120 | if (new == NULL) | 122 | if (new == NULL) |
121 | return ERR_PTR(-ENOMEM); | 123 | return ERR_PTR(-ENOMEM); |
122 | if (old) | 124 | if (old) |
123 | memcpy(new, old, nr_probes * sizeof(void *)); | 125 | memcpy(new, old, nr_probes * sizeof(struct tracepoint_func)); |
124 | new[nr_probes] = probe; | 126 | new[nr_probes].func = probe; |
125 | new[nr_probes + 1] = NULL; | 127 | new[nr_probes].data = data; |
128 | new[nr_probes + 1].func = NULL; | ||
126 | entry->refcount = nr_probes + 1; | 129 | entry->refcount = nr_probes + 1; |
127 | entry->funcs = new; | 130 | entry->funcs = new; |
128 | debug_print_probes(entry); | 131 | debug_print_probes(entry); |
@@ -130,10 +133,11 @@ tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe) | |||
130 | } | 133 | } |
131 | 134 | ||
132 | static void * | 135 | static void * |
133 | tracepoint_entry_remove_probe(struct tracepoint_entry *entry, void *probe) | 136 | tracepoint_entry_remove_probe(struct tracepoint_entry *entry, |
137 | void *probe, void *data) | ||
134 | { | 138 | { |
135 | int nr_probes = 0, nr_del = 0, i; | 139 | int nr_probes = 0, nr_del = 0, i; |
136 | void **old, **new; | 140 | struct tracepoint_func *old, *new; |
137 | 141 | ||
138 | old = entry->funcs; | 142 | old = entry->funcs; |
139 | 143 | ||
@@ -142,8 +146,10 @@ tracepoint_entry_remove_probe(struct tracepoint_entry *entry, void *probe) | |||
142 | 146 | ||
143 | debug_print_probes(entry); | 147 | debug_print_probes(entry); |
144 | /* (N -> M), (N > 1, M >= 0) probes */ | 148 | /* (N -> M), (N > 1, M >= 0) probes */ |
145 | for (nr_probes = 0; old[nr_probes]; nr_probes++) { | 149 | for (nr_probes = 0; old[nr_probes].func; nr_probes++) { |
146 | if ((!probe || old[nr_probes] == probe)) | 150 | if (!probe || |
151 | (old[nr_probes].func == probe && | ||
152 | old[nr_probes].data == data)) | ||
147 | nr_del++; | 153 | nr_del++; |
148 | } | 154 | } |
149 | 155 | ||
@@ -160,10 +166,11 @@ tracepoint_entry_remove_probe(struct tracepoint_entry *entry, void *probe) | |||
160 | new = allocate_probes(nr_probes - nr_del + 1); | 166 | new = allocate_probes(nr_probes - nr_del + 1); |
161 | if (new == NULL) | 167 | if (new == NULL) |
162 | return ERR_PTR(-ENOMEM); | 168 | return ERR_PTR(-ENOMEM); |
163 | for (i = 0; old[i]; i++) | 169 | for (i = 0; old[i].func; i++) |
164 | if ((probe && old[i] != probe)) | 170 | if (probe && |
171 | (old[i].func != probe || old[i].data != data)) | ||
165 | new[j++] = old[i]; | 172 | new[j++] = old[i]; |
166 | new[nr_probes - nr_del] = NULL; | 173 | new[nr_probes - nr_del].func = NULL; |
167 | entry->refcount = nr_probes - nr_del; | 174 | entry->refcount = nr_probes - nr_del; |
168 | entry->funcs = new; | 175 | entry->funcs = new; |
169 | } | 176 | } |
@@ -315,18 +322,19 @@ static void tracepoint_update_probes(void) | |||
315 | module_update_tracepoints(); | 322 | module_update_tracepoints(); |
316 | } | 323 | } |
317 | 324 | ||
318 | static void *tracepoint_add_probe(const char *name, void *probe) | 325 | static struct tracepoint_func * |
326 | tracepoint_add_probe(const char *name, void *probe, void *data) | ||
319 | { | 327 | { |
320 | struct tracepoint_entry *entry; | 328 | struct tracepoint_entry *entry; |
321 | void *old; | 329 | struct tracepoint_func *old; |
322 | 330 | ||
323 | entry = get_tracepoint(name); | 331 | entry = get_tracepoint(name); |
324 | if (!entry) { | 332 | if (!entry) { |
325 | entry = add_tracepoint(name); | 333 | entry = add_tracepoint(name); |
326 | if (IS_ERR(entry)) | 334 | if (IS_ERR(entry)) |
327 | return entry; | 335 | return (struct tracepoint_func *)entry; |
328 | } | 336 | } |
329 | old = tracepoint_entry_add_probe(entry, probe); | 337 | old = tracepoint_entry_add_probe(entry, probe, data); |
330 | if (IS_ERR(old) && !entry->refcount) | 338 | if (IS_ERR(old) && !entry->refcount) |
331 | remove_tracepoint(entry); | 339 | remove_tracepoint(entry); |
332 | return old; | 340 | return old; |
@@ -340,12 +348,12 @@ static void *tracepoint_add_probe(const char *name, void *probe) | |||
340 | * Returns 0 if ok, error value on error. | 348 | * Returns 0 if ok, error value on error. |
341 | * The probe address must at least be aligned on the architecture pointer size. | 349 | * The probe address must at least be aligned on the architecture pointer size. |
342 | */ | 350 | */ |
343 | int tracepoint_probe_register(const char *name, void *probe) | 351 | int tracepoint_probe_register(const char *name, void *probe, void *data) |
344 | { | 352 | { |
345 | void *old; | 353 | struct tracepoint_func *old; |
346 | 354 | ||
347 | mutex_lock(&tracepoints_mutex); | 355 | mutex_lock(&tracepoints_mutex); |
348 | old = tracepoint_add_probe(name, probe); | 356 | old = tracepoint_add_probe(name, probe, data); |
349 | mutex_unlock(&tracepoints_mutex); | 357 | mutex_unlock(&tracepoints_mutex); |
350 | if (IS_ERR(old)) | 358 | if (IS_ERR(old)) |
351 | return PTR_ERR(old); | 359 | return PTR_ERR(old); |
@@ -356,15 +364,16 @@ int tracepoint_probe_register(const char *name, void *probe) | |||
356 | } | 364 | } |
357 | EXPORT_SYMBOL_GPL(tracepoint_probe_register); | 365 | EXPORT_SYMBOL_GPL(tracepoint_probe_register); |
358 | 366 | ||
359 | static void *tracepoint_remove_probe(const char *name, void *probe) | 367 | static struct tracepoint_func * |
368 | tracepoint_remove_probe(const char *name, void *probe, void *data) | ||
360 | { | 369 | { |
361 | struct tracepoint_entry *entry; | 370 | struct tracepoint_entry *entry; |
362 | void *old; | 371 | struct tracepoint_func *old; |
363 | 372 | ||
364 | entry = get_tracepoint(name); | 373 | entry = get_tracepoint(name); |
365 | if (!entry) | 374 | if (!entry) |
366 | return ERR_PTR(-ENOENT); | 375 | return ERR_PTR(-ENOENT); |
367 | old = tracepoint_entry_remove_probe(entry, probe); | 376 | old = tracepoint_entry_remove_probe(entry, probe, data); |
368 | if (IS_ERR(old)) | 377 | if (IS_ERR(old)) |
369 | return old; | 378 | return old; |
370 | if (!entry->refcount) | 379 | if (!entry->refcount) |
@@ -382,12 +391,12 @@ static void *tracepoint_remove_probe(const char *name, void *probe) | |||
382 | * itself uses stop_machine(), which insures that every preempt disabled section | 391 | * itself uses stop_machine(), which insures that every preempt disabled section |
383 | * have finished. | 392 | * have finished. |
384 | */ | 393 | */ |
385 | int tracepoint_probe_unregister(const char *name, void *probe) | 394 | int tracepoint_probe_unregister(const char *name, void *probe, void *data) |
386 | { | 395 | { |
387 | void *old; | 396 | struct tracepoint_func *old; |
388 | 397 | ||
389 | mutex_lock(&tracepoints_mutex); | 398 | mutex_lock(&tracepoints_mutex); |
390 | old = tracepoint_remove_probe(name, probe); | 399 | old = tracepoint_remove_probe(name, probe, data); |
391 | mutex_unlock(&tracepoints_mutex); | 400 | mutex_unlock(&tracepoints_mutex); |
392 | if (IS_ERR(old)) | 401 | if (IS_ERR(old)) |
393 | return PTR_ERR(old); | 402 | return PTR_ERR(old); |
@@ -418,12 +427,13 @@ static void tracepoint_add_old_probes(void *old) | |||
418 | * | 427 | * |
419 | * caller must call tracepoint_probe_update_all() | 428 | * caller must call tracepoint_probe_update_all() |
420 | */ | 429 | */ |
421 | int tracepoint_probe_register_noupdate(const char *name, void *probe) | 430 | int tracepoint_probe_register_noupdate(const char *name, void *probe, |
431 | void *data) | ||
422 | { | 432 | { |
423 | void *old; | 433 | struct tracepoint_func *old; |
424 | 434 | ||
425 | mutex_lock(&tracepoints_mutex); | 435 | mutex_lock(&tracepoints_mutex); |
426 | old = tracepoint_add_probe(name, probe); | 436 | old = tracepoint_add_probe(name, probe, data); |
427 | if (IS_ERR(old)) { | 437 | if (IS_ERR(old)) { |
428 | mutex_unlock(&tracepoints_mutex); | 438 | mutex_unlock(&tracepoints_mutex); |
429 | return PTR_ERR(old); | 439 | return PTR_ERR(old); |
@@ -441,12 +451,13 @@ EXPORT_SYMBOL_GPL(tracepoint_probe_register_noupdate); | |||
441 | * | 451 | * |
442 | * caller must call tracepoint_probe_update_all() | 452 | * caller must call tracepoint_probe_update_all() |
443 | */ | 453 | */ |
444 | int tracepoint_probe_unregister_noupdate(const char *name, void *probe) | 454 | int tracepoint_probe_unregister_noupdate(const char *name, void *probe, |
455 | void *data) | ||
445 | { | 456 | { |
446 | void *old; | 457 | struct tracepoint_func *old; |
447 | 458 | ||
448 | mutex_lock(&tracepoints_mutex); | 459 | mutex_lock(&tracepoints_mutex); |
449 | old = tracepoint_remove_probe(name, probe); | 460 | old = tracepoint_remove_probe(name, probe, data); |
450 | if (IS_ERR(old)) { | 461 | if (IS_ERR(old)) { |
451 | mutex_unlock(&tracepoints_mutex); | 462 | mutex_unlock(&tracepoints_mutex); |
452 | return PTR_ERR(old); | 463 | return PTR_ERR(old); |
diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c index cf208d8042b1..ad41529fb60f 100644 --- a/net/core/drop_monitor.c +++ b/net/core/drop_monitor.c | |||
@@ -172,12 +172,12 @@ out: | |||
172 | return; | 172 | return; |
173 | } | 173 | } |
174 | 174 | ||
175 | static void trace_kfree_skb_hit(struct sk_buff *skb, void *location) | 175 | static void trace_kfree_skb_hit(void *ignore, struct sk_buff *skb, void *location) |
176 | { | 176 | { |
177 | trace_drop_common(skb, location); | 177 | trace_drop_common(skb, location); |
178 | } | 178 | } |
179 | 179 | ||
180 | static void trace_napi_poll_hit(struct napi_struct *napi) | 180 | static void trace_napi_poll_hit(void *ignore, struct napi_struct *napi) |
181 | { | 181 | { |
182 | struct dm_hw_stat_delta *new_stat; | 182 | struct dm_hw_stat_delta *new_stat; |
183 | 183 | ||
@@ -225,12 +225,12 @@ static int set_all_monitor_traces(int state) | |||
225 | 225 | ||
226 | switch (state) { | 226 | switch (state) { |
227 | case TRACE_ON: | 227 | case TRACE_ON: |
228 | rc |= register_trace_kfree_skb(trace_kfree_skb_hit); | 228 | rc |= register_trace_kfree_skb(trace_kfree_skb_hit, NULL); |
229 | rc |= register_trace_napi_poll(trace_napi_poll_hit); | 229 | rc |= register_trace_napi_poll(trace_napi_poll_hit, NULL); |
230 | break; | 230 | break; |
231 | case TRACE_OFF: | 231 | case TRACE_OFF: |
232 | rc |= unregister_trace_kfree_skb(trace_kfree_skb_hit); | 232 | rc |= unregister_trace_kfree_skb(trace_kfree_skb_hit, NULL); |
233 | rc |= unregister_trace_napi_poll(trace_napi_poll_hit); | 233 | rc |= unregister_trace_napi_poll(trace_napi_poll_hit, NULL); |
234 | 234 | ||
235 | tracepoint_synchronize_unregister(); | 235 | tracepoint_synchronize_unregister(); |
236 | 236 | ||
diff --git a/samples/tracepoints/tp-samples-trace.h b/samples/tracepoints/tp-samples-trace.h index dffdc49878af..4d46be965961 100644 --- a/samples/tracepoints/tp-samples-trace.h +++ b/samples/tracepoints/tp-samples-trace.h | |||
@@ -7,7 +7,5 @@ | |||
7 | DECLARE_TRACE(subsys_event, | 7 | DECLARE_TRACE(subsys_event, |
8 | TP_PROTO(struct inode *inode, struct file *file), | 8 | TP_PROTO(struct inode *inode, struct file *file), |
9 | TP_ARGS(inode, file)); | 9 | TP_ARGS(inode, file)); |
10 | DECLARE_TRACE(subsys_eventb, | 10 | DECLARE_TRACE_NOARGS(subsys_eventb); |
11 | TP_PROTO(void), | ||
12 | TP_ARGS()); | ||
13 | #endif | 11 | #endif |
diff --git a/samples/tracepoints/tracepoint-probe-sample.c b/samples/tracepoints/tracepoint-probe-sample.c index 9e60eb6ca2d8..744c0b9652a7 100644 --- a/samples/tracepoints/tracepoint-probe-sample.c +++ b/samples/tracepoints/tracepoint-probe-sample.c | |||
@@ -13,7 +13,8 @@ | |||
13 | * Here the caller only guarantees locking for struct file and struct inode. | 13 | * Here the caller only guarantees locking for struct file and struct inode. |
14 | * Locking must therefore be done in the probe to use the dentry. | 14 | * Locking must therefore be done in the probe to use the dentry. |
15 | */ | 15 | */ |
16 | static void probe_subsys_event(struct inode *inode, struct file *file) | 16 | static void probe_subsys_event(void *ignore, |
17 | struct inode *inode, struct file *file) | ||
17 | { | 18 | { |
18 | path_get(&file->f_path); | 19 | path_get(&file->f_path); |
19 | dget(file->f_path.dentry); | 20 | dget(file->f_path.dentry); |
@@ -23,7 +24,7 @@ static void probe_subsys_event(struct inode *inode, struct file *file) | |||
23 | path_put(&file->f_path); | 24 | path_put(&file->f_path); |
24 | } | 25 | } |
25 | 26 | ||
26 | static void probe_subsys_eventb(void) | 27 | static void probe_subsys_eventb(void *ignore) |
27 | { | 28 | { |
28 | printk(KERN_INFO "Event B is encountered\n"); | 29 | printk(KERN_INFO "Event B is encountered\n"); |
29 | } | 30 | } |
@@ -32,9 +33,9 @@ static int __init tp_sample_trace_init(void) | |||
32 | { | 33 | { |
33 | int ret; | 34 | int ret; |
34 | 35 | ||
35 | ret = register_trace_subsys_event(probe_subsys_event); | 36 | ret = register_trace_subsys_event(probe_subsys_event, NULL); |
36 | WARN_ON(ret); | 37 | WARN_ON(ret); |
37 | ret = register_trace_subsys_eventb(probe_subsys_eventb); | 38 | ret = register_trace_subsys_eventb(probe_subsys_eventb, NULL); |
38 | WARN_ON(ret); | 39 | WARN_ON(ret); |
39 | 40 | ||
40 | return 0; | 41 | return 0; |
@@ -44,8 +45,8 @@ module_init(tp_sample_trace_init); | |||
44 | 45 | ||
45 | static void __exit tp_sample_trace_exit(void) | 46 | static void __exit tp_sample_trace_exit(void) |
46 | { | 47 | { |
47 | unregister_trace_subsys_eventb(probe_subsys_eventb); | 48 | unregister_trace_subsys_eventb(probe_subsys_eventb, NULL); |
48 | unregister_trace_subsys_event(probe_subsys_event); | 49 | unregister_trace_subsys_event(probe_subsys_event, NULL); |
49 | tracepoint_synchronize_unregister(); | 50 | tracepoint_synchronize_unregister(); |
50 | } | 51 | } |
51 | 52 | ||
diff --git a/samples/tracepoints/tracepoint-probe-sample2.c b/samples/tracepoints/tracepoint-probe-sample2.c index be2a960573f1..9fcf990e5d4b 100644 --- a/samples/tracepoints/tracepoint-probe-sample2.c +++ b/samples/tracepoints/tracepoint-probe-sample2.c | |||
@@ -12,7 +12,8 @@ | |||
12 | * Here the caller only guarantees locking for struct file and struct inode. | 12 | * Here the caller only guarantees locking for struct file and struct inode. |
13 | * Locking must therefore be done in the probe to use the dentry. | 13 | * Locking must therefore be done in the probe to use the dentry. |
14 | */ | 14 | */ |
15 | static void probe_subsys_event(struct inode *inode, struct file *file) | 15 | static void probe_subsys_event(void *ignore, |
16 | struct inode *inode, struct file *file) | ||
16 | { | 17 | { |
17 | printk(KERN_INFO "Event is encountered with inode number %lu\n", | 18 | printk(KERN_INFO "Event is encountered with inode number %lu\n", |
18 | inode->i_ino); | 19 | inode->i_ino); |
@@ -22,7 +23,7 @@ static int __init tp_sample_trace_init(void) | |||
22 | { | 23 | { |
23 | int ret; | 24 | int ret; |
24 | 25 | ||
25 | ret = register_trace_subsys_event(probe_subsys_event); | 26 | ret = register_trace_subsys_event(probe_subsys_event, NULL); |
26 | WARN_ON(ret); | 27 | WARN_ON(ret); |
27 | 28 | ||
28 | return 0; | 29 | return 0; |
@@ -32,7 +33,7 @@ module_init(tp_sample_trace_init); | |||
32 | 33 | ||
33 | static void __exit tp_sample_trace_exit(void) | 34 | static void __exit tp_sample_trace_exit(void) |
34 | { | 35 | { |
35 | unregister_trace_subsys_event(probe_subsys_event); | 36 | unregister_trace_subsys_event(probe_subsys_event, NULL); |
36 | tracepoint_synchronize_unregister(); | 37 | tracepoint_synchronize_unregister(); |
37 | } | 38 | } |
38 | 39 | ||
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 2cab8e8c33d0..909fa766fa1c 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt | |||
@@ -43,6 +43,9 @@ OPTIONS | |||
43 | -c:: | 43 | -c:: |
44 | scale counter values | 44 | scale counter values |
45 | 45 | ||
46 | -B:: | ||
47 | print large numbers with thousands' separators according to locale | ||
48 | |||
46 | EXAMPLES | 49 | EXAMPLES |
47 | -------- | 50 | -------- |
48 | 51 | ||
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 77bcc9b130f5..08278eda31a5 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -277,7 +277,7 @@ static void hist_entry__print_hits(struct hist_entry *self) | |||
277 | printf("%*s: %Lu\n", BITS_PER_LONG / 2, "h->sum", h->sum); | 277 | printf("%*s: %Lu\n", BITS_PER_LONG / 2, "h->sum", h->sum); |
278 | } | 278 | } |
279 | 279 | ||
280 | static void annotate_sym(struct hist_entry *he) | 280 | static int hist_entry__tty_annotate(struct hist_entry *he) |
281 | { | 281 | { |
282 | struct map *map = he->ms.map; | 282 | struct map *map = he->ms.map; |
283 | struct dso *dso = map->dso; | 283 | struct dso *dso = map->dso; |
@@ -288,7 +288,7 @@ static void annotate_sym(struct hist_entry *he) | |||
288 | struct objdump_line *pos, *n; | 288 | struct objdump_line *pos, *n; |
289 | 289 | ||
290 | if (hist_entry__annotate(he, &head) < 0) | 290 | if (hist_entry__annotate(he, &head) < 0) |
291 | return; | 291 | return -1; |
292 | 292 | ||
293 | if (full_paths) | 293 | if (full_paths) |
294 | d_filename = filename; | 294 | d_filename = filename; |
@@ -317,30 +317,59 @@ static void annotate_sym(struct hist_entry *he) | |||
317 | 317 | ||
318 | if (print_line) | 318 | if (print_line) |
319 | free_source_line(he, len); | 319 | free_source_line(he, len); |
320 | |||
321 | return 0; | ||
320 | } | 322 | } |
321 | 323 | ||
322 | static void hists__find_annotations(struct hists *self) | 324 | static void hists__find_annotations(struct hists *self) |
323 | { | 325 | { |
324 | struct rb_node *nd; | 326 | struct rb_node *first = rb_first(&self->entries), *nd = first; |
327 | int key = KEY_RIGHT; | ||
325 | 328 | ||
326 | for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { | 329 | while (nd) { |
327 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); | 330 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); |
328 | struct sym_priv *priv; | 331 | struct sym_priv *priv; |
329 | 332 | ||
330 | if (he->ms.sym == NULL) | 333 | if (he->ms.sym == NULL || he->ms.map->dso->annotate_warned) |
331 | continue; | 334 | goto find_next; |
332 | 335 | ||
333 | priv = symbol__priv(he->ms.sym); | 336 | priv = symbol__priv(he->ms.sym); |
334 | if (priv->hist == NULL) | 337 | if (priv->hist == NULL) { |
338 | find_next: | ||
339 | if (key == KEY_LEFT) | ||
340 | nd = rb_prev(nd); | ||
341 | else | ||
342 | nd = rb_next(nd); | ||
335 | continue; | 343 | continue; |
344 | } | ||
336 | 345 | ||
337 | annotate_sym(he); | 346 | if (use_browser) { |
338 | /* | 347 | key = hist_entry__tui_annotate(he); |
339 | * Since we have a hist_entry per IP for the same symbol, free | 348 | if (is_exit_key(key)) |
340 | * he->ms.sym->hist to signal we already processed this symbol. | 349 | break; |
341 | */ | 350 | switch (key) { |
342 | free(priv->hist); | 351 | case KEY_RIGHT: |
343 | priv->hist = NULL; | 352 | case '\t': |
353 | nd = rb_next(nd); | ||
354 | break; | ||
355 | case KEY_LEFT: | ||
356 | if (nd == first) | ||
357 | continue; | ||
358 | nd = rb_prev(nd); | ||
359 | default: | ||
360 | break; | ||
361 | } | ||
362 | } else { | ||
363 | hist_entry__tty_annotate(he); | ||
364 | nd = rb_next(nd); | ||
365 | /* | ||
366 | * Since we have a hist_entry per IP for the same | ||
367 | * symbol, free he->ms.sym->hist to signal we already | ||
368 | * processed this symbol. | ||
369 | */ | ||
370 | free(priv->hist); | ||
371 | priv->hist = NULL; | ||
372 | } | ||
344 | } | 373 | } |
345 | } | 374 | } |
346 | 375 | ||
@@ -416,6 +445,8 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used) | |||
416 | { | 445 | { |
417 | argc = parse_options(argc, argv, options, annotate_usage, 0); | 446 | argc = parse_options(argc, argv, options, annotate_usage, 0); |
418 | 447 | ||
448 | setup_browser(); | ||
449 | |||
419 | symbol_conf.priv_size = sizeof(struct sym_priv); | 450 | symbol_conf.priv_size = sizeof(struct sym_priv); |
420 | symbol_conf.try_vmlinux_path = true; | 451 | symbol_conf.try_vmlinux_path = true; |
421 | 452 | ||
@@ -435,8 +466,6 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used) | |||
435 | sym_hist_filter = argv[0]; | 466 | sym_hist_filter = argv[0]; |
436 | } | 467 | } |
437 | 468 | ||
438 | setup_pager(); | ||
439 | |||
440 | if (field_sep && *field_sep == '.') { | 469 | if (field_sep && *field_sep == '.') { |
441 | pr_err("'.' is the only non valid --field-separator argument\n"); | 470 | pr_err("'.' is the only non valid --field-separator argument\n"); |
442 | return -1; | 471 | return -1; |
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 61c6d70732c9..e4a4da32a568 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
@@ -65,8 +65,10 @@ static int parse_probe_event(const char *str) | |||
65 | int ret; | 65 | int ret; |
66 | 66 | ||
67 | pr_debug("probe-definition(%d): %s\n", params.nevents, str); | 67 | pr_debug("probe-definition(%d): %s\n", params.nevents, str); |
68 | if (++params.nevents == MAX_PROBES) | 68 | if (++params.nevents == MAX_PROBES) { |
69 | die("Too many probes (> %d) are specified.", MAX_PROBES); | 69 | pr_err("Too many probes (> %d) were specified.", MAX_PROBES); |
70 | return -1; | ||
71 | } | ||
70 | 72 | ||
71 | /* Parse a perf-probe command into event */ | 73 | /* Parse a perf-probe command into event */ |
72 | ret = parse_perf_probe_command(str, pev); | 74 | ret = parse_perf_probe_command(str, pev); |
@@ -84,7 +86,9 @@ static int parse_probe_event_argv(int argc, const char **argv) | |||
84 | len = 0; | 86 | len = 0; |
85 | for (i = 0; i < argc; i++) | 87 | for (i = 0; i < argc; i++) |
86 | len += strlen(argv[i]) + 1; | 88 | len += strlen(argv[i]) + 1; |
87 | buf = xzalloc(len + 1); | 89 | buf = zalloc(len + 1); |
90 | if (buf == NULL) | ||
91 | return -ENOMEM; | ||
88 | len = 0; | 92 | len = 0; |
89 | for (i = 0; i < argc; i++) | 93 | for (i = 0; i < argc; i++) |
90 | len += sprintf(&buf[len], "%s ", argv[i]); | 94 | len += sprintf(&buf[len], "%s ", argv[i]); |
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index cb46c7d0ea99..9bc89050e6f8 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -25,6 +25,7 @@ | |||
25 | 25 | ||
26 | #include <unistd.h> | 26 | #include <unistd.h> |
27 | #include <sched.h> | 27 | #include <sched.h> |
28 | #include <sys/mman.h> | ||
28 | 29 | ||
29 | enum write_mode_t { | 30 | enum write_mode_t { |
30 | WRITE_FORCE, | 31 | WRITE_FORCE, |
@@ -60,13 +61,8 @@ static bool call_graph = false; | |||
60 | static bool inherit_stat = false; | 61 | static bool inherit_stat = false; |
61 | static bool no_samples = false; | 62 | static bool no_samples = false; |
62 | static bool sample_address = false; | 63 | static bool sample_address = false; |
63 | static bool multiplex = false; | ||
64 | static int multiplex_fd = -1; | ||
65 | 64 | ||
66 | static long samples = 0; | 65 | static long samples = 0; |
67 | static struct timeval last_read; | ||
68 | static struct timeval this_read; | ||
69 | |||
70 | static u64 bytes_written = 0; | 66 | static u64 bytes_written = 0; |
71 | 67 | ||
72 | static struct pollfd *event_array; | 68 | static struct pollfd *event_array; |
@@ -86,7 +82,7 @@ struct mmap_data { | |||
86 | unsigned int prev; | 82 | unsigned int prev; |
87 | }; | 83 | }; |
88 | 84 | ||
89 | static struct mmap_data *mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; | 85 | static struct mmap_data mmap_array[MAX_NR_CPUS]; |
90 | 86 | ||
91 | static unsigned long mmap_read_head(struct mmap_data *md) | 87 | static unsigned long mmap_read_head(struct mmap_data *md) |
92 | { | 88 | { |
@@ -146,8 +142,6 @@ static void mmap_read(struct mmap_data *md) | |||
146 | void *buf; | 142 | void *buf; |
147 | int diff; | 143 | int diff; |
148 | 144 | ||
149 | gettimeofday(&this_read, NULL); | ||
150 | |||
151 | /* | 145 | /* |
152 | * If we're further behind than half the buffer, there's a chance | 146 | * If we're further behind than half the buffer, there's a chance |
153 | * the writer will bite our tail and mess up the samples under us. | 147 | * the writer will bite our tail and mess up the samples under us. |
@@ -158,23 +152,13 @@ static void mmap_read(struct mmap_data *md) | |||
158 | */ | 152 | */ |
159 | diff = head - old; | 153 | diff = head - old; |
160 | if (diff < 0) { | 154 | if (diff < 0) { |
161 | struct timeval iv; | 155 | fprintf(stderr, "WARNING: failed to keep up with mmap data\n"); |
162 | unsigned long msecs; | ||
163 | |||
164 | timersub(&this_read, &last_read, &iv); | ||
165 | msecs = iv.tv_sec*1000 + iv.tv_usec/1000; | ||
166 | |||
167 | fprintf(stderr, "WARNING: failed to keep up with mmap data." | ||
168 | " Last read %lu msecs ago.\n", msecs); | ||
169 | |||
170 | /* | 156 | /* |
171 | * head points to a known good entry, start there. | 157 | * head points to a known good entry, start there. |
172 | */ | 158 | */ |
173 | old = head; | 159 | old = head; |
174 | } | 160 | } |
175 | 161 | ||
176 | last_read = this_read; | ||
177 | |||
178 | if (old != head) | 162 | if (old != head) |
179 | samples++; | 163 | samples++; |
180 | 164 | ||
@@ -380,27 +364,30 @@ try_again: | |||
380 | */ | 364 | */ |
381 | if (group && group_fd == -1) | 365 | if (group && group_fd == -1) |
382 | group_fd = fd[nr_cpu][counter][thread_index]; | 366 | group_fd = fd[nr_cpu][counter][thread_index]; |
383 | if (multiplex && multiplex_fd == -1) | ||
384 | multiplex_fd = fd[nr_cpu][counter][thread_index]; | ||
385 | 367 | ||
386 | if (multiplex && fd[nr_cpu][counter][thread_index] != multiplex_fd) { | 368 | if (counter || thread_index) { |
387 | 369 | ret = ioctl(fd[nr_cpu][counter][thread_index], | |
388 | ret = ioctl(fd[nr_cpu][counter][thread_index], PERF_EVENT_IOC_SET_OUTPUT, multiplex_fd); | 370 | PERF_EVENT_IOC_SET_OUTPUT, |
389 | assert(ret != -1); | 371 | fd[nr_cpu][0][0]); |
372 | if (ret) { | ||
373 | error("failed to set output: %d (%s)\n", errno, | ||
374 | strerror(errno)); | ||
375 | exit(-1); | ||
376 | } | ||
390 | } else { | 377 | } else { |
391 | event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index]; | 378 | mmap_array[nr_cpu].counter = counter; |
392 | event_array[nr_poll].events = POLLIN; | 379 | mmap_array[nr_cpu].prev = 0; |
393 | nr_poll++; | 380 | mmap_array[nr_cpu].mask = mmap_pages*page_size - 1; |
394 | 381 | mmap_array[nr_cpu].base = mmap(NULL, (mmap_pages+1)*page_size, | |
395 | mmap_array[nr_cpu][counter][thread_index].counter = counter; | ||
396 | mmap_array[nr_cpu][counter][thread_index].prev = 0; | ||
397 | mmap_array[nr_cpu][counter][thread_index].mask = mmap_pages*page_size - 1; | ||
398 | mmap_array[nr_cpu][counter][thread_index].base = mmap(NULL, (mmap_pages+1)*page_size, | ||
399 | PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter][thread_index], 0); | 382 | PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter][thread_index], 0); |
400 | if (mmap_array[nr_cpu][counter][thread_index].base == MAP_FAILED) { | 383 | if (mmap_array[nr_cpu].base == MAP_FAILED) { |
401 | error("failed to mmap with %d (%s)\n", errno, strerror(errno)); | 384 | error("failed to mmap with %d (%s)\n", errno, strerror(errno)); |
402 | exit(-1); | 385 | exit(-1); |
403 | } | 386 | } |
387 | |||
388 | event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index]; | ||
389 | event_array[nr_poll].events = POLLIN; | ||
390 | nr_poll++; | ||
404 | } | 391 | } |
405 | 392 | ||
406 | if (filter != NULL) { | 393 | if (filter != NULL) { |
@@ -501,16 +488,11 @@ static struct perf_event_header finished_round_event = { | |||
501 | 488 | ||
502 | static void mmap_read_all(void) | 489 | static void mmap_read_all(void) |
503 | { | 490 | { |
504 | int i, counter, thread; | 491 | int i; |
505 | 492 | ||
506 | for (i = 0; i < nr_cpu; i++) { | 493 | for (i = 0; i < nr_cpu; i++) { |
507 | for (counter = 0; counter < nr_counters; counter++) { | 494 | if (mmap_array[i].base) |
508 | for (thread = 0; thread < thread_num; thread++) { | 495 | mmap_read(&mmap_array[i]); |
509 | if (mmap_array[i][counter][thread].base) | ||
510 | mmap_read(&mmap_array[i][counter][thread]); | ||
511 | } | ||
512 | |||
513 | } | ||
514 | } | 496 | } |
515 | 497 | ||
516 | if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO)) | 498 | if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO)) |
@@ -834,8 +816,6 @@ static const struct option options[] = { | |||
834 | "Sample addresses"), | 816 | "Sample addresses"), |
835 | OPT_BOOLEAN('n', "no-samples", &no_samples, | 817 | OPT_BOOLEAN('n', "no-samples", &no_samples, |
836 | "don't sample"), | 818 | "don't sample"), |
837 | OPT_BOOLEAN('M', "multiplex", &multiplex, | ||
838 | "multiplex counter output in a single channel"), | ||
839 | OPT_END() | 819 | OPT_END() |
840 | }; | 820 | }; |
841 | 821 | ||
@@ -887,9 +867,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
887 | for (i = 0; i < MAX_NR_CPUS; i++) { | 867 | for (i = 0; i < MAX_NR_CPUS; i++) { |
888 | for (j = 0; j < MAX_COUNTERS; j++) { | 868 | for (j = 0; j < MAX_COUNTERS; j++) { |
889 | fd[i][j] = malloc(sizeof(int)*thread_num); | 869 | fd[i][j] = malloc(sizeof(int)*thread_num); |
890 | mmap_array[i][j] = zalloc( | 870 | if (!fd[i][j]) |
891 | sizeof(struct mmap_data)*thread_num); | ||
892 | if (!fd[i][j] || !mmap_array[i][j]) | ||
893 | return -ENOMEM; | 871 | return -ENOMEM; |
894 | } | 872 | } |
895 | } | 873 | } |
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 1d3c1003b43a..359205782964 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -116,7 +116,7 @@ static int perf_session__add_hist_entry(struct perf_session *self, | |||
116 | * so we don't allocated the extra space needed because the stdio | 116 | * so we don't allocated the extra space needed because the stdio |
117 | * code will not use it. | 117 | * code will not use it. |
118 | */ | 118 | */ |
119 | if (use_browser) | 119 | if (use_browser > 0) |
120 | err = hist_entry__inc_addr_samples(he, al->addr); | 120 | err = hist_entry__inc_addr_samples(he, al->addr); |
121 | out_free_syms: | 121 | out_free_syms: |
122 | free(syms); | 122 | free(syms); |
@@ -288,6 +288,38 @@ static size_t hists__fprintf_nr_sample_events(struct hists *self, | |||
288 | return ret + fprintf(fp, "\n#\n"); | 288 | return ret + fprintf(fp, "\n#\n"); |
289 | } | 289 | } |
290 | 290 | ||
291 | static int hists__tty_browse_tree(struct rb_root *tree, const char *help) | ||
292 | { | ||
293 | struct rb_node *next = rb_first(tree); | ||
294 | |||
295 | while (next) { | ||
296 | struct hists *hists = rb_entry(next, struct hists, rb_node); | ||
297 | const char *evname = NULL; | ||
298 | |||
299 | if (rb_first(&hists->entries) != rb_last(&hists->entries)) | ||
300 | evname = __event_name(hists->type, hists->config); | ||
301 | |||
302 | hists__fprintf_nr_sample_events(hists, evname, stdout); | ||
303 | hists__fprintf(hists, NULL, false, stdout); | ||
304 | fprintf(stdout, "\n\n"); | ||
305 | next = rb_next(&hists->rb_node); | ||
306 | } | ||
307 | |||
308 | if (sort_order == default_sort_order && | ||
309 | parent_pattern == default_parent_pattern) { | ||
310 | fprintf(stdout, "#\n# (%s)\n#\n", help); | ||
311 | |||
312 | if (show_threads) { | ||
313 | bool style = !strcmp(pretty_printing_style, "raw"); | ||
314 | perf_read_values_display(stdout, &show_threads_values, | ||
315 | style); | ||
316 | perf_read_values_destroy(&show_threads_values); | ||
317 | } | ||
318 | } | ||
319 | |||
320 | return 0; | ||
321 | } | ||
322 | |||
291 | static int __cmd_report(void) | 323 | static int __cmd_report(void) |
292 | { | 324 | { |
293 | int ret = -EINVAL; | 325 | int ret = -EINVAL; |
@@ -330,34 +362,14 @@ static int __cmd_report(void) | |||
330 | hists = rb_entry(next, struct hists, rb_node); | 362 | hists = rb_entry(next, struct hists, rb_node); |
331 | hists__collapse_resort(hists); | 363 | hists__collapse_resort(hists); |
332 | hists__output_resort(hists); | 364 | hists__output_resort(hists); |
333 | if (use_browser) | ||
334 | hists__browse(hists, help, input_name); | ||
335 | else { | ||
336 | const char *evname = NULL; | ||
337 | if (rb_first(&session->hists.entries) != | ||
338 | rb_last(&session->hists.entries)) | ||
339 | evname = __event_name(hists->type, hists->config); | ||
340 | |||
341 | hists__fprintf_nr_sample_events(hists, evname, stdout); | ||
342 | |||
343 | hists__fprintf(hists, NULL, false, stdout); | ||
344 | fprintf(stdout, "\n\n"); | ||
345 | } | ||
346 | |||
347 | next = rb_next(&hists->rb_node); | 365 | next = rb_next(&hists->rb_node); |
348 | } | 366 | } |
349 | 367 | ||
350 | if (!use_browser && sort_order == default_sort_order && | 368 | if (use_browser > 0) |
351 | parent_pattern == default_parent_pattern) { | 369 | hists__tui_browse_tree(&session->hists_tree, help); |
352 | fprintf(stdout, "#\n# (%s)\n#\n", help); | 370 | else |
371 | hists__tty_browse_tree(&session->hists_tree, help); | ||
353 | 372 | ||
354 | if (show_threads) { | ||
355 | bool style = !strcmp(pretty_printing_style, "raw"); | ||
356 | perf_read_values_display(stdout, &show_threads_values, | ||
357 | style); | ||
358 | perf_read_values_destroy(&show_threads_values); | ||
359 | } | ||
360 | } | ||
361 | out_delete: | 373 | out_delete: |
362 | perf_session__delete(session); | 374 | perf_session__delete(session); |
363 | return ret; | 375 | return ret; |
@@ -491,7 +503,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __used) | |||
491 | * so don't allocate extra space that won't be used in the stdio | 503 | * so don't allocate extra space that won't be used in the stdio |
492 | * implementation. | 504 | * implementation. |
493 | */ | 505 | */ |
494 | if (use_browser) | 506 | if (use_browser > 0) |
495 | symbol_conf.priv_size = sizeof(struct sym_priv); | 507 | symbol_conf.priv_size = sizeof(struct sym_priv); |
496 | 508 | ||
497 | if (symbol__init() < 0) | 509 | if (symbol__init() < 0) |
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index ff8c413b7e73..9a39ca3c3ac4 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -50,6 +50,7 @@ | |||
50 | 50 | ||
51 | #include <sys/prctl.h> | 51 | #include <sys/prctl.h> |
52 | #include <math.h> | 52 | #include <math.h> |
53 | #include <locale.h> | ||
53 | 54 | ||
54 | static struct perf_event_attr default_attrs[] = { | 55 | static struct perf_event_attr default_attrs[] = { |
55 | 56 | ||
@@ -80,6 +81,8 @@ static pid_t *all_tids = NULL; | |||
80 | static int thread_num = 0; | 81 | static int thread_num = 0; |
81 | static pid_t child_pid = -1; | 82 | static pid_t child_pid = -1; |
82 | static bool null_run = false; | 83 | static bool null_run = false; |
84 | static bool big_num = false; | ||
85 | |||
83 | 86 | ||
84 | static int *fd[MAX_NR_CPUS][MAX_COUNTERS]; | 87 | static int *fd[MAX_NR_CPUS][MAX_COUNTERS]; |
85 | 88 | ||
@@ -377,7 +380,7 @@ static void nsec_printout(int counter, double avg) | |||
377 | { | 380 | { |
378 | double msecs = avg / 1e6; | 381 | double msecs = avg / 1e6; |
379 | 382 | ||
380 | fprintf(stderr, " %14.6f %-24s", msecs, event_name(counter)); | 383 | fprintf(stderr, " %18.6f %-24s", msecs, event_name(counter)); |
381 | 384 | ||
382 | if (MATCH_EVENT(SOFTWARE, SW_TASK_CLOCK, counter)) { | 385 | if (MATCH_EVENT(SOFTWARE, SW_TASK_CLOCK, counter)) { |
383 | fprintf(stderr, " # %10.3f CPUs ", | 386 | fprintf(stderr, " # %10.3f CPUs ", |
@@ -389,7 +392,10 @@ static void abs_printout(int counter, double avg) | |||
389 | { | 392 | { |
390 | double total, ratio = 0.0; | 393 | double total, ratio = 0.0; |
391 | 394 | ||
392 | fprintf(stderr, " %14.0f %-24s", avg, event_name(counter)); | 395 | if (big_num) |
396 | fprintf(stderr, " %'18.0f %-24s", avg, event_name(counter)); | ||
397 | else | ||
398 | fprintf(stderr, " %18.0f %-24s", avg, event_name(counter)); | ||
393 | 399 | ||
394 | if (MATCH_EVENT(HARDWARE, HW_INSTRUCTIONS, counter)) { | 400 | if (MATCH_EVENT(HARDWARE, HW_INSTRUCTIONS, counter)) { |
395 | total = avg_stats(&runtime_cycles_stats); | 401 | total = avg_stats(&runtime_cycles_stats); |
@@ -426,7 +432,7 @@ static void print_counter(int counter) | |||
426 | int scaled = event_scaled[counter]; | 432 | int scaled = event_scaled[counter]; |
427 | 433 | ||
428 | if (scaled == -1) { | 434 | if (scaled == -1) { |
429 | fprintf(stderr, " %14s %-24s\n", | 435 | fprintf(stderr, " %18s %-24s\n", |
430 | "<not counted>", event_name(counter)); | 436 | "<not counted>", event_name(counter)); |
431 | return; | 437 | return; |
432 | } | 438 | } |
@@ -477,7 +483,7 @@ static void print_stat(int argc, const char **argv) | |||
477 | print_counter(counter); | 483 | print_counter(counter); |
478 | 484 | ||
479 | fprintf(stderr, "\n"); | 485 | fprintf(stderr, "\n"); |
480 | fprintf(stderr, " %14.9f seconds time elapsed", | 486 | fprintf(stderr, " %18.9f seconds time elapsed", |
481 | avg_stats(&walltime_nsecs_stats)/1e9); | 487 | avg_stats(&walltime_nsecs_stats)/1e9); |
482 | if (run_count > 1) { | 488 | if (run_count > 1) { |
483 | fprintf(stderr, " ( +- %7.3f%% )", | 489 | fprintf(stderr, " ( +- %7.3f%% )", |
@@ -534,6 +540,8 @@ static const struct option options[] = { | |||
534 | "repeat command and print average + stddev (max: 100)"), | 540 | "repeat command and print average + stddev (max: 100)"), |
535 | OPT_BOOLEAN('n', "null", &null_run, | 541 | OPT_BOOLEAN('n', "null", &null_run, |
536 | "null run - dont start any counters"), | 542 | "null run - dont start any counters"), |
543 | OPT_BOOLEAN('B', "big-num", &big_num, | ||
544 | "print large numbers with thousands\' separators"), | ||
537 | OPT_END() | 545 | OPT_END() |
538 | }; | 546 | }; |
539 | 547 | ||
@@ -542,6 +550,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) | |||
542 | int status; | 550 | int status; |
543 | int i,j; | 551 | int i,j; |
544 | 552 | ||
553 | setlocale(LC_ALL, ""); | ||
554 | |||
545 | argc = parse_options(argc, argv, options, stat_usage, | 555 | argc = parse_options(argc, argv, options, stat_usage, |
546 | PARSE_OPT_STOP_AT_NON_OPTION); | 556 | PARSE_OPT_STOP_AT_NON_OPTION); |
547 | if (!argc && target_pid == -1 && target_tid == -1) | 557 | if (!argc && target_pid == -1 && target_tid == -1) |
diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 08e0e5d2b50e..6e4871191138 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c | |||
@@ -15,15 +15,15 @@ | |||
15 | #include "util/parse-events.h" | 15 | #include "util/parse-events.h" |
16 | #include "util/debugfs.h" | 16 | #include "util/debugfs.h" |
17 | 17 | ||
18 | bool use_browser; | ||
19 | |||
20 | const char perf_usage_string[] = | 18 | const char perf_usage_string[] = |
21 | "perf [--version] [--help] COMMAND [ARGS]"; | 19 | "perf [--version] [--help] COMMAND [ARGS]"; |
22 | 20 | ||
23 | const char perf_more_info_string[] = | 21 | const char perf_more_info_string[] = |
24 | "See 'perf help COMMAND' for more information on a specific command."; | 22 | "See 'perf help COMMAND' for more information on a specific command."; |
25 | 23 | ||
24 | int use_browser = -1; | ||
26 | static int use_pager = -1; | 25 | static int use_pager = -1; |
26 | |||
27 | struct pager_config { | 27 | struct pager_config { |
28 | const char *cmd; | 28 | const char *cmd; |
29 | int val; | 29 | int val; |
@@ -49,6 +49,24 @@ int check_pager_config(const char *cmd) | |||
49 | return c.val; | 49 | return c.val; |
50 | } | 50 | } |
51 | 51 | ||
52 | static int tui_command_config(const char *var, const char *value, void *data) | ||
53 | { | ||
54 | struct pager_config *c = data; | ||
55 | if (!prefixcmp(var, "tui.") && !strcmp(var + 4, c->cmd)) | ||
56 | c->val = perf_config_bool(var, value); | ||
57 | return 0; | ||
58 | } | ||
59 | |||
60 | /* returns 0 for "no tui", 1 for "use tui", and -1 for "not specified" */ | ||
61 | static int check_tui_config(const char *cmd) | ||
62 | { | ||
63 | struct pager_config c; | ||
64 | c.cmd = cmd; | ||
65 | c.val = -1; | ||
66 | perf_config(tui_command_config, &c); | ||
67 | return c.val; | ||
68 | } | ||
69 | |||
52 | static void commit_pager_choice(void) | 70 | static void commit_pager_choice(void) |
53 | { | 71 | { |
54 | switch (use_pager) { | 72 | switch (use_pager) { |
@@ -255,6 +273,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) | |||
255 | if (p->option & RUN_SETUP) | 273 | if (p->option & RUN_SETUP) |
256 | prefix = NULL; /* setup_perf_directory(); */ | 274 | prefix = NULL; /* setup_perf_directory(); */ |
257 | 275 | ||
276 | if (use_browser == -1) | ||
277 | use_browser = check_tui_config(p->cmd); | ||
278 | |||
258 | if (use_pager == -1 && p->option & RUN_SETUP) | 279 | if (use_pager == -1 && p->option & RUN_SETUP) |
259 | use_pager = check_pager_config(p->cmd); | 280 | use_pager = check_pager_config(p->cmd); |
260 | if (use_pager == -1 && p->option & USE_PAGER) | 281 | if (use_pager == -1 && p->option & USE_PAGER) |
diff --git a/tools/perf/util/abspath.c b/tools/perf/util/abspath.c index a791dd467261..0e76affe9c36 100644 --- a/tools/perf/util/abspath.c +++ b/tools/perf/util/abspath.c | |||
@@ -1,86 +1,5 @@ | |||
1 | #include "cache.h" | 1 | #include "cache.h" |
2 | 2 | ||
3 | /* | ||
4 | * Do not use this for inspecting *tracked* content. When path is a | ||
5 | * symlink to a directory, we do not want to say it is a directory when | ||
6 | * dealing with tracked content in the working tree. | ||
7 | */ | ||
8 | static int is_directory(const char *path) | ||
9 | { | ||
10 | struct stat st; | ||
11 | return (!stat(path, &st) && S_ISDIR(st.st_mode)); | ||
12 | } | ||
13 | |||
14 | /* We allow "recursive" symbolic links. Only within reason, though. */ | ||
15 | #define MAXDEPTH 5 | ||
16 | |||
17 | const char *make_absolute_path(const char *path) | ||
18 | { | ||
19 | static char bufs[2][PATH_MAX + 1], *buf = bufs[0], *next_buf = bufs[1]; | ||
20 | char cwd[1024] = ""; | ||
21 | int buf_index = 1, len; | ||
22 | |||
23 | int depth = MAXDEPTH; | ||
24 | char *last_elem = NULL; | ||
25 | struct stat st; | ||
26 | |||
27 | if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX) | ||
28 | die ("Too long path: %.*s", 60, path); | ||
29 | |||
30 | while (depth--) { | ||
31 | if (!is_directory(buf)) { | ||
32 | char *last_slash = strrchr(buf, '/'); | ||
33 | if (last_slash) { | ||
34 | *last_slash = '\0'; | ||
35 | last_elem = xstrdup(last_slash + 1); | ||
36 | } else { | ||
37 | last_elem = xstrdup(buf); | ||
38 | *buf = '\0'; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | if (*buf) { | ||
43 | if (!*cwd && !getcwd(cwd, sizeof(cwd))) | ||
44 | die ("Could not get current working directory"); | ||
45 | |||
46 | if (chdir(buf)) | ||
47 | die ("Could not switch to '%s'", buf); | ||
48 | } | ||
49 | if (!getcwd(buf, PATH_MAX)) | ||
50 | die ("Could not get current working directory"); | ||
51 | |||
52 | if (last_elem) { | ||
53 | len = strlen(buf); | ||
54 | |||
55 | if (len + strlen(last_elem) + 2 > PATH_MAX) | ||
56 | die ("Too long path name: '%s/%s'", | ||
57 | buf, last_elem); | ||
58 | buf[len] = '/'; | ||
59 | strcpy(buf + len + 1, last_elem); | ||
60 | free(last_elem); | ||
61 | last_elem = NULL; | ||
62 | } | ||
63 | |||
64 | if (!lstat(buf, &st) && S_ISLNK(st.st_mode)) { | ||
65 | len = readlink(buf, next_buf, PATH_MAX); | ||
66 | if (len < 0) | ||
67 | die ("Invalid symlink: %s", buf); | ||
68 | if (PATH_MAX <= len) | ||
69 | die("symbolic link too long: %s", buf); | ||
70 | next_buf[len] = '\0'; | ||
71 | buf = next_buf; | ||
72 | buf_index = 1 - buf_index; | ||
73 | next_buf = bufs[buf_index]; | ||
74 | } else | ||
75 | break; | ||
76 | } | ||
77 | |||
78 | if (*cwd && chdir(cwd)) | ||
79 | die ("Could not change back to '%s'", cwd); | ||
80 | |||
81 | return buf; | ||
82 | } | ||
83 | |||
84 | static const char *get_pwd_cwd(void) | 3 | static const char *get_pwd_cwd(void) |
85 | { | 4 | { |
86 | static char cwd[PATH_MAX + 1]; | 5 | static char cwd[PATH_MAX + 1]; |
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 0f60a3906808..70c5cf87d020 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c | |||
@@ -6,6 +6,8 @@ | |||
6 | * Copyright (C) 2009, 2010 Red Hat Inc. | 6 | * Copyright (C) 2009, 2010 Red Hat Inc. |
7 | * Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo <acme@redhat.com> | 7 | * Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo <acme@redhat.com> |
8 | */ | 8 | */ |
9 | #include "util.h" | ||
10 | #include <stdio.h> | ||
9 | #include "build-id.h" | 11 | #include "build-id.h" |
10 | #include "event.h" | 12 | #include "event.h" |
11 | #include "symbol.h" | 13 | #include "symbol.h" |
@@ -37,3 +39,23 @@ struct perf_event_ops build_id__mark_dso_hit_ops = { | |||
37 | .mmap = event__process_mmap, | 39 | .mmap = event__process_mmap, |
38 | .fork = event__process_task, | 40 | .fork = event__process_task, |
39 | }; | 41 | }; |
42 | |||
43 | char *dso__build_id_filename(struct dso *self, char *bf, size_t size) | ||
44 | { | ||
45 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; | ||
46 | const char *home; | ||
47 | |||
48 | if (!self->has_build_id) | ||
49 | return NULL; | ||
50 | |||
51 | build_id__sprintf(self->build_id, sizeof(self->build_id), build_id_hex); | ||
52 | home = getenv("HOME"); | ||
53 | if (bf == NULL) { | ||
54 | if (asprintf(&bf, "%s/%s/.build-id/%.2s/%s", home, | ||
55 | DEBUG_CACHE_DIR, build_id_hex, build_id_hex + 2) < 0) | ||
56 | return NULL; | ||
57 | } else | ||
58 | snprintf(bf, size, "%s/%s/.build-id/%.2s/%s", home, | ||
59 | DEBUG_CACHE_DIR, build_id_hex, build_id_hex + 2); | ||
60 | return bf; | ||
61 | } | ||
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h index 1d981d63cf9a..5dafb00eaa06 100644 --- a/tools/perf/util/build-id.h +++ b/tools/perf/util/build-id.h | |||
@@ -5,4 +5,6 @@ | |||
5 | 5 | ||
6 | extern struct perf_event_ops build_id__mark_dso_hit_ops; | 6 | extern struct perf_event_ops build_id__mark_dso_hit_ops; |
7 | 7 | ||
8 | char *dso__build_id_filename(struct dso *self, char *bf, size_t size); | ||
9 | |||
8 | #endif | 10 | #endif |
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h index 4b9aab7f0405..65fe664fddf6 100644 --- a/tools/perf/util/cache.h +++ b/tools/perf/util/cache.h | |||
@@ -13,56 +13,16 @@ | |||
13 | 13 | ||
14 | #define PERF_DIR_ENVIRONMENT "PERF_DIR" | 14 | #define PERF_DIR_ENVIRONMENT "PERF_DIR" |
15 | #define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE" | 15 | #define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE" |
16 | #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf" | ||
17 | #define DB_ENVIRONMENT "PERF_OBJECT_DIRECTORY" | ||
18 | #define INDEX_ENVIRONMENT "PERF_INDEX_FILE" | ||
19 | #define GRAFT_ENVIRONMENT "PERF_GRAFT_FILE" | ||
20 | #define TEMPLATE_DIR_ENVIRONMENT "PERF_TEMPLATE_DIR" | ||
21 | #define CONFIG_ENVIRONMENT "PERF_CONFIG" | ||
22 | #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH" | 16 | #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH" |
23 | #define CEILING_DIRECTORIES_ENVIRONMENT "PERF_CEILING_DIRECTORIES" | 17 | #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf" |
24 | #define PERFATTRIBUTES_FILE ".perfattributes" | ||
25 | #define INFOATTRIBUTES_FILE "info/attributes" | ||
26 | #define ATTRIBUTE_MACRO_PREFIX "[attr]" | ||
27 | #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" | 18 | #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" |
28 | 19 | ||
29 | typedef int (*config_fn_t)(const char *, const char *, void *); | 20 | typedef int (*config_fn_t)(const char *, const char *, void *); |
30 | extern int perf_default_config(const char *, const char *, void *); | 21 | extern int perf_default_config(const char *, const char *, void *); |
31 | extern int perf_config_from_file(config_fn_t fn, const char *, void *); | ||
32 | extern int perf_config(config_fn_t fn, void *); | 22 | extern int perf_config(config_fn_t fn, void *); |
33 | extern int perf_parse_ulong(const char *, unsigned long *); | ||
34 | extern int perf_config_int(const char *, const char *); | 23 | extern int perf_config_int(const char *, const char *); |
35 | extern unsigned long perf_config_ulong(const char *, const char *); | ||
36 | extern int perf_config_bool_or_int(const char *, const char *, int *); | ||
37 | extern int perf_config_bool(const char *, const char *); | 24 | extern int perf_config_bool(const char *, const char *); |
38 | extern int perf_config_string(const char **, const char *, const char *); | ||
39 | extern int perf_config_set(const char *, const char *); | ||
40 | extern int perf_config_set_multivar(const char *, const char *, const char *, int); | ||
41 | extern int perf_config_rename_section(const char *, const char *); | ||
42 | extern const char *perf_etc_perfconfig(void); | ||
43 | extern int check_repository_format_version(const char *var, const char *value, void *cb); | ||
44 | extern int perf_config_system(void); | ||
45 | extern int perf_config_global(void); | ||
46 | extern int config_error_nonbool(const char *); | 25 | extern int config_error_nonbool(const char *); |
47 | extern const char *config_exclusive_filename; | ||
48 | |||
49 | #define MAX_PERFNAME (1000) | ||
50 | extern char perf_default_email[MAX_PERFNAME]; | ||
51 | extern char perf_default_name[MAX_PERFNAME]; | ||
52 | extern int user_ident_explicitly_given; | ||
53 | |||
54 | extern const char *perf_log_output_encoding; | ||
55 | extern const char *perf_mailmap_file; | ||
56 | |||
57 | /* IO helper functions */ | ||
58 | extern void maybe_flush_or_die(FILE *, const char *); | ||
59 | extern int copy_fd(int ifd, int ofd); | ||
60 | extern int copy_file(const char *dst, const char *src, int mode); | ||
61 | extern ssize_t write_in_full(int fd, const void *buf, size_t count); | ||
62 | extern void write_or_die(int fd, const void *buf, size_t count); | ||
63 | extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg); | ||
64 | extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg); | ||
65 | extern void fsync_or_die(int fd, const char *); | ||
66 | 26 | ||
67 | /* pager.c */ | 27 | /* pager.c */ |
68 | extern void setup_pager(void); | 28 | extern void setup_pager(void); |
@@ -70,7 +30,7 @@ extern const char *pager_program; | |||
70 | extern int pager_in_use(void); | 30 | extern int pager_in_use(void); |
71 | extern int pager_use_color; | 31 | extern int pager_use_color; |
72 | 32 | ||
73 | extern bool use_browser; | 33 | extern int use_browser; |
74 | 34 | ||
75 | #ifdef NO_NEWT_SUPPORT | 35 | #ifdef NO_NEWT_SUPPORT |
76 | static inline void setup_browser(void) | 36 | static inline void setup_browser(void) |
@@ -83,9 +43,6 @@ void setup_browser(void); | |||
83 | void exit_browser(bool wait_for_ok); | 43 | void exit_browser(bool wait_for_ok); |
84 | #endif | 44 | #endif |
85 | 45 | ||
86 | extern const char *editor_program; | ||
87 | extern const char *excludes_file; | ||
88 | |||
89 | char *alias_lookup(const char *alias); | 46 | char *alias_lookup(const char *alias); |
90 | int split_cmdline(char *cmdline, const char ***argv); | 47 | int split_cmdline(char *cmdline, const char ***argv); |
91 | 48 | ||
@@ -115,22 +72,12 @@ static inline int is_absolute_path(const char *path) | |||
115 | return path[0] == '/'; | 72 | return path[0] == '/'; |
116 | } | 73 | } |
117 | 74 | ||
118 | const char *make_absolute_path(const char *path); | ||
119 | const char *make_nonrelative_path(const char *path); | 75 | const char *make_nonrelative_path(const char *path); |
120 | const char *make_relative_path(const char *abs, const char *base); | ||
121 | int normalize_path_copy(char *dst, const char *src); | ||
122 | int longest_ancestor_length(const char *path, const char *prefix_list); | ||
123 | char *strip_path_suffix(const char *path, const char *suffix); | 76 | char *strip_path_suffix(const char *path, const char *suffix); |
124 | 77 | ||
125 | extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2))); | 78 | extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2))); |
126 | extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2))); | 79 | extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2))); |
127 | /* perf_mkstemp() - create tmp file honoring TMPDIR variable */ | ||
128 | extern int perf_mkstemp(char *path, size_t len, const char *template); | ||
129 | 80 | ||
130 | extern char *mksnpath(char *buf, size_t n, const char *fmt, ...) | ||
131 | __attribute__((format (printf, 3, 4))); | ||
132 | extern char *perf_snpath(char *buf, size_t n, const char *fmt, ...) | ||
133 | __attribute__((format (printf, 3, 4))); | ||
134 | extern char *perf_pathdup(const char *fmt, ...) | 81 | extern char *perf_pathdup(const char *fmt, ...) |
135 | __attribute__((format (printf, 1, 2))); | 82 | __attribute__((format (printf, 1, 2))); |
136 | 83 | ||
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 21a52e0a4435..62b69ad4aa73 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <errno.h> | 15 | #include <errno.h> |
16 | #include <math.h> | 16 | #include <math.h> |
17 | 17 | ||
18 | #include "util.h" | ||
18 | #include "callchain.h" | 19 | #include "callchain.h" |
19 | 20 | ||
20 | bool ip_callchain__valid(struct ip_callchain *chain, event_t *event) | 21 | bool ip_callchain__valid(struct ip_callchain *chain, event_t *event) |
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 1cba1f5504e7..1ca73e4a2723 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h | |||
@@ -5,7 +5,6 @@ | |||
5 | #include <linux/list.h> | 5 | #include <linux/list.h> |
6 | #include <linux/rbtree.h> | 6 | #include <linux/rbtree.h> |
7 | #include "event.h" | 7 | #include "event.h" |
8 | #include "util.h" | ||
9 | #include "symbol.h" | 8 | #include "symbol.h" |
10 | 9 | ||
11 | enum chain_mode { | 10 | enum chain_mode { |
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 8784649109ce..dabe892d0e53 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c | |||
@@ -16,7 +16,7 @@ static const char *config_file_name; | |||
16 | static int config_linenr; | 16 | static int config_linenr; |
17 | static int config_file_eof; | 17 | static int config_file_eof; |
18 | 18 | ||
19 | const char *config_exclusive_filename = NULL; | 19 | static const char *config_exclusive_filename; |
20 | 20 | ||
21 | static int get_next_char(void) | 21 | static int get_next_char(void) |
22 | { | 22 | { |
@@ -291,19 +291,6 @@ static int perf_parse_long(const char *value, long *ret) | |||
291 | return 0; | 291 | return 0; |
292 | } | 292 | } |
293 | 293 | ||
294 | int perf_parse_ulong(const char *value, unsigned long *ret) | ||
295 | { | ||
296 | if (value && *value) { | ||
297 | char *end; | ||
298 | unsigned long val = strtoul(value, &end, 0); | ||
299 | if (!parse_unit_factor(end, &val)) | ||
300 | return 0; | ||
301 | *ret = val; | ||
302 | return 1; | ||
303 | } | ||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | static void die_bad_config(const char *name) | 294 | static void die_bad_config(const char *name) |
308 | { | 295 | { |
309 | if (config_file_name) | 296 | if (config_file_name) |
@@ -319,15 +306,7 @@ int perf_config_int(const char *name, const char *value) | |||
319 | return ret; | 306 | return ret; |
320 | } | 307 | } |
321 | 308 | ||
322 | unsigned long perf_config_ulong(const char *name, const char *value) | 309 | static int perf_config_bool_or_int(const char *name, const char *value, int *is_bool) |
323 | { | ||
324 | unsigned long ret; | ||
325 | if (!perf_parse_ulong(value, &ret)) | ||
326 | die_bad_config(name); | ||
327 | return ret; | ||
328 | } | ||
329 | |||
330 | int perf_config_bool_or_int(const char *name, const char *value, int *is_bool) | ||
331 | { | 310 | { |
332 | *is_bool = 1; | 311 | *is_bool = 1; |
333 | if (!value) | 312 | if (!value) |
@@ -348,14 +327,6 @@ int perf_config_bool(const char *name, const char *value) | |||
348 | return !!perf_config_bool_or_int(name, value, &discard); | 327 | return !!perf_config_bool_or_int(name, value, &discard); |
349 | } | 328 | } |
350 | 329 | ||
351 | int perf_config_string(const char **dest, const char *var, const char *value) | ||
352 | { | ||
353 | if (!value) | ||
354 | return config_error_nonbool(var); | ||
355 | *dest = strdup(value); | ||
356 | return 0; | ||
357 | } | ||
358 | |||
359 | static int perf_default_core_config(const char *var __used, const char *value __used) | 330 | static int perf_default_core_config(const char *var __used, const char *value __used) |
360 | { | 331 | { |
361 | /* Add other config variables here and to Documentation/config.txt. */ | 332 | /* Add other config variables here and to Documentation/config.txt. */ |
@@ -371,7 +342,7 @@ int perf_default_config(const char *var, const char *value, void *dummy __used) | |||
371 | return 0; | 342 | return 0; |
372 | } | 343 | } |
373 | 344 | ||
374 | int perf_config_from_file(config_fn_t fn, const char *filename, void *data) | 345 | static int perf_config_from_file(config_fn_t fn, const char *filename, void *data) |
375 | { | 346 | { |
376 | int ret; | 347 | int ret; |
377 | FILE *f = fopen(filename, "r"); | 348 | FILE *f = fopen(filename, "r"); |
@@ -389,7 +360,7 @@ int perf_config_from_file(config_fn_t fn, const char *filename, void *data) | |||
389 | return ret; | 360 | return ret; |
390 | } | 361 | } |
391 | 362 | ||
392 | const char *perf_etc_perfconfig(void) | 363 | static const char *perf_etc_perfconfig(void) |
393 | { | 364 | { |
394 | static const char *system_wide; | 365 | static const char *system_wide; |
395 | if (!system_wide) | 366 | if (!system_wide) |
@@ -403,12 +374,12 @@ static int perf_env_bool(const char *k, int def) | |||
403 | return v ? perf_config_bool(k, v) : def; | 374 | return v ? perf_config_bool(k, v) : def; |
404 | } | 375 | } |
405 | 376 | ||
406 | int perf_config_system(void) | 377 | static int perf_config_system(void) |
407 | { | 378 | { |
408 | return !perf_env_bool("PERF_CONFIG_NOSYSTEM", 0); | 379 | return !perf_env_bool("PERF_CONFIG_NOSYSTEM", 0); |
409 | } | 380 | } |
410 | 381 | ||
411 | int perf_config_global(void) | 382 | static int perf_config_global(void) |
412 | { | 383 | { |
413 | return !perf_env_bool("PERF_CONFIG_NOGLOBAL", 0); | 384 | return !perf_env_bool("PERF_CONFIG_NOGLOBAL", 0); |
414 | } | 385 | } |
@@ -450,426 +421,6 @@ int perf_config(config_fn_t fn, void *data) | |||
450 | } | 421 | } |
451 | 422 | ||
452 | /* | 423 | /* |
453 | * Find all the stuff for perf_config_set() below. | ||
454 | */ | ||
455 | |||
456 | #define MAX_MATCHES 512 | ||
457 | |||
458 | static struct { | ||
459 | int baselen; | ||
460 | char* key; | ||
461 | int do_not_match; | ||
462 | regex_t* value_regex; | ||
463 | int multi_replace; | ||
464 | size_t offset[MAX_MATCHES]; | ||
465 | enum { START, SECTION_SEEN, SECTION_END_SEEN, KEY_SEEN } state; | ||
466 | int seen; | ||
467 | } store; | ||
468 | |||
469 | static int matches(const char* key, const char* value) | ||
470 | { | ||
471 | return !strcmp(key, store.key) && | ||
472 | (store.value_regex == NULL || | ||
473 | (store.do_not_match ^ | ||
474 | !regexec(store.value_regex, value, 0, NULL, 0))); | ||
475 | } | ||
476 | |||
477 | static int store_aux(const char* key, const char* value, void *cb __used) | ||
478 | { | ||
479 | int section_len; | ||
480 | const char *ep; | ||
481 | |||
482 | switch (store.state) { | ||
483 | case KEY_SEEN: | ||
484 | if (matches(key, value)) { | ||
485 | if (store.seen == 1 && store.multi_replace == 0) { | ||
486 | warning("%s has multiple values", key); | ||
487 | } else if (store.seen >= MAX_MATCHES) { | ||
488 | error("too many matches for %s", key); | ||
489 | return 1; | ||
490 | } | ||
491 | |||
492 | store.offset[store.seen] = ftell(config_file); | ||
493 | store.seen++; | ||
494 | } | ||
495 | break; | ||
496 | case SECTION_SEEN: | ||
497 | /* | ||
498 | * What we are looking for is in store.key (both | ||
499 | * section and var), and its section part is baselen | ||
500 | * long. We found key (again, both section and var). | ||
501 | * We would want to know if this key is in the same | ||
502 | * section as what we are looking for. We already | ||
503 | * know we are in the same section as what should | ||
504 | * hold store.key. | ||
505 | */ | ||
506 | ep = strrchr(key, '.'); | ||
507 | section_len = ep - key; | ||
508 | |||
509 | if ((section_len != store.baselen) || | ||
510 | memcmp(key, store.key, section_len+1)) { | ||
511 | store.state = SECTION_END_SEEN; | ||
512 | break; | ||
513 | } | ||
514 | |||
515 | /* | ||
516 | * Do not increment matches: this is no match, but we | ||
517 | * just made sure we are in the desired section. | ||
518 | */ | ||
519 | store.offset[store.seen] = ftell(config_file); | ||
520 | /* fallthru */ | ||
521 | case SECTION_END_SEEN: | ||
522 | case START: | ||
523 | if (matches(key, value)) { | ||
524 | store.offset[store.seen] = ftell(config_file); | ||
525 | store.state = KEY_SEEN; | ||
526 | store.seen++; | ||
527 | } else { | ||
528 | if (strrchr(key, '.') - key == store.baselen && | ||
529 | !strncmp(key, store.key, store.baselen)) { | ||
530 | store.state = SECTION_SEEN; | ||
531 | store.offset[store.seen] = ftell(config_file); | ||
532 | } | ||
533 | } | ||
534 | default: | ||
535 | break; | ||
536 | } | ||
537 | return 0; | ||
538 | } | ||
539 | |||
540 | static int store_write_section(int fd, const char* key) | ||
541 | { | ||
542 | const char *dot; | ||
543 | int i, success; | ||
544 | struct strbuf sb = STRBUF_INIT; | ||
545 | |||
546 | dot = memchr(key, '.', store.baselen); | ||
547 | if (dot) { | ||
548 | strbuf_addf(&sb, "[%.*s \"", (int)(dot - key), key); | ||
549 | for (i = dot - key + 1; i < store.baselen; i++) { | ||
550 | if (key[i] == '"' || key[i] == '\\') | ||
551 | strbuf_addch(&sb, '\\'); | ||
552 | strbuf_addch(&sb, key[i]); | ||
553 | } | ||
554 | strbuf_addstr(&sb, "\"]\n"); | ||
555 | } else { | ||
556 | strbuf_addf(&sb, "[%.*s]\n", store.baselen, key); | ||
557 | } | ||
558 | |||
559 | success = (write_in_full(fd, sb.buf, sb.len) == (ssize_t)sb.len); | ||
560 | strbuf_release(&sb); | ||
561 | |||
562 | return success; | ||
563 | } | ||
564 | |||
565 | static int store_write_pair(int fd, const char* key, const char* value) | ||
566 | { | ||
567 | int i, success; | ||
568 | int length = strlen(key + store.baselen + 1); | ||
569 | const char *quote = ""; | ||
570 | struct strbuf sb = STRBUF_INIT; | ||
571 | |||
572 | /* | ||
573 | * Check to see if the value needs to be surrounded with a dq pair. | ||
574 | * Note that problematic characters are always backslash-quoted; this | ||
575 | * check is about not losing leading or trailing SP and strings that | ||
576 | * follow beginning-of-comment characters (i.e. ';' and '#') by the | ||
577 | * configuration parser. | ||
578 | */ | ||
579 | if (value[0] == ' ') | ||
580 | quote = "\""; | ||
581 | for (i = 0; value[i]; i++) | ||
582 | if (value[i] == ';' || value[i] == '#') | ||
583 | quote = "\""; | ||
584 | if (i && value[i - 1] == ' ') | ||
585 | quote = "\""; | ||
586 | |||
587 | strbuf_addf(&sb, "\t%.*s = %s", | ||
588 | length, key + store.baselen + 1, quote); | ||
589 | |||
590 | for (i = 0; value[i]; i++) | ||
591 | switch (value[i]) { | ||
592 | case '\n': | ||
593 | strbuf_addstr(&sb, "\\n"); | ||
594 | break; | ||
595 | case '\t': | ||
596 | strbuf_addstr(&sb, "\\t"); | ||
597 | break; | ||
598 | case '"': | ||
599 | case '\\': | ||
600 | strbuf_addch(&sb, '\\'); | ||
601 | default: | ||
602 | strbuf_addch(&sb, value[i]); | ||
603 | break; | ||
604 | } | ||
605 | strbuf_addf(&sb, "%s\n", quote); | ||
606 | |||
607 | success = (write_in_full(fd, sb.buf, sb.len) == (ssize_t)sb.len); | ||
608 | strbuf_release(&sb); | ||
609 | |||
610 | return success; | ||
611 | } | ||
612 | |||
613 | static ssize_t find_beginning_of_line(const char* contents, size_t size, | ||
614 | size_t offset_, int* found_bracket) | ||
615 | { | ||
616 | size_t equal_offset = size, bracket_offset = size; | ||
617 | ssize_t offset; | ||
618 | |||
619 | contline: | ||
620 | for (offset = offset_-2; offset > 0 | ||
621 | && contents[offset] != '\n'; offset--) | ||
622 | switch (contents[offset]) { | ||
623 | case '=': equal_offset = offset; break; | ||
624 | case ']': bracket_offset = offset; break; | ||
625 | default: break; | ||
626 | } | ||
627 | if (offset > 0 && contents[offset-1] == '\\') { | ||
628 | offset_ = offset; | ||
629 | goto contline; | ||
630 | } | ||
631 | if (bracket_offset < equal_offset) { | ||
632 | *found_bracket = 1; | ||
633 | offset = bracket_offset+1; | ||
634 | } else | ||
635 | offset++; | ||
636 | |||
637 | return offset; | ||
638 | } | ||
639 | |||
640 | int perf_config_set(const char* key, const char* value) | ||
641 | { | ||
642 | return perf_config_set_multivar(key, value, NULL, 0); | ||
643 | } | ||
644 | |||
645 | /* | ||
646 | * If value==NULL, unset in (remove from) config, | ||
647 | * if value_regex!=NULL, disregard key/value pairs where value does not match. | ||
648 | * if multi_replace==0, nothing, or only one matching key/value is replaced, | ||
649 | * else all matching key/values (regardless how many) are removed, | ||
650 | * before the new pair is written. | ||
651 | * | ||
652 | * Returns 0 on success. | ||
653 | * | ||
654 | * This function does this: | ||
655 | * | ||
656 | * - it locks the config file by creating ".perf/config.lock" | ||
657 | * | ||
658 | * - it then parses the config using store_aux() as validator to find | ||
659 | * the position on the key/value pair to replace. If it is to be unset, | ||
660 | * it must be found exactly once. | ||
661 | * | ||
662 | * - the config file is mmap()ed and the part before the match (if any) is | ||
663 | * written to the lock file, then the changed part and the rest. | ||
664 | * | ||
665 | * - the config file is removed and the lock file rename()d to it. | ||
666 | * | ||
667 | */ | ||
668 | int perf_config_set_multivar(const char* key, const char* value, | ||
669 | const char* value_regex, int multi_replace) | ||
670 | { | ||
671 | int i, dot; | ||
672 | int fd = -1, in_fd; | ||
673 | int ret = 0; | ||
674 | char* config_filename; | ||
675 | const char* last_dot = strrchr(key, '.'); | ||
676 | |||
677 | if (config_exclusive_filename) | ||
678 | config_filename = strdup(config_exclusive_filename); | ||
679 | else | ||
680 | config_filename = perf_pathdup("config"); | ||
681 | |||
682 | /* | ||
683 | * Since "key" actually contains the section name and the real | ||
684 | * key name separated by a dot, we have to know where the dot is. | ||
685 | */ | ||
686 | |||
687 | if (last_dot == NULL) { | ||
688 | error("key does not contain a section: %s", key); | ||
689 | ret = 2; | ||
690 | goto out_free; | ||
691 | } | ||
692 | store.baselen = last_dot - key; | ||
693 | |||
694 | store.multi_replace = multi_replace; | ||
695 | |||
696 | /* | ||
697 | * Validate the key and while at it, lower case it for matching. | ||
698 | */ | ||
699 | store.key = malloc(strlen(key) + 1); | ||
700 | dot = 0; | ||
701 | for (i = 0; key[i]; i++) { | ||
702 | unsigned char c = key[i]; | ||
703 | if (c == '.') | ||
704 | dot = 1; | ||
705 | /* Leave the extended basename untouched.. */ | ||
706 | if (!dot || i > store.baselen) { | ||
707 | if (!iskeychar(c) || (i == store.baselen+1 && !isalpha(c))) { | ||
708 | error("invalid key: %s", key); | ||
709 | free(store.key); | ||
710 | ret = 1; | ||
711 | goto out_free; | ||
712 | } | ||
713 | c = tolower(c); | ||
714 | } else if (c == '\n') { | ||
715 | error("invalid key (newline): %s", key); | ||
716 | free(store.key); | ||
717 | ret = 1; | ||
718 | goto out_free; | ||
719 | } | ||
720 | store.key[i] = c; | ||
721 | } | ||
722 | store.key[i] = 0; | ||
723 | |||
724 | /* | ||
725 | * If .perf/config does not exist yet, write a minimal version. | ||
726 | */ | ||
727 | in_fd = open(config_filename, O_RDONLY); | ||
728 | if ( in_fd < 0 ) { | ||
729 | free(store.key); | ||
730 | |||
731 | if ( ENOENT != errno ) { | ||
732 | error("opening %s: %s", config_filename, | ||
733 | strerror(errno)); | ||
734 | ret = 3; /* same as "invalid config file" */ | ||
735 | goto out_free; | ||
736 | } | ||
737 | /* if nothing to unset, error out */ | ||
738 | if (value == NULL) { | ||
739 | ret = 5; | ||
740 | goto out_free; | ||
741 | } | ||
742 | |||
743 | store.key = (char*)key; | ||
744 | if (!store_write_section(fd, key) || | ||
745 | !store_write_pair(fd, key, value)) | ||
746 | goto write_err_out; | ||
747 | } else { | ||
748 | struct stat st; | ||
749 | char *contents; | ||
750 | ssize_t contents_sz, copy_begin, copy_end; | ||
751 | int new_line = 0; | ||
752 | |||
753 | if (value_regex == NULL) | ||
754 | store.value_regex = NULL; | ||
755 | else { | ||
756 | if (value_regex[0] == '!') { | ||
757 | store.do_not_match = 1; | ||
758 | value_regex++; | ||
759 | } else | ||
760 | store.do_not_match = 0; | ||
761 | |||
762 | store.value_regex = (regex_t*)malloc(sizeof(regex_t)); | ||
763 | if (regcomp(store.value_regex, value_regex, | ||
764 | REG_EXTENDED)) { | ||
765 | error("invalid pattern: %s", value_regex); | ||
766 | free(store.value_regex); | ||
767 | ret = 6; | ||
768 | goto out_free; | ||
769 | } | ||
770 | } | ||
771 | |||
772 | store.offset[0] = 0; | ||
773 | store.state = START; | ||
774 | store.seen = 0; | ||
775 | |||
776 | /* | ||
777 | * After this, store.offset will contain the *end* offset | ||
778 | * of the last match, or remain at 0 if no match was found. | ||
779 | * As a side effect, we make sure to transform only a valid | ||
780 | * existing config file. | ||
781 | */ | ||
782 | if (perf_config_from_file(store_aux, config_filename, NULL)) { | ||
783 | error("invalid config file %s", config_filename); | ||
784 | free(store.key); | ||
785 | if (store.value_regex != NULL) { | ||
786 | regfree(store.value_regex); | ||
787 | free(store.value_regex); | ||
788 | } | ||
789 | ret = 3; | ||
790 | goto out_free; | ||
791 | } | ||
792 | |||
793 | free(store.key); | ||
794 | if (store.value_regex != NULL) { | ||
795 | regfree(store.value_regex); | ||
796 | free(store.value_regex); | ||
797 | } | ||
798 | |||
799 | /* if nothing to unset, or too many matches, error out */ | ||
800 | if ((store.seen == 0 && value == NULL) || | ||
801 | (store.seen > 1 && multi_replace == 0)) { | ||
802 | ret = 5; | ||
803 | goto out_free; | ||
804 | } | ||
805 | |||
806 | fstat(in_fd, &st); | ||
807 | contents_sz = xsize_t(st.st_size); | ||
808 | contents = mmap(NULL, contents_sz, PROT_READ, | ||
809 | MAP_PRIVATE, in_fd, 0); | ||
810 | close(in_fd); | ||
811 | |||
812 | if (store.seen == 0) | ||
813 | store.seen = 1; | ||
814 | |||
815 | for (i = 0, copy_begin = 0; i < store.seen; i++) { | ||
816 | if (store.offset[i] == 0) { | ||
817 | store.offset[i] = copy_end = contents_sz; | ||
818 | } else if (store.state != KEY_SEEN) { | ||
819 | copy_end = store.offset[i]; | ||
820 | } else | ||
821 | copy_end = find_beginning_of_line( | ||
822 | contents, contents_sz, | ||
823 | store.offset[i]-2, &new_line); | ||
824 | |||
825 | if (copy_end > 0 && contents[copy_end-1] != '\n') | ||
826 | new_line = 1; | ||
827 | |||
828 | /* write the first part of the config */ | ||
829 | if (copy_end > copy_begin) { | ||
830 | if (write_in_full(fd, contents + copy_begin, | ||
831 | copy_end - copy_begin) < | ||
832 | copy_end - copy_begin) | ||
833 | goto write_err_out; | ||
834 | if (new_line && | ||
835 | write_in_full(fd, "\n", 1) != 1) | ||
836 | goto write_err_out; | ||
837 | } | ||
838 | copy_begin = store.offset[i]; | ||
839 | } | ||
840 | |||
841 | /* write the pair (value == NULL means unset) */ | ||
842 | if (value != NULL) { | ||
843 | if (store.state == START) { | ||
844 | if (!store_write_section(fd, key)) | ||
845 | goto write_err_out; | ||
846 | } | ||
847 | if (!store_write_pair(fd, key, value)) | ||
848 | goto write_err_out; | ||
849 | } | ||
850 | |||
851 | /* write the rest of the config */ | ||
852 | if (copy_begin < contents_sz) | ||
853 | if (write_in_full(fd, contents + copy_begin, | ||
854 | contents_sz - copy_begin) < | ||
855 | contents_sz - copy_begin) | ||
856 | goto write_err_out; | ||
857 | |||
858 | munmap(contents, contents_sz); | ||
859 | } | ||
860 | |||
861 | ret = 0; | ||
862 | |||
863 | out_free: | ||
864 | free(config_filename); | ||
865 | return ret; | ||
866 | |||
867 | write_err_out: | ||
868 | goto out_free; | ||
869 | |||
870 | } | ||
871 | |||
872 | /* | ||
873 | * Call this to report error for your variable that should not | 424 | * Call this to report error for your variable that should not |
874 | * get a boolean value (i.e. "[my] var" means "true"). | 425 | * get a boolean value (i.e. "[my] var" means "true"). |
875 | */ | 426 | */ |
diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c index 2745605dba11..67eeff571568 100644 --- a/tools/perf/util/exec_cmd.c +++ b/tools/perf/util/exec_cmd.c | |||
@@ -53,8 +53,8 @@ const char *perf_extract_argv0_path(const char *argv0) | |||
53 | slash--; | 53 | slash--; |
54 | 54 | ||
55 | if (slash >= argv0) { | 55 | if (slash >= argv0) { |
56 | argv0_path = xstrndup(argv0, slash - argv0); | 56 | argv0_path = strndup(argv0, slash - argv0); |
57 | return slash + 1; | 57 | return argv0_path ? slash + 1 : NULL; |
58 | } | 58 | } |
59 | 59 | ||
60 | return argv0; | 60 | return argv0; |
@@ -116,7 +116,7 @@ void setup_path(void) | |||
116 | strbuf_release(&new_path); | 116 | strbuf_release(&new_path); |
117 | } | 117 | } |
118 | 118 | ||
119 | const char **prepare_perf_cmd(const char **argv) | 119 | static const char **prepare_perf_cmd(const char **argv) |
120 | { | 120 | { |
121 | int argc; | 121 | int argc; |
122 | const char **nargv; | 122 | const char **nargv; |
diff --git a/tools/perf/util/exec_cmd.h b/tools/perf/util/exec_cmd.h index 31647ac92ed1..bc4b915963f5 100644 --- a/tools/perf/util/exec_cmd.h +++ b/tools/perf/util/exec_cmd.h | |||
@@ -5,7 +5,6 @@ extern void perf_set_argv_exec_path(const char *exec_path); | |||
5 | extern const char *perf_extract_argv0_path(const char *path); | 5 | extern const char *perf_extract_argv0_path(const char *path); |
6 | extern const char *perf_exec_path(void); | 6 | extern const char *perf_exec_path(void); |
7 | extern void setup_path(void); | 7 | extern void setup_path(void); |
8 | extern const char **prepare_perf_cmd(const char **argv); | ||
9 | extern int execv_perf_cmd(const char **argv); /* NULL terminated */ | 8 | extern int execv_perf_cmd(const char **argv); /* NULL terminated */ |
10 | extern int execl_perf_cmd(const char *cmd, ...); | 9 | extern int execl_perf_cmd(const char *cmd, ...); |
11 | extern const char *system_path(const char *path); | 10 | extern const char *system_path(const char *path); |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 8847bec64c54..1f62435f96c2 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -221,29 +221,38 @@ static int __dsos__write_buildid_table(struct list_head *head, pid_t pid, | |||
221 | return 0; | 221 | return 0; |
222 | } | 222 | } |
223 | 223 | ||
224 | static int machine__write_buildid_table(struct machine *self, int fd) | ||
225 | { | ||
226 | int err; | ||
227 | u16 kmisc = PERF_RECORD_MISC_KERNEL, | ||
228 | umisc = PERF_RECORD_MISC_USER; | ||
229 | |||
230 | if (!machine__is_host(self)) { | ||
231 | kmisc = PERF_RECORD_MISC_GUEST_KERNEL; | ||
232 | umisc = PERF_RECORD_MISC_GUEST_USER; | ||
233 | } | ||
234 | |||
235 | err = __dsos__write_buildid_table(&self->kernel_dsos, self->pid, | ||
236 | kmisc, fd); | ||
237 | if (err == 0) | ||
238 | err = __dsos__write_buildid_table(&self->user_dsos, | ||
239 | self->pid, umisc, fd); | ||
240 | return err; | ||
241 | } | ||
242 | |||
224 | static int dsos__write_buildid_table(struct perf_header *header, int fd) | 243 | static int dsos__write_buildid_table(struct perf_header *header, int fd) |
225 | { | 244 | { |
226 | struct perf_session *session = container_of(header, | 245 | struct perf_session *session = container_of(header, |
227 | struct perf_session, header); | 246 | struct perf_session, header); |
228 | struct rb_node *nd; | 247 | struct rb_node *nd; |
229 | int err = 0; | 248 | int err = machine__write_buildid_table(&session->host_machine, fd); |
230 | u16 kmisc, umisc; | 249 | |
250 | if (err) | ||
251 | return err; | ||
231 | 252 | ||
232 | for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { | 253 | for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { |
233 | struct machine *pos = rb_entry(nd, struct machine, rb_node); | 254 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
234 | if (machine__is_host(pos)) { | 255 | err = machine__write_buildid_table(pos, fd); |
235 | kmisc = PERF_RECORD_MISC_KERNEL; | ||
236 | umisc = PERF_RECORD_MISC_USER; | ||
237 | } else { | ||
238 | kmisc = PERF_RECORD_MISC_GUEST_KERNEL; | ||
239 | umisc = PERF_RECORD_MISC_GUEST_USER; | ||
240 | } | ||
241 | |||
242 | err = __dsos__write_buildid_table(&pos->kernel_dsos, pos->pid, | ||
243 | kmisc, fd); | ||
244 | if (err == 0) | ||
245 | err = __dsos__write_buildid_table(&pos->user_dsos, | ||
246 | pos->pid, umisc, fd); | ||
247 | if (err) | 256 | if (err) |
248 | break; | 257 | break; |
249 | } | 258 | } |
@@ -363,12 +372,17 @@ static int __dsos__cache_build_ids(struct list_head *head, const char *debugdir) | |||
363 | return err; | 372 | return err; |
364 | } | 373 | } |
365 | 374 | ||
366 | static int dsos__cache_build_ids(struct perf_header *self) | 375 | static int machine__cache_build_ids(struct machine *self, const char *debugdir) |
376 | { | ||
377 | int ret = __dsos__cache_build_ids(&self->kernel_dsos, debugdir); | ||
378 | ret |= __dsos__cache_build_ids(&self->user_dsos, debugdir); | ||
379 | return ret; | ||
380 | } | ||
381 | |||
382 | static int perf_session__cache_build_ids(struct perf_session *self) | ||
367 | { | 383 | { |
368 | struct perf_session *session = container_of(self, | ||
369 | struct perf_session, header); | ||
370 | struct rb_node *nd; | 384 | struct rb_node *nd; |
371 | int ret = 0; | 385 | int ret; |
372 | char debugdir[PATH_MAX]; | 386 | char debugdir[PATH_MAX]; |
373 | 387 | ||
374 | snprintf(debugdir, sizeof(debugdir), "%s/%s", getenv("HOME"), | 388 | snprintf(debugdir, sizeof(debugdir), "%s/%s", getenv("HOME"), |
@@ -377,25 +391,30 @@ static int dsos__cache_build_ids(struct perf_header *self) | |||
377 | if (mkdir(debugdir, 0755) != 0 && errno != EEXIST) | 391 | if (mkdir(debugdir, 0755) != 0 && errno != EEXIST) |
378 | return -1; | 392 | return -1; |
379 | 393 | ||
380 | for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { | 394 | ret = machine__cache_build_ids(&self->host_machine, debugdir); |
395 | |||
396 | for (nd = rb_first(&self->machines); nd; nd = rb_next(nd)) { | ||
381 | struct machine *pos = rb_entry(nd, struct machine, rb_node); | 397 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
382 | ret |= __dsos__cache_build_ids(&pos->kernel_dsos, debugdir); | 398 | ret |= machine__cache_build_ids(pos, debugdir); |
383 | ret |= __dsos__cache_build_ids(&pos->user_dsos, debugdir); | ||
384 | } | 399 | } |
385 | return ret ? -1 : 0; | 400 | return ret ? -1 : 0; |
386 | } | 401 | } |
387 | 402 | ||
388 | static bool dsos__read_build_ids(struct perf_header *self, bool with_hits) | 403 | static bool machine__read_build_ids(struct machine *self, bool with_hits) |
404 | { | ||
405 | bool ret = __dsos__read_build_ids(&self->kernel_dsos, with_hits); | ||
406 | ret |= __dsos__read_build_ids(&self->user_dsos, with_hits); | ||
407 | return ret; | ||
408 | } | ||
409 | |||
410 | static bool perf_session__read_build_ids(struct perf_session *self, bool with_hits) | ||
389 | { | 411 | { |
390 | bool ret = false; | ||
391 | struct perf_session *session = container_of(self, | ||
392 | struct perf_session, header); | ||
393 | struct rb_node *nd; | 412 | struct rb_node *nd; |
413 | bool ret = machine__read_build_ids(&self->host_machine, with_hits); | ||
394 | 414 | ||
395 | for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { | 415 | for (nd = rb_first(&self->machines); nd; nd = rb_next(nd)) { |
396 | struct machine *pos = rb_entry(nd, struct machine, rb_node); | 416 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
397 | ret |= __dsos__read_build_ids(&pos->kernel_dsos, with_hits); | 417 | ret |= machine__read_build_ids(pos, with_hits); |
398 | ret |= __dsos__read_build_ids(&pos->user_dsos, with_hits); | ||
399 | } | 418 | } |
400 | 419 | ||
401 | return ret; | 420 | return ret; |
@@ -404,12 +423,14 @@ static bool dsos__read_build_ids(struct perf_header *self, bool with_hits) | |||
404 | static int perf_header__adds_write(struct perf_header *self, int fd) | 423 | static int perf_header__adds_write(struct perf_header *self, int fd) |
405 | { | 424 | { |
406 | int nr_sections; | 425 | int nr_sections; |
426 | struct perf_session *session; | ||
407 | struct perf_file_section *feat_sec; | 427 | struct perf_file_section *feat_sec; |
408 | int sec_size; | 428 | int sec_size; |
409 | u64 sec_start; | 429 | u64 sec_start; |
410 | int idx = 0, err; | 430 | int idx = 0, err; |
411 | 431 | ||
412 | if (dsos__read_build_ids(self, true)) | 432 | session = container_of(self, struct perf_session, header); |
433 | if (perf_session__read_build_ids(session, true)) | ||
413 | perf_header__set_feat(self, HEADER_BUILD_ID); | 434 | perf_header__set_feat(self, HEADER_BUILD_ID); |
414 | 435 | ||
415 | nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS); | 436 | nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS); |
@@ -450,7 +471,7 @@ static int perf_header__adds_write(struct perf_header *self, int fd) | |||
450 | } | 471 | } |
451 | buildid_sec->size = lseek(fd, 0, SEEK_CUR) - | 472 | buildid_sec->size = lseek(fd, 0, SEEK_CUR) - |
452 | buildid_sec->offset; | 473 | buildid_sec->offset; |
453 | dsos__cache_build_ids(self); | 474 | perf_session__cache_build_ids(session); |
454 | } | 475 | } |
455 | 476 | ||
456 | lseek(fd, sec_start, SEEK_SET); | 477 | lseek(fd, sec_start, SEEK_SET); |
@@ -490,7 +511,6 @@ int perf_header__write(struct perf_header *self, int fd, bool at_exit) | |||
490 | 511 | ||
491 | lseek(fd, sizeof(f_header), SEEK_SET); | 512 | lseek(fd, sizeof(f_header), SEEK_SET); |
492 | 513 | ||
493 | |||
494 | for (i = 0; i < self->attrs; i++) { | 514 | for (i = 0; i < self->attrs; i++) { |
495 | attr = self->attr[i]; | 515 | attr = self->attr[i]; |
496 | 516 | ||
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c index fbb00978b2e2..6f2975a00358 100644 --- a/tools/perf/util/help.c +++ b/tools/perf/util/help.c | |||
@@ -4,28 +4,6 @@ | |||
4 | #include "levenshtein.h" | 4 | #include "levenshtein.h" |
5 | #include "help.h" | 5 | #include "help.h" |
6 | 6 | ||
7 | /* most GUI terminals set COLUMNS (although some don't export it) */ | ||
8 | static int term_columns(void) | ||
9 | { | ||
10 | char *col_string = getenv("COLUMNS"); | ||
11 | int n_cols; | ||
12 | |||
13 | if (col_string && (n_cols = atoi(col_string)) > 0) | ||
14 | return n_cols; | ||
15 | |||
16 | #ifdef TIOCGWINSZ | ||
17 | { | ||
18 | struct winsize ws; | ||
19 | if (!ioctl(1, TIOCGWINSZ, &ws)) { | ||
20 | if (ws.ws_col) | ||
21 | return ws.ws_col; | ||
22 | } | ||
23 | } | ||
24 | #endif | ||
25 | |||
26 | return 80; | ||
27 | } | ||
28 | |||
29 | void add_cmdname(struct cmdnames *cmds, const char *name, size_t len) | 7 | void add_cmdname(struct cmdnames *cmds, const char *name, size_t len) |
30 | { | 8 | { |
31 | struct cmdname *ent = malloc(sizeof(*ent) + len + 1); | 9 | struct cmdname *ent = malloc(sizeof(*ent) + len + 1); |
@@ -96,9 +74,13 @@ static void pretty_print_string_list(struct cmdnames *cmds, int longest) | |||
96 | { | 74 | { |
97 | int cols = 1, rows; | 75 | int cols = 1, rows; |
98 | int space = longest + 1; /* min 1 SP between words */ | 76 | int space = longest + 1; /* min 1 SP between words */ |
99 | int max_cols = term_columns() - 1; /* don't print *on* the edge */ | 77 | struct winsize win; |
78 | int max_cols; | ||
100 | int i, j; | 79 | int i, j; |
101 | 80 | ||
81 | get_term_dimensions(&win); | ||
82 | max_cols = win.ws_col - 1; /* don't print *on* the edge */ | ||
83 | |||
102 | if (space < max_cols) | 84 | if (space < max_cols) |
103 | cols = max_cols / space; | 85 | cols = max_cols / space; |
104 | rows = (cmds->cnt + cols - 1) / cols; | 86 | rows = (cmds->cnt + cols - 1) / cols; |
@@ -324,7 +306,7 @@ const char *help_unknown_cmd(const char *cmd) | |||
324 | 306 | ||
325 | main_cmds.names[0] = NULL; | 307 | main_cmds.names[0] = NULL; |
326 | clean_cmdnames(&main_cmds); | 308 | clean_cmdnames(&main_cmds); |
327 | fprintf(stderr, "WARNING: You called a Git program named '%s', " | 309 | fprintf(stderr, "WARNING: You called a perf program named '%s', " |
328 | "which does not exist.\n" | 310 | "which does not exist.\n" |
329 | "Continuing under the assumption that you meant '%s'\n", | 311 | "Continuing under the assumption that you meant '%s'\n", |
330 | cmd, assumed); | 312 | cmd, assumed); |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 9a71c94f057a..cbf7eae2ce09 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #include "util.h" | 1 | #include "util.h" |
2 | #include "build-id.h" | ||
2 | #include "hist.h" | 3 | #include "hist.h" |
3 | #include "session.h" | 4 | #include "session.h" |
4 | #include "sort.h" | 5 | #include "sort.h" |
@@ -988,22 +989,42 @@ int hist_entry__annotate(struct hist_entry *self, struct list_head *head) | |||
988 | struct symbol *sym = self->ms.sym; | 989 | struct symbol *sym = self->ms.sym; |
989 | struct map *map = self->ms.map; | 990 | struct map *map = self->ms.map; |
990 | struct dso *dso = map->dso; | 991 | struct dso *dso = map->dso; |
991 | const char *filename = dso->long_name; | 992 | char *filename = dso__build_id_filename(dso, NULL, 0); |
993 | bool free_filename = true; | ||
992 | char command[PATH_MAX * 2]; | 994 | char command[PATH_MAX * 2]; |
993 | FILE *file; | 995 | FILE *file; |
996 | int err = 0; | ||
994 | u64 len; | 997 | u64 len; |
995 | 998 | ||
996 | if (!filename) | 999 | if (filename == NULL) { |
997 | return -1; | 1000 | if (dso->has_build_id) { |
1001 | pr_err("Can't annotate %s: not enough memory\n", | ||
1002 | sym->name); | ||
1003 | return -ENOMEM; | ||
1004 | } | ||
1005 | goto fallback; | ||
1006 | } else if (readlink(filename, command, sizeof(command)) < 0 || | ||
1007 | strstr(command, "[kernel.kallsyms]") || | ||
1008 | access(filename, R_OK)) { | ||
1009 | free(filename); | ||
1010 | fallback: | ||
1011 | /* | ||
1012 | * If we don't have build-ids or the build-id file isn't in the | ||
1013 | * cache, or is just a kallsyms file, well, lets hope that this | ||
1014 | * DSO is the same as when 'perf record' ran. | ||
1015 | */ | ||
1016 | filename = dso->long_name; | ||
1017 | free_filename = false; | ||
1018 | } | ||
998 | 1019 | ||
999 | if (dso->origin == DSO__ORIG_KERNEL) { | 1020 | if (dso->origin == DSO__ORIG_KERNEL) { |
1000 | if (dso->annotate_warned) | 1021 | if (dso->annotate_warned) |
1001 | return 0; | 1022 | goto out_free_filename; |
1023 | err = -ENOENT; | ||
1002 | dso->annotate_warned = 1; | 1024 | dso->annotate_warned = 1; |
1003 | pr_err("Can't annotate %s: No vmlinux file was found in the " | 1025 | pr_err("Can't annotate %s: No vmlinux file was found in the " |
1004 | "path:\n", sym->name); | 1026 | "path\n", sym->name); |
1005 | vmlinux_path__fprintf(stderr); | 1027 | goto out_free_filename; |
1006 | return -1; | ||
1007 | } | 1028 | } |
1008 | 1029 | ||
1009 | pr_debug("%s: filename=%s, sym=%s, start=%#Lx, end=%#Lx\n", __func__, | 1030 | pr_debug("%s: filename=%s, sym=%s, start=%#Lx, end=%#Lx\n", __func__, |
@@ -1025,14 +1046,17 @@ int hist_entry__annotate(struct hist_entry *self, struct list_head *head) | |||
1025 | 1046 | ||
1026 | file = popen(command, "r"); | 1047 | file = popen(command, "r"); |
1027 | if (!file) | 1048 | if (!file) |
1028 | return -1; | 1049 | goto out_free_filename; |
1029 | 1050 | ||
1030 | while (!feof(file)) | 1051 | while (!feof(file)) |
1031 | if (hist_entry__parse_objdump_line(self, file, head) < 0) | 1052 | if (hist_entry__parse_objdump_line(self, file, head) < 0) |
1032 | break; | 1053 | break; |
1033 | 1054 | ||
1034 | pclose(file); | 1055 | pclose(file); |
1035 | return 0; | 1056 | out_free_filename: |
1057 | if (free_filename) | ||
1058 | free(filename); | ||
1059 | return err; | ||
1036 | } | 1060 | } |
1037 | 1061 | ||
1038 | void hists__inc_nr_events(struct hists *self, u32 type) | 1062 | void hists__inc_nr_events(struct hists *self, u32 type) |
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 6f17dcd8412c..83fa33a7b38b 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -98,12 +98,32 @@ void hists__filter_by_thread(struct hists *self, const struct thread *thread); | |||
98 | #ifdef NO_NEWT_SUPPORT | 98 | #ifdef NO_NEWT_SUPPORT |
99 | static inline int hists__browse(struct hists *self __used, | 99 | static inline int hists__browse(struct hists *self __used, |
100 | const char *helpline __used, | 100 | const char *helpline __used, |
101 | const char *input_name __used) | 101 | const char *ev_name __used) |
102 | { | 102 | { |
103 | return 0; | 103 | return 0; |
104 | } | 104 | } |
105 | |||
106 | static inline int hists__tui_browse_tree(struct rb_root *self __used, | ||
107 | const char *help __used) | ||
108 | { | ||
109 | return 0; | ||
110 | } | ||
111 | |||
112 | static inline int hist_entry__tui_annotate(struct hist_entry *self __used) | ||
113 | { | ||
114 | return 0; | ||
115 | } | ||
116 | #define KEY_LEFT -1 | ||
117 | #define KEY_RIGHT -2 | ||
105 | #else | 118 | #else |
119 | #include <newt.h> | ||
106 | int hists__browse(struct hists *self, const char *helpline, | 120 | int hists__browse(struct hists *self, const char *helpline, |
107 | const char *input_name); | 121 | const char *ev_name); |
122 | int hist_entry__tui_annotate(struct hist_entry *self); | ||
123 | |||
124 | #define KEY_LEFT NEWT_KEY_LEFT | ||
125 | #define KEY_RIGHT NEWT_KEY_RIGHT | ||
126 | |||
127 | int hists__tui_browse_tree(struct rb_root *self, const char *help); | ||
108 | #endif | 128 | #endif |
109 | #endif /* __PERF_HIST_H */ | 129 | #endif /* __PERF_HIST_H */ |
diff --git a/tools/perf/util/newt.c b/tools/perf/util/newt.c index ccb7c5bb269e..d54c540f49db 100644 --- a/tools/perf/util/newt.c +++ b/tools/perf/util/newt.c | |||
@@ -1,7 +1,15 @@ | |||
1 | #define _GNU_SOURCE | 1 | #define _GNU_SOURCE |
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #undef _GNU_SOURCE | 3 | #undef _GNU_SOURCE |
4 | 4 | /* | |
5 | * slang versions <= 2.0.6 have a "#if HAVE_LONG_LONG" that breaks | ||
6 | * the build if it isn't defined. Use the equivalent one that glibc | ||
7 | * has on features.h. | ||
8 | */ | ||
9 | #include <features.h> | ||
10 | #ifndef HAVE_LONG_LONG | ||
11 | #define HAVE_LONG_LONG __GLIBC_HAVE_LONG_LONG | ||
12 | #endif | ||
5 | #include <slang.h> | 13 | #include <slang.h> |
6 | #include <stdlib.h> | 14 | #include <stdlib.h> |
7 | #include <newt.h> | 15 | #include <newt.h> |
@@ -227,6 +235,15 @@ static bool dialog_yesno(const char *msg) | |||
227 | return newtWinChoice(NULL, yes, no, (char *)msg) == 1; | 235 | return newtWinChoice(NULL, yes, no, (char *)msg) == 1; |
228 | } | 236 | } |
229 | 237 | ||
238 | static void ui__error_window(const char *fmt, ...) | ||
239 | { | ||
240 | va_list ap; | ||
241 | |||
242 | va_start(ap, fmt); | ||
243 | newtWinMessagev((char *)"Error", (char *)"Ok", (char *)fmt, ap); | ||
244 | va_end(ap); | ||
245 | } | ||
246 | |||
230 | #define HE_COLORSET_TOP 50 | 247 | #define HE_COLORSET_TOP 50 |
231 | #define HE_COLORSET_MEDIUM 51 | 248 | #define HE_COLORSET_MEDIUM 51 |
232 | #define HE_COLORSET_NORMAL 52 | 249 | #define HE_COLORSET_NORMAL 52 |
@@ -375,8 +392,11 @@ static int ui_browser__run(struct ui_browser *self, const char *title, | |||
375 | newtFormAddHotKey(self->form, NEWT_KEY_DOWN); | 392 | newtFormAddHotKey(self->form, NEWT_KEY_DOWN); |
376 | newtFormAddHotKey(self->form, NEWT_KEY_PGUP); | 393 | newtFormAddHotKey(self->form, NEWT_KEY_PGUP); |
377 | newtFormAddHotKey(self->form, NEWT_KEY_PGDN); | 394 | newtFormAddHotKey(self->form, NEWT_KEY_PGDN); |
395 | newtFormAddHotKey(self->form, ' '); | ||
378 | newtFormAddHotKey(self->form, NEWT_KEY_HOME); | 396 | newtFormAddHotKey(self->form, NEWT_KEY_HOME); |
379 | newtFormAddHotKey(self->form, NEWT_KEY_END); | 397 | newtFormAddHotKey(self->form, NEWT_KEY_END); |
398 | newtFormAddHotKey(self->form, NEWT_KEY_TAB); | ||
399 | newtFormAddHotKey(self->form, NEWT_KEY_RIGHT); | ||
380 | 400 | ||
381 | if (ui_browser__refresh_entries(self) < 0) | 401 | if (ui_browser__refresh_entries(self) < 0) |
382 | return -1; | 402 | return -1; |
@@ -389,6 +409,8 @@ static int ui_browser__run(struct ui_browser *self, const char *title, | |||
389 | 409 | ||
390 | if (es->reason != NEWT_EXIT_HOTKEY) | 410 | if (es->reason != NEWT_EXIT_HOTKEY) |
391 | break; | 411 | break; |
412 | if (is_exit_key(es->u.key)) | ||
413 | return es->u.key; | ||
392 | switch (es->u.key) { | 414 | switch (es->u.key) { |
393 | case NEWT_KEY_DOWN: | 415 | case NEWT_KEY_DOWN: |
394 | if (self->index == self->nr_entries - 1) | 416 | if (self->index == self->nr_entries - 1) |
@@ -411,6 +433,7 @@ static int ui_browser__run(struct ui_browser *self, const char *title, | |||
411 | } | 433 | } |
412 | break; | 434 | break; |
413 | case NEWT_KEY_PGDN: | 435 | case NEWT_KEY_PGDN: |
436 | case ' ': | ||
414 | if (self->first_visible_entry_idx + self->height > self->nr_entries - 1) | 437 | if (self->first_visible_entry_idx + self->height > self->nr_entries - 1) |
415 | break; | 438 | break; |
416 | 439 | ||
@@ -461,12 +484,10 @@ static int ui_browser__run(struct ui_browser *self, const char *title, | |||
461 | } | 484 | } |
462 | } | 485 | } |
463 | break; | 486 | break; |
464 | case NEWT_KEY_ESCAPE: | 487 | case NEWT_KEY_RIGHT: |
465 | case NEWT_KEY_LEFT: | 488 | case NEWT_KEY_LEFT: |
466 | case CTRL('c'): | 489 | case NEWT_KEY_TAB: |
467 | case 'Q': | 490 | return es->u.key; |
468 | case 'q': | ||
469 | return 0; | ||
470 | default: | 491 | default: |
471 | continue; | 492 | continue; |
472 | } | 493 | } |
@@ -658,18 +679,24 @@ static size_t hist_entry__append_browser(struct hist_entry *self, | |||
658 | return ret; | 679 | return ret; |
659 | } | 680 | } |
660 | 681 | ||
661 | static void hist_entry__annotate_browser(struct hist_entry *self) | 682 | int hist_entry__tui_annotate(struct hist_entry *self) |
662 | { | 683 | { |
663 | struct ui_browser browser; | 684 | struct ui_browser browser; |
664 | struct newtExitStruct es; | 685 | struct newtExitStruct es; |
665 | struct objdump_line *pos, *n; | 686 | struct objdump_line *pos, *n; |
666 | LIST_HEAD(head); | 687 | LIST_HEAD(head); |
688 | int ret; | ||
667 | 689 | ||
668 | if (self->ms.sym == NULL) | 690 | if (self->ms.sym == NULL) |
669 | return; | 691 | return -1; |
670 | 692 | ||
671 | if (hist_entry__annotate(self, &head) < 0) | 693 | if (self->ms.map->dso->annotate_warned) |
672 | return; | 694 | return -1; |
695 | |||
696 | if (hist_entry__annotate(self, &head) < 0) { | ||
697 | ui__error_window(browser__last_msg); | ||
698 | return -1; | ||
699 | } | ||
673 | 700 | ||
674 | ui_helpline__push("Press <- or ESC to exit"); | 701 | ui_helpline__push("Press <- or ESC to exit"); |
675 | 702 | ||
@@ -684,7 +711,7 @@ static void hist_entry__annotate_browser(struct hist_entry *self) | |||
684 | } | 711 | } |
685 | 712 | ||
686 | browser.width += 18; /* Percentage */ | 713 | browser.width += 18; /* Percentage */ |
687 | ui_browser__run(&browser, self->ms.sym->name, &es); | 714 | ret = ui_browser__run(&browser, self->ms.sym->name, &es); |
688 | newtFormDestroy(browser.form); | 715 | newtFormDestroy(browser.form); |
689 | newtPopWindow(); | 716 | newtPopWindow(); |
690 | list_for_each_entry_safe(pos, n, &head, node) { | 717 | list_for_each_entry_safe(pos, n, &head, node) { |
@@ -692,6 +719,7 @@ static void hist_entry__annotate_browser(struct hist_entry *self) | |||
692 | objdump_line__free(pos); | 719 | objdump_line__free(pos); |
693 | } | 720 | } |
694 | ui_helpline__pop(); | 721 | ui_helpline__pop(); |
722 | return ret; | ||
695 | } | 723 | } |
696 | 724 | ||
697 | static const void *newt__symbol_tree_get_current(newtComponent self) | 725 | static const void *newt__symbol_tree_get_current(newtComponent self) |
@@ -814,6 +842,8 @@ static int hist_browser__populate(struct hist_browser *self, struct hists *hists | |||
814 | newtFormAddHotKey(self->form, 'h'); | 842 | newtFormAddHotKey(self->form, 'h'); |
815 | newtFormAddHotKey(self->form, NEWT_KEY_F1); | 843 | newtFormAddHotKey(self->form, NEWT_KEY_F1); |
816 | newtFormAddHotKey(self->form, NEWT_KEY_RIGHT); | 844 | newtFormAddHotKey(self->form, NEWT_KEY_RIGHT); |
845 | newtFormAddHotKey(self->form, NEWT_KEY_TAB); | ||
846 | newtFormAddHotKey(self->form, NEWT_KEY_UNTAB); | ||
817 | newtFormAddComponents(self->form, self->tree, NULL); | 847 | newtFormAddComponents(self->form, self->tree, NULL); |
818 | self->selection = newt__symbol_tree_get_current(self->tree); | 848 | self->selection = newt__symbol_tree_get_current(self->tree); |
819 | 849 | ||
@@ -845,7 +875,7 @@ static struct thread *hist_browser__selected_thread(struct hist_browser *self) | |||
845 | return he ? he->thread : NULL; | 875 | return he ? he->thread : NULL; |
846 | } | 876 | } |
847 | 877 | ||
848 | static int hist_browser__title(char *bf, size_t size, const char *input_name, | 878 | static int hist_browser__title(char *bf, size_t size, const char *ev_name, |
849 | const struct dso *dso, const struct thread *thread) | 879 | const struct dso *dso, const struct thread *thread) |
850 | { | 880 | { |
851 | int printed = 0; | 881 | int printed = 0; |
@@ -859,18 +889,18 @@ static int hist_browser__title(char *bf, size_t size, const char *input_name, | |||
859 | printed += snprintf(bf + printed, size - printed, | 889 | printed += snprintf(bf + printed, size - printed, |
860 | "%sDSO: %s", thread ? " " : "", | 890 | "%sDSO: %s", thread ? " " : "", |
861 | dso->short_name); | 891 | dso->short_name); |
862 | return printed ?: snprintf(bf, size, "Report: %s", input_name); | 892 | return printed ?: snprintf(bf, size, "Event: %s", ev_name); |
863 | } | 893 | } |
864 | 894 | ||
865 | int hists__browse(struct hists *self, const char *helpline, const char *input_name) | 895 | int hists__browse(struct hists *self, const char *helpline, const char *ev_name) |
866 | { | 896 | { |
867 | struct hist_browser *browser = hist_browser__new(); | 897 | struct hist_browser *browser = hist_browser__new(); |
868 | struct pstack *fstack = pstack__new(2); | 898 | struct pstack *fstack; |
869 | const struct thread *thread_filter = NULL; | 899 | const struct thread *thread_filter = NULL; |
870 | const struct dso *dso_filter = NULL; | 900 | const struct dso *dso_filter = NULL; |
871 | struct newtExitStruct es; | 901 | struct newtExitStruct es; |
872 | char msg[160]; | 902 | char msg[160]; |
873 | int err = -1; | 903 | int key = -1; |
874 | 904 | ||
875 | if (browser == NULL) | 905 | if (browser == NULL) |
876 | return -1; | 906 | return -1; |
@@ -881,7 +911,7 @@ int hists__browse(struct hists *self, const char *helpline, const char *input_na | |||
881 | 911 | ||
882 | ui_helpline__push(helpline); | 912 | ui_helpline__push(helpline); |
883 | 913 | ||
884 | hist_browser__title(msg, sizeof(msg), input_name, | 914 | hist_browser__title(msg, sizeof(msg), ev_name, |
885 | dso_filter, thread_filter); | 915 | dso_filter, thread_filter); |
886 | if (hist_browser__populate(browser, self, msg) < 0) | 916 | if (hist_browser__populate(browser, self, msg) < 0) |
887 | goto out_free_stack; | 917 | goto out_free_stack; |
@@ -899,11 +929,27 @@ int hists__browse(struct hists *self, const char *helpline, const char *input_na | |||
899 | dso = browser->selection->map ? browser->selection->map->dso : NULL; | 929 | dso = browser->selection->map ? browser->selection->map->dso : NULL; |
900 | 930 | ||
901 | if (es.reason == NEWT_EXIT_HOTKEY) { | 931 | if (es.reason == NEWT_EXIT_HOTKEY) { |
902 | if (es.u.key == NEWT_KEY_F1) | 932 | key = es.u.key; |
933 | |||
934 | switch (key) { | ||
935 | case NEWT_KEY_F1: | ||
903 | goto do_help; | 936 | goto do_help; |
937 | case NEWT_KEY_TAB: | ||
938 | case NEWT_KEY_UNTAB: | ||
939 | /* | ||
940 | * Exit the browser, let hists__browser_tree | ||
941 | * go to the next or previous | ||
942 | */ | ||
943 | goto out_free_stack; | ||
944 | default:; | ||
945 | } | ||
904 | 946 | ||
905 | switch (toupper(es.u.key)) { | 947 | key = toupper(key); |
948 | switch (key) { | ||
906 | case 'A': | 949 | case 'A': |
950 | if (browser->selection->map == NULL && | ||
951 | browser->selection->map->dso->annotate_warned) | ||
952 | continue; | ||
907 | goto do_annotate; | 953 | goto do_annotate; |
908 | case 'D': | 954 | case 'D': |
909 | goto zoom_dso; | 955 | goto zoom_dso; |
@@ -922,14 +968,14 @@ do_help: | |||
922 | continue; | 968 | continue; |
923 | default:; | 969 | default:; |
924 | } | 970 | } |
925 | if (toupper(es.u.key) == 'Q' || | 971 | if (is_exit_key(key)) { |
926 | es.u.key == CTRL('c')) | 972 | if (key == NEWT_KEY_ESCAPE) { |
927 | break; | 973 | if (dialog_yesno("Do you really want to exit?")) |
928 | if (es.u.key == NEWT_KEY_ESCAPE) { | 974 | break; |
929 | if (dialog_yesno("Do you really want to exit?")) | 975 | else |
976 | continue; | ||
977 | } else | ||
930 | break; | 978 | break; |
931 | else | ||
932 | continue; | ||
933 | } | 979 | } |
934 | 980 | ||
935 | if (es.u.key == NEWT_KEY_LEFT) { | 981 | if (es.u.key == NEWT_KEY_LEFT) { |
@@ -947,6 +993,7 @@ do_help: | |||
947 | } | 993 | } |
948 | 994 | ||
949 | if (browser->selection->sym != NULL && | 995 | if (browser->selection->sym != NULL && |
996 | !browser->selection->map->dso->annotate_warned && | ||
950 | asprintf(&options[nr_options], "Annotate %s", | 997 | asprintf(&options[nr_options], "Annotate %s", |
951 | browser->selection->sym->name) > 0) | 998 | browser->selection->sym->name) > 0) |
952 | annotate = nr_options++; | 999 | annotate = nr_options++; |
@@ -981,6 +1028,7 @@ do_help: | |||
981 | struct hist_entry *he; | 1028 | struct hist_entry *he; |
982 | do_annotate: | 1029 | do_annotate: |
983 | if (browser->selection->map->dso->origin == DSO__ORIG_KERNEL) { | 1030 | if (browser->selection->map->dso->origin == DSO__ORIG_KERNEL) { |
1031 | browser->selection->map->dso->annotate_warned = 1; | ||
984 | ui_helpline__puts("No vmlinux file found, can't " | 1032 | ui_helpline__puts("No vmlinux file found, can't " |
985 | "annotate with just a " | 1033 | "annotate with just a " |
986 | "kallsyms file"); | 1034 | "kallsyms file"); |
@@ -991,7 +1039,7 @@ do_annotate: | |||
991 | if (he == NULL) | 1039 | if (he == NULL) |
992 | continue; | 1040 | continue; |
993 | 1041 | ||
994 | hist_entry__annotate_browser(he); | 1042 | hist_entry__tui_annotate(he); |
995 | } else if (choice == zoom_dso) { | 1043 | } else if (choice == zoom_dso) { |
996 | zoom_dso: | 1044 | zoom_dso: |
997 | if (dso_filter) { | 1045 | if (dso_filter) { |
@@ -1008,7 +1056,7 @@ zoom_out_dso: | |||
1008 | pstack__push(fstack, &dso_filter); | 1056 | pstack__push(fstack, &dso_filter); |
1009 | } | 1057 | } |
1010 | hists__filter_by_dso(self, dso_filter); | 1058 | hists__filter_by_dso(self, dso_filter); |
1011 | hist_browser__title(msg, sizeof(msg), input_name, | 1059 | hist_browser__title(msg, sizeof(msg), ev_name, |
1012 | dso_filter, thread_filter); | 1060 | dso_filter, thread_filter); |
1013 | if (hist_browser__populate(browser, self, msg) < 0) | 1061 | if (hist_browser__populate(browser, self, msg) < 0) |
1014 | goto out; | 1062 | goto out; |
@@ -1027,18 +1075,49 @@ zoom_out_thread: | |||
1027 | pstack__push(fstack, &thread_filter); | 1075 | pstack__push(fstack, &thread_filter); |
1028 | } | 1076 | } |
1029 | hists__filter_by_thread(self, thread_filter); | 1077 | hists__filter_by_thread(self, thread_filter); |
1030 | hist_browser__title(msg, sizeof(msg), input_name, | 1078 | hist_browser__title(msg, sizeof(msg), ev_name, |
1031 | dso_filter, thread_filter); | 1079 | dso_filter, thread_filter); |
1032 | if (hist_browser__populate(browser, self, msg) < 0) | 1080 | if (hist_browser__populate(browser, self, msg) < 0) |
1033 | goto out; | 1081 | goto out; |
1034 | } | 1082 | } |
1035 | } | 1083 | } |
1036 | err = 0; | ||
1037 | out_free_stack: | 1084 | out_free_stack: |
1038 | pstack__delete(fstack); | 1085 | pstack__delete(fstack); |
1039 | out: | 1086 | out: |
1040 | hist_browser__delete(browser); | 1087 | hist_browser__delete(browser); |
1041 | return err; | 1088 | return key; |
1089 | } | ||
1090 | |||
1091 | int hists__tui_browse_tree(struct rb_root *self, const char *help) | ||
1092 | { | ||
1093 | struct rb_node *first = rb_first(self), *nd = first, *next; | ||
1094 | int key = 0; | ||
1095 | |||
1096 | while (nd) { | ||
1097 | struct hists *hists = rb_entry(nd, struct hists, rb_node); | ||
1098 | const char *ev_name = __event_name(hists->type, hists->config); | ||
1099 | |||
1100 | key = hists__browse(hists, help, ev_name); | ||
1101 | |||
1102 | if (is_exit_key(key)) | ||
1103 | break; | ||
1104 | |||
1105 | switch (key) { | ||
1106 | case NEWT_KEY_TAB: | ||
1107 | next = rb_next(nd); | ||
1108 | if (next) | ||
1109 | nd = next; | ||
1110 | break; | ||
1111 | case NEWT_KEY_UNTAB: | ||
1112 | if (nd == first) | ||
1113 | continue; | ||
1114 | nd = rb_prev(nd); | ||
1115 | default: | ||
1116 | break; | ||
1117 | } | ||
1118 | } | ||
1119 | |||
1120 | return key; | ||
1042 | } | 1121 | } |
1043 | 1122 | ||
1044 | static struct newtPercentTreeColors { | 1123 | static struct newtPercentTreeColors { |
@@ -1058,10 +1137,13 @@ static struct newtPercentTreeColors { | |||
1058 | void setup_browser(void) | 1137 | void setup_browser(void) |
1059 | { | 1138 | { |
1060 | struct newtPercentTreeColors *c = &defaultPercentTreeColors; | 1139 | struct newtPercentTreeColors *c = &defaultPercentTreeColors; |
1061 | if (!isatty(1)) | 1140 | |
1141 | if (!isatty(1) || !use_browser || dump_trace) { | ||
1142 | setup_pager(); | ||
1062 | return; | 1143 | return; |
1144 | } | ||
1063 | 1145 | ||
1064 | use_browser = true; | 1146 | use_browser = 1; |
1065 | newtInit(); | 1147 | newtInit(); |
1066 | newtCls(); | 1148 | newtCls(); |
1067 | ui_helpline__puts(" "); | 1149 | ui_helpline__puts(" "); |
@@ -1074,7 +1156,7 @@ void setup_browser(void) | |||
1074 | 1156 | ||
1075 | void exit_browser(bool wait_for_ok) | 1157 | void exit_browser(bool wait_for_ok) |
1076 | { | 1158 | { |
1077 | if (use_browser) { | 1159 | if (use_browser > 0) { |
1078 | if (wait_for_ok) { | 1160 | if (wait_for_ok) { |
1079 | char title[] = "Fatal Error", ok[] = "Ok"; | 1161 | char title[] = "Fatal Error", ok[] = "Ok"; |
1080 | newtWinMessage(title, ok, browser__last_msg); | 1162 | newtWinMessage(title, ok, browser__last_msg); |
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c index fd1f2faaade4..58a470d036dd 100644 --- a/tools/perf/util/path.c +++ b/tools/perf/util/path.c | |||
@@ -54,21 +54,6 @@ static char *cleanup_path(char *path) | |||
54 | return path; | 54 | return path; |
55 | } | 55 | } |
56 | 56 | ||
57 | char *mksnpath(char *buf, size_t n, const char *fmt, ...) | ||
58 | { | ||
59 | va_list args; | ||
60 | unsigned len; | ||
61 | |||
62 | va_start(args, fmt); | ||
63 | len = vsnprintf(buf, n, fmt, args); | ||
64 | va_end(args); | ||
65 | if (len >= n) { | ||
66 | strlcpy(buf, bad_path, n); | ||
67 | return buf; | ||
68 | } | ||
69 | return cleanup_path(buf); | ||
70 | } | ||
71 | |||
72 | static char *perf_vsnpath(char *buf, size_t n, const char *fmt, va_list args) | 57 | static char *perf_vsnpath(char *buf, size_t n, const char *fmt, va_list args) |
73 | { | 58 | { |
74 | const char *perf_dir = get_perf_dir(); | 59 | const char *perf_dir = get_perf_dir(); |
@@ -89,15 +74,6 @@ bad: | |||
89 | return buf; | 74 | return buf; |
90 | } | 75 | } |
91 | 76 | ||
92 | char *perf_snpath(char *buf, size_t n, const char *fmt, ...) | ||
93 | { | ||
94 | va_list args; | ||
95 | va_start(args, fmt); | ||
96 | (void)perf_vsnpath(buf, n, fmt, args); | ||
97 | va_end(args); | ||
98 | return buf; | ||
99 | } | ||
100 | |||
101 | char *perf_pathdup(const char *fmt, ...) | 77 | char *perf_pathdup(const char *fmt, ...) |
102 | { | 78 | { |
103 | char path[PATH_MAX]; | 79 | char path[PATH_MAX]; |
@@ -143,184 +119,6 @@ char *perf_path(const char *fmt, ...) | |||
143 | return cleanup_path(pathname); | 119 | return cleanup_path(pathname); |
144 | } | 120 | } |
145 | 121 | ||
146 | |||
147 | /* perf_mkstemp() - create tmp file honoring TMPDIR variable */ | ||
148 | int perf_mkstemp(char *path, size_t len, const char *template) | ||
149 | { | ||
150 | const char *tmp; | ||
151 | size_t n; | ||
152 | |||
153 | tmp = getenv("TMPDIR"); | ||
154 | if (!tmp) | ||
155 | tmp = "/tmp"; | ||
156 | n = snprintf(path, len, "%s/%s", tmp, template); | ||
157 | if (len <= n) { | ||
158 | errno = ENAMETOOLONG; | ||
159 | return -1; | ||
160 | } | ||
161 | return mkstemp(path); | ||
162 | } | ||
163 | |||
164 | |||
165 | const char *make_relative_path(const char *abs_path, const char *base) | ||
166 | { | ||
167 | static char buf[PATH_MAX + 1]; | ||
168 | int baselen; | ||
169 | |||
170 | if (!base) | ||
171 | return abs_path; | ||
172 | |||
173 | baselen = strlen(base); | ||
174 | if (prefixcmp(abs_path, base)) | ||
175 | return abs_path; | ||
176 | if (abs_path[baselen] == '/') | ||
177 | baselen++; | ||
178 | else if (base[baselen - 1] != '/') | ||
179 | return abs_path; | ||
180 | |||
181 | strcpy(buf, abs_path + baselen); | ||
182 | |||
183 | return buf; | ||
184 | } | ||
185 | |||
186 | /* | ||
187 | * It is okay if dst == src, but they should not overlap otherwise. | ||
188 | * | ||
189 | * Performs the following normalizations on src, storing the result in dst: | ||
190 | * - Ensures that components are separated by '/' (Windows only) | ||
191 | * - Squashes sequences of '/'. | ||
192 | * - Removes "." components. | ||
193 | * - Removes ".." components, and the components the precede them. | ||
194 | * Returns failure (non-zero) if a ".." component appears as first path | ||
195 | * component anytime during the normalization. Otherwise, returns success (0). | ||
196 | * | ||
197 | * Note that this function is purely textual. It does not follow symlinks, | ||
198 | * verify the existence of the path, or make any system calls. | ||
199 | */ | ||
200 | int normalize_path_copy(char *dst, const char *src) | ||
201 | { | ||
202 | char *dst0; | ||
203 | |||
204 | if (has_dos_drive_prefix(src)) { | ||
205 | *dst++ = *src++; | ||
206 | *dst++ = *src++; | ||
207 | } | ||
208 | dst0 = dst; | ||
209 | |||
210 | if (is_dir_sep(*src)) { | ||
211 | *dst++ = '/'; | ||
212 | while (is_dir_sep(*src)) | ||
213 | src++; | ||
214 | } | ||
215 | |||
216 | for (;;) { | ||
217 | char c = *src; | ||
218 | |||
219 | /* | ||
220 | * A path component that begins with . could be | ||
221 | * special: | ||
222 | * (1) "." and ends -- ignore and terminate. | ||
223 | * (2) "./" -- ignore them, eat slash and continue. | ||
224 | * (3) ".." and ends -- strip one and terminate. | ||
225 | * (4) "../" -- strip one, eat slash and continue. | ||
226 | */ | ||
227 | if (c == '.') { | ||
228 | if (!src[1]) { | ||
229 | /* (1) */ | ||
230 | src++; | ||
231 | } else if (is_dir_sep(src[1])) { | ||
232 | /* (2) */ | ||
233 | src += 2; | ||
234 | while (is_dir_sep(*src)) | ||
235 | src++; | ||
236 | continue; | ||
237 | } else if (src[1] == '.') { | ||
238 | if (!src[2]) { | ||
239 | /* (3) */ | ||
240 | src += 2; | ||
241 | goto up_one; | ||
242 | } else if (is_dir_sep(src[2])) { | ||
243 | /* (4) */ | ||
244 | src += 3; | ||
245 | while (is_dir_sep(*src)) | ||
246 | src++; | ||
247 | goto up_one; | ||
248 | } | ||
249 | } | ||
250 | } | ||
251 | |||
252 | /* copy up to the next '/', and eat all '/' */ | ||
253 | while ((c = *src++) != '\0' && !is_dir_sep(c)) | ||
254 | *dst++ = c; | ||
255 | if (is_dir_sep(c)) { | ||
256 | *dst++ = '/'; | ||
257 | while (is_dir_sep(c)) | ||
258 | c = *src++; | ||
259 | src--; | ||
260 | } else if (!c) | ||
261 | break; | ||
262 | continue; | ||
263 | |||
264 | up_one: | ||
265 | /* | ||
266 | * dst0..dst is prefix portion, and dst[-1] is '/'; | ||
267 | * go up one level. | ||
268 | */ | ||
269 | dst--; /* go to trailing '/' */ | ||
270 | if (dst <= dst0) | ||
271 | return -1; | ||
272 | /* Windows: dst[-1] cannot be backslash anymore */ | ||
273 | while (dst0 < dst && dst[-1] != '/') | ||
274 | dst--; | ||
275 | } | ||
276 | *dst = '\0'; | ||
277 | return 0; | ||
278 | } | ||
279 | |||
280 | /* | ||
281 | * path = Canonical absolute path | ||
282 | * prefix_list = Colon-separated list of absolute paths | ||
283 | * | ||
284 | * Determines, for each path in prefix_list, whether the "prefix" really | ||
285 | * is an ancestor directory of path. Returns the length of the longest | ||
286 | * ancestor directory, excluding any trailing slashes, or -1 if no prefix | ||
287 | * is an ancestor. (Note that this means 0 is returned if prefix_list is | ||
288 | * "/".) "/foo" is not considered an ancestor of "/foobar". Directories | ||
289 | * are not considered to be their own ancestors. path must be in a | ||
290 | * canonical form: empty components, or "." or ".." components are not | ||
291 | * allowed. prefix_list may be null, which is like "". | ||
292 | */ | ||
293 | int longest_ancestor_length(const char *path, const char *prefix_list) | ||
294 | { | ||
295 | char buf[PATH_MAX+1]; | ||
296 | const char *ceil, *colon; | ||
297 | int len, max_len = -1; | ||
298 | |||
299 | if (prefix_list == NULL || !strcmp(path, "/")) | ||
300 | return -1; | ||
301 | |||
302 | for (colon = ceil = prefix_list; *colon; ceil = colon+1) { | ||
303 | for (colon = ceil; *colon && *colon != PATH_SEP; colon++); | ||
304 | len = colon - ceil; | ||
305 | if (len == 0 || len > PATH_MAX || !is_absolute_path(ceil)) | ||
306 | continue; | ||
307 | strlcpy(buf, ceil, len+1); | ||
308 | if (normalize_path_copy(buf, buf) < 0) | ||
309 | continue; | ||
310 | len = strlen(buf); | ||
311 | if (len > 0 && buf[len-1] == '/') | ||
312 | buf[--len] = '\0'; | ||
313 | |||
314 | if (!strncmp(path, buf, len) && | ||
315 | path[len] == '/' && | ||
316 | len > max_len) { | ||
317 | max_len = len; | ||
318 | } | ||
319 | } | ||
320 | |||
321 | return max_len; | ||
322 | } | ||
323 | |||
324 | /* strip arbitrary amount of directory separators at end of path */ | 122 | /* strip arbitrary amount of directory separators at end of path */ |
325 | static inline int chomp_trailing_dir_sep(const char *path, int len) | 123 | static inline int chomp_trailing_dir_sep(const char *path, int len) |
326 | { | 124 | { |
@@ -354,5 +152,5 @@ char *strip_path_suffix(const char *path, const char *suffix) | |||
354 | 152 | ||
355 | if (path_len && !is_dir_sep(path[path_len - 1])) | 153 | if (path_len && !is_dir_sep(path[path_len - 1])) |
356 | return NULL; | 154 | return NULL; |
357 | return xstrndup(path, chomp_trailing_dir_sep(path, path_len)); | 155 | return strndup(path, chomp_trailing_dir_sep(path, path_len)); |
358 | } | 156 | } |
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 562b1443e785..d964cb199c67 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c | |||
@@ -668,6 +668,7 @@ static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
668 | ret = dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1); | 668 | ret = dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1); |
669 | if (ret <= 0 || nops == 0) { | 669 | if (ret <= 0 || nops == 0) { |
670 | pf->fb_ops = NULL; | 670 | pf->fb_ops = NULL; |
671 | #if _ELFUTILS_PREREQ(0, 142) | ||
671 | } else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa && | 672 | } else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa && |
672 | pf->cfi != NULL) { | 673 | pf->cfi != NULL) { |
673 | Dwarf_Frame *frame; | 674 | Dwarf_Frame *frame; |
@@ -677,6 +678,7 @@ static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
677 | (uintmax_t)pf->addr); | 678 | (uintmax_t)pf->addr); |
678 | return -ENOENT; | 679 | return -ENOENT; |
679 | } | 680 | } |
681 | #endif | ||
680 | } | 682 | } |
681 | 683 | ||
682 | /* Find each argument */ | 684 | /* Find each argument */ |
@@ -741,32 +743,36 @@ static int find_lazy_match_lines(struct list_head *head, | |||
741 | const char *fname, const char *pat) | 743 | const char *fname, const char *pat) |
742 | { | 744 | { |
743 | char *fbuf, *p1, *p2; | 745 | char *fbuf, *p1, *p2; |
744 | int fd, ret, line, nlines = 0; | 746 | int fd, line, nlines = -1; |
745 | struct stat st; | 747 | struct stat st; |
746 | 748 | ||
747 | fd = open(fname, O_RDONLY); | 749 | fd = open(fname, O_RDONLY); |
748 | if (fd < 0) { | 750 | if (fd < 0) { |
749 | pr_warning("Failed to open %s: %s\n", fname, strerror(-fd)); | 751 | pr_warning("Failed to open %s: %s\n", fname, strerror(-fd)); |
750 | return fd; | 752 | return -errno; |
751 | } | 753 | } |
752 | 754 | ||
753 | ret = fstat(fd, &st); | 755 | if (fstat(fd, &st) < 0) { |
754 | if (ret < 0) { | ||
755 | pr_warning("Failed to get the size of %s: %s\n", | 756 | pr_warning("Failed to get the size of %s: %s\n", |
756 | fname, strerror(errno)); | 757 | fname, strerror(errno)); |
757 | return ret; | 758 | nlines = -errno; |
759 | goto out_close; | ||
758 | } | 760 | } |
759 | fbuf = xmalloc(st.st_size + 2); | 761 | |
760 | ret = read(fd, fbuf, st.st_size); | 762 | nlines = -ENOMEM; |
761 | if (ret < 0) { | 763 | fbuf = malloc(st.st_size + 2); |
764 | if (fbuf == NULL) | ||
765 | goto out_close; | ||
766 | if (read(fd, fbuf, st.st_size) < 0) { | ||
762 | pr_warning("Failed to read %s: %s\n", fname, strerror(errno)); | 767 | pr_warning("Failed to read %s: %s\n", fname, strerror(errno)); |
763 | return ret; | 768 | nlines = -errno; |
769 | goto out_free_fbuf; | ||
764 | } | 770 | } |
765 | close(fd); | ||
766 | fbuf[st.st_size] = '\n'; /* Dummy line */ | 771 | fbuf[st.st_size] = '\n'; /* Dummy line */ |
767 | fbuf[st.st_size + 1] = '\0'; | 772 | fbuf[st.st_size + 1] = '\0'; |
768 | p1 = fbuf; | 773 | p1 = fbuf; |
769 | line = 1; | 774 | line = 1; |
775 | nlines = 0; | ||
770 | while ((p2 = strchr(p1, '\n')) != NULL) { | 776 | while ((p2 = strchr(p1, '\n')) != NULL) { |
771 | *p2 = '\0'; | 777 | *p2 = '\0'; |
772 | if (strlazymatch(p1, pat)) { | 778 | if (strlazymatch(p1, pat)) { |
@@ -776,7 +782,10 @@ static int find_lazy_match_lines(struct list_head *head, | |||
776 | line++; | 782 | line++; |
777 | p1 = p2 + 1; | 783 | p1 = p2 + 1; |
778 | } | 784 | } |
785 | out_free_fbuf: | ||
779 | free(fbuf); | 786 | free(fbuf); |
787 | out_close: | ||
788 | close(fd); | ||
780 | return nlines; | 789 | return nlines; |
781 | } | 790 | } |
782 | 791 | ||
@@ -953,11 +962,15 @@ int find_kprobe_trace_events(int fd, struct perf_probe_event *pev, | |||
953 | if (!dbg) { | 962 | if (!dbg) { |
954 | pr_warning("No dwarf info found in the vmlinux - " | 963 | pr_warning("No dwarf info found in the vmlinux - " |
955 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); | 964 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); |
965 | free(pf.tevs); | ||
966 | *tevs = NULL; | ||
956 | return -EBADF; | 967 | return -EBADF; |
957 | } | 968 | } |
958 | 969 | ||
970 | #if _ELFUTILS_PREREQ(0, 142) | ||
959 | /* Get the call frame information from this dwarf */ | 971 | /* Get the call frame information from this dwarf */ |
960 | pf.cfi = dwarf_getcfi(dbg); | 972 | pf.cfi = dwarf_getcfi(dbg); |
973 | #endif | ||
961 | 974 | ||
962 | off = 0; | 975 | off = 0; |
963 | line_list__init(&pf.lcache); | 976 | line_list__init(&pf.lcache); |
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h index 66f1980e3855..e1f61dcd18ff 100644 --- a/tools/perf/util/probe-finder.h +++ b/tools/perf/util/probe-finder.h | |||
@@ -29,6 +29,7 @@ extern int find_line_range(int fd, struct line_range *lr); | |||
29 | 29 | ||
30 | #include <dwarf.h> | 30 | #include <dwarf.h> |
31 | #include <libdw.h> | 31 | #include <libdw.h> |
32 | #include <version.h> | ||
32 | 33 | ||
33 | struct probe_finder { | 34 | struct probe_finder { |
34 | struct perf_probe_event *pev; /* Target probe event */ | 35 | struct perf_probe_event *pev; /* Target probe event */ |
@@ -44,7 +45,9 @@ struct probe_finder { | |||
44 | struct list_head lcache; /* Line cache for lazy match */ | 45 | struct list_head lcache; /* Line cache for lazy match */ |
45 | 46 | ||
46 | /* For variable searching */ | 47 | /* For variable searching */ |
48 | #if _ELFUTILS_PREREQ(0, 142) | ||
47 | Dwarf_CFI *cfi; /* Call Frame Information */ | 49 | Dwarf_CFI *cfi; /* Call Frame Information */ |
50 | #endif | ||
48 | Dwarf_Op *fb_ops; /* Frame base attribute */ | 51 | Dwarf_Op *fb_ops; /* Frame base attribute */ |
49 | struct perf_probe_arg *pvar; /* Current target variable */ | 52 | struct perf_probe_arg *pvar; /* Current target variable */ |
50 | struct kprobe_trace_arg *tvar; /* Current result variable */ | 53 | struct kprobe_trace_arg *tvar; /* Current result variable */ |
diff --git a/tools/perf/util/quote.c b/tools/perf/util/quote.c index 2726fe40eb5d..01f03242b86a 100644 --- a/tools/perf/util/quote.c +++ b/tools/perf/util/quote.c | |||
@@ -1,8 +1,6 @@ | |||
1 | #include "cache.h" | 1 | #include "cache.h" |
2 | #include "quote.h" | 2 | #include "quote.h" |
3 | 3 | ||
4 | int quote_path_fully = 1; | ||
5 | |||
6 | /* Help to copy the thing properly quoted for the shell safety. | 4 | /* Help to copy the thing properly quoted for the shell safety. |
7 | * any single quote is replaced with '\'', any exclamation point | 5 | * any single quote is replaced with '\'', any exclamation point |
8 | * is replaced with '\!', and the whole thing is enclosed in a | 6 | * is replaced with '\!', and the whole thing is enclosed in a |
@@ -19,7 +17,7 @@ static inline int need_bs_quote(char c) | |||
19 | return (c == '\'' || c == '!'); | 17 | return (c == '\'' || c == '!'); |
20 | } | 18 | } |
21 | 19 | ||
22 | void sq_quote_buf(struct strbuf *dst, const char *src) | 20 | static void sq_quote_buf(struct strbuf *dst, const char *src) |
23 | { | 21 | { |
24 | char *to_free = NULL; | 22 | char *to_free = NULL; |
25 | 23 | ||
@@ -41,23 +39,6 @@ void sq_quote_buf(struct strbuf *dst, const char *src) | |||
41 | free(to_free); | 39 | free(to_free); |
42 | } | 40 | } |
43 | 41 | ||
44 | void sq_quote_print(FILE *stream, const char *src) | ||
45 | { | ||
46 | char c; | ||
47 | |||
48 | fputc('\'', stream); | ||
49 | while ((c = *src++)) { | ||
50 | if (need_bs_quote(c)) { | ||
51 | fputs("'\\", stream); | ||
52 | fputc(c, stream); | ||
53 | fputc('\'', stream); | ||
54 | } else { | ||
55 | fputc(c, stream); | ||
56 | } | ||
57 | } | ||
58 | fputc('\'', stream); | ||
59 | } | ||
60 | |||
61 | void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen) | 42 | void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen) |
62 | { | 43 | { |
63 | int i; | 44 | int i; |
@@ -71,415 +52,3 @@ void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen) | |||
71 | die("Too many or long arguments"); | 52 | die("Too many or long arguments"); |
72 | } | 53 | } |
73 | } | 54 | } |
74 | |||
75 | char *sq_dequote_step(char *arg, char **next) | ||
76 | { | ||
77 | char *dst = arg; | ||
78 | char *src = arg; | ||
79 | char c; | ||
80 | |||
81 | if (*src != '\'') | ||
82 | return NULL; | ||
83 | for (;;) { | ||
84 | c = *++src; | ||
85 | if (!c) | ||
86 | return NULL; | ||
87 | if (c != '\'') { | ||
88 | *dst++ = c; | ||
89 | continue; | ||
90 | } | ||
91 | /* We stepped out of sq */ | ||
92 | switch (*++src) { | ||
93 | case '\0': | ||
94 | *dst = 0; | ||
95 | if (next) | ||
96 | *next = NULL; | ||
97 | return arg; | ||
98 | case '\\': | ||
99 | c = *++src; | ||
100 | if (need_bs_quote(c) && *++src == '\'') { | ||
101 | *dst++ = c; | ||
102 | continue; | ||
103 | } | ||
104 | /* Fallthrough */ | ||
105 | default: | ||
106 | if (!next || !isspace(*src)) | ||
107 | return NULL; | ||
108 | do { | ||
109 | c = *++src; | ||
110 | } while (isspace(c)); | ||
111 | *dst = 0; | ||
112 | *next = src; | ||
113 | return arg; | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | |||
118 | char *sq_dequote(char *arg) | ||
119 | { | ||
120 | return sq_dequote_step(arg, NULL); | ||
121 | } | ||
122 | |||
123 | int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc) | ||
124 | { | ||
125 | char *next = arg; | ||
126 | |||
127 | if (!*arg) | ||
128 | return 0; | ||
129 | do { | ||
130 | char *dequoted = sq_dequote_step(next, &next); | ||
131 | if (!dequoted) | ||
132 | return -1; | ||
133 | ALLOC_GROW(*argv, *nr + 1, *alloc); | ||
134 | (*argv)[(*nr)++] = dequoted; | ||
135 | } while (next); | ||
136 | |||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | /* 1 means: quote as octal | ||
141 | * 0 means: quote as octal if (quote_path_fully) | ||
142 | * -1 means: never quote | ||
143 | * c: quote as "\\c" | ||
144 | */ | ||
145 | #define X8(x) x, x, x, x, x, x, x, x | ||
146 | #define X16(x) X8(x), X8(x) | ||
147 | static signed char const sq_lookup[256] = { | ||
148 | /* 0 1 2 3 4 5 6 7 */ | ||
149 | /* 0x00 */ 1, 1, 1, 1, 1, 1, 1, 'a', | ||
150 | /* 0x08 */ 'b', 't', 'n', 'v', 'f', 'r', 1, 1, | ||
151 | /* 0x10 */ X16(1), | ||
152 | /* 0x20 */ -1, -1, '"', -1, -1, -1, -1, -1, | ||
153 | /* 0x28 */ X16(-1), X16(-1), X16(-1), | ||
154 | /* 0x58 */ -1, -1, -1, -1,'\\', -1, -1, -1, | ||
155 | /* 0x60 */ X16(-1), X8(-1), | ||
156 | /* 0x78 */ -1, -1, -1, -1, -1, -1, -1, 1, | ||
157 | /* 0x80 */ /* set to 0 */ | ||
158 | }; | ||
159 | |||
160 | static inline int sq_must_quote(char c) | ||
161 | { | ||
162 | return sq_lookup[(unsigned char)c] + quote_path_fully > 0; | ||
163 | } | ||
164 | |||
165 | /* | ||
166 | * Returns the longest prefix not needing a quote up to maxlen if | ||
167 | * positive. | ||
168 | * This stops at the first \0 because it's marked as a character | ||
169 | * needing an escape. | ||
170 | */ | ||
171 | static ssize_t next_quote_pos(const char *s, ssize_t maxlen) | ||
172 | { | ||
173 | ssize_t len; | ||
174 | |||
175 | if (maxlen < 0) { | ||
176 | for (len = 0; !sq_must_quote(s[len]); len++); | ||
177 | } else { | ||
178 | for (len = 0; len < maxlen && !sq_must_quote(s[len]); len++); | ||
179 | } | ||
180 | return len; | ||
181 | } | ||
182 | |||
183 | /* | ||
184 | * C-style name quoting. | ||
185 | * | ||
186 | * (1) if sb and fp are both NULL, inspect the input name and counts the | ||
187 | * number of bytes that are needed to hold c_style quoted version of name, | ||
188 | * counting the double quotes around it but not terminating NUL, and | ||
189 | * returns it. | ||
190 | * However, if name does not need c_style quoting, it returns 0. | ||
191 | * | ||
192 | * (2) if sb or fp are not NULL, it emits the c_style quoted version | ||
193 | * of name, enclosed with double quotes if asked and needed only. | ||
194 | * Return value is the same as in (1). | ||
195 | */ | ||
196 | static size_t quote_c_style_counted(const char *name, ssize_t maxlen, | ||
197 | struct strbuf *sb, FILE *fp, int no_dq) | ||
198 | { | ||
199 | #define EMIT(c) \ | ||
200 | do { \ | ||
201 | if (sb) strbuf_addch(sb, (c)); \ | ||
202 | if (fp) fputc((c), fp); \ | ||
203 | count++; \ | ||
204 | } while (0) | ||
205 | |||
206 | #define EMITBUF(s, l) \ | ||
207 | do { \ | ||
208 | int __ret; \ | ||
209 | if (sb) strbuf_add(sb, (s), (l)); \ | ||
210 | if (fp) __ret = fwrite((s), (l), 1, fp); \ | ||
211 | count += (l); \ | ||
212 | } while (0) | ||
213 | |||
214 | ssize_t len, count = 0; | ||
215 | const char *p = name; | ||
216 | |||
217 | for (;;) { | ||
218 | int ch; | ||
219 | |||
220 | len = next_quote_pos(p, maxlen); | ||
221 | if (len == maxlen || !p[len]) | ||
222 | break; | ||
223 | |||
224 | if (!no_dq && p == name) | ||
225 | EMIT('"'); | ||
226 | |||
227 | EMITBUF(p, len); | ||
228 | EMIT('\\'); | ||
229 | p += len; | ||
230 | ch = (unsigned char)*p++; | ||
231 | if (sq_lookup[ch] >= ' ') { | ||
232 | EMIT(sq_lookup[ch]); | ||
233 | } else { | ||
234 | EMIT(((ch >> 6) & 03) + '0'); | ||
235 | EMIT(((ch >> 3) & 07) + '0'); | ||
236 | EMIT(((ch >> 0) & 07) + '0'); | ||
237 | } | ||
238 | } | ||
239 | |||
240 | EMITBUF(p, len); | ||
241 | if (p == name) /* no ending quote needed */ | ||
242 | return 0; | ||
243 | |||
244 | if (!no_dq) | ||
245 | EMIT('"'); | ||
246 | return count; | ||
247 | } | ||
248 | |||
249 | size_t quote_c_style(const char *name, struct strbuf *sb, FILE *fp, int nodq) | ||
250 | { | ||
251 | return quote_c_style_counted(name, -1, sb, fp, nodq); | ||
252 | } | ||
253 | |||
254 | void quote_two_c_style(struct strbuf *sb, const char *prefix, const char *path, int nodq) | ||
255 | { | ||
256 | if (quote_c_style(prefix, NULL, NULL, 0) || | ||
257 | quote_c_style(path, NULL, NULL, 0)) { | ||
258 | if (!nodq) | ||
259 | strbuf_addch(sb, '"'); | ||
260 | quote_c_style(prefix, sb, NULL, 1); | ||
261 | quote_c_style(path, sb, NULL, 1); | ||
262 | if (!nodq) | ||
263 | strbuf_addch(sb, '"'); | ||
264 | } else { | ||
265 | strbuf_addstr(sb, prefix); | ||
266 | strbuf_addstr(sb, path); | ||
267 | } | ||
268 | } | ||
269 | |||
270 | void write_name_quoted(const char *name, FILE *fp, int terminator) | ||
271 | { | ||
272 | if (terminator) { | ||
273 | quote_c_style(name, NULL, fp, 0); | ||
274 | } else { | ||
275 | fputs(name, fp); | ||
276 | } | ||
277 | fputc(terminator, fp); | ||
278 | } | ||
279 | |||
280 | void write_name_quotedpfx(const char *pfx, ssize_t pfxlen, | ||
281 | const char *name, FILE *fp, int terminator) | ||
282 | { | ||
283 | int needquote = 0; | ||
284 | |||
285 | if (terminator) { | ||
286 | needquote = next_quote_pos(pfx, pfxlen) < pfxlen | ||
287 | || name[next_quote_pos(name, -1)]; | ||
288 | } | ||
289 | if (needquote) { | ||
290 | fputc('"', fp); | ||
291 | quote_c_style_counted(pfx, pfxlen, NULL, fp, 1); | ||
292 | quote_c_style(name, NULL, fp, 1); | ||
293 | fputc('"', fp); | ||
294 | } else { | ||
295 | int ret; | ||
296 | |||
297 | ret = fwrite(pfx, pfxlen, 1, fp); | ||
298 | fputs(name, fp); | ||
299 | } | ||
300 | fputc(terminator, fp); | ||
301 | } | ||
302 | |||
303 | /* quote path as relative to the given prefix */ | ||
304 | char *quote_path_relative(const char *in, int len, | ||
305 | struct strbuf *out, const char *prefix) | ||
306 | { | ||
307 | int needquote; | ||
308 | |||
309 | if (len < 0) | ||
310 | len = strlen(in); | ||
311 | |||
312 | /* "../" prefix itself does not need quoting, but "in" might. */ | ||
313 | needquote = (next_quote_pos(in, len) < len); | ||
314 | strbuf_setlen(out, 0); | ||
315 | strbuf_grow(out, len); | ||
316 | |||
317 | if (needquote) | ||
318 | strbuf_addch(out, '"'); | ||
319 | if (prefix) { | ||
320 | int off = 0; | ||
321 | while (off < len && prefix[off] && prefix[off] == in[off]) | ||
322 | if (prefix[off] == '/') { | ||
323 | prefix += off + 1; | ||
324 | in += off + 1; | ||
325 | len -= off + 1; | ||
326 | off = 0; | ||
327 | } else | ||
328 | off++; | ||
329 | |||
330 | for (; *prefix; prefix++) | ||
331 | if (*prefix == '/') | ||
332 | strbuf_addstr(out, "../"); | ||
333 | } | ||
334 | |||
335 | quote_c_style_counted (in, len, out, NULL, 1); | ||
336 | |||
337 | if (needquote) | ||
338 | strbuf_addch(out, '"'); | ||
339 | if (!out->len) | ||
340 | strbuf_addstr(out, "./"); | ||
341 | |||
342 | return out->buf; | ||
343 | } | ||
344 | |||
345 | /* | ||
346 | * C-style name unquoting. | ||
347 | * | ||
348 | * Quoted should point at the opening double quote. | ||
349 | * + Returns 0 if it was able to unquote the string properly, and appends the | ||
350 | * result in the strbuf `sb'. | ||
351 | * + Returns -1 in case of error, and doesn't touch the strbuf. Though note | ||
352 | * that this function will allocate memory in the strbuf, so calling | ||
353 | * strbuf_release is mandatory whichever result unquote_c_style returns. | ||
354 | * | ||
355 | * Updates endp pointer to point at one past the ending double quote if given. | ||
356 | */ | ||
357 | int unquote_c_style(struct strbuf *sb, const char *quoted, const char **endp) | ||
358 | { | ||
359 | size_t oldlen = sb->len, len; | ||
360 | int ch, ac; | ||
361 | |||
362 | if (*quoted++ != '"') | ||
363 | return -1; | ||
364 | |||
365 | for (;;) { | ||
366 | len = strcspn(quoted, "\"\\"); | ||
367 | strbuf_add(sb, quoted, len); | ||
368 | quoted += len; | ||
369 | |||
370 | switch (*quoted++) { | ||
371 | case '"': | ||
372 | if (endp) | ||
373 | *endp = quoted; | ||
374 | return 0; | ||
375 | case '\\': | ||
376 | break; | ||
377 | default: | ||
378 | goto error; | ||
379 | } | ||
380 | |||
381 | switch ((ch = *quoted++)) { | ||
382 | case 'a': ch = '\a'; break; | ||
383 | case 'b': ch = '\b'; break; | ||
384 | case 'f': ch = '\f'; break; | ||
385 | case 'n': ch = '\n'; break; | ||
386 | case 'r': ch = '\r'; break; | ||
387 | case 't': ch = '\t'; break; | ||
388 | case 'v': ch = '\v'; break; | ||
389 | |||
390 | case '\\': case '"': | ||
391 | break; /* verbatim */ | ||
392 | |||
393 | /* octal values with first digit over 4 overflow */ | ||
394 | case '0': case '1': case '2': case '3': | ||
395 | ac = ((ch - '0') << 6); | ||
396 | if ((ch = *quoted++) < '0' || '7' < ch) | ||
397 | goto error; | ||
398 | ac |= ((ch - '0') << 3); | ||
399 | if ((ch = *quoted++) < '0' || '7' < ch) | ||
400 | goto error; | ||
401 | ac |= (ch - '0'); | ||
402 | ch = ac; | ||
403 | break; | ||
404 | default: | ||
405 | goto error; | ||
406 | } | ||
407 | strbuf_addch(sb, ch); | ||
408 | } | ||
409 | |||
410 | error: | ||
411 | strbuf_setlen(sb, oldlen); | ||
412 | return -1; | ||
413 | } | ||
414 | |||
415 | /* quoting as a string literal for other languages */ | ||
416 | |||
417 | void perl_quote_print(FILE *stream, const char *src) | ||
418 | { | ||
419 | const char sq = '\''; | ||
420 | const char bq = '\\'; | ||
421 | char c; | ||
422 | |||
423 | fputc(sq, stream); | ||
424 | while ((c = *src++)) { | ||
425 | if (c == sq || c == bq) | ||
426 | fputc(bq, stream); | ||
427 | fputc(c, stream); | ||
428 | } | ||
429 | fputc(sq, stream); | ||
430 | } | ||
431 | |||
432 | void python_quote_print(FILE *stream, const char *src) | ||
433 | { | ||
434 | const char sq = '\''; | ||
435 | const char bq = '\\'; | ||
436 | const char nl = '\n'; | ||
437 | char c; | ||
438 | |||
439 | fputc(sq, stream); | ||
440 | while ((c = *src++)) { | ||
441 | if (c == nl) { | ||
442 | fputc(bq, stream); | ||
443 | fputc('n', stream); | ||
444 | continue; | ||
445 | } | ||
446 | if (c == sq || c == bq) | ||
447 | fputc(bq, stream); | ||
448 | fputc(c, stream); | ||
449 | } | ||
450 | fputc(sq, stream); | ||
451 | } | ||
452 | |||
453 | void tcl_quote_print(FILE *stream, const char *src) | ||
454 | { | ||
455 | char c; | ||
456 | |||
457 | fputc('"', stream); | ||
458 | while ((c = *src++)) { | ||
459 | switch (c) { | ||
460 | case '[': case ']': | ||
461 | case '{': case '}': | ||
462 | case '$': case '\\': case '"': | ||
463 | fputc('\\', stream); | ||
464 | default: | ||
465 | fputc(c, stream); | ||
466 | break; | ||
467 | case '\f': | ||
468 | fputs("\\f", stream); | ||
469 | break; | ||
470 | case '\r': | ||
471 | fputs("\\r", stream); | ||
472 | break; | ||
473 | case '\n': | ||
474 | fputs("\\n", stream); | ||
475 | break; | ||
476 | case '\t': | ||
477 | fputs("\\t", stream); | ||
478 | break; | ||
479 | case '\v': | ||
480 | fputs("\\v", stream); | ||
481 | break; | ||
482 | } | ||
483 | } | ||
484 | fputc('"', stream); | ||
485 | } | ||
diff --git a/tools/perf/util/quote.h b/tools/perf/util/quote.h index b6a019733919..172889ea234f 100644 --- a/tools/perf/util/quote.h +++ b/tools/perf/util/quote.h | |||
@@ -22,47 +22,8 @@ | |||
22 | * | 22 | * |
23 | * Note that the above examples leak memory! Remember to free result from | 23 | * Note that the above examples leak memory! Remember to free result from |
24 | * sq_quote() in a real application. | 24 | * sq_quote() in a real application. |
25 | * | ||
26 | * sq_quote_buf() writes to an existing buffer of specified size; it | ||
27 | * will return the number of characters that would have been written | ||
28 | * excluding the final null regardless of the buffer size. | ||
29 | */ | 25 | */ |
30 | 26 | ||
31 | extern void sq_quote_print(FILE *stream, const char *src); | ||
32 | |||
33 | extern void sq_quote_buf(struct strbuf *, const char *src); | ||
34 | extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen); | 27 | extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen); |
35 | 28 | ||
36 | /* This unwraps what sq_quote() produces in place, but returns | ||
37 | * NULL if the input does not look like what sq_quote would have | ||
38 | * produced. | ||
39 | */ | ||
40 | extern char *sq_dequote(char *); | ||
41 | |||
42 | /* | ||
43 | * Same as the above, but can be used to unwrap many arguments in the | ||
44 | * same string separated by space. "next" is changed to point to the | ||
45 | * next argument that should be passed as first parameter. When there | ||
46 | * is no more argument to be dequoted, "next" is updated to point to NULL. | ||
47 | */ | ||
48 | extern char *sq_dequote_step(char *arg, char **next); | ||
49 | extern int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc); | ||
50 | |||
51 | extern int unquote_c_style(struct strbuf *, const char *quoted, const char **endp); | ||
52 | extern size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq); | ||
53 | extern void quote_two_c_style(struct strbuf *, const char *, const char *, int); | ||
54 | |||
55 | extern void write_name_quoted(const char *name, FILE *, int terminator); | ||
56 | extern void write_name_quotedpfx(const char *pfx, ssize_t pfxlen, | ||
57 | const char *name, FILE *, int terminator); | ||
58 | |||
59 | /* quote path as relative to the given prefix */ | ||
60 | char *quote_path_relative(const char *in, int len, | ||
61 | struct strbuf *out, const char *prefix); | ||
62 | |||
63 | /* quoting as a string literal for other languages */ | ||
64 | extern void perl_quote_print(FILE *stream, const char *src); | ||
65 | extern void python_quote_print(FILE *stream, const char *src); | ||
66 | extern void tcl_quote_print(FILE *stream, const char *src); | ||
67 | |||
68 | #endif /* __PERF_QUOTE_H */ | 29 | #endif /* __PERF_QUOTE_H */ |
diff --git a/tools/perf/util/run-command.c b/tools/perf/util/run-command.c index 2b615acf94d7..da8e9b285f51 100644 --- a/tools/perf/util/run-command.c +++ b/tools/perf/util/run-command.c | |||
@@ -212,93 +212,3 @@ int run_command_v_opt(const char **argv, int opt) | |||
212 | prepare_run_command_v_opt(&cmd, argv, opt); | 212 | prepare_run_command_v_opt(&cmd, argv, opt); |
213 | return run_command(&cmd); | 213 | return run_command(&cmd); |
214 | } | 214 | } |
215 | |||
216 | int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const char *const *env) | ||
217 | { | ||
218 | struct child_process cmd; | ||
219 | prepare_run_command_v_opt(&cmd, argv, opt); | ||
220 | cmd.dir = dir; | ||
221 | cmd.env = env; | ||
222 | return run_command(&cmd); | ||
223 | } | ||
224 | |||
225 | int start_async(struct async *async) | ||
226 | { | ||
227 | int pipe_out[2]; | ||
228 | |||
229 | if (pipe(pipe_out) < 0) | ||
230 | return error("cannot create pipe: %s", strerror(errno)); | ||
231 | async->out = pipe_out[0]; | ||
232 | |||
233 | /* Flush stdio before fork() to avoid cloning buffers */ | ||
234 | fflush(NULL); | ||
235 | |||
236 | async->pid = fork(); | ||
237 | if (async->pid < 0) { | ||
238 | error("fork (async) failed: %s", strerror(errno)); | ||
239 | close_pair(pipe_out); | ||
240 | return -1; | ||
241 | } | ||
242 | if (!async->pid) { | ||
243 | close(pipe_out[0]); | ||
244 | exit(!!async->proc(pipe_out[1], async->data)); | ||
245 | } | ||
246 | close(pipe_out[1]); | ||
247 | |||
248 | return 0; | ||
249 | } | ||
250 | |||
251 | int finish_async(struct async *async) | ||
252 | { | ||
253 | int ret = 0; | ||
254 | |||
255 | if (wait_or_whine(async->pid)) | ||
256 | ret = error("waitpid (async) failed"); | ||
257 | |||
258 | return ret; | ||
259 | } | ||
260 | |||
261 | int run_hook(const char *index_file, const char *name, ...) | ||
262 | { | ||
263 | struct child_process hook; | ||
264 | const char **argv = NULL, *env[2]; | ||
265 | char idx[PATH_MAX]; | ||
266 | va_list args; | ||
267 | int ret; | ||
268 | size_t i = 0, alloc = 0; | ||
269 | |||
270 | if (access(perf_path("hooks/%s", name), X_OK) < 0) | ||
271 | return 0; | ||
272 | |||
273 | va_start(args, name); | ||
274 | ALLOC_GROW(argv, i + 1, alloc); | ||
275 | argv[i++] = perf_path("hooks/%s", name); | ||
276 | while (argv[i-1]) { | ||
277 | ALLOC_GROW(argv, i + 1, alloc); | ||
278 | argv[i++] = va_arg(args, const char *); | ||
279 | } | ||
280 | va_end(args); | ||
281 | |||
282 | memset(&hook, 0, sizeof(hook)); | ||
283 | hook.argv = argv; | ||
284 | hook.no_stdin = 1; | ||
285 | hook.stdout_to_stderr = 1; | ||
286 | if (index_file) { | ||
287 | snprintf(idx, sizeof(idx), "PERF_INDEX_FILE=%s", index_file); | ||
288 | env[0] = idx; | ||
289 | env[1] = NULL; | ||
290 | hook.env = env; | ||
291 | } | ||
292 | |||
293 | ret = start_command(&hook); | ||
294 | free(argv); | ||
295 | if (ret) { | ||
296 | warning("Could not spawn %s", argv[0]); | ||
297 | return ret; | ||
298 | } | ||
299 | ret = finish_command(&hook); | ||
300 | if (ret == -ERR_RUN_COMMAND_WAITPID_SIGNAL) | ||
301 | warning("%s exited due to uncaught signal", argv[0]); | ||
302 | |||
303 | return ret; | ||
304 | } | ||
diff --git a/tools/perf/util/run-command.h b/tools/perf/util/run-command.h index d79028727ce2..1ef264d5069c 100644 --- a/tools/perf/util/run-command.h +++ b/tools/perf/util/run-command.h | |||
@@ -50,39 +50,9 @@ int start_command(struct child_process *); | |||
50 | int finish_command(struct child_process *); | 50 | int finish_command(struct child_process *); |
51 | int run_command(struct child_process *); | 51 | int run_command(struct child_process *); |
52 | 52 | ||
53 | extern int run_hook(const char *index_file, const char *name, ...); | ||
54 | |||
55 | #define RUN_COMMAND_NO_STDIN 1 | 53 | #define RUN_COMMAND_NO_STDIN 1 |
56 | #define RUN_PERF_CMD 2 /*If this is to be perf sub-command */ | 54 | #define RUN_PERF_CMD 2 /*If this is to be perf sub-command */ |
57 | #define RUN_COMMAND_STDOUT_TO_STDERR 4 | 55 | #define RUN_COMMAND_STDOUT_TO_STDERR 4 |
58 | int run_command_v_opt(const char **argv, int opt); | 56 | int run_command_v_opt(const char **argv, int opt); |
59 | 57 | ||
60 | /* | ||
61 | * env (the environment) is to be formatted like environ: "VAR=VALUE". | ||
62 | * To unset an environment variable use just "VAR". | ||
63 | */ | ||
64 | int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const char *const *env); | ||
65 | |||
66 | /* | ||
67 | * The purpose of the following functions is to feed a pipe by running | ||
68 | * a function asynchronously and providing output that the caller reads. | ||
69 | * | ||
70 | * It is expected that no synchronization and mutual exclusion between | ||
71 | * the caller and the feed function is necessary so that the function | ||
72 | * can run in a thread without interfering with the caller. | ||
73 | */ | ||
74 | struct async { | ||
75 | /* | ||
76 | * proc writes to fd and closes it; | ||
77 | * returns 0 on success, non-zero on failure | ||
78 | */ | ||
79 | int (*proc)(int fd, void *data); | ||
80 | void *data; | ||
81 | int out; /* caller reads from here and closes it */ | ||
82 | pid_t pid; | ||
83 | }; | ||
84 | |||
85 | int start_async(struct async *async); | ||
86 | int finish_async(struct async *async); | ||
87 | |||
88 | #endif /* __PERF_RUN_COMMAND_H */ | 58 | #endif /* __PERF_RUN_COMMAND_H */ |
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 25bfca4f10f0..8f83a1835766 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <byteswap.h> | 5 | #include <byteswap.h> |
6 | #include <unistd.h> | 6 | #include <unistd.h> |
7 | #include <sys/types.h> | 7 | #include <sys/types.h> |
8 | #include <sys/mman.h> | ||
8 | 9 | ||
9 | #include "session.h" | 10 | #include "session.h" |
10 | #include "sort.h" | 11 | #include "sort.h" |
@@ -894,3 +895,10 @@ size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp) | |||
894 | __dsos__fprintf(&self->host_machine.user_dsos, fp) + | 895 | __dsos__fprintf(&self->host_machine.user_dsos, fp) + |
895 | machines__fprintf_dsos(&self->machines, fp); | 896 | machines__fprintf_dsos(&self->machines, fp); |
896 | } | 897 | } |
898 | |||
899 | size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp, | ||
900 | bool with_hits) | ||
901 | { | ||
902 | size_t ret = machine__fprintf_dsos_buildid(&self->host_machine, fp, with_hits); | ||
903 | return ret + machines__fprintf_dsos_buildid(&self->machines, fp, with_hits); | ||
904 | } | ||
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index e7fce486ebe2..55c6881b218d 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h | |||
@@ -132,12 +132,8 @@ void perf_session__process_machines(struct perf_session *self, | |||
132 | 132 | ||
133 | size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp); | 133 | size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp); |
134 | 134 | ||
135 | static inline | 135 | size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, |
136 | size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp, | 136 | FILE *fp, bool with_hits); |
137 | bool with_hits) | ||
138 | { | ||
139 | return machines__fprintf_dsos_buildid(&self->machines, fp, with_hits); | ||
140 | } | ||
141 | 137 | ||
142 | static inline | 138 | static inline |
143 | size_t perf_session__fprintf_nr_events(struct perf_session *self, FILE *fp) | 139 | size_t perf_session__fprintf_nr_events(struct perf_session *self, FILE *fp) |
diff --git a/tools/perf/util/sigchain.c b/tools/perf/util/sigchain.c index 1118b99e57d3..ba785e9b1841 100644 --- a/tools/perf/util/sigchain.c +++ b/tools/perf/util/sigchain.c | |||
@@ -16,7 +16,7 @@ static void check_signum(int sig) | |||
16 | die("BUG: signal out of range: %d", sig); | 16 | die("BUG: signal out of range: %d", sig); |
17 | } | 17 | } |
18 | 18 | ||
19 | int sigchain_push(int sig, sigchain_fun f) | 19 | static int sigchain_push(int sig, sigchain_fun f) |
20 | { | 20 | { |
21 | struct sigchain_signal *s = signals + sig; | 21 | struct sigchain_signal *s = signals + sig; |
22 | check_signum(sig); | 22 | check_signum(sig); |
diff --git a/tools/perf/util/sigchain.h b/tools/perf/util/sigchain.h index 1a53c11265fd..959d64eb5557 100644 --- a/tools/perf/util/sigchain.h +++ b/tools/perf/util/sigchain.h | |||
@@ -3,7 +3,6 @@ | |||
3 | 3 | ||
4 | typedef void (*sigchain_fun)(int); | 4 | typedef void (*sigchain_fun)(int); |
5 | 5 | ||
6 | int sigchain_push(int sig, sigchain_fun f); | ||
7 | int sigchain_pop(int sig); | 6 | int sigchain_pop(int sig); |
8 | 7 | ||
9 | void sigchain_push_common(sigchain_fun f); | 8 | void sigchain_push_common(sigchain_fun f); |
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c index 5249d5a1b0c2..92e068517c1a 100644 --- a/tools/perf/util/strbuf.c +++ b/tools/perf/util/strbuf.c | |||
@@ -41,16 +41,6 @@ char *strbuf_detach(struct strbuf *sb, size_t *sz) | |||
41 | return res; | 41 | return res; |
42 | } | 42 | } |
43 | 43 | ||
44 | void strbuf_attach(struct strbuf *sb, void *buf, size_t len, size_t alloc) | ||
45 | { | ||
46 | strbuf_release(sb); | ||
47 | sb->buf = buf; | ||
48 | sb->len = len; | ||
49 | sb->alloc = alloc; | ||
50 | strbuf_grow(sb, 0); | ||
51 | sb->buf[sb->len] = '\0'; | ||
52 | } | ||
53 | |||
54 | void strbuf_grow(struct strbuf *sb, size_t extra) | 44 | void strbuf_grow(struct strbuf *sb, size_t extra) |
55 | { | 45 | { |
56 | if (sb->len + extra + 1 <= sb->len) | 46 | if (sb->len + extra + 1 <= sb->len) |
@@ -60,94 +50,7 @@ void strbuf_grow(struct strbuf *sb, size_t extra) | |||
60 | ALLOC_GROW(sb->buf, sb->len + extra + 1, sb->alloc); | 50 | ALLOC_GROW(sb->buf, sb->len + extra + 1, sb->alloc); |
61 | } | 51 | } |
62 | 52 | ||
63 | void strbuf_trim(struct strbuf *sb) | 53 | static void strbuf_splice(struct strbuf *sb, size_t pos, size_t len, |
64 | { | ||
65 | char *b = sb->buf; | ||
66 | while (sb->len > 0 && isspace((unsigned char)sb->buf[sb->len - 1])) | ||
67 | sb->len--; | ||
68 | while (sb->len > 0 && isspace(*b)) { | ||
69 | b++; | ||
70 | sb->len--; | ||
71 | } | ||
72 | memmove(sb->buf, b, sb->len); | ||
73 | sb->buf[sb->len] = '\0'; | ||
74 | } | ||
75 | void strbuf_rtrim(struct strbuf *sb) | ||
76 | { | ||
77 | while (sb->len > 0 && isspace((unsigned char)sb->buf[sb->len - 1])) | ||
78 | sb->len--; | ||
79 | sb->buf[sb->len] = '\0'; | ||
80 | } | ||
81 | |||
82 | void strbuf_ltrim(struct strbuf *sb) | ||
83 | { | ||
84 | char *b = sb->buf; | ||
85 | while (sb->len > 0 && isspace(*b)) { | ||
86 | b++; | ||
87 | sb->len--; | ||
88 | } | ||
89 | memmove(sb->buf, b, sb->len); | ||
90 | sb->buf[sb->len] = '\0'; | ||
91 | } | ||
92 | |||
93 | void strbuf_tolower(struct strbuf *sb) | ||
94 | { | ||
95 | unsigned int i; | ||
96 | |||
97 | for (i = 0; i < sb->len; i++) | ||
98 | sb->buf[i] = tolower(sb->buf[i]); | ||
99 | } | ||
100 | |||
101 | struct strbuf **strbuf_split(const struct strbuf *sb, int delim) | ||
102 | { | ||
103 | int alloc = 2, pos = 0; | ||
104 | char *n, *p; | ||
105 | struct strbuf **ret; | ||
106 | struct strbuf *t; | ||
107 | |||
108 | ret = calloc(alloc, sizeof(struct strbuf *)); | ||
109 | p = n = sb->buf; | ||
110 | while (n < sb->buf + sb->len) { | ||
111 | int len; | ||
112 | n = memchr(n, delim, sb->len - (n - sb->buf)); | ||
113 | if (pos + 1 >= alloc) { | ||
114 | alloc = alloc * 2; | ||
115 | ret = realloc(ret, sizeof(struct strbuf *) * alloc); | ||
116 | } | ||
117 | if (!n) | ||
118 | n = sb->buf + sb->len - 1; | ||
119 | len = n - p + 1; | ||
120 | t = malloc(sizeof(struct strbuf)); | ||
121 | strbuf_init(t, len); | ||
122 | strbuf_add(t, p, len); | ||
123 | ret[pos] = t; | ||
124 | ret[++pos] = NULL; | ||
125 | p = ++n; | ||
126 | } | ||
127 | return ret; | ||
128 | } | ||
129 | |||
130 | void strbuf_list_free(struct strbuf **sbs) | ||
131 | { | ||
132 | struct strbuf **s = sbs; | ||
133 | |||
134 | while (*s) { | ||
135 | strbuf_release(*s); | ||
136 | free(*s++); | ||
137 | } | ||
138 | free(sbs); | ||
139 | } | ||
140 | |||
141 | int strbuf_cmp(const struct strbuf *a, const struct strbuf *b) | ||
142 | { | ||
143 | int len = a->len < b->len ? a->len: b->len; | ||
144 | int cmp = memcmp(a->buf, b->buf, len); | ||
145 | if (cmp) | ||
146 | return cmp; | ||
147 | return a->len < b->len ? -1: a->len != b->len; | ||
148 | } | ||
149 | |||
150 | void strbuf_splice(struct strbuf *sb, size_t pos, size_t len, | ||
151 | const void *data, size_t dlen) | 54 | const void *data, size_t dlen) |
152 | { | 55 | { |
153 | if (pos + len < pos) | 56 | if (pos + len < pos) |
@@ -166,11 +69,6 @@ void strbuf_splice(struct strbuf *sb, size_t pos, size_t len, | |||
166 | strbuf_setlen(sb, sb->len + dlen - len); | 69 | strbuf_setlen(sb, sb->len + dlen - len); |
167 | } | 70 | } |
168 | 71 | ||
169 | void strbuf_insert(struct strbuf *sb, size_t pos, const void *data, size_t len) | ||
170 | { | ||
171 | strbuf_splice(sb, pos, 0, data, len); | ||
172 | } | ||
173 | |||
174 | void strbuf_remove(struct strbuf *sb, size_t pos, size_t len) | 72 | void strbuf_remove(struct strbuf *sb, size_t pos, size_t len) |
175 | { | 73 | { |
176 | strbuf_splice(sb, pos, len, NULL, 0); | 74 | strbuf_splice(sb, pos, len, NULL, 0); |
@@ -183,13 +81,6 @@ void strbuf_add(struct strbuf *sb, const void *data, size_t len) | |||
183 | strbuf_setlen(sb, sb->len + len); | 81 | strbuf_setlen(sb, sb->len + len); |
184 | } | 82 | } |
185 | 83 | ||
186 | void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len) | ||
187 | { | ||
188 | strbuf_grow(sb, len); | ||
189 | memcpy(sb->buf + sb->len, sb->buf + pos, len); | ||
190 | strbuf_setlen(sb, sb->len + len); | ||
191 | } | ||
192 | |||
193 | void strbuf_addf(struct strbuf *sb, const char *fmt, ...) | 84 | void strbuf_addf(struct strbuf *sb, const char *fmt, ...) |
194 | { | 85 | { |
195 | int len; | 86 | int len; |
@@ -214,57 +105,6 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...) | |||
214 | strbuf_setlen(sb, sb->len + len); | 105 | strbuf_setlen(sb, sb->len + len); |
215 | } | 106 | } |
216 | 107 | ||
217 | void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn, | ||
218 | void *context) | ||
219 | { | ||
220 | for (;;) { | ||
221 | const char *percent; | ||
222 | size_t consumed; | ||
223 | |||
224 | percent = strchrnul(format, '%'); | ||
225 | strbuf_add(sb, format, percent - format); | ||
226 | if (!*percent) | ||
227 | break; | ||
228 | format = percent + 1; | ||
229 | |||
230 | consumed = fn(sb, format, context); | ||
231 | if (consumed) | ||
232 | format += consumed; | ||
233 | else | ||
234 | strbuf_addch(sb, '%'); | ||
235 | } | ||
236 | } | ||
237 | |||
238 | size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder, | ||
239 | void *context) | ||
240 | { | ||
241 | struct strbuf_expand_dict_entry *e = context; | ||
242 | size_t len; | ||
243 | |||
244 | for (; e->placeholder && (len = strlen(e->placeholder)); e++) { | ||
245 | if (!strncmp(placeholder, e->placeholder, len)) { | ||
246 | if (e->value) | ||
247 | strbuf_addstr(sb, e->value); | ||
248 | return len; | ||
249 | } | ||
250 | } | ||
251 | return 0; | ||
252 | } | ||
253 | |||
254 | size_t strbuf_fread(struct strbuf *sb, size_t size, FILE *f) | ||
255 | { | ||
256 | size_t res; | ||
257 | size_t oldalloc = sb->alloc; | ||
258 | |||
259 | strbuf_grow(sb, size); | ||
260 | res = fread(sb->buf + sb->len, 1, size, f); | ||
261 | if (res > 0) | ||
262 | strbuf_setlen(sb, sb->len + res); | ||
263 | else if (oldalloc == 0) | ||
264 | strbuf_release(sb); | ||
265 | return res; | ||
266 | } | ||
267 | |||
268 | ssize_t strbuf_read(struct strbuf *sb, int fd, ssize_t hint) | 108 | ssize_t strbuf_read(struct strbuf *sb, int fd, ssize_t hint) |
269 | { | 109 | { |
270 | size_t oldlen = sb->len; | 110 | size_t oldlen = sb->len; |
@@ -291,70 +131,3 @@ ssize_t strbuf_read(struct strbuf *sb, int fd, ssize_t hint) | |||
291 | sb->buf[sb->len] = '\0'; | 131 | sb->buf[sb->len] = '\0'; |
292 | return sb->len - oldlen; | 132 | return sb->len - oldlen; |
293 | } | 133 | } |
294 | |||
295 | #define STRBUF_MAXLINK (2*PATH_MAX) | ||
296 | |||
297 | int strbuf_readlink(struct strbuf *sb, const char *path, ssize_t hint) | ||
298 | { | ||
299 | size_t oldalloc = sb->alloc; | ||
300 | |||
301 | if (hint < 32) | ||
302 | hint = 32; | ||
303 | |||
304 | while (hint < STRBUF_MAXLINK) { | ||
305 | ssize_t len; | ||
306 | |||
307 | strbuf_grow(sb, hint); | ||
308 | len = readlink(path, sb->buf, hint); | ||
309 | if (len < 0) { | ||
310 | if (errno != ERANGE) | ||
311 | break; | ||
312 | } else if (len < hint) { | ||
313 | strbuf_setlen(sb, len); | ||
314 | return 0; | ||
315 | } | ||
316 | |||
317 | /* .. the buffer was too small - try again */ | ||
318 | hint *= 2; | ||
319 | } | ||
320 | if (oldalloc == 0) | ||
321 | strbuf_release(sb); | ||
322 | return -1; | ||
323 | } | ||
324 | |||
325 | int strbuf_getline(struct strbuf *sb, FILE *fp, int term) | ||
326 | { | ||
327 | int ch; | ||
328 | |||
329 | strbuf_grow(sb, 0); | ||
330 | if (feof(fp)) | ||
331 | return EOF; | ||
332 | |||
333 | strbuf_reset(sb); | ||
334 | while ((ch = fgetc(fp)) != EOF) { | ||
335 | if (ch == term) | ||
336 | break; | ||
337 | strbuf_grow(sb, 1); | ||
338 | sb->buf[sb->len++] = ch; | ||
339 | } | ||
340 | if (ch == EOF && sb->len == 0) | ||
341 | return EOF; | ||
342 | |||
343 | sb->buf[sb->len] = '\0'; | ||
344 | return 0; | ||
345 | } | ||
346 | |||
347 | int strbuf_read_file(struct strbuf *sb, const char *path, ssize_t hint) | ||
348 | { | ||
349 | int fd, len; | ||
350 | |||
351 | fd = open(path, O_RDONLY); | ||
352 | if (fd < 0) | ||
353 | return -1; | ||
354 | len = strbuf_read(sb, fd, hint); | ||
355 | close(fd); | ||
356 | if (len < 0) | ||
357 | return -1; | ||
358 | |||
359 | return len; | ||
360 | } | ||
diff --git a/tools/perf/util/strbuf.h b/tools/perf/util/strbuf.h index a3d121d6c83e..436ac319f6c7 100644 --- a/tools/perf/util/strbuf.h +++ b/tools/perf/util/strbuf.h | |||
@@ -53,12 +53,6 @@ struct strbuf { | |||
53 | extern void strbuf_init(struct strbuf *buf, ssize_t hint); | 53 | extern void strbuf_init(struct strbuf *buf, ssize_t hint); |
54 | extern void strbuf_release(struct strbuf *); | 54 | extern void strbuf_release(struct strbuf *); |
55 | extern char *strbuf_detach(struct strbuf *, size_t *); | 55 | extern char *strbuf_detach(struct strbuf *, size_t *); |
56 | extern void strbuf_attach(struct strbuf *, void *, size_t, size_t); | ||
57 | static inline void strbuf_swap(struct strbuf *a, struct strbuf *b) { | ||
58 | struct strbuf tmp = *a; | ||
59 | *a = *b; | ||
60 | *b = tmp; | ||
61 | } | ||
62 | 56 | ||
63 | /*----- strbuf size related -----*/ | 57 | /*----- strbuf size related -----*/ |
64 | static inline ssize_t strbuf_avail(const struct strbuf *sb) { | 58 | static inline ssize_t strbuf_avail(const struct strbuf *sb) { |
@@ -74,17 +68,6 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len) { | |||
74 | sb->len = len; | 68 | sb->len = len; |
75 | sb->buf[len] = '\0'; | 69 | sb->buf[len] = '\0'; |
76 | } | 70 | } |
77 | #define strbuf_reset(sb) strbuf_setlen(sb, 0) | ||
78 | |||
79 | /*----- content related -----*/ | ||
80 | extern void strbuf_trim(struct strbuf *); | ||
81 | extern void strbuf_rtrim(struct strbuf *); | ||
82 | extern void strbuf_ltrim(struct strbuf *); | ||
83 | extern int strbuf_cmp(const struct strbuf *, const struct strbuf *); | ||
84 | extern void strbuf_tolower(struct strbuf *); | ||
85 | |||
86 | extern struct strbuf **strbuf_split(const struct strbuf *, int delim); | ||
87 | extern void strbuf_list_free(struct strbuf **); | ||
88 | 71 | ||
89 | /*----- add data in your buffer -----*/ | 72 | /*----- add data in your buffer -----*/ |
90 | static inline void strbuf_addch(struct strbuf *sb, int c) { | 73 | static inline void strbuf_addch(struct strbuf *sb, int c) { |
@@ -93,45 +76,17 @@ static inline void strbuf_addch(struct strbuf *sb, int c) { | |||
93 | sb->buf[sb->len] = '\0'; | 76 | sb->buf[sb->len] = '\0'; |
94 | } | 77 | } |
95 | 78 | ||
96 | extern void strbuf_insert(struct strbuf *, size_t pos, const void *, size_t); | ||
97 | extern void strbuf_remove(struct strbuf *, size_t pos, size_t len); | 79 | extern void strbuf_remove(struct strbuf *, size_t pos, size_t len); |
98 | 80 | ||
99 | /* splice pos..pos+len with given data */ | ||
100 | extern void strbuf_splice(struct strbuf *, size_t pos, size_t len, | ||
101 | const void *, size_t); | ||
102 | |||
103 | extern void strbuf_add(struct strbuf *, const void *, size_t); | 81 | extern void strbuf_add(struct strbuf *, const void *, size_t); |
104 | static inline void strbuf_addstr(struct strbuf *sb, const char *s) { | 82 | static inline void strbuf_addstr(struct strbuf *sb, const char *s) { |
105 | strbuf_add(sb, s, strlen(s)); | 83 | strbuf_add(sb, s, strlen(s)); |
106 | } | 84 | } |
107 | static inline void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2) { | ||
108 | strbuf_add(sb, sb2->buf, sb2->len); | ||
109 | } | ||
110 | extern void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len); | ||
111 | |||
112 | typedef size_t (*expand_fn_t) (struct strbuf *sb, const char *placeholder, void *context); | ||
113 | extern void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn, void *context); | ||
114 | struct strbuf_expand_dict_entry { | ||
115 | const char *placeholder; | ||
116 | const char *value; | ||
117 | }; | ||
118 | extern size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder, void *context); | ||
119 | 85 | ||
120 | __attribute__((format(printf,2,3))) | 86 | __attribute__((format(printf,2,3))) |
121 | extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...); | 87 | extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...); |
122 | 88 | ||
123 | extern size_t strbuf_fread(struct strbuf *, size_t, FILE *); | ||
124 | /* XXX: if read fails, any partial read is undone */ | 89 | /* XXX: if read fails, any partial read is undone */ |
125 | extern ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint); | 90 | extern ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint); |
126 | extern int strbuf_read_file(struct strbuf *sb, const char *path, ssize_t hint); | ||
127 | extern int strbuf_readlink(struct strbuf *sb, const char *path, ssize_t hint); | ||
128 | |||
129 | extern int strbuf_getline(struct strbuf *, FILE *, int); | ||
130 | |||
131 | extern void stripspace(struct strbuf *buf, int skip_comments); | ||
132 | extern int launch_editor(const char *path, struct strbuf *buffer, const char *const *env); | ||
133 | |||
134 | extern int strbuf_branchname(struct strbuf *sb, const char *name); | ||
135 | extern int strbuf_check_branch_ref(struct strbuf *sb, const char *name); | ||
136 | 91 | ||
137 | #endif /* __PERF_STRBUF_H */ | 92 | #endif /* __PERF_STRBUF_H */ |
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index a06131f6259a..aaa51ba147df 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <sys/param.h> | 11 | #include <sys/param.h> |
12 | #include <fcntl.h> | 12 | #include <fcntl.h> |
13 | #include <unistd.h> | 13 | #include <unistd.h> |
14 | #include "build-id.h" | ||
14 | #include "symbol.h" | 15 | #include "symbol.h" |
15 | #include "strlist.h" | 16 | #include "strlist.h" |
16 | 17 | ||
@@ -1131,6 +1132,10 @@ bool __dsos__read_build_ids(struct list_head *head, bool with_hits) | |||
1131 | list_for_each_entry(pos, head, node) { | 1132 | list_for_each_entry(pos, head, node) { |
1132 | if (with_hits && !pos->hit) | 1133 | if (with_hits && !pos->hit) |
1133 | continue; | 1134 | continue; |
1135 | if (pos->has_build_id) { | ||
1136 | have_build_id = true; | ||
1137 | continue; | ||
1138 | } | ||
1134 | if (filename__read_build_id(pos->long_name, pos->build_id, | 1139 | if (filename__read_build_id(pos->long_name, pos->build_id, |
1135 | sizeof(pos->build_id)) > 0) { | 1140 | sizeof(pos->build_id)) > 0) { |
1136 | have_build_id = true; | 1141 | have_build_id = true; |
@@ -1289,7 +1294,6 @@ int dso__load(struct dso *self, struct map *map, symbol_filter_t filter) | |||
1289 | int size = PATH_MAX; | 1294 | int size = PATH_MAX; |
1290 | char *name; | 1295 | char *name; |
1291 | u8 build_id[BUILD_ID_SIZE]; | 1296 | u8 build_id[BUILD_ID_SIZE]; |
1292 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; | ||
1293 | int ret = -1; | 1297 | int ret = -1; |
1294 | int fd; | 1298 | int fd; |
1295 | struct machine *machine; | 1299 | struct machine *machine; |
@@ -1321,15 +1325,8 @@ int dso__load(struct dso *self, struct map *map, symbol_filter_t filter) | |||
1321 | } | 1325 | } |
1322 | 1326 | ||
1323 | self->origin = DSO__ORIG_BUILD_ID_CACHE; | 1327 | self->origin = DSO__ORIG_BUILD_ID_CACHE; |
1324 | 1328 | if (dso__build_id_filename(self, name, size) != NULL) | |
1325 | if (self->has_build_id) { | ||
1326 | build_id__sprintf(self->build_id, sizeof(self->build_id), | ||
1327 | build_id_hex); | ||
1328 | snprintf(name, size, "%s/%s/.build-id/%.2s/%s", | ||
1329 | getenv("HOME"), DEBUG_CACHE_DIR, | ||
1330 | build_id_hex, build_id_hex + 2); | ||
1331 | goto open_file; | 1329 | goto open_file; |
1332 | } | ||
1333 | more: | 1330 | more: |
1334 | do { | 1331 | do { |
1335 | self->origin++; | 1332 | self->origin++; |
@@ -1345,6 +1342,7 @@ more: | |||
1345 | case DSO__ORIG_BUILDID: | 1342 | case DSO__ORIG_BUILDID: |
1346 | if (filename__read_build_id(self->long_name, build_id, | 1343 | if (filename__read_build_id(self->long_name, build_id, |
1347 | sizeof(build_id))) { | 1344 | sizeof(build_id))) { |
1345 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; | ||
1348 | build_id__sprintf(build_id, sizeof(build_id), | 1346 | build_id__sprintf(build_id, sizeof(build_id), |
1349 | build_id_hex); | 1347 | build_id_hex); |
1350 | snprintf(name, size, | 1348 | snprintf(name, size, |
@@ -1933,6 +1931,12 @@ static size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, | |||
1933 | return ret; | 1931 | return ret; |
1934 | } | 1932 | } |
1935 | 1933 | ||
1934 | size_t machine__fprintf_dsos_buildid(struct machine *self, FILE *fp, bool with_hits) | ||
1935 | { | ||
1936 | return __dsos__fprintf_buildid(&self->kernel_dsos, fp, with_hits) + | ||
1937 | __dsos__fprintf_buildid(&self->user_dsos, fp, with_hits); | ||
1938 | } | ||
1939 | |||
1936 | size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits) | 1940 | size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits) |
1937 | { | 1941 | { |
1938 | struct rb_node *nd; | 1942 | struct rb_node *nd; |
@@ -1940,8 +1944,7 @@ size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_ | |||
1940 | 1944 | ||
1941 | for (nd = rb_first(self); nd; nd = rb_next(nd)) { | 1945 | for (nd = rb_first(self); nd; nd = rb_next(nd)) { |
1942 | struct machine *pos = rb_entry(nd, struct machine, rb_node); | 1946 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
1943 | ret += __dsos__fprintf_buildid(&pos->kernel_dsos, fp, with_hits); | 1947 | ret += machine__fprintf_dsos_buildid(pos, fp, with_hits); |
1944 | ret += __dsos__fprintf_buildid(&pos->user_dsos, fp, with_hits); | ||
1945 | } | 1948 | } |
1946 | return ret; | 1949 | return ret; |
1947 | } | 1950 | } |
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 032469e41876..5d25b5eb1456 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -170,6 +170,7 @@ int machine__load_vmlinux_path(struct machine *self, enum map_type type, | |||
170 | 170 | ||
171 | size_t __dsos__fprintf(struct list_head *head, FILE *fp); | 171 | size_t __dsos__fprintf(struct list_head *head, FILE *fp); |
172 | 172 | ||
173 | size_t machine__fprintf_dsos_buildid(struct machine *self, FILE *fp, bool with_hits); | ||
173 | size_t machines__fprintf_dsos(struct rb_root *self, FILE *fp); | 174 | size_t machines__fprintf_dsos(struct rb_root *self, FILE *fp); |
174 | size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits); | 175 | size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits); |
175 | 176 | ||
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c index cb54cd002f49..f55cc3a765a1 100644 --- a/tools/perf/util/trace-event-read.c +++ b/tools/perf/util/trace-event-read.c | |||
@@ -53,12 +53,6 @@ static unsigned long page_size; | |||
53 | static ssize_t calc_data_size; | 53 | static ssize_t calc_data_size; |
54 | static bool repipe; | 54 | static bool repipe; |
55 | 55 | ||
56 | /* If it fails, the next read will report it */ | ||
57 | static void skip(int size) | ||
58 | { | ||
59 | lseek(input_fd, size, SEEK_CUR); | ||
60 | } | ||
61 | |||
62 | static int do_read(int fd, void *buf, int size) | 56 | static int do_read(int fd, void *buf, int size) |
63 | { | 57 | { |
64 | int rsize = size; | 58 | int rsize = size; |
@@ -98,6 +92,19 @@ static int read_or_die(void *data, int size) | |||
98 | return r; | 92 | return r; |
99 | } | 93 | } |
100 | 94 | ||
95 | /* If it fails, the next read will report it */ | ||
96 | static void skip(int size) | ||
97 | { | ||
98 | char buf[BUFSIZ]; | ||
99 | int r; | ||
100 | |||
101 | while (size) { | ||
102 | r = size > BUFSIZ ? BUFSIZ : size; | ||
103 | read_or_die(buf, r); | ||
104 | size -= r; | ||
105 | }; | ||
106 | } | ||
107 | |||
101 | static unsigned int read4(void) | 108 | static unsigned int read4(void) |
102 | { | 109 | { |
103 | unsigned int data; | 110 | unsigned int data; |
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 406d452956db..b3e86b1e4444 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h | |||
@@ -233,7 +233,12 @@ static inline unsigned long long __data2host8(unsigned long long data) | |||
233 | 233 | ||
234 | #define data2host2(ptr) __data2host2(*(unsigned short *)ptr) | 234 | #define data2host2(ptr) __data2host2(*(unsigned short *)ptr) |
235 | #define data2host4(ptr) __data2host4(*(unsigned int *)ptr) | 235 | #define data2host4(ptr) __data2host4(*(unsigned int *)ptr) |
236 | #define data2host8(ptr) __data2host8(*(unsigned long long *)ptr) | 236 | #define data2host8(ptr) ({ \ |
237 | unsigned long long __val; \ | ||
238 | \ | ||
239 | memcpy(&__val, (ptr), sizeof(unsigned long long)); \ | ||
240 | __data2host8(__val); \ | ||
241 | }) | ||
237 | 242 | ||
238 | extern int header_page_ts_offset; | 243 | extern int header_page_ts_offset; |
239 | extern int header_page_ts_size; | 244 | extern int header_page_ts_size; |
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 0795bf304b19..4e8b6b0c551c 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -81,7 +81,7 @@ | |||
81 | #include <inttypes.h> | 81 | #include <inttypes.h> |
82 | #include "../../../include/linux/magic.h" | 82 | #include "../../../include/linux/magic.h" |
83 | #include "types.h" | 83 | #include "types.h" |
84 | 84 | #include <sys/ttydefaults.h> | |
85 | 85 | ||
86 | #ifndef NO_ICONV | 86 | #ifndef NO_ICONV |
87 | #include <iconv.h> | 87 | #include <iconv.h> |
@@ -152,7 +152,6 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2))) | |||
152 | extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN); | 152 | extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN); |
153 | 153 | ||
154 | extern int prefixcmp(const char *str, const char *prefix); | 154 | extern int prefixcmp(const char *str, const char *prefix); |
155 | extern time_t tm_to_time_t(const struct tm *tm); | ||
156 | 155 | ||
157 | static inline const char *skip_prefix(const char *str, const char *prefix) | 156 | static inline const char *skip_prefix(const char *str, const char *prefix) |
158 | { | 157 | { |
@@ -160,119 +159,6 @@ static inline const char *skip_prefix(const char *str, const char *prefix) | |||
160 | return strncmp(str, prefix, len) ? NULL : str + len; | 159 | return strncmp(str, prefix, len) ? NULL : str + len; |
161 | } | 160 | } |
162 | 161 | ||
163 | #if defined(NO_MMAP) || defined(USE_WIN32_MMAP) | ||
164 | |||
165 | #ifndef PROT_READ | ||
166 | #define PROT_READ 1 | ||
167 | #define PROT_WRITE 2 | ||
168 | #define MAP_PRIVATE 1 | ||
169 | #define MAP_FAILED ((void*)-1) | ||
170 | #endif | ||
171 | |||
172 | #define mmap git_mmap | ||
173 | #define munmap git_munmap | ||
174 | extern void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); | ||
175 | extern int git_munmap(void *start, size_t length); | ||
176 | |||
177 | #else /* NO_MMAP || USE_WIN32_MMAP */ | ||
178 | |||
179 | #include <sys/mman.h> | ||
180 | |||
181 | #endif /* NO_MMAP || USE_WIN32_MMAP */ | ||
182 | |||
183 | #ifdef NO_MMAP | ||
184 | |||
185 | /* This value must be multiple of (pagesize * 2) */ | ||
186 | #define DEFAULT_PACKED_GIT_WINDOW_SIZE (1 * 1024 * 1024) | ||
187 | |||
188 | #else /* NO_MMAP */ | ||
189 | |||
190 | /* This value must be multiple of (pagesize * 2) */ | ||
191 | #define DEFAULT_PACKED_GIT_WINDOW_SIZE \ | ||
192 | (sizeof(void*) >= 8 \ | ||
193 | ? 1 * 1024 * 1024 * 1024 \ | ||
194 | : 32 * 1024 * 1024) | ||
195 | |||
196 | #endif /* NO_MMAP */ | ||
197 | |||
198 | #ifdef NO_ST_BLOCKS_IN_STRUCT_STAT | ||
199 | #define on_disk_bytes(st) ((st).st_size) | ||
200 | #else | ||
201 | #define on_disk_bytes(st) ((st).st_blocks * 512) | ||
202 | #endif | ||
203 | |||
204 | #define DEFAULT_PACKED_GIT_LIMIT \ | ||
205 | ((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256)) | ||
206 | |||
207 | #ifdef NO_PREAD | ||
208 | #define pread git_pread | ||
209 | extern ssize_t git_pread(int fd, void *buf, size_t count, off_t offset); | ||
210 | #endif | ||
211 | /* | ||
212 | * Forward decl that will remind us if its twin in cache.h changes. | ||
213 | * This function is used in compat/pread.c. But we can't include | ||
214 | * cache.h there. | ||
215 | */ | ||
216 | extern ssize_t read_in_full(int fd, void *buf, size_t count); | ||
217 | |||
218 | #ifdef NO_SETENV | ||
219 | #define setenv gitsetenv | ||
220 | extern int gitsetenv(const char *, const char *, int); | ||
221 | #endif | ||
222 | |||
223 | #ifdef NO_MKDTEMP | ||
224 | #define mkdtemp gitmkdtemp | ||
225 | extern char *gitmkdtemp(char *); | ||
226 | #endif | ||
227 | |||
228 | #ifdef NO_UNSETENV | ||
229 | #define unsetenv gitunsetenv | ||
230 | extern void gitunsetenv(const char *); | ||
231 | #endif | ||
232 | |||
233 | #ifdef NO_STRCASESTR | ||
234 | #define strcasestr gitstrcasestr | ||
235 | extern char *gitstrcasestr(const char *haystack, const char *needle); | ||
236 | #endif | ||
237 | |||
238 | #ifdef NO_STRLCPY | ||
239 | #define strlcpy gitstrlcpy | ||
240 | extern size_t gitstrlcpy(char *, const char *, size_t); | ||
241 | #endif | ||
242 | |||
243 | #ifdef NO_STRTOUMAX | ||
244 | #define strtoumax gitstrtoumax | ||
245 | extern uintmax_t gitstrtoumax(const char *, char **, int); | ||
246 | #endif | ||
247 | |||
248 | #ifdef NO_HSTRERROR | ||
249 | #define hstrerror githstrerror | ||
250 | extern const char *githstrerror(int herror); | ||
251 | #endif | ||
252 | |||
253 | #ifdef NO_MEMMEM | ||
254 | #define memmem gitmemmem | ||
255 | void *gitmemmem(const void *haystack, size_t haystacklen, | ||
256 | const void *needle, size_t needlelen); | ||
257 | #endif | ||
258 | |||
259 | #ifdef FREAD_READS_DIRECTORIES | ||
260 | #ifdef fopen | ||
261 | #undef fopen | ||
262 | #endif | ||
263 | #define fopen(a,b) git_fopen(a,b) | ||
264 | extern FILE *git_fopen(const char*, const char*); | ||
265 | #endif | ||
266 | |||
267 | #ifdef SNPRINTF_RETURNS_BOGUS | ||
268 | #define snprintf git_snprintf | ||
269 | extern int git_snprintf(char *str, size_t maxsize, | ||
270 | const char *format, ...); | ||
271 | #define vsnprintf git_vsnprintf | ||
272 | extern int git_vsnprintf(char *str, size_t maxsize, | ||
273 | const char *format, va_list ap); | ||
274 | #endif | ||
275 | |||
276 | #ifdef __GLIBC_PREREQ | 162 | #ifdef __GLIBC_PREREQ |
277 | #if __GLIBC_PREREQ(2, 1) | 163 | #if __GLIBC_PREREQ(2, 1) |
278 | #define HAVE_STRCHRNUL | 164 | #define HAVE_STRCHRNUL |
@@ -293,28 +179,14 @@ static inline char *gitstrchrnul(const char *s, int c) | |||
293 | * Wrappers: | 179 | * Wrappers: |
294 | */ | 180 | */ |
295 | extern char *xstrdup(const char *str); | 181 | extern char *xstrdup(const char *str); |
296 | extern void *xmalloc(size_t size) __attribute__((weak)); | ||
297 | extern void *xmemdupz(const void *data, size_t len); | ||
298 | extern char *xstrndup(const char *str, size_t len); | ||
299 | extern void *xrealloc(void *ptr, size_t size) __attribute__((weak)); | 182 | extern void *xrealloc(void *ptr, size_t size) __attribute__((weak)); |
300 | 183 | ||
301 | static inline void *xzalloc(size_t size) | ||
302 | { | ||
303 | void *buf = xmalloc(size); | ||
304 | |||
305 | return memset(buf, 0, size); | ||
306 | } | ||
307 | 184 | ||
308 | static inline void *zalloc(size_t size) | 185 | static inline void *zalloc(size_t size) |
309 | { | 186 | { |
310 | return calloc(1, size); | 187 | return calloc(1, size); |
311 | } | 188 | } |
312 | 189 | ||
313 | static inline size_t xsize_t(off_t len) | ||
314 | { | ||
315 | return (size_t)len; | ||
316 | } | ||
317 | |||
318 | static inline int has_extension(const char *filename, const char *ext) | 190 | static inline int has_extension(const char *filename, const char *ext) |
319 | { | 191 | { |
320 | size_t len = strlen(filename); | 192 | size_t len = strlen(filename); |
@@ -351,8 +223,6 @@ extern unsigned char sane_ctype[256]; | |||
351 | #define isalpha(x) sane_istest(x,GIT_ALPHA) | 223 | #define isalpha(x) sane_istest(x,GIT_ALPHA) |
352 | #define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) | 224 | #define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) |
353 | #define isprint(x) sane_istest(x,GIT_PRINT) | 225 | #define isprint(x) sane_istest(x,GIT_PRINT) |
354 | #define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL) | ||
355 | #define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL) | ||
356 | #define tolower(x) sane_case((unsigned char)(x), 0x20) | 226 | #define tolower(x) sane_case((unsigned char)(x), 0x20) |
357 | #define toupper(x) sane_case((unsigned char)(x), 0) | 227 | #define toupper(x) sane_case((unsigned char)(x), 0) |
358 | 228 | ||
@@ -363,38 +233,6 @@ static inline int sane_case(int x, int high) | |||
363 | return x; | 233 | return x; |
364 | } | 234 | } |
365 | 235 | ||
366 | static inline int strtoul_ui(char const *s, int base, unsigned int *result) | ||
367 | { | ||
368 | unsigned long ul; | ||
369 | char *p; | ||
370 | |||
371 | errno = 0; | ||
372 | ul = strtoul(s, &p, base); | ||
373 | if (errno || *p || p == s || (unsigned int) ul != ul) | ||
374 | return -1; | ||
375 | *result = ul; | ||
376 | return 0; | ||
377 | } | ||
378 | |||
379 | static inline int strtol_i(char const *s, int base, int *result) | ||
380 | { | ||
381 | long ul; | ||
382 | char *p; | ||
383 | |||
384 | errno = 0; | ||
385 | ul = strtol(s, &p, base); | ||
386 | if (errno || *p || p == s || (int) ul != ul) | ||
387 | return -1; | ||
388 | *result = ul; | ||
389 | return 0; | ||
390 | } | ||
391 | |||
392 | #ifdef INTERNAL_QSORT | ||
393 | void git_qsort(void *base, size_t nmemb, size_t size, | ||
394 | int(*compar)(const void *, const void *)); | ||
395 | #define qsort git_qsort | ||
396 | #endif | ||
397 | |||
398 | #ifndef DIR_HAS_BSD_GROUP_SEMANTICS | 236 | #ifndef DIR_HAS_BSD_GROUP_SEMANTICS |
399 | # define FORCE_DIR_SET_GID S_ISGID | 237 | # define FORCE_DIR_SET_GID S_ISGID |
400 | #else | 238 | #else |
@@ -425,6 +263,19 @@ bool strglobmatch(const char *str, const char *pat); | |||
425 | bool strlazymatch(const char *str, const char *pat); | 263 | bool strlazymatch(const char *str, const char *pat); |
426 | unsigned long convert_unit(unsigned long value, char *unit); | 264 | unsigned long convert_unit(unsigned long value, char *unit); |
427 | 265 | ||
266 | #ifndef ESC | ||
267 | #define ESC 27 | ||
268 | #endif | ||
269 | |||
270 | static inline bool is_exit_key(int key) | ||
271 | { | ||
272 | char up; | ||
273 | if (key == CTRL('c') || key == ESC) | ||
274 | return true; | ||
275 | up = toupper(key); | ||
276 | return up == 'Q'; | ||
277 | } | ||
278 | |||
428 | #define _STR(x) #x | 279 | #define _STR(x) #x |
429 | #define STR(x) _STR(x) | 280 | #define STR(x) _STR(x) |
430 | 281 | ||
diff --git a/tools/perf/util/wrapper.c b/tools/perf/util/wrapper.c index bf44ca85d23b..73e900edb5a2 100644 --- a/tools/perf/util/wrapper.c +++ b/tools/perf/util/wrapper.c | |||
@@ -23,46 +23,6 @@ char *xstrdup(const char *str) | |||
23 | return ret; | 23 | return ret; |
24 | } | 24 | } |
25 | 25 | ||
26 | void *xmalloc(size_t size) | ||
27 | { | ||
28 | void *ret = malloc(size); | ||
29 | if (!ret && !size) | ||
30 | ret = malloc(1); | ||
31 | if (!ret) { | ||
32 | release_pack_memory(size, -1); | ||
33 | ret = malloc(size); | ||
34 | if (!ret && !size) | ||
35 | ret = malloc(1); | ||
36 | if (!ret) | ||
37 | die("Out of memory, malloc failed"); | ||
38 | } | ||
39 | #ifdef XMALLOC_POISON | ||
40 | memset(ret, 0xA5, size); | ||
41 | #endif | ||
42 | return ret; | ||
43 | } | ||
44 | |||
45 | /* | ||
46 | * xmemdupz() allocates (len + 1) bytes of memory, duplicates "len" bytes of | ||
47 | * "data" to the allocated memory, zero terminates the allocated memory, | ||
48 | * and returns a pointer to the allocated memory. If the allocation fails, | ||
49 | * the program dies. | ||
50 | */ | ||
51 | void *xmemdupz(const void *data, size_t len) | ||
52 | { | ||
53 | char *p = xmalloc(len + 1); | ||
54 | memcpy(p, data, len); | ||
55 | p[len] = '\0'; | ||
56 | return p; | ||
57 | } | ||
58 | |||
59 | char *xstrndup(const char *str, size_t len) | ||
60 | { | ||
61 | char *p = memchr(str, '\0', len); | ||
62 | |||
63 | return xmemdupz(str, p ? (size_t)(p - str) : len); | ||
64 | } | ||
65 | |||
66 | void *xrealloc(void *ptr, size_t size) | 26 | void *xrealloc(void *ptr, size_t size) |
67 | { | 27 | { |
68 | void *ret = realloc(ptr, size); | 28 | void *ret = realloc(ptr, size); |
@@ -78,73 +38,3 @@ void *xrealloc(void *ptr, size_t size) | |||
78 | } | 38 | } |
79 | return ret; | 39 | return ret; |
80 | } | 40 | } |
81 | |||
82 | /* | ||
83 | * xread() is the same a read(), but it automatically restarts read() | ||
84 | * operations with a recoverable error (EAGAIN and EINTR). xread() | ||
85 | * DOES NOT GUARANTEE that "len" bytes is read even if the data is available. | ||
86 | */ | ||
87 | static ssize_t xread(int fd, void *buf, size_t len) | ||
88 | { | ||
89 | ssize_t nr; | ||
90 | while (1) { | ||
91 | nr = read(fd, buf, len); | ||
92 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
93 | continue; | ||
94 | return nr; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | /* | ||
99 | * xwrite() is the same a write(), but it automatically restarts write() | ||
100 | * operations with a recoverable error (EAGAIN and EINTR). xwrite() DOES NOT | ||
101 | * GUARANTEE that "len" bytes is written even if the operation is successful. | ||
102 | */ | ||
103 | static ssize_t xwrite(int fd, const void *buf, size_t len) | ||
104 | { | ||
105 | ssize_t nr; | ||
106 | while (1) { | ||
107 | nr = write(fd, buf, len); | ||
108 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
109 | continue; | ||
110 | return nr; | ||
111 | } | ||
112 | } | ||
113 | |||
114 | ssize_t read_in_full(int fd, void *buf, size_t count) | ||
115 | { | ||
116 | char *p = buf; | ||
117 | ssize_t total = 0; | ||
118 | |||
119 | while (count > 0) { | ||
120 | ssize_t loaded = xread(fd, p, count); | ||
121 | if (loaded <= 0) | ||
122 | return total ? total : loaded; | ||
123 | count -= loaded; | ||
124 | p += loaded; | ||
125 | total += loaded; | ||
126 | } | ||
127 | |||
128 | return total; | ||
129 | } | ||
130 | |||
131 | ssize_t write_in_full(int fd, const void *buf, size_t count) | ||
132 | { | ||
133 | const char *p = buf; | ||
134 | ssize_t total = 0; | ||
135 | |||
136 | while (count > 0) { | ||
137 | ssize_t written = xwrite(fd, p, count); | ||
138 | if (written < 0) | ||
139 | return -1; | ||
140 | if (!written) { | ||
141 | errno = ENOSPC; | ||
142 | return -1; | ||
143 | } | ||
144 | count -= written; | ||
145 | p += written; | ||
146 | total += written; | ||
147 | } | ||
148 | |||
149 | return total; | ||
150 | } | ||