[PATCH 06/16] platform/x86: wmi: Fix error handling when creating devices

2017-05-26 Thread Darren Hart
From: Andy Lutomirski 

We have two memory leaks. If guid_already_parsed returned true, we leak
the wmi_block. If wmi_create_device failed, we leak the device.

Simplify the logic and fix both of them.

Signed-off-by: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Mario Limonciello 
Cc: Pali Rohár 
Cc: Rafael Wysocki 
Cc: linux-kernel@vger.kernel.org
Cc: platform-driver-...@vger.kernel.org
Cc: linux-a...@vger.kernel.org
Signed-off-by: Darren Hart (VMware) 
---
 drivers/platform/x86/wmi.c | 28 +++-
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index f06b7c0..31c317f 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -757,6 +757,15 @@ static int parse_wdg(struct device *wmi_bus_dev, struct 
acpi_device *device)
if (debug_dump_wdg)
wmi_dump_wdg([i]);
 
+   /*
+* Some WMI devices, like those for nVidia hooks, have a
+* duplicate GUID. It's not clear what we should do in this
+* case yet, so for now, we'll just ignore the duplicate
+* for device creation.
+*/
+   if (guid_already_parsed(device, gblock[i].guid))
+   continue;
+
wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL);
if (!wblock)
return -ENOMEM;
@@ -764,19 +773,12 @@ static int parse_wdg(struct device *wmi_bus_dev, struct 
acpi_device *device)
wblock->acpi_device = device;
wblock->gblock = gblock[i];
 
-   /*
- Some WMI devices, like those for nVidia hooks, have a
- duplicate GUID. It's not clear what we should do in this
- case yet, so for now, we'll just ignore the duplicate
- for device creation.
-   */
-   if (!guid_already_parsed(device, gblock[i].guid)) {
-   retval = wmi_create_device(wmi_bus_dev, [i],
-  wblock, device);
-   if (retval) {
-   wmi_free_devices(device);
-   goto out_free_pointer;
-   }
+   retval = wmi_create_device(wmi_bus_dev, [i],
+  wblock, device);
+   if (retval) {
+   put_device(>dev.dev);
+   wmi_free_devices(device);
+   goto out_free_pointer;
}
 
list_add_tail(>list, _block_list);
-- 
2.9.4



[PATCH 11/16] platform/x86: wmi: Add a new interface to read block data

2017-05-26 Thread Darren Hart
From: Andy Lutomirski 

wmi_query_block is unnecessarily indirect. Add a straightforward
method for wmi bus drivers to use to read block data.

Signed-off-by: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Mario Limonciello 
Cc: Pali Rohár 
Cc: Rafael Wysocki 
Cc: linux-kernel@vger.kernel.org
Cc: platform-driver-...@vger.kernel.org
Cc: linux-a...@vger.kernel.org
Signed-off-by: Darren Hart (VMware) 
---
 drivers/platform/x86/wmi.c | 54 --
 include/linux/wmi.h|  4 
 2 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index 208e187..483e4a6 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -244,19 +244,10 @@ u32 method_id, const struct acpi_buffer *in, struct 
acpi_buffer *out)
 }
 EXPORT_SYMBOL_GPL(wmi_evaluate_method);
 
-/**
- * wmi_query_block - Return contents of a WMI block
- * @guid_string: 36 char string of the form 
fa50ff2b-f2e8-45de-83fa-65417f2f49ba
- * @instance: Instance index
- * : Empty buffer to return the contents of the data block to
- *
- * Return the contents of an ACPI-WMI data block to a buffer
- */
-acpi_status wmi_query_block(const char *guid_string, u8 instance,
-struct acpi_buffer *out)
+static acpi_status __query_block(struct wmi_block *wblock, u8 instance,
+struct acpi_buffer *out)
 {
struct guid_block *block = NULL;
-   struct wmi_block *wblock = NULL;
acpi_handle handle;
acpi_status status, wc_status = AE_ERROR;
struct acpi_object_list input;
@@ -264,12 +255,9 @@ struct acpi_buffer *out)
char method[5];
char wc_method[5] = "WC";
 
-   if (!guid_string || !out)
+   if (!out)
return AE_BAD_PARAMETER;
 
-   if (!find_guid(guid_string, ))
-   return AE_ERROR;
-
block = >gblock;
handle = wblock->acpi_device->handle;
 
@@ -320,8 +308,42 @@ struct acpi_buffer *out)
 
return status;
 }
+
+/**
+ * wmi_query_block - Return contents of a WMI block (deprecated)
+ * @guid_string: 36 char string of the form 
fa50ff2b-f2e8-45de-83fa-65417f2f49ba
+ * @instance: Instance index
+ * : Empty buffer to return the contents of the data block to
+ *
+ * Return the contents of an ACPI-WMI data block to a buffer
+ */
+acpi_status wmi_query_block(const char *guid_string, u8 instance,
+   struct acpi_buffer *out)
+{
+   struct wmi_block *wblock;
+
+   if (!guid_string)
+   return AE_BAD_PARAMETER;
+
+   if (!find_guid(guid_string, ))
+   return AE_ERROR;
+
+   return __query_block(wblock, instance, out);
+}
 EXPORT_SYMBOL_GPL(wmi_query_block);
 
+union acpi_object *wmidev_block_query(struct wmi_device *wdev, u8 instance)
+{
+   struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
+   struct wmi_block *wblock = container_of(wdev, struct wmi_block, dev);
+
+   if (ACPI_FAILURE(__query_block(wblock, instance, )))
+   return NULL;
+
+   return (union acpi_object *)out.pointer;
+}
+EXPORT_SYMBOL_GPL(wmidev_block_query);
+
 /**
  * wmi_set_block - Write to a WMI block
  * @guid_string: 36 char string of the form 
fa50ff2b-f2e8-45de-83fa-65417f2f49ba
@@ -331,7 +353,7 @@ EXPORT_SYMBOL_GPL(wmi_query_block);
  * Write the contents of the input buffer to an ACPI-WMI data block
  */
 acpi_status wmi_set_block(const char *guid_string, u8 instance,
-const struct acpi_buffer *in)
+ const struct acpi_buffer *in)
 {
struct guid_block *block = NULL;
struct wmi_block *wblock = NULL;
diff --git a/include/linux/wmi.h b/include/linux/wmi.h
index c6eedfd..0ab2540 100644
--- a/include/linux/wmi.h
+++ b/include/linux/wmi.h
@@ -29,6 +29,10 @@ struct wmi_device {
bool readable, writeable;
 };
 
+/* Caller must kfree the result. */
+extern union acpi_object *wmidev_block_query(struct wmi_device *wdev,
+u8 instance);
+
 struct wmi_device_id {
const char *guid_string;
 };
-- 
2.9.4



Re: [PATCHv4] usb: typec: Add a sysfs node to manage port type

2017-05-26 Thread Greg Kroah-Hartman
On Fri, May 26, 2017 at 01:42:57PM -0700, Badhri Jagan Sridharan wrote:
> User space applications in some cases have the need to enforce a
> specific port type(DFP/UFP/DRP). This change allows userspace to
> attempt setting the desired port type. Low level drivers can
> however reject the request if the specific port type is not supported.
> 
> Signed-off-by: Badhri Jagan Sridharan 
> ---
> Changelog since v1:
> - introduced a new variable port_type in struct typec_port to track
>   the current port type instead of changing type member in
>   typec_capability to address Heikki Krogerus comments.
> - changed the output format and strings that would be displayed as
>   suggested by Heikki Krogerus.
> 
> Changelog since v2:
> - introduced a new mutex lock to protect port_type for addressing
>   the race conditions identified by Geunter Roeck
> - added typec_port_types_drp for printing port_type when cap->type
>   is TYPE_PORT_DRP as suggested by Geunter Roeck
> - Power role swap and data role swaps would be rejected unless
>   port port_type == TYPE_PORT_DRP
> - port_type_store would return immediately if the current port_type
>   is same as the new port_type as suggested by Geunter Roeck
> 
> Changelog since v3:
> - Moved as much as code outside port_type_lock as suggested by
>   Geunter Roeck
> - Removed Change-Id line from commit message identified by
>   Greg Kroah-Hartman

Ok, this is how you write a changelog for a patch, very nice job!

greg k-h


Re: [PATCH v1 1/1] intel_telemetry_debugfs: fix oops found while load/unload module test

2017-05-26 Thread Darren Hart
On Sat, May 27, 2017 at 08:17:39AM -0700, priyalee.kushw...@intel.com wrote:
> From: Priyalee Kushwaha 
> 
> This fix oops found while testing load/unload test of
> intel_telemetry_debugfs module. Module_init uses register_pm_notifier
> for PM callbacks, but unregister_pm_notifier was missing from
> module_exit.
> 
>  [ 97.481860] BUG: unable to handle kernel paging request at a006f010
>  [ 97.489742] IP: blocking_notifier_chain_register+0x3a/0xa0
>  [ 97.495898] PGD 2e0a067
>  [ 97.495899] PUD 2e0b063
>  [ 97.498737] PMD 179e29067
>  [ 97.501573] PTE 0
> 
>  [ 97.508423] Oops:  1 PREEMPT SMP
>  [ 97.512724] Modules linked in: intel_telemetry_debugfs intel_rapl gpio_keys 
> dwc3 udc_core intel_telemetry_pltdrv intel_punit_ipc intel_telemetry_core 
> rtc_cmos efivars x86_pkg_temp_thermal iwlwifi snd_hda_codec_hdmi 
> soc_button_array btusb cfg80211 btrtl mei_me hci_uart btbcm mei btintel i915 
> bluetooth intel_pmc_ipc snd_hda_intel spi_pxa2xx_platform snd_hda_codec 
> dwc3_pci snd_hda_core tpm_tis tpm_tis_core tpm efivarfs
>  [ 97.558453] CPU: 0 PID: 889 Comm: modprobe Not tainted 
> 4.11.0-rc6-intel-dev-bkc #1
>  [ 97.566950] Hardware name: Intel Corp. Joule DVT3/SDS, BIOS 
> GTPP181A.X64.0143.B30.1701132137 01/13/2017
>  [ 97.577518] task: 8801793a21c0 task.stack: 8801793f
>  [ 97.584162] RIP: 0010:blocking_notifier_chain_register+0x3a/0xa0
>  [ 97.590903] RSP: 0018:8801793f3c58 EFLAGS: 00010286
>  [ 97.596802] RAX: a006f000 RBX: 81e3ea20 RCX: 
> 
>  [ 97.604812] RDX: 880179eaf210 RSI: a0131000 RDI: 
> 81e3ea20
>  [ 97.612821] RBP: 8801793f3c68 R08: 0006 R09: 
> 005c
>  [ 97.620847] R10:  R11: 0006 R12: 
> a0131000
>  [ 97.628855] R13:  R14: 880176e35f48 R15: 
> 8801793f3ea8
>  [ 97.636865] FS: 7f7eeba07700() GS:88017fc0() 
> knlGS:
>  [ 97.645948] CS: 0010 DS:  ES:  CR0: 80050033
>  [ 97.652423] CR2: a006f010 CR3: 0001775ef000 CR4: 
> 003406f0
>  [ 97.660423] Call Trace:
>  [ 97.663166] ? 0xa0031000
>  [ 97.666885] register_pm_notifier+0x18/0x20
>  [ 97.671581] telemetry_debugfs_init+0x92/0x1000
> 
> Signed-off-by: Priyalee Kushwaha 

Hi Priyalee,

Thanks for catching this, we should get a fix into the RC cycle. but I think we
can make some small changes that will improve legibility here.

> ---
>  drivers/platform/x86/intel_telemetry_debugfs.c | 12 +++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/x86/intel_telemetry_debugfs.c 
> b/drivers/platform/x86/intel_telemetry_debugfs.c
> index ef29f18..0f93975 100644
> --- a/drivers/platform/x86/intel_telemetry_debugfs.c
> +++ b/drivers/platform/x86/intel_telemetry_debugfs.c
> @@ -966,8 +966,12 @@ static int __init telemetry_debugfs_init(void)
>  #endif /* CONFIG_PM_SLEEP */
>  
>   debugfs_conf->telemetry_dbg_dir = debugfs_create_dir("telemetry", NULL);
> - if (!debugfs_conf->telemetry_dbg_dir)
> + if (!debugfs_conf->telemetry_dbg_dir) {
> +#ifdef CONFIG_PM_SLEEP
> + unregister_pm_notifier(_notifier);
> +#endif /* CONFIG_PM_SLEEP */
>   return -ENOMEM;
> + }

As a general rule, we try to avoid peppering code with #ifdef blocks, and prefer
to create no-op functions, or similar. CONFIG_PM_SLEEP unfortunately doesn't
have such no-op functions.

Rather than add the CONFIG_PM_SLEEP block above, please convert the above to use
an err= and goto statement, and create the appropriate labels below.

+Rafael, Len, Pavel, linux-pm: Is there a preferred approach for dealing with
   CONFIG_PM_SLEEP?

>  
>   f = debugfs_create_file("pss_info", S_IFREG | S_IRUGO,
>   debugfs_conf->telemetry_dbg_dir, NULL,
> @@ -1014,6 +1018,9 @@ static int __init telemetry_debugfs_init(void)
>  out:
>   debugfs_remove_recursive(debugfs_conf->telemetry_dbg_dir);
>   debugfs_conf->telemetry_dbg_dir = NULL;

  e.g.

   out_pm:

> +#ifdef CONFIG_PM_SLEEP
> + unregister_pm_notifier(_notifier);
> +#endif /* CONFIG_PM_SLEEP */
>  
>   return err;
>  }
> @@ -1022,6 +1029,9 @@ static void __exit telemetry_debugfs_exit(void)
>  {
>   debugfs_remove_recursive(debugfs_conf->telemetry_dbg_dir);
>   debugfs_conf->telemetry_dbg_dir = NULL;
> +#ifdef CONFIG_PM_SLEEP
> + unregister_pm_notifier(_notifier);
> +#endif /* CONFIG_PM_SLEEP */
>  }
>  
>  late_initcall(telemetry_debugfs_init);
> -- 
> 2.10.0
> 
> 

-- 
Darren Hart
VMware Open Source Technology Center


[PATCH v2 2/3] clk: hi3660: add clocks for video encoder, decoder and ISP

2017-05-26 Thread Guodong Xu
From: Chen Jun 

This patch adds more clocks for hi3660, including:
 - video encoder and decoder
 - ISP (Image Signal Processing)

Signed-off-by: Chen Jun 
Signed-off-by: Zhong Kaihua 
Signed-off-by: Guodong Xu 
Reviewed-by: Zhangfei Gao 
---
 drivers/clk/hisilicon/clk-hi3660.c   | 40 
 include/dt-bindings/clock/hi3660-clock.h | 17 ++
 2 files changed, 57 insertions(+)

diff --git a/drivers/clk/hisilicon/clk-hi3660.c 
b/drivers/clk/hisilicon/clk-hi3660.c
index 143ce0c..67c4d44 100644
--- a/drivers/clk/hisilicon/clk-hi3660.c
+++ b/drivers/clk/hisilicon/clk-hi3660.c
@@ -47,9 +47,14 @@ static const struct hisi_fixed_factor_clock 
hi3660_crg_fixed_factor_clks[] = {
{ HI3660_CLK_GATE_SPI2, "clk_gate_spi2", "clk_ppll0", 1, 8, 0, },
{ HI3660_PCIEPHY_REF, "clk_pciephy_ref", "clk_div_pciephy", 1, 1, 0, },
{ HI3660_CLK_ABB_USB, "clk_abb_usb", "clk_gate_usb_tcxo_en", 1, 1, 0 },
+   { HI3660_VENC_VOLT_HOLD, "venc_volt_hold", "peri_volt_hold", 1, 1, 0, },
+   { HI3660_CLK_FAC_ISP_SNCLK, "clk_isp_snclk_fac", "clk_isp_snclk_angt",
+ 1, 10, 0, },
 };
 
 static const struct hisi_gate_clock hi3660_crgctrl_gate_sep_clks[] = {
+   { HI3660_PERI_VOLT_HOLD, "peri_volt_hold", "clkin_sys",
+ CLK_SET_RATE_PARENT, 0x0, 0, 0, },
{ HI3660_HCLK_GATE_SDIO0, "hclk_gate_sdio0", "clk_div_sysbus",
  CLK_SET_RATE_PARENT, 0x0, 21, 0, },
{ HI3660_HCLK_GATE_SD, "hclk_gate_sd", "clk_div_sysbus",
@@ -120,6 +125,10 @@ static const struct hisi_gate_clock 
hi3660_crgctrl_gate_sep_clks[] = {
  CLK_SET_RATE_PARENT, 0x20, 27, 0, },
{ HI3660_CLK_GATE_DMAC, "clk_gate_dmac", "clk_div_sysbus",
  CLK_SET_RATE_PARENT, 0x30, 1, 0, },
+   { HI3660_CLK_GATE_VENC, "clk_gate_venc", "clk_div_venc",
+ CLK_SET_RATE_PARENT, 0x30, 10, 0, },
+   { HI3660_CLK_GATE_VDEC, "clk_gate_vdec", "clk_div_vdec",
+ CLK_SET_RATE_PARENT, 0x30, 11, 0, },
{ HI3660_PCLK_GATE_DSS, "pclk_gate_dss", "clk_div_cfgbus",
  CLK_SET_RATE_PARENT, 0x30, 12, 0, },
{ HI3660_ACLK_GATE_DSS, "aclk_gate_dss", "clk_gate_vivobus",
@@ -148,6 +157,12 @@ static const struct hisi_gate_clock 
hi3660_crgctrl_gate_sep_clks[] = {
  CLK_SET_RATE_PARENT, 0x40, 17, 0, },
{ HI3660_CLK_GATE_SDIO0, "clk_gate_sdio0", "clk_mux_sdio_sys",
  CLK_SET_RATE_PARENT, 0x40, 19, 0, },
+   { HI3660_CLK_GATE_ISP_SNCLK0, "clk_gate_isp_snclk0",
+ "clk_isp_snclk_mux", CLK_SET_RATE_PARENT, 0x50, 16, 0, },
+   { HI3660_CLK_GATE_ISP_SNCLK1, "clk_gate_isp_snclk1",
+ "clk_isp_snclk_mux", CLK_SET_RATE_PARENT, 0x50, 17, 0, },
+   { HI3660_CLK_GATE_ISP_SNCLK2, "clk_gate_isp_snclk2",
+ "clk_isp_snclk_mux", CLK_SET_RATE_PARENT, 0x50, 18, 0, },
{ HI3660_CLK_GATE_UFS_SUBSYS, "clk_gate_ufs_subsys", "clk_div_sysbus",
  CLK_SET_RATE_PARENT, 0x50, 21, 0, },
{ HI3660_PCLK_GATE_DSI0, "pclk_gate_dsi0", "clk_div_cfgbus",
@@ -171,6 +186,10 @@ static const struct hisi_gate_clock 
hi3660_crgctrl_gate_clks[] = {
  CLK_SET_RATE_PARENT, 0xf0, 7, CLK_GATE_HIWORD_MASK, },
{ HI3660_CLK_ANDGT_EDC0, "clk_andgt_edc0", "clk_mux_edc0",
  CLK_SET_RATE_PARENT, 0xf0, 8, CLK_GATE_HIWORD_MASK, },
+   { HI3660_CLK_ANDGT_VDEC, "clk_andgt_vdec", "clk_mux_vdec",
+ CLK_SET_RATE_PARENT, 0xf0, 15, CLK_GATE_HIWORD_MASK, },
+   { HI3660_CLK_ANDGT_VENC, "clk_andgt_venc", "clk_mux_venc",
+ CLK_SET_RATE_PARENT, 0xf4, 0, CLK_GATE_HIWORD_MASK, },
{ HI3660_CLK_GATE_UFSPHY_GT, "clk_gate_ufsphy_gt", "clk_div_ufsperi",
  CLK_SET_RATE_PARENT, 0xf4, 1, CLK_GATE_HIWORD_MASK, },
{ HI3660_CLK_ANDGT_MMC, "clk_andgt_mmc", "clk_mux_mmc_pll",
@@ -195,6 +214,8 @@ static const struct hisi_gate_clock 
hi3660_crgctrl_gate_clks[] = {
  CLK_SET_RATE_PARENT, 0xf8, 3, CLK_GATE_HIWORD_MASK, },
{ HI3660_CLK_320M_PLL_GT, "clk_320m_pll_gt", "clk_mux_320m",
  CLK_SET_RATE_PARENT, 0xf8, 10, 0, },
+   { HI3660_CLK_ANGT_ISP_SNCLK, "clk_isp_snclk_angt", "clk_div_a53hpm",
+ CLK_SET_RATE_PARENT, 0x108, 2, CLK_GATE_HIWORD_MASK, },
{ HI3660_AUTODIV_EMMC0BUS, "autodiv_emmc0bus", "autodiv_sysbus",
  CLK_SET_RATE_PARENT, 0x404, 1, CLK_GATE_HIWORD_MASK, },
{ HI3660_AUTODIV_SYSBUS, "autodiv_sysbus", "clk_div_sysbus",
@@ -239,6 +260,10 @@ static const char *const
 clk_mux_spi_p[] = {"clkin_sys", "clk_div_spi",};
 static const char *const
 clk_mux_i2c_p[] = {"clkin_sys", "clk_div_i2c",};
+static const char *const
+clk_mux_venc_p[] = {"clk_ppll0", "clk_ppll1", "clk_ppll3", "clk_ppll3",};
+static const char *const
+clk_mux_isp_snclk_p[] = {"clkin_sys", "clk_isp_snclk_div"};
 
 static const struct hisi_mux_clock hi3660_crgctrl_mux_clks[] = {
{ HI3660_CLK_MUX_SYSBUS, "clk_mux_sysbus", clk_mux_sysbus_p,

[PATCH v2 0/3] clk: hi3660: add more clocks and fix bugs

2017-05-26 Thread Guodong Xu
This patchset adds more clocks for hi3660, video encoder/decoder, ISP. It
includes also bug fixes.

v2 update:
 - added ISP clocks into patch 2.

Chen Jun (2):
  clk: hi3660: fix wrong parent name of clk_mux_sysbus
  clk: hi3660: add clocks for video encoder, decoder and ISP

Zhong Kaihua (1):
  clk: hi3660: Set PPLL2 to 2880M

 drivers/clk/hisilicon/clk-hi3660.c   | 50 +---
 include/dt-bindings/clock/hi3660-clock.h | 17 +++
 2 files changed, 63 insertions(+), 4 deletions(-)

-- 
2.10.2



[PATCH v2 1/3] clk: hi3660: fix wrong parent name of clk_mux_sysbus

2017-05-26 Thread Guodong Xu
From: Chen Jun 

Parent name of clk_mux_sysbus is not correct. This patch fixes it.

Signed-off-by: Chen Jun 
Signed-off-by: John Stultz 
Signed-off-by: Guodong Xu 
---
 drivers/clk/hisilicon/clk-hi3660.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/hisilicon/clk-hi3660.c 
b/drivers/clk/hisilicon/clk-hi3660.c
index 96a9697..143ce0c 100644
--- a/drivers/clk/hisilicon/clk-hi3660.c
+++ b/drivers/clk/hisilicon/clk-hi3660.c
@@ -206,6 +206,8 @@ static const struct hisi_gate_clock 
hi3660_crgctrl_gate_clks[] = {
 };
 
 static const char *const
+clk_mux_sysbus_p[] = {"clk_ppll1", "clk_ppll0"};
+static const char *const
 clk_mux_sdio_sys_p[] = {"clk_factor_mmc", "clk_div_sdio",};
 static const char *const
 clk_mux_sd_sys_p[] = {"clk_factor_mmc", "clk_div_sd",};
@@ -239,8 +241,8 @@ static const char *const
 clk_mux_i2c_p[] = {"clkin_sys", "clk_div_i2c",};
 
 static const struct hisi_mux_clock hi3660_crgctrl_mux_clks[] = {
-   { HI3660_CLK_MUX_SYSBUS, "clk_mux_sysbus", clk_mux_sdio_sys_p,
- ARRAY_SIZE(clk_mux_sdio_sys_p), CLK_SET_RATE_PARENT, 0xac, 0, 1,
+   { HI3660_CLK_MUX_SYSBUS, "clk_mux_sysbus", clk_mux_sysbus_p,
+ ARRAY_SIZE(clk_mux_sysbus_p), CLK_SET_RATE_PARENT, 0xac, 0, 1,
  CLK_MUX_HIWORD_MASK, },
{ HI3660_CLK_MUX_UART0, "clk_mux_uart0", clk_mux_uart0_p,
  ARRAY_SIZE(clk_mux_uart0_p), CLK_SET_RATE_PARENT, 0xac, 2, 1,
-- 
2.10.2



[PATCH v2 3/3] clk: hi3660: Set PPLL2 to 2880M

2017-05-26 Thread Guodong Xu
From: Zhong Kaihua 

Set PPLL2 to 2880M. With this patch, we saw better compatibility
on various 1080p HDMI monitors.

Signed-off-by: Zhong Kaihua 
Signed-off-by: Zheng Shaobo 
---
 drivers/clk/hisilicon/clk-hi3660.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/hisilicon/clk-hi3660.c 
b/drivers/clk/hisilicon/clk-hi3660.c
index 67c4d44..eb9ba41 100644
--- a/drivers/clk/hisilicon/clk-hi3660.c
+++ b/drivers/clk/hisilicon/clk-hi3660.c
@@ -20,7 +20,7 @@ static const struct hisi_fixed_rate_clock 
hi3660_fixed_rate_clks[] = {
{ HI3660_CLK_FLL_SRC, "clk_fll_src", NULL, 0, 12800, },
{ HI3660_CLK_PPLL0, "clk_ppll0", NULL, 0, 16, },
{ HI3660_CLK_PPLL1, "clk_ppll1", NULL, 0, 186600, },
-   { HI3660_CLK_PPLL2, "clk_ppll2", NULL, 0, 96000, },
+   { HI3660_CLK_PPLL2, "clk_ppll2", NULL, 0, 288000, },
{ HI3660_CLK_PPLL3, "clk_ppll3", NULL, 0, 129000, },
{ HI3660_CLK_SCPLL, "clk_scpll", NULL, 0, 24576, },
{ HI3660_PCLK, "pclk", NULL, 0, 2000, },
@@ -42,7 +42,7 @@ static const struct hisi_fixed_factor_clock 
hi3660_crg_fixed_factor_clks[] = {
{ HI3660_CLK_GATE_I2C6, "clk_gate_i2c6", "clk_i2c6_iomcu", 1, 4, 0, },
{ HI3660_CLK_DIV_SYSBUS, "clk_div_sysbus", "clk_mux_sysbus", 1, 7, 0, },
{ HI3660_CLK_DIV_320M, "clk_div_320m", "clk_320m_pll_gt", 1, 5, 0, },
-   { HI3660_CLK_DIV_A53, "clk_div_a53hpm", "clk_a53hpm_andgt", 1, 2, 0, },
+   { HI3660_CLK_DIV_A53, "clk_div_a53hpm", "clk_a53hpm_andgt", 1, 6, 0, },
{ HI3660_CLK_GATE_SPI0, "clk_gate_spi0", "clk_ppll0", 1, 8, 0, },
{ HI3660_CLK_GATE_SPI2, "clk_gate_spi2", "clk_ppll0", 1, 8, 0, },
{ HI3660_PCIEPHY_REF, "clk_pciephy_ref", "clk_div_pciephy", 1, 1, 0, },
-- 
2.10.2



Re: [PATCH 2/2] Revert "ACPI / button: Change default behavior to lid_init_state=open"

2017-05-26 Thread Peter Hutterer
On May 25 2017, Benjamin Tissoires wrote:
> On May 15 2017 or thereabouts, Rafael J. Wysocki wrote:

> > >> >> Benjamin, my understanding is that this is the case, is it correct?
> > >> >
> > >> > That is correct. This patch I reverted introduces regression for 
> > >> > professional
> > >> > laptops that expect the LID switch to be reported accurately.
> > >>
> > >> And from a user's perspective, what does not work any more?
> > >
> > > If you boot or resume your laptop with the lid closed on a docking
> > > station while using an external monitor connected to it, both internal
> > > and external displays will light on, while only the external should.
> > >
> > > There is a design choice in gdm to only provide the greater on the
> > > internal display when lit on, so users only see a gray area on the
> > > external monitor. Also, the cursor will not show up as it's by default
> > > on the internal display too.
> > >
> > > To "fix" that, users have to open the laptop once and close it once
> > > again to sync the state of the switch with the hardware state.
> >
> > OK
> >
> > Yeah, that sucks.
> >
> > So without the Lv's patch the behavior (on the systems in question) is
> > as expected, right?
> 
> Would you agree to take both these reverts without Lv's ACK? We already
> tried to explain for 2 weeks that they are valuable, but it seems we
> can't make change his mind.
> 
> I have more that 26 emails in my INBOX (not counting my replies) and I
> would really like switching to more valuable work than explaining again
> and again that when a regression is introduced, it needs to be fixed (or
> reverted in that case).

Yes please. This should have stopped right after "regression on basically
every decent laptop out there" and we should be discussing how to fix the
devices that actually need quirks because they're broken. Instead it 
turned into a discussion on why we should stick with the regression and
convince all of userspace to change and implement broken heuristics. I've
used up my time budget for that.

Cheers,
   Peter


Re: [PATCH] ARM: dts: keystone-k2l: fix broken Ethernet due to disabled OSR

2017-05-26 Thread Sekhar Nori
Hi Arnd,

On Friday 31 March 2017 03:43 PM, Arnd Bergmann wrote:
> On Wed, Mar 29, 2017 at 6:13 PM, santosh.shilim...@oracle.com
>  wrote:
>>> Signed-off-by: Murali Karicheri 
>>> Acked-by: Tero Kristo 
>>> [nsek...@ti.com: commit message updates, port to latest mainline]
>>> Signed-off-by: Sekhar Nori 
>>> ---
>>
>> Acked-by: Santosh Shilimkar 
>>
>> Can you please pick this up for rcx fixes ?
> 
> Applied, thanks!

Looks like this fix never made to to mainline. Do you have the patch
with you still? It will have to be marked for v4.11 stable and pushed.

Thanks,
Sekhar


Re: [patch V3 25/32] kprobes: Cure hotplug lock ordering issues

2017-05-26 Thread Thomas Gleixner
On Thu, 25 May 2017, Masami Hiramatsu wrote:
> On Wed, 24 May 2017 10:15:36 +0200
> Thomas Gleixner  wrote:
> 
> > Converting the cpu hotplug locking to a percpu rwsem unearthed hidden lock
> > ordering problems.
> > 
> > There is a wide range of locks involved in this: kprobe_mutex,
> > jump_label_mutex, ftrace_lock, text_mutex, event_mutex,
> > func_hash->regex_lock and a gazillion of lock order permutations with
> > nested get_online_cpus() calls.
> 
> And module_mutex too ;-)

Indeed.

> > Some of those permutations are potential deadlocks even with the current
> > nesting hotplug locking scheme, but they can't be discovered by lockdep.
> > 
> > The conversion of the hotplug locking to a percpu rwsem requires to prevent
> > nested locking, so it's required to take the hotplug rwsem early in the
> > call chain and establish a proper lock order.
> > 
> > After quite some analysis and going down the wrong road severa times the
> > following lock order has been chosen:
> > 
> > kprobe_mutex -> cpus_rwsem -> jump_label_mutex -> text_mutex
> 
> This seems only change the locking order of module_mutex and
> cpus_rwsem. Previously module_mutex -> cpus_rwsem, now
> cpus_rwsem -> module_mutex. and it seems OK to me.
> (checked in module.c and other use cases of module_mutex)

This also changes the jump label / text mutex interaction with hotplug
locking if you look closely :)



[PATCH v3 1/2] net: phy: Add Cortina CS4340 driver

2017-05-26 Thread Bogdan Purcareata
Add basic support for Cortina PHY drivers. Support only CS4340 for now.
The phys are not compatible with IEEE 802.3 clause 22/45 registers.

Implement proper read_status support. The generic 10G phy driver causes
bus register access errors.

The driver should be described using the "ethernet-phy-id" device tree
compatible.

Signed-off-by: Bogdan Purcareata 
---
v2 -> v3:
- Add probe function to check the device we're talking with is the same
  as the one described in the device tree.
- Change the link status (GPIO interrupt status) register and validate
  that the read is done from the right place (cable plug-in / plug-out).
- Some functions + Kconfig entry renaming.

v1 -> v2:
- Rename "mdio-cortina.c" to "cortina.c" since it's a phy driver.
- Test probing based on the "ethernet-phy-id" compatible. In the previous
  version, getting the phy_id via get_phy_c45_ids() involved an additional
  hack. Drop that approach and document probing in the commit message.

 drivers/net/phy/Kconfig   |   5 ++
 drivers/net/phy/Makefile  |   1 +
 drivers/net/phy/cortina.c | 115 ++
 3 files changed, 121 insertions(+)
 create mode 100644 drivers/net/phy/cortina.c

diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 22dea7f..8cd7a0e 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -240,6 +240,11 @@ config CICADA_PHY
---help---
  Currently supports the cis8204
 
+config CORTINA_PHY
+   tristate "Cortina EDC CDR 10G Ethernet PHY"
+   ---help---
+ Currently supports the CS4340 phy.
+
 config DAVICOM_PHY
tristate "Davicom PHYs"
---help---
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index 79365be..0de3e20 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -47,6 +47,7 @@ obj-$(CONFIG_BCM_CYGNUS_PHY)  += bcm-cygnus.o
 obj-$(CONFIG_BCM_NET_PHYLIB)   += bcm-phy-lib.o
 obj-$(CONFIG_BROADCOM_PHY) += broadcom.o
 obj-$(CONFIG_CICADA_PHY)   += cicada.o
+obj-$(CONFIG_CORTINA_PHY)  += cortina.o
 obj-$(CONFIG_DAVICOM_PHY)  += davicom.o
 obj-$(CONFIG_DP83640_PHY)  += dp83640.o
 obj-$(CONFIG_DP83848_PHY)  += dp83848.o
diff --git a/drivers/net/phy/cortina.c b/drivers/net/phy/cortina.c
new file mode 100644
index 000..209c022
--- /dev/null
+++ b/drivers/net/phy/cortina.c
@@ -0,0 +1,115 @@
+/*
+ *Copyright 2017 NXP
+ *
+ *This program is free software; you can redistribute it and/or modify
+ *it under the terms of the GNU General Public License as published by
+ *the Free Software Foundation; either version 2 of the License, or
+ *(at your option) any later version.
+ *
+ *This program is distributed in the hope that it will be useful,
+ *but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *GNU General Public License for more details.
+ *
+ */
+#include 
+#include 
+
+#define PHY_ID_CS4340  0x13e51002
+
+#define VILLA_GLOBAL_CHIP_ID_LSB   0x0
+#define VILLA_GLOBAL_CHIP_ID_MSB   0x1
+
+#define VILLA_GLOBAL_GPIO_1_INTS   0x017
+
+static int cortina_read_reg(struct phy_device *phydev, u16 regnum)
+{
+   return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr,
+   MII_ADDR_C45 | regnum);
+}
+
+static int cortina_config_aneg(struct phy_device *phydev)
+{
+   phydev->supported = SUPPORTED_1baseT_Full;
+   phydev->advertising = SUPPORTED_1baseT_Full;
+
+   return 0;
+}
+
+static int cortina_read_status(struct phy_device *phydev)
+{
+   int gpio_int_status, ret = 0;
+
+   gpio_int_status = cortina_read_reg(phydev, VILLA_GLOBAL_GPIO_1_INTS);
+   if (gpio_int_status < 0) {
+   ret = gpio_int_status;
+   goto err;
+   }
+
+   if (gpio_int_status & 0x8) {
+   /* up when edc_convergedS set */
+   phydev->speed = SPEED_1;
+   phydev->duplex = DUPLEX_FULL;
+   phydev->link = 1;
+   } else {
+   phydev->link = 0;
+   }
+
+err:
+   return ret;
+}
+
+static int cortina_soft_reset(struct phy_device *phydev)
+{
+   return 0;
+}
+
+static int cortina_probe(struct phy_device *phydev)
+{
+   u32 phy_id = 0, id_lsb, id_msb;
+
+   /* Read device id from phy registers. */
+   id_lsb = cortina_read_reg(phydev, VILLA_GLOBAL_CHIP_ID_LSB);
+   if (id_lsb < 0)
+   return -ENXIO;
+
+   phy_id = id_lsb << 16;
+
+   id_msb = cortina_read_reg(phydev, VILLA_GLOBAL_CHIP_ID_MSB);
+   if (id_msb < 0)
+   return -ENXIO;
+
+   phy_id |= id_msb;
+
+   /* Make sure the device tree binding matched the driver with the
+* right device.
+*/
+   if (phy_id != phydev->drv->phy_id) {
+   phydev_err(phydev, "Error matching phy with %s driver\n",

Re: [PATCH 1/5] efi: Move the x86 secure boot switch to generic code

2017-05-26 Thread joeyli
Hi David,

On Wed, May 24, 2017 at 03:45:25PM +0100, David Howells wrote:
> Move the switch-statement in x86's setup_arch() that inteprets the
> secure_boot boot parameter to generic code.
> 
> Suggested-by: Ard Biesheuvel 
> Signed-off-by: David Howells 

I reviewed the context for this patch.

Reviewed-by: Joey Lee 

Regards
Joey Lee

> ---
> 
>  arch/x86/kernel/setup.c   |   14 +-
>  drivers/firmware/efi/Kconfig  |   23 +++
>  drivers/firmware/efi/Makefile |1 +
>  drivers/firmware/efi/secureboot.c |   34 ++
>  include/linux/efi.h   |6 ++
>  5 files changed, 65 insertions(+), 13 deletions(-)
>  create mode 100644 drivers/firmware/efi/secureboot.c
> 
> diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> index 0b4d3c686b1e..8bffbd8d2c1c 100644
> --- a/arch/x86/kernel/setup.c
> +++ b/arch/x86/kernel/setup.c
> @@ -1177,19 +1177,7 @@ void __init setup_arch(char **cmdline_p)
>   /* Allocate bigger log buffer */
>   setup_log_buf(1);
>  
> - if (efi_enabled(EFI_BOOT)) {
> - switch (boot_params.secure_boot) {
> - case efi_secureboot_mode_disabled:
> - pr_info("Secure boot disabled\n");
> - break;
> - case efi_secureboot_mode_enabled:
> - pr_info("Secure boot enabled\n");
> - break;
> - default:
> - pr_info("Secure boot could not be determined\n");
> - break;
> - }
> - }
> + efi_set_secure_boot(boot_params.secure_boot);
>  
>   reserve_initrd();
>  
> diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig
> index 394db40ed374..c40fdeaf9a45 100644
> --- a/drivers/firmware/efi/Kconfig
> +++ b/drivers/firmware/efi/Kconfig
> @@ -84,6 +84,29 @@ config EFI_PARAMS_FROM_FDT
>  config EFI_RUNTIME_WRAPPERS
>   bool
>  
> +config EFI_SECURE_BOOT
> + bool "Support UEFI Secure Boot and lock down the kernel in secure boot 
> mode"
> + default n
> + help
> +   UEFI Secure Boot provides a mechanism for ensuring that the firmware
> +   will only load signed bootloaders and kernels.  Secure boot mode may
> +   be determined from EFI variables provided by the system firmware if
> +   not indicated by the boot parameters.
> +
> +   Enabling this option turns on support for UEFI secure boot in the
> +   kernel.  This will result in various kernel facilities being locked
> +   away from userspace if the kernel detects that it has been booted in
> +   secure boot mode.  If it hasn't been booted in secure boot mode, or
> +   this cannot be determined, the lock down doesn't occur.
> +
> +   The kernel facilities that get locked down include:
> +   - Viewing or changing the kernel's memory
> +   - Directly accessing ioports
> +   - Directly specifying ioports and other hardware parameters to drivers
> +   - Storing the kernel image unencrypted for hibernation
> +   - Loading unsigned modules
> +   - Kexec'ing unsigned images
> +
>  config EFI_ARMSTUB
>   bool
>  
> diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
> index 0329d319d89a..9dfd8530063f 100644
> --- a/drivers/firmware/efi/Makefile
> +++ b/drivers/firmware/efi/Makefile
> @@ -23,6 +23,7 @@ obj-$(CONFIG_EFI_FAKE_MEMMAP)   += fake_mem.o
>  obj-$(CONFIG_EFI_BOOTLOADER_CONTROL) += efibc.o
>  obj-$(CONFIG_EFI_TEST)   += test/
>  obj-$(CONFIG_EFI_DEV_PATH_PARSER)+= dev-path-parser.o
> +obj-$(CONFIG_EFI_SECURE_BOOT)+= secureboot.o
>  obj-$(CONFIG_APPLE_PROPERTIES)   += apple-properties.o
>  
>  arm-obj-$(CONFIG_EFI):= arm-init.o arm-runtime.o
> diff --git a/drivers/firmware/efi/secureboot.c 
> b/drivers/firmware/efi/secureboot.c
> new file mode 100644
> index ..cf5bccae15e8
> --- /dev/null
> +++ b/drivers/firmware/efi/secureboot.c
> @@ -0,0 +1,34 @@
> +/* Core kernel secure boot support.
> + *
> + * Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
> + * Written by David Howells (dhowe...@redhat.com)
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public Licence
> + * as published by the Free Software Foundation; either version
> + * 2 of the Licence, or (at your option) any later version.
> + */
> +
> +#include 
> +#include 
> +#include 
> +
> +/*
> + * Decide what to do when UEFI secure boot mode is enabled.
> + */
> +void __init efi_set_secure_boot(enum efi_secureboot_mode mode)
> +{
> + if (efi_enabled(EFI_BOOT)) {
> + switch (mode) {
> + case efi_secureboot_mode_disabled:
> + pr_info("Secure boot disabled\n");
> + break;
> +   

[PATCH v3 2/2] dt-bindings: net: Add Cortina device tree bindings

2017-05-26 Thread Bogdan Purcareata
Add device tree description info for Cortina 10G phy devices.

Signed-off-by: Bogdan Purcareata 
---
Patch introduced in v3 of the patchset.

 Documentation/devicetree/bindings/net/cortina.txt | 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/cortina.txt

diff --git a/Documentation/devicetree/bindings/net/cortina.txt 
b/Documentation/devicetree/bindings/net/cortina.txt
new file mode 100644
index 000..006a1ee
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/cortina.txt
@@ -0,0 +1,19 @@
+Cortina Phy Driver Device Tree Bindings
+---
+
+The driver supports the Cortina Electronic Dispersion Compensation (EDC)
+devices, equipped with clock and data recovery (CDR) circuits. These
+devices make use of registers that are not compatible with Clause 45 or
+Clause 22, therefore they need to be described using the
+"ethernet-phy-id" compatible.
+
+Since the driver only implements  polling mode support, interrupts info
+can be skipped.
+
+Example (CS4340 phy):
+   mdio {
+   cs4340_phy@1 {
+   compatible = "ethernet-phy-id13e5.1002";
+   reg = <0x10>;
+   };
+   };
-- 
1.9.1



[PATCH v3 0/2] net: phy: Support managed Cortina phys

2017-05-26 Thread Bogdan Purcareata
So far, the Cortina family phys (CS4340 in this particular case) are only
supported in fixed link mode (via fixed_phy_register). The generic 10G
phy driver does not work well with the phylib state machine, when the phy
is registered via of_phy_connect. This prohibits the user from describing the
phy nodes in the device tree.

In order to support this scenario, and to properly describe the board
device tree, add a minimal Cortina driver that reads the status from the
right register. With the generic 10G C45 driver, the kernel will print
messages like:
[0.226521] mdio_bus 8b96000: Error while reading PHY16 reg at 1.6
[0.232780] mdio_bus 8b96000: Error while reading PHY16 reg at 1.5

v2 -> v3:
- Add documentation entry.

v1 -> v2:
- Change approach for getting the phy_id from hacking get_phy_c45_ids to
  describing the device in the device tree via ethernet-phy-id.

More patch version changes per individual patches.

Bogdan Purcareata (2):
  net: phy: Add Cortina CS4340 driver
  dt-bindings: net: Add Cortina device tree bindings

 Documentation/devicetree/bindings/net/cortina.txt |  19 
 drivers/net/phy/Kconfig   |   5 +
 drivers/net/phy/Makefile  |   1 +
 drivers/net/phy/cortina.c | 115 ++
 4 files changed, 140 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/cortina.txt
 create mode 100644 drivers/net/phy/cortina.c

-- 
1.9.1



[GIT PULL] sound fixes for 4.12-rc3

2017-05-26 Thread Takashi Iwai
Linus,

please pull sound fixes for v4.12-rc3 from:

  git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git 
tags/sound-4.12-rc3

The topmost commit is 1fc2e41f7af4572b07190f9dec28396b418e9a36



sound fixes for 4.12-rc3

This contains a few HD-audio device-specific quirks and an endianess
fix for USB-audio, as well as the update of quirk model list
document.  All fixes are small and trivial.

The document update could have been postponed, but it's a good thing
for user and has absolutely zero risk of breakage, so included here.



Alexander Tsoy (1):
  ALSA: hda - apply STAC_9200_DELL_M22 quirk for Dell Latitude D430

Johan Hovold (1):
  ALSA: usb-audio: fix Amanero Combo384 quirk on big-endian hosts

Takashi Iwai (4):
  ALSA: hda - No loopback on ALC299 codec
  ALSA: hda - Apply dual-codec quirk for MSI Z270-Gaming mobo
  ALSA: hda - Provide dual-codecs model option for a few Realtek codecs
  ALSA: hda - Update the list of quirk models

---
 Documentation/sound/hd-audio/models.rst | 114 ++--
 sound/pci/hda/patch_realtek.c   |   7 ++
 sound/pci/hda/patch_sigmatel.c  |   2 +
 sound/usb/quirks.c  |   2 +-
 4 files changed, 75 insertions(+), 50 deletions(-)

diff --git a/Documentation/sound/hd-audio/models.rst 
b/Documentation/sound/hd-audio/models.rst
index 5338673c88d9..773d2bfacc6c 100644
--- a/Documentation/sound/hd-audio/models.rst
+++ b/Documentation/sound/hd-audio/models.rst
@@ -16,6 +16,8 @@ ALC880
 6-jack in back, 2-jack in front
 6stack-digout
 6-jack with a SPDIF out
+6stack-automute
+6-jack with headphone jack detection
 
 ALC260
 ==
@@ -62,6 +64,8 @@ lenovo-dock
 Enables docking station I/O for some Lenovos
 hp-gpio-led
 GPIO LED support on HP laptops
+hp-dock-gpio-mic1-led
+HP dock with mic LED support
 dell-headset-multi
 Headset jack, which can also be used as mic-in
 dell-headset-dock
@@ -72,6 +76,12 @@ alc283-sense-combo
 Combo jack sensing on ALC283
 tpt440-dock
 Pin configs for Lenovo Thinkpad Dock support
+tpt440
+Lenovo Thinkpad T440s setup
+tpt460
+Lenovo Thinkpad T460/560 setup
+dual-codecs
+Lenovo laptops with dual codecs
 
 ALC66x/67x/892
 ==
@@ -97,6 +107,8 @@ inv-dmic
 Inverted internal mic workaround
 dell-headset-multi
 Headset jack, which can also be used as mic-in
+dual-codecs
+Lenovo laptops with dual codecs
 
 ALC680
 ==
@@ -114,6 +126,8 @@ inv-dmic
 Inverted internal mic workaround
 no-primary-hp
 VAIO Z/VGC-LN51JGB workaround (for fixed speaker DAC)
+dual-codecs
+ALC1220 dual codecs for Gaming mobos
 
 ALC861/660
 ==
@@ -206,65 +220,47 @@ auto
 
 Conexant 5045
 =
-laptop-hpsense
-Laptop with HP sense (old model laptop)
-laptop-micsense
-Laptop with Mic sense (old model fujitsu)
-laptop-hpmicsense
-Laptop with HP and Mic senses
-benq
-Benq R55E
-laptop-hp530
-HP 530 laptop
-test
-for testing/debugging purpose, almost all controls can be
-adjusted.  Appearing only when compiled with $CONFIG_SND_DEBUG=y
+cap-mix-amp
+Fix max input level on mixer widget
+toshiba-p105
+Toshiba P105 quirk
+hp-530
+HP 530 quirk
 
 Conexant 5047
 =
-laptop
-Basic Laptop config 
-laptop-hp
-Laptop config for some HP models (subdevice 30A5)
-laptop-eapd
-Laptop config with EAPD support
-test
-for testing/debugging purpose, almost all controls can be
-adjusted.  Appearing only when compiled with $CONFIG_SND_DEBUG=y
+cap-mix-amp
+Fix max input level on mixer widget
 
 Conexant 5051
 =
-laptop
-Basic Laptop config (default)
-hp
-HP Spartan laptop
-hp-dv6736
-HP dv6736
-hp-f700
-HP Compaq Presario F700
-ideapad
-Lenovo IdeaPad laptop
-toshiba
-Toshiba Satellite M300
+lenovo-x200
+Lenovo X200 quirk
 
 Conexant 5066
 =
-laptop
-Basic Laptop config (default)
-hp-laptop
-HP laptops, e g G60
-asus
-Asus K52JU, Lenovo G560
-dell-laptop
-Dell laptops
-dell-vostro
-Dell Vostro
-olpc-xo-1_5
-OLPC XO 1.5
-ideapad
-Lenovo IdeaPad U150
+stereo-dmic
+Workaround for inverted stereo digital mic
+gpio1
+Enable GPIO1 pin
+headphone-mic-pin
+Enable headphone mic NID 0x18 without detection
+tp410
+Thinkpad T400 & co quirks
 thinkpad
-Lenovo Thinkpad
+Thinkpad mute/mic LED quirk
+lemote-a1004
+Lemote A1004 quirk
+lemote-a1205
+Lemote A1205 quirk
+olpc-xo
+OLPC XO quirk
+mute-led-eapd
+Mute LED control via EAPD
+hp-dock
+HP dock support
+mute-led-gpio
+Mute LED control via GPIO
 
 STAC9200
 
@@ -444,6 +440,8 @@ dell-eq
 Dell desktops/laptops
 alienware
 Alienware M17x
+asus-mobo
+Pin configs for ASUS mobo with 5.1/SPDIF out
 auto
 BIOS setup (default)
 
@@ -477,6 

Re: [PATCH 1/5] MIPS: Optimize uasm insn lookup.

2017-05-26 Thread Matt Redfearn

Hi David,


On 26/05/17 01:38, David Daney wrote:

Instead of doing a linear search through the insn_table for each
instruction, use the opcode as direct index into the table.  This will
give constant time lookup performance as the number of supported
opcodes increases.  Make the tables const as they are only ever read.
For uasm-mips.c sort the table alphabetically, and remove duplicate
entries, uasm-micromips.c was already sorted and duplicate free.
There is a small savings in object size as struct insn loses a field:

$ size arch/mips/mm/uasm-mips.o arch/mips/mm/uasm-mips.o.save
text   data bss dec hex filename
   10040  0   0   100402738 arch/mips/mm/uasm-mips.o
9240   1120   0   103602878 arch/mips/mm/uasm-mips.o.save

Signed-off-by: David Daney 
---
  arch/mips/mm/uasm-micromips.c | 188 ++--
  arch/mips/mm/uasm-mips.c  | 217 +-
  arch/mips/mm/uasm.c   |   3 +-
  3 files changed, 199 insertions(+), 209 deletions(-)

diff --git a/arch/mips/mm/uasm-micromips.c b/arch/mips/mm/uasm-micromips.c
index 277cf52..da6de62 100644
--- a/arch/mips/mm/uasm-micromips.c
+++ b/arch/mips/mm/uasm-micromips.c
@@ -40,93 +40,92 @@
  
  #include "uasm.c"
  
-static struct insn insn_table_MM[] = {

-   { insn_addu, M(mm_pool32a_op, 0, 0, 0, 0, mm_addu32_op), RT | RS | RD },
-   { insn_addiu, M(mm_addiu32_op, 0, 0, 0, 0, 0), RT | RS | SIMM },
-   { insn_and, M(mm_pool32a_op, 0, 0, 0, 0, mm_and_op), RT | RS | RD },
-   { insn_andi, M(mm_andi32_op, 0, 0, 0, 0, 0), RT | RS | UIMM },
-   { insn_beq, M(mm_beq32_op, 0, 0, 0, 0, 0), RS | RT | BIMM },
-   { insn_beql, 0, 0 },
-   { insn_bgez, M(mm_pool32i_op, mm_bgez_op, 0, 0, 0, 0), RS | BIMM },
-   { insn_bgezl, 0, 0 },
-   { insn_bltz, M(mm_pool32i_op, mm_bltz_op, 0, 0, 0, 0), RS | BIMM },
-   { insn_bltzl, 0, 0 },
-   { insn_bne, M(mm_bne32_op, 0, 0, 0, 0, 0), RT | RS | BIMM },
-   { insn_cache, M(mm_pool32b_op, 0, 0, mm_cache_func, 0, 0), RT | RS | 
SIMM },
-   { insn_cfc1, M(mm_pool32f_op, 0, 0, 0, mm_cfc1_op, mm_32f_73_op), RT | 
RS },
-   { insn_cfcmsa, M(mm_pool32s_op, 0, msa_cfc_op, 0, 0, mm_32s_elm_op), RD 
| RE },
-   { insn_ctc1, M(mm_pool32f_op, 0, 0, 0, mm_ctc1_op, mm_32f_73_op), RT | 
RS },
-   { insn_ctcmsa, M(mm_pool32s_op, 0, msa_ctc_op, 0, 0, mm_32s_elm_op), RD 
| RE },
-   { insn_daddu, 0, 0 },
-   { insn_daddiu, 0, 0 },
-   { insn_di, M(mm_pool32a_op, 0, 0, 0, mm_di_op, mm_pool32axf_op), RS },
-   { insn_divu, M(mm_pool32a_op, 0, 0, 0, mm_divu_op, mm_pool32axf_op), RT 
| RS },
-   { insn_dmfc0, 0, 0 },
-   { insn_dmtc0, 0, 0 },
-   { insn_dsll, 0, 0 },
-   { insn_dsll32, 0, 0 },
-   { insn_dsra, 0, 0 },
-   { insn_dsrl, 0, 0 },
-   { insn_dsrl32, 0, 0 },
-   { insn_drotr, 0, 0 },
-   { insn_drotr32, 0, 0 },
-   { insn_dsubu, 0, 0 },
-   { insn_eret, M(mm_pool32a_op, 0, 0, 0, mm_eret_op, mm_pool32axf_op), 0 
},
-   { insn_ins, M(mm_pool32a_op, 0, 0, 0, 0, mm_ins_op), RT | RS | RD | RE 
},
-   { insn_ext, M(mm_pool32a_op, 0, 0, 0, 0, mm_ext_op), RT | RS | RD | RE 
},
-   { insn_j, M(mm_j32_op, 0, 0, 0, 0, 0), JIMM },
-   { insn_jal, M(mm_jal32_op, 0, 0, 0, 0, 0), JIMM },
-   { insn_jalr, M(mm_pool32a_op, 0, 0, 0, mm_jalr_op, mm_pool32axf_op), RT 
| RS },
-   { insn_jr, M(mm_pool32a_op, 0, 0, 0, mm_jalr_op, mm_pool32axf_op), RS },
-   { insn_lb, M(mm_lb32_op, 0, 0, 0, 0, 0), RT | RS | SIMM },
-   { insn_ld, 0, 0 },
-   { insn_lh, M(mm_lh32_op, 0, 0, 0, 0, 0), RS | RS | SIMM },
-   { insn_ll, M(mm_pool32c_op, 0, 0, (mm_ll_func << 1), 0, 0), RS | RT | 
SIMM },
-   { insn_lld, 0, 0 },
-   { insn_lui, M(mm_pool32i_op, mm_lui_op, 0, 0, 0, 0), RS | SIMM },
-   { insn_lw, M(mm_lw32_op, 0, 0, 0, 0, 0), RT | RS | SIMM },
-   { insn_mfc0, M(mm_pool32a_op, 0, 0, 0, mm_mfc0_op, mm_pool32axf_op), RT 
| RS | RD },
-   { insn_mfhi, M(mm_pool32a_op, 0, 0, 0, mm_mfhi32_op, mm_pool32axf_op), 
RS },
-   { insn_mflo, M(mm_pool32a_op, 0, 0, 0, mm_mflo32_op, mm_pool32axf_op), 
RS },
-   { insn_mtc0, M(mm_pool32a_op, 0, 0, 0, mm_mtc0_op, mm_pool32axf_op), RT 
| RS | RD },
-   { insn_mthi, M(mm_pool32a_op, 0, 0, 0, mm_mthi32_op, mm_pool32axf_op), 
RS },
-   { insn_mtlo, M(mm_pool32a_op, 0, 0, 0, mm_mtlo32_op, mm_pool32axf_op), 
RS },
-   { insn_mul, M(mm_pool32a_op, 0, 0, 0, 0, mm_mul_op), RT | RS | RD },
-   { insn_or, M(mm_pool32a_op, 0, 0, 0, 0, mm_or32_op), RT | RS | RD },
-   { insn_ori, M(mm_ori32_op, 0, 0, 0, 0, 0), RT | RS | UIMM },
-   { insn_pref, M(mm_pool32c_op, 0, 0, (mm_pref_func << 1), 0, 0), RT | RS 
| SIMM },
-   { insn_rfe, 0, 0 },
-   { insn_sc, M(mm_pool32c_op, 0, 0, (mm_sc_func << 1), 0, 0), RT | RS | 
SIMM },
-   { insn_scd, 0, 0 },
-   { insn_sd, 0, 0 },
-   { 

[PATCH] powerpc/perf: Fix Power9 test_adder field

2017-05-26 Thread Madhavan Srinivasan
Commit 8d911904f3ce4 ('powerpc/perf: Add restrictions to PMC5 in power9 DD1')
was added to restrict the use of PMC5 in Power9 DD1. Intend is to diable
the use of PMC5 using raw event code. Commit instead of updating 
"power9_isa207_pmu"
structure, updated "power9_pmu" structure. Patch to fix the same.

Fixes: 8d911904f3ce4 ('powerpc/perf: Add restrictions to PMC5 in power9 DD1')
Reported-by: Shriya 
Signed-off-by: Madhavan Srinivasan 
---
 arch/powerpc/perf/power9-pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/perf/power9-pmu.c b/arch/powerpc/perf/power9-pmu.c
index 018f8e90ac35..bb28e1a41257 100644
--- a/arch/powerpc/perf/power9-pmu.c
+++ b/arch/powerpc/perf/power9-pmu.c
@@ -402,7 +402,7 @@ static struct power_pmu power9_isa207_pmu = {
.name   = "POWER9",
.n_counter  = MAX_PMU_COUNTERS,
.add_fields = ISA207_ADD_FIELDS,
-   .test_adder = ISA207_TEST_ADDER,
+   .test_adder = P9_DD1_TEST_ADDER,
.compute_mmcr   = isa207_compute_mmcr,
.config_bhrb= power9_config_bhrb,
.bhrb_filter_map= power9_bhrb_filter_map,
@@ -421,7 +421,7 @@ static struct power_pmu power9_pmu = {
.name   = "POWER9",
.n_counter  = MAX_PMU_COUNTERS,
.add_fields = ISA207_ADD_FIELDS,
-   .test_adder = P9_DD1_TEST_ADDER,
+   .test_adder = ISA207_TEST_ADDER,
.compute_mmcr   = isa207_compute_mmcr,
.config_bhrb= power9_config_bhrb,
.bhrb_filter_map= power9_bhrb_filter_map,
-- 
2.7.4



[RFC PATCH v4 05/12] x86/ioapic: Refactor the delay logic in timer_irq_works()

2017-05-26 Thread Dou Liyang
Kernel use timer_irq_works() to detects the timer IRQs. It calls
mdelay(10) to delay ten ticks and checks whether the timer IRQs work
or not. The mdelay() depends on the loops_per_jiffy which is set up
in calibrate_delay(). But in "notsc" case, calibrating delay also
should make sure the timer IRQs work well. There need each other.

Current kernel defaults the IRQs is available when it calibrates delay.
But it is wrong in the dump-capture kernel with 'notsc' option inherited
from 1st kernel option. The correct design is making the interrupt mode
setup and checking IRQs works in advance of calibrate_delay(). That results
in the mdelay() being unusable in timer_irq_works().

Refactor the delay logic by waiting for some cycles. In the system with
X86_FEATURE_TSC feature, Use rdtsc(), others will call __delay() directly.

Note: regard 4G as the max CPU frequence of current single CPU.

Signed-off-by: Dou Liyang 
---

V3 --> V4:
  -Rewrite the changelog
  -Delete a blank line
v2 --> v3:
  -Find a new way to for waiting.
  -Reference to the realization of hpet_clocksource_register() by Thomas.

 arch/x86/kernel/apic/io_apic.c | 45 --
 1 file changed, 43 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
index 347bb9f..f710077 100644
--- a/arch/x86/kernel/apic/io_apic.c
+++ b/arch/x86/kernel/apic/io_apic.c
@@ -1607,6 +1607,43 @@ static int __init notimercheck(char *s)
 }
 __setup("no_timer_check", notimercheck);
 
+static void __init delay_with_tsc(void)
+{
+   unsigned long long start, now;
+   unsigned long ticks = jiffies;
+
+   start = rdtsc();
+
+   /*
+* We don't know the TSC frequency yet, but waiting for
+* 400/HZ TSC cycles is safe:
+* 4 GHz == 10 jiffies
+* 1 GHz == 40 jiffies
+*/
+   do {
+   rep_nop();
+   now = rdtsc();
+   } while ((now - start) < 400UL / HZ &&
+   time_before_eq(jiffies, ticks + 4));
+}
+
+static void __init delay_without_tsc(void)
+{
+   int band = 1;
+   unsigned long ticks = jiffies;
+
+   /*
+* We don't know any frequency yet, but waiting for
+* 4094000/HZ cycles is safe:
+* 4 GHz == 10 jiffies
+* 1 GHz == 40 jiffies
+* 1 << 1 + 1 << 2 +...+ 1 << 11 = 4094
+*/
+   do {
+   __delay(((1 << band++) * 1000UL) / HZ);
+   } while (band < 12 && time_before_eq(jiffies, ticks + 4));
+}
+
 /*
  * There is a nasty bug in some older SMP boards, their mptable lies
  * about the timer IRQ. We do the following to work around the situation:
@@ -1625,8 +1662,12 @@ static int __init timer_irq_works(void)
 
local_save_flags(flags);
local_irq_enable();
-   /* Let ten ticks pass... */
-   mdelay((10 * 1000) / HZ);
+
+   if (boot_cpu_has(X86_FEATURE_TSC))
+   delay_with_tsc();
+   else
+   delay_without_tsc();
+
local_irq_restore(flags);
 
/*
-- 
2.5.5





Re: [PATCH 3/5] Add the ability to lock down access to the running kernel image

2017-05-26 Thread joeyli
On Wed, May 24, 2017 at 03:45:45PM +0100, David Howells wrote:
> Provide a single call to allow kernel code to determine whether the system
> should be locked down, thereby disallowing various accesses that might
> allow the running kernel image to be changed including the loading of
> modules that aren't validly signed with a key we recognise, fiddling with
> MSR registers and disallowing hibernation,
> 
> Signed-off-by: David Howells 
> Acked-by: James Morris 

Reviewed-by: Joey Lee 

Regards
Joey Lee

> ---
> 
>  include/linux/kernel.h   |9 +
>  include/linux/security.h |   11 +++
>  security/Kconfig |   15 +++
>  security/Makefile|3 +++
>  security/lock_down.c |   46 
> ++
>  5 files changed, 84 insertions(+)
>  create mode 100644 security/lock_down.c
> 
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index 13bc08aba704..282a1684d6e8 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -276,6 +276,15 @@ extern int oops_may_print(void);
>  void do_exit(long error_code) __noreturn;
>  void complete_and_exit(struct completion *, long) __noreturn;
>  
> +#ifdef CONFIG_LOCK_DOWN_KERNEL
> +extern bool kernel_is_locked_down(void);
> +#else
> +static inline bool kernel_is_locked_down(void)
> +{
> + return false;
> +}
> +#endif
> +
>  /* Internal, do not use. */
>  int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long 
> *res);
>  int __must_check _kstrtol(const char *s, unsigned int base, long *res);
> diff --git a/include/linux/security.h b/include/linux/security.h
> index af675b576645..8db2d886aa90 100644
> --- a/include/linux/security.h
> +++ b/include/linux/security.h
> @@ -1698,5 +1698,16 @@ static inline void free_secdata(void *secdata)
>  { }
>  #endif /* CONFIG_SECURITY */
>  
> +#ifdef CONFIG_LOCK_DOWN_KERNEL
> +extern void __init lock_kernel_down(void);
> +#ifdef CONFIG_ALLOW_LOCKDOWN_LIFT
> +extern void lift_kernel_lockdown(void);
> +#endif
> +#else
> +static inline void lock_kernel_down(void)
> +{
> +}
> +#endif
> +
>  #endif /* ! __LINUX_SECURITY_H */
>  
> diff --git a/security/Kconfig b/security/Kconfig
> index 93027fdf47d1..4baac4aab277 100644
> --- a/security/Kconfig
> +++ b/security/Kconfig
> @@ -189,6 +189,21 @@ config STATIC_USERMODEHELPER_PATH
> If you wish for all usermode helper programs to be disabled,
> specify an empty string here (i.e. "").
>  
> +config LOCK_DOWN_KERNEL
> + bool "Allow the kernel to be 'locked down'"
> + help
> +   Allow the kernel to be locked down under certain circumstances, for
> +   instance if UEFI secure boot is enabled.  Locking down the kernel
> +   turns off various features that might otherwise allow access to the
> +   kernel image (eg. setting MSR registers).
> +
> +config ALLOW_LOCKDOWN_LIFT
> + bool
> + help
> +   Allow the lockdown on a kernel to be lifted, thereby restoring the
> +   ability of userspace to access the kernel image (eg. by SysRq+x under
> +   x86).
> +
>  source security/selinux/Kconfig
>  source security/smack/Kconfig
>  source security/tomoyo/Kconfig
> diff --git a/security/Makefile b/security/Makefile
> index f2d71cdb8e19..8c4a43e3d4e0 100644
> --- a/security/Makefile
> +++ b/security/Makefile
> @@ -29,3 +29,6 @@ obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o
>  # Object integrity file lists
>  subdir-$(CONFIG_INTEGRITY)   += integrity
>  obj-$(CONFIG_INTEGRITY)  += integrity/
> +
> +# Allow the kernel to be locked down
> +obj-$(CONFIG_LOCK_DOWN_KERNEL)   += lock_down.o
> diff --git a/security/lock_down.c b/security/lock_down.c
> new file mode 100644
> index ..dd98422fbda7
> --- /dev/null
> +++ b/security/lock_down.c
> @@ -0,0 +1,46 @@
> +/* Lock down the kernel
> + *
> + * Copyright (C) 2016 Red Hat, Inc. All Rights Reserved.
> + * Written by David Howells (dhowe...@redhat.com)
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public Licence
> + * as published by the Free Software Foundation; either version
> + * 2 of the Licence, or (at your option) any later version.
> + */
> +
> +#include 
> +#include 
> +
> +#ifdef CONFIG_ALLOW_LOCKDOWN_LIFT
> +static __read_mostly bool kernel_locked_down;
> +#else
> +static __ro_after_init bool kernel_locked_down;
> +#endif
> +
> +/*
> + * Put the kernel into lock-down mode.
> + */
> +void __init lock_kernel_down(void)
> +{
> + kernel_locked_down = true;
> +}
> +
> +/*
> + * Take the kernel out of lockdown mode.
> + */
> +#ifdef CONFIG_ALLOW_LOCKDOWN_LIFT
> +void lift_kernel_lockdown(void)
> +{
> + kernel_locked_down = false;
> +}
> +#endif
> +
> +/**
> + * kernel_is_locked_down - Find out if the kernel is locked down
> + */
> +bool kernel_is_locked_down(void)
> +{
> +  

[PATCH 5/8] i2c: break out ACPI support into seperate file

2017-05-26 Thread Wolfram Sang
Removes some ifdeffery. Also add the new file to the relevant
MAINTAINERS section.

Signed-off-by: Wolfram Sang 
---
 MAINTAINERS |   1 +
 drivers/i2c/Makefile|   1 +
 drivers/i2c/i2c-core-acpi.c | 653 
 drivers/i2c/i2c-core-base.c | 648 ---
 drivers/i2c/i2c-core.h  |  15 +
 5 files changed, 670 insertions(+), 648 deletions(-)
 create mode 100644 drivers/i2c/i2c-core-acpi.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 9e984645c4b08b..3ce38e77f96e6b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6273,6 +6273,7 @@ M:Mika Westerberg 

 L: linux-...@vger.kernel.org
 L: linux-a...@vger.kernel.org
 S: Maintained
+F: drivers/i2c/i2c-core-acpi.c
 
 I2C-TAOS-EVM DRIVER
 M: Jean Delvare 
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 189e0e6476f0a6..7bb65a4369e1e1 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -5,6 +5,7 @@
 obj-$(CONFIG_I2C_BOARDINFO)+= i2c-boardinfo.o
 obj-$(CONFIG_I2C)  += i2c-core.o
 i2c-core-objs  := i2c-core-base.o i2c-core-smbus.o
+i2c-core-$(CONFIG_ACPI)+= i2c-core-acpi.o
 i2c-core-$(CONFIG_I2C_SLAVE)   += i2c-core-slave.o
 i2c-core-$(CONFIG_OF)  += i2c-core-of.o
 
diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
new file mode 100644
index 00..052005579ed626
--- /dev/null
+++ b/drivers/i2c/i2c-core-acpi.c
@@ -0,0 +1,653 @@
+/*
+ * Linux I2C core ACPI support code
+ *
+ * Copyright (C) 2014 Intel Corp, Author: Lan Tianyu 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "i2c-core.h"
+
+struct i2c_acpi_handler_data {
+   struct acpi_connection_info info;
+   struct i2c_adapter *adapter;
+};
+
+struct gsb_buffer {
+   u8  status;
+   u8  len;
+   union {
+   u16 wdata;
+   u8  bdata;
+   u8  data[0];
+   };
+} __packed;
+
+struct i2c_acpi_lookup {
+   struct i2c_board_info *info;
+   acpi_handle adapter_handle;
+   acpi_handle device_handle;
+   acpi_handle search_handle;
+   int n;
+   int index;
+   u32 speed;
+   u32 min_speed;
+};
+
+static int i2c_acpi_fill_info(struct acpi_resource *ares, void *data)
+{
+   struct i2c_acpi_lookup *lookup = data;
+   struct i2c_board_info *info = lookup->info;
+   struct acpi_resource_i2c_serialbus *sb;
+   acpi_status status;
+
+   if (info->addr || ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS)
+   return 1;
+
+   sb = >data.i2c_serial_bus;
+   if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C)
+   return 1;
+
+   if (lookup->index != -1 && lookup->n++ != lookup->index)
+   return 1;
+
+   status = acpi_get_handle(lookup->device_handle,
+sb->resource_source.string_ptr,
+>adapter_handle);
+   if (!ACPI_SUCCESS(status))
+   return 1;
+
+   info->addr = sb->slave_address;
+   lookup->speed = sb->connection_speed;
+   if (sb->access_mode == ACPI_I2C_10BIT_MODE)
+   info->flags |= I2C_CLIENT_TEN;
+
+   return 1;
+}
+
+static int i2c_acpi_do_lookup(struct acpi_device *adev,
+ struct i2c_acpi_lookup *lookup)
+{
+   struct i2c_board_info *info = lookup->info;
+   struct list_head resource_list;
+   int ret;
+
+   if (acpi_bus_get_status(adev) || !adev->status.present ||
+   acpi_device_enumerated(adev))
+   return -EINVAL;
+
+   memset(info, 0, sizeof(*info));
+   lookup->device_handle = acpi_device_handle(adev);
+
+   /* Look up for I2cSerialBus resource */
+   INIT_LIST_HEAD(_list);
+   ret = acpi_dev_get_resources(adev, _list,
+i2c_acpi_fill_info, lookup);
+   acpi_dev_free_resource_list(_list);
+
+   if (ret < 0 || !info->addr)
+   return -EINVAL;
+
+   return 0;
+}
+
+static int i2c_acpi_get_info(struct acpi_device *adev,
+struct i2c_board_info *info,
+struct i2c_adapter *adapter,
+acpi_handle *adapter_handle)
+{
+   struct list_head resource_list;
+   struct resource_entry *entry;
+   struct i2c_acpi_lookup lookup;
+   int ret;
+
+   memset(, 0, sizeof(lookup));
+   lookup.info = info;
+   lookup.index = -1;
+
+   ret = i2c_acpi_do_lookup(adev, );
+   if (ret)
+

[PATCH 6/8] docs: i2c: dev-interface: adapt to new filenames of the i2c core

2017-05-26 Thread Wolfram Sang
The I2C core files were renamed, adapt the textfile to it.

Signed-off-by: Wolfram Sang 
---
 Documentation/i2c/dev-interface | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/Documentation/i2c/dev-interface b/Documentation/i2c/dev-interface
index bcf919d8625ceb..5ff19447ac4420 100644
--- a/Documentation/i2c/dev-interface
+++ b/Documentation/i2c/dev-interface
@@ -191,7 +191,7 @@ checking on future transactions.)
 4* Other ioctl() calls are converted to in-kernel function calls by
 i2c-dev. Examples include I2C_FUNCS, which queries the I2C adapter
 functionality using i2c.h:i2c_get_functionality(), and I2C_SMBUS, which
-performs an SMBus transaction using i2c-core.c:i2c_smbus_xfer().
+performs an SMBus transaction using i2c-core-smbus.c:i2c_smbus_xfer().
 
 The i2c-dev driver is responsible for checking all the parameters that
 come from user-space for validity. After this point, there is no
@@ -200,13 +200,13 @@ and calls that would have been performed by kernel I2C 
chip drivers
 directly. This means that I2C bus drivers don't need to implement
 anything special to support access from user-space.
 
-5* These i2c-core.c/i2c.h functions are wrappers to the actual
-implementation of your I2C bus driver. Each adapter must declare
-callback functions implementing these standard calls.
-i2c.h:i2c_get_functionality() calls i2c_adapter.algo->functionality(),
-while i2c-core.c:i2c_smbus_xfer() calls either
+5* These i2c.h functions are wrappers to the actual implementation of
+your I2C bus driver. Each adapter must declare callback functions
+implementing these standard calls. i2c.h:i2c_get_functionality() calls
+i2c_adapter.algo->functionality(), while
+i2c-core-smbus.c:i2c_smbus_xfer() calls either
 adapter.algo->smbus_xfer() if it is implemented, or if not,
-i2c-core.c:i2c_smbus_xfer_emulated() which in turn calls
+i2c-core-smbus.c:i2c_smbus_xfer_emulated() which in turn calls
 i2c_adapter.algo->master_xfer().
 
 After your I2C bus driver has processed these requests, execution runs
-- 
2.11.0



[PATCH 0/8] i2c: refactor core and break out blocks

2017-05-26 Thread Wolfram Sang
Yes, I wanted to do this for years now... The I2C core became a huge monolithic
blob getting harder and harder to maintain. This series breaks out some
functional parts into seperate files. This makes the code easier to handle
because of the smaller chunks. It reduces ifdeffery because we can now handle
compilation at the Makefile level. And it helps to spread responsibility, e.g.
the ACPI maintainers do now have a dedicated file listed in MAINTAINERS.

This series was tested with a Renesas Lager board (R-Car H2 SoC). It booted
normally and all device drivers for I2C clients seem to work normally. I wired
two I2C busses together and used i2c-slave-eeprom to let one I2C IP core read
out data from the other. That all worked fine. Buildbot is also happy, it found
two issues of the first (non public) iteration. Thanks!

I did not test ACPI and hope for some assistance here :) I'd also be happy if
people could check the includes of the newly created files, there might be
missing some.

As a result, the main i2c-core file goes down from ~3600 lines to ~2000 lines.
I think this is pretty helpful. I plan to apply this for v4.13 to not block
other core changes. Let's see if we are there yet and the series is ready.
Looking forward to comments.

A branch can be found here:
git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/core-refactor

Kind regards,

   Wolfram


Wolfram Sang (8):
  i2c: rename core source file to allow refactorization
  i2c: break out slave support into seperate file
  i2c: break out smbus support into seperate file
  i2c: break out OF support into seperate file
  i2c: break out ACPI support into seperate file
  docs: i2c: dev-interface: adapt to new filenames of the i2c core
  i2c: remove unneeded includes from core
  i2c: reformat core-base file header

 Documentation/driver-api/i2c.rst|5 +-
 Documentation/i2c/dev-interface |   14 +-
 MAINTAINERS |1 +
 drivers/i2c/Makefile|7 +-
 drivers/i2c/busses/i2c-designware-core.c|2 +-
 drivers/i2c/i2c-core-acpi.c |  653 +++
 drivers/i2c/{i2c-core.c => i2c-core-base.c} | 1681 +--
 drivers/i2c/i2c-core-of.c   |  276 +
 drivers/i2c/i2c-core-slave.c|  115 ++
 drivers/i2c/i2c-core-smbus.c|  594 ++
 drivers/i2c/i2c-core.h  |   24 +
 include/trace/events/i2c.h  |  226 +---
 include/trace/events/smbus.h|  249 
 13 files changed, 1978 insertions(+), 1869 deletions(-)
 create mode 100644 drivers/i2c/i2c-core-acpi.c
 rename drivers/i2c/{i2c-core.c => i2c-core-base.c} (58%)
 create mode 100644 drivers/i2c/i2c-core-of.c
 create mode 100644 drivers/i2c/i2c-core-slave.c
 create mode 100644 drivers/i2c/i2c-core-smbus.c
 create mode 100644 include/trace/events/smbus.h

-- 
2.11.0



[PATCH V2 17/37] perf intel-pt: Fix transactions_sample_type

2017-05-26 Thread Adrian Hunter
'transactions_sample_type' is needed to correctly inject transactions
samples but it was not being set. Set it from the event sample type.

Signed-off-by: Adrian Hunter 
---
 tools/perf/util/intel-pt.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 3ae03f920253..6df836469f2b 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -2035,6 +2035,7 @@ static int intel_pt_synth_events(struct intel_pt *pt,
return err;
}
pt->sample_transactions = true;
+   pt->transactions_sample_type = attr.sample_type;
pt->transactions_id = id;
id += 1;
evlist__for_each_entry(evlist, evsel) {
-- 
1.9.1



[PATCH V2 21/37] perf script: Add 'synth' field for synthesized event payloads

2017-05-26 Thread Adrian Hunter
Add a field to display the content the raw_data of a synthesized event.

Signed-off-by: Adrian Hunter 
---
 tools/perf/Documentation/perf-script.txt |  6 +-
 tools/perf/builtin-script.c  | 20 ++--
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-script.txt 
b/tools/perf/Documentation/perf-script.txt
index cb0eda3925e6..43770f174f64 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -117,7 +117,8 @@ OPTIONS
 Comma separated list of fields to print. Options are:
 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
 srcline, period, iregs, brstack, brstacksym, flags, bpf-output, 
brstackinsn,
-callindent, insn, insnlen. Field list can be prepended with the type, 
trace, sw or hw,
+callindent, insn, insnlen, synth.
+Field list can be prepended with the type, trace, sw or hw,
 to indicate to which event type the field list applies.
 e.g., -F sw:comm,tid,time,ip,sym  and -F trace:time,cpu,trace
 
@@ -185,6 +186,9 @@ OPTIONS
instruction bytes and the instruction length of the current
instruction.
 
+   The synth field is used by synthesized events which may be created when
+   Instruction Trace decoding.
+
Finally, a user may not set fields to none for all event types.
i.e., -F "" is not allowed.
 
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 99167bafe81c..f7a5130d2fd0 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -85,6 +85,7 @@ enum perf_output_field {
PERF_OUTPUT_INSN= 1U << 21,
PERF_OUTPUT_INSNLEN = 1U << 22,
PERF_OUTPUT_BRSTACKINSN = 1U << 23,
+   PERF_OUTPUT_SYNTH   = 1U << 24,
 };
 
 struct output_option {
@@ -115,6 +116,7 @@ struct output_option {
{.str = "insn", .field = PERF_OUTPUT_INSN},
{.str = "insnlen", .field = PERF_OUTPUT_INSNLEN},
{.str = "brstackinsn", .field = PERF_OUTPUT_BRSTACKINSN},
+   {.str = "synth", .field = PERF_OUTPUT_SYNTH},
 };
 
 enum {
@@ -194,7 +196,8 @@ enum {
.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
  PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
  PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
- PERF_OUTPUT_SYM | PERF_OUTPUT_DSO,
+ PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
+ PERF_OUTPUT_SYNTH,
 
.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
},
@@ -1117,6 +1120,15 @@ static void print_sample_bpf_output(struct perf_sample 
*sample)
   (char *)(sample->raw_data));
 }
 
+static void print_sample_synth(struct perf_sample *sample __maybe_unused,
+  struct perf_evsel *evsel)
+{
+   switch (evsel->attr.config) {
+   default:
+   break;
+   }
+}
+
 struct perf_script {
struct perf_tooltool;
struct perf_session *session;
@@ -1201,6 +1213,10 @@ static void process_event(struct perf_script *script,
if (PRINT_FIELD(TRACE))
event_format__print(evsel->tp_format, sample->cpu,
sample->raw_data, sample->raw_size);
+
+   if (attr->type == PERF_TYPE_SYNTH && PRINT_FIELD(SYNTH))
+   print_sample_synth(sample, evsel);
+
if (PRINT_FIELD(ADDR))
print_sample_addr(sample, thread, attr);
 
@@ -2489,7 +2505,7 @@ int cmd_script(int argc, const char **argv)
 "Valid types: hw,sw,trace,raw,synth. "
 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
 "addr,symoff,period,iregs,brstack,brstacksym,flags,"
-"bpf-output,callindent,insn,insnlen,brstackinsn",
+"bpf-output,callindent,insn,insnlen,brstackinsn,synth",
 parse_output_fields),
OPT_BOOLEAN('a', "all-cpus", _wide,
"system-wide collection from all CPUs"),
-- 
1.9.1



[PATCH V2 35/37] perf intel-pt: Update documentation to include new ptwrite and power events

2017-05-26 Thread Adrian Hunter
Update documentation to include new ptwrite and power events.

Signed-off-by: Adrian Hunter 
---
 tools/perf/Documentation/intel-pt.txt | 42 +--
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/intel-pt.txt 
b/tools/perf/Documentation/intel-pt.txt
index d157dee7a4ec..4b6cdbf8f935 100644
--- a/tools/perf/Documentation/intel-pt.txt
+++ b/tools/perf/Documentation/intel-pt.txt
@@ -108,6 +108,9 @@ approach is available to export the data to a postgresql 
database.  Refer to
 script export-to-postgresql.py for more details, and to script
 call-graph-from-postgresql.py for an example of using the database.
 
+There is also script intel-pt-events.py which provides an example of how to
+unpack the raw data for power events and PTWRITE.
+
 As mentioned above, it is easy to capture too much data.  One way to limit the
 data captured is to use 'snapshot' mode which is explained further below.
 Refer to 'new snapshot option' and 'Intel PT modes of operation' further below.
@@ -710,13 +713,15 @@ Having no option is the same as
 
 which, in turn, is the same as
 
-   --itrace=ibxe
+   --itrace=ibxwpe
 
 The letters are:
 
i   synthesize "instructions" events
b   synthesize "branches" events
x   synthesize "transactions" events
+   w   synthesize "ptwrite" events
+   p   synthesize "power" events
c   synthesize branches events (calls only)
r   synthesize branches events (returns only)
e   synthesize tracing error events
@@ -735,7 +740,40 @@ and "r" can be combined to get calls and returns.
 'flags' field can be used in perf script to determine whether the event is a
 tranasaction start, commit or abort.
 
-Error events are new.  They show where the decoder lost the trace.  Error 
events
+Note that "instructions", "branches" and "transactions" events depend on code
+flow packets which can be disabled by using the config term "branch=0".  Refer
+to the config terms section above.
+
+"ptwrite" events record the payload of the ptwrite instruction and whether
+"fup_on_ptw" was used.  "ptwrite" events depend on PTWRITE packets which are
+recorded only if the "ptw" config term was used.  Refer to the config terms
+section above.  perf script "synth" field displays "ptwrite" information like
+this: "ip: 0 payload: 0x123456789abcdef0"  where "ip" is 1 if "fup_on_ptw" was
+used.
+
+"Power" events correspond to power event packets and CBR (core-to-bus ratio)
+packets.  While CBR packets are always recorded when tracing is enabled, power
+event packets are recorded only if the "pwr_evt" config term was used.  Refer 
to
+the config terms section above.  The power events record information about
+C-state changes, whereas CBR is indicative of CPU frequency.  perf script
+"event,synth" fields display information like this:
+   cbr:  cbr: 22 freq: 2189 MHz (200%)
+   mwait:  hints: 0x60 extensions: 0x1
+   pwre:  hw: 0 cstate: 2 sub-cstate: 0
+   exstop:  ip: 1
+   pwrx:  deepest cstate: 2 last cstate: 2 wake reason: 0x4
+Where:
+   "cbr" includes the frequency and the percentage of maximum non-turbo
+   "mwait" shows mwait hints and extensions
+   "pwre" shows C-state transitions (to a C-state deeper than C0) and
+   whether initiated by hardware
+   "exstop" indicates execution stopped and whether the IP was recorded
+   exactly,
+   "pwrx" indicates return to C0
+For more details refer to the Intel 64 and IA-32 Architectures Software
+Developer Manuals.
+
+Error events show where the decoder lost the trace.  Error events
 are quite important.  Users must know if what they are seeing is a complete
 picture or not.
 
-- 
1.9.1



[PATCH V2 29/37] perf intel-pt: Tidy Intel PT evsel lookup into separate function

2017-05-26 Thread Adrian Hunter
Tidy the lookup of the Intel PT selected event (perf_evsel) into a separate
function.

Signed-off-by: Adrian Hunter 
---
 tools/perf/util/intel-pt.c | 25 +++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index b670502b0264..a9486b57584f 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1922,24 +1922,29 @@ static int intel_pt_synth_event(struct perf_session 
*session,
   , intel_pt_event_synth);
 }
 
+static struct perf_evsel *intel_pt_evsel(struct intel_pt *pt,
+struct perf_evlist *evlist)
+{
+   struct perf_evsel *evsel;
+
+   evlist__for_each_entry(evlist, evsel) {
+   if (evsel->attr.type == pt->pmu_type && evsel->ids)
+   return evsel;
+   }
+
+   return NULL;
+}
+
 static int intel_pt_synth_events(struct intel_pt *pt,
 struct perf_session *session)
 {
struct perf_evlist *evlist = session->evlist;
-   struct perf_evsel *evsel;
+   struct perf_evsel *evsel = intel_pt_evsel(pt, evlist);
struct perf_event_attr attr;
-   bool found = false;
u64 id;
int err;
 
-   evlist__for_each_entry(evlist, evsel) {
-   if (evsel->attr.type == pt->pmu_type && evsel->ids) {
-   found = true;
-   break;
-   }
-   }
-
-   if (!found) {
+   if (!evsel) {
pr_debug("There are no selected events with Intel Processor 
Trace data\n");
return 0;
}
-- 
1.9.1



[PATCH V2 33/37] perf intel-pt: Synthesize new power and ptwrite events

2017-05-26 Thread Adrian Hunter
Synthesize new power and ptwrite events.

Signed-off-by: Adrian Hunter 
---
 tools/perf/util/intel-pt.c | 283 +
 1 file changed, 283 insertions(+)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index ace79a405f98..754e92ee6c3e 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -92,6 +92,18 @@ struct intel_pt {
u64 transactions_sample_type;
u64 transactions_id;
 
+   bool sample_ptwrites;
+   u64 ptwrites_sample_type;
+   u64 ptwrites_id;
+
+   bool sample_pwr_events;
+   u64 pwr_events_sample_type;
+   u64 mwait_id;
+   u64 pwre_id;
+   u64 exstop_id;
+   u64 pwrx_id;
+   u64 cbr_id;
+
bool synth_needs_swap;
 
u64 tsc_bit;
@@ -102,6 +114,7 @@ struct intel_pt {
u64 cyc_bit;
u64 noretcomp_bit;
unsigned max_non_turbo_ratio;
+   unsigned cbr2khz;
 
unsigned long num_events;
 
@@ -1236,6 +1249,175 @@ static int intel_pt_synth_transaction_sample(struct 
intel_pt_queue *ptq)
pt->transactions_sample_type);
 }
 
+static void intel_pt_prep_p_sample(struct intel_pt *pt,
+  struct intel_pt_queue *ptq,
+  union perf_event *event,
+  struct perf_sample *sample)
+{
+   intel_pt_prep_sample(pt, ptq, event, sample);
+
+   /*
+* Zero IP is used to mean "trace start" but that is not the case for
+* power or PTWRITE events with no IP, so clear the flags.
+*/
+   if (!sample->ip)
+   sample->flags = 0;
+}
+
+static int intel_pt_synth_ptwrite_sample(struct intel_pt_queue *ptq)
+{
+   struct intel_pt *pt = ptq->pt;
+   union perf_event *event = ptq->event_buf;
+   struct perf_sample sample = { .ip = 0, };
+   struct perf_synth_intel_ptwrite raw;
+
+   if (intel_pt_skip_event(pt))
+   return 0;
+
+   intel_pt_prep_p_sample(pt, ptq, event, );
+
+   sample.id = ptq->pt->ptwrites_id;
+   sample.stream_id = ptq->pt->ptwrites_id;
+
+   raw.flags = 0;
+   raw.ip = !!(ptq->state->flags & INTEL_PT_FUP_IP);
+   raw.payload = cpu_to_le64(ptq->state->ptw_payload);
+
+   sample.raw_size = sizeof(raw);
+   sample.raw_data = 
+
+   return intel_pt_deliver_synth_event(pt, ptq, event, ,
+   pt->ptwrites_sample_type);
+}
+
+static int intel_pt_synth_cbr_sample(struct intel_pt_queue *ptq)
+{
+   struct intel_pt *pt = ptq->pt;
+   union perf_event *event = ptq->event_buf;
+   struct perf_sample sample = { .ip = 0, };
+   struct perf_synth_intel_cbr raw;
+   u32 flags;
+
+   if (intel_pt_skip_event(pt))
+   return 0;
+
+   intel_pt_prep_p_sample(pt, ptq, event, );
+
+   sample.id = ptq->pt->cbr_id;
+   sample.stream_id = ptq->pt->cbr_id;
+
+   flags = (u16)ptq->state->cbr_payload | (pt->max_non_turbo_ratio << 16);
+   raw.flags = cpu_to_le32(flags);
+   raw.freq = cpu_to_le32(raw.cbr * pt->cbr2khz);
+   raw.reserved3 = 0;
+
+   sample.raw_size = sizeof(raw);
+   sample.raw_data = 
+
+   return intel_pt_deliver_synth_event(pt, ptq, event, ,
+   pt->pwr_events_sample_type);
+}
+
+static int intel_pt_synth_mwait_sample(struct intel_pt_queue *ptq)
+{
+   struct intel_pt *pt = ptq->pt;
+   union perf_event *event = ptq->event_buf;
+   struct perf_sample sample = { .ip = 0, };
+   struct perf_synth_intel_mwait raw;
+
+   if (intel_pt_skip_event(pt))
+   return 0;
+
+   intel_pt_prep_p_sample(pt, ptq, event, );
+
+   sample.id = ptq->pt->mwait_id;
+   sample.stream_id = ptq->pt->mwait_id;
+
+   raw.reserved = 0;
+   raw.payload = cpu_to_le64(ptq->state->mwait_payload);
+
+   sample.raw_size = sizeof(raw);
+   sample.raw_data = 
+
+   return intel_pt_deliver_synth_event(pt, ptq, event, ,
+   pt->pwr_events_sample_type);
+}
+
+static int intel_pt_synth_pwre_sample(struct intel_pt_queue *ptq)
+{
+   struct intel_pt *pt = ptq->pt;
+   union perf_event *event = ptq->event_buf;
+   struct perf_sample sample = { .ip = 0, };
+   struct perf_synth_intel_pwre raw;
+
+   if (intel_pt_skip_event(pt))
+   return 0;
+
+   intel_pt_prep_p_sample(pt, ptq, event, );
+
+   sample.id = ptq->pt->pwre_id;
+   sample.stream_id = ptq->pt->pwre_id;
+
+   raw.reserved = 0;
+   raw.payload = cpu_to_le64(ptq->state->pwre_payload);
+
+   sample.raw_size = sizeof(raw);
+   sample.raw_data = 
+
+   return intel_pt_deliver_synth_event(pt, ptq, event, ,
+   pt->pwr_events_sample_type);
+}
+
+static int intel_pt_synth_exstop_sample(struct intel_pt_queue *ptq)

[PATCH V2 32/37] perf intel-pt: Move code in intel_pt_synth_events() to simplify attr setting

2017-05-26 Thread Adrian Hunter
intel_pt_synth_events() uses the same attr structure to create each event.
Move the code around a bit to simplify that.

Signed-off-by: Adrian Hunter 
---
 tools/perf/util/intel-pt.c | 45 ++---
 1 file changed, 22 insertions(+), 23 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index a20712e1ed28..ace79a405f98 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1997,6 +1997,25 @@ static int intel_pt_synth_events(struct intel_pt *pt,
if (!id)
id = 1;
 
+   if (pt->synth_opts.branches) {
+   attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
+   attr.sample_period = 1;
+   attr.sample_type |= PERF_SAMPLE_ADDR;
+   err = intel_pt_synth_event(session, "branches", , id);
+   if (err)
+   return err;
+   pt->sample_branches = true;
+   pt->branches_sample_type = attr.sample_type;
+   pt->branches_id = id;
+   id += 1;
+   attr.sample_type &= ~(u64)PERF_SAMPLE_ADDR;
+   }
+
+   if (pt->synth_opts.callchain)
+   attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
+   if (pt->synth_opts.last_branch)
+   attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
+
if (pt->synth_opts.instructions) {
attr.config = PERF_COUNT_HW_INSTRUCTIONS;
if (pt->synth_opts.period_type == PERF_ITRACE_PERIOD_NANOSECS)
@@ -2004,10 +2023,6 @@ static int intel_pt_synth_events(struct intel_pt *pt,
intel_pt_ns_to_ticks(pt, pt->synth_opts.period);
else
attr.sample_period = pt->synth_opts.period;
-   if (pt->synth_opts.callchain)
-   attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
-   if (pt->synth_opts.last_branch)
-   attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
err = intel_pt_synth_event(session, "instructions", , id);
if (err)
return err;
@@ -2017,13 +2032,11 @@ static int intel_pt_synth_events(struct intel_pt *pt,
id += 1;
}
 
+   attr.sample_type &= ~(u64)PERF_SAMPLE_PERIOD;
+   attr.sample_period = 1;
+
if (pt->synth_opts.transactions) {
attr.config = PERF_COUNT_HW_INSTRUCTIONS;
-   attr.sample_period = 1;
-   if (pt->synth_opts.callchain)
-   attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
-   if (pt->synth_opts.last_branch)
-   attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
err = intel_pt_synth_event(session, "transactions", , id);
if (err)
return err;
@@ -2034,20 +2047,6 @@ static int intel_pt_synth_events(struct intel_pt *pt,
id += 1;
}
 
-   if (pt->synth_opts.branches) {
-   attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
-   attr.sample_period = 1;
-   attr.sample_type |= PERF_SAMPLE_ADDR;
-   attr.sample_type &= ~(u64)PERF_SAMPLE_CALLCHAIN;
-   attr.sample_type &= ~(u64)PERF_SAMPLE_BRANCH_STACK;
-   err = intel_pt_synth_event(session, "branches", , id);
-   if (err)
-   return err;
-   pt->sample_branches = true;
-   pt->branches_sample_type = attr.sample_type;
-   pt->branches_id = id;
-   }
-
pt->synth_needs_swap = evsel->needs_swap;
 
return 0;
-- 
1.9.1



Re: linux-next: build warning after merge of the drivers-x86 tree

2017-05-26 Thread Arnd Bergmann
On Fri, May 26, 2017 at 1:34 AM, Stephen Rothwell  wrote:
> On Mon, 22 May 2017 21:03:06 +0300 Andy Shevchenko 
>  wrote:
>> On Sat, May 20, 2017 at 1:09 AM, Darren Hart  wrote:
>> > On Fri, May 19, 2017 at 01:23:17PM +1000, Stephen Rothwell wrote:
>> >>
>> >> After merging the drivers-x86 tree, today's linux-next build (x86_64
>> >> allmodconfig) produced this warning:
>> >>
>> >> drivers/platform/x86/ideapad-laptop.c:438:16: warning: 'touchpad_store' 
>> >> defined but not used [-Wunused-function]
>> >>  static ssize_t touchpad_store(struct device *dev,
>> >> ^
>> >>
>> >> Introduced by commit
>> >>
>> >>   7f363145992c ("platform/x86: ideapad-laptop: Switch touchpad attribute 
>> >> to be RO")
>> >
>> >
>> > Andy, you warned me about this and I had forgotten before I included it in 
>> > next.
>> >
>> > Would you like to drop this change, or drop the touchpad_store function?
>>
>> I would go with Arnd's patch if he respins one addressing my comment.
>
> Any progress on this?

Andy wrote that he committed an updated patch on May 23. The git tree
at git://git.infradead.org/users/dvhart/linux-platform-drivers-x86.git#for-next
appears to currently contain an older state from May 15.

Arnd


[PATCH V2 36/37] perf intel-pt: Do not use TSC packets for calculating CPU cycles to TSC

2017-05-26 Thread Adrian Hunter
CBR (core-to-bus ratio) packets provide an indication of CPU frequency. A
more accurate measure can be made by counting the cycles (given by CYC
packets) in between other timing packets (either MTC or TSC). Using TSC
packets has at least 2 issues: 1) timing might have stopped (e.g. mwait) or
2) TSC packets within PSB+ might slip past CYC packets. For now, simply do
not use TSC packets for calculating CPU cycles to TSC. That leaves the case
where 2 MTC packets are used, otherwise falling back to the CBR value.

Signed-off-by: Adrian Hunter 
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 5dea06289db5..aa1593ce551d 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -711,6 +711,12 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info 
*pkt_info)
break;
 
case INTEL_PT_TSC:
+   /*
+* For now, do not support using TSC packets - refer
+* intel_pt_calc_cyc_to_tsc().
+*/
+   if (data->from_mtc)
+   return 1;
timestamp = pkt_info->packet.payload |
(data->timestamp & (0xffULL << 56));
if (data->from_mtc && timestamp < data->timestamp &&
@@ -828,6 +834,14 @@ static void intel_pt_calc_cyc_to_tsc(struct 
intel_pt_decoder *decoder,
.cbr_cyc_to_tsc = 0,
};
 
+   /*
+* For now, do not support using TSC packets for at least the reasons:
+* 1) timing might have stopped
+* 2) TSC packets within PSB+ can slip against CYC packets
+*/
+   if (!from_mtc)
+   return;
+
intel_pt_pkt_lookahead(decoder, intel_pt_calc_cyc_cb, );
 }
 
-- 
1.9.1



[PATCH V2 37/37] perf auxtrace: Add CPU filter support

2017-05-26 Thread Adrian Hunter
Decoding auxtrace data can take a long time. To avoid decoding
unnecessarily, filter auxtrace data that is collected per-cpu before it is
decoded.

Signed-off-by: Adrian Hunter 
---
 tools/perf/builtin-report.c |  1 +
 tools/perf/builtin-script.c |  1 +
 tools/perf/util/auxtrace.c  | 10 ++
 tools/perf/util/auxtrace.h  |  2 ++
 4 files changed, 14 insertions(+)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 22478ff2b706..6de88f156ec6 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -558,6 +558,7 @@ static int __cmd_report(struct report *rep)
ui__error("failed to set cpu bitmap\n");
return ret;
}
+   session->itrace_synth_opts->cpu_bitmap = rep->cpu_bitmap;
}
 
if (rep->show_threads) {
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 4a13daacba25..4c41d0358966 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2874,6 +2874,7 @@ int cmd_script(int argc, const char **argv)
err = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap);
if (err < 0)
goto out_delete;
+   itrace_synth_opts.cpu_bitmap = cpu_bitmap;
}
 
if (!no_callchain)
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 651c01dfa5d3..5547457566a7 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -322,6 +322,13 @@ static int auxtrace_queues__add_event_buffer(struct 
auxtrace_queues *queues,
return auxtrace_queues__add_buffer(queues, idx, buffer);
 }
 
+static bool filter_cpu(struct perf_session *session, int cpu)
+{
+   unsigned long *cpu_bitmap = session->itrace_synth_opts->cpu_bitmap;
+
+   return cpu_bitmap && cpu != -1 && !test_bit(cpu, cpu_bitmap);
+}
+
 int auxtrace_queues__add_event(struct auxtrace_queues *queues,
   struct perf_session *session,
   union perf_event *event, off_t data_offset,
@@ -331,6 +338,9 @@ int auxtrace_queues__add_event(struct auxtrace_queues 
*queues,
unsigned int idx;
int err;
 
+   if (filter_cpu(session, event->auxtrace.cpu))
+   return 0;
+
buffer = zalloc(sizeof(struct auxtrace_buffer));
if (!buffer)
return -ENOMEM;
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 68e0aa40b24a..33b5e6cdf38c 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -74,6 +74,7 @@ enum itrace_period_type {
  * @period: 'instructions' events period
  * @period_type: 'instructions' events period type
  * @initial_skip: skip N events at the beginning.
+ * @cpu_bitmap: CPUs for which to synthesize events, or NULL for all
  */
 struct itrace_synth_opts {
boolset;
@@ -96,6 +97,7 @@ struct itrace_synth_opts {
unsigned long long  period;
enum itrace_period_type period_type;
unsigned long   initial_skip;
+   unsigned long   *cpu_bitmap;
 };
 
 /**
-- 
1.9.1



[PATCH V2 34/37] perf intel-pt: Add example script for power events and PTWRITE

2017-05-26 Thread Adrian Hunter
Add script intel-pt-events.py that provides an example of how to unpack the
raw data for power events and PTWRITE.

Signed-off-by: Adrian Hunter 
---
 .../perf/scripts/python/bin/intel-pt-events-record |  13 +++
 .../perf/scripts/python/bin/intel-pt-events-report |   3 +
 tools/perf/scripts/python/intel-pt-events.py   | 128 +
 3 files changed, 144 insertions(+)
 create mode 100644 tools/perf/scripts/python/bin/intel-pt-events-record
 create mode 100644 tools/perf/scripts/python/bin/intel-pt-events-report
 create mode 100644 tools/perf/scripts/python/intel-pt-events.py

diff --git a/tools/perf/scripts/python/bin/intel-pt-events-record 
b/tools/perf/scripts/python/bin/intel-pt-events-record
new file mode 100644
index ..10fe2b6977d4
--- /dev/null
+++ b/tools/perf/scripts/python/bin/intel-pt-events-record
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+#
+# print Intel PT Power Events and PTWRITE. The intel_pt PMU event needs
+# to be specified with appropriate config terms.
+#
+if ! echo "$@" | grep -q intel_pt ; then
+   echo "Options must include the Intel PT event e.g. -e 
intel_pt/pwr_evt,ptw/"
+   echo "and for power events it probably needs to be system wide i.e. -a 
option"
+   echo "For example: -a -e intel_pt/pwr_evt,branch=0/ sleep 1"
+   exit 1
+fi
+perf record $@
diff --git a/tools/perf/scripts/python/bin/intel-pt-events-report 
b/tools/perf/scripts/python/bin/intel-pt-events-report
new file mode 100644
index ..9a9c92fcd026
--- /dev/null
+++ b/tools/perf/scripts/python/bin/intel-pt-events-report
@@ -0,0 +1,3 @@
+#!/bin/bash
+# description: print Intel PT Power Events and PTWRITE
+perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/intel-pt-events.py
\ No newline at end of file
diff --git a/tools/perf/scripts/python/intel-pt-events.py 
b/tools/perf/scripts/python/intel-pt-events.py
new file mode 100644
index ..b19172d673af
--- /dev/null
+++ b/tools/perf/scripts/python/intel-pt-events.py
@@ -0,0 +1,128 @@
+# intel-pt-events.py: Print Intel PT Power Events and PTWRITE
+# Copyright (c) 2017, Intel Corporation.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2, as published by the Free Software Foundation.
+#
+# This program is distributed in the hope it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+
+import os
+import sys
+import struct
+
+sys.path.append(os.environ['PERF_EXEC_PATH'] + \
+   '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
+
+# These perf imports are not used at present
+#from perf_trace_context import *
+#from Core import *
+
+def trace_begin():
+   print "Intel PT Power Events and PTWRITE"
+
+def trace_end():
+   print "End"
+
+def trace_unhandled(event_name, context, event_fields_dict):
+   print ' '.join(['%s=%s'%(k,str(v))for k,v in 
sorted(event_fields_dict.items())])
+
+def print_ptwrite(raw_buf):
+   data = struct.unpack_from("> 32) & 0x3
+   print "hints: %#x extensions: %#x" % (hints, extensions),
+
+def print_pwre(raw_buf):
+   data = struct.unpack_from("> 7) & 1
+   cstate = (payload >> 12) & 0xf
+   subcstate = (payload >> 8) & 0xf
+   print "hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate),
+
+def print_exstop(raw_buf):
+   data = struct.unpack_from("> 4) & 0xf
+   wake_reason = (payload >> 8) & 0xf
+   print "deepest cstate: %u last cstate: %u wake reason: %#x" % 
(deepest_cstate, last_cstate, wake_reason),
+
+def print_common_start(comm, sample, name):
+   ts = sample["time"]
+   cpu = sample["cpu"]
+   pid = sample["pid"]
+   tid = sample["tid"]
+   print "%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 
10, ts %10, name),
+
+def print_common_ip(sample, symbol, dso):
+   ip = sample["ip"]
+   print "%16x %s 

[PATCH V2 27/37] perf intel-pt: Remove unused instructions_sample_period

2017-05-26 Thread Adrian Hunter
Remove unused struct intel_pt member instructions_sample_period.

Signed-off-by: Adrian Hunter 
---
 tools/perf/util/intel-pt.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index dbff5dca09f0..f8237a0e2946 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -81,7 +81,6 @@ struct intel_pt {
 
bool sample_instructions;
u64 instructions_sample_type;
-   u64 instructions_sample_period;
u64 instructions_id;
 
bool sample_branches;
@@ -1978,7 +1977,6 @@ static int intel_pt_synth_events(struct intel_pt *pt,
intel_pt_ns_to_ticks(pt, pt->synth_opts.period);
else
attr.sample_period = pt->synth_opts.period;
-   pt->instructions_sample_period = attr.sample_period;
if (pt->synth_opts.callchain)
attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
if (pt->synth_opts.last_branch)
-- 
1.9.1



[PATCH V2 23/37] perf auxtrace: Add itrace option to output ptwrite events

2017-05-26 Thread Adrian Hunter
Add itrace option to output ptwrite events.

Signed-off-by: Adrian Hunter 
---
 tools/perf/Documentation/itrace.txt | 7 ---
 tools/perf/util/auxtrace.c  | 4 
 tools/perf/util/auxtrace.h  | 2 ++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/itrace.txt 
b/tools/perf/Documentation/itrace.txt
index e2a4c5e0dbe5..deafd16692b6 100644
--- a/tools/perf/Documentation/itrace.txt
+++ b/tools/perf/Documentation/itrace.txt
@@ -3,13 +3,14 @@
c   synthesize branches events (calls only)
r   synthesize branches events (returns only)
x   synthesize transactions events
+   w   synthesize ptwrite events
e   synthesize error events
d   create a debug log
g   synthesize a call chain (use with i or x)
l   synthesize last branch entries (use with i or x)
s   skip initial number of events
 
-   The default is all events i.e. the same as --itrace=ibxe
+   The default is all events i.e. the same as --itrace=ibxwe
 
In addition, the period (default 10) for instructions events
can be specified in units of:
@@ -26,8 +27,8 @@
Also the number of last branch entries (default 64, max. 1024) for
instructions or transactions events can be specified.
 
-   It is also possible to skip events generated (instructions, branches, 
transactions)
-   at the beginning. This is useful to ignore initialization code.
+   It is also possible to skip events generated (instructions, branches, 
transactions,
+   ptwrite) at the beginning. This is useful to ignore initialization code.
 
--itrace=i0nss100
 
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 0daf63b9ee3e..baad91ed1e05 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -947,6 +947,7 @@ void itrace_synth_opts__set_default(struct 
itrace_synth_opts *synth_opts)
synth_opts->instructions = true;
synth_opts->branches = true;
synth_opts->transactions = true;
+   synth_opts->ptwrites = true;
synth_opts->errors = true;
synth_opts->period_type = PERF_ITRACE_DEFAULT_PERIOD_TYPE;
synth_opts->period = PERF_ITRACE_DEFAULT_PERIOD;
@@ -1030,6 +1031,9 @@ int itrace_parse_synth_opts(const struct option *opt, 
const char *str,
case 'x':
synth_opts->transactions = true;
break;
+   case 'w':
+   synth_opts->ptwrites = true;
+   break;
case 'e':
synth_opts->errors = true;
break;
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 9f0de72d58e2..b48afb2f18f3 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -59,6 +59,7 @@ enum itrace_period_type {
  * @instructions: whether to synthesize 'instructions' events
  * @branches: whether to synthesize 'branches' events
  * @transactions: whether to synthesize events for transactions
+ * @ptwrites: whether to synthesize events for ptwrites
  * @errors: whether to synthesize decoder error events
  * @dont_decode: whether to skip decoding entirely
  * @log: write a decoding log
@@ -79,6 +80,7 @@ struct itrace_synth_opts {
boolinstructions;
boolbranches;
booltransactions;
+   boolptwrites;
boolerrors;
booldont_decode;
boollog;
-- 
1.9.1



[PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events

2017-05-26 Thread Adrian Hunter
Add definitions for synthesized Intel PT events for power and ptwrite.

Signed-off-by: Adrian Hunter 
---
 tools/perf/builtin-script.c | 114 +++-
 tools/perf/util/event.h |  90 ++
 2 files changed, 203 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index f7a5130d2fd0..4a13daacba25 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1120,10 +1120,122 @@ static void print_sample_bpf_output(struct perf_sample 
*sample)
   (char *)(sample->raw_data));
 }
 
-static void print_sample_synth(struct perf_sample *sample __maybe_unused,
+static void print_sample_spacing(int len, int spacing)
+{
+   if (len > 0 && len < spacing)
+   printf("%*s", spacing - len, "");
+}
+
+static void print_sample_pt_spacing(int len)
+{
+   print_sample_spacing(len, 34);
+}
+
+static void print_sample_synth_ptwrite(struct perf_sample *sample)
+{
+   struct perf_synth_intel_ptwrite *data = sample->raw_data;
+   int len;
+
+   if (sample->raw_size < sizeof(*data))
+   return;
+
+   len = printf(" IP: %u payload: %#" PRIx64 " ",
+data->ip, le64_to_cpu(data->payload));
+   print_sample_pt_spacing(len);
+}
+
+static void print_sample_synth_mwait(struct perf_sample *sample)
+{
+   struct perf_synth_intel_mwait *data = sample->raw_data;
+   int len;
+
+   if (sample->raw_size < sizeof(*data))
+   return;
+
+   len = printf(" hints: %#x extensions: %#x ",
+data->hints, data->extensions);
+   print_sample_pt_spacing(len);
+}
+
+static void print_sample_synth_pwre(struct perf_sample *sample)
+{
+   struct perf_synth_intel_pwre *data = sample->raw_data;
+   int len;
+
+   if (sample->raw_size < sizeof(*data))
+   return;
+
+   len = printf(" hw: %u cstate: %u sub-cstate: %u ",
+data->hw, data->cstate, data->subcstate);
+   print_sample_pt_spacing(len);
+}
+
+static void print_sample_synth_exstop(struct perf_sample *sample)
+{
+   struct perf_synth_intel_exstop *data = sample->raw_data;
+   int len;
+
+   if (sample->raw_size < sizeof(*data))
+   return;
+
+   len = printf(" IP: %u ", data->ip);
+   print_sample_pt_spacing(len);
+}
+
+static void print_sample_synth_pwrx(struct perf_sample *sample)
+{
+   struct perf_synth_intel_pwrx *data = sample->raw_data;
+   int len;
+
+   if (sample->raw_size < sizeof(*data))
+   return;
+
+   len = printf(" deepest cstate: %u last cstate: %u wake reason: %#x ",
+data->deepest_cstate, data->last_cstate,
+data->wake_reason);
+   print_sample_pt_spacing(len);
+}
+
+static void print_sample_synth_cbr(struct perf_sample *sample)
+{
+   struct perf_synth_intel_cbr *data = sample->raw_data;
+   unsigned int percent, freq;
+   int len;
+
+   if (sample->raw_size < sizeof(*data))
+   return;
+
+   freq = (le32_to_cpu(data->freq) + 500) / 1000;
+   len = printf(" cbr: %2u freq: %4u MHz ", data->cbr, freq);
+   if (data->max_nonturbo) {
+   percent = (5 + (1000 * data->cbr) / data->max_nonturbo) / 10;
+   len += printf("(%3u%%) ", percent);
+   }
+   print_sample_pt_spacing(len);
+}
+
+static void print_sample_synth(struct perf_sample *sample,
   struct perf_evsel *evsel)
 {
switch (evsel->attr.config) {
+   case PERF_SYNTH_INTEL_PTWRITE:
+   print_sample_synth_ptwrite(sample);
+   break;
+   case PERF_SYNTH_INTEL_MWAIT:
+   print_sample_synth_mwait(sample);
+   break;
+   case PERF_SYNTH_INTEL_PWRE:
+   print_sample_synth_pwre(sample);
+   break;
+   case PERF_SYNTH_INTEL_EXSTOP:
+   print_sample_synth_exstop(sample);
+   break;
+   case PERF_SYNTH_INTEL_PWRX:
+   print_sample_synth_pwrx(sample);
+   break;
+   case PERF_SYNTH_INTEL_CBR:
+   print_sample_synth_cbr(sample);
+   break;
default:
break;
}
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index af285ed951f4..7823d43315b7 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -255,6 +255,96 @@ enum auxtrace_error_type {
 /* Attribute type for custom synthesized events */
 #define PERF_TYPE_SYNTH30
 
+/* Attribute config for custom synthesized events */
+enum perf_synth_id {
+   PERF_SYNTH_INTEL_PTWRITE,
+   PERF_SYNTH_INTEL_MWAIT,
+   PERF_SYNTH_INTEL_PWRE,
+   PERF_SYNTH_INTEL_EXSTOP,
+   PERF_SYNTH_INTEL_PWRX,
+   PERF_SYNTH_INTEL_CBR,
+};
+
+/*
+ * Raw data formats for synthesized events. Note that raw 

[PATCH V2 28/37] perf intel-pt: Join needlessly wrapped lines

2017-05-26 Thread Adrian Hunter
Join needlessly wrapped lines.

Signed-off-by: Adrian Hunter 
---
 tools/perf/util/intel-pt.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index f8237a0e2946..b670502b0264 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1298,15 +1298,13 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
 
ptq->have_sample = false;
 
-   if (pt->sample_instructions &&
-   (state->type & INTEL_PT_INSTRUCTION)) {
+   if (pt->sample_instructions && (state->type & INTEL_PT_INSTRUCTION)) {
err = intel_pt_synth_instruction_sample(ptq);
if (err)
return err;
}
 
-   if (pt->sample_transactions &&
-   (state->type & INTEL_PT_TRANSACTION)) {
+   if (pt->sample_transactions && (state->type & INTEL_PT_TRANSACTION)) {
err = intel_pt_synth_transaction_sample(ptq);
if (err)
return err;
-- 
1.9.1



[PATCH V2 12/37] perf intel-pt: Add documentation for new config terms

2017-05-26 Thread Adrian Hunter
Add documentation for new config terms.

Signed-off-by: Adrian Hunter 
---
 tools/perf/Documentation/intel-pt.txt | 36 +++
 1 file changed, 36 insertions(+)

diff --git a/tools/perf/Documentation/intel-pt.txt 
b/tools/perf/Documentation/intel-pt.txt
index b0b3007d3c9c..d157dee7a4ec 100644
--- a/tools/perf/Documentation/intel-pt.txt
+++ b/tools/perf/Documentation/intel-pt.txt
@@ -364,6 +364,42 @@ cyc_thresh Specifies how frequently CYC packets are 
produced - see cyc
 
CYC packets are not requested by default.
 
+pt Specifies pass-through which enables the 'branch' config term.
+
+   The default config selects 'pt' if it is available, so a user 
will
+   never need to specify this term.
+
+branch Enable branch tracing.  Branch tracing is enabled by default so 
to
+   disable branch tracing use 'branch=0'.
+
+   The default config selects 'branch' if it is available.
+
+ptwEnable PTWRITE packets which are produced when a ptwrite 
instruction
+   is executed.
+
+   Support for this feature is indicated by:
+
+   /sys/bus/event_source/devices/intel_pt/caps/ptwrite
+
+   which contains "1" if the feature is supported and
+   "0" otherwise.
+
+fup_on_ptw Enable a FUP packet to follow the PTWRITE packet.  The FUP 
packet
+   provides the address of the ptwrite instruction.  In the 
absence of
+   fup_on_ptw, the decoder will use the address of the previous 
branch
+   if branch tracing is enabled, otherwise the address will be 
zero.
+   Note that fup_on_ptw will work even when branch tracing is 
disabled.
+
+pwr_evtEnable power events.  The power events provide 
information about
+   changes to the CPU C-state.
+
+   Support for this feature is indicated by:
+
+   
/sys/bus/event_source/devices/intel_pt/caps/power_event_trace
+
+   which contains "1" if the feature is supported and
+   "0" otherwise.
+
 
 new snapshot option
 ---
-- 
1.9.1



[PATCH V2 11/37] perf intel-pt: Add default config for pass-through branch enable

2017-05-26 Thread Adrian Hunter
Branch tracing is enabled by default, so a fake config bit called 'pt'
(pass-through) was added to allow the 'branch enable' bit to have affect.
Add default config 'pt,branch' which will allow users to disable branch
tracing using 'branch=0' instead of having to specify 'pt,branch=0'.

Signed-off-by: Adrian Hunter 
---
 tools/perf/arch/x86/util/intel-pt.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/tools/perf/arch/x86/util/intel-pt.c 
b/tools/perf/arch/x86/util/intel-pt.c
index f630de0206a1..007621a7e420 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -196,6 +196,7 @@ static u64 intel_pt_default_config(struct perf_pmu 
*intel_pt_pmu)
int psb_cyc, psb_periods, psb_period;
int pos = 0;
u64 config;
+   char c;
 
pos += scnprintf(buf + pos, sizeof(buf) - pos, "tsc");
 
@@ -229,6 +230,10 @@ static u64 intel_pt_default_config(struct perf_pmu 
*intel_pt_pmu)
}
}
 
+   if (perf_pmu__scan_file(intel_pt_pmu, "format/pt", "%c", ) == 1 &&
+   perf_pmu__scan_file(intel_pt_pmu, "format/branch", "%c", ) == 1)
+   pos += scnprintf(buf + pos, sizeof(buf) - pos, ",pt,branch");
+
pr_debug2("%s default config: %s\n", intel_pt_pmu->name, buf);
 
intel_pt_parse_terms(_pt_pmu->format, buf, );
-- 
1.9.1



[PATCH V2 16/37] perf intel-pt: Remove redundant initial_skip checks

2017-05-26 Thread Adrian Hunter
'initial_skip' is checked inside the sample synthesis functions which means
it is actually being done twice for 'instructions' and 'transactions'
samples. Remove the redundant checks.

Signed-off-by: Adrian Hunter 
---
 tools/perf/util/intel-pt.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 5c59b8c6a719..3ae03f920253 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1322,18 +1322,14 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
ptq->have_sample = false;
 
if (pt->sample_instructions &&
-   (state->type & INTEL_PT_INSTRUCTION) &&
-   (!pt->synth_opts.initial_skip ||
-pt->num_events++ >= pt->synth_opts.initial_skip)) {
+   (state->type & INTEL_PT_INSTRUCTION)) {
err = intel_pt_synth_instruction_sample(ptq);
if (err)
return err;
}
 
if (pt->sample_transactions &&
-   (state->type & INTEL_PT_TRANSACTION) &&
-   (!pt->synth_opts.initial_skip ||
-pt->num_events++ >= pt->synth_opts.initial_skip)) {
+   (state->type & INTEL_PT_TRANSACTION)) {
err = intel_pt_synth_transaction_sample(ptq);
if (err)
return err;
-- 
1.9.1



[PATCH V2 24/37] perf auxtrace: Add itrace option to output power events

2017-05-26 Thread Adrian Hunter
Add itrace option to output power events.

Signed-off-by: Adrian Hunter 
---
 tools/perf/Documentation/itrace.txt | 5 +++--
 tools/perf/util/auxtrace.c  | 4 
 tools/perf/util/auxtrace.h  | 2 ++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/itrace.txt 
b/tools/perf/Documentation/itrace.txt
index deafd16692b6..a3abe04c779d 100644
--- a/tools/perf/Documentation/itrace.txt
+++ b/tools/perf/Documentation/itrace.txt
@@ -4,13 +4,14 @@
r   synthesize branches events (returns only)
x   synthesize transactions events
w   synthesize ptwrite events
+   p   synthesize power events
e   synthesize error events
d   create a debug log
g   synthesize a call chain (use with i or x)
l   synthesize last branch entries (use with i or x)
s   skip initial number of events
 
-   The default is all events i.e. the same as --itrace=ibxwe
+   The default is all events i.e. the same as --itrace=ibxwpe
 
In addition, the period (default 10) for instructions events
can be specified in units of:
@@ -28,7 +29,7 @@
instructions or transactions events can be specified.
 
It is also possible to skip events generated (instructions, branches, 
transactions,
-   ptwrite) at the beginning. This is useful to ignore initialization code.
+   ptwrite, power) at the beginning. This is useful to ignore 
initialization code.
 
--itrace=i0nss100
 
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index baad91ed1e05..651c01dfa5d3 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -948,6 +948,7 @@ void itrace_synth_opts__set_default(struct 
itrace_synth_opts *synth_opts)
synth_opts->branches = true;
synth_opts->transactions = true;
synth_opts->ptwrites = true;
+   synth_opts->pwr_events = true;
synth_opts->errors = true;
synth_opts->period_type = PERF_ITRACE_DEFAULT_PERIOD_TYPE;
synth_opts->period = PERF_ITRACE_DEFAULT_PERIOD;
@@ -1034,6 +1035,9 @@ int itrace_parse_synth_opts(const struct option *opt, 
const char *str,
case 'w':
synth_opts->ptwrites = true;
break;
+   case 'p':
+   synth_opts->pwr_events = true;
+   break;
case 'e':
synth_opts->errors = true;
break;
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index b48afb2f18f3..68e0aa40b24a 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -60,6 +60,7 @@ enum itrace_period_type {
  * @branches: whether to synthesize 'branches' events
  * @transactions: whether to synthesize events for transactions
  * @ptwrites: whether to synthesize events for ptwrites
+ * @pwr_events: whether to synthesize power events
  * @errors: whether to synthesize decoder error events
  * @dont_decode: whether to skip decoding entirely
  * @log: write a decoding log
@@ -81,6 +82,7 @@ struct itrace_synth_opts {
boolbranches;
booltransactions;
boolptwrites;
+   boolpwr_events;
boolerrors;
booldont_decode;
boollog;
-- 
1.9.1



[PATCH V2 18/37] perf tools: Fix message because cpu list option is -C not -c

2017-05-26 Thread Adrian Hunter
Fix message because cpu list option is -C not -c

Signed-off-by: Adrian Hunter 
---
 tools/perf/util/session.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 7dc1096264c5..d19c40a81040 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -2035,7 +2035,7 @@ int perf_session__cpu_bitmap(struct perf_session *session,
 
if (!(evsel->attr.sample_type & PERF_SAMPLE_CPU)) {
pr_err("File does not contain CPU events. "
-  "Remove -c option to proceed.\n");
+  "Remove -C option to proceed.\n");
return -1;
}
}
-- 
1.9.1



Re: [PATCH 4/5] efi: Lock down the kernel if booted in secure boot mode

2017-05-26 Thread joeyli
On Wed, May 24, 2017 at 03:45:56PM +0100, David Howells wrote:
> UEFI Secure Boot provides a mechanism for ensuring that the firmware will
> only load signed bootloaders and kernels.  Certain use cases may also
> require that all kernel modules also be signed.  Add a configuration option
> that to lock down the kernel - which includes requiring validly signed
> modules - if the kernel is secure-booted.
> 
> Signed-off-by: David Howells 
> cc: linux-...@vger.kernel.org

Reviewed-by: Joey Lee 

Regards
Joey Lee

> ---
> 
>  drivers/firmware/efi/Kconfig  |1 +
>  drivers/firmware/efi/secureboot.c |   10 +-
>  2 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig
> index c40fdeaf9a45..d03af2d5f52f 100644
> --- a/drivers/firmware/efi/Kconfig
> +++ b/drivers/firmware/efi/Kconfig
> @@ -87,6 +87,7 @@ config EFI_RUNTIME_WRAPPERS
>  config EFI_SECURE_BOOT
>   bool "Support UEFI Secure Boot and lock down the kernel in secure boot 
> mode"
>   default n
> + select LOCK_DOWN_KERNEL
>   help
> UEFI Secure Boot provides a mechanism for ensuring that the firmware
> will only load signed bootloaders and kernels.  Secure boot mode may
> diff --git a/drivers/firmware/efi/secureboot.c 
> b/drivers/firmware/efi/secureboot.c
> index 730518061a14..7292a3b832e3 100644
> --- a/drivers/firmware/efi/secureboot.c
> +++ b/drivers/firmware/efi/secureboot.c
> @@ -12,6 +12,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  /*
>   * Decide what to do when UEFI secure boot mode is enabled.
> @@ -23,10 +24,17 @@ void __init efi_set_secure_boot(enum efi_secureboot_mode 
> mode)
>   case efi_secureboot_mode_disabled:
>   pr_info("Secure boot disabled\n");
>   break;
> +
>   case efi_secureboot_mode_enabled:
>   set_bit(EFI_SECURE_BOOT, );
> - pr_info("Secure boot enabled\n");
> + if (IS_ENABLED(CONFIG_LOCK_DOWN_KERNEL)) {
> + lock_kernel_down();
> + pr_info("Secure boot enabled and kernel locked 
> down\n");
> + } else {
> + pr_info("Secure boot enabled\n");
> + }
>   break;
> +
>   default:
>   pr_info("Secure boot could not be determined\n");
>   break;
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-efi" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 14/37] perf intel-pt: Add reserved byte to CBR packet payload

2017-05-26 Thread Adrian Hunter
Future proof CBR packet decoding by passing through also the undefined
'reserved' byte in the packet payload.

Signed-off-by: Adrian Hunter 
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 +-
 tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index e42804d10001..96bf8d8e83c0 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1444,7 +1444,7 @@ static void intel_pt_calc_mtc_timestamp(struct 
intel_pt_decoder *decoder)
 
 static void intel_pt_calc_cbr(struct intel_pt_decoder *decoder)
 {
-   unsigned int cbr = decoder->packet.payload;
+   unsigned int cbr = decoder->packet.payload & 0xff;
 
if (decoder->cbr == cbr)
return;
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c 
b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
index accdb646a03d..ba4c9dd18643 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
@@ -130,7 +130,7 @@ static int intel_pt_get_cbr(const unsigned char *buf, 
size_t len,
if (len < 4)
return INTEL_PT_NEED_MORE_BYTES;
packet->type = INTEL_PT_CBR;
-   packet->payload = buf[2];
+   packet->payload = le16_to_cpu(*(uint16_t *)(buf + 2));
return 4;
 }
 
-- 
1.9.1



Re: [Intel-gfx] [PATCH v5 4/5] drm/i915/gvt: Dmabuf support for GVT-g

2017-05-26 Thread Chris Wilson
On Thu, May 25, 2017 at 02:28:25PM +0100, Chris Wilson wrote:
> On Tue, May 23, 2017 at 06:32:00PM +0800, Xiaoguang Chen wrote:
> > +   gtt_entries = (gen8_pte_t __iomem *)dev_priv->ggtt.gsm +
> > +   (fb_gma >> PAGE_SHIFT);
> > +   for_each_sg(st->sgl, sg, fb_size, i) {
> > +   sg->offset = 0;
> > +   sg->length = PAGE_SIZE;
> > +   sg_dma_address(sg) =
> > +   GEN8_DECODE_PTE(readq(_entries[i]));
> > +   sg_dma_len(sg) = PAGE_SIZE;
> 
> This assumes that the entries are PAGE_SIZE. This will not remain true.

Ok, we will only be supporting different page sizes for ppgtt. However,
it is probably better to use I915_GTT_PAGE_SIZE to match our insertions.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


[PATCH V2 19/37] perf script: Fix message because field list option is -F not -f

2017-05-26 Thread Adrian Hunter
Fix message because field list option is -F not -f.

Signed-off-by: Adrian Hunter 
---
 tools/perf/builtin-script.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index d05aec491cff..79a101e0e13b 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -383,7 +383,7 @@ static int perf_session__check_output_opt(struct 
perf_session *session)
 */
if (!evsel && output[j].user_set && !output[j].wildcard_set) {
pr_err("%s events do not exist. "
-  "Remove corresponding -f option to proceed.\n",
+  "Remove corresponding -F option to proceed.\n",
   event_type(j));
return -1;
}
-- 
1.9.1



[PATCH V2 20/37] perf script: Add 'synth' event type for synthesized events

2017-05-26 Thread Adrian Hunter
Instruction trace decoders such as Intel PT may have additional information
recorded in the trace. For example, Intel PT has power information and a
there is a new instruction 'ptwrite' that can write a value into a PTWRITE
trace packet. Such information may be associated with an IP and so can be
treated as a sample (PERF_RECORD_SAMPLE). Custom data can be incorporated
in the sample as raw_data (PERF_SAMPLE_RAW). However a means of identifying
the raw data format is needed. That will be done by synthesizing an
attribute for it. So add an attribute type for custom synthesized events.
Different synthesized events will be identified by the attribute 'config'.

Signed-off-by: Adrian Hunter 
---
 tools/perf/builtin-script.c | 74 +++--
 tools/perf/util/event.h |  3 ++
 2 files changed, 61 insertions(+), 16 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 79a101e0e13b..99167bafe81c 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -117,6 +117,11 @@ struct output_option {
{.str = "brstackinsn", .field = PERF_OUTPUT_BRSTACKINSN},
 };
 
+enum {
+   OUTPUT_TYPE_SYNTH = PERF_TYPE_MAX,
+   OUTPUT_TYPE_MAX
+};
+
 /* default set to maintain compatibility with current format */
 static struct {
bool user_set;
@@ -124,7 +129,7 @@ struct output_option {
unsigned int print_ip_opts;
u64 fields;
u64 invalid_fields;
-} output[PERF_TYPE_MAX] = {
+} output[OUTPUT_TYPE_MAX] = {
 
[PERF_TYPE_HARDWARE] = {
.user_set = false,
@@ -182,12 +187,43 @@ struct output_option {
 
.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
},
+
+   [OUTPUT_TYPE_SYNTH] = {
+   .user_set = false,
+
+   .fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
+ PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
+ PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
+ PERF_OUTPUT_SYM | PERF_OUTPUT_DSO,
+
+   .invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
+   },
 };
 
+static inline int output_type(unsigned int type)
+{
+   switch (type) {
+   case PERF_TYPE_SYNTH:
+   return OUTPUT_TYPE_SYNTH;
+   default:
+   return type;
+   }
+}
+
+static inline unsigned int attr_type(unsigned int type)
+{
+   switch (type) {
+   case OUTPUT_TYPE_SYNTH:
+   return PERF_TYPE_SYNTH;
+   default:
+   return type;
+   }
+}
+
 static bool output_set_by_user(void)
 {
int j;
-   for (j = 0; j < PERF_TYPE_MAX; ++j) {
+   for (j = 0; j < OUTPUT_TYPE_MAX; ++j) {
if (output[j].user_set)
return true;
}
@@ -208,7 +244,7 @@ static const char *output_field2str(enum perf_output_field 
field)
return str;
 }
 
-#define PRINT_FIELD(x)  (output[attr->type].fields & PERF_OUTPUT_##x)
+#define PRINT_FIELD(x)  (output[output_type(attr->type)].fields & 
PERF_OUTPUT_##x)
 
 static int perf_evsel__do_check_stype(struct perf_evsel *evsel,
  u64 sample_type, const char *sample_msg,
@@ -216,7 +252,7 @@ static int perf_evsel__do_check_stype(struct perf_evsel 
*evsel,
  bool allow_user_set)
 {
struct perf_event_attr *attr = >attr;
-   int type = attr->type;
+   int type = output_type(attr->type);
const char *evname;
 
if (attr->sample_type & sample_type)
@@ -346,7 +382,7 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
 
 static void set_print_ip_opts(struct perf_event_attr *attr)
 {
-   unsigned int type = attr->type;
+   unsigned int type = output_type(attr->type);
 
output[type].print_ip_opts = 0;
if (PRINT_FIELD(IP))
@@ -374,14 +410,15 @@ static int perf_session__check_output_opt(struct 
perf_session *session)
unsigned int j;
struct perf_evsel *evsel;
 
-   for (j = 0; j < PERF_TYPE_MAX; ++j) {
-   evsel = perf_session__find_first_evtype(session, j);
+   for (j = 0; j < OUTPUT_TYPE_MAX; ++j) {
+   evsel = perf_session__find_first_evtype(session, attr_type(j));
 
/*
 * even if fields is set to 0 (ie., show nothing) event must
 * exist if user explicitly includes it on the command line
 */
-   if (!evsel && output[j].user_set && !output[j].wildcard_set) {
+   if (!evsel && output[j].user_set && !output[j].wildcard_set &&
+   j != OUTPUT_TYPE_SYNTH) {
pr_err("%s events do not exist. "
   "Remove corresponding -F option to proceed.\n",
   event_type(j));
@@ -906,6 +943,7 @@ static void print_sample_bts(struct perf_sample *sample,
   

[PATCH V2 22/37] tools include: Add byte-swapping macros to kernel.h

2017-05-26 Thread Adrian Hunter
Add byte-swapping macros to kernel.h

Signed-off-by: Adrian Hunter 
---
 tools/include/linux/kernel.h | 35 +--
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h
index 73ccc48126bb..039bb85e4171 100644
--- a/tools/include/linux/kernel.h
+++ b/tools/include/linux/kernel.h
@@ -5,6 +5,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #ifndef UINT_MAX
 #define UINT_MAX   (~0U)
@@ -67,12 +69,33 @@
 #endif
 #endif
 
-/*
- * Both need more care to handle endianness
- * (Don't use bitmap_copy_le() for now)
- */
-#define cpu_to_le64(x) (x)
-#define cpu_to_le32(x) (x)
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define cpu_to_le16 bswap_16
+#define cpu_to_le32 bswap_32
+#define cpu_to_le64 bswap_64
+#define le16_to_cpu bswap_16
+#define le32_to_cpu bswap_32
+#define le64_to_cpu bswap_64
+#define cpu_to_be16
+#define cpu_to_be32
+#define cpu_to_be64
+#define be16_to_cpu
+#define be32_to_cpu
+#define be64_to_cpu
+#else
+#define cpu_to_le16
+#define cpu_to_le32
+#define cpu_to_le64
+#define le16_to_cpu
+#define le32_to_cpu
+#define le64_to_cpu
+#define cpu_to_be16 bswap_16
+#define cpu_to_be32 bswap_32
+#define cpu_to_be64 bswap_64
+#define be16_to_cpu bswap_16
+#define be32_to_cpu bswap_32
+#define be64_to_cpu bswap_64
+#endif
 
 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
 int scnprintf(char * buf, size_t size, const char * fmt, ...);
-- 
1.9.1



[PATCH V2 15/37] perf intel-pt: Add decoder support for CBR events

2017-05-26 Thread Adrian Hunter
Add decoder support for informing the tools of changes to the core-to-bus
ratio (CBR).

Signed-off-by: Adrian Hunter 
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 19 +++
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.h |  2 ++
 2 files changed, 21 insertions(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 96bf8d8e83c0..5dea06289db5 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -141,6 +141,7 @@ struct intel_pt_decoder {
int pkt_len;
int last_packet_type;
unsigned int cbr;
+   unsigned int cbr_seen;
unsigned int max_non_turbo_ratio;
double max_non_turbo_ratio_fp;
double cbr_cyc_to_tsc;
@@ -167,6 +168,7 @@ struct intel_pt_decoder {
uint64_t fup_ptw_payload;
uint64_t fup_mwait_payload;
uint64_t fup_pwre_payload;
+   uint64_t cbr_payload;
uint64_t timestamp_insn_cnt;
uint64_t sample_insn_cnt;
uint64_t stuck_ip;
@@ -1446,6 +1448,8 @@ static void intel_pt_calc_cbr(struct intel_pt_decoder 
*decoder)
 {
unsigned int cbr = decoder->packet.payload & 0xff;
 
+   decoder->cbr_payload = decoder->packet.payload;
+
if (decoder->cbr == cbr)
return;
 
@@ -1806,6 +1810,16 @@ static int intel_pt_walk_trace(struct intel_pt_decoder 
*decoder)
 
case INTEL_PT_CBR:
intel_pt_calc_cbr(decoder);
+   if (!decoder->branch_enable &&
+   decoder->cbr != decoder->cbr_seen) {
+   decoder->cbr_seen = decoder->cbr;
+   decoder->state.type = INTEL_PT_CBR_CHG;
+   decoder->state.from_ip = decoder->ip;
+   decoder->state.to_ip = 0;
+   decoder->state.cbr_payload =
+   decoder->packet.payload;
+   return 0;
+   }
break;
 
case INTEL_PT_MODE_EXEC:
@@ -2343,6 +2357,11 @@ const struct intel_pt_state *intel_pt_decode(struct 
intel_pt_decoder *decoder)
decoder->sample_insn_cnt = decoder->timestamp_insn_cnt;
} else {
decoder->state.err = 0;
+   if (decoder->cbr != decoder->cbr_seen && decoder->state.type) {
+   decoder->cbr_seen = decoder->cbr;
+   decoder->state.type |= INTEL_PT_CBR_CHG;
+   decoder->state.cbr_payload = decoder->cbr_payload;
+   }
if (intel_pt_sample_time(decoder->pkt_state)) {
decoder->sample_timestamp = decoder->timestamp;
decoder->sample_insn_cnt = decoder->timestamp_insn_cnt;
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
index 414c88e9e0da..921b22e8ca0e 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
@@ -36,6 +36,7 @@ enum intel_pt_sample_type {
INTEL_PT_PWR_ENTRY  = 1 << 5,
INTEL_PT_EX_STOP= 1 << 6,
INTEL_PT_PWR_EXIT   = 1 << 7,
+   INTEL_PT_CBR_CHG= 1 << 8,
 };
 
 enum intel_pt_period_type {
@@ -73,6 +74,7 @@ struct intel_pt_state {
uint64_t mwait_payload;
uint64_t pwre_payload;
uint64_t pwrx_payload;
+   uint64_t cbr_payload;
uint32_t flags;
enum intel_pt_insn_op insn_op;
int insn_len;
-- 
1.9.1



[PATCH V2 07/37] perf intel-pt: Use FUP always when scanning for an IP

2017-05-26 Thread Adrian Hunter
The decoder will try to use branch packets to find an IP to start decoding
or to recover from errors. Currently the FUP packet is used only in the
case of an overflow, however there is no reason for that to be a special
case. So just use FUP always when scanning for an IP.

Signed-off-by: Adrian Hunter 
Cc: sta...@vger.kernel.org
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 72b9dc8135a2..923c60efda26 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1882,14 +1882,10 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder 
*decoder)
break;
 
case INTEL_PT_FUP:
-   if (decoder->overflow) {
-   if (intel_pt_have_ip(decoder))
-   intel_pt_set_ip(decoder);
-   if (decoder->ip)
-   return 0;
-   }
-   if (decoder->packet.count && decoder->have_last_ip)
-   intel_pt_set_last_ip(decoder);
+   if (intel_pt_have_ip(decoder))
+   intel_pt_set_ip(decoder);
+   if (decoder->ip)
+   return 0;
break;
 
case INTEL_PT_MTC:
-- 
1.9.1



[PATCH V2 08/37] perf intel-pt: Clear FUP flag on error

2017-05-26 Thread Adrian Hunter
Sometimes a FUP packet is associated with a TSX transaction and a flag is
set to indicate that. Ensure that flag is cleared on any error condition
because at that point the decoder can no longer assume it is correct.

Signed-off-by: Adrian Hunter 
Cc: sta...@vger.kernel.org
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 923c60efda26..a97710162e07 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1962,6 +1962,8 @@ static int intel_pt_sync_ip(struct intel_pt_decoder 
*decoder)
 {
int err;
 
+   decoder->set_fup_tx_flags = false;
+
intel_pt_log("Scanning for full IP\n");
err = intel_pt_walk_to_ip(decoder);
if (err)
-- 
1.9.1



[PATCH V2 10/37] perf intel-pt: Allow decoding with branch tracing disabled

2017-05-26 Thread Adrian Hunter
The kernel now supports the disabling of branch tracing, however the
decoder assumes branch tracing is always enabled. Pass through a parameter
to indicate whether branch tracing is enabled and use it to avoid cases
when the decoder is expecting branch packets. There are 2 such cases.
First, FUP packets which can bind to an IP even when there is no branch
tracing. Secondly, the decoder will try to use branch packets to find an IP
to start decoding or to recover from errors.

Signed-off-by: Adrian Hunter 
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 +
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.h |  1 +
 tools/perf/util/intel-pt.c  | 14 ++
 3 files changed, 28 insertions(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index cad40fe93bd2..dacb9223e743 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -106,6 +106,7 @@ struct intel_pt_decoder {
const unsigned char *buf;
size_t len;
bool return_compression;
+   bool branch_enable;
bool mtc_insn;
bool pge;
bool have_tma;
@@ -214,6 +215,7 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct 
intel_pt_params *params)
decoder->pgd_ip = params->pgd_ip;
decoder->data   = params->data;
decoder->return_compression = params->return_compression;
+   decoder->branch_enable  = params->branch_enable;
 
decoder->period = params->period;
decoder->period_type= params->period_type;
@@ -1650,6 +1652,10 @@ static int intel_pt_walk_trace(struct intel_pt_decoder 
*decoder)
break;
}
intel_pt_set_last_ip(decoder);
+   if (!decoder->branch_enable) {
+   decoder->ip = decoder->last_ip;
+   break;
+   }
err = intel_pt_walk_fup(decoder);
if (err != -EAGAIN) {
if (err)
@@ -1964,6 +1970,13 @@ static int intel_pt_sync_ip(struct intel_pt_decoder 
*decoder)
 
decoder->set_fup_tx_flags = false;
 
+   if (!decoder->branch_enable) {
+   decoder->pkt_state = INTEL_PT_STATE_IN_SYNC;
+   decoder->overflow = false;
+   decoder->state.type = 0; /* Do not have a sample */
+   return 0;
+   }
+
intel_pt_log("Scanning for full IP\n");
err = intel_pt_walk_to_ip(decoder);
if (err)
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
index e90619a43c0c..add3bed58349 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
@@ -87,6 +87,7 @@ struct intel_pt_params {
bool (*pgd_ip)(uint64_t ip, void *data);
void *data;
bool return_compression;
+   bool branch_enable;
uint64_t period;
enum intel_pt_period_type period_type;
unsigned max_non_turbo_ratio;
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 4c7718f87a08..5c59b8c6a719 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -668,6 +668,19 @@ static bool intel_pt_return_compression(struct intel_pt 
*pt)
return true;
 }
 
+static bool intel_pt_branch_enable(struct intel_pt *pt)
+{
+   struct perf_evsel *evsel;
+   u64 config;
+
+   evlist__for_each_entry(pt->session->evlist, evsel) {
+   if (intel_pt_get_config(pt, >attr, ) &&
+   (config & 1) && !(config & 0x2000))
+   return false;
+   }
+   return true;
+}
+
 static unsigned int intel_pt_mtc_period(struct intel_pt *pt)
 {
struct perf_evsel *evsel;
@@ -799,6 +812,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct 
intel_pt *pt,
params.walk_insn = intel_pt_walk_next_insn;
params.data = ptq;
params.return_compression = intel_pt_return_compression(pt);
+   params.branch_enable = intel_pt_branch_enable(pt);
params.max_non_turbo_ratio = pt->max_non_turbo_ratio;
params.mtc_period = intel_pt_mtc_period(pt);
params.tsc_ctc_ratio_n = pt->tsc_ctc_ratio_n;
-- 
1.9.1



[PATCH V2 00/37] perf intel-pt: Power events and PTWRITE

2017-05-26 Thread Adrian Hunter
Hi

Here are some patches to support Intel PT Power events and PTWRITE.
Power events report changes to C-state but I have also added support
for the existing CBR (core-to-bus ratio) packet and included that
when outputting power events.  The PTWRITE packet is associated with
the new ptwrite instruction, which is essentially just a way to stuff
a 32 or 64 bit value into the PT trace.  More details can be found in
the patches that add documentation and in the Intel SDM.

As far as I know, there isn't any hardware released that supports
the new packets, however the CBR packet is not new and will now be
visible by default.

There are also some miscellaneous improvements to Intel PT.

There are 3 patches that introduce a new way to define synthesized
events that carry arbitrary raw_data.  I sent an RFC about that earlier.
The 3 patches are:
  perf script: Add 'synth' event type for synthesized events
  perf script: Add 'synth' field for synthesized event payloads
  perf script: Add synthesized Intel PT power and ptwrite events


Changes in V2:

Reorder patches and add stable tags to fixes.


Adrian Hunter (37):
  perf intel-pt: Move decoder error setting into one condition
  perf intel-pt: Improve sample timestamp
  perf intel-pt: Fix missing stack clear
  perf intel-pt: Ensure IP is zero when state is INTEL_PT_STATE_NO_IP
  perf intel-pt: Fix last_ip usage
  perf intel-pt: Ensure never to set 'last_ip' when packet 'count' is zero
  perf intel-pt: Use FUP always when scanning for an IP
  perf intel-pt: Clear FUP flag on error
  perf intel-pt: Add missing __fallthrough
  perf intel-pt: Allow decoding with branch tracing disabled
  perf intel-pt: Add default config for pass-through branch enable
  perf intel-pt: Add documentation for new config terms
  perf intel-pt: Add decoder support for ptwrite and power event packets
  perf intel-pt: Add reserved byte to CBR packet payload
  perf intel-pt: Add decoder support for CBR events
  perf intel-pt: Remove redundant initial_skip checks
  perf intel-pt: Fix transactions_sample_type
  perf tools: Fix message because cpu list option is -C not -c
  perf script: Fix message because field list option is -F not -f
  perf script: Add 'synth' event type for synthesized events
  perf script: Add 'synth' field for synthesized event payloads
  tools include: Add byte-swapping macros to kernel.h
  perf auxtrace: Add itrace option to output ptwrite events
  perf auxtrace: Add itrace option to output power events
  perf script: Add synthesized Intel PT power and ptwrite events
  perf intel-pt: Factor out common code synthesizing event samples
  perf intel-pt: Remove unused instructions_sample_period
  perf intel-pt: Join needlessly wrapped lines
  perf intel-pt: Tidy Intel PT evsel lookup into separate function
  perf intel-pt: Tidy messages into called function intel_pt_synth_event()
  perf intel-pt: Factor out intel_pt_set_event_name()
  perf intel-pt: Move code in intel_pt_synth_events() to simplify attr 
setting
  perf intel-pt: Synthesize new power and ptwrite events
  perf intel-pt: Add example script for power events and PTWRITE
  perf intel-pt: Update documentation to include new ptwrite and power 
events
  perf intel-pt: Do not use TSC packets for calculating CPU cycles to TSC
  perf auxtrace: Add CPU filter support

 tools/include/linux/kernel.h   |  35 +-
 tools/perf/Documentation/intel-pt.txt  |  78 ++-
 tools/perf/Documentation/itrace.txt|   8 +-
 tools/perf/Documentation/perf-script.txt   |   6 +-
 tools/perf/arch/x86/util/intel-pt.c|   5 +
 tools/perf/builtin-report.c|   1 +
 tools/perf/builtin-script.c| 207 ++-
 .../perf/scripts/python/bin/intel-pt-events-record |  13 +
 .../perf/scripts/python/bin/intel-pt-events-report |   3 +
 tools/perf/scripts/python/intel-pt-events.py   | 128 
 tools/perf/util/auxtrace.c |  18 +
 tools/perf/util/auxtrace.h |   6 +
 tools/perf/util/event.h|  93 +++
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 304 +-
 .../perf/util/intel-pt-decoder/intel-pt-decoder.h  |  13 +
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.c   | 110 +++-
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.h   |   7 +
 tools/perf/util/intel-pt.c | 642 +++--
 tools/perf/util/session.c  |   2 +-
 19 files changed, 1435 insertions(+), 244 deletions(-)
 create mode 100644 tools/perf/scripts/python/bin/intel-pt-events-record
 create mode 100644 tools/perf/scripts/python/bin/intel-pt-events-report
 create mode 100644 tools/perf/scripts/python/intel-pt-events.py


Regards
Adrian


[PATCH V2 13/37] perf intel-pt: Add decoder support for ptwrite and power event packets

2017-05-26 Thread Adrian Hunter
Add decoder support for PTWRITE, MWAIT, PWRE, PWRX and EXSTOP packets. This
patch only affects the decoder, so the tools still do not select or consume
the new information. That is added in subsequent patches.

Signed-off-by: Adrian Hunter 
---
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 176 -
 .../perf/util/intel-pt-decoder/intel-pt-decoder.h  |  10 ++
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.c   | 108 +
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.h   |   7 +
 4 files changed, 293 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index dacb9223e743..e42804d10001 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -158,8 +158,15 @@ struct intel_pt_decoder {
bool continuous_period;
bool overflow;
bool set_fup_tx_flags;
+   bool set_fup_ptw;
+   bool set_fup_mwait;
+   bool set_fup_pwre;
+   bool set_fup_exstop;
unsigned int fup_tx_flags;
unsigned int tx_flags;
+   uint64_t fup_ptw_payload;
+   uint64_t fup_mwait_payload;
+   uint64_t fup_pwre_payload;
uint64_t timestamp_insn_cnt;
uint64_t sample_insn_cnt;
uint64_t stuck_ip;
@@ -660,6 +667,8 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info 
*pkt_info)
case INTEL_PT_PAD:
case INTEL_PT_VMCS:
case INTEL_PT_MNT:
+   case INTEL_PT_PTWRITE:
+   case INTEL_PT_PTWRITE_IP:
return 0;
 
case INTEL_PT_MTC:
@@ -758,6 +767,11 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info 
*pkt_info)
 
case INTEL_PT_TIP_PGD:
case INTEL_PT_TRACESTOP:
+   case INTEL_PT_EXSTOP:
+   case INTEL_PT_EXSTOP_IP:
+   case INTEL_PT_MWAIT:
+   case INTEL_PT_PWRE:
+   case INTEL_PT_PWRX:
case INTEL_PT_OVF:
case INTEL_PT_BAD: /* Does not happen */
default:
@@ -1016,6 +1030,57 @@ static int intel_pt_walk_insn(struct intel_pt_decoder 
*decoder,
return err;
 }
 
+static bool intel_pt_fup_event(struct intel_pt_decoder *decoder)
+{
+   bool ret = false;
+
+   if (decoder->set_fup_tx_flags) {
+   decoder->set_fup_tx_flags = false;
+   decoder->tx_flags = decoder->fup_tx_flags;
+   decoder->state.type = INTEL_PT_TRANSACTION;
+   decoder->state.from_ip = decoder->ip;
+   decoder->state.to_ip = 0;
+   decoder->state.flags = decoder->fup_tx_flags;
+   return true;
+   }
+   if (decoder->set_fup_ptw) {
+   decoder->set_fup_ptw = false;
+   decoder->state.type = INTEL_PT_PTW;
+   decoder->state.flags |= INTEL_PT_FUP_IP;
+   decoder->state.from_ip = decoder->ip;
+   decoder->state.to_ip = 0;
+   decoder->state.ptw_payload = decoder->fup_ptw_payload;
+   return true;
+   }
+   if (decoder->set_fup_mwait) {
+   decoder->set_fup_mwait = false;
+   decoder->state.type = INTEL_PT_MWAIT_OP;
+   decoder->state.from_ip = decoder->ip;
+   decoder->state.to_ip = 0;
+   decoder->state.mwait_payload = decoder->fup_mwait_payload;
+   ret = true;
+   }
+   if (decoder->set_fup_pwre) {
+   decoder->set_fup_pwre = false;
+   decoder->state.type |= INTEL_PT_PWR_ENTRY;
+   decoder->state.type &= ~INTEL_PT_BRANCH;
+   decoder->state.from_ip = decoder->ip;
+   decoder->state.to_ip = 0;
+   decoder->state.pwre_payload = decoder->fup_pwre_payload;
+   ret = true;
+   }
+   if (decoder->set_fup_exstop) {
+   decoder->set_fup_exstop = false;
+   decoder->state.type |= INTEL_PT_EX_STOP;
+   decoder->state.type &= ~INTEL_PT_BRANCH;
+   decoder->state.flags |= INTEL_PT_FUP_IP;
+   decoder->state.from_ip = decoder->ip;
+   decoder->state.to_ip = 0;
+   ret = true;
+   }
+   return ret;
+}
+
 static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)
 {
struct intel_pt_insn intel_pt_insn;
@@ -1029,15 +1094,8 @@ static int intel_pt_walk_fup(struct intel_pt_decoder 
*decoder)
if (err == INTEL_PT_RETURN)
return 0;
if (err == -EAGAIN) {
-   if (decoder->set_fup_tx_flags) {
-   decoder->set_fup_tx_flags = false;
-   decoder->tx_flags = decoder->fup_tx_flags;
-   decoder->state.type = INTEL_PT_TRANSACTION;
-   decoder->state.from_ip = decoder->ip;
-   decoder->state.to_ip = 0;
- 

[PATCH V2 02/37] perf intel-pt: Improve sample timestamp

2017-05-26 Thread Adrian Hunter
The decoder uses its current timestamp in samples. Usually that is a
timestamp that has already passed, but in some cases it is a timestamp for
a branch that the decoder is walking towards, and consequently hasn't
reached. Improve that situation by using the pkt_state to determine when
to use the current or previous timestamp.

Signed-off-by: Adrian Hunter 
Cc: sta...@vger.kernel.org
---
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 34 --
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 5a9676c6e23f..d5c69e822282 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -64,6 +64,25 @@ enum intel_pt_pkt_state {
INTEL_PT_STATE_FUP_NO_TIP,
 };
 
+static inline bool intel_pt_sample_time(enum intel_pt_pkt_state pkt_state)
+{
+   switch (pkt_state) {
+   case INTEL_PT_STATE_NO_PSB:
+   case INTEL_PT_STATE_NO_IP:
+   case INTEL_PT_STATE_ERR_RESYNC:
+   case INTEL_PT_STATE_IN_SYNC:
+   case INTEL_PT_STATE_TNT:
+   return true;
+   case INTEL_PT_STATE_TIP:
+   case INTEL_PT_STATE_TIP_PGD:
+   case INTEL_PT_STATE_FUP:
+   case INTEL_PT_STATE_FUP_NO_TIP:
+   return false;
+   default:
+   return true;
+   };
+}
+
 #ifdef INTEL_PT_STRICT
 #define INTEL_PT_STATE_ERR1INTEL_PT_STATE_NO_PSB
 #define INTEL_PT_STATE_ERR2INTEL_PT_STATE_NO_PSB
@@ -99,6 +118,7 @@ struct intel_pt_decoder {
uint64_t timestamp;
uint64_t tsc_timestamp;
uint64_t ref_timestamp;
+   uint64_t sample_timestamp;
uint64_t ret_addr;
uint64_t ctc_timestamp;
uint64_t ctc_delta;
@@ -139,6 +159,7 @@ struct intel_pt_decoder {
unsigned int fup_tx_flags;
unsigned int tx_flags;
uint64_t timestamp_insn_cnt;
+   uint64_t sample_insn_cnt;
uint64_t stuck_ip;
int no_progress;
int stuck_ip_prd;
@@ -898,6 +919,7 @@ static int intel_pt_walk_insn(struct intel_pt_decoder 
*decoder,
 
decoder->tot_insn_cnt += insn_cnt;
decoder->timestamp_insn_cnt += insn_cnt;
+   decoder->sample_insn_cnt += insn_cnt;
decoder->period_insn_cnt += insn_cnt;
 
if (err) {
@@ -2069,7 +2091,7 @@ static int intel_pt_sync(struct intel_pt_decoder *decoder)
 
 static uint64_t intel_pt_est_timestamp(struct intel_pt_decoder *decoder)
 {
-   uint64_t est = decoder->timestamp_insn_cnt << 1;
+   uint64_t est = decoder->sample_insn_cnt << 1;
 
if (!decoder->cbr || !decoder->max_non_turbo_ratio)
goto out;
@@ -2077,7 +2099,7 @@ static uint64_t intel_pt_est_timestamp(struct 
intel_pt_decoder *decoder)
est *= decoder->max_non_turbo_ratio;
est /= decoder->cbr;
 out:
-   return decoder->timestamp + est;
+   return decoder->sample_timestamp + est;
 }
 
 const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
@@ -2133,11 +2155,17 @@ const struct intel_pt_state *intel_pt_decode(struct 
intel_pt_decoder *decoder)
if (err) {
decoder->state.err = intel_pt_ext_err(err);
decoder->state.from_ip = decoder->ip;
+   decoder->sample_timestamp = decoder->timestamp;
+   decoder->sample_insn_cnt = decoder->timestamp_insn_cnt;
} else {
decoder->state.err = 0;
+   if (intel_pt_sample_time(decoder->pkt_state)) {
+   decoder->sample_timestamp = decoder->timestamp;
+   decoder->sample_insn_cnt = decoder->timestamp_insn_cnt;
+   }
}
 
-   decoder->state.timestamp = decoder->timestamp;
+   decoder->state.timestamp = decoder->sample_timestamp;
decoder->state.est_timestamp = intel_pt_est_timestamp(decoder);
decoder->state.cr3 = decoder->cr3;
decoder->state.tot_insn_cnt = decoder->tot_insn_cnt;
-- 
1.9.1



[PATCH V2 03/37] perf intel-pt: Fix missing stack clear

2017-05-26 Thread Adrian Hunter
The return compression stack must be cleared whenever there is a PSB. Fix
one case where that was not happening.

Signed-off-by: Adrian Hunter 
Cc: sta...@vger.kernel.org
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index d5c69e822282..28b16c3acdde 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1932,6 +1932,7 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder 
*decoder)
break;
 
case INTEL_PT_PSB:
+   intel_pt_clear_stack(>stack);
err = intel_pt_walk_psb(decoder);
if (err)
return err;
-- 
1.9.1



Re: [PATCH] ARM: dts: rockchip: correct regular setting for act8846

2017-05-26 Thread Eddie Cai
2017-05-24 20:27 GMT+08:00 Robin Murphy :
> On 24/05/17 12:34, Heiko Stuebner wrote:
>> Am Mittwoch, 24. Mai 2017, 11:26:10 CEST schrieb Robin Murphy:
>>> On 24/05/17 09:17, Heiko Stuebner wrote:
 Hi Eddie,

 Am Mittwoch, 24. Mai 2017, 15:33:41 CEST schrieb Eddie Cai:
> the previous setting of act8846 is just copy from firefly board. but
> the reload board is a little different from firefly board. let's correct
> it.
>
> Signed-off-by: Eddie Cai 
> ---
>  arch/arm/boot/dts/rk3288-firefly-reload-core.dtsi | 21 
> +++--
>  1 file changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/arch/arm/boot/dts/rk3288-firefly-reload-core.dtsi 
> b/arch/arm/boot/dts/rk3288-firefly-reload-core.dtsi
> index 8134966..4cfa109 100644
> --- a/arch/arm/boot/dts/rk3288-firefly-reload-core.dtsi
> +++ b/arch/arm/boot/dts/rk3288-firefly-reload-core.dtsi
> @@ -179,6 +179,7 @@
>regulator-name = "vccio_sd";
>regulator-min-microvolt = <330>;
>regulator-max-microvolt = <330>;
> +  regulator-always-on;

 the rest below looks pretty straight forward, but why does vccio_sd
 need to be always on?

 I've checked the reload's schematics but did not find any further users
 of vccio_sd that may warant this attribute.
>>>
>>> It looks like the card detect line is pulled up externally to vcc_sd,
>>> which isn't always-on either, so you probably do want this - on the
>>> (unrelated) rk3288 TV box I've been hacking on, I discovered that
>>> powering off the sdmmc-supply domain also kills the internal pull-up and
>>> leaves sdmmc_cd floating. The resulting stochastic card polling
>>> mechanism is amusing, but probably undesirable ;)
>>
>> Hmm, are you mixing up vcc_sd and vccio_sd?
>>
>> vccio_sd is the io supply (vqmmc in mmc-terms) to the mmc-host itself
>> while vcc_sd is the actual card supply (vmmc in mmc-terms).
>
> Yes, that is what I meant, although I was implicitly assuming the case
> where the MMC host driver has already turned off vcc_sd due to no card
> being present. I'll double-check, but I'm 99% certain that *unlike*
> Firefly, the Hotack board I've got (seemingly a straight implementation
> of the "Box" reference design based on what I've managed to
> reverse-engineer from scouring the internet) has no external pull-ups
> for anything on its microSD socket, so is entirely reliant on everything
> being pulled up internally to SDMMC0_VDD, i.e. vccio_sd.
>
>> After looking through some schematics, the pull-up to vcc_sd seems to be
>> the common pattern for rk3288 devices. So I guess this means the fixed
>> regulator vcc_sd should get an regulator-always-on instead to stabilize
>> the card-detect?
>
> That might make sense, especially where vcc_sd is just vcc_io behind a
> MOSFET switch, so turning it "off" when there's no card to draw power
> anyway probably doesn't achieve much. Plus if you can then rely on
> vcc_sd not going away it might be worth disabling the internal pull-ups
> which are still being set by all the sdmmc_* pinctrl configs as well.
the host might want to reset the card power when the card controller hang up.
it won't work if we add regulator-always-on to vcc_sd.  So i would
still prefer to
add regulator-always-on to vccio_sd instead of vcc_sd
>
> Robin.
>
>};
>
>vdd10_lcd: REG6 {
> @@ -187,24 +188,23 @@
>regulator-max-microvolt = <100>;
>};
>
> -  vcca_18: REG7  {
> -  regulator-name = "vcca_18";
> -  regulator-min-microvolt = <180>;
> -  regulator-max-microvolt = <180>;
> -  regulator-always-on;
> +  vcca_33: REG7  {
> +  regulator-name = "vcca_33";
> +  regulator-min-microvolt = <330>;
> +  regulator-max-microvolt = <330>;
>};
>
> -  vcca_33: REG8 {
> -  regulator-name = "vcca_33";
> +  vcc_lan: REG8 {
> +  regulator-name = "vcc_lan";
>regulator-min-microvolt = <330>;
>regulator-max-microvolt = <330>;
> -  regulator-always-on;
>};
>
> -  vcc_lan: REG9 {
> -  regulator-name = "vcca_lan";
> +  vccio_pmu: REG9 {
> +  regulator-name = "vccio_pmu";
>regulator-min-microvolt = 

[tip:smp/hotplug] padata: Make padata_alloc() static

2017-05-26 Thread tip-bot for Thomas Gleixner
Commit-ID:  9596695ee1e7eedd743c43811fe68299eb005b5c
Gitweb: http://git.kernel.org/tip/9596695ee1e7eedd743c43811fe68299eb005b5c
Author: Thomas Gleixner 
AuthorDate: Wed, 24 May 2017 10:15:17 +0200
Committer:  Thomas Gleixner 
CommitDate: Fri, 26 May 2017 10:10:37 +0200

padata: Make padata_alloc() static

No users outside of padata.c

Signed-off-by: Thomas Gleixner 
Tested-by: Paul E. McKenney 
Acked-by: Ingo Molnar 
Cc: Steffen Klassert 
Cc: Peter Zijlstra 
Cc: Sebastian Siewior 
Cc: Steven Rostedt 
Cc: linux-cry...@vger.kernel.org
Link: http://lkml.kernel.org/r/20170524081547.491457...@linutronix.de

---
 include/linux/padata.h |  3 ---
 kernel/padata.c| 32 
 2 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/include/linux/padata.h b/include/linux/padata.h
index 0f9e567..2f9c1f9 100644
--- a/include/linux/padata.h
+++ b/include/linux/padata.h
@@ -166,9 +166,6 @@ struct padata_instance {
 
 extern struct padata_instance *padata_alloc_possible(
struct workqueue_struct *wq);
-extern struct padata_instance *padata_alloc(struct workqueue_struct *wq,
-   const struct cpumask *pcpumask,
-   const struct cpumask *cbcpumask);
 extern void padata_free(struct padata_instance *pinst);
 extern int padata_do_parallel(struct padata_instance *pinst,
  struct padata_priv *padata, int cb_cpu);
diff --git a/kernel/padata.c b/kernel/padata.c
index ac8f1e5..0c708f6 100644
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -934,19 +934,6 @@ static struct kobj_type padata_attr_type = {
 };
 
 /**
- * padata_alloc_possible - Allocate and initialize padata instance.
- * Use the cpu_possible_mask for serial and
- * parallel workers.
- *
- * @wq: workqueue to use for the allocated padata instance
- */
-struct padata_instance *padata_alloc_possible(struct workqueue_struct *wq)
-{
-   return padata_alloc(wq, cpu_possible_mask, cpu_possible_mask);
-}
-EXPORT_SYMBOL(padata_alloc_possible);
-
-/**
  * padata_alloc - allocate and initialize a padata instance and specify
  *cpumasks for serial and parallel workers.
  *
@@ -954,9 +941,9 @@ EXPORT_SYMBOL(padata_alloc_possible);
  * @pcpumask: cpumask that will be used for padata parallelization
  * @cbcpumask: cpumask that will be used for padata serialization
  */
-struct padata_instance *padata_alloc(struct workqueue_struct *wq,
-const struct cpumask *pcpumask,
-const struct cpumask *cbcpumask)
+static struct padata_instance *padata_alloc(struct workqueue_struct *wq,
+   const struct cpumask *pcpumask,
+   const struct cpumask *cbcpumask)
 {
struct padata_instance *pinst;
struct parallel_data *pd = NULL;
@@ -1011,6 +998,19 @@ err:
 }
 
 /**
+ * padata_alloc_possible - Allocate and initialize padata instance.
+ * Use the cpu_possible_mask for serial and
+ * parallel workers.
+ *
+ * @wq: workqueue to use for the allocated padata instance
+ */
+struct padata_instance *padata_alloc_possible(struct workqueue_struct *wq)
+{
+   return padata_alloc(wq, cpu_possible_mask, cpu_possible_mask);
+}
+EXPORT_SYMBOL(padata_alloc_possible);
+
+/**
  * padata_free - free a padata instance
  *
  * @padata_inst: padata instance to free


[tip:smp/hotplug] s390/kernel: Use stop_machine_cpuslocked()

2017-05-26 Thread tip-bot for Sebastian Andrzej Siewior
Commit-ID:  2337e879e8805a630b418f3e73a98084d4724b83
Gitweb: http://git.kernel.org/tip/2337e879e8805a630b418f3e73a98084d4724b83
Author: Sebastian Andrzej Siewior 
AuthorDate: Wed, 24 May 2017 10:15:26 +0200
Committer:  Thomas Gleixner 
CommitDate: Fri, 26 May 2017 10:10:41 +0200

s390/kernel: Use stop_machine_cpuslocked()

stp_work_fn() holds get_online_cpus() while invoking stop_machine().

stop_machine() invokes get_online_cpus() as well. This is correct, but
prevents the conversion of the hotplug locking to a percpu rwsem.

Use stop_machine_cpuslocked() to avoid the nested call. Convert
*_online_cpus() to the new interfaces while at it.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Acked-by: Ingo Molnar 
Acked-by: Heiko Carstens 
Cc: Paul E. McKenney 
Cc: linux-s...@vger.kernel.org
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: David Hildenbrand 
Cc: Martin Schwidefsky 
Link: http://lkml.kernel.org/r/20170524081548.250203...@linutronix.de

---
 arch/s390/kernel/time.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c
index c3a52f9..192efdf 100644
--- a/arch/s390/kernel/time.c
+++ b/arch/s390/kernel/time.c
@@ -636,10 +636,10 @@ static void stp_work_fn(struct work_struct *work)
goto out_unlock;
 
memset(_sync, 0, sizeof(stp_sync));
-   get_online_cpus();
+   cpus_read_lock();
atomic_set(_sync.cpus, num_online_cpus() - 1);
-   stop_machine(stp_sync_clock, _sync, cpu_online_mask);
-   put_online_cpus();
+   stop_machine_cpuslocked(stp_sync_clock, _sync, cpu_online_mask);
+   cpus_read_unlock();
 
if (!check_sync_clock())
/*


Re: [RESEND: PATCH v4 1/4] firmware: scm: Add new SCM call for switching memory ownership

2017-05-26 Thread Bjorn Andersson
On Tue 16 May 11:01 PDT 2017, Avaneesh Kumar Dwivedi wrote:

> diff --git a/drivers/firmware/qcom_scm-32.c b/drivers/firmware/qcom_scm-32.c
> index 93e3b96..4eb7d59 100644
> --- a/drivers/firmware/qcom_scm-32.c
> +++ b/drivers/firmware/qcom_scm-32.c
> @@ -596,3 +596,9 @@ int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, 
> u64 addr, u32 size,
>  {
>   return -ENODEV;
>  }
> +int __qcom_scm_assign_mem(struct device *dev, phys_addr_t mem_addr,
> + size_t mem_sz, phys_addr_t srcVm, size_t srcVm_sz,
> + phys_addr_t destVm, size_t destVm_sz)
> +{
> +return -ENODEV;

Indentation please.

> +}
[..]
> diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom_scm.c
> index bb16510..a2363e2 100644
> --- a/drivers/firmware/qcom_scm.c
> +++ b/drivers/firmware/qcom_scm.c
> @@ -40,6 +40,24 @@ struct qcom_scm {
>   struct reset_controller_dev reset;
>  };
>  
> +struct qcom_scm_current_perm_info {
> + __le32 destVm;

__le32 vmid;

> + __le32 destVmPerm;

__le32 perm;

> + __le64 ctx;
> + __le32 ctx_size;
> +};
> +
> +struct qcom_scm_mem_map_info {
> + __le64 mem_addr;
> + __le64 mem_size;
> +};
> +
> +struct qcom_scm_hyp_map_info {
> + __le32 srcVm[2];
> + struct qcom_scm_mem_map_info mem_region;
> + struct qcom_scm_current_perm_info destVm[2];
> +};

As described below, both arrays in this struct should be dynamic size,
so I recommend dropping the struct and just do the offset math yourself
in the function.

> +
>  static struct qcom_scm *__scm;
>  
>  static int qcom_scm_clk_enable(void)
> @@ -292,6 +310,63 @@ int qcom_scm_pas_shutdown(u32 peripheral)
>  }
>  EXPORT_SYMBOL(qcom_scm_pas_shutdown);
>  
> +/**
> + * qcom_scm_assign_mem() - Provide interface to request to map a memory
> + * region into intermediate physical address table as well map
> + * access permissions for any other proc on SOC. So that when other proc
> + * applies the same intermediate physical address passed by requesting
> + * processor in this case apps proc, on memory bus it can access the
> + * region without fault.

The first line should be a short description of the function.

> + * @mem_addr: Start pointer of region which need to be mapped.
> + * @mem_sz: Size of the region.
> + * @srcVm: Detail of current owners, each set bit in flag indicate id of
> + * shared owners.
> + * @newVm: Details of new owners and permission flags for each of them.
> + * @newVm_sz: Size of array pointed by newVm.

If necessary (appropriate in your case) a longer description should go
here - with blank lines before and after.

> + * Return 0 on success.

For more info on the format, please see:

https://www.kernel.org/doc/Documentation/kernel-doc-nano-HOWTO.txt

> + */
> +int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz, int srcVm,
> + struct qcom_scm_destVmPerm *newVm, size_t newVm_sz)

It's more idiomatic to pass the number of elements in an array than the
size of the array, so make newVm_sz be the number of items.

And please refrain from using camelCase in the Linux kernel.

> +{
> + unsigned long dma_attrs = DMA_ATTR_FORCE_CONTIGUOUS;
> + struct qcom_scm_hyp_map_info *hmi;

Skip this struct and just store the base address in a void *, then have
one pointer for each of the substructures (to help fill them in).

> + phys_addr_t addr[3];
> + size_t size[3];

Please give these 6 variables names.

> + int ret;
> + int i;
> +
> + hmi = dma_alloc_attrs(__scm->dev, sizeof(*hmi),
> + [1], GFP_KERNEL, dma_attrs);

This function should handle arbitrary number of src and destination vms;
so start by calculating the hweight of the source, allocate the
appropriate amount of srcVM and dstVM space and then calculate the
offsets within that block for each entry.


Check and handle !hmi

> + hmi->mem_region.mem_addr = cpu_to_le64(mem_addr);
> + hmi->mem_region.mem_size = cpu_to_le64(mem_sz);
> +
> + addr[0] = addr[1] + sizeof(hmi->srcVm);
> + size[0] = sizeof(hmi->mem_region);
> +
> + ret = hweight_long(srcVm);
> + for (i = 0; i < ret; i++) {
> + hmi->srcVm[i] = cpu_to_le32(ffs(srcVm) - 0x1);

Subtract 1, rather than 0x1

> + srcVm ^= 1 << (ffs(srcVm) - 0x1);

Make this easier to read with:

for (...) {
vmid = ffs(srcVm) - 1;

hmi->srcVm[i] = cpu_to_le32(vmid);
srcVm &= ~BIT(vmid);
}

> + }
> + size[1] = ret * sizeof(srcVm);
> +
> + ret = newVm_sz/sizeof(struct qcom_scm_destVmPerm);
> + for (i = 0; i < ret; i++) {
> + hmi->destVm[i].destVm = cpu_to_le32(newVm[i].destVm);
> + hmi->destVm[i].destVmPerm = cpu_to_le32(newVm[i].destVmPerm);
> + hmi->destVm[i].ctx = 0;
> + hmi->destVm[i].ctx_size = 0;
> + }
> + addr[2] = addr[0] + sizeof(hmi->mem_region);
> + size[2] = ret * sizeof(struct qcom_scm_current_perm_info);
> +
> + ret = 

[PATCH 4/6] regulator: hi6421v530: add driver for hi6421v530 voltage regulator

2017-05-26 Thread Guodong Xu
From: Wang Xiaoyin 

add the driver for hi6421v530 voltage regulator

Signed-off-by: Wang Xiaoyin 
Signed-off-by: Guodong Xu 
---
 drivers/regulator/Kconfig|  10 +
 drivers/regulator/Makefile   |   1 +
 drivers/regulator/hi6421v530-regulator.c | 355 +++
 3 files changed, 366 insertions(+)
 create mode 100644 drivers/regulator/hi6421v530-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 48db87d..c389ce8 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -296,6 +296,16 @@ config REGULATOR_HI6421
  21 general purpose LDOs, 3 dedicated LDOs, and 5 BUCKs. All
  of them come with support to either ECO (idle) or sleep mode.
 
+config REGULATOR_HI6421V530
+   tristate "HiSilicon Hi6421v530 PMIC voltage regulator support"
+   depends on MFD_HI6421V530_PMIC && OF
+   help
+ This driver provides support for the voltage regulators on
+ HiSilicon Hi6421v530 PMU / Codec IC.
+ Hi6421v530 is a multi-function device which, on regulator part,
+ provides 5 general purpose LDOs, and all of them come with support
+ to either ECO (idle) or sleep mode.
+
 config REGULATOR_HI655X
tristate "Hisilicon HI655X PMIC regulators support"
depends on ARCH_HISI || COMPILE_TEST
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index dc3503f..36e2b75 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o
 obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o
 obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o
 obj-$(CONFIG_REGULATOR_HI6421) += hi6421-regulator.o
+obj-$(CONFIG_REGULATOR_HI6421V530) += hi6421v530-regulator.o
 obj-$(CONFIG_REGULATOR_HI655X) += hi655x-regulator.o
 obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o
 obj-$(CONFIG_REGULATOR_ISL9305) += isl9305.o
diff --git a/drivers/regulator/hi6421v530-regulator.c 
b/drivers/regulator/hi6421v530-regulator.c
new file mode 100644
index 000..82854d0
--- /dev/null
+++ b/drivers/regulator/hi6421v530-regulator.c
@@ -0,0 +1,355 @@
+/*
+ * Device driver for regulators in Hi6421V530 IC
+ *
+ * Copyright (c) <2017> HiSilicon Technologies Co., Ltd.
+ *  http://www.hisilicon.com
+ * Copyright (c) <2017> Linaro Ltd.
+ *  http://www.linaro.org
+ *
+ * Author: Wang Xiaoyin 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * struct hi6421c530_regulator_pdata - Hi6421V530 regulator data
+ * of platform device.
+ * @lock: mutex to serialize regulator enable
+ */
+struct hi6421v530_regulator_pdata {
+   struct mutex lock;
+};
+
+/*
+ * struct hi6421v530_regulator_info - hi6421v530 regulator information
+ * @desc: regulator description
+ * @mode_mask: ECO mode bitmask of LDOs; for BUCKs, this masks sleep
+ * @eco_microamp: eco mode load upper limit (in uA), valid for LDOs only
+ */
+struct hi6421v530_regulator_info {
+   struct regulator_desc   desc;
+   u8  mode_mask;
+   u32 eco_microamp;
+};
+
+/* HI6421v530 regulators */
+enum hi6421v530_regulator_id {
+   HI6421V530_LDO3,
+   HI6421V530_LDO9,
+   HI6421V530_LDO11,
+   HI6421V530_LDO15,
+   HI6421V530_LDO16,
+   HI6421V530_NUM_REGULATORS,
+};
+
+#define HI6421V530_REGULATOR_OF_MATCH(_name, id)   \
+{  \
+   .name = #_name, \
+   .driver_data = (void *) HI6421V530_##id,\
+}
+
+static struct of_regulator_match hi6421v530_regulator_match[] = {
+   HI6421V530_REGULATOR_OF_MATCH(hi6421v530_ldo3, LDO3),
+   HI6421V530_REGULATOR_OF_MATCH(hi6421v530_ldo9, LDO9),
+   HI6421V530_REGULATOR_OF_MATCH(hi6421v530_ldo11, LDO11),
+   HI6421V530_REGULATOR_OF_MATCH(hi6421v530_ldo15, LDO15),
+   HI6421V530_REGULATOR_OF_MATCH(hi6421v530_ldo16, LDO16),
+};
+
+static const unsigned int ldo_3_voltages[] = {
+   180, 1825000, 185, 1875000,
+   190, 1925000, 195, 1975000,
+   200, 2025000, 205, 2075000,
+   210, 2125000, 215, 220,
+};
+
+static const unsigned int ldo_9_11_voltages[] = {
+   175, 180, 1825000, 280,
+   285, 295, 300, 330,
+};
+
+static const unsigned int ldo_15_16_voltages[] = {
+   175, 180, 240, 260,
+   270, 285, 295, 300,
+};
+
+static const struct regulator_ops hi6421v530_ldo_ops;
+
+#define 

[PATCH 5/6] arm64: dts: hikey960: add device node for pmic and regulators

2017-05-26 Thread Guodong Xu
From: Wang Xiaoyin 

add device node for hi6421 pmic core and hi6421v530
voltage regulator,include LDO(1,3,9,11,15,16)

Signed-off-by: Wang Xiaoyin 
Signed-off-by: Guodong Xu 
---
 arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts | 60 +++
 1 file changed, 60 insertions(+)

diff --git a/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts 
b/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts
index ca448f0..b7a404a 100644
--- a/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts
+++ b/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts
@@ -97,6 +97,66 @@
default-state = "off";
};
};
+
+   pmic: pmic@fff34000 {
+   compatible = "hisilicon,hi6421v530-pmic";
+   reg = <0x0 0xfff34000 0x0 0x1000>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+
+   regulators {
+   ldo1: LDO1 {
+   regulator-compatible = "hi6421v530_ldo1";
+   regulator-name = "LDO1";
+   regulator-min-microvolt = <100>;
+   regulator-max-microvolt = <150>;
+   regulator-always-on;
+   regulator-enable-ramp-delay = <120>;
+   };
+
+   ldo3: LDO3 {
+   regulator-compatible = "hi6421v530_ldo3";
+   regulator-name = "LDO3";
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <220>;
+   regulator-always-on;
+   regulator-enable-ramp-delay = <120>;
+   };
+
+   ldo9: LDO9 {
+   regulator-compatible = "hi6421v530_ldo9";
+   regulator-name = "LDO9";
+   regulator-min-microvolt = <175>;
+   regulator-max-microvolt = <330>;
+   regulator-enable-ramp-delay = <240>;
+   };
+
+   ldo11: LDO11 {
+   regulator-compatible = "hi6421v530_ldo11";
+   regulator-name = "LDO11";
+   regulator-min-microvolt = <175>;
+   regulator-max-microvolt = <330>;
+   regulator-enable-ramp-delay = <240>;
+   };
+
+   ldo15: LDO15 {
+   regulator-compatible = "hi6421v530_ldo15";
+   regulator-name = "LDO15";
+   regulator-min-microvolt = <175>;
+   regulator-max-microvolt = <300>;
+   regulator-always-on;
+   regulator-enable-ramp-delay = <120>;
+   };
+
+   ldo16: LDO16 {
+   regulator-compatible = "hi6421v530_ldo16";
+   regulator-name = "LDO16";
+   regulator-min-microvolt = <175>;
+   regulator-max-microvolt = <300>;
+   regulator-enable-ramp-delay = <360>;
+   };
+   };
+   };
 };
 
  {
-- 
2.10.2



[PATCH 0/6] MFD: add driver for HiSilicon Hi6421v530 PMIC

2017-05-26 Thread Guodong Xu
This patchset adds driver for HiSilicon Hi6421v530 PMIC.

Mainline kernel already has driver support to a similar chip, Hi6421.
Hi6421 and Hi6421v530 are both from the same vendor, HiSilicon, but
they are at different revisions. They both use the same Memory-mapped
I/O method to communicate with Main SoC. However, they differ quite a
lot in their regulator designs. Eg. they have completely different LDO
voltage points.

In order to enable future extension of Hi6421v530 functionality, a new
mfd driver and regulator driver are added in this patchset. Only header
file hi6421-pmic.h is reused between them. Patch 2 is for just this
purpose.

Patch 3 and 4 adds mfd and regulator driver respectively.
Patch 5 is dts change, it depends and can be applied on hi3660/hikey960
patchset [1].
Patch 6 enables the relevant config items.

[1], http://www.spinics.net/lists/devicetree/msg178303.html

Guodong Xu (4):
  dt-bindings: mfd: Add hi6421v530 bindings
  mfd: hi6421-pmic: move hi6421_regmap_config definition to header file
  mfd: hi6421v530: add support for HiSilicon Hi6421v530
  arm64: defconfig: enable hi6421v530 MFD and regulator

Wang Xiaoyin (2):
  regulator: hi6421v530: add driver for hi6421v530 voltage regulator
  arm64: dts: hikey960: add device node for pmic and regulators

 .../bindings/mfd/hisilicon,hi6421v530.txt  |  25 ++
 arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts  |  60 
 arch/arm64/configs/defconfig   |   2 +
 drivers/mfd/Kconfig|   9 +
 drivers/mfd/Makefile   |   1 +
 drivers/mfd/hi6421-pmic-core.c |   7 -
 drivers/mfd/hi6421v530-pmic.c  |  92 ++
 drivers/regulator/Kconfig  |  10 +
 drivers/regulator/Makefile |   1 +
 drivers/regulator/hi6421v530-regulator.c   | 355 +
 include/linux/mfd/hi6421-pmic.h|   6 +
 11 files changed, 561 insertions(+), 7 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/mfd/hisilicon,hi6421v530.txt
 create mode 100644 drivers/mfd/hi6421v530-pmic.c
 create mode 100644 drivers/regulator/hi6421v530-regulator.c

-- 
2.10.2



[PATCH 3/6] mfd: hi6421v530: add support for HiSilicon Hi6421v530

2017-05-26 Thread Guodong Xu
Add support for HiSilicon Hi6421v530 PMIC. Hi6421v530 communicates with
main SoC via memory-mapped I/O.

Hi6421v530 and Hi6421 are PMIC chips from the same vendor, HiSilicon, but
at different revisions. They share the same memory-mapped I/O design. They
differ in regulator details, eg. LDO voltage points.

Signed-off-by: Guodong Xu 
Signed-off-by: Wang Xiaoyin 
---
 drivers/mfd/Kconfig   |  9 +
 drivers/mfd/Makefile  |  1 +
 drivers/mfd/hi6421v530-pmic.c | 92 +++
 3 files changed, 102 insertions(+)
 create mode 100644 drivers/mfd/hi6421v530-pmic.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 3eb5c93..bdc8304 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -388,6 +388,15 @@ config MFD_HI6421_PMIC
  menus in order to enable them.
  We communicate with the Hi6421 via memory-mapped I/O.
 
+config MFD_HI6421V530_PMIC
+   tristate "HiSilicon Hi6421v530 PMU/Codec IC"
+   depends on OF
+   select MFD_CORE
+   select REGMAP_MMIO
+   help
+ Add support for HiSilicon Hi6421v530 PMIC. Hi6421v530 communicates
+ with main SoC via memory-mapped I/O.
+
 config MFD_HI655X_PMIC
tristate "HiSilicon Hi655X series PMU/Codec IC"
depends on ARCH_HISI || COMPILE_TEST
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index c16bf1e..cde62fc 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -206,6 +206,7 @@ obj-$(CONFIG_MFD_STW481X)   += stw481x.o
 obj-$(CONFIG_MFD_IPAQ_MICRO)   += ipaq-micro.o
 obj-$(CONFIG_MFD_MENF21BMC)+= menf21bmc.o
 obj-$(CONFIG_MFD_HI6421_PMIC)  += hi6421-pmic-core.o
+obj-$(CONFIG_MFD_HI6421V530_PMIC)  += hi6421v530-pmic.o
 obj-$(CONFIG_MFD_HI655X_PMIC)   += hi655x-pmic.o
 obj-$(CONFIG_MFD_DLN2) += dln2.o
 obj-$(CONFIG_MFD_RT5033)   += rt5033.o
diff --git a/drivers/mfd/hi6421v530-pmic.c b/drivers/mfd/hi6421v530-pmic.c
new file mode 100644
index 000..651659a
--- /dev/null
+++ b/drivers/mfd/hi6421v530-pmic.c
@@ -0,0 +1,92 @@
+/*
+ * Device driver for Hi6421 IC
+ *
+ * Copyright (c) <2017> HiSilicon Technologies Co., Ltd.
+ *  http://www.hisilicon.com
+ * Copyright (c) <2017> Linaro Ltd.
+ *  http://www.linaro.org
+ *
+ * Author: Wang Xiaoyin 
+ * Guodong Xu 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static const struct mfd_cell hi6421v530_devs[] = {
+   { .name = "hi6421v530-regulator", },
+};
+
+static int hi6421v530_pmic_probe(struct platform_device *pdev)
+{
+   struct hi6421_pmic *pmic;
+   struct resource *res;
+   void __iomem *base;
+   int ret;
+
+   pmic = devm_kzalloc(>dev, sizeof(*pmic), GFP_KERNEL);
+   if (!pmic)
+   return -ENOMEM;
+
+   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   base = devm_ioremap_resource(>dev, res);
+   if (IS_ERR(base))
+   return PTR_ERR(base);
+
+   pmic->regmap = devm_regmap_init_mmio_clk(>dev, NULL, base,
+_regmap_config);
+   if (IS_ERR(pmic->regmap)) {
+   dev_err(>dev,
+   "regmap init failed: %ld\n", PTR_ERR(pmic->regmap));
+   return PTR_ERR(pmic->regmap);
+   }
+
+   platform_set_drvdata(pdev, pmic);
+
+   ret = devm_mfd_add_devices(>dev, 0, hi6421v530_devs,
+  ARRAY_SIZE(hi6421v530_devs), NULL, 0, NULL);
+   if (ret) {
+   dev_err(>dev, "add mfd devices failed: %d\n", ret);
+   return ret;
+   }
+
+   return 0;
+}
+
+static const struct of_device_id of_hi6421v530_pmic_match_tbl[] = {
+   { .compatible = "hisilicon,hi6421v530-pmic", },
+   { },
+};
+MODULE_DEVICE_TABLE(of, of_hi6421v530_pmic_match_tbl);
+
+static struct platform_driver hi6421v530_pmic_driver = {
+   .driver = {
+   .name   = "hi6421v530_pmic",
+   .of_match_table = of_hi6421v530_pmic_match_tbl,
+   },
+   .probe  = hi6421v530_pmic_probe,
+};
+module_platform_driver(hi6421v530_pmic_driver);
+
+MODULE_AUTHOR("Guodong Xu ");

[PATCH 6/6] arm64: defconfig: enable hi6421v530 MFD and regulator

2017-05-26 Thread Guodong Xu
Enable configs for hi6421v530 mfd and regulator driver

Signed-off-by: Guodong Xu 
---
 arch/arm64/configs/defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index ce07285..287e943 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -305,6 +305,7 @@ CONFIG_S3C2410_WATCHDOG=y
 CONFIG_MESON_GXBB_WATCHDOG=m
 CONFIG_MESON_WATCHDOG=m
 CONFIG_MFD_EXYNOS_LPASS=m
+CONFIG_MFD_HI6421V530_PMIC=y
 CONFIG_MFD_MAX77620=y
 CONFIG_MFD_RK808=y
 CONFIG_MFD_SPMI_PMIC=y
@@ -315,6 +316,7 @@ CONFIG_MFD_CROS_EC=y
 CONFIG_MFD_CROS_EC_I2C=y
 CONFIG_REGULATOR_FIXED_VOLTAGE=y
 CONFIG_REGULATOR_GPIO=y
+CONFIG_REGULATOR_HI6421V530=y
 CONFIG_REGULATOR_HI655X=y
 CONFIG_REGULATOR_MAX77620=y
 CONFIG_REGULATOR_PWM=y
-- 
2.10.2



[PATCH 1/6] dt-bindings: mfd: Add hi6421v530 bindings

2017-05-26 Thread Guodong Xu
DT bindings for hisilicon HI655x PMIC chip.

Signed-off-by: Guodong Xu 
---
 .../bindings/mfd/hisilicon,hi6421v530.txt  | 25 ++
 1 file changed, 25 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mfd/hisilicon,hi6421v530.txt

diff --git a/Documentation/devicetree/bindings/mfd/hisilicon,hi6421v530.txt 
b/Documentation/devicetree/bindings/mfd/hisilicon,hi6421v530.txt
new file mode 100644
index 000..6ffe6f6
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/hisilicon,hi6421v530.txt
@@ -0,0 +1,25 @@
+Hisilicon Hi6421v530 Power Management Integrated Circuit (PMIC)
+
+The hardware layout for access PMIC Hi6421v530 from AP SoC Hi3660.
+Between PMIC Hi6421v530 and Hi3660, the physical signal channel is SSI.
+We can use memory-mapped I/O to communicate.
+
+++ +-+
+|| | |
+|Hi3660  |   SSI bus   |  Hi6421v530 |
+||-| |
+||(REGMAP_MMIO)| |
+++ +-+
+
+Required properties:
+- compatible:   Should be "hisilicon,hi6421v530-pmic".
+- reg:  Base address of PMIC on Hi3660 SoC.
+- interrupt-controller: Hi6421v530 has internal IRQs (has own IRQ domain).
+
+Example:
+   pmic: pmic@fff34000 {
+   compatible = "hisilicon,hi6421v530-pmic";
+   reg = <0x0 0xfff34000 0x0 0x1000>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   }
-- 
2.10.2



[PATCH 2/6] mfd: hi6421-pmic: move hi6421_regmap_config definition to header file

2017-05-26 Thread Guodong Xu
Move hi6421_regmap_config definition from c code to common header:
 - include/linux/mfd/hi6421-pmic.h

This is to improve code re-use for upcoming hi6421 series of MFD driver.

Signed-off-by: Guodong Xu 
---
 drivers/mfd/hi6421-pmic-core.c  | 7 ---
 include/linux/mfd/hi6421-pmic.h | 6 ++
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/mfd/hi6421-pmic-core.c b/drivers/mfd/hi6421-pmic-core.c
index 3fd703f..dc1b5cf 100644
--- a/drivers/mfd/hi6421-pmic-core.c
+++ b/drivers/mfd/hi6421-pmic-core.c
@@ -35,13 +35,6 @@ static const struct mfd_cell hi6421_devs[] = {
{ .name = "hi6421-regulator", },
 };
 
-static const struct regmap_config hi6421_regmap_config = {
-   .reg_bits = 32,
-   .reg_stride = 4,
-   .val_bits = 8,
-   .max_register = HI6421_REG_TO_BUS_ADDR(HI6421_REG_MAX),
-};
-
 static int hi6421_pmic_probe(struct platform_device *pdev)
 {
struct hi6421_pmic *pmic;
diff --git a/include/linux/mfd/hi6421-pmic.h b/include/linux/mfd/hi6421-pmic.h
index 587273e..f4674ff 100644
--- a/include/linux/mfd/hi6421-pmic.h
+++ b/include/linux/mfd/hi6421-pmic.h
@@ -38,4 +38,10 @@ struct hi6421_pmic {
struct regmap   *regmap;
 };
 
+static const struct regmap_config hi6421_regmap_config = {
+   .reg_bits = 32,
+   .reg_stride = 4,
+   .val_bits = 8,
+   .max_register = HI6421_REG_TO_BUS_ADDR(HI6421_REG_MAX),
+};
 #endif /* __HI6421_PMIC_H */
-- 
2.10.2



RE: [PATCH] pinctrl/amd: Use regular interrupt instead of chained

2017-05-26 Thread Thomas Gleixner
Nehal,

On Fri, 26 May 2017, Shah, Nehal-bakulchandra wrote:
> Thanks for the patch. However, we have received this issue from multiple
> people and different disro but it occurs only on Gigabyte hardware. With
> reference AM4 ryzen board we are not facing this issue.  We are in
> discussion with gigabyte to check the BIOS part. Once we have clarity on
> that, we can consider driver part. Also, this code is running on multiple
> platform of different customers so changing directly at this point of
> time may be risky in my point of view. Requesting you to hold this patch
> till we get clarity on bios end.

It does not matter at all whether this is a problem only on GB
hardware. Fact is, that this happened and it will happen again.

The patch does not change any functionality of the driver, it merily makes
it more robust and spares users the bloody annoying experience of a non
booting machine and the tedious task of figuring out why.

The main objective of the kernel is robustness and not pleasing the ego of
silicon vendors. We can't prevent the stupidity of BIOS people, we merily
can deal with it.

That patch should go into mainline ASAP and backported to stable in order
to help those people who bought wreckaged hardware.

Thanks,

tglx


Re: [PATCH 00/21] liblockdep fixes for v4.12

2017-05-26 Thread Ingo Molnar

* Levin, Alexander (Sasha Levin)  wrote:

>  MAINTAINERS|   2 +-
>  tools/Makefile |   8 +++--
>  tools/include/linux/bitops.h   |  10 ++
>  tools/include/linux/err.h  |   5 +++
>  tools/include/linux/jhash.h| 175 
> +++
>  tools/include/linux/sched/clock.h  |   0
>  tools/include/linux/sched/mm.h |   0
>  tools/include/linux/sched/task.h   |   0
>  tools/include/linux/unaligned/packed_struct.h  |  46 
> +++
>  tools/lib/lockdep/Makefile |   9 +++---
>  tools/lib/lockdep/lockdep.c|  17 ++
>  tools/lib/lockdep/preload.c|   3 +-
>  tools/lib/lockdep/run_tests.sh |   8 ++---
>  tools/lib/lockdep/uinclude/linux/bitops.h  |   3 --
>  tools/lib/lockdep/uinclude/linux/compiler.h|   2 ++
>  tools/lib/lockdep/uinclude/linux/debug_locks.h |   2 +-
>  tools/lib/lockdep/uinclude/linux/irqflags.h|   8 ++---
>  tools/lib/lockdep/uinclude/linux/kallsyms.h|   3 +-
>  tools/lib/lockdep/uinclude/linux/kernel.h  |  20 ++--
>  tools/lib/lockdep/uinclude/linux/lockdep.h |  26 
>  tools/lib/lockdep/uinclude/linux/module.h  |   5 +++
>  tools/lib/lockdep/uinclude/linux/rcu.h |   2 ++
>  22 files changed, 317 insertions(+), 37 deletions(-)
>  create mode 100644 tools/include/linux/jhash.h
>  create mode 100644 tools/include/linux/sched/clock.h
>  create mode 100644 tools/include/linux/sched/mm.h
>  create mode 100644 tools/include/linux/sched/task.h
>  create mode 100644 tools/include/linux/unaligned/packed_struct.h
>  delete mode 100644 tools/lib/lockdep/uinclude/linux/bitops.h

Yeah, so what needs to be fixed as well is for liblockdep to exclusively use 
tools/include/ (and extend those headers where required).

perf already uses that method and it works well.

liblockdep already uses tools/include/ in part, but even after I apply all your 
patches, there's still lib/lockdep/uinclude/ which appears to duplicate a 
number 
of headers.

I did a quick check - for example WARN_ON() et al is duplicated in 
tools/lib/lockdep/uinclude/linux/kernel.h.

Thanks,

Ingo


Re: [PATCH 01/15] liblockdep: Fix undefined symbol prandom_u32

2017-05-26 Thread Ingo Molnar

* Levin, Alexander (Sasha Levin)  wrote:

> On Wed, May 24, 2017 at 09:53:37AM +0200, Ingo Molnar wrote:
> > 
> > So I'm not sure how you sent these patches, but probably due to the lack of 
> > a 
> > boilerplate message, the order was all mixed up. I got the patch order 
> > right on 
> > the third attempt.
> > 
> > But then I encountered this build failure (when applied to Linus's latest 
> > tree):
> > 
> > triton:~/tip/tools/lib/lockdep> make
> >   CC   common.o
> >   CC   lockdep.o
> > In file included from lockdep.c:25:0:
> > ../../../kernel/locking/lockdep.c:33:28: fatal error: linux/sched/mm.h: No 
> > such 
> > file or directory
> >  #include 
> > ^
> 
> Heh, apparently a bunch of stuff changed between the point when I sent my
> original pull request and now... I'll resend with additional fixes.

Yeah, and also note that this is v4.13 material at best - liblockdep broke a 
long 
time ago so it falls under 'development', not 'regression fixes'.

Thanks,

Ingo


Re: [PATCH 7/7] DWARF: add the config option

2017-05-26 Thread Jiri Slaby
On 05/19/2017, 11:35 PM, Josh Poimboeuf wrote:
>   
> https://github.com/jpoimboe/linux/blob/undwarf/arch/x86/kernel/unwind_undwarf.c

JFYI, it crashes in sha1_transform_avx due to crypto changes. You
perhaps missed that this beast uses ebp (not rbp) register for
computations. I had to do:

--- a/arch/x86/crypto/sha1_ssse3_asm.S
+++ b/arch/x86/crypto/sha1_ssse3_asm.S
@@ -37,7 +37,7 @@
 #define REG_A  %ecx
 #define REG_B  %esi
 #define REG_C  %edi
-#define REG_D  %ebp
+#define REG_D  %r12d
 #define REG_E  %edx

 #define REG_T1 %eax
@@ -74,6 +74,7 @@
SYM_FUNC_START(\name)

push%rbx
+   push%r12
push%rbp

mov %rsp, %rbp
@@ -99,6 +100,7 @@
rep stosq

leaveq  # deallocate workspace
+   pop %r12
pop %rbx
ret


I am afraid there are more of these, e.g. in aesni-intel_asm.S.

thanks,
-- 
js
suse labs


Re: [patch V3 00/32] cpu/hotplug: Convert get_online_cpus() to a percpu_rwsem

2017-05-26 Thread Ingo Molnar

* Thomas Gleixner  wrote:

> get_online_cpus() is used in hot pathes in mainline and even more so in
> RT. That can show up badly under certain conditions because every locker
> contends on a global mutex. RT has it's own homebrewn mitigation which is
> a (badly done) open coded implementation of percpu_rwsems with recursion
> support.
> 
> The proper replacement for that are percpu_rwsems, but that requires to
> remove recursion support.
> 
> The conversion unearthed real locking issues which were previously not
> visible because the get_online_cpus() lockdep annotation was implemented
> with recursion support which prevents lockdep from tracking full dependency
> chains. These potential deadlocks are not related to recursive calls, they
> trigger on the first invocation because lockdep now has the full dependency
> chains available.
> 
> The following patch series addresses this by
> 
>  - Cleaning up places which call get_online_cpus() nested
> 
>  - Replacing a few instances with cpu_hotplug_disable() to prevent circular
>locking dependencies.
> 
> The series is on top of 4.12-rc2. It's available in git from
> 
>git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git WIP.hotplug
> 
> Changes since V2:
> 
>   - Reworked the approach vs. perf/ftrace/kprobes, which simplified the lot
>   
>   - Renamed get_online_cpus() to cpus_read_lock() to reflect the nature of
> the interface
> 
>   - Link the lockchains between hotplug control task and per cpu hotplug
> threads and fixed the fallout of that.
> 
> Thanks,
> 
> tglx
> 
> ---
>  arch/arm/kernel/hw_breakpoint.c   |   11 -
>  arch/arm/kernel/patch.c   |2 
>  arch/arm/probes/kprobes/core.c|3 
>  arch/arm64/include/asm/insn.h |1 
>  arch/arm64/kernel/insn.c  |5 
>  arch/mips/kernel/jump_label.c |2 
>  arch/powerpc/kvm/book3s_hv.c  |   14 -
>  arch/powerpc/platforms/powernv/subcore.c  |7 
>  arch/s390/kernel/jump_label.c |2 
>  arch/s390/kernel/kprobes.c|4 
>  arch/s390/kernel/time.c   |6 
>  arch/x86/events/core.c|1 
>  arch/x86/events/intel/cqm.c   |   16 -
>  arch/x86/kernel/cpu/mtrr/main.c   |2 
>  b/arch/sparc/kernel/jump_label.c  |2 
>  b/arch/tile/kernel/jump_label.c   |2 
>  b/arch/x86/events/intel/core.c|   11 -
>  b/arch/x86/kernel/jump_label.c|2 
>  b/kernel/jump_label.c |   20 +-
>  drivers/acpi/processor_driver.c   |4 
>  drivers/acpi/processor_throttling.c   |   16 -
>  drivers/cpufreq/cpufreq.c |   21 +-
>  drivers/hwtracing/coresight/coresight-etm3x.c |   20 +-
>  drivers/hwtracing/coresight/coresight-etm4x.c |   20 +-
>  drivers/pci/pci-driver.c  |   47 +++--
>  include/linux/cpu.h   |   34 ++--
>  include/linux/cpuhotplug.h|   38 
>  include/linux/padata.h|3 
>  include/linux/pci.h   |1 
>  include/linux/perf_event.h|2 
>  include/linux/sched.h |   10 +
>  include/linux/stop_machine.h  |   26 ++-
>  kernel/cpu.c  |  213 
> +++---
>  kernel/events/core.c  |  106 +---
>  kernel/kprobes.c  |   59 +++
>  kernel/padata.c   |   43 ++---
>  kernel/stop_machine.c |   11 -
>  37 files changed, 444 insertions(+), 343 deletions(-)

Very nice work!

Modulo the open question about perf that Paul noticed:

Acked-by: Ingo Molnar 

Thanks,

Ingo


[ANNOUNCE] autofs 5.1.3 release

2017-05-26 Thread Ian Kent
Hi all,

It's time for a new release, autofs-5.1.3.

Of particular interest is the addition browse support for amd format
maps.

The browsable_dirs configuration option can be set to either "yes" or
"no" and the pseudo option "browsable" can be used as an option of
mount type "auto" mounts.

Note that the browsable_dirs "full" option and the mount type auto
"fullybrowsabe" option, mostly used for map debugging, cannot be
provided by autofs.

Related changes are the removal of the requirement to include entries
for amd format maps in the master map. The optional amd format map
 mount sections may be used without adding these entries, in the same
way these sections are used in the amd configuration.

This prevents the need to include potentially incompatible entries in
shared master maps in multi-vendor environments.

Something to watch out for is that autofs is no longer tolerant of
misconfigured nsswitch "automount:" entries. If nsswitch sources that
aren't configured are present it can lead to an unconditional 10
second delay at startup with some unexpected log errors. autofs is
probably not going to interfere with nsswitch.conf because it is not
the owner of the file so it needs to be set correctly by people using
autofs. This will often mean just removing the inappropriate "nisplus"
source present in the default installed nsswitch.conf. 

There's two added configuration parameters which hopefully will help
with map source availability problems at startup.

The "master_wait" configuration option (default 10 seconds) will retry
reading the master map for the configured time when certain errors are
encountered (the reason misconfigured nsswitch configurations cause a
delay).

And the option "sss_master_map_wait" (default 0, disabled) has been
added specifically for the sss source. This option may be needed
because the error returned when sss is not yet available to answer
queries can't be distinguished from a real "map does not exist" return.
The default of disabled is because the sss source not being ready
problem has already be resolved in recent versions of sss itself.

Additionally there a number of bug fixes and small improvements.

autofs
==

The package can be found at:
https://www.kernel.org/pub/linux/daemons/autofs/v5/

It is autofs-5.1.3.tar.[gz|xz]

No source rpm is there as it can be produced by using:

rpmbuild -ts autofs-5.1.3.tar.gz

and the binary rpm by using:

rpmbuild -tb autofs-5.1.3.tar.gz

See the README.amd-maps file for information about using amd format
maps.

Here are the entries from the CHANGELOG which outline the updates:

24/05/2016 autofs-5.1.3
===
- fix release date in CHANGELOG.
- build: check for clock_gettime in librt.
- fix compiler warning in try_remount().
- drop redundant \n in logerr().
- Fix size arg of fgets(3).
- fix libtirpc detection with -Wl,--as-needed.
- Fix a typo in CREDITS.
- Change .requestor to .requester for consistency.
- fix file map changed check.
- Remove unused local 2KB buffer.
- Fix typos in error messages.
- Fix fgets(3) size argument (another one).
- fix short memory allocation in lookup_amd_instance().
- fix count_mounts() function.
- configure: add cache variable for Linux proc filesystem check.
- Avoid local variable name shadowing another.
- fix typo in MOUNT_FLAG_GHOST comment.
- fix cachefs parse message not being logged.
- fix argc off by one in mount_autofs.c.
- fix _strncmp() usage.
- fix create_client() RPC client handling.
- update and add README for old autofs schema.
- wait for master map available at start.
- add master read wait option.
- work around sss startup delay.
- add sss master map wait config option.
- fix quoted key handling in sanitize_path().
- fix included master map not found return.
- dont exit on master map read fail timeout.
- set sane default master read wait timeout.
- don't return until after master map retry read.
- make lookup_nss_read_master() return nss status.
- check NFS server availability on local mount fallback.
- check NFS server availability on local mount fallback.
- make set_direct_mount_catatonic() more general.
- set autofs mounts catatonic at exit.
- honor last rw in mount options when doing a bind mount.
- fix typos in README.amd-maps.
- add ref counting to struct map_source.
- add support for amd browsable option.
- add function conf_amd_get_map_name().
- add function conf_amd_get_mount_paths().
- include amd mount sections mounts in master mounts list.
- check for conflicting amd section mounts.
- add function conf_get_map_options().
- capture cache option and its settings during parsing.
- handle map_option cache for top level mounts.
- handle amd cache option all in amd type auto mounts.
- fix bogus check in expire_cleanup().
- delay submount exit for amd submounts.
- add the mount requestor's pid to pending_args.
- create thread-local ID for mount attempts.
- log functions to prefix messages with attempt_id if available.
- factor out 

Re: [PATCH] KVM: x86: dynamically allocate large struct in em_fxrstor

2017-05-26 Thread Paolo Bonzini


On 26/05/2017 06:13, Nick Desaulniers wrote:
> On Thu, May 25, 2017 at 04:07:08PM +0200, Paolo Bonzini wrote:
>> I think we should do the fixup backwards.
>>
>> That is:
>>
>> - first do get_fpu
>>
>> - if the fixup is necessary, i.e. ctxt->mode < X86EMUL_MODE_PROT64, do
>> fxsave into 
>>
>> - then do segmented_read_std with the correct size, which is
>>   - offsetof(struct fxregs_state, xmm_space[16]), i.e. 416
>> if ctxt->mode == X86EMUL_MODE_PROT64
>>   - offsetof(struct fxregs_state, xmm_space[8]), i.e. 288
>> if ctxt->mode < X86EMUL_MODE_PROT64 and CR4.OSFXSR=1
>>   - offsetof(struct fxregs_state, xmm_space[0]), i.e. 160
>> if ctxt->mode < X86EMUL_MODE_PROT64 and CR4.OSFXSR=0
> 
> but we still want to do a segmented_read_std with size 512 otherwise,
> correct?

No, 512 is never necessary.  ctxt->mode is never > X86EMUL_MODE_PROT64
(see the definition of enum x86emul_mode in
arch/x86/include/asm/kvm_emulate.h.

>> - then check fx_state.mxcsr
>>
>> - then do fxrstor
> 
> This sounds like we conditionally do the fxsave, but then always do the
> fxrstor.  Is that ok? I guess the original code kind of does that as
> well.

Correct.  They idea is that fxrstor on Linux always accesses 416 bytes,
but we may have to restore only the first part for accurate emulation.
The fxsave retrieves the current state so that we can leave it
unmodified when we do fxrstor.

>> - finally do put_fpu
> 
> Sounds straight forward.  I can see how fxsave and CR4.OSFXSR are
> accessed in fxstor_fixup.  Is it ok to skip those memcpy's that would
> otherwise occur when calling fxrstor_fixup() (which after these changes,
> we would not be)?

Yes, the memcpys are replaced with a shorter segmented_read_std.

Thanks,

Paolo


[PATCH v2 1/4] pinctrl: rockchip: Add iomux-route switching support

2017-05-26 Thread David Wu
On the some rockchip SOCS, some things like rk3399 specific uart2 can use
multiple pins. Somewhere between the pin io-cells and the uart it seems
to have some sort of switch to decide to which pin to actually route the
data.

+---+++  /- GPIO4_B0 (pinmux 2)

| uart2 | -- | switch | --- GPIO4_C0 (pinmux 2)

+---+++  \- GPIO4_C3 (pinmux 2)
(switch selects one of the 3 pins base on the GRF_SOC_CON7[BIT0, BIT1])

The routing switch is determined by one pin of a specific group to be set
to its special pinmux function. If the pinmux setting is wrong for that
pin the ip block won't work correctly anyway.

Signed-off-by: David Wu 
---
 drivers/pinctrl/pinctrl-rockchip.c | 65 +-
 1 file changed, 64 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-rockchip.c 
b/drivers/pinctrl/pinctrl-rockchip.c
index f141aa0..a5d7177 100644
--- a/drivers/pinctrl/pinctrl-rockchip.c
+++ b/drivers/pinctrl/pinctrl-rockchip.c
@@ -146,6 +146,7 @@ struct rockchip_drv {
  * @irq_lock: bus lock for irq chip
  * @new_irqs: newly configured irqs which must be muxed as GPIOs in
  * irq_bus_sync_unlock()
+ * @route_mask: bits describing the routing pins of per bank
  */
 struct rockchip_pin_bank {
void __iomem*reg_base;
@@ -170,6 +171,7 @@ struct rockchip_pin_bank {
u32 toggle_edge_mode;
struct mutexirq_lock;
u32 new_irqs;
+   u32 route_mask;
 };
 
 #define PIN_BANK(id, pins, label)  \
@@ -293,6 +295,22 @@ struct rockchip_pin_bank {
}
 
 /**
+ * struct rockchip_mux_recalced_data: represent a pin iomux data.
+ * @bank_num: bank number.
+ * @pin: index at register or used to calc index.
+ * @func: the min pin.
+ * @route_offset: the max pin.
+ * @route_val: the register offset.
+ */
+struct rockchip_mux_route_data {
+   u8 bank_num;
+   u8 pin;
+   u8 func;
+   u32 route_offset;
+   u32 route_val;
+};
+
+/**
  */
 struct rockchip_pin_ctrl {
struct rockchip_pin_bank*pin_banks;
@@ -304,6 +322,8 @@ struct rockchip_pin_ctrl {
int pmu_mux_offset;
int grf_drv_offset;
int pmu_drv_offset;
+   struct rockchip_mux_route_data *iomux_routes;
+   u32 niomux_routes;
 
void(*pull_calc_reg)(struct rockchip_pin_bank *bank,
int pin_num, struct regmap **regmap,
@@ -585,6 +605,30 @@ static void rk3328_recalc_mux(u8 bank_num, int pin, int 
*reg,
*bit = data->bit;
 }
 
+static bool rockchip_get_mux_route(struct rockchip_pin_bank *bank, int pin,
+  int mux, u32 *reg, u32 *value)
+{
+   struct rockchip_pinctrl *info = bank->drvdata;
+   struct rockchip_pin_ctrl *ctrl = info->ctrl;
+   struct rockchip_mux_route_data *data;
+   int i;
+
+   for (i = 0; i < ctrl->niomux_routes; i++) {
+   data = >iomux_routes[i];
+   if ((data->bank_num == bank->bank_num) &&
+   (data->pin == pin) && (data->func == mux))
+   break;
+   }
+
+   if (i >= ctrl->niomux_routes)
+   return false;
+
+   *reg = data->route_offset;
+   *value = data->route_val;
+
+   return true;
+}
+
 static int rockchip_get_mux(struct rockchip_pin_bank *bank, int pin)
 {
struct rockchip_pinctrl *info = bank->drvdata;
@@ -683,7 +727,7 @@ static int rockchip_set_mux(struct rockchip_pin_bank *bank, 
int pin, int mux)
struct regmap *regmap;
int reg, ret, mask, mux_type;
u8 bit;
-   u32 data, rmask;
+   u32 data, rmask, route_reg, route_val;
 
ret = rockchip_verify_mux(bank, pin, mux);
if (ret < 0)
@@ -719,6 +763,15 @@ static int rockchip_set_mux(struct rockchip_pin_bank 
*bank, int pin, int mux)
if (ctrl->iomux_recalc && (mux_type & IOMUX_RECALCED))
ctrl->iomux_recalc(bank->bank_num, pin, , , );
 
+   if (bank->route_mask & BIT(pin)) {
+   if (rockchip_get_mux_route(bank, pin, mux, _reg,
+  _val)) {
+   ret = regmap_write(regmap, route_reg, route_val);
+   if (ret)
+   return ret;
+   }
+   }
+
data = (mask << (bit + 16));
rmask = data | (data >> 16);
data |= (mux & mask) << bit;
@@ -2585,6 +2638,16 @@ static struct rockchip_pin_ctrl 
*rockchip_pinctrl_get_soc_data(
 
bank_pins += 8;
}
+
+   /* calculate the per-bank route_mask */
+   for (j = 0; j < ctrl->niomux_routes; j++) {
+   int pin = 0;
+
+   if 

[PATCH v2 2/4] pinctrl: rockchip: Add iomux-route switching support for rk3228

2017-05-26 Thread David Wu
There are 9 IP blocks pin routes need to be switched, that are
pwm-0, pwm-1, pwm-2, pwm-3, sdio, spi, emmc, uart2, uart1.

Signed-off-by: David Wu 
---
Change in v2:
 - calculate the per-bank value dynamically (Heiko)
 
 drivers/pinctrl/pinctrl-rockchip.c | 132 +
 1 file changed, 132 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-rockchip.c 
b/drivers/pinctrl/pinctrl-rockchip.c
index a5d7177..605e24e 100644
--- a/drivers/pinctrl/pinctrl-rockchip.c
+++ b/drivers/pinctrl/pinctrl-rockchip.c
@@ -605,6 +605,136 @@ static void rk3328_recalc_mux(u8 bank_num, int pin, int 
*reg,
*bit = data->bit;
 }
 
+static struct rockchip_mux_route_data rk3228_mux_route_data[] = {
+   {
+   /* pwm0-0 */
+   .bank_num = 0,
+   .pin = 26,
+   .func = 1,
+   .route_offset = 0x50,
+   .route_val = BIT(16),
+   }, {
+   /* pwm0-1 */
+   .bank_num = 3,
+   .pin = 21,
+   .func = 1,
+   .route_offset = 0x50,
+   .route_val = BIT(16) | BIT(0),
+   }, {
+   /* pwm1-0 */
+   .bank_num = 0,
+   .pin = 27,
+   .func = 1,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 1),
+   }, {
+   /* pwm1-1 */
+   .bank_num = 0,
+   .pin = 30,
+   .func = 2,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 1) | BIT(1),
+   }, {
+   /* pwm2-0 */
+   .bank_num = 0,
+   .pin = 28,
+   .func = 1,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 2),
+   }, {
+   /* pwm2-1 */
+   .bank_num = 1,
+   .pin = 12,
+   .func = 2,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 2) | BIT(2),
+   }, {
+   /* pwm3-0 */
+   .bank_num = 3,
+   .pin = 26,
+   .func = 1,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 3),
+   }, {
+   /* pwm3-1 */
+   .bank_num = 1,
+   .pin = 11,
+   .func = 2,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 3) | BIT(3),
+   }, {
+   /* sdio-0_d0 */
+   .bank_num = 1,
+   .pin = 1,
+   .func = 1,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 4),
+   }, {
+   /* sdio-1_d0 */
+   .bank_num = 3,
+   .pin = 2,
+   .func = 1,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 4) | BIT(4),
+   }, {
+   /* spi-0_rx */
+   .bank_num = 0,
+   .pin = 13,
+   .func = 2,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 5),
+   }, {
+   /* spi-1_rx */
+   .bank_num = 2,
+   .pin = 0,
+   .func = 2,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 5) | BIT(5),
+   }, {
+   /* emmc-0_cmd */
+   .bank_num = 1,
+   .pin = 22,
+   .func = 2,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 7),
+   }, {
+   /* emmc-1_cmd */
+   .bank_num = 2,
+   .pin = 4,
+   .func = 2,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 7) | BIT(7),
+   }, {
+   /* uart2-0_rx */
+   .bank_num = 1,
+   .pin = 19,
+   .func = 2,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 8),
+   }, {
+   /* uart2-1_rx */
+   .bank_num = 1,
+   .pin = 10,
+   .func = 2,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 8) | BIT(8),
+   }, {
+   /* uart1-0_rx */
+   .bank_num = 1,
+   .pin = 10,
+   .func = 1,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 11),
+   }, {
+   /* uart1-1_rx */
+   .bank_num = 3,
+   .pin = 13,
+   .func = 1,
+   .route_offset = 0x50,
+   .route_val = BIT(16 + 11) | BIT(11),
+   },
+};
+
 static bool rockchip_get_mux_route(struct rockchip_pin_bank *bank, int pin,
   int mux, u32 *reg, u32 *value)
 {
@@ -2898,6 +3028,8 @@ static int rockchip_pinctrl_probe(struct platform_device 
*pdev)
.label  = "RK3228-GPIO",
.type   = RK3288,
.grf_mux_offset = 0x0,
+   

[PATCH v2 4/4] pinctrl: rockchip: Add iomux-route switching support for rk3399

2017-05-26 Thread David Wu
There are 2 IP blocks pin routes need to be switched, that are
uart2dbg, pcie_clkreq.

Signed-off-by: David Wu 
---
Change in v2:
 - calculate the per-bank value dynamically (Heiko)

 drivers/pinctrl/pinctrl-rockchip.c | 41 ++
 1 file changed, 41 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-rockchip.c 
b/drivers/pinctrl/pinctrl-rockchip.c
index 2563959..6690883 100644
--- a/drivers/pinctrl/pinctrl-rockchip.c
+++ b/drivers/pinctrl/pinctrl-rockchip.c
@@ -816,6 +816,45 @@ static void rk3328_recalc_mux(u8 bank_num, int pin, int 
*reg,
},
 };
 
+static struct rockchip_mux_route_data rk3399_mux_route_data[] = {
+   {
+   /* uart2dbga_rx */
+   .bank_num = 4,
+   .pin = 8,
+   .func = 2,
+   .route_offset = 0xe21c,
+   .route_val = BIT(16 + 10) | BIT(16 + 11),
+   }, {
+   /* uart2dbgb_rx */
+   .bank_num = 4,
+   .pin = 16,
+   .func = 2,
+   .route_offset = 0xe21c,
+   .route_val = BIT(16 + 10) | BIT(16 + 11) | BIT(10),
+   }, {
+   /* uart2dbgc_rx */
+   .bank_num = 4,
+   .pin = 19,
+   .func = 1,
+   .route_offset = 0xe21c,
+   .route_val = BIT(16 + 10) | BIT(16 + 11) | BIT(11),
+   }, {
+   /* pcie_clkreqn */
+   .bank_num = 2,
+   .pin = 26,
+   .func = 2,
+   .route_offset = 0xe21c,
+   .route_val = BIT(16 + 14),
+   }, {
+   /* pcie_clkreqnb */
+   .bank_num = 4,
+   .pin = 24,
+   .func = 1,
+   .route_offset = 0xe21c,
+   .route_val = BIT(16 + 14) | BIT(14),
+   },
+};
+
 static bool rockchip_get_mux_route(struct rockchip_pin_bank *bank, int pin,
   int mux, u32 *reg, u32 *value)
 {
@@ -3270,6 +3309,8 @@ static int rockchip_pinctrl_probe(struct platform_device 
*pdev)
.pmu_mux_offset = 0x0,
.grf_drv_offset = 0xe100,
.pmu_drv_offset = 0x80,
+   .iomux_routes   = rk3399_mux_route_data,
+   .niomux_routes  = ARRAY_SIZE(rk3399_mux_route_data),
.pull_calc_reg  = rk3399_calc_pull_reg_and_bit,
.drv_calc_reg   = rk3399_calc_drv_reg_and_bit,
 };
-- 
1.9.1




Re: [PATCH 2/6] mfd: hi6421-pmic: move hi6421_regmap_config definition to header file

2017-05-26 Thread Arnd Bergmann
On Fri, May 26, 2017 at 8:35 AM, Guodong Xu  wrote:
> Move hi6421_regmap_config definition from c code to common header:
>  - include/linux/mfd/hi6421-pmic.h
>
> This is to improve code re-use for upcoming hi6421 series of MFD driver.
>
> Signed-off-by: Guodong Xu 

> diff --git a/include/linux/mfd/hi6421-pmic.h b/include/linux/mfd/hi6421-pmic.h
> index 587273e..f4674ff 100644
> --- a/include/linux/mfd/hi6421-pmic.h
> +++ b/include/linux/mfd/hi6421-pmic.h
> @@ -38,4 +38,10 @@ struct hi6421_pmic {
> struct regmap   *regmap;
>  };
>
> +static const struct regmap_config hi6421_regmap_config = {
> +   .reg_bits = 32,
> +   .reg_stride = 4,
> +   .val_bits = 8,
> +   .max_register = HI6421_REG_TO_BUS_ADDR(HI6421_REG_MAX),
> +};
>  #endif /* __HI6421_PMIC_H */

Header files should not have static variables in general, it will cause warnings
about unused variables when you include the header from another file
(depending on compiler version and warning options, I think older gcc
versions don't warn about this, but clang and latest gcc do).

How about adding the new code into the existing
drivers/mfd/hi6421-pmic-core.c file, and splitting out the part that differs
(the regmap_update_bits is the only difference I see) into a callback
that you reference through the of_device_id->data pointer?

Arnd


[tip:smp/hotplug] hwtracing/coresight-etm3x: Use cpuhp_setup_state_nocalls_cpuslocked()

2017-05-26 Thread tip-bot for Sebastian Andrzej Siewior
Commit-ID:  e560c89c8ac0baadf0da351f602c599016568fc7
Gitweb: http://git.kernel.org/tip/e560c89c8ac0baadf0da351f602c599016568fc7
Author: Sebastian Andrzej Siewior 
AuthorDate: Wed, 24 May 2017 10:15:22 +0200
Committer:  Thomas Gleixner 
CommitDate: Fri, 26 May 2017 10:10:39 +0200

hwtracing/coresight-etm3x: Use cpuhp_setup_state_nocalls_cpuslocked()

etm_probe() holds get_online_cpus() while invoking
cpuhp_setup_state_nocalls().

cpuhp_setup_state_nocalls() invokes get_online_cpus() as well. This is
correct, but prevents the conversion of the hotplug locking to a percpu
rwsem.

Use cpuhp_setup_state_nocalls_cpuslocked() to avoid the nested
call. Convert *_online_cpus() to the new interfaces while at it.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Acked-by: Ingo Molnar 
Acked-by: Mathieu Poirier 
Cc: Paul E. McKenney 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: linux-arm-ker...@lists.infradead.org
Link: http://lkml.kernel.org/r/20170524081547.889092...@linutronix.de

---
 drivers/hwtracing/coresight/coresight-etm3x.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c 
b/drivers/hwtracing/coresight/coresight-etm3x.c
index a51b6b6..93ee8fc 100644
--- a/drivers/hwtracing/coresight/coresight-etm3x.c
+++ b/drivers/hwtracing/coresight/coresight-etm3x.c
@@ -587,7 +587,7 @@ static void etm_disable_sysfs(struct coresight_device 
*csdev)
 * after cpu online mask indicates the cpu is offline but before the
 * DYING hotplug callback is serviced by the ETM driver.
 */
-   get_online_cpus();
+   cpus_read_lock();
spin_lock(>spinlock);
 
/*
@@ -597,7 +597,7 @@ static void etm_disable_sysfs(struct coresight_device 
*csdev)
smp_call_function_single(drvdata->cpu, etm_disable_hw, drvdata, 1);
 
spin_unlock(>spinlock);
-   put_online_cpus();
+   cpus_read_unlock();
 
dev_info(drvdata->dev, "ETM tracing disabled\n");
 }
@@ -795,7 +795,7 @@ static int etm_probe(struct amba_device *adev, const struct 
amba_id *id)
 
drvdata->cpu = pdata ? pdata->cpu : 0;
 
-   get_online_cpus();
+   cpus_read_lock();
etmdrvdata[drvdata->cpu] = drvdata;
 
if (smp_call_function_single(drvdata->cpu,
@@ -803,17 +803,17 @@ static int etm_probe(struct amba_device *adev, const 
struct amba_id *id)
dev_err(dev, "ETM arch init failed\n");
 
if (!etm_count++) {
-   cpuhp_setup_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING,
- "arm/coresight:starting",
- etm_starting_cpu, etm_dying_cpu);
-   ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
-   "arm/coresight:online",
-   etm_online_cpu, NULL);
+   
cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ARM_CORESIGHT_STARTING,
+"arm/coresight:starting",
+etm_starting_cpu, 
etm_dying_cpu);
+   ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ONLINE_DYN,
+  
"arm/coresight:online",
+  etm_online_cpu, 
NULL);
if (ret < 0)
goto err_arch_supported;
hp_online = ret;
}
-   put_online_cpus();
+   cpus_read_unlock();
 
if (etm_arch_supported(drvdata->arch) == false) {
ret = -EINVAL;


[tip:smp/hotplug] perf/x86/intel/cqm: Use cpuhp_setup_state_cpuslocked()

2017-05-26 Thread tip-bot for Sebastian Andrzej Siewior
Commit-ID:  04b247c2ebdd6ba1c46c7c22546229a89760b43a
Gitweb: http://git.kernel.org/tip/04b247c2ebdd6ba1c46c7c22546229a89760b43a
Author: Sebastian Andrzej Siewior 
AuthorDate: Wed, 24 May 2017 10:15:24 +0200
Committer:  Thomas Gleixner 
CommitDate: Fri, 26 May 2017 10:10:40 +0200

perf/x86/intel/cqm: Use cpuhp_setup_state_cpuslocked()

intel_cqm_init() holds get_online_cpus() while registerring the hotplug
callbacks.

cpuhp_setup_state() invokes get_online_cpus() as well. This is correct, but
prevents the conversion of the hotplug locking to a percpu rwsem.

Use cpuhp_setup_state_cpuslocked() to avoid the nested call. Convert
*_online_cpus() to the new interfaces while at it.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Acked-by: Ingo Molnar 
Cc: Paul E. McKenney 
Cc: Fenghua Yu 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Link: http://lkml.kernel.org/r/20170524081548.075604...@linutronix.de

---
 arch/x86/events/intel/cqm.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/x86/events/intel/cqm.c b/arch/x86/events/intel/cqm.c
index 8c00dc0..2521f77 100644
--- a/arch/x86/events/intel/cqm.c
+++ b/arch/x86/events/intel/cqm.c
@@ -1682,7 +1682,7 @@ static int __init intel_cqm_init(void)
 *
 * Also, check that the scales match on all cpus.
 */
-   get_online_cpus();
+   cpus_read_lock();
for_each_online_cpu(cpu) {
struct cpuinfo_x86 *c = _data(cpu);
 
@@ -1746,14 +1746,14 @@ static int __init intel_cqm_init(void)
 * Setup the hot cpu notifier once we are sure cqm
 * is enabled to avoid notifier leak.
 */
-   cpuhp_setup_state(CPUHP_AP_PERF_X86_CQM_STARTING,
- "perf/x86/cqm:starting",
- intel_cqm_cpu_starting, NULL);
-   cpuhp_setup_state(CPUHP_AP_PERF_X86_CQM_ONLINE, "perf/x86/cqm:online",
- NULL, intel_cqm_cpu_exit);
-
+   cpuhp_setup_state_cpuslocked(CPUHP_AP_PERF_X86_CQM_STARTING,
+"perf/x86/cqm:starting",
+intel_cqm_cpu_starting, NULL);
+   cpuhp_setup_state_cpuslocked(CPUHP_AP_PERF_X86_CQM_ONLINE,
+"perf/x86/cqm:online",
+NULL, intel_cqm_cpu_exit);
 out:
-   put_online_cpus();
+   cpus_read_unlock();
 
if (ret) {
kfree(str);


[tip:smp/hotplug] cpufreq: Use cpuhp_setup_state_nocalls_cpuslocked()

2017-05-26 Thread tip-bot for Sebastian Andrzej Siewior
Commit-ID:  a92551e41d5a7b563ae440496bc5ca19d205231d
Gitweb: http://git.kernel.org/tip/a92551e41d5a7b563ae440496bc5ca19d205231d
Author: Sebastian Andrzej Siewior 
AuthorDate: Wed, 24 May 2017 10:15:20 +0200
Committer:  Thomas Gleixner 
CommitDate: Fri, 26 May 2017 10:10:38 +0200

cpufreq: Use cpuhp_setup_state_nocalls_cpuslocked()

cpufreq holds get_online_cpus() while invoking cpuhp_setup_state_nocalls()
to make subsys_interface_register() and the registration of hotplug calls
atomic versus cpu hotplug.

cpuhp_setup_state_nocalls() invokes get_online_cpus() as well. This is
correct, but prevents the conversion of the hotplug locking to a percpu
rwsem.

Use cpuhp_setup/remove_state_nocalls_cpuslocked() to avoid the nested
call. Convert *_online_cpus() to the new interfaces while at it.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Tested-by: Paul E. McKenney 
Acked-by: Ingo Molnar 
Acked-by: "Rafael J. Wysocki" 
Acked-by: Viresh Kumar 
Cc: linux...@vger.kernel.org
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Link: http://lkml.kernel.org/r/20170524081547.731628...@linutronix.de

---
 drivers/cpufreq/cpufreq.c | 21 +++--
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 0e3f649..6001369 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -887,7 +887,7 @@ static ssize_t store(struct kobject *kobj, struct attribute 
*attr,
struct freq_attr *fattr = to_attr(attr);
ssize_t ret = -EINVAL;
 
-   get_online_cpus();
+   cpus_read_lock();
 
if (cpu_online(policy->cpu)) {
down_write(>rwsem);
@@ -895,7 +895,7 @@ static ssize_t store(struct kobject *kobj, struct attribute 
*attr,
up_write(>rwsem);
}
 
-   put_online_cpus();
+   cpus_read_unlock();
 
return ret;
 }
@@ -2441,7 +2441,7 @@ int cpufreq_register_driver(struct cpufreq_driver 
*driver_data)
pr_debug("trying to register driver %s\n", driver_data->name);
 
/* Protect against concurrent CPU online/offline. */
-   get_online_cpus();
+   cpus_read_lock();
 
write_lock_irqsave(_driver_lock, flags);
if (cpufreq_driver) {
@@ -2473,9 +2473,10 @@ int cpufreq_register_driver(struct cpufreq_driver 
*driver_data)
goto err_if_unreg;
}
 
-   ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "cpufreq:online",
-   cpuhp_cpufreq_online,
-   cpuhp_cpufreq_offline);
+   ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ONLINE_DYN,
+  "cpufreq:online",
+  cpuhp_cpufreq_online,
+  cpuhp_cpufreq_offline);
if (ret < 0)
goto err_if_unreg;
hp_online = ret;
@@ -2493,7 +2494,7 @@ err_null_driver:
cpufreq_driver = NULL;
write_unlock_irqrestore(_driver_lock, flags);
 out:
-   put_online_cpus();
+   cpus_read_unlock();
return ret;
 }
 EXPORT_SYMBOL_GPL(cpufreq_register_driver);
@@ -2516,17 +2517,17 @@ int cpufreq_unregister_driver(struct cpufreq_driver 
*driver)
pr_debug("unregistering driver %s\n", driver->name);
 
/* Protect against concurrent cpu hotplug */
-   get_online_cpus();
+   cpus_read_lock();
subsys_interface_unregister(_interface);
remove_boost_sysfs_file();
-   cpuhp_remove_state_nocalls(hp_online);
+   cpuhp_remove_state_nocalls_cpuslocked(hp_online);
 
write_lock_irqsave(_driver_lock, flags);
 
cpufreq_driver = NULL;
 
write_unlock_irqrestore(_driver_lock, flags);
-   put_online_cpus();
+   cpus_read_unlock();
 
return 0;
 }


[tip:smp/hotplug] KVM/PPC/Book3S HV: Use cpuhp_setup_state_nocalls_cpuslocked()

2017-05-26 Thread tip-bot for Sebastian Andrzej Siewior
Commit-ID:  419af25fa4d0974fd758a668c08c369c19392a47
Gitweb: http://git.kernel.org/tip/419af25fa4d0974fd758a668c08c369c19392a47
Author: Sebastian Andrzej Siewior 
AuthorDate: Wed, 24 May 2017 10:15:21 +0200
Committer:  Thomas Gleixner 
CommitDate: Fri, 26 May 2017 10:10:39 +0200

KVM/PPC/Book3S HV: Use cpuhp_setup_state_nocalls_cpuslocked()

kvmppc_alloc_host_rm_ops() holds get_online_cpus() while invoking
cpuhp_setup_state_nocalls().

cpuhp_setup_state_nocalls() invokes get_online_cpus() as well. This is
correct, but prevents the conversion of the hotplug locking to a percpu
rwsem.

Use cpuhp_setup_state_nocalls_cpuslocked() to avoid the nested
call. Convert *_online_cpus() to the new interfaces while at it.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Acked-by: Ingo Molnar 
Cc: Paul E. McKenney 
Cc: k...@vger.kernel.org
Cc: Peter Zijlstra 
Cc: Benjamin Herrenschmidt 
Cc: Steven Rostedt 
Cc: kvm-...@vger.kernel.org
Cc: Michael Ellerman 
Cc: linuxppc-...@lists.ozlabs.org
Cc: Alexander Graf 
Link: http://lkml.kernel.org/r/20170524081547.809616...@linutronix.de

---
 arch/powerpc/kvm/book3s_hv.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 42b7a4f..48a6bd1 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -3317,7 +3317,7 @@ void kvmppc_alloc_host_rm_ops(void)
return;
}
 
-   get_online_cpus();
+   cpus_read_lock();
 
for (cpu = 0; cpu < nr_cpu_ids; cpu += threads_per_core) {
if (!cpu_online(cpu))
@@ -3339,17 +3339,17 @@ void kvmppc_alloc_host_rm_ops(void)
l_ops = (unsigned long) ops;
 
if (cmpxchg64((unsigned long *)_host_rm_ops_hv, 0, l_ops)) {
-   put_online_cpus();
+   cpus_read_unlock();
kfree(ops->rm_core);
kfree(ops);
return;
}
 
-   cpuhp_setup_state_nocalls(CPUHP_KVM_PPC_BOOK3S_PREPARE,
- "ppc/kvm_book3s:prepare",
- kvmppc_set_host_core,
- kvmppc_clear_host_core);
-   put_online_cpus();
+   cpuhp_setup_state_nocalls_cpuslocked(CPUHP_KVM_PPC_BOOK3S_PREPARE,
+"ppc/kvm_book3s:prepare",
+kvmppc_set_host_core,
+kvmppc_clear_host_core);
+   cpus_read_unlock();
 }
 
 void kvmppc_free_host_rm_ops(void)


[tip:smp/hotplug] hwtracing/coresight-etm4x: Use cpuhp_setup_state_nocalls_cpuslocked()

2017-05-26 Thread tip-bot for Sebastian Andrzej Siewior
Commit-ID:  e9f5d63f84febb7e9dfe4e0dc696adf88053fbf2
Gitweb: http://git.kernel.org/tip/e9f5d63f84febb7e9dfe4e0dc696adf88053fbf2
Author: Sebastian Andrzej Siewior 
AuthorDate: Wed, 24 May 2017 10:15:23 +0200
Committer:  Thomas Gleixner 
CommitDate: Fri, 26 May 2017 10:10:39 +0200

hwtracing/coresight-etm4x: Use cpuhp_setup_state_nocalls_cpuslocked()

etm_probe4() holds get_online_cpus() while invoking
cpuhp_setup_state_nocalls().

cpuhp_setup_state_nocalls() invokes get_online_cpus() as well. This is
correct, but prevents the conversion of the hotplug locking to a percpu
rwsem.

Use cpuhp_setup_state_nocalls_cpuslocked() to avoid the nested
call. Convert *_online_cpus() to the new interfaces while at it.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Acked-by: Ingo Molnar 
Acked-by: Mathieu Poirier 
Cc: Paul E. McKenney 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: linux-arm-ker...@lists.infradead.org
Link: http://lkml.kernel.org/r/20170524081547.983493...@linutronix.de

---
 drivers/hwtracing/coresight/coresight-etm4x.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c 
b/drivers/hwtracing/coresight/coresight-etm4x.c
index d1340fb..532adc9 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x.c
@@ -371,7 +371,7 @@ static void etm4_disable_sysfs(struct coresight_device 
*csdev)
 * after cpu online mask indicates the cpu is offline but before the
 * DYING hotplug callback is serviced by the ETM driver.
 */
-   get_online_cpus();
+   cpus_read_lock();
spin_lock(>spinlock);
 
/*
@@ -381,7 +381,7 @@ static void etm4_disable_sysfs(struct coresight_device 
*csdev)
smp_call_function_single(drvdata->cpu, etm4_disable_hw, drvdata, 1);
 
spin_unlock(>spinlock);
-   put_online_cpus();
+   cpus_read_unlock();
 
dev_info(drvdata->dev, "ETM tracing disabled\n");
 }
@@ -982,7 +982,7 @@ static int etm4_probe(struct amba_device *adev, const 
struct amba_id *id)
 
drvdata->cpu = pdata ? pdata->cpu : 0;
 
-   get_online_cpus();
+   cpus_read_lock();
etmdrvdata[drvdata->cpu] = drvdata;
 
if (smp_call_function_single(drvdata->cpu,
@@ -990,18 +990,18 @@ static int etm4_probe(struct amba_device *adev, const 
struct amba_id *id)
dev_err(dev, "ETM arch init failed\n");
 
if (!etm4_count++) {
-   cpuhp_setup_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING,
- "arm/coresight4:starting",
- etm4_starting_cpu, etm4_dying_cpu);
-   ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
-   "arm/coresight4:online",
-   etm4_online_cpu, NULL);
+   
cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ARM_CORESIGHT_STARTING,
+"arm/coresight4:starting",
+etm4_starting_cpu, 
etm4_dying_cpu);
+   ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ONLINE_DYN,
+  
"arm/coresight4:online",
+  etm4_online_cpu, 
NULL);
if (ret < 0)
goto err_arch_supported;
hp_online = ret;
}
 
-   put_online_cpus();
+   cpus_read_unlock();
 
if (etm4_arch_supported(drvdata->arch) == false) {
ret = -EINVAL;


[tip:smp/hotplug] perf/x86/intel: Drop get_online_cpus() in intel_snb_check_microcode()

2017-05-26 Thread tip-bot for Sebastian Andrzej Siewior
Commit-ID:  1ba143a5216fb148211160a0ecc1f8d3f92f06bb
Gitweb: http://git.kernel.org/tip/1ba143a5216fb148211160a0ecc1f8d3f92f06bb
Author: Sebastian Andrzej Siewior 
AuthorDate: Wed, 24 May 2017 10:15:30 +0200
Committer:  Thomas Gleixner 
CommitDate: Fri, 26 May 2017 10:10:43 +0200

perf/x86/intel: Drop get_online_cpus() in intel_snb_check_microcode()

If intel_snb_check_microcode() is invoked via
  microcode_init -> perf_check_microcode -> intel_snb_check_microcode

then get_online_cpus() is invoked nested. This works with the current
implementation of get_online_cpus() but prevents converting it to a percpu
rwsem.

intel_snb_check_microcode() is also invoked from intel_sandybridge_quirk()
unprotected.

Drop get_online_cpus() from intel_snb_check_microcode() and add it to
intel_sandybridge_quirk() so both call sites are protected.

Convert *_online_cpus() to the new interfaces while at it.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Acked-by: Ingo Molnar 
Acked-by: Borislav Petkov 
Cc: Paul E. McKenney 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Borislav Petkov 
Link: http://lkml.kernel.org/r/20170524081548.594862...@linutronix.de

---
 arch/x86/events/intel/core.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index a6d91d4..b9174aa 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -3410,12 +3410,10 @@ static void intel_snb_check_microcode(void)
int pebs_broken = 0;
int cpu;
 
-   get_online_cpus();
for_each_online_cpu(cpu) {
if ((pebs_broken = intel_snb_pebs_broken(cpu)))
break;
}
-   put_online_cpus();
 
if (pebs_broken == x86_pmu.pebs_broken)
return;
@@ -3488,7 +3486,9 @@ static bool check_msr(unsigned long msr, u64 mask)
 static __init void intel_sandybridge_quirk(void)
 {
x86_pmu.check_microcode = intel_snb_check_microcode;
+   cpus_read_lock();
intel_snb_check_microcode();
+   cpus_read_unlock();
 }
 
 static const struct { int id; char *name; } intel_arch_events_map[] 
__initconst = {
@@ -4112,13 +4112,12 @@ static __init int fixup_ht_bug(void)
 
lockup_detector_resume();
 
-   get_online_cpus();
+   cpus_read_lock();
 
-   for_each_online_cpu(c) {
+   for_each_online_cpu(c)
free_excl_cntrs(c);
-   }
 
-   put_online_cpus();
+   cpus_read_unlock();
pr_info("PMU erratum BJ122, BV98, HSD29 workaround disabled, HT off\n");
return 0;
 }


[tip:smp/hotplug] ACPI/processor: Use cpu_hotplug_disable() instead of get_online_cpus()

2017-05-26 Thread tip-bot for Thomas Gleixner
Commit-ID:  fdaf0a51bad496289356d11d796095a293794b5f
Gitweb: http://git.kernel.org/tip/fdaf0a51bad496289356d11d796095a293794b5f
Author: Thomas Gleixner 
AuthorDate: Wed, 24 May 2017 10:15:33 +0200
Committer:  Thomas Gleixner 
CommitDate: Fri, 26 May 2017 10:10:44 +0200

ACPI/processor: Use cpu_hotplug_disable() instead of get_online_cpus()

Converting the hotplug locking, i.e. get_online_cpus(), to a percpu rwsem
unearthed a circular lock dependency which was hidden from lockdep due to
the lockdep annotation of get_online_cpus() which prevents lockdep from
creating full dependency chains.

CPU0CPU1

lock(());
 lock(cpu_hotplug_lock.rw_sem);
 lock(());
lock(cpu_hotplug_lock.rw_sem);

This dependency is established via acpi_processor_start() which calls into
the work queue code. And the work queue code establishes the reverse
dependency.

This is not a problem of get_online_cpus() recursion, it's a possible
deadlock undetected by lockdep so far.

The cure is to use cpu_hotplug_disable() instead of get_online_cpus() to
protect the probing from acpi_processor_start().

There is a side effect to this: cpu_hotplug_disable() makes a concurrent
cpu hotplug attempt via the sysfs interfaces fail with -EBUSY, but that
probing usually happens during the boot process where no interaction is
possible. Any later invocations are infrequent enough and concurrent
hotplug attempts are so unlikely that the danger of user space visible
regressions is very close to zero. Anyway, thats preferrable over a real
deadlock.

Signed-off-by: Thomas Gleixner 
Acked-by: Ingo Molnar 
Acked-by: Rafael J. Wysocki 
Cc: Paul E. McKenney 
Cc: Peter Zijlstra 
Cc: Sebastian Siewior 
Cc: Steven Rostedt 
Cc: linux-a...@vger.kernel.org
Cc: Len Brown 
Link: http://lkml.kernel.org/r/20170524081548.851588...@linutronix.de

---
 drivers/acpi/processor_driver.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index 8697a82..591d1dd 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -268,9 +268,9 @@ static int acpi_processor_start(struct device *dev)
return -ENODEV;
 
/* Protect against concurrent CPU hotplug operations */
-   get_online_cpus();
+   cpu_hotplug_disable();
ret = __acpi_processor_start(device);
-   put_online_cpus();
+   cpu_hotplug_enable();
return ret;
 }
 


[tip:smp/hotplug] x86/perf: Drop EXPORT of perf_check_microcode

2017-05-26 Thread tip-bot for Thomas Gleixner
Commit-ID:  27d3b157fee0bad264eb745d5c547e2e0676f1a2
Gitweb: http://git.kernel.org/tip/27d3b157fee0bad264eb745d5c547e2e0676f1a2
Author: Thomas Gleixner 
AuthorDate: Wed, 24 May 2017 10:15:29 +0200
Committer:  Thomas Gleixner 
CommitDate: Fri, 26 May 2017 10:10:42 +0200

x86/perf: Drop EXPORT of perf_check_microcode

The only caller is the microcode update, which cannot be modular.

Drop the export.

Signed-off-by: Thomas Gleixner 
Acked-by: Ingo Molnar 
Acked-by: Borislav Petkov 
Cc: Paul E. McKenney 
Cc: Peter Zijlstra 
Cc: Sebastian Siewior 
Cc: Steven Rostedt 
Cc: Borislav Petkov 
Link: http://lkml.kernel.org/r/20170524081548.515204...@linutronix.de

---
 arch/x86/events/core.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 580b60f..ac650d5 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2224,7 +2224,6 @@ void perf_check_microcode(void)
if (x86_pmu.check_microcode)
x86_pmu.check_microcode();
 }
-EXPORT_SYMBOL_GPL(perf_check_microcode);
 
 static struct pmu pmu = {
.pmu_enable = x86_pmu_enable,


[PATCH v4 2/2] arm: dts: Add Mediatek MT2701 i2c device node

2017-05-26 Thread Jun Gao
From: Jun Gao 

Add MT2701 i2c device node.

Signed-off-by: Jun Gao 
---
 arch/arm/boot/dts/mt2701-evb.dts | 42 
 arch/arm/boot/dts/mt2701.dtsi| 42 
 2 files changed, 84 insertions(+)

diff --git a/arch/arm/boot/dts/mt2701-evb.dts b/arch/arm/boot/dts/mt2701-evb.dts
index a483798..3f5a96c 100644
--- a/arch/arm/boot/dts/mt2701-evb.dts
+++ b/arch/arm/boot/dts/mt2701-evb.dts
@@ -28,7 +28,49 @@
status = "okay";
 };
 
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   status = "okay";
+};
+
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   status = "okay";
+};
+
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   status = "okay";
+};
+
  {
+   i2c0_pins_a: i2c0@0 {
+   pins1 {
+   pinmux = ,
+;
+   bias-disable;
+   };
+   };
+
+   i2c1_pins_a: i2c1@0 {
+   pins1 {
+   pinmux = ,
+;
+   bias-disable;
+   };
+   };
+
+   i2c2_pins_a: i2c2@0 {
+   pins1 {
+   pinmux = ,
+;
+   bias-disable;
+   };
+   };
+
spi_pins_a: spi0@0 {
pins_spi {
pinmux = ,
diff --git a/arch/arm/boot/dts/mt2701.dtsi b/arch/arm/boot/dts/mt2701.dtsi
index 8037210..1b6157e 100644
--- a/arch/arm/boot/dts/mt2701.dtsi
+++ b/arch/arm/boot/dts/mt2701.dtsi
@@ -286,6 +286,48 @@
status = "disabled";
};
 
+   i2c0: i2c@11007000 {
+   compatible = "mediatek,mt2701-i2c",
+"mediatek,mt6577-i2c";
+   reg = <0 0x11007000 0 0x70>,
+ <0 0x11000200 0 0x80>;
+   interrupts = ;
+   clock-div = <16>;
+   clocks = < CLK_PERI_I2C0>, < CLK_PERI_AP_DMA>;
+   clock-names = "main", "dma";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   status = "disabled";
+   };
+
+   i2c1: i2c@11008000 {
+   compatible = "mediatek,mt2701-i2c",
+"mediatek,mt6577-i2c";
+   reg = <0 0x11008000 0 0x70>,
+ <0 0x11000280 0 0x80>;
+   interrupts = ;
+   clock-div = <16>;
+   clocks = < CLK_PERI_I2C1>, < CLK_PERI_AP_DMA>;
+   clock-names = "main", "dma";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   status = "disabled";
+   };
+
+   i2c2: i2c@11009000 {
+   compatible = "mediatek,mt2701-i2c",
+"mediatek,mt6577-i2c";
+   reg = <0 0x11009000 0 0x70>,
+ <0 0x11000300 0 0x80>;
+   interrupts = ;
+   clock-div = <16>;
+   clocks = < CLK_PERI_I2C2>, < CLK_PERI_AP_DMA>;
+   clock-names = "main", "dma";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   status = "disabled";
+   };
+
spi0: spi@1100a000 {
compatible = "mediatek,mt2701-spi";
#address-cells = <1>;
-- 
1.8.1.1



[PATCH v4 0/2] Add i2c dt-binding and device node for Mediatek MT2701 Soc

2017-05-26 Thread Jun Gao
This patch series based on v4.12-rc1, include MT2701 i2c dt-binding
and device node.

changes since v3:
- Add fallback compatible to dt-binding

changes since v2:
- Modify commit message
- Revise dt-binding documentation

changes since v1:
- Modify commit message

Dependent on "Add clock and power domain DT nodes for Mediatek MT2701"[1].

[1] 
http://lists.infradead.org/pipermail/linux-mediatek/2016-December/007637.html

Jun Gao (2):
  dt-bindings: i2c: Add Mediatek MT2701 i2c binding
  arm: dts: Add Mediatek MT2701 i2c device node

 .../devicetree/bindings/i2c/i2c-mt6577.txt | 11 +++---
 arch/arm/boot/dts/mt2701-evb.dts   | 42 ++
 arch/arm/boot/dts/mt2701.dtsi  | 42 ++
 3 files changed, 90 insertions(+), 5 deletions(-)

--
1.8.1.1



[PATCH v4 1/2] dt-bindings: i2c: Add Mediatek MT2701 i2c binding

2017-05-26 Thread Jun Gao
From: Jun Gao 

Add MT2701 i2c binding to i2c-mt6577.txt and there is no need to
modify i2c driver.

Signed-off-by: Jun Gao 
---
 Documentation/devicetree/bindings/i2c/i2c-mt6577.txt | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-mt6577.txt 
b/Documentation/devicetree/bindings/i2c/i2c-mt6577.txt
index 0ce6fa3..52f2023 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-mt6577.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-mt6577.txt
@@ -4,11 +4,12 @@ The Mediatek's I2C controller is used to interface with I2C 
devices.
 
 Required properties:
   - compatible: value should be either of the following.
-  (a) "mediatek,mt6577-i2c", for i2c compatible with mt6577 i2c.
-  (b) "mediatek,mt6589-i2c", for i2c compatible with mt6589 i2c.
-  (c) "mediatek,mt8127-i2c", for i2c compatible with mt8127 i2c.
-  (d) "mediatek,mt8135-i2c", for i2c compatible with mt8135 i2c.
-  (e) "mediatek,mt8173-i2c", for i2c compatible with mt8173 i2c.
+   "mediatek,mt2701-i2c", "mediatek,mt6577-i2c": for Mediatek MT2701
+   "mediatek,mt6577-i2c": for Mediatek MT6577
+   "mediatek,mt6589-i2c": for Mediatek MT6589
+   "mediatek,mt8127-i2c": for Mediatek MT8127
+   "mediatek,mt8135-i2c": for Mediatek MT8135
+   "mediatek,mt8173-i2c": for Mediatek MT8173
   - reg: physical base address of the controller and dma base, length of memory
 mapped region.
   - interrupts: interrupt number to the cpu.
-- 
1.8.1.1



Re: [PATCH 2/5] efi: Add EFI_SECURE_BOOT bit

2017-05-26 Thread joeyli
On Wed, May 24, 2017 at 03:45:32PM +0100, David Howells wrote:
> From: Josh Boyer 
> 
> UEFI machines can be booted in Secure Boot mode.  Add a EFI_SECURE_BOOT bit
> that can be passed to efi_enabled() to find out whether secure boot is
> enabled.
> 
> This will be used by the SysRq+x handler, registered by the x86 arch, to
> find out whether secure boot mode is enabled so that it can be disabled.
> 
> Signed-off-by: Josh Boyer 
> Signed-off-by: David Howells 
> cc: linux-...@vger.kernel.org

Reviewed-by: Joey Lee 

Regards
Joey Lee

> ---
> 
>  drivers/firmware/efi/secureboot.c |1 +
>  include/linux/efi.h   |1 +
>  2 files changed, 2 insertions(+)
> 
> diff --git a/drivers/firmware/efi/secureboot.c 
> b/drivers/firmware/efi/secureboot.c
> index cf5bccae15e8..730518061a14 100644
> --- a/drivers/firmware/efi/secureboot.c
> +++ b/drivers/firmware/efi/secureboot.c
> @@ -24,6 +24,7 @@ void __init efi_set_secure_boot(enum efi_secureboot_mode 
> mode)
>   pr_info("Secure boot disabled\n");
>   break;
>   case efi_secureboot_mode_enabled:
> + set_bit(EFI_SECURE_BOOT, );
>   pr_info("Secure boot enabled\n");
>   break;
>   default:
> diff --git a/include/linux/efi.h b/include/linux/efi.h
> index e2f53edccf15..5e9a2d7df089 100644
> --- a/include/linux/efi.h
> +++ b/include/linux/efi.h
> @@ -1081,6 +1081,7 @@ extern int __init efi_setup_pcdp_console(char *);
>  #define EFI_DBG  8   /* Print additional debug info 
> at runtime */
>  #define EFI_NX_PE_DATA   9   /* Can runtime data regions be 
> mapped non-executable? */
>  #define EFI_MEM_ATTR 10  /* Did firmware publish an 
> EFI_MEMORY_ATTRIBUTES table? */
> +#define EFI_SECURE_BOOT  11  /* Are we in Secure Boot mode? 
> */
>  
>  #ifdef CONFIG_EFI
>  /*
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-efi" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] ARM: dts: keystone-k2l: fix broken Ethernet due to disabled OSR

2017-05-26 Thread Arnd Bergmann
On Fri, May 26, 2017 at 9:44 AM, Sekhar Nori  wrote:
> Hi Arnd,
>
> On Friday 31 March 2017 03:43 PM, Arnd Bergmann wrote:
>> On Wed, Mar 29, 2017 at 6:13 PM, santosh.shilim...@oracle.com
>>  wrote:
 Signed-off-by: Murali Karicheri 
 Acked-by: Tero Kristo 
 [nsek...@ti.com: commit message updates, port to latest mainline]
 Signed-off-by: Sekhar Nori 
 ---
>>>
>>> Acked-by: Santosh Shilimkar 
>>>
>>> Can you please pick this up for rcx fixes ?
>>
>> Applied, thanks!
>
> Looks like this fix never made to to mainline. Do you have the patch
> with you still? It will have to be marked for v4.11 stable and pushed.

Sorry about the mistake, I don't know what happened here but I
found it in my git reflog and applied it to the latest fixes branch
with the stable tag added.

Thanks for checking this and the reminder.

   Arnd


[PATCH] arm64: dts: uniphier: reserve more memory for LD11/LD20

2017-05-26 Thread Masahiro Yamada
Reserve enough space below the kernel base.
The assumed address map is:
  8000 - 80ff : for IPP
  8100 - 81ff : for ARM secure
  8200 -  : for Linux

Signed-off-by: Masahiro Yamada 
---

 arch/arm64/boot/dts/socionext/uniphier-ld11.dtsi | 2 +-
 arch/arm64/boot/dts/socionext/uniphier-ld20.dtsi | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/boot/dts/socionext/uniphier-ld11.dtsi 
b/arch/arm64/boot/dts/socionext/uniphier-ld11.dtsi
index 53ede23d68cb..702f5b175456 100644
--- a/arch/arm64/boot/dts/socionext/uniphier-ld11.dtsi
+++ b/arch/arm64/boot/dts/socionext/uniphier-ld11.dtsi
@@ -43,7 +43,7 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
-/memreserve/ 0x8000 0x0008;
+/memreserve/ 0x8000 0x0200;
 
 / {
compatible = "socionext,uniphier-ld11";
diff --git a/arch/arm64/boot/dts/socionext/uniphier-ld20.dtsi 
b/arch/arm64/boot/dts/socionext/uniphier-ld20.dtsi
index aa4dad51bf46..f120059e6e24 100644
--- a/arch/arm64/boot/dts/socionext/uniphier-ld20.dtsi
+++ b/arch/arm64/boot/dts/socionext/uniphier-ld20.dtsi
@@ -43,7 +43,7 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
-/memreserve/ 0x8000 0x0008;
+/memreserve/ 0x8000 0x0200;
 
 / {
compatible = "socionext,uniphier-ld20";
-- 
2.7.4



Re: [PATCH] ARM: dts: keystone-k2l: fix broken Ethernet due to disabled OSR

2017-05-26 Thread Sekhar Nori
On Friday 26 May 2017 01:42 PM, Arnd Bergmann wrote:
> On Fri, May 26, 2017 at 9:44 AM, Sekhar Nori  wrote:
>> Hi Arnd,
>>
>> On Friday 31 March 2017 03:43 PM, Arnd Bergmann wrote:
>>> On Wed, Mar 29, 2017 at 6:13 PM, santosh.shilim...@oracle.com
>>>  wrote:
> Signed-off-by: Murali Karicheri 
> Acked-by: Tero Kristo 
> [nsek...@ti.com: commit message updates, port to latest mainline]
> Signed-off-by: Sekhar Nori 
> ---

 Acked-by: Santosh Shilimkar 

 Can you please pick this up for rcx fixes ?
>>>
>>> Applied, thanks!
>>
>> Looks like this fix never made to to mainline. Do you have the patch
>> with you still? It will have to be marked for v4.11 stable and pushed.
> 
> Sorry about the mistake, I don't know what happened here but I
> found it in my git reflog and applied it to the latest fixes branch
> with the stable tag added.
> 
> Thanks for checking this and the reminder.

No problem, Arnd. Thanks for taking care of it.

Regards,
Sekhar


[PATCH] arm64: dts: uniphier: reserve more memory for LD11/LD20

2017-05-26 Thread Masahiro Yamada
Reserve enough space below the kernel base.
The assumed address map is:
  8000 - 80ff : for IPP
  8100 - 81ff : for ARM secure
  8200 -  : for Linux

Signed-off-by: Masahiro Yamada 
---

 arch/arm64/boot/dts/socionext/uniphier-ld11.dtsi | 2 +-
 arch/arm64/boot/dts/socionext/uniphier-ld20.dtsi | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/boot/dts/socionext/uniphier-ld11.dtsi 
b/arch/arm64/boot/dts/socionext/uniphier-ld11.dtsi
index 53ede23d68cb..702f5b175456 100644
--- a/arch/arm64/boot/dts/socionext/uniphier-ld11.dtsi
+++ b/arch/arm64/boot/dts/socionext/uniphier-ld11.dtsi
@@ -43,7 +43,7 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
-/memreserve/ 0x8000 0x0008;
+/memreserve/ 0x8000 0x0200;
 
 / {
compatible = "socionext,uniphier-ld11";
diff --git a/arch/arm64/boot/dts/socionext/uniphier-ld20.dtsi 
b/arch/arm64/boot/dts/socionext/uniphier-ld20.dtsi
index aa4dad51bf46..f120059e6e24 100644
--- a/arch/arm64/boot/dts/socionext/uniphier-ld20.dtsi
+++ b/arch/arm64/boot/dts/socionext/uniphier-ld20.dtsi
@@ -43,7 +43,7 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
-/memreserve/ 0x8000 0x0008;
+/memreserve/ 0x8000 0x0200;
 
 / {
compatible = "socionext,uniphier-ld20";
-- 
2.7.4



[PATCH 4/8] i2c: break out OF support into seperate file

2017-05-26 Thread Wolfram Sang
Also removes some ifdeffery.

Signed-off-by: Wolfram Sang 
---
 drivers/i2c/Makefile|   1 +
 drivers/i2c/i2c-core-base.c | 265 +-
 drivers/i2c/i2c-core-of.c   | 276 
 drivers/i2c/i2c-core.h  |   8 ++
 4 files changed, 286 insertions(+), 264 deletions(-)
 create mode 100644 drivers/i2c/i2c-core-of.c

diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index a6a90fe2db887a..189e0e6476f0a6 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_I2C_BOARDINFO) += i2c-boardinfo.o
 obj-$(CONFIG_I2C)  += i2c-core.o
 i2c-core-objs  := i2c-core-base.o i2c-core-smbus.o
 i2c-core-$(CONFIG_I2C_SLAVE)   += i2c-core-slave.o
+i2c-core-$(CONFIG_OF)  += i2c-core-of.o
 
 obj-$(CONFIG_I2C_SMBUS)+= i2c-smbus.o
 obj-$(CONFIG_I2C_CHARDEV)  += i2c-dev.o
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 70fc4624c69c25..461451da106504 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -16,9 +16,6 @@
 /* With some changes from Kyösti Mälkki .
Mux support by Rodolfo Giometti  and
Michael Lawnick 
-   OF support is copyright (c) 2008 Jochen Friedrich 
-   (based on a previous patch from Jon Smirl ) and
-   (c) 2013  Wolfram Sang 
I2C ACPI code Copyright (C) 2014 Intel Corp
Author: Lan Tianyu 
  */
@@ -1191,7 +1188,7 @@ static unsigned short i2c_encode_flags_to_addr(struct 
i2c_client *client)
 
 /* This is a permissive address validity check, I2C address map constraints
  * are purposely not enforced, except for the general call address. */
-static int i2c_check_addr_validity(unsigned addr, unsigned short flags)
+int i2c_check_addr_validity(unsigned addr, unsigned short flags)
 {
if (flags & I2C_CLIENT_TEN) {
/* 10-bit address, all values are valid */
@@ -1760,210 +1757,6 @@ static void i2c_scan_static_board_info(struct 
i2c_adapter *adapter)
up_read(&__i2c_board_lock);
 }
 
-/* OF support code */
-
-#if IS_ENABLED(CONFIG_OF)
-static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap,
-struct device_node *node)
-{
-   struct i2c_client *result;
-   struct i2c_board_info info = {};
-   struct dev_archdata dev_ad = {};
-   const __be32 *addr_be;
-   u32 addr;
-   int len;
-
-   dev_dbg(>dev, "of_i2c: register %s\n", node->full_name);
-
-   if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) {
-   dev_err(>dev, "of_i2c: modalias failure on %s\n",
-   node->full_name);
-   return ERR_PTR(-EINVAL);
-   }
-
-   addr_be = of_get_property(node, "reg", );
-   if (!addr_be || (len < sizeof(*addr_be))) {
-   dev_err(>dev, "of_i2c: invalid reg on %s\n",
-   node->full_name);
-   return ERR_PTR(-EINVAL);
-   }
-
-   addr = be32_to_cpup(addr_be);
-   if (addr & I2C_TEN_BIT_ADDRESS) {
-   addr &= ~I2C_TEN_BIT_ADDRESS;
-   info.flags |= I2C_CLIENT_TEN;
-   }
-
-   if (addr & I2C_OWN_SLAVE_ADDRESS) {
-   addr &= ~I2C_OWN_SLAVE_ADDRESS;
-   info.flags |= I2C_CLIENT_SLAVE;
-   }
-
-   if (i2c_check_addr_validity(addr, info.flags)) {
-   dev_err(>dev, "of_i2c: invalid addr=%x on %s\n",
-   addr, node->full_name);
-   return ERR_PTR(-EINVAL);
-   }
-
-   info.addr = addr;
-   info.of_node = of_node_get(node);
-   info.archdata = _ad;
-
-   if (of_property_read_bool(node, "host-notify"))
-   info.flags |= I2C_CLIENT_HOST_NOTIFY;
-
-   if (of_get_property(node, "wakeup-source", NULL))
-   info.flags |= I2C_CLIENT_WAKE;
-
-   result = i2c_new_device(adap, );
-   if (result == NULL) {
-   dev_err(>dev, "of_i2c: Failure registering %s\n",
-   node->full_name);
-   of_node_put(node);
-   return ERR_PTR(-EINVAL);
-   }
-   return result;
-}
-
-static void of_i2c_register_devices(struct i2c_adapter *adap)
-{
-   struct device_node *bus, *node;
-   struct i2c_client *client;
-
-   /* Only register child devices if the adapter has a node pointer set */
-   if (!adap->dev.of_node)
-   return;
-
-   dev_dbg(>dev, "of_i2c: walking child nodes\n");
-
-   bus = of_get_child_by_name(adap->dev.of_node, "i2c-bus");
-   if (!bus)
-   bus = of_node_get(adap->dev.of_node);
-
-   for_each_available_child_of_node(bus, node) {
-   if (of_node_test_and_set_flag(node, OF_POPULATED))
-   continue;

[PATCH 3/8] i2c: break out smbus support into seperate file

2017-05-26 Thread Wolfram Sang
Break out the exported SMBus functions and the emulation layer into a
seperate file. This also involved splitting up the tracing header into
an I2C and an SMBus part.

Signed-off-by: Wolfram Sang 
---
 Documentation/driver-api/i2c.rst |   3 +
 drivers/i2c/Makefile |   2 +-
 drivers/i2c/i2c-core-base.c  | 574 -
 drivers/i2c/i2c-core-smbus.c | 594 +++
 include/trace/events/i2c.h   | 226 +--
 include/trace/events/smbus.h | 249 
 6 files changed, 849 insertions(+), 799 deletions(-)
 create mode 100644 drivers/i2c/i2c-core-smbus.c
 create mode 100644 include/trace/events/smbus.h

diff --git a/Documentation/driver-api/i2c.rst b/Documentation/driver-api/i2c.rst
index 67366d9ff7303f..7582c079d74795 100644
--- a/Documentation/driver-api/i2c.rst
+++ b/Documentation/driver-api/i2c.rst
@@ -43,3 +43,6 @@ i2c_adapter devices which don't support those I2C operations.
 
 .. kernel-doc:: drivers/i2c/i2c-core-base.c
:export:
+
+.. kernel-doc:: drivers/i2c/i2c-core-smbus.c
+   :export:
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 6c54716e7f28ca..a6a90fe2db887a 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -4,7 +4,7 @@
 
 obj-$(CONFIG_I2C_BOARDINFO)+= i2c-boardinfo.o
 obj-$(CONFIG_I2C)  += i2c-core.o
-i2c-core-objs  := i2c-core-base.o
+i2c-core-objs  := i2c-core-base.o i2c-core-smbus.o
 i2c-core-$(CONFIG_I2C_SLAVE)   += i2c-core-slave.o
 
 obj-$(CONFIG_I2C_SMBUS)+= i2c-smbus.o
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 88c0ca664a7b8f..70fc4624c69c25 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -14,9 +14,6 @@
 /* - */
 
 /* With some changes from Kyösti Mälkki .
-   All SMBus-related things are written by Frodo Looijaard 
-   SMBus 2.0 support by Mark Studebaker  and
-   Jean Delvare 
Mux support by Rodolfo Giometti  and
Michael Lawnick 
OF support is copyright (c) 2008 Jochen Friedrich 
@@ -3155,577 +3152,6 @@ void i2c_put_adapter(struct i2c_adapter *adap)
 }
 EXPORT_SYMBOL(i2c_put_adapter);
 
-/* The SMBus parts */
-
-#define POLY(0x1070U << 3)
-static u8 crc8(u16 data)
-{
-   int i;
-
-   for (i = 0; i < 8; i++) {
-   if (data & 0x8000)
-   data = data ^ POLY;
-   data = data << 1;
-   }
-   return (u8)(data >> 8);
-}
-
-/* Incremental CRC8 over count bytes in the array pointed to by p */
-static u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count)
-{
-   int i;
-
-   for (i = 0; i < count; i++)
-   crc = crc8((crc ^ p[i]) << 8);
-   return crc;
-}
-
-/* Assume a 7-bit address, which is reasonable for SMBus */
-static u8 i2c_smbus_msg_pec(u8 pec, struct i2c_msg *msg)
-{
-   /* The address will be sent first */
-   u8 addr = i2c_8bit_addr_from_msg(msg);
-   pec = i2c_smbus_pec(pec, , 1);
-
-   /* The data buffer follows */
-   return i2c_smbus_pec(pec, msg->buf, msg->len);
-}
-
-/* Used for write only transactions */
-static inline void i2c_smbus_add_pec(struct i2c_msg *msg)
-{
-   msg->buf[msg->len] = i2c_smbus_msg_pec(0, msg);
-   msg->len++;
-}
-
-/* Return <0 on CRC error
-   If there was a write before this read (most cases) we need to take the
-   partial CRC from the write part into account.
-   Note that this function does modify the message (we need to decrease the
-   message length to hide the CRC byte from the caller). */
-static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg)
-{
-   u8 rpec = msg->buf[--msg->len];
-   cpec = i2c_smbus_msg_pec(cpec, msg);
-
-   if (rpec != cpec) {
-   pr_debug("Bad PEC 0x%02x vs. 0x%02x\n",
-   rpec, cpec);
-   return -EBADMSG;
-   }
-   return 0;
-}
-
-/**
- * i2c_smbus_read_byte - SMBus "receive byte" protocol
- * @client: Handle to slave device
- *
- * This executes the SMBus "receive byte" protocol, returning negative errno
- * else the byte received from the device.
- */
-s32 i2c_smbus_read_byte(const struct i2c_client *client)
-{
-   union i2c_smbus_data data;
-   int status;
-
-   status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
-   I2C_SMBUS_READ, 0,
-   I2C_SMBUS_BYTE, );
-   return (status < 0) ? status : data.byte;
-}
-EXPORT_SYMBOL(i2c_smbus_read_byte);
-
-/**
- * i2c_smbus_write_byte - SMBus "send byte" protocol
- * @client: Handle to slave device
- * @value: Byte to be sent
- *
- * This executes the SMBus "send byte" protocol, returning negative errno
- * else 

[PATCH 1/8] i2c: rename core source file to allow refactorization

2017-05-26 Thread Wolfram Sang
The I2C core became quite huge and its monolithic structure makes
maintenance hard. So, prepare to break out some functionality into
seperate files by renaming the source file. Note that we keep the
resulting object name constant to avoid regressions.

Signed-off-by: Wolfram Sang 
---
 Documentation/driver-api/i2c.rst| 2 +-
 drivers/i2c/Makefile| 4 +++-
 drivers/i2c/busses/i2c-designware-core.c| 2 +-
 drivers/i2c/{i2c-core.c => i2c-core-base.c} | 0
 4 files changed, 5 insertions(+), 3 deletions(-)
 rename drivers/i2c/{i2c-core.c => i2c-core-base.c} (100%)

diff --git a/Documentation/driver-api/i2c.rst b/Documentation/driver-api/i2c.rst
index 0bf86a445d0135..67366d9ff7303f 100644
--- a/Documentation/driver-api/i2c.rst
+++ b/Documentation/driver-api/i2c.rst
@@ -41,5 +41,5 @@ i2c_adapter devices which don't support those I2C operations.
 .. kernel-doc:: drivers/i2c/i2c-boardinfo.c
:functions: i2c_register_board_info
 
-.. kernel-doc:: drivers/i2c/i2c-core.c
+.. kernel-doc:: drivers/i2c/i2c-core-base.c
:export:
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 45095b3d16a914..d459c7e5907607 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -4,6 +4,8 @@
 
 obj-$(CONFIG_I2C_BOARDINFO)+= i2c-boardinfo.o
 obj-$(CONFIG_I2C)  += i2c-core.o
+i2c-core-objs  := i2c-core-base.o
+
 obj-$(CONFIG_I2C_SMBUS)+= i2c-smbus.o
 obj-$(CONFIG_I2C_CHARDEV)  += i2c-dev.o
 obj-$(CONFIG_I2C_MUX)  += i2c-mux.o
@@ -12,4 +14,4 @@ obj-$(CONFIG_I2C_STUB)+= i2c-stub.o
 obj-$(CONFIG_I2C_SLAVE_EEPROM) += i2c-slave-eeprom.o
 
 ccflags-$(CONFIG_I2C_DEBUG_CORE) := -DDEBUG
-CFLAGS_i2c-core.o := -Wno-deprecated-declarations
+CFLAGS_i2c-core-base.o := -Wno-deprecated-declarations
diff --git a/drivers/i2c/busses/i2c-designware-core.c 
b/drivers/i2c/busses/i2c-designware-core.c
index c453717b753b72..3c41995634c2f9 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -583,7 +583,7 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
 */
 
/*
-* i2c-core.c always sets the buffer length of
+* i2c-core always sets the buffer length of
 * I2C_FUNC_SMBUS_BLOCK_DATA to 1. The length will
 * be adjusted when receiving the first byte.
 * Thus we can't stop the transaction here.
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core-base.c
similarity index 100%
rename from drivers/i2c/i2c-core.c
rename to drivers/i2c/i2c-core-base.c
-- 
2.11.0



[PATCH V2 01/37] perf intel-pt: Move decoder error setting into one condition

2017-05-26 Thread Adrian Hunter
Move decoder error setting into one condition.

Cc'ed to stable because later fixes depend on it.

Signed-off-by: Adrian Hunter 
Cc: sta...@vger.kernel.org
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c 
b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 7cf7f7aca4d2..5a9676c6e23f 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -2130,15 +2130,18 @@ const struct intel_pt_state *intel_pt_decode(struct 
intel_pt_decoder *decoder)
}
} while (err == -ENOLINK);
 
-   decoder->state.err = err ? intel_pt_ext_err(err) : 0;
+   if (err) {
+   decoder->state.err = intel_pt_ext_err(err);
+   decoder->state.from_ip = decoder->ip;
+   } else {
+   decoder->state.err = 0;
+   }
+
decoder->state.timestamp = decoder->timestamp;
decoder->state.est_timestamp = intel_pt_est_timestamp(decoder);
decoder->state.cr3 = decoder->cr3;
decoder->state.tot_insn_cnt = decoder->tot_insn_cnt;
 
-   if (err)
-   decoder->state.from_ip = decoder->ip;
-
return >state;
 }
 
-- 
1.9.1



[PATCH 2/8] i2c: break out slave support into seperate file

2017-05-26 Thread Wolfram Sang
Also removes some ifdeffery.

Signed-off-by: Wolfram Sang 
---
 drivers/i2c/Makefile |   1 +
 drivers/i2c/i2c-core-base.c  | 102 +-
 drivers/i2c/i2c-core-slave.c | 115 +++
 drivers/i2c/i2c-core.h   |   1 +
 4 files changed, 118 insertions(+), 101 deletions(-)
 create mode 100644 drivers/i2c/i2c-core-slave.c

diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index d459c7e5907607..6c54716e7f28ca 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -5,6 +5,7 @@
 obj-$(CONFIG_I2C_BOARDINFO)+= i2c-boardinfo.o
 obj-$(CONFIG_I2C)  += i2c-core.o
 i2c-core-objs  := i2c-core-base.o
+i2c-core-$(CONFIG_I2C_SLAVE)   += i2c-core-slave.o
 
 obj-$(CONFIG_I2C_SMBUS)+= i2c-smbus.o
 obj-$(CONFIG_I2C_CHARDEV)  += i2c-dev.o
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 82576aaccc909b..88c0ca664a7b8f 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -24,7 +24,6 @@
(c) 2013  Wolfram Sang 
I2C ACPI code Copyright (C) 2014 Intel Corp
Author: Lan Tianyu 
-   I2C slave support (c) 2014 by Wolfram Sang 
  */
 
 #define pr_fmt(fmt) "i2c-core: " fmt
@@ -1213,7 +1212,7 @@ static int i2c_check_addr_validity(unsigned addr, 
unsigned short flags)
  * device uses a reserved address, then it shouldn't be probed. 7-bit
  * addressing is assumed, 10-bit address devices are rare and should be
  * explicitly enumerated. */
-static int i2c_check_7bit_addr_validity_strict(unsigned short addr)
+int i2c_check_7bit_addr_validity_strict(unsigned short addr)
 {
/*
 * Reserved addresses per I2C specification:
@@ -3727,105 +3726,6 @@ s32 i2c_smbus_read_i2c_block_data_or_emulated(const 
struct i2c_client *client,
 }
 EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data_or_emulated);
 
-#if IS_ENABLED(CONFIG_I2C_SLAVE)
-int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb)
-{
-   int ret;
-
-   if (!client || !slave_cb) {
-   WARN(1, "insufficient data\n");
-   return -EINVAL;
-   }
-
-   if (!(client->flags & I2C_CLIENT_SLAVE))
-   dev_warn(>dev, "%s: client slave flag not set. You 
might see address collisions\n",
-__func__);
-
-   if (!(client->flags & I2C_CLIENT_TEN)) {
-   /* Enforce stricter address checking */
-   ret = i2c_check_7bit_addr_validity_strict(client->addr);
-   if (ret) {
-   dev_err(>dev, "%s: invalid address\n", 
__func__);
-   return ret;
-   }
-   }
-
-   if (!client->adapter->algo->reg_slave) {
-   dev_err(>dev, "%s: not supported by adapter\n", 
__func__);
-   return -EOPNOTSUPP;
-   }
-
-   client->slave_cb = slave_cb;
-
-   i2c_lock_adapter(client->adapter);
-   ret = client->adapter->algo->reg_slave(client);
-   i2c_unlock_adapter(client->adapter);
-
-   if (ret) {
-   client->slave_cb = NULL;
-   dev_err(>dev, "%s: adapter returned error %d\n", 
__func__, ret);
-   }
-
-   return ret;
-}
-EXPORT_SYMBOL_GPL(i2c_slave_register);
-
-int i2c_slave_unregister(struct i2c_client *client)
-{
-   int ret;
-
-   if (!client->adapter->algo->unreg_slave) {
-   dev_err(>dev, "%s: not supported by adapter\n", 
__func__);
-   return -EOPNOTSUPP;
-   }
-
-   i2c_lock_adapter(client->adapter);
-   ret = client->adapter->algo->unreg_slave(client);
-   i2c_unlock_adapter(client->adapter);
-
-   if (ret == 0)
-   client->slave_cb = NULL;
-   else
-   dev_err(>dev, "%s: adapter returned error %d\n", 
__func__, ret);
-
-   return ret;
-}
-EXPORT_SYMBOL_GPL(i2c_slave_unregister);
-
-/**
- * i2c_detect_slave_mode - detect operation mode
- * @dev: The device owning the bus
- *
- * This checks the device nodes for an I2C slave by checking the address
- * used in the reg property. If the address match the I2C_OWN_SLAVE_ADDRESS
- * flag this means the device is configured to act as a I2C slave and it will
- * be listening at that address.
- *
- * Returns true if an I2C own slave address is detected, otherwise returns
- * false.
- */
-bool i2c_detect_slave_mode(struct device *dev)
-{
-   if (IS_BUILTIN(CONFIG_OF) && dev->of_node) {
-   struct device_node *child;
-   u32 reg;
-
-   for_each_child_of_node(dev->of_node, child) {
-   of_property_read_u32(child, "reg", );
-   if (reg & I2C_OWN_SLAVE_ADDRESS) {
-   of_node_put(child);
-   return true;
-   }
-   }
-   } else if (IS_BUILTIN(CONFIG_ACPI) && 

[PATCH 7/8] i2c: remove unneeded includes from core

2017-05-26 Thread Wolfram Sang
They seem like cruft to me. I couldn't find any evidence that something
included from there is actually used.

Signed-off-by: Wolfram Sang 
---
 drivers/i2c/i2c-core-base.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index ac7b95e4cda75d..78135c1deaab59 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -21,7 +21,6 @@
 #define pr_fmt(fmt) "i2c-core: " fmt
 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -29,7 +28,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
-- 
2.11.0



<    1   2   3   4   5   6   7   8   9   10   >