Re: [PATCH 2/3] phy: rockchip-emmc: Be tolerant to card clock of 0 in power on

2016-07-24 Thread Kishon Vijay Abraham I
Ulf,

On Saturday 23 July 2016 03:09 PM, Ulf Hansson wrote:
> On 29 June 2016 at 17:18, Doug Anderson  wrote:
>> Kishon,
>>
>> On Wed, Jun 29, 2016 at 6:49 AM, Kishon Vijay Abraham I  
>> wrote:
>>> Hi,
>>>
>>> On Monday 27 June 2016 11:09 PM, Douglas Anderson wrote:
 It's possible that there are some reasons to turn the PHY on while the
 clock is 0.  In this case we just won't wait for the DLL to lock.

 This is a bit of a stopgap until we figure out exactly when we're
 supposed to wait for the DLL to lock and when we're supposed to power
 cycle the PHY.

 Note: this patch should help with suspend/resume where the system will
 try to turn the PHY back on when the clock is 0.

 Signed-off-by: Douglas Anderson 
 ---
  drivers/phy/phy-rockchip-emmc.c | 59 
 ++---
  1 file changed, 37 insertions(+), 22 deletions(-)

 diff --git a/drivers/phy/phy-rockchip-emmc.c 
 b/drivers/phy/phy-rockchip-emmc.c
 index 9dce958233a0..a2aa6aca7dec 100644
 --- a/drivers/phy/phy-rockchip-emmc.c
 +++ b/drivers/phy/phy-rockchip-emmc.c
 @@ -88,15 +88,36 @@ static int rockchip_emmc_phy_power(struct phy *phy, 
 bool on_off)
   unsigned int caldone;
   unsigned int dllrdy;
   unsigned int freqsel = PHYCTRL_FREQSEL_200M;
 + unsigned long rate;
   unsigned long timeout;

 - if (rk_phy->emmcclk != NULL) {
 - unsigned long rate = clk_get_rate(rk_phy->emmcclk);
 + /*
 +  * Keep phyctrl_pdb and phyctrl_endll low to allow
 +  * initialization of CALIO state M/C DFFs
 +  */
 + regmap_write(rk_phy->reg_base,
 +  rk_phy->reg_offset + GRF_EMMCPHY_CON6,
 +  HIWORD_UPDATE(PHYCTRL_PDB_PWR_OFF,
 +PHYCTRL_PDB_MASK,
 +PHYCTRL_PDB_SHIFT));
 + regmap_write(rk_phy->reg_base,
 +  rk_phy->reg_offset + GRF_EMMCPHY_CON6,
 +  HIWORD_UPDATE(PHYCTRL_ENDLL_DISABLE,
 +PHYCTRL_ENDLL_MASK,
 +PHYCTRL_ENDLL_SHIFT));
 +
 + /* Already finish power_off above */
 + if (on_off == PHYCTRL_PDB_PWR_OFF)
 + return 0;
 +
 + rate = clk_get_rate(rk_phy->emmcclk);
 +
 + if (rate != 0) {
   unsigned long ideal_rate;
   unsigned long diff;

   switch (rate) {
 - case 0 ... 7499:
 + case 1 ... 7499:
   ideal_rate = 5000;
   freqsel = PHYCTRL_FREQSEL_50M;
   break;
 @@ -127,25 +148,6 @@ static int rockchip_emmc_phy_power(struct phy *phy, 
 bool on_off)
   }

   /*
 -  * Keep phyctrl_pdb and phyctrl_endll low to allow
 -  * initialization of CALIO state M/C DFFs
 -  */
 - regmap_write(rk_phy->reg_base,
 -  rk_phy->reg_offset + GRF_EMMCPHY_CON6,
 -  HIWORD_UPDATE(PHYCTRL_PDB_PWR_OFF,
 -PHYCTRL_PDB_MASK,
 -PHYCTRL_PDB_SHIFT));
 - regmap_write(rk_phy->reg_base,
 -  rk_phy->reg_offset + GRF_EMMCPHY_CON6,
 -  HIWORD_UPDATE(PHYCTRL_ENDLL_DISABLE,
 -PHYCTRL_ENDLL_MASK,
 -PHYCTRL_ENDLL_SHIFT));
 -
 - /* Already finish power_off above */
 - if (on_off == PHYCTRL_PDB_PWR_OFF)
 - return 0;
 -
 - /*
* According to the user manual, calpad calibration
* cycle takes more than 2us without the minimal recommended
* value, so we may need a little margin here
 @@ -183,6 +185,19 @@ static int rockchip_emmc_phy_power(struct phy *phy, 
 bool on_off)
HIWORD_UPDATE(PHYCTRL_ENDLL_ENABLE,
  PHYCTRL_ENDLL_MASK,
  PHYCTRL_ENDLL_SHIFT));
 +
 + /*
 +  * We turned on the DLL even though the rate was 0 because we the
 +  * clock might be turned on later.  ...but we can't wait for the DLL
 +  * to lock when the rate is 0 because it will never lock with no
 +  * input clock.
 +  *
 +  * Technically we should be checking the lock later when the clock
 +  * is turned on, but for now we won't.
 +  */
 + if (rate == 0)
 + return 0;
>>>
>>> Why not return initially from rockchip_emmc_phy_power if the clock rate is 
>>> '0'.
>>> Are there other functions to lock the DLL apart from phy_power?
>>
>> Yeah, it's a 

Re: [PATCH 2/3] phy: rockchip-emmc: Be tolerant to card clock of 0 in power on

2016-07-24 Thread Kishon Vijay Abraham I
Ulf,

On Saturday 23 July 2016 03:09 PM, Ulf Hansson wrote:
> On 29 June 2016 at 17:18, Doug Anderson  wrote:
>> Kishon,
>>
>> On Wed, Jun 29, 2016 at 6:49 AM, Kishon Vijay Abraham I  
>> wrote:
>>> Hi,
>>>
>>> On Monday 27 June 2016 11:09 PM, Douglas Anderson wrote:
 It's possible that there are some reasons to turn the PHY on while the
 clock is 0.  In this case we just won't wait for the DLL to lock.

 This is a bit of a stopgap until we figure out exactly when we're
 supposed to wait for the DLL to lock and when we're supposed to power
 cycle the PHY.

 Note: this patch should help with suspend/resume where the system will
 try to turn the PHY back on when the clock is 0.

 Signed-off-by: Douglas Anderson 
 ---
  drivers/phy/phy-rockchip-emmc.c | 59 
 ++---
  1 file changed, 37 insertions(+), 22 deletions(-)

 diff --git a/drivers/phy/phy-rockchip-emmc.c 
 b/drivers/phy/phy-rockchip-emmc.c
 index 9dce958233a0..a2aa6aca7dec 100644
 --- a/drivers/phy/phy-rockchip-emmc.c
 +++ b/drivers/phy/phy-rockchip-emmc.c
 @@ -88,15 +88,36 @@ static int rockchip_emmc_phy_power(struct phy *phy, 
 bool on_off)
   unsigned int caldone;
   unsigned int dllrdy;
   unsigned int freqsel = PHYCTRL_FREQSEL_200M;
 + unsigned long rate;
   unsigned long timeout;

 - if (rk_phy->emmcclk != NULL) {
 - unsigned long rate = clk_get_rate(rk_phy->emmcclk);
 + /*
 +  * Keep phyctrl_pdb and phyctrl_endll low to allow
 +  * initialization of CALIO state M/C DFFs
 +  */
 + regmap_write(rk_phy->reg_base,
 +  rk_phy->reg_offset + GRF_EMMCPHY_CON6,
 +  HIWORD_UPDATE(PHYCTRL_PDB_PWR_OFF,
 +PHYCTRL_PDB_MASK,
 +PHYCTRL_PDB_SHIFT));
 + regmap_write(rk_phy->reg_base,
 +  rk_phy->reg_offset + GRF_EMMCPHY_CON6,
 +  HIWORD_UPDATE(PHYCTRL_ENDLL_DISABLE,
 +PHYCTRL_ENDLL_MASK,
 +PHYCTRL_ENDLL_SHIFT));
 +
 + /* Already finish power_off above */
 + if (on_off == PHYCTRL_PDB_PWR_OFF)
 + return 0;
 +
 + rate = clk_get_rate(rk_phy->emmcclk);
 +
 + if (rate != 0) {
   unsigned long ideal_rate;
   unsigned long diff;

   switch (rate) {
 - case 0 ... 7499:
 + case 1 ... 7499:
   ideal_rate = 5000;
   freqsel = PHYCTRL_FREQSEL_50M;
   break;
 @@ -127,25 +148,6 @@ static int rockchip_emmc_phy_power(struct phy *phy, 
 bool on_off)
   }

   /*
 -  * Keep phyctrl_pdb and phyctrl_endll low to allow
 -  * initialization of CALIO state M/C DFFs
 -  */
 - regmap_write(rk_phy->reg_base,
 -  rk_phy->reg_offset + GRF_EMMCPHY_CON6,
 -  HIWORD_UPDATE(PHYCTRL_PDB_PWR_OFF,
 -PHYCTRL_PDB_MASK,
 -PHYCTRL_PDB_SHIFT));
 - regmap_write(rk_phy->reg_base,
 -  rk_phy->reg_offset + GRF_EMMCPHY_CON6,
 -  HIWORD_UPDATE(PHYCTRL_ENDLL_DISABLE,
 -PHYCTRL_ENDLL_MASK,
 -PHYCTRL_ENDLL_SHIFT));
 -
 - /* Already finish power_off above */
 - if (on_off == PHYCTRL_PDB_PWR_OFF)
 - return 0;
 -
 - /*
* According to the user manual, calpad calibration
* cycle takes more than 2us without the minimal recommended
* value, so we may need a little margin here
 @@ -183,6 +185,19 @@ static int rockchip_emmc_phy_power(struct phy *phy, 
 bool on_off)
HIWORD_UPDATE(PHYCTRL_ENDLL_ENABLE,
  PHYCTRL_ENDLL_MASK,
  PHYCTRL_ENDLL_SHIFT));
 +
 + /*
 +  * We turned on the DLL even though the rate was 0 because we the
 +  * clock might be turned on later.  ...but we can't wait for the DLL
 +  * to lock when the rate is 0 because it will never lock with no
 +  * input clock.
 +  *
 +  * Technically we should be checking the lock later when the clock
 +  * is turned on, but for now we won't.
 +  */
 + if (rate == 0)
 + return 0;
>>>
>>> Why not return initially from rockchip_emmc_phy_power if the clock rate is 
>>> '0'.
>>> Are there other functions to lock the DLL apart from phy_power?
>>
>> Yeah, it's a big ugly right now.  This ugliness is really needed
>> because 

[PATCH v5 2/2] QE: remove PPCisms for QE

2016-07-24 Thread Zhao Qiang
QE was supported on PowerPC, and dependent on PPC,
Now it is supported on other platforms. so remove PPCisms.

Signed-off-by: Zhao Qiang 
---
Changes for v2:
- na
Changes for v3:
- add NO_IRQ
Changes for v4:
- modify spin_event_timeout to opencoded timeout loop
- remove NO_IRQ
- modify virq_to_hw to opencoed code
Changes for v5:
- modify commit msg
- modify depends of QUICC_ENGINE
- add kerneldoc header for qe_issue_cmd

 drivers/irqchip/qe_ic.c   | 28 +--
 drivers/soc/fsl/qe/Kconfig|  2 +-
 drivers/soc/fsl/qe/qe.c   | 80 ++-
 drivers/soc/fsl/qe/qe_io.c| 42 ++-
 drivers/soc/fsl/qe/qe_tdm.c   |  8 ++---
 drivers/soc/fsl/qe/ucc.c  | 10 +++---
 drivers/soc/fsl/qe/ucc_fast.c | 68 ++--
 include/soc/fsl/qe/qe.h   |  1 -
 include/soc/fsl/qe/qe_ic.h| 12 +++
 9 files changed, 133 insertions(+), 118 deletions(-)

diff --git a/drivers/irqchip/qe_ic.c b/drivers/irqchip/qe_ic.c
index 46652c0..32deb60 100644
--- a/drivers/irqchip/qe_ic.c
+++ b/drivers/irqchip/qe_ic.c
@@ -18,7 +18,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -177,13 +180,13 @@ static struct qe_ic_info qe_ic_info[] = {
 
 static inline u32 qe_ic_read(volatile __be32  __iomem * base, unsigned int reg)
 {
-   return in_be32(base + (reg >> 2));
+   return ioread32be(base + (reg >> 2));
 }
 
 static inline void qe_ic_write(volatile __be32  __iomem * base, unsigned int 
reg,
   u32 value)
 {
-   out_be32(base + (reg >> 2), value);
+   iowrite32be(value, base + (reg >> 2));
 }
 
 static inline struct qe_ic *qe_ic_from_irq(unsigned int virq)
@@ -285,7 +288,7 @@ static const struct irq_domain_ops qe_ic_host_ops = {
.xlate = irq_domain_xlate_onetwocell,
 };
 
-/* Return an interrupt vector or NO_IRQ if no interrupt is pending. */
+/* Return an interrupt vector or 0 if no interrupt is pending. */
 unsigned int qe_ic_get_low_irq(struct qe_ic *qe_ic)
 {
int irq;
@@ -296,12 +299,12 @@ unsigned int qe_ic_get_low_irq(struct qe_ic *qe_ic)
irq = qe_ic_read(qe_ic->regs, QEIC_CIVEC) >> 26;
 
if (irq == 0)
-   return NO_IRQ;
+   return 0;
 
return irq_linear_revmap(qe_ic->irqhost, irq);
 }
 
-/* Return an interrupt vector or NO_IRQ if no interrupt is pending. */
+/* Return an interrupt vector or 0 if no interrupt is pending. */
 unsigned int qe_ic_get_high_irq(struct qe_ic *qe_ic)
 {
int irq;
@@ -312,7 +315,7 @@ unsigned int qe_ic_get_high_irq(struct qe_ic *qe_ic)
irq = qe_ic_read(qe_ic->regs, QEIC_CHIVEC) >> 26;
 
if (irq == 0)
-   return NO_IRQ;
+   return 0;
 
return irq_linear_revmap(qe_ic->irqhost, irq);
 }
@@ -355,7 +358,7 @@ static int __init qe_ic_init(unsigned int flags)
qe_ic->virq_high = irq_of_parse_and_map(node, 0);
qe_ic->virq_low = irq_of_parse_and_map(node, 1);
 
-   if (qe_ic->virq_low == NO_IRQ) {
+   if (qe_ic->virq_low == 0) {
pr_err("Failed to map QE_IC low IRQ\n");
ret = -ENOMEM;
goto err_domain_remove;
@@ -387,7 +390,7 @@ static int __init qe_ic_init(unsigned int flags)
irq_set_handler_data(qe_ic->virq_low, qe_ic);
irq_set_chained_handler(qe_ic->virq_low, qe_ic_cascade_low_mpic);
 
-   if (qe_ic->virq_high != NO_IRQ &&
+   if (qe_ic->virq_high != 0 &&
qe_ic->virq_high != qe_ic->virq_low) {
irq_set_handler_data(qe_ic->virq_high, qe_ic);
irq_set_chained_handler(qe_ic->virq_high,
@@ -407,7 +410,8 @@ err_put_node:
 void qe_ic_set_highest_priority(unsigned int virq, int high)
 {
struct qe_ic *qe_ic = qe_ic_from_irq(virq);
-   unsigned int src = virq_to_hw(virq);
+   struct irq_data *irq_data = irq_get_irq_data(virq);
+   irq_hw_number_t src = WARN_ON(!irq_data) ? 0 : irq_data->hwirq;
u32 temp = 0;
 
temp = qe_ic_read(qe_ic->regs, QEIC_CICR);
@@ -425,7 +429,8 @@ void qe_ic_set_highest_priority(unsigned int virq, int high)
 int qe_ic_set_priority(unsigned int virq, unsigned int priority)
 {
struct qe_ic *qe_ic = qe_ic_from_irq(virq);
-   unsigned int src = virq_to_hw(virq);
+   struct irq_data *irq_data = irq_get_irq_data(virq);
+   irq_hw_number_t src = WARN_ON(!irq_data) ? 0 : irq_data->hwirq;
u32 temp;
 
if (priority > 8 || priority == 0)
@@ -455,7 +460,8 @@ int qe_ic_set_priority(unsigned int virq, unsigned int 
priority)
 int qe_ic_set_high_priority(unsigned int virq, unsigned int priority, int high)
 {
struct qe_ic *qe_ic = qe_ic_from_irq(virq);
-   unsigned int src = virq_to_hw(virq);
+   struct irq_data *irq_data = irq_get_irq_data(virq);
+   irq_hw_number_t src 

[PATCH v5 2/2] QE: remove PPCisms for QE

2016-07-24 Thread Zhao Qiang
QE was supported on PowerPC, and dependent on PPC,
Now it is supported on other platforms. so remove PPCisms.

Signed-off-by: Zhao Qiang 
---
Changes for v2:
- na
Changes for v3:
- add NO_IRQ
Changes for v4:
- modify spin_event_timeout to opencoded timeout loop
- remove NO_IRQ
- modify virq_to_hw to opencoed code
Changes for v5:
- modify commit msg
- modify depends of QUICC_ENGINE
- add kerneldoc header for qe_issue_cmd

 drivers/irqchip/qe_ic.c   | 28 +--
 drivers/soc/fsl/qe/Kconfig|  2 +-
 drivers/soc/fsl/qe/qe.c   | 80 ++-
 drivers/soc/fsl/qe/qe_io.c| 42 ++-
 drivers/soc/fsl/qe/qe_tdm.c   |  8 ++---
 drivers/soc/fsl/qe/ucc.c  | 10 +++---
 drivers/soc/fsl/qe/ucc_fast.c | 68 ++--
 include/soc/fsl/qe/qe.h   |  1 -
 include/soc/fsl/qe/qe_ic.h| 12 +++
 9 files changed, 133 insertions(+), 118 deletions(-)

diff --git a/drivers/irqchip/qe_ic.c b/drivers/irqchip/qe_ic.c
index 46652c0..32deb60 100644
--- a/drivers/irqchip/qe_ic.c
+++ b/drivers/irqchip/qe_ic.c
@@ -18,7 +18,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -177,13 +180,13 @@ static struct qe_ic_info qe_ic_info[] = {
 
 static inline u32 qe_ic_read(volatile __be32  __iomem * base, unsigned int reg)
 {
-   return in_be32(base + (reg >> 2));
+   return ioread32be(base + (reg >> 2));
 }
 
 static inline void qe_ic_write(volatile __be32  __iomem * base, unsigned int 
reg,
   u32 value)
 {
-   out_be32(base + (reg >> 2), value);
+   iowrite32be(value, base + (reg >> 2));
 }
 
 static inline struct qe_ic *qe_ic_from_irq(unsigned int virq)
@@ -285,7 +288,7 @@ static const struct irq_domain_ops qe_ic_host_ops = {
.xlate = irq_domain_xlate_onetwocell,
 };
 
-/* Return an interrupt vector or NO_IRQ if no interrupt is pending. */
+/* Return an interrupt vector or 0 if no interrupt is pending. */
 unsigned int qe_ic_get_low_irq(struct qe_ic *qe_ic)
 {
int irq;
@@ -296,12 +299,12 @@ unsigned int qe_ic_get_low_irq(struct qe_ic *qe_ic)
irq = qe_ic_read(qe_ic->regs, QEIC_CIVEC) >> 26;
 
if (irq == 0)
-   return NO_IRQ;
+   return 0;
 
return irq_linear_revmap(qe_ic->irqhost, irq);
 }
 
-/* Return an interrupt vector or NO_IRQ if no interrupt is pending. */
+/* Return an interrupt vector or 0 if no interrupt is pending. */
 unsigned int qe_ic_get_high_irq(struct qe_ic *qe_ic)
 {
int irq;
@@ -312,7 +315,7 @@ unsigned int qe_ic_get_high_irq(struct qe_ic *qe_ic)
irq = qe_ic_read(qe_ic->regs, QEIC_CHIVEC) >> 26;
 
if (irq == 0)
-   return NO_IRQ;
+   return 0;
 
return irq_linear_revmap(qe_ic->irqhost, irq);
 }
@@ -355,7 +358,7 @@ static int __init qe_ic_init(unsigned int flags)
qe_ic->virq_high = irq_of_parse_and_map(node, 0);
qe_ic->virq_low = irq_of_parse_and_map(node, 1);
 
-   if (qe_ic->virq_low == NO_IRQ) {
+   if (qe_ic->virq_low == 0) {
pr_err("Failed to map QE_IC low IRQ\n");
ret = -ENOMEM;
goto err_domain_remove;
@@ -387,7 +390,7 @@ static int __init qe_ic_init(unsigned int flags)
irq_set_handler_data(qe_ic->virq_low, qe_ic);
irq_set_chained_handler(qe_ic->virq_low, qe_ic_cascade_low_mpic);
 
-   if (qe_ic->virq_high != NO_IRQ &&
+   if (qe_ic->virq_high != 0 &&
qe_ic->virq_high != qe_ic->virq_low) {
irq_set_handler_data(qe_ic->virq_high, qe_ic);
irq_set_chained_handler(qe_ic->virq_high,
@@ -407,7 +410,8 @@ err_put_node:
 void qe_ic_set_highest_priority(unsigned int virq, int high)
 {
struct qe_ic *qe_ic = qe_ic_from_irq(virq);
-   unsigned int src = virq_to_hw(virq);
+   struct irq_data *irq_data = irq_get_irq_data(virq);
+   irq_hw_number_t src = WARN_ON(!irq_data) ? 0 : irq_data->hwirq;
u32 temp = 0;
 
temp = qe_ic_read(qe_ic->regs, QEIC_CICR);
@@ -425,7 +429,8 @@ void qe_ic_set_highest_priority(unsigned int virq, int high)
 int qe_ic_set_priority(unsigned int virq, unsigned int priority)
 {
struct qe_ic *qe_ic = qe_ic_from_irq(virq);
-   unsigned int src = virq_to_hw(virq);
+   struct irq_data *irq_data = irq_get_irq_data(virq);
+   irq_hw_number_t src = WARN_ON(!irq_data) ? 0 : irq_data->hwirq;
u32 temp;
 
if (priority > 8 || priority == 0)
@@ -455,7 +460,8 @@ int qe_ic_set_priority(unsigned int virq, unsigned int 
priority)
 int qe_ic_set_high_priority(unsigned int virq, unsigned int priority, int high)
 {
struct qe_ic *qe_ic = qe_ic_from_irq(virq);
-   unsigned int src = virq_to_hw(virq);
+   struct irq_data *irq_data = irq_get_irq_data(virq);
+   irq_hw_number_t src = 

Re: [RFC PATCH v3 00/13] ACPI IORT ARM SMMU v3 support

2016-07-24 Thread Dennis Chen
Hi
On Wed, Jul 20, 2016 at 12:23:22PM +0100, Lorenzo Pieralisi wrote:
> This RFC patch series is v3 of a previous posting:
> 
> https://lkml.org/lkml/2016/6/7/523
> 
> v2 -> v3
>   - Rebased on top of dependencies series [1][2][3](v4.7-rc3)
>   - Added back reliance on ACPI early probing infrastructure
>   - Patch[1-3] merged through other dependent series
>   - Added back IOMMU fwnode generalization
>   - Move SMMU v3 static functions configuration to IORT code
>   - Implemented generic IOMMU fwspec API
>   - Added code to implement fwnode platform device look-up
> 
> v1 -> v2:
>   - Rebased on top of dependencies series [1][2][3](v4.7-rc1)
>   - Removed IOMMU fwnode generalization
>   - Implemented ARM SMMU v3 ACPI probing instead of ARM SMMU v2
> owing to patch series dependencies [1]
>   - Moved platform device creation logic to IORT code to
> generalize its usage for ARM SMMU v1-v2-v3 components
>   - Removed reliance on ACPI early device probing
>   - Created IORT specific iommu_xlate() translation hook leaving
> OF code unchanged according to v1 reviews
> 
> The ACPI IORT table provides information that allows instantiating
> ARM SMMU devices and carrying out id mappings between components on
> ARM based systems (devices, IOMMUs, interrupt controllers).
> 
> http://infocenter.arm.com/help/topic/com.arm.doc.den0049b/DEN0049B_IO_Remapping_Table.pdf
> 
> Building on basic IORT support, available through [2]:
> 
> this patchset enables ARM SMMU v3 support on ACPI systems.
> 
> Most of the code is aimed at building the required generic ACPI
> infrastructure to create and enable IOMMU components and to bring
> the IOMMU infrastructure for ACPI on par with DT, which is going to
> make future ARM SMMU components easier to integrate.
> 
> PATCH (1) adds a FWNODE_IOMMU type to the struct fwnode_handle type.
>   It is required to attach a fwnode identifier to platform
>   devices allocated/detected through IORT tables entries;
>   IOMMU devices have to have an identifier to look them up
>   eg IOMMU core layer carrying out id translation. This can be
>   done through a fwnode_handle (ie IOMMU platform devices created
>   out of IORT tables are not ACPI devices hence they can't be
>   allocated as such, otherwise they would have a fwnode_handle of
>   type FWNODE_ACPI). This patch requires discussion and it is key
>   to the RFC.
> 
> PATCH (2) makes use of the ACPI early probing API to add a linker script
>   section for probing devices via IORT ACPI kernel code.
> 
> PATCH (3) provides IORT support for registering IOMMU IORT node through
>   their fwnode handle.
> 
> PATCH (4) implements core code fwnode based platform devices look-up.
> 
> PATCH (5) extends iommu_fwspec so that it can be used on ACPI based
>   system by creating a generic IOMMU fwspec kernel layer.
> 
> PATCH (6) implements the of_dma_configure() API in ACPI world -
>   acpi_dma_configure() - and patches PCI and ACPI core code to
>   start making use of it.
> 
> PATCH (7) provides an IORT function to detect existence of specific type
>   of IORT components.
> 
> PATCH (8) creates the kernel infrastructure required to create ARM SMMU
>   platform devices for IORT nodes.
> 
> PATCH (9) refactors the ARM SMMU v3 driver so that the init functions are
>   split in a way that groups together code that probes through DT
>   and code that carries out HW registers FW agnostic probing, in
>   preparation for adding the ACPI probing path.
> 
> PATCH (10) rework ARM SMMU v3 platform driver registration to make it work
>on ACPI systems.
> 
> PATCH (11) Building on patch (8), it adds ARM SMMU v3 IORT IOMMU
>operations to create and probe ARM SMMU v3 components.
> 
> PATCH (12) Extend the IORT iort_node_map_rid() to work on a type mask
>instead of a single type so that the translation API can
>be used on a range of components.
> 
> PATCH (13) provides IORT infrastructure to carry out IOMMU configuration
>for devices and hook it up to the previously introduced ACPI
>DMA configure API.
> 
> This patchset is built on top and depends on these three patch series:
> 
> [1] R.Murphy "Generic DT bindings for PCI and ARM SMMU v3" v4
> https://marc.info/?l=devicetree=146739193215518=2
> 
> [2] T.Nowicki "Introduce ACPI world to ITS irqchip" v7
> https://marc.info/?l=linux-arm-kernel=146642080022289=2
> 
> [3] T.Nowicki "Support for ARM64 ACPI based PCI host controller" v8
> http://marc.info/?l=linux-acpi=146462129816292=2
> 
> and is provided for early review/testing purposes here:
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/lpieralisi/linux.git 
> acpi/iort-smmu-v3i
>
I thought I can got all the 13 patches applied with the above git tree, but I 
can't 

Re: [RFC PATCH v3 00/13] ACPI IORT ARM SMMU v3 support

2016-07-24 Thread Dennis Chen
Hi
On Wed, Jul 20, 2016 at 12:23:22PM +0100, Lorenzo Pieralisi wrote:
> This RFC patch series is v3 of a previous posting:
> 
> https://lkml.org/lkml/2016/6/7/523
> 
> v2 -> v3
>   - Rebased on top of dependencies series [1][2][3](v4.7-rc3)
>   - Added back reliance on ACPI early probing infrastructure
>   - Patch[1-3] merged through other dependent series
>   - Added back IOMMU fwnode generalization
>   - Move SMMU v3 static functions configuration to IORT code
>   - Implemented generic IOMMU fwspec API
>   - Added code to implement fwnode platform device look-up
> 
> v1 -> v2:
>   - Rebased on top of dependencies series [1][2][3](v4.7-rc1)
>   - Removed IOMMU fwnode generalization
>   - Implemented ARM SMMU v3 ACPI probing instead of ARM SMMU v2
> owing to patch series dependencies [1]
>   - Moved platform device creation logic to IORT code to
> generalize its usage for ARM SMMU v1-v2-v3 components
>   - Removed reliance on ACPI early device probing
>   - Created IORT specific iommu_xlate() translation hook leaving
> OF code unchanged according to v1 reviews
> 
> The ACPI IORT table provides information that allows instantiating
> ARM SMMU devices and carrying out id mappings between components on
> ARM based systems (devices, IOMMUs, interrupt controllers).
> 
> http://infocenter.arm.com/help/topic/com.arm.doc.den0049b/DEN0049B_IO_Remapping_Table.pdf
> 
> Building on basic IORT support, available through [2]:
> 
> this patchset enables ARM SMMU v3 support on ACPI systems.
> 
> Most of the code is aimed at building the required generic ACPI
> infrastructure to create and enable IOMMU components and to bring
> the IOMMU infrastructure for ACPI on par with DT, which is going to
> make future ARM SMMU components easier to integrate.
> 
> PATCH (1) adds a FWNODE_IOMMU type to the struct fwnode_handle type.
>   It is required to attach a fwnode identifier to platform
>   devices allocated/detected through IORT tables entries;
>   IOMMU devices have to have an identifier to look them up
>   eg IOMMU core layer carrying out id translation. This can be
>   done through a fwnode_handle (ie IOMMU platform devices created
>   out of IORT tables are not ACPI devices hence they can't be
>   allocated as such, otherwise they would have a fwnode_handle of
>   type FWNODE_ACPI). This patch requires discussion and it is key
>   to the RFC.
> 
> PATCH (2) makes use of the ACPI early probing API to add a linker script
>   section for probing devices via IORT ACPI kernel code.
> 
> PATCH (3) provides IORT support for registering IOMMU IORT node through
>   their fwnode handle.
> 
> PATCH (4) implements core code fwnode based platform devices look-up.
> 
> PATCH (5) extends iommu_fwspec so that it can be used on ACPI based
>   system by creating a generic IOMMU fwspec kernel layer.
> 
> PATCH (6) implements the of_dma_configure() API in ACPI world -
>   acpi_dma_configure() - and patches PCI and ACPI core code to
>   start making use of it.
> 
> PATCH (7) provides an IORT function to detect existence of specific type
>   of IORT components.
> 
> PATCH (8) creates the kernel infrastructure required to create ARM SMMU
>   platform devices for IORT nodes.
> 
> PATCH (9) refactors the ARM SMMU v3 driver so that the init functions are
>   split in a way that groups together code that probes through DT
>   and code that carries out HW registers FW agnostic probing, in
>   preparation for adding the ACPI probing path.
> 
> PATCH (10) rework ARM SMMU v3 platform driver registration to make it work
>on ACPI systems.
> 
> PATCH (11) Building on patch (8), it adds ARM SMMU v3 IORT IOMMU
>operations to create and probe ARM SMMU v3 components.
> 
> PATCH (12) Extend the IORT iort_node_map_rid() to work on a type mask
>instead of a single type so that the translation API can
>be used on a range of components.
> 
> PATCH (13) provides IORT infrastructure to carry out IOMMU configuration
>for devices and hook it up to the previously introduced ACPI
>DMA configure API.
> 
> This patchset is built on top and depends on these three patch series:
> 
> [1] R.Murphy "Generic DT bindings for PCI and ARM SMMU v3" v4
> https://marc.info/?l=devicetree=146739193215518=2
> 
> [2] T.Nowicki "Introduce ACPI world to ITS irqchip" v7
> https://marc.info/?l=linux-arm-kernel=146642080022289=2
> 
> [3] T.Nowicki "Support for ARM64 ACPI based PCI host controller" v8
> http://marc.info/?l=linux-acpi=146462129816292=2
> 
> and is provided for early review/testing purposes here:
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/lpieralisi/linux.git 
> acpi/iort-smmu-v3i
>
I thought I can got all the 13 patches applied with the above git tree, but I 
can't 

Re: [PATCH 3.12 28/88] netfilter: x_tables: validate targets of jumps

2016-07-24 Thread Michal Kubecek
On Thu, Jul 21, 2016 at 09:00:33PM +0200, Jiri Slaby wrote:
> On 07/21/2016, 08:56 PM, Greg KH wrote:
> > On Thu, Jul 21, 2016 at 08:36:18AM +0200, Jiri Slaby wrote:
> >> On 07/14/2016, 10:15 AM, Jiri Slaby wrote:
> >>> From: Florian Westphal 
> >>>
> >>> 3.12-stable review patch.  If anyone has any objections, please let me 
> >>> know.
> >>>
> >>> ===
> >>>
> >>> commit 36472341017529e2b12573093cc0f68719300997 upstream.
> >>
> >> I am now dropping this one. 3.12.62 will be released without that patch.
> >> After the performance issue is resolved, it will be requeued.
> > 
> > Personally, I think the bug fixes were more important than the
> > performance issues at this point in time, but it's your call to make :)
> 
> Ok, but to quote [1]:
> iptables-restore will take forever (gave up after 10 minutes)
> 
> I would say it proved itself not to be a performance issue, but rather a
> functional issue :). Both Pablo and Florian suggested to postpone the patch.

Even worse: because of a shared lock which is held for all this time,
this allows (on kernel >= 3.8) an unprivileged user to block similar
operation in all network namespaces including init_net.

While a partial DoS like this is certainly better than allowing to crash
the system, it could still be considered a security issue.

Michal Kubecek


Re: [PATCH 3.12 28/88] netfilter: x_tables: validate targets of jumps

2016-07-24 Thread Michal Kubecek
On Thu, Jul 21, 2016 at 09:00:33PM +0200, Jiri Slaby wrote:
> On 07/21/2016, 08:56 PM, Greg KH wrote:
> > On Thu, Jul 21, 2016 at 08:36:18AM +0200, Jiri Slaby wrote:
> >> On 07/14/2016, 10:15 AM, Jiri Slaby wrote:
> >>> From: Florian Westphal 
> >>>
> >>> 3.12-stable review patch.  If anyone has any objections, please let me 
> >>> know.
> >>>
> >>> ===
> >>>
> >>> commit 36472341017529e2b12573093cc0f68719300997 upstream.
> >>
> >> I am now dropping this one. 3.12.62 will be released without that patch.
> >> After the performance issue is resolved, it will be requeued.
> > 
> > Personally, I think the bug fixes were more important than the
> > performance issues at this point in time, but it's your call to make :)
> 
> Ok, but to quote [1]:
> iptables-restore will take forever (gave up after 10 minutes)
> 
> I would say it proved itself not to be a performance issue, but rather a
> functional issue :). Both Pablo and Florian suggested to postpone the patch.

Even worse: because of a shared lock which is held for all this time,
this allows (on kernel >= 3.8) an unprivileged user to block similar
operation in all network namespaces including init_net.

While a partial DoS like this is certainly better than allowing to crash
the system, it could still be considered a security issue.

Michal Kubecek


RE: Why does BIOS assign memory to 16 byte BAR

2016-07-24 Thread Bharat Kumar Gogada
> Subject: RE: Why does BIOS assign memory to 16 byte BAR
> 
> > Subject: Re: Why does BIOS assign memory to 16 byte BAR
> >
> > On Fri, Jul 22, 2016 at 10:15:46AM -0500, Bjorn Helgaas wrote:
> > > Hi Bharat,
> > >
> > > On Fri, Jul 22, 2016 at 09:24:22AM +, Bharat Kumar Gogada wrote:
> > > > Hi,
> > > >
> > > > I'm observing that on x86 BIOS successfully assigns memory if an End
> > > > point requests BAR of size 16byte.
> > > >
> > > > But as per Spec:
> > > > The minimum memory address range requested by a BAR is 128 bytes.
> > >
> > > Can you provide the spec reference for this?  I don't see it in PCI
> > > r3.0.
> > >
> > > PCI r3.0, sec 6.2.5.1, shows bits 4-31 of a memory BAR as writable,
> > > which would correspond to a minimum size of 16 bytes.
> >
> > The reference above is to the conventional PCI spec.  I happened to trip
> over
> > a note in PCIe r3.0, sec 1.3.2.2, that for a PCI Express endpoint, "the
> minimum
> > memory address range requested by a BAR is 128 bytes."
> >
> > I don't think linux currently enforces this minimum.
> >
> 
> Hi Bjorn Thanks for the reply.
> 
> Here is what the issue we are seeing.
> 
> We have total memory for BAR's on our SoC of 256 MB.
> When an End Point request individually 16 byte BAR's our root port assigns
> memory to BAR's successfully.
> 
> But if I have an End point which has 4 BAR's each 32 bit and request as
> following:
> When 1st BAR requests 1GB BAR it fails due to lack of memory. (We are
> running this as part of SIG compliance test case)
> 2nd BAR requests 1MB and other 2 BAR's request 16byte, but these are not
> getting BAR's assigned. (Even though BAR space is available, since 1GB failed,
> We have 256 MB still)
> 
> We have only one End point connected to our root port.
> 
> Here is the log:
> [2.319289] nwl-pcie fd0e.pcie: Link is UP
> [2.319332] PCI host bridge /amba/pcie@fd0e ranges:
> [2.319349]   No bus range found for /amba/pcie@fd0e, using [bus 00-
> ff]
> [2.319374]IO 0xe000..0xe000 -> 0x
> [2.319415]   MEM 0xe010..0xefff -> 0xe010
> [2.319431]   MEM 0x6..0x7 -> 0x6
> [2.319539] nwl-pcie fd0e.pcie: PCI host bridge to bus :00
> [2.319557] pci_bus :00: root bus resource [bus 00-ff]
> [2.319573] pci_bus :00: root bus resource [io  0x-0x]
> [2.319589] pci_bus :00: root bus resource [mem 0xe010-0xefff]
> [2.319606] pci_bus :00: root bus resource [mem 0x6-
> 0x7 pref]
> [2.319845] pci :00:00.0: cannot attach to SMMU, is it on the same bus?
> [2.319861] iommu: Adding device :00:00.0 to group 1
> [2.320243] pci :01:00.0: cannot attach to SMMU, is it on the same bus?
> [2.320258] iommu: Adding device :01:00.0 to group 1
> [2.320313] pci :00:00.0: BAR 8: no space for [mem size 0x6000]
> [2.320331] pci :00:00.0: BAR 8: failed to assign [mem size 0x6000]
> [2.320349] pci :00:00.0: BAR 6: assigned [mem 0xe010-0xe01007ff
> pref]
> [2.320374] pci :01:00.0: BAR 0: no space for [mem size 0x4000]
> [2.320390] pci :01:00.0: BAR 0: failed to assign [mem size 0x4000]
> [2.320407] pci :01:00.0: BAR 4: no space for [mem size 0x0010
> 64bit]
> [2.320423] pci :01:00.0: BAR 4: failed to assign [mem size 0x0010
> 64bit]
> [2.320446] pci :01:00.0: BAR 2: no space for [mem size 0x0010]
> [2.320461] pci :01:00.0: BAR 2: failed to assign [mem size 0x0010]
> [2.320477] pci :01:00.0: BAR 3: no space for [mem size 0x0010]
> [2.320493] pci :01:00.0: BAR 3: failed to assign [mem size 0x0010]
> [2.320509] pci :00:00.0: PCI bridge to [bus 01-0c]
> 
> Please let me know, what might might be the issue.
> 

Adding to the above will kernel allocate other memory BARs to an End Point if 
one BAR assignment fails ?

What if the End Point has multiple function and say first function BAR 
assignment failed,
will the kernel assign BAR's to second function on same bus and device ?  

Thanks & Regards,
Bharat


RE: Why does BIOS assign memory to 16 byte BAR

2016-07-24 Thread Bharat Kumar Gogada
> Subject: RE: Why does BIOS assign memory to 16 byte BAR
> 
> > Subject: Re: Why does BIOS assign memory to 16 byte BAR
> >
> > On Fri, Jul 22, 2016 at 10:15:46AM -0500, Bjorn Helgaas wrote:
> > > Hi Bharat,
> > >
> > > On Fri, Jul 22, 2016 at 09:24:22AM +, Bharat Kumar Gogada wrote:
> > > > Hi,
> > > >
> > > > I'm observing that on x86 BIOS successfully assigns memory if an End
> > > > point requests BAR of size 16byte.
> > > >
> > > > But as per Spec:
> > > > The minimum memory address range requested by a BAR is 128 bytes.
> > >
> > > Can you provide the spec reference for this?  I don't see it in PCI
> > > r3.0.
> > >
> > > PCI r3.0, sec 6.2.5.1, shows bits 4-31 of a memory BAR as writable,
> > > which would correspond to a minimum size of 16 bytes.
> >
> > The reference above is to the conventional PCI spec.  I happened to trip
> over
> > a note in PCIe r3.0, sec 1.3.2.2, that for a PCI Express endpoint, "the
> minimum
> > memory address range requested by a BAR is 128 bytes."
> >
> > I don't think linux currently enforces this minimum.
> >
> 
> Hi Bjorn Thanks for the reply.
> 
> Here is what the issue we are seeing.
> 
> We have total memory for BAR's on our SoC of 256 MB.
> When an End Point request individually 16 byte BAR's our root port assigns
> memory to BAR's successfully.
> 
> But if I have an End point which has 4 BAR's each 32 bit and request as
> following:
> When 1st BAR requests 1GB BAR it fails due to lack of memory. (We are
> running this as part of SIG compliance test case)
> 2nd BAR requests 1MB and other 2 BAR's request 16byte, but these are not
> getting BAR's assigned. (Even though BAR space is available, since 1GB failed,
> We have 256 MB still)
> 
> We have only one End point connected to our root port.
> 
> Here is the log:
> [2.319289] nwl-pcie fd0e.pcie: Link is UP
> [2.319332] PCI host bridge /amba/pcie@fd0e ranges:
> [2.319349]   No bus range found for /amba/pcie@fd0e, using [bus 00-
> ff]
> [2.319374]IO 0xe000..0xe000 -> 0x
> [2.319415]   MEM 0xe010..0xefff -> 0xe010
> [2.319431]   MEM 0x6..0x7 -> 0x6
> [2.319539] nwl-pcie fd0e.pcie: PCI host bridge to bus :00
> [2.319557] pci_bus :00: root bus resource [bus 00-ff]
> [2.319573] pci_bus :00: root bus resource [io  0x-0x]
> [2.319589] pci_bus :00: root bus resource [mem 0xe010-0xefff]
> [2.319606] pci_bus :00: root bus resource [mem 0x6-
> 0x7 pref]
> [2.319845] pci :00:00.0: cannot attach to SMMU, is it on the same bus?
> [2.319861] iommu: Adding device :00:00.0 to group 1
> [2.320243] pci :01:00.0: cannot attach to SMMU, is it on the same bus?
> [2.320258] iommu: Adding device :01:00.0 to group 1
> [2.320313] pci :00:00.0: BAR 8: no space for [mem size 0x6000]
> [2.320331] pci :00:00.0: BAR 8: failed to assign [mem size 0x6000]
> [2.320349] pci :00:00.0: BAR 6: assigned [mem 0xe010-0xe01007ff
> pref]
> [2.320374] pci :01:00.0: BAR 0: no space for [mem size 0x4000]
> [2.320390] pci :01:00.0: BAR 0: failed to assign [mem size 0x4000]
> [2.320407] pci :01:00.0: BAR 4: no space for [mem size 0x0010
> 64bit]
> [2.320423] pci :01:00.0: BAR 4: failed to assign [mem size 0x0010
> 64bit]
> [2.320446] pci :01:00.0: BAR 2: no space for [mem size 0x0010]
> [2.320461] pci :01:00.0: BAR 2: failed to assign [mem size 0x0010]
> [2.320477] pci :01:00.0: BAR 3: no space for [mem size 0x0010]
> [2.320493] pci :01:00.0: BAR 3: failed to assign [mem size 0x0010]
> [2.320509] pci :00:00.0: PCI bridge to [bus 01-0c]
> 
> Please let me know, what might might be the issue.
> 

Adding to the above will kernel allocate other memory BARs to an End Point if 
one BAR assignment fails ?

What if the End Point has multiple function and say first function BAR 
assignment failed,
will the kernel assign BAR's to second function on same bus and device ?  

Thanks & Regards,
Bharat


Re: [PATCH] PM / OPP: optimize dev_pm_opp_set_rate() a bit

2016-07-24 Thread Jisheng Zhang
Dear all,

On Fri, 22 Jul 2016 22:30:53 +0800 kbuild test robot wrote:

> Hi,
> 
> [auto build test WARNING on pm/linux-next]
> [also build test WARNING on v4.7-rc7 next-20160722]
> [if your patch is applied to the wrong git tree, please drop us a note to 
> help improve the system]
> 
> url:
> https://github.com/0day-ci/linux/commits/Jisheng-Zhang/PM-OPP-optimize-dev_pm_opp_set_rate-a-bit/20160722-205339
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git 
> linux-next
> config: x86_64-allmodconfig (attached as .config)
> compiler: gcc-6 (Debian 6.1.1-9) 6.1.1 20160705
> reproduce:
> # save the attached .config to linux build tree
> make ARCH=x86_64 
> 
> Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
> http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings
> 
> All warnings (new ones prefixed by >>):
> 
>drivers/base/power/opp/core.c: In function 'dev_pm_opp_set_rate':
> >> drivers/base/power/opp/core.c:666:3: warning: 'ou_volt_max' may be used 
> >> uninitialized in this function [-Wmaybe-uninitialized]  
>   _set_opp_voltage(dev, reg, ou_volt, ou_volt_min, ou_volt_max);
>   ^
> >> drivers/base/power/opp/core.c:666:3: warning: 'ou_volt_min' may be used 
> >> uninitialized in this function [-Wmaybe-uninitialized]
> >> drivers/base/power/opp/core.c:666:3: warning: 'ou_volt' may be used 
> >> uninitialized in this function [-Wmaybe-uninitialized]  

These warnings seem weired. We only use them when !IS_ERR(old_opp), and we
should already set them if !IS_ERR(old_opp). Another weired thing is if
we add something, printk e.g in _find_freq_ceil(), then these warnings disappear

Could you please kindly give some suggestions about how to fix these warnings?

Thanks,
Jisheng

> 
> vim +/ou_volt_max +666 drivers/base/power/opp/core.c
> 
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  650   if 
> (freq < old_freq) {
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  651   
> ret = _set_opp_voltage(dev, reg, u_volt, u_volt_min,
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  652   
>u_volt_max);
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  653   
> if (ret)
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  654   
> goto restore_freq;
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  655   }
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  656  
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  657   return 
> 0;
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  658  
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  659  
> restore_freq:
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  660   if 
> (clk_set_rate(clk, old_freq))
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  661   
> dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n",
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  662   
> __func__, old_freq);
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  663  
> restore_voltage:
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  664   /* This 
> shouldn't harm even if the voltages weren't updated earlier */
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  665   if 
> (!IS_ERR(old_opp))
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09 @666   
> _set_opp_voltage(dev, reg, ou_volt, ou_volt_min, ou_volt_max);
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  667  
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  668   return 
> ret;
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  669  }
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  670  
> EXPORT_SYMBOL_GPL(dev_pm_opp_set_rate);
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  671  
> 2c2709dc drivers/base/power/opp/core.c Viresh Kumar 2016-02-16  672  /* 
> OPP-dev Helpers */
> 2c2709dc drivers/base/power/opp/core.c Viresh Kumar 2016-02-16  673  static 
> void _kfree_opp_dev_rcu(struct rcu_head *head)
> 06441658 drivers/base/power/opp.c  Viresh Kumar 2015-07-29  674  {
> 
> :: The code at line 666 was first introduced by commit
> :: 6a0712f6f199e737aa5913d28ec4bd3a25de9660 PM / OPP: Add 
> dev_pm_opp_set_rate()
> 
> :: TO: Viresh Kumar 
> :: CC: Rafael J. Wysocki 
> 
> ---
> 0-DAY kernel test infrastructureOpen Source Technology Center
> https://lists.01.org/pipermail/kbuild-all   Intel Corporation



Re: [PATCH] PM / OPP: optimize dev_pm_opp_set_rate() a bit

2016-07-24 Thread Jisheng Zhang
Dear all,

On Fri, 22 Jul 2016 22:30:53 +0800 kbuild test robot wrote:

> Hi,
> 
> [auto build test WARNING on pm/linux-next]
> [also build test WARNING on v4.7-rc7 next-20160722]
> [if your patch is applied to the wrong git tree, please drop us a note to 
> help improve the system]
> 
> url:
> https://github.com/0day-ci/linux/commits/Jisheng-Zhang/PM-OPP-optimize-dev_pm_opp_set_rate-a-bit/20160722-205339
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git 
> linux-next
> config: x86_64-allmodconfig (attached as .config)
> compiler: gcc-6 (Debian 6.1.1-9) 6.1.1 20160705
> reproduce:
> # save the attached .config to linux build tree
> make ARCH=x86_64 
> 
> Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
> http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings
> 
> All warnings (new ones prefixed by >>):
> 
>drivers/base/power/opp/core.c: In function 'dev_pm_opp_set_rate':
> >> drivers/base/power/opp/core.c:666:3: warning: 'ou_volt_max' may be used 
> >> uninitialized in this function [-Wmaybe-uninitialized]  
>   _set_opp_voltage(dev, reg, ou_volt, ou_volt_min, ou_volt_max);
>   ^
> >> drivers/base/power/opp/core.c:666:3: warning: 'ou_volt_min' may be used 
> >> uninitialized in this function [-Wmaybe-uninitialized]
> >> drivers/base/power/opp/core.c:666:3: warning: 'ou_volt' may be used 
> >> uninitialized in this function [-Wmaybe-uninitialized]  

These warnings seem weired. We only use them when !IS_ERR(old_opp), and we
should already set them if !IS_ERR(old_opp). Another weired thing is if
we add something, printk e.g in _find_freq_ceil(), then these warnings disappear

Could you please kindly give some suggestions about how to fix these warnings?

Thanks,
Jisheng

> 
> vim +/ou_volt_max +666 drivers/base/power/opp/core.c
> 
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  650   if 
> (freq < old_freq) {
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  651   
> ret = _set_opp_voltage(dev, reg, u_volt, u_volt_min,
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  652   
>u_volt_max);
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  653   
> if (ret)
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  654   
> goto restore_freq;
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  655   }
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  656  
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  657   return 
> 0;
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  658  
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  659  
> restore_freq:
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  660   if 
> (clk_set_rate(clk, old_freq))
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  661   
> dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n",
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  662   
> __func__, old_freq);
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  663  
> restore_voltage:
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  664   /* This 
> shouldn't harm even if the voltages weren't updated earlier */
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  665   if 
> (!IS_ERR(old_opp))
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09 @666   
> _set_opp_voltage(dev, reg, ou_volt, ou_volt_min, ou_volt_max);
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  667  
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  668   return 
> ret;
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  669  }
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  670  
> EXPORT_SYMBOL_GPL(dev_pm_opp_set_rate);
> 6a0712f6 drivers/base/power/opp/core.c Viresh Kumar 2016-02-09  671  
> 2c2709dc drivers/base/power/opp/core.c Viresh Kumar 2016-02-16  672  /* 
> OPP-dev Helpers */
> 2c2709dc drivers/base/power/opp/core.c Viresh Kumar 2016-02-16  673  static 
> void _kfree_opp_dev_rcu(struct rcu_head *head)
> 06441658 drivers/base/power/opp.c  Viresh Kumar 2015-07-29  674  {
> 
> :: The code at line 666 was first introduced by commit
> :: 6a0712f6f199e737aa5913d28ec4bd3a25de9660 PM / OPP: Add 
> dev_pm_opp_set_rate()
> 
> :: TO: Viresh Kumar 
> :: CC: Rafael J. Wysocki 
> 
> ---
> 0-DAY kernel test infrastructureOpen Source Technology Center
> https://lists.01.org/pipermail/kbuild-all   Intel Corporation



Re: [PATCH] net: neigh: disallow state transition DELAY->STALE in neigh_update()

2016-07-24 Thread YOSHIFUJI Hideaki/吉藤英明
Hi,

Chunhui He wrote:
> Hi,
> 
> On Fri, 22 Jul 2016 10:20:01 +0300 (EEST), Julian Anastasov  
> wrote:
>>
>>  Hello,
>>
>> On Thu, 21 Jul 2016, Chunhui He wrote:
>>
>>> If neigh entry was CONNECTED and address is not changed, and if new state is
>>> STALE, entry state will not change. Because DELAY is not in CONNECTED, it's
>>> possible to change state from DELAY to STALE.
>>>
>>> That is bad. Consider a host in IPv4 nerwork, a neigh entry in STALE state
>>> is referenced to send packets, so goes to DELAY state. If the entry is not
>>> confirmed by upper layer, it goes to PROBE state, and sends ARP request.
>>> The neigh host sends ARP reply, then the entry goes to REACHABLE state.
>>> But the entry state may be reseted to STALE by broadcast ARP packets, before
>>> the entry goes to PROBE state. So it's possible that the entry will never go
>>> to REACHABLE state, without external confirmation.
>>>
>>> In my case, the gateway refuses to send unicast packets to me, before it 
>>> sees
>>> my ARP request. So it's critical to enter REACHABLE state by sending ARP
>>> request, but not by external confirmation.
>>>
>>> This fixes neigh_update() not to change to STALE if old state is CONNECTED 
>>> or
>>> DELAY.
>>>
>>> Signed-off-by: Chunhui He 
>>> ---
>>>  net/core/neighbour.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/net/core/neighbour.c b/net/core/neighbour.c
>>> index 510cd62..29429eb 100644
>>> --- a/net/core/neighbour.c
>>> +++ b/net/core/neighbour.c
>>> @@ -1152,7 +1152,7 @@ int neigh_update(struct neighbour *neigh, const u8 
>>> *lladdr, u8 new,
>>> } else {
>>> if (lladdr == neigh->ha && new == NUD_STALE &&
>>> ((flags & NEIGH_UPDATE_F_WEAK_OVERRIDE) ||
>>> -(old & NUD_CONNECTED))
>>> +(old & (NUD_CONNECTED | NUD_DELAY)))
>>> )
>>> new = old;
>>> }
>>
>>  You change looks correct to me. But this place
>> has more problems. There is no good reason to set NUD_STALE
>> for any state that is NUD_VALID if address is not changed.
>> This matches perfectly the comment above this code:
>> NUD_STALE should change a NUD_VALID state only when
>> address changes. It also means that IPv6 does not need
>> to provide NEIGH_UPDATE_F_WEAK_OVERRIDE anymore when
>> NEIGH_UPDATE_F_OVERRIDE is also present.
>>
> 
> The NEIGH_UPDATE_F_WEAK_OVERRIDE is confusing to me, so I choose not to deal
> with the flag.

IPv6 depends on WEAK_OVERRIDE.  Please do not change.

> 
>>  By this way the state machine can continue with
>> the resolving: NUD_STALE -> NUD_DELAY (traffic) ->
>> NUD_PROBE (retries) -> NUD_REACHABLE (unicast reply)
>> while the address is not changed. Your change covers only
>> NUD_DELAY, not NUD_PROBE, so it is better to allow more
>> retries to send. We should not give up until success (NUD_REACHABLE).
>>
> 
> I have thought about this.
> The origin code allows NUD_DELAY -> NUD_STALE and NUD_PROBE -> NUD_STALE.
> This part was imported to kernel since v2.1.79, I don't know clearly why it
> allows that.
> 
> My analysis:
> (1) As shown in my previous mail, NUD_DELAY -> NUD_STALE may cause "dead 
> loop",
> so it should be fixed.
> 
> (2) But NUD_PROBE -> NUD_STALE is acceptable, because in NUD_PROBE, ARP 
> request
> has been sent, it is sufficient to break the "dead loop".
> More attempts are accomplished by the following sequence:
> NUD_STALE --> NUD_DELAY -(sent req)-> NUD_PROBE -(reset by neigh_update())->
> NUD_STALE --> NUD_DELAY -(send req again)-> ... -->
> NUD_REACHABLE
> 
> 
> But I also agree your change.
> 
>>  Second problem: NEIGH_UPDATE_F_WEAK_OVERRIDE has no
>> priority over NEIGH_UPDATE_F_ADMIN. For example, now I can not
>> change from NUD_PERMANENT to NUD_STALE:
>>
>> # ip neigh add 192.168.168.111 lladdr 00:11:22:33:44:55 nud perm dev wlan0
>> # ip neigh show to 192.168.168.111
>> 192.168.168.111 dev wlan0 lladdr 00:11:22:33:44:55 PERMANENT
>> # ip neigh change 192.168.168.111 lladdr 00:11:22:33:44:55 nud stale dev 
>> wlan0
>> # ip neigh show to 192.168.168.111
>> 192.168.168.111 dev wlan0 lladdr 00:11:22:33:44:55 PERMANENT
>>
>>  IMHO, here is how this place should look:
>>
>> diff --git a/net/core/neighbour.c b/net/core/neighbour.c
>> index 5cdc62a..2b1cb91 100644
>> --- a/net/core/neighbour.c
>> +++ b/net/core/neighbour.c
>> @@ -1151,10 +1151,8 @@ int neigh_update(struct neighbour *neigh, const u8 
>> *lladdr, u8 new,
>>  goto out;
>>  } else {
>>  if (lladdr == neigh->ha && new == NUD_STALE &&
>> -((flags & NEIGH_UPDATE_F_WEAK_OVERRIDE) ||
>> - (old & NUD_CONNECTED))
>> -)
>> -new = old;
>> +!(flags & NEIGH_UPDATE_F_ADMIN))
>> +  

Re: [PATCH] net: neigh: disallow state transition DELAY->STALE in neigh_update()

2016-07-24 Thread YOSHIFUJI Hideaki/吉藤英明
Hi,

Chunhui He wrote:
> Hi,
> 
> On Fri, 22 Jul 2016 10:20:01 +0300 (EEST), Julian Anastasov  
> wrote:
>>
>>  Hello,
>>
>> On Thu, 21 Jul 2016, Chunhui He wrote:
>>
>>> If neigh entry was CONNECTED and address is not changed, and if new state is
>>> STALE, entry state will not change. Because DELAY is not in CONNECTED, it's
>>> possible to change state from DELAY to STALE.
>>>
>>> That is bad. Consider a host in IPv4 nerwork, a neigh entry in STALE state
>>> is referenced to send packets, so goes to DELAY state. If the entry is not
>>> confirmed by upper layer, it goes to PROBE state, and sends ARP request.
>>> The neigh host sends ARP reply, then the entry goes to REACHABLE state.
>>> But the entry state may be reseted to STALE by broadcast ARP packets, before
>>> the entry goes to PROBE state. So it's possible that the entry will never go
>>> to REACHABLE state, without external confirmation.
>>>
>>> In my case, the gateway refuses to send unicast packets to me, before it 
>>> sees
>>> my ARP request. So it's critical to enter REACHABLE state by sending ARP
>>> request, but not by external confirmation.
>>>
>>> This fixes neigh_update() not to change to STALE if old state is CONNECTED 
>>> or
>>> DELAY.
>>>
>>> Signed-off-by: Chunhui He 
>>> ---
>>>  net/core/neighbour.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/net/core/neighbour.c b/net/core/neighbour.c
>>> index 510cd62..29429eb 100644
>>> --- a/net/core/neighbour.c
>>> +++ b/net/core/neighbour.c
>>> @@ -1152,7 +1152,7 @@ int neigh_update(struct neighbour *neigh, const u8 
>>> *lladdr, u8 new,
>>> } else {
>>> if (lladdr == neigh->ha && new == NUD_STALE &&
>>> ((flags & NEIGH_UPDATE_F_WEAK_OVERRIDE) ||
>>> -(old & NUD_CONNECTED))
>>> +(old & (NUD_CONNECTED | NUD_DELAY)))
>>> )
>>> new = old;
>>> }
>>
>>  You change looks correct to me. But this place
>> has more problems. There is no good reason to set NUD_STALE
>> for any state that is NUD_VALID if address is not changed.
>> This matches perfectly the comment above this code:
>> NUD_STALE should change a NUD_VALID state only when
>> address changes. It also means that IPv6 does not need
>> to provide NEIGH_UPDATE_F_WEAK_OVERRIDE anymore when
>> NEIGH_UPDATE_F_OVERRIDE is also present.
>>
> 
> The NEIGH_UPDATE_F_WEAK_OVERRIDE is confusing to me, so I choose not to deal
> with the flag.

IPv6 depends on WEAK_OVERRIDE.  Please do not change.

> 
>>  By this way the state machine can continue with
>> the resolving: NUD_STALE -> NUD_DELAY (traffic) ->
>> NUD_PROBE (retries) -> NUD_REACHABLE (unicast reply)
>> while the address is not changed. Your change covers only
>> NUD_DELAY, not NUD_PROBE, so it is better to allow more
>> retries to send. We should not give up until success (NUD_REACHABLE).
>>
> 
> I have thought about this.
> The origin code allows NUD_DELAY -> NUD_STALE and NUD_PROBE -> NUD_STALE.
> This part was imported to kernel since v2.1.79, I don't know clearly why it
> allows that.
> 
> My analysis:
> (1) As shown in my previous mail, NUD_DELAY -> NUD_STALE may cause "dead 
> loop",
> so it should be fixed.
> 
> (2) But NUD_PROBE -> NUD_STALE is acceptable, because in NUD_PROBE, ARP 
> request
> has been sent, it is sufficient to break the "dead loop".
> More attempts are accomplished by the following sequence:
> NUD_STALE --> NUD_DELAY -(sent req)-> NUD_PROBE -(reset by neigh_update())->
> NUD_STALE --> NUD_DELAY -(send req again)-> ... -->
> NUD_REACHABLE
> 
> 
> But I also agree your change.
> 
>>  Second problem: NEIGH_UPDATE_F_WEAK_OVERRIDE has no
>> priority over NEIGH_UPDATE_F_ADMIN. For example, now I can not
>> change from NUD_PERMANENT to NUD_STALE:
>>
>> # ip neigh add 192.168.168.111 lladdr 00:11:22:33:44:55 nud perm dev wlan0
>> # ip neigh show to 192.168.168.111
>> 192.168.168.111 dev wlan0 lladdr 00:11:22:33:44:55 PERMANENT
>> # ip neigh change 192.168.168.111 lladdr 00:11:22:33:44:55 nud stale dev 
>> wlan0
>> # ip neigh show to 192.168.168.111
>> 192.168.168.111 dev wlan0 lladdr 00:11:22:33:44:55 PERMANENT
>>
>>  IMHO, here is how this place should look:
>>
>> diff --git a/net/core/neighbour.c b/net/core/neighbour.c
>> index 5cdc62a..2b1cb91 100644
>> --- a/net/core/neighbour.c
>> +++ b/net/core/neighbour.c
>> @@ -1151,10 +1151,8 @@ int neigh_update(struct neighbour *neigh, const u8 
>> *lladdr, u8 new,
>>  goto out;
>>  } else {
>>  if (lladdr == neigh->ha && new == NUD_STALE &&
>> -((flags & NEIGH_UPDATE_F_WEAK_OVERRIDE) ||
>> - (old & NUD_CONNECTED))
>> -)
>> -new = old;
>> +!(flags & NEIGH_UPDATE_F_ADMIN))
>> +goto out;
>>  }

[PATCH v2] PM / OPP: optimize dev_pm_opp_set_rate() performance a bit

2016-07-24 Thread Jisheng Zhang
In dev_pm_opp_set_rate(), _find_opp_table() is called 4 times: once by
_get_opp_clk(), once by dev_pm_opp_set_rate() itself, and twice by
dev_pm_opp_find_freq_ceil(). If there are several opp_tables in the
system, three times of opp table finding is a big waste. This patch
reduced the call of _find_opp_table() to twice.

Signed-off-by: Jisheng Zhang 
---
Since v1:
 - avoid opp_table pointer usage after the rcu_read_unlock() as pointed
   out by Viresh, thus we can only reduced the call of _find_opp_table
   to twice.

 drivers/base/power/opp/core.c | 31 +++
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c
index 7c04c87..cde7514 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -402,6 +402,22 @@ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct 
device *dev,
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact);
 
+static struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table,
+ unsigned long *freq)
+{
+   struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
+
+   list_for_each_entry_rcu(temp_opp, _table->opp_list, node) {
+   if (temp_opp->available && temp_opp->rate >= *freq) {
+   opp = temp_opp;
+   *freq = opp->rate;
+   break;
+   }
+   }
+
+   return opp;
+}
+
 /**
  * dev_pm_opp_find_freq_ceil() - Search for an rounded ceil freq
  * @dev:   device for which we do this operation
@@ -427,7 +443,6 @@ struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device 
*dev,
 unsigned long *freq)
 {
struct opp_table *opp_table;
-   struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
 
opp_rcu_lockdep_assert();
 
@@ -440,15 +455,7 @@ struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device 
*dev,
if (IS_ERR(opp_table))
return ERR_CAST(opp_table);
 
-   list_for_each_entry_rcu(temp_opp, _table->opp_list, node) {
-   if (temp_opp->available && temp_opp->rate >= *freq) {
-   opp = temp_opp;
-   *freq = opp->rate;
-   break;
-   }
-   }
-
-   return opp;
+   return _find_freq_ceil(opp_table, freq);
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil);
 
@@ -612,7 +619,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long 
target_freq)
return PTR_ERR(opp_table);
}
 
-   old_opp = dev_pm_opp_find_freq_ceil(dev, _freq);
+   old_opp = _find_freq_ceil(opp_table, _freq);
if (!IS_ERR(old_opp)) {
ou_volt = old_opp->u_volt;
ou_volt_min = old_opp->u_volt_min;
@@ -622,7 +629,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long 
target_freq)
__func__, old_freq, PTR_ERR(old_opp));
}
 
-   opp = dev_pm_opp_find_freq_ceil(dev, );
+   opp = _find_freq_ceil(opp_table, );
if (IS_ERR(opp)) {
ret = PTR_ERR(opp);
dev_err(dev, "%s: failed to find OPP for freq %lu (%d)\n",
-- 
2.8.1



[PATCH v2] PM / OPP: optimize dev_pm_opp_set_rate() performance a bit

2016-07-24 Thread Jisheng Zhang
In dev_pm_opp_set_rate(), _find_opp_table() is called 4 times: once by
_get_opp_clk(), once by dev_pm_opp_set_rate() itself, and twice by
dev_pm_opp_find_freq_ceil(). If there are several opp_tables in the
system, three times of opp table finding is a big waste. This patch
reduced the call of _find_opp_table() to twice.

Signed-off-by: Jisheng Zhang 
---
Since v1:
 - avoid opp_table pointer usage after the rcu_read_unlock() as pointed
   out by Viresh, thus we can only reduced the call of _find_opp_table
   to twice.

 drivers/base/power/opp/core.c | 31 +++
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c
index 7c04c87..cde7514 100644
--- a/drivers/base/power/opp/core.c
+++ b/drivers/base/power/opp/core.c
@@ -402,6 +402,22 @@ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct 
device *dev,
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact);
 
+static struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table,
+ unsigned long *freq)
+{
+   struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
+
+   list_for_each_entry_rcu(temp_opp, _table->opp_list, node) {
+   if (temp_opp->available && temp_opp->rate >= *freq) {
+   opp = temp_opp;
+   *freq = opp->rate;
+   break;
+   }
+   }
+
+   return opp;
+}
+
 /**
  * dev_pm_opp_find_freq_ceil() - Search for an rounded ceil freq
  * @dev:   device for which we do this operation
@@ -427,7 +443,6 @@ struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device 
*dev,
 unsigned long *freq)
 {
struct opp_table *opp_table;
-   struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
 
opp_rcu_lockdep_assert();
 
@@ -440,15 +455,7 @@ struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device 
*dev,
if (IS_ERR(opp_table))
return ERR_CAST(opp_table);
 
-   list_for_each_entry_rcu(temp_opp, _table->opp_list, node) {
-   if (temp_opp->available && temp_opp->rate >= *freq) {
-   opp = temp_opp;
-   *freq = opp->rate;
-   break;
-   }
-   }
-
-   return opp;
+   return _find_freq_ceil(opp_table, freq);
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil);
 
@@ -612,7 +619,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long 
target_freq)
return PTR_ERR(opp_table);
}
 
-   old_opp = dev_pm_opp_find_freq_ceil(dev, _freq);
+   old_opp = _find_freq_ceil(opp_table, _freq);
if (!IS_ERR(old_opp)) {
ou_volt = old_opp->u_volt;
ou_volt_min = old_opp->u_volt_min;
@@ -622,7 +629,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long 
target_freq)
__func__, old_freq, PTR_ERR(old_opp));
}
 
-   opp = dev_pm_opp_find_freq_ceil(dev, );
+   opp = _find_freq_ceil(opp_table, );
if (IS_ERR(opp)) {
ret = PTR_ERR(opp);
dev_err(dev, "%s: failed to find OPP for freq %lu (%d)\n",
-- 
2.8.1



Re: [PATCH] PM / OPP: optimize dev_pm_opp_set_rate() a bit

2016-07-24 Thread Jisheng Zhang
Dear Viresh,

On Fri, 22 Jul 2016 09:21:51 -0700 Viresh Kumar  wrote:

> On 22-07-16, 20:42, Jisheng Zhang wrote:
> >  static int _set_opp_voltage(struct device *dev, struct regulator *reg,
> > unsigned long u_volt, unsigned long u_volt_min,
> > unsigned long u_volt_max)
> > @@ -586,9 +565,24 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned 
> > long target_freq)
> > return -EINVAL;
> > }
> >  
> > -   clk = _get_opp_clk(dev);
> > -   if (IS_ERR(clk))
> > +   rcu_read_lock();
> > +
> > +   opp_table = _find_opp_table(dev);
> > +   if (IS_ERR(opp_table)) {
> > +   dev_err(dev, "%s: device opp doesn't exist\n", __func__);
> > +   rcu_read_unlock();
> > +   return PTR_ERR(opp_table);
> > +   }
> > +
> > +   clk = opp_table->clk;
> > +   if (IS_ERR(clk)) {
> > +   dev_err(dev, "%s: No clock available for the device\n",
> > +   __func__);
> > +   rcu_read_unlock();
> > return PTR_ERR(clk);
> > +   }
> > +
> > +   rcu_read_unlock();  
> 
> It is not _safe_ to use opp_table pointer after the rcu_read_unlock()

Oops, indeed. Thanks very much for pointing it out! Will fix it in v2, so
it seems we can only reduce the call of _find_opp_table to twice.

Thanks,
Jisheng


Re: [PATCH] PM / OPP: optimize dev_pm_opp_set_rate() a bit

2016-07-24 Thread Jisheng Zhang
Dear Viresh,

On Fri, 22 Jul 2016 09:21:51 -0700 Viresh Kumar  wrote:

> On 22-07-16, 20:42, Jisheng Zhang wrote:
> >  static int _set_opp_voltage(struct device *dev, struct regulator *reg,
> > unsigned long u_volt, unsigned long u_volt_min,
> > unsigned long u_volt_max)
> > @@ -586,9 +565,24 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned 
> > long target_freq)
> > return -EINVAL;
> > }
> >  
> > -   clk = _get_opp_clk(dev);
> > -   if (IS_ERR(clk))
> > +   rcu_read_lock();
> > +
> > +   opp_table = _find_opp_table(dev);
> > +   if (IS_ERR(opp_table)) {
> > +   dev_err(dev, "%s: device opp doesn't exist\n", __func__);
> > +   rcu_read_unlock();
> > +   return PTR_ERR(opp_table);
> > +   }
> > +
> > +   clk = opp_table->clk;
> > +   if (IS_ERR(clk)) {
> > +   dev_err(dev, "%s: No clock available for the device\n",
> > +   __func__);
> > +   rcu_read_unlock();
> > return PTR_ERR(clk);
> > +   }
> > +
> > +   rcu_read_unlock();  
> 
> It is not _safe_ to use opp_table pointer after the rcu_read_unlock()

Oops, indeed. Thanks very much for pointing it out! Will fix it in v2, so
it seems we can only reduce the call of _find_opp_table to twice.

Thanks,
Jisheng


Re: [PATCH net-next v4] cdc_ether: Improve ZTE MF823/831/910 handling

2016-07-24 Thread David Miller
From: Kristian Evensen 
Date: Thu, 21 Jul 2016 11:10:06 +0200

> The firmware in several ZTE devices (at least the MF823/831/910
> modems/mifis) use OS fingerprinting to determine which type of device to
> export. In addition, these devices export a REST API which can be used to
> control the type of device. So far, on Linux, the devices have been seen as
> RNDIS or CDC Ether.
> 
> When CDC Ether is used, devices of the same type are, as with RNDIS,
> exported with the same, bogus random MAC address. In addition, the devices
> (at least on all firmware revisions I have found) use the bogus MAC when
> sending traffic routed from external networks. And as a final feature, the
> devices sometimes export the link state incorrectly. There are also
> references online to several other ZTE devices displaying this behavior,
> with several different PIDs and MAC addresses.
> 
> This patch tries to improve the handling of ZTE devices by doing the
> following:
 ...
> v3->v4:
> * Forgot to remove unused variables, sorry about that (thanks David
> Miller).

Applied, thanks.


Re: [PATCH net-next v4] cdc_ether: Improve ZTE MF823/831/910 handling

2016-07-24 Thread David Miller
From: Kristian Evensen 
Date: Thu, 21 Jul 2016 11:10:06 +0200

> The firmware in several ZTE devices (at least the MF823/831/910
> modems/mifis) use OS fingerprinting to determine which type of device to
> export. In addition, these devices export a REST API which can be used to
> control the type of device. So far, on Linux, the devices have been seen as
> RNDIS or CDC Ether.
> 
> When CDC Ether is used, devices of the same type are, as with RNDIS,
> exported with the same, bogus random MAC address. In addition, the devices
> (at least on all firmware revisions I have found) use the bogus MAC when
> sending traffic routed from external networks. And as a final feature, the
> devices sometimes export the link state incorrectly. There are also
> references online to several other ZTE devices displaying this behavior,
> with several different PIDs and MAC addresses.
> 
> This patch tries to improve the handling of ZTE devices by doing the
> following:
 ...
> v3->v4:
> * Forgot to remove unused variables, sorry about that (thanks David
> Miller).

Applied, thanks.


Re: [PATCH v2] include: mman: Use bool instead of int for the return value of arch_validate_prot

2016-07-24 Thread Michael Ellerman
cheng...@emindsoft.com.cn writes:

> From: Chen Gang 
>
> For pure bool function's return value, bool is a little better more or
> less than int.
>
> Signed-off-by: Chen Gang 
> ---
>  arch/powerpc/include/asm/mman.h | 8 
>  include/linux/mman.h| 2 +-
>  2 files changed, 5 insertions(+), 5 deletions(-)

LGTM.

Acked-by: Michael Ellerman 

Andrew do you want to take this or should I?

cheers


Re: [PATCH v2] include: mman: Use bool instead of int for the return value of arch_validate_prot

2016-07-24 Thread Michael Ellerman
cheng...@emindsoft.com.cn writes:

> From: Chen Gang 
>
> For pure bool function's return value, bool is a little better more or
> less than int.
>
> Signed-off-by: Chen Gang 
> ---
>  arch/powerpc/include/asm/mman.h | 8 
>  include/linux/mman.h| 2 +-
>  2 files changed, 5 insertions(+), 5 deletions(-)

LGTM.

Acked-by: Michael Ellerman 

Andrew do you want to take this or should I?

cheers


Re: [PATCH 0/2] PCI: altera: fix link retrain

2016-07-24 Thread Ley Foon Tan
On Sat, Jul 23, 2016 at 5:07 AM, Bjorn Helgaas  wrote:
>
> On Tue, Jun 21, 2016 at 04:53:11PM +0800, Ley Foon Tan wrote:
> > This 2 patches fix the issue before and after retrain link.
> >
> > Ley Foon Tan (2):
> >   PCI: altera: check link status before retrain link
> >   PCI: altera: Polling for link up status after retrain the link
> >
> >  drivers/pci/host/pcie-altera.c | 48 
> > +++---
> >  1 file changed, 31 insertions(+), 17 deletions(-)
>
> I applied these to pci/host-altera for v4.8, thanks!
>
> I split the code move into its own patch so the bug fix is clearly
> visible.  I also fixed these whitespace errors:
>
>   if(!altera_pcie_link_is_up(pcie))
>   while(!altera_pcie_link_is_up(pcie)) {
>
> A space is required after "if" and "while".
Hi Bjorn

Thanks a lot!

Regards
Ley Foon


Re: [PATCH 0/2] PCI: altera: fix link retrain

2016-07-24 Thread Ley Foon Tan
On Sat, Jul 23, 2016 at 5:07 AM, Bjorn Helgaas  wrote:
>
> On Tue, Jun 21, 2016 at 04:53:11PM +0800, Ley Foon Tan wrote:
> > This 2 patches fix the issue before and after retrain link.
> >
> > Ley Foon Tan (2):
> >   PCI: altera: check link status before retrain link
> >   PCI: altera: Polling for link up status after retrain the link
> >
> >  drivers/pci/host/pcie-altera.c | 48 
> > +++---
> >  1 file changed, 31 insertions(+), 17 deletions(-)
>
> I applied these to pci/host-altera for v4.8, thanks!
>
> I split the code move into its own patch so the bug fix is clearly
> visible.  I also fixed these whitespace errors:
>
>   if(!altera_pcie_link_is_up(pcie))
>   while(!altera_pcie_link_is_up(pcie)) {
>
> A space is required after "if" and "while".
Hi Bjorn

Thanks a lot!

Regards
Ley Foon


Re: [PATCH net-next V3] net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)

2016-07-24 Thread Leon Romanovsky
On Tue, Jul 19, 2016 at 10:49:57AM -0700, Joe Perches wrote:
> On Tue, 2016-07-19 at 20:26 +0300, Leon Romanovsky wrote:
> > On Tue, Jul 19, 2016 at 02:09:25PM +0300, Netanel Belgazal wrote:
> > > This is the debugging message interface.
> > > https://www.kernel.org/doc/Documentation/networking/netif-msg.txt
> > This document was updated last time in 2006 and I doubt that it is
> > relevant in 2016. You have dynamic debug prints infrastructure for it,
> > use it.
> 
> I think this is uninformed.
> 
> netif_ works well, is compatible with dynamic debug,
> and is commonly used with new networking drivers.
> 

I have a very strong feeling that it is not "used in new drivers" by was
influenced (copied) from "old drivers". The same goes for real life usage of
module version which was introduced in this patch.


signature.asc
Description: Digital signature


Re: [PATCH net-next V3] net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)

2016-07-24 Thread Leon Romanovsky
On Tue, Jul 19, 2016 at 10:49:57AM -0700, Joe Perches wrote:
> On Tue, 2016-07-19 at 20:26 +0300, Leon Romanovsky wrote:
> > On Tue, Jul 19, 2016 at 02:09:25PM +0300, Netanel Belgazal wrote:
> > > This is the debugging message interface.
> > > https://www.kernel.org/doc/Documentation/networking/netif-msg.txt
> > This document was updated last time in 2006 and I doubt that it is
> > relevant in 2016. You have dynamic debug prints infrastructure for it,
> > use it.
> 
> I think this is uninformed.
> 
> netif_ works well, is compatible with dynamic debug,
> and is commonly used with new networking drivers.
> 

I have a very strong feeling that it is not "used in new drivers" by was
influenced (copied) from "old drivers". The same goes for real life usage of
module version which was introduced in this patch.


signature.asc
Description: Digital signature


linux-next: manual merge of the nvdimm tree with the kvm tree

2016-07-24 Thread Stephen Rothwell
Hi Dan,

Today's linux-next merge of the nvdimm tree got a conflict in:

  arch/x86/kvm/vmx.c

between commits:

  64672c95ea4c ("kvm: vmx: hook preemption timer support")
  37e4c997dadf ("KVM: VMX: validate individual bits of guest 
MSR_IA32_FEATURE_CONTROL")

from the kvm tree and commit:

  dfa169bbee00 ("Revert "KVM: x86: add pcommit support"")

from the nvdimm tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc arch/x86/kvm/vmx.c
index 9dcfb31f81ae,48394e9d56ef..
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@@ -7680,19 -7554,6 +7676,12 @@@ static int handle_pml_full(struct kvm_v
return 1;
  }
  
- static int handle_pcommit(struct kvm_vcpu *vcpu)
- {
-   /* we never catch pcommit instruct for L1 guest. */
-   WARN_ON(1);
-   return 1;
- }
- 
 +static int handle_preemption_timer(struct kvm_vcpu *vcpu)
 +{
 +  kvm_lapic_expired_hv_timer(vcpu);
 +  return 1;
 +}
 +
  /*
   * The exit handlers return 1 if the exit was handled fully and guest 
execution
   * may resume.  Otherwise they set the kvm_run parameter to indicate what 
needs
@@@ -7743,8 -7604,6 +7732,7 @@@ static int (*const kvm_vmx_exit_handler
[EXIT_REASON_XSAVES]  = handle_xsaves,
[EXIT_REASON_XRSTORS] = handle_xrstors,
[EXIT_REASON_PML_FULL]= handle_pml_full,
-   [EXIT_REASON_PCOMMIT] = handle_pcommit,
 +  [EXIT_REASON_PREEMPTION_TIMER]= handle_preemption_timer,
  };
  
  static const int kvm_vmx_max_exit_handlers =
@@@ -8053,10 -7912,6 +8041,8 @@@ static bool nested_vmx_exit_handled(str
 * the XSS exit bitmap in vmcs12.
 */
return nested_cpu_has2(vmcs12, SECONDARY_EXEC_XSAVES);
-   case EXIT_REASON_PCOMMIT:
-   return nested_cpu_has2(vmcs12, SECONDARY_EXEC_PCOMMIT);
 +  case EXIT_REASON_PREEMPTION_TIMER:
 +  return false;
default:
return true;
}
@@@ -9239,22 -9072,6 +9225,13 @@@ static void vmx_cpuid_update(struct kvm
  
if (cpu_has_secondary_exec_ctrls())
vmcs_set_secondary_exec_control(secondary_exec_ctl);
 +
-   if (static_cpu_has(X86_FEATURE_PCOMMIT) && nested) {
-   if (guest_cpuid_has_pcommit(vcpu))
-   vmx->nested.nested_vmx_secondary_ctls_high |=
-   SECONDARY_EXEC_PCOMMIT;
-   else
-   vmx->nested.nested_vmx_secondary_ctls_high &=
-   ~SECONDARY_EXEC_PCOMMIT;
-   }
- 
 +  if (nested_vmx_allowed(vcpu))
 +  to_vmx(vcpu)->msr_ia32_feature_control_valid_bits |=
 +  FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX;
 +  else
 +  to_vmx(vcpu)->msr_ia32_feature_control_valid_bits &=
 +  ~FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX;
  }
  
  static void vmx_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)


linux-next: manual merge of the nvdimm tree with the kvm tree

2016-07-24 Thread Stephen Rothwell
Hi Dan,

Today's linux-next merge of the nvdimm tree got a conflict in:

  arch/x86/kvm/vmx.c

between commits:

  64672c95ea4c ("kvm: vmx: hook preemption timer support")
  37e4c997dadf ("KVM: VMX: validate individual bits of guest 
MSR_IA32_FEATURE_CONTROL")

from the kvm tree and commit:

  dfa169bbee00 ("Revert "KVM: x86: add pcommit support"")

from the nvdimm tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc arch/x86/kvm/vmx.c
index 9dcfb31f81ae,48394e9d56ef..
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@@ -7680,19 -7554,6 +7676,12 @@@ static int handle_pml_full(struct kvm_v
return 1;
  }
  
- static int handle_pcommit(struct kvm_vcpu *vcpu)
- {
-   /* we never catch pcommit instruct for L1 guest. */
-   WARN_ON(1);
-   return 1;
- }
- 
 +static int handle_preemption_timer(struct kvm_vcpu *vcpu)
 +{
 +  kvm_lapic_expired_hv_timer(vcpu);
 +  return 1;
 +}
 +
  /*
   * The exit handlers return 1 if the exit was handled fully and guest 
execution
   * may resume.  Otherwise they set the kvm_run parameter to indicate what 
needs
@@@ -7743,8 -7604,6 +7732,7 @@@ static int (*const kvm_vmx_exit_handler
[EXIT_REASON_XSAVES]  = handle_xsaves,
[EXIT_REASON_XRSTORS] = handle_xrstors,
[EXIT_REASON_PML_FULL]= handle_pml_full,
-   [EXIT_REASON_PCOMMIT] = handle_pcommit,
 +  [EXIT_REASON_PREEMPTION_TIMER]= handle_preemption_timer,
  };
  
  static const int kvm_vmx_max_exit_handlers =
@@@ -8053,10 -7912,6 +8041,8 @@@ static bool nested_vmx_exit_handled(str
 * the XSS exit bitmap in vmcs12.
 */
return nested_cpu_has2(vmcs12, SECONDARY_EXEC_XSAVES);
-   case EXIT_REASON_PCOMMIT:
-   return nested_cpu_has2(vmcs12, SECONDARY_EXEC_PCOMMIT);
 +  case EXIT_REASON_PREEMPTION_TIMER:
 +  return false;
default:
return true;
}
@@@ -9239,22 -9072,6 +9225,13 @@@ static void vmx_cpuid_update(struct kvm
  
if (cpu_has_secondary_exec_ctrls())
vmcs_set_secondary_exec_control(secondary_exec_ctl);
 +
-   if (static_cpu_has(X86_FEATURE_PCOMMIT) && nested) {
-   if (guest_cpuid_has_pcommit(vcpu))
-   vmx->nested.nested_vmx_secondary_ctls_high |=
-   SECONDARY_EXEC_PCOMMIT;
-   else
-   vmx->nested.nested_vmx_secondary_ctls_high &=
-   ~SECONDARY_EXEC_PCOMMIT;
-   }
- 
 +  if (nested_vmx_allowed(vcpu))
 +  to_vmx(vcpu)->msr_ia32_feature_control_valid_bits |=
 +  FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX;
 +  else
 +  to_vmx(vcpu)->msr_ia32_feature_control_valid_bits &=
 +  ~FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX;
  }
  
  static void vmx_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)


Re: [PATCH] [media] cxd2841er: avoid misleading gcc warning

2016-07-24 Thread Abylay Ospan
Hello Arnd,

thanks for patch. it looks ok.
Acked-by: Abylay Ospan 


2016-07-13 16:42 GMT-04:00 Arnd Bergmann :
> The addition of jump label support in dynamic_debug caused an unexpected
> warning in exactly one file in the kernel:
>
> drivers/media/dvb-frontends/cxd2841er.c: In function 'cxd2841er_tune_tc':
> include/linux/dynamic_debug.h:134:3: error: 'carrier_offset' may be used 
> uninitialized in this function [-Werror=maybe-uninitialized]
>__dynamic_dev_dbg(, dev, fmt, \
>^
> drivers/media/dvb-frontends/cxd2841er.c:3177:11: note: 'carrier_offset' was 
> declared here
>   int ret, carrier_offset;
>^~
>
> The problem seems to be that the compiler gets confused by the extra 
> conditionals
> in static_branch_unlikely, to the point where it can no longer keep track of
> which branches have already been taken, and it doesn't realize that this 
> variable
> is now always initialized when it gets used.
>
> I have done lots of randconfig kernel builds and could not find any other file
> with this behavior, so I assume it's a rare enough glitch that we don't need
> to change the jump label support but instead just work around the warning in
> the driver.
>
> To achieve that, I'm moving the check for the return value into the switch()
> statement, which is an obvious transformation, but is enough to un-confuse
> the compiler here. The resulting code is not as nice to read, but at
> least we retain the behavior of warning if it gets changed to actually
> access an uninitialized carrier offset value in the future.
>
> Signed-off-by: Arnd Bergmann 
> Fixes: (in linux-mm) "dynamic_debug: add jump label support"
> ---
>  drivers/media/dvb-frontends/cxd2841er.c | 10 --
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/dvb-frontends/cxd2841er.c 
> b/drivers/media/dvb-frontends/cxd2841er.c
> index 721fb074da7c..0639ca281a2c 100644
> --- a/drivers/media/dvb-frontends/cxd2841er.c
> +++ b/drivers/media/dvb-frontends/cxd2841er.c
> @@ -3223,20 +3223,28 @@ static int cxd2841er_tune_tc(struct dvb_frontend *fe,
> ret = cxd2841er_get_carrier_offset_i(
> priv, p->bandwidth_hz,
> _offset);
> +   if (ret)
> +   return ret;
> break;
> case SYS_DVBT:
> ret = cxd2841er_get_carrier_offset_t(
> priv, p->bandwidth_hz,
> _offset);
> +   if (ret)
> +   return ret;
> break;
> case SYS_DVBT2:
> ret = cxd2841er_get_carrier_offset_t2(
> priv, p->bandwidth_hz,
> _offset);
> +   if (ret)
> +   return ret;
> break;
> case SYS_DVBC_ANNEX_A:
> ret = cxd2841er_get_carrier_offset_c(
> priv, _offset);
> +   if (ret)
> +   return ret;
> break;
> default:
> dev_dbg(>i2c->dev,
> @@ -3244,8 +3252,6 @@ static int cxd2841er_tune_tc(struct dvb_frontend *fe,
> __func__, priv->system);
> return -EINVAL;
> }
> -   if (ret)
> -   return ret;
> dev_dbg(>i2c->dev, "%s(): carrier offset %d\n",
> __func__, carrier_offset);
> p->frequency += carrier_offset;
> --
> 2.9.0
>



-- 
Abylay Ospan,
NetUP Inc.
http://www.netup.tv


Re: [PATCH] [media] cxd2841er: avoid misleading gcc warning

2016-07-24 Thread Abylay Ospan
Hello Arnd,

thanks for patch. it looks ok.
Acked-by: Abylay Ospan 


2016-07-13 16:42 GMT-04:00 Arnd Bergmann :
> The addition of jump label support in dynamic_debug caused an unexpected
> warning in exactly one file in the kernel:
>
> drivers/media/dvb-frontends/cxd2841er.c: In function 'cxd2841er_tune_tc':
> include/linux/dynamic_debug.h:134:3: error: 'carrier_offset' may be used 
> uninitialized in this function [-Werror=maybe-uninitialized]
>__dynamic_dev_dbg(, dev, fmt, \
>^
> drivers/media/dvb-frontends/cxd2841er.c:3177:11: note: 'carrier_offset' was 
> declared here
>   int ret, carrier_offset;
>^~
>
> The problem seems to be that the compiler gets confused by the extra 
> conditionals
> in static_branch_unlikely, to the point where it can no longer keep track of
> which branches have already been taken, and it doesn't realize that this 
> variable
> is now always initialized when it gets used.
>
> I have done lots of randconfig kernel builds and could not find any other file
> with this behavior, so I assume it's a rare enough glitch that we don't need
> to change the jump label support but instead just work around the warning in
> the driver.
>
> To achieve that, I'm moving the check for the return value into the switch()
> statement, which is an obvious transformation, but is enough to un-confuse
> the compiler here. The resulting code is not as nice to read, but at
> least we retain the behavior of warning if it gets changed to actually
> access an uninitialized carrier offset value in the future.
>
> Signed-off-by: Arnd Bergmann 
> Fixes: (in linux-mm) "dynamic_debug: add jump label support"
> ---
>  drivers/media/dvb-frontends/cxd2841er.c | 10 --
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/dvb-frontends/cxd2841er.c 
> b/drivers/media/dvb-frontends/cxd2841er.c
> index 721fb074da7c..0639ca281a2c 100644
> --- a/drivers/media/dvb-frontends/cxd2841er.c
> +++ b/drivers/media/dvb-frontends/cxd2841er.c
> @@ -3223,20 +3223,28 @@ static int cxd2841er_tune_tc(struct dvb_frontend *fe,
> ret = cxd2841er_get_carrier_offset_i(
> priv, p->bandwidth_hz,
> _offset);
> +   if (ret)
> +   return ret;
> break;
> case SYS_DVBT:
> ret = cxd2841er_get_carrier_offset_t(
> priv, p->bandwidth_hz,
> _offset);
> +   if (ret)
> +   return ret;
> break;
> case SYS_DVBT2:
> ret = cxd2841er_get_carrier_offset_t2(
> priv, p->bandwidth_hz,
> _offset);
> +   if (ret)
> +   return ret;
> break;
> case SYS_DVBC_ANNEX_A:
> ret = cxd2841er_get_carrier_offset_c(
> priv, _offset);
> +   if (ret)
> +   return ret;
> break;
> default:
> dev_dbg(>i2c->dev,
> @@ -3244,8 +3252,6 @@ static int cxd2841er_tune_tc(struct dvb_frontend *fe,
> __func__, priv->system);
> return -EINVAL;
> }
> -   if (ret)
> -   return ret;
> dev_dbg(>i2c->dev, "%s(): carrier offset %d\n",
> __func__, carrier_offset);
> p->frequency += carrier_offset;
> --
> 2.9.0
>



-- 
Abylay Ospan,
NetUP Inc.
http://www.netup.tv


Re: [RFC/PATCH 00/14] split exception table content out of module.h into extable.h

2016-07-24 Thread Linus Torvalds
On Sun, Jul 24, 2016 at 8:42 PM, Paul Gortmaker
 wrote:
>
> While doing an audit looking for unnecessary instances of module.h
> inclusion across arch/x86/ I found a significant number of includes
> of module.h were for things like search_exception_table and friends.
>
> For historical reasons (i.e. pre-git) the exception table stuff was
> buried in the middle of the module.h file.  So we have core kernel
> files that are completely non-modular (both arch specific and arch
> independent) that are just including module.h for this.
>
> The converse is also true, in that conventional drivers, be they for
> filesystems or actual hardware peripherals or similar, do not
> normally care about the exception tables.
>
> Here we fork the exception table content [...]

This looks to be the right thing to do as far as I can tell. I'm not
sure how big of a problem the extable stuff is (we definitely have
much bigger unnecessary include files that cause a lot more problems),
but it seems like a reasonable cleanup.

  Linus


Re: [RFC/PATCH 00/14] split exception table content out of module.h into extable.h

2016-07-24 Thread Linus Torvalds
On Sun, Jul 24, 2016 at 8:42 PM, Paul Gortmaker
 wrote:
>
> While doing an audit looking for unnecessary instances of module.h
> inclusion across arch/x86/ I found a significant number of includes
> of module.h were for things like search_exception_table and friends.
>
> For historical reasons (i.e. pre-git) the exception table stuff was
> buried in the middle of the module.h file.  So we have core kernel
> files that are completely non-modular (both arch specific and arch
> independent) that are just including module.h for this.
>
> The converse is also true, in that conventional drivers, be they for
> filesystems or actual hardware peripherals or similar, do not
> normally care about the exception tables.
>
> Here we fork the exception table content [...]

This looks to be the right thing to do as far as I can tell. I'm not
sure how big of a problem the extable stuff is (we definitely have
much bigger unnecessary include files that cause a lot more problems),
but it seems like a reasonable cleanup.

  Linus


Re: linux-next: build failure after merge of the sh tree

2016-07-24 Thread Stephen Rothwell
Hi Rich,

On Sun, 24 Jul 2016 23:57:30 -0400 Rich Felker  wrote:
>
> If it's acceptable I'll rebase this change into sh for-next and the
> patch I send to the subsystem maintainer.

Sure.

-- 
Cheers,
Stephen Rothwell


Re: linux-next: build failure after merge of the sh tree

2016-07-24 Thread Stephen Rothwell
Hi Rich,

On Sun, 24 Jul 2016 23:57:30 -0400 Rich Felker  wrote:
>
> If it's acceptable I'll rebase this change into sh for-next and the
> patch I send to the subsystem maintainer.

Sure.

-- 
Cheers,
Stephen Rothwell


Re: linux-next: manual merge of the tip tree with the sh tree

2016-07-24 Thread Stephen Rothwell
Hi Rich,

On Sun, 24 Jul 2016 23:55:03 -0400 Rich Felker  wrote:
>
> On Sun, Jul 24, 2016 at 03:13:42PM +1000, Stephen Rothwell wrote:
> > 
> > Today's linux-next merge of the tip tree got a conflict in:
> > 
> >   arch/sh/include/asm/spinlock.h
> > 
> > between commit:
> > 
> >   2da83dfce7df ("sh: add J2 atomics using the cas.l instruction")
> > 
> > from the sh tree and commit:
> > 
> >   726328d92a42 ("locking/spinlock, arch: Update and fix spin_unlock_wait() 
> > implementations")
> > 
> > from the tip tree.
> > 
> > I fixed it up (I used this file from the sh tree and then added the merge
> > fix patch below) and can carry the fix as necessary. This is now fixed
> > as far as linux-next is concerned, but any non trivial conflicts should
> > be mentioned to your upstream maintainer when your tree is submitted for
> > merging.  You may also want to consider cooperating with the maintainer
> > of the conflicting tree to minimise any particularly complex conflicts.  
> 
> Assuming the J2 SMP changes go upstream this merge window, should I
> simply cite this conflict and your patch when sending the pull request
> to Linux, or include the merge fix patch myself?

Just mention it to Linus.
-- 
Cheers,
Stephen Rothwell


Re: linux-next: manual merge of the tip tree with the sh tree

2016-07-24 Thread Stephen Rothwell
Hi Rich,

On Sun, 24 Jul 2016 23:55:03 -0400 Rich Felker  wrote:
>
> On Sun, Jul 24, 2016 at 03:13:42PM +1000, Stephen Rothwell wrote:
> > 
> > Today's linux-next merge of the tip tree got a conflict in:
> > 
> >   arch/sh/include/asm/spinlock.h
> > 
> > between commit:
> > 
> >   2da83dfce7df ("sh: add J2 atomics using the cas.l instruction")
> > 
> > from the sh tree and commit:
> > 
> >   726328d92a42 ("locking/spinlock, arch: Update and fix spin_unlock_wait() 
> > implementations")
> > 
> > from the tip tree.
> > 
> > I fixed it up (I used this file from the sh tree and then added the merge
> > fix patch below) and can carry the fix as necessary. This is now fixed
> > as far as linux-next is concerned, but any non trivial conflicts should
> > be mentioned to your upstream maintainer when your tree is submitted for
> > merging.  You may also want to consider cooperating with the maintainer
> > of the conflicting tree to minimise any particularly complex conflicts.  
> 
> Assuming the J2 SMP changes go upstream this merge window, should I
> simply cite this conflict and your patch when sending the pull request
> to Linux, or include the merge fix patch myself?

Just mention it to Linus.
-- 
Cheers,
Stephen Rothwell


[PATCH v2 3/5] pstore: support multiple pmsg instances

2016-07-24 Thread Nobuhiro Iwamatsu
From: Hiraku Toyooka 

This enables pmsg to deal with multiple instances. One possible
use is content priority control on limited persistent store space. By
using different buffers, we can prevent important messages from being
overwritten by less important messages.

When pstore backend module specifies the number of instances (num_pmsg)
in pstore_info, multiple /dev/pmsg[ID] appear. (ID is an integer
starting at 0. It corresponds to minor number of the each char device.)
Writes to each /dev/pmsg[ID] are isolated each other. After reboot, the
contents are available in /sys/fs/pstore/pmsg-[backend]-[ID].

Signed-off-by: Hiraku Toyooka 
Signed-off-by: Nobuhiro Iwamatsu 
Cc: Mark Salyzyn 
Cc: Seiji Aguchi 
---
 fs/pstore/pmsg.c   | 20 ++--
 include/linux/pstore.h |  1 +
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/fs/pstore/pmsg.c b/fs/pstore/pmsg.c
index 7de20cd..2e281ed 100644
--- a/fs/pstore/pmsg.c
+++ b/fs/pstore/pmsg.c
@@ -52,8 +52,8 @@ static ssize_t write_pmsg(struct file *file, const char 
__user *buf,
vfree(buffer);
return -EFAULT;
}
-   psinfo->write_buf(PSTORE_TYPE_PMSG, 0, , 0, buffer, 0, c,
- psinfo);
+   psinfo->write_buf(PSTORE_TYPE_PMSG, 0, ,
+ iminor(file->f_inode), buffer, 0, c, psinfo);
 
i += c;
}
@@ -85,6 +85,7 @@ static char *pmsg_devnode(struct device *dev, umode_t *mode)
 void pstore_register_pmsg(void)
 {
struct device *pmsg_device;
+   int i = 0;
 
pmsg_major = register_chrdev(0, PMSG_NAME, _fops);
if (pmsg_major < 0) {
@@ -105,9 +106,24 @@ void pstore_register_pmsg(void)
pr_err("failed to create device\n");
goto err_device;
}
+
+   /* allocate additional /dev/pmsg[ID] */
+   for (i = 1; i < psinfo->num_pmsg; i++) {
+   struct device *pmsg_device;
+
+   pmsg_device = device_create(pmsg_class, NULL,
+   MKDEV(pmsg_major, i), NULL, "%s%d",
+   PMSG_NAME, i);
+   if (IS_ERR(pmsg_device)) {
+   pr_err("failed to create device\n");
+   goto err_device;
+   }
+   }
return;
 
 err_device:
+   for (i--; i >= 0; i--)
+   device_destroy(pmsg_class, MKDEV(pmsg_major, i));
class_destroy(pmsg_class);
 err_class:
unregister_chrdev(pmsg_major, PMSG_NAME);
diff --git a/include/linux/pstore.h b/include/linux/pstore.h
index 831479f..b0c24cc 100644
--- a/include/linux/pstore.h
+++ b/include/linux/pstore.h
@@ -54,6 +54,7 @@ struct pstore_info {
size_t  bufsize;
struct mutexread_mutex; /* serialize open/read/close */
int flags;
+   unsigned intnum_pmsg;
int (*open)(struct pstore_info *psi);
int (*close)(struct pstore_info *psi);
ssize_t (*read)(u64 *id, enum pstore_type_id *type,
-- 
2.8.1




[PATCH v2 5/5] selftests/pstore: add testcases for multiple pmsg instances

2016-07-24 Thread Nobuhiro Iwamatsu
From: Hiraku Toyooka 

To test multiple pmsg, we should check that /dev/pmsg[N] (N > 0) is
available. After reboot, we should check that pmsg-[backend]-[N] which
keeps content is detected even if pmsg-[backend]-[N-M] (0 < M <= N)
doesn't exist due to lack of contents.

So this adds the following testcases.
 - pstore_tests
   - Write unique string to the last /dev/pmsgN
 - pstore_post_reboot_tests
   - Check the last pmsg area is detected

Signed-off-by: Hiraku Toyooka 
Signed-off-by: Nobuhiro Iwamatsu 
Cc: Mark Salyzyn 
Cc: Seiji Aguchi 
Cc: Shuah Khan 
---
 tools/testing/selftests/pstore/common_tests| 21 +++--
 .../selftests/pstore/pstore_post_reboot_tests  | 27 --
 tools/testing/selftests/pstore/pstore_tests| 16 ++---
 3 files changed, 47 insertions(+), 17 deletions(-)

diff --git a/tools/testing/selftests/pstore/common_tests 
b/tools/testing/selftests/pstore/common_tests
index 3ea64d7..566a25d 100755
--- a/tools/testing/selftests/pstore/common_tests
+++ b/tools/testing/selftests/pstore/common_tests
@@ -27,9 +27,9 @@ show_result() { # result_value
 }
 
 check_files_exist() { # type of pstorefs file
-if [ -e ${1}-${backend}-0 ]; then
+if [ -e ${1}0 ]; then
prlog "ok"
-   for f in `ls ${1}-${backend}-*`; do
+   for f in `ls ${1}*`; do
 prlog -e "\t${f}"
done
 else
@@ -53,6 +53,23 @@ operate_files() { # tested value, files, operation
 fi
 }
 
+check_pmsg_content() { # pmsg filename
+prev_uuid=`cat $TOP_DIR/prev_uuid`
+if [ $? -eq 0 ]; then
+   nr_matched=`grep -c "$TEST_STRING_PATTERN" $1`
+   if [ "$nr_matched" = "1" ]; then
+   grep -q "$TEST_STRING_PATTERN"$prev_uuid $1
+   show_result $?
+   else
+   prlog "FAIL"
+   rc=1
+   fi
+else
+   prlog "FAIL"
+   rc=1
+fi
+}
+
 # Parameters
 TEST_STRING_PATTERN="Testing pstore: uuid="
 UUID=`cat /proc/sys/kernel/random/uuid`
diff --git a/tools/testing/selftests/pstore/pstore_post_reboot_tests 
b/tools/testing/selftests/pstore/pstore_post_reboot_tests
index 6ccb154..272498f 100755
--- a/tools/testing/selftests/pstore/pstore_post_reboot_tests
+++ b/tools/testing/selftests/pstore/pstore_post_reboot_tests
@@ -35,13 +35,13 @@ fi
 cd ${mount_point}
 
 prlog -n "Checking dmesg files exist in pstore filesystem ... "
-check_files_exist dmesg
+check_files_exist dmesg-${backend}-
 
 prlog -n "Checking console files exist in pstore filesystem ... "
-check_files_exist console
+check_files_exist console-${backend}-
 
 prlog -n "Checking pmsg files exist in pstore filesystem ... "
-check_files_exist pmsg
+check_files_exist pmsg-${backend}-
 
 prlog -n "Checking dmesg files contain oops end marker"
 grep_end_trace() {
@@ -54,16 +54,19 @@ prlog -n "Checking console file contains oops end marker 
... "
 grep -q "\---\[ end trace" console-${backend}-0
 show_result $?
 
-prlog -n "Checking pmsg file properly keeps the content written before crash 
... "
-prev_uuid=`cat $TOP_DIR/prev_uuid`
-if [ $? -eq 0 ]; then
-nr_matched=`grep -c "$TEST_STRING_PATTERN" pmsg-${backend}-0`
-if [ $nr_matched -eq 1 ]; then
-   grep -q "$TEST_STRING_PATTERN"$prev_uuid pmsg-${backend}-0
-   show_result $?
+prlog -n "Checking pmsg-"${backend}"-0 properly keeps the content written 
before crash ... "
+check_pmsg_content pmsg-${backend}-0
+
+prlog -n "Checking the last pmsg area is detected "
+last_num_pmsg=`ls -v pmsg-* | tail -n1 | sed -e 
"s/^pmsg-${backend}-\([0-9]*\).*$/\1/"`
+last_num_devpmsg=`ls -v /dev/pmsg* | tail -n1 | sed -e 
"s/^\/dev\/pmsg\([0-9]*\).*$/\1/"`
+#checks the last number of pmsg-*-* and /dev/pmsg* correspond.
+if [ "$last_num_pmsg" -eq "$last_num_devpmsg" ]; then
+if [ "$last_num_pmsg" = "0" ]; then
+   prlog "... No multiple pmsg-*-* exists. We skip this testcase."
 else
-   prlog "FAIL"
-   rc=1
+   prlog -n "(pmsg-${backend}-${last_num_pmsg}) ... "
+   check_pmsg_content pmsg-${backend}-${last_num_pmsg}
 fi
 else
 prlog "FAIL"
diff --git a/tools/testing/selftests/pstore/pstore_tests 
b/tools/testing/selftests/pstore/pstore_tests
index f25d2a3..5abf0e5 100755
--- a/tools/testing/selftests/pstore/pstore_tests
+++ b/tools/testing/selftests/pstore/pstore_tests
@@ -13,9 +13,8 @@ prlog -n "Checking pstore console is registered ... "
 dmesg | grep -q "console \[pstore"
 show_result $?
 
-prlog -n "Checking /dev/pmsg0 exists ... "
-test -e /dev/pmsg0
-show_result $?
+prlog -n "Checking /dev/pmsg files exist ... "
+check_files_exist /dev/pmsg
 
 prlog -n "Writing unique string to /dev/pmsg0 ... "
 if [ -e "/dev/pmsg0" ]; then
@@ -27,4 +26,15 @@ else
 rc=1
 fi
 
+last_devpmsg=`ls -v /dev/pmsg* | tail -n1`
+prlog -n "Writing unique string to the last /dev/pmsgN "
+if [ 

[PATCH v2 3/5] pstore: support multiple pmsg instances

2016-07-24 Thread Nobuhiro Iwamatsu
From: Hiraku Toyooka 

This enables pmsg to deal with multiple instances. One possible
use is content priority control on limited persistent store space. By
using different buffers, we can prevent important messages from being
overwritten by less important messages.

When pstore backend module specifies the number of instances (num_pmsg)
in pstore_info, multiple /dev/pmsg[ID] appear. (ID is an integer
starting at 0. It corresponds to minor number of the each char device.)
Writes to each /dev/pmsg[ID] are isolated each other. After reboot, the
contents are available in /sys/fs/pstore/pmsg-[backend]-[ID].

Signed-off-by: Hiraku Toyooka 
Signed-off-by: Nobuhiro Iwamatsu 
Cc: Mark Salyzyn 
Cc: Seiji Aguchi 
---
 fs/pstore/pmsg.c   | 20 ++--
 include/linux/pstore.h |  1 +
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/fs/pstore/pmsg.c b/fs/pstore/pmsg.c
index 7de20cd..2e281ed 100644
--- a/fs/pstore/pmsg.c
+++ b/fs/pstore/pmsg.c
@@ -52,8 +52,8 @@ static ssize_t write_pmsg(struct file *file, const char 
__user *buf,
vfree(buffer);
return -EFAULT;
}
-   psinfo->write_buf(PSTORE_TYPE_PMSG, 0, , 0, buffer, 0, c,
- psinfo);
+   psinfo->write_buf(PSTORE_TYPE_PMSG, 0, ,
+ iminor(file->f_inode), buffer, 0, c, psinfo);
 
i += c;
}
@@ -85,6 +85,7 @@ static char *pmsg_devnode(struct device *dev, umode_t *mode)
 void pstore_register_pmsg(void)
 {
struct device *pmsg_device;
+   int i = 0;
 
pmsg_major = register_chrdev(0, PMSG_NAME, _fops);
if (pmsg_major < 0) {
@@ -105,9 +106,24 @@ void pstore_register_pmsg(void)
pr_err("failed to create device\n");
goto err_device;
}
+
+   /* allocate additional /dev/pmsg[ID] */
+   for (i = 1; i < psinfo->num_pmsg; i++) {
+   struct device *pmsg_device;
+
+   pmsg_device = device_create(pmsg_class, NULL,
+   MKDEV(pmsg_major, i), NULL, "%s%d",
+   PMSG_NAME, i);
+   if (IS_ERR(pmsg_device)) {
+   pr_err("failed to create device\n");
+   goto err_device;
+   }
+   }
return;
 
 err_device:
+   for (i--; i >= 0; i--)
+   device_destroy(pmsg_class, MKDEV(pmsg_major, i));
class_destroy(pmsg_class);
 err_class:
unregister_chrdev(pmsg_major, PMSG_NAME);
diff --git a/include/linux/pstore.h b/include/linux/pstore.h
index 831479f..b0c24cc 100644
--- a/include/linux/pstore.h
+++ b/include/linux/pstore.h
@@ -54,6 +54,7 @@ struct pstore_info {
size_t  bufsize;
struct mutexread_mutex; /* serialize open/read/close */
int flags;
+   unsigned intnum_pmsg;
int (*open)(struct pstore_info *psi);
int (*close)(struct pstore_info *psi);
ssize_t (*read)(u64 *id, enum pstore_type_id *type,
-- 
2.8.1




[PATCH v2 5/5] selftests/pstore: add testcases for multiple pmsg instances

2016-07-24 Thread Nobuhiro Iwamatsu
From: Hiraku Toyooka 

To test multiple pmsg, we should check that /dev/pmsg[N] (N > 0) is
available. After reboot, we should check that pmsg-[backend]-[N] which
keeps content is detected even if pmsg-[backend]-[N-M] (0 < M <= N)
doesn't exist due to lack of contents.

So this adds the following testcases.
 - pstore_tests
   - Write unique string to the last /dev/pmsgN
 - pstore_post_reboot_tests
   - Check the last pmsg area is detected

Signed-off-by: Hiraku Toyooka 
Signed-off-by: Nobuhiro Iwamatsu 
Cc: Mark Salyzyn 
Cc: Seiji Aguchi 
Cc: Shuah Khan 
---
 tools/testing/selftests/pstore/common_tests| 21 +++--
 .../selftests/pstore/pstore_post_reboot_tests  | 27 --
 tools/testing/selftests/pstore/pstore_tests| 16 ++---
 3 files changed, 47 insertions(+), 17 deletions(-)

diff --git a/tools/testing/selftests/pstore/common_tests 
b/tools/testing/selftests/pstore/common_tests
index 3ea64d7..566a25d 100755
--- a/tools/testing/selftests/pstore/common_tests
+++ b/tools/testing/selftests/pstore/common_tests
@@ -27,9 +27,9 @@ show_result() { # result_value
 }
 
 check_files_exist() { # type of pstorefs file
-if [ -e ${1}-${backend}-0 ]; then
+if [ -e ${1}0 ]; then
prlog "ok"
-   for f in `ls ${1}-${backend}-*`; do
+   for f in `ls ${1}*`; do
 prlog -e "\t${f}"
done
 else
@@ -53,6 +53,23 @@ operate_files() { # tested value, files, operation
 fi
 }
 
+check_pmsg_content() { # pmsg filename
+prev_uuid=`cat $TOP_DIR/prev_uuid`
+if [ $? -eq 0 ]; then
+   nr_matched=`grep -c "$TEST_STRING_PATTERN" $1`
+   if [ "$nr_matched" = "1" ]; then
+   grep -q "$TEST_STRING_PATTERN"$prev_uuid $1
+   show_result $?
+   else
+   prlog "FAIL"
+   rc=1
+   fi
+else
+   prlog "FAIL"
+   rc=1
+fi
+}
+
 # Parameters
 TEST_STRING_PATTERN="Testing pstore: uuid="
 UUID=`cat /proc/sys/kernel/random/uuid`
diff --git a/tools/testing/selftests/pstore/pstore_post_reboot_tests 
b/tools/testing/selftests/pstore/pstore_post_reboot_tests
index 6ccb154..272498f 100755
--- a/tools/testing/selftests/pstore/pstore_post_reboot_tests
+++ b/tools/testing/selftests/pstore/pstore_post_reboot_tests
@@ -35,13 +35,13 @@ fi
 cd ${mount_point}
 
 prlog -n "Checking dmesg files exist in pstore filesystem ... "
-check_files_exist dmesg
+check_files_exist dmesg-${backend}-
 
 prlog -n "Checking console files exist in pstore filesystem ... "
-check_files_exist console
+check_files_exist console-${backend}-
 
 prlog -n "Checking pmsg files exist in pstore filesystem ... "
-check_files_exist pmsg
+check_files_exist pmsg-${backend}-
 
 prlog -n "Checking dmesg files contain oops end marker"
 grep_end_trace() {
@@ -54,16 +54,19 @@ prlog -n "Checking console file contains oops end marker 
... "
 grep -q "\---\[ end trace" console-${backend}-0
 show_result $?
 
-prlog -n "Checking pmsg file properly keeps the content written before crash 
... "
-prev_uuid=`cat $TOP_DIR/prev_uuid`
-if [ $? -eq 0 ]; then
-nr_matched=`grep -c "$TEST_STRING_PATTERN" pmsg-${backend}-0`
-if [ $nr_matched -eq 1 ]; then
-   grep -q "$TEST_STRING_PATTERN"$prev_uuid pmsg-${backend}-0
-   show_result $?
+prlog -n "Checking pmsg-"${backend}"-0 properly keeps the content written 
before crash ... "
+check_pmsg_content pmsg-${backend}-0
+
+prlog -n "Checking the last pmsg area is detected "
+last_num_pmsg=`ls -v pmsg-* | tail -n1 | sed -e 
"s/^pmsg-${backend}-\([0-9]*\).*$/\1/"`
+last_num_devpmsg=`ls -v /dev/pmsg* | tail -n1 | sed -e 
"s/^\/dev\/pmsg\([0-9]*\).*$/\1/"`
+#checks the last number of pmsg-*-* and /dev/pmsg* correspond.
+if [ "$last_num_pmsg" -eq "$last_num_devpmsg" ]; then
+if [ "$last_num_pmsg" = "0" ]; then
+   prlog "... No multiple pmsg-*-* exists. We skip this testcase."
 else
-   prlog "FAIL"
-   rc=1
+   prlog -n "(pmsg-${backend}-${last_num_pmsg}) ... "
+   check_pmsg_content pmsg-${backend}-${last_num_pmsg}
 fi
 else
 prlog "FAIL"
diff --git a/tools/testing/selftests/pstore/pstore_tests 
b/tools/testing/selftests/pstore/pstore_tests
index f25d2a3..5abf0e5 100755
--- a/tools/testing/selftests/pstore/pstore_tests
+++ b/tools/testing/selftests/pstore/pstore_tests
@@ -13,9 +13,8 @@ prlog -n "Checking pstore console is registered ... "
 dmesg | grep -q "console \[pstore"
 show_result $?
 
-prlog -n "Checking /dev/pmsg0 exists ... "
-test -e /dev/pmsg0
-show_result $?
+prlog -n "Checking /dev/pmsg files exist ... "
+check_files_exist /dev/pmsg
 
 prlog -n "Writing unique string to /dev/pmsg0 ... "
 if [ -e "/dev/pmsg0" ]; then
@@ -27,4 +26,15 @@ else
 rc=1
 fi
 
+last_devpmsg=`ls -v /dev/pmsg* | tail -n1`
+prlog -n "Writing unique string to the last /dev/pmsgN "
+if [ "$last_devpmsg" = "/dev/pmsg0" ]; then
+prlog "... No multiple /dev/pmsg* exists. We skip this testcase."
+else
+prlog -n "(${last_devpmsg}) ... "
+echo 

[PATCH v2 1/5] ramoops: use persistent_ram_free() instead of kfree() for freeing prz

2016-07-24 Thread Nobuhiro Iwamatsu
From: Hiraku Toyooka 

persistent_ram_zone(=prz) structures are allocated by persistent_ram_new(),
which includes vmap() or ioremap(). But they are currently freed by
kfree(). This uses persistent_ram_free() for correct this asymmetry usage.

Signed-off-by: Hiraku Toyooka 
Signed-off-by: Nobuhiro Iwamatsu 
Cc: Mark Salyzyn 
Cc: Seiji Aguchi 
---
 fs/pstore/ram.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index bd9812e..22416c0 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -567,11 +567,11 @@ fail_buf:
kfree(cxt->pstore.buf);
 fail_clear:
cxt->pstore.bufsize = 0;
-   kfree(cxt->mprz);
+   persistent_ram_free(cxt->mprz);
 fail_init_mprz:
-   kfree(cxt->fprz);
+   persistent_ram_free(cxt->fprz);
 fail_init_fprz:
-   kfree(cxt->cprz);
+   persistent_ram_free(cxt->cprz);
 fail_init_cprz:
ramoops_free_przs(cxt);
 fail_out:
-- 
2.8.1




[PATCH v2 2/5] ramoops: introduce generic init/free functions for prz

2016-07-24 Thread Nobuhiro Iwamatsu
From: Hiraku Toyooka 

We modifies initialization and freeing code for prz for generic usage.
This change

 * add generic function __ramoops_init_prz() to reduce redundancy
   between ramoops_init_prz() and ramoops_init_przs().
 * rename 'przs' member in struct ramoops_context to 'dprzs' so that
   it stands for 'dump przs'.
 * rename ramoops_init_prz() to ramoops_init_dprzs().
 * change parameter of ramoops_free_przs() from struct ramoops_context *
   into struct persistent_ram_zone * in order to make it available for
   all prz array.

Signed-off-by: Hiraku Toyooka 
Signed-off-by: Nobuhiro Iwamatsu 
Cc: Mark Salyzyn 
Cc: Seiji Aguchi 
---
 fs/pstore/ram.c | 65 -
 1 file changed, 36 insertions(+), 29 deletions(-)

diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 22416c0..288c5d0 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -83,7 +83,7 @@ MODULE_PARM_DESC(ramoops_ecc,
"bytes ECC)");
 
 struct ramoops_context {
-   struct persistent_ram_zone **przs;
+   struct persistent_ram_zone **dprzs;
struct persistent_ram_zone *cprz;
struct persistent_ram_zone *fprz;
struct persistent_ram_zone *mprz;
@@ -199,7 +199,7 @@ static ssize_t ramoops_pstore_read(u64 *id, enum 
pstore_type_id *type,
 
/* Find the next valid persistent_ram_zone for DMESG */
while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) {
-   prz = ramoops_get_next_prz(cxt->przs, >dump_read_cnt,
+   prz = ramoops_get_next_prz(cxt->dprzs, >dump_read_cnt,
   cxt->max_dump_cnt, id, type,
   PSTORE_TYPE_DMESG, 1);
if (!prz_ok(prz))
@@ -314,10 +314,10 @@ static int notrace ramoops_pstore_write_buf(enum 
pstore_type_id type,
if (part != 1)
return -ENOSPC;
 
-   if (!cxt->przs)
+   if (!cxt->dprzs)
return -ENOSPC;
 
-   prz = cxt->przs[cxt->dump_write_cnt];
+   prz = cxt->dprzs[cxt->dump_write_cnt];
 
hlen = ramoops_write_kmsg_hdr(prz, compressed);
if (size + hlen > prz->buffer_size)
@@ -339,7 +339,7 @@ static int ramoops_pstore_erase(enum pstore_type_id type, 
u64 id, int count,
case PSTORE_TYPE_DMESG:
if (id >= cxt->max_dump_cnt)
return -EINVAL;
-   prz = cxt->przs[id];
+   prz = cxt->dprzs[id];
break;
case PSTORE_TYPE_CONSOLE:
prz = cxt->cprz;
@@ -371,21 +371,24 @@ static struct ramoops_context oops_cxt = {
},
 };
 
-static void ramoops_free_przs(struct ramoops_context *cxt)
+static void ramoops_free_przs(struct persistent_ram_zone **przs)
 {
int i;
 
-   cxt->max_dump_cnt = 0;
-   if (!cxt->przs)
+   if (!przs)
return;
 
-   for (i = 0; !IS_ERR_OR_NULL(cxt->przs[i]); i++)
-   persistent_ram_free(cxt->przs[i]);
-   kfree(cxt->przs);
+   for (i = 0; i < !IS_ERR_OR_NULL(przs[i]); i++)
+   persistent_ram_free(przs[i]);
+   kfree(przs);
 }
 
-static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
-phys_addr_t *paddr, size_t dump_mem_sz)
+static int __ramoops_init_prz(struct device *dev, struct ramoops_context *cxt,
+ struct persistent_ram_zone **prz,
+ phys_addr_t *paddr, size_t sz, u32 sig, bool zap);
+
+static int ramoops_init_dprzs(struct device *dev, struct ramoops_context *cxt,
+ phys_addr_t *paddr, size_t dump_mem_sz)
 {
int err = -ENOMEM;
int i;
@@ -402,29 +405,24 @@ static int ramoops_init_przs(struct device *dev, struct 
ramoops_context *cxt,
if (!cxt->max_dump_cnt)
return -ENOMEM;
 
-   cxt->przs = kzalloc(sizeof(*cxt->przs) * cxt->max_dump_cnt,
+   cxt->dprzs = kcalloc(cxt->max_dump_cnt, sizeof(*cxt->dprzs),
 GFP_KERNEL);
-   if (!cxt->przs) {
+   if (!cxt->dprzs) {
dev_err(dev, "failed to initialize a prz array for dumps\n");
goto fail_prz;
}
 
for (i = 0; i < cxt->max_dump_cnt; i++) {
-   cxt->przs[i] = persistent_ram_new(*paddr, cxt->record_size, 0,
- >ecc_info,
- cxt->memtype);
-   if (IS_ERR(cxt->przs[i])) {
-   err = PTR_ERR(cxt->przs[i]);
-   dev_err(dev, "failed to request mem region 
(0x%zx@0x%llx): %d\n",
-   cxt->record_size, (unsigned long long)*paddr, 
err);
+   err = __ramoops_init_prz(dev, cxt, >dprzs[i], paddr,
+   

[PATCH v2 0/5] pstore: ramoops: support multiple pmsg instances

2016-07-24 Thread Nobuhiro Iwamatsu
The following series implements multiple pmsg. This feature allows
userspace program to control individual content aging or priority.

If a pstore backend module(e.g. ramoops) requires the multiple pmsg
instances when registering itself to pstore, multiple /dev/pmsg[ID]
are created. Writes to each /dev/pmsg[ID] are isolated each other. After
reboot, the contents are available in /sys/fs/pstore/pmsg-[backend]-[ID].

In addition, we add multiple pmsg support for ramoops. We can
specify multiple pmsg area size by its module parameter as follows.

 pmsg_size=0x1000,0x2000,...

I did check the operation of this feature on CycloneV (socfpga) Helio board.

v2:
  Rebase to v4.7.
  Fix compile error by ramoops_free_przs function.

Hiraku Toyooka (5):
  ramoops: use persistent_ram_free() instead of kfree() for freeing prz
  ramoops: introduce generic init/free functions for prz
  pstore: support multiple pmsg instances
  ramoops: support multiple pmsg instances
  selftests/pstore: add testcases for multiple pmsg instances

 Documentation/ramoops.txt  |  22 +++
 fs/pstore/pmsg.c   |  20 +-
 fs/pstore/ram.c| 215 -
 include/linux/pstore.h |   1 +
 include/linux/pstore_ram.h |   8 +-
 tools/testing/selftests/pstore/common_tests|  21 +-
 .../selftests/pstore/pstore_post_reboot_tests  |  27 +--
 tools/testing/selftests/pstore/pstore_tests|  16 +-
 8 files changed, 257 insertions(+), 73 deletions(-)

-- 
2.8.1




[PATCH v2 4/5] ramoops: support multiple pmsg instances

2016-07-24 Thread Nobuhiro Iwamatsu
From: Hiraku Toyooka 

This enables ramoops to deal with multiple pmsg instances.
A User can configure the size of each buffers by its module parameter
as follows.

  pmsg_size=0x1000,0x2000,...

Then, the ramoops allocates multiple buffers and tells the number
of buffers to pstore to create multiple /dev/pmsg[ID].

Signed-off-by: Hiraku Toyooka 
Signed-off-by: Nobuhiro Iwamatsu 
Cc: Mark Salyzyn 
Cc: Seiji Aguchi 
---
 Documentation/ramoops.txt  |  22 +++
 fs/pstore/ram.c| 146 ++---
 include/linux/pstore_ram.h |   8 ++-
 3 files changed, 153 insertions(+), 23 deletions(-)

diff --git a/Documentation/ramoops.txt b/Documentation/ramoops.txt
index 5d86756..cff6ac7 100644
--- a/Documentation/ramoops.txt
+++ b/Documentation/ramoops.txt
@@ -126,3 +126,25 @@ file. Here is an example of usage:
  0 811d9c54  8101a7a0  __const_udelay <- 
native_machine_emergency_restart+0x110/0x1e0
  0 811d9c34  811d9c80  __delay <- __const_udelay+0x30/0x40
  0 811d9d14  811d9c3f  delay_tsc <- __delay+0xf/0x20
+
+6. Pmsg support
+
+Ramoops supports pmsg - logging userspace mesages in persistent store. By
+default, one pmsg area becomes available in ramoops. You can write data into
+/dev/pmsg0, e.g.:
+
+ # echo foo > /dev/pmsg0
+
+After reboot, the stored data can be read from pmsg-ramoops-0 on the pstore
+filesystem.
+
+You can specify size of the pmsg area by additional kernel command line, e.g.:
+
+ "ramoops.pmsg_size=0x1000"
+
+You can also use multiple pmsg areas, e.g.:
+
+ "ramoops.pmsg_size=0x1000,0x2000,..."
+
+Then, pmsg0, pmsg1, ... will appear on /dev. This is useful to control
+individual content aging or priority.
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 288c5d0..2bf893f 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -51,8 +51,8 @@ static ulong ramoops_ftrace_size = MIN_MEM_SIZE;
 module_param_named(ftrace_size, ramoops_ftrace_size, ulong, 0400);
 MODULE_PARM_DESC(ftrace_size, "size of ftrace log");
 
-static ulong ramoops_pmsg_size = MIN_MEM_SIZE;
-module_param_named(pmsg_size, ramoops_pmsg_size, ulong, 0400);
+static char *ramoops_pmsg_size_str;
+module_param_named(pmsg_size, ramoops_pmsg_size_str, charp, 0400);
 MODULE_PARM_DESC(pmsg_size, "size of user space message log");
 
 static unsigned long long mem_address;
@@ -86,14 +86,14 @@ struct ramoops_context {
struct persistent_ram_zone **dprzs;
struct persistent_ram_zone *cprz;
struct persistent_ram_zone *fprz;
-   struct persistent_ram_zone *mprz;
+   struct persistent_ram_zone **mprzs;
phys_addr_t phys_addr;
unsigned long size;
unsigned int memtype;
size_t record_size;
size_t console_size;
size_t ftrace_size;
-   size_t pmsg_size;
+   size_t *pmsg_size;
int dump_oops;
struct persistent_ram_ecc_info ecc_info;
unsigned int max_dump_cnt;
@@ -103,6 +103,7 @@ struct ramoops_context {
unsigned int console_read_cnt;
unsigned int ftrace_read_cnt;
unsigned int pmsg_read_cnt;
+   unsigned int num_pmsg;
struct pstore_info pstore;
 };
 
@@ -220,9 +221,10 @@ static ssize_t ramoops_pstore_read(u64 *id, enum 
pstore_type_id *type,
if (!prz_ok(prz))
prz = ramoops_get_next_prz(>fprz, >ftrace_read_cnt,
   1, id, type, PSTORE_TYPE_FTRACE, 0);
-   if (!prz_ok(prz))
-   prz = ramoops_get_next_prz(>mprz, >pmsg_read_cnt,
-  1, id, type, PSTORE_TYPE_PMSG, 0);
+   while (cxt->pmsg_read_cnt < cxt->num_pmsg && !prz)
+   prz = ramoops_get_next_prz(cxt->mprzs, >pmsg_read_cnt,
+  cxt->num_pmsg, id, type,
+  PSTORE_TYPE_PMSG, 0);
if (!prz_ok(prz))
return 0;
 
@@ -286,9 +288,11 @@ static int notrace ramoops_pstore_write_buf(enum 
pstore_type_id type,
persistent_ram_write(cxt->fprz, buf, size);
return 0;
} else if (type == PSTORE_TYPE_PMSG) {
-   if (!cxt->mprz)
+   if (part >= cxt->num_pmsg)
+   return -EINVAL;
+   if (!cxt->mprzs || !cxt->mprzs[part])
return -ENOMEM;
-   persistent_ram_write(cxt->mprz, buf, size);
+   persistent_ram_write(cxt->mprzs[part], buf, size);
return 0;
}
 
@@ -348,7 +352,9 @@ static int ramoops_pstore_erase(enum pstore_type_id type, 
u64 id, int count,
prz = cxt->fprz;
break;
case PSTORE_TYPE_PMSG:
-   prz = cxt->mprz;
+   if (id >= cxt->num_pmsg)
+   return -EINVAL;
+  

[PATCH v2 1/5] ramoops: use persistent_ram_free() instead of kfree() for freeing prz

2016-07-24 Thread Nobuhiro Iwamatsu
From: Hiraku Toyooka 

persistent_ram_zone(=prz) structures are allocated by persistent_ram_new(),
which includes vmap() or ioremap(). But they are currently freed by
kfree(). This uses persistent_ram_free() for correct this asymmetry usage.

Signed-off-by: Hiraku Toyooka 
Signed-off-by: Nobuhiro Iwamatsu 
Cc: Mark Salyzyn 
Cc: Seiji Aguchi 
---
 fs/pstore/ram.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index bd9812e..22416c0 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -567,11 +567,11 @@ fail_buf:
kfree(cxt->pstore.buf);
 fail_clear:
cxt->pstore.bufsize = 0;
-   kfree(cxt->mprz);
+   persistent_ram_free(cxt->mprz);
 fail_init_mprz:
-   kfree(cxt->fprz);
+   persistent_ram_free(cxt->fprz);
 fail_init_fprz:
-   kfree(cxt->cprz);
+   persistent_ram_free(cxt->cprz);
 fail_init_cprz:
ramoops_free_przs(cxt);
 fail_out:
-- 
2.8.1




[PATCH v2 2/5] ramoops: introduce generic init/free functions for prz

2016-07-24 Thread Nobuhiro Iwamatsu
From: Hiraku Toyooka 

We modifies initialization and freeing code for prz for generic usage.
This change

 * add generic function __ramoops_init_prz() to reduce redundancy
   between ramoops_init_prz() and ramoops_init_przs().
 * rename 'przs' member in struct ramoops_context to 'dprzs' so that
   it stands for 'dump przs'.
 * rename ramoops_init_prz() to ramoops_init_dprzs().
 * change parameter of ramoops_free_przs() from struct ramoops_context *
   into struct persistent_ram_zone * in order to make it available for
   all prz array.

Signed-off-by: Hiraku Toyooka 
Signed-off-by: Nobuhiro Iwamatsu 
Cc: Mark Salyzyn 
Cc: Seiji Aguchi 
---
 fs/pstore/ram.c | 65 -
 1 file changed, 36 insertions(+), 29 deletions(-)

diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 22416c0..288c5d0 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -83,7 +83,7 @@ MODULE_PARM_DESC(ramoops_ecc,
"bytes ECC)");
 
 struct ramoops_context {
-   struct persistent_ram_zone **przs;
+   struct persistent_ram_zone **dprzs;
struct persistent_ram_zone *cprz;
struct persistent_ram_zone *fprz;
struct persistent_ram_zone *mprz;
@@ -199,7 +199,7 @@ static ssize_t ramoops_pstore_read(u64 *id, enum 
pstore_type_id *type,
 
/* Find the next valid persistent_ram_zone for DMESG */
while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) {
-   prz = ramoops_get_next_prz(cxt->przs, >dump_read_cnt,
+   prz = ramoops_get_next_prz(cxt->dprzs, >dump_read_cnt,
   cxt->max_dump_cnt, id, type,
   PSTORE_TYPE_DMESG, 1);
if (!prz_ok(prz))
@@ -314,10 +314,10 @@ static int notrace ramoops_pstore_write_buf(enum 
pstore_type_id type,
if (part != 1)
return -ENOSPC;
 
-   if (!cxt->przs)
+   if (!cxt->dprzs)
return -ENOSPC;
 
-   prz = cxt->przs[cxt->dump_write_cnt];
+   prz = cxt->dprzs[cxt->dump_write_cnt];
 
hlen = ramoops_write_kmsg_hdr(prz, compressed);
if (size + hlen > prz->buffer_size)
@@ -339,7 +339,7 @@ static int ramoops_pstore_erase(enum pstore_type_id type, 
u64 id, int count,
case PSTORE_TYPE_DMESG:
if (id >= cxt->max_dump_cnt)
return -EINVAL;
-   prz = cxt->przs[id];
+   prz = cxt->dprzs[id];
break;
case PSTORE_TYPE_CONSOLE:
prz = cxt->cprz;
@@ -371,21 +371,24 @@ static struct ramoops_context oops_cxt = {
},
 };
 
-static void ramoops_free_przs(struct ramoops_context *cxt)
+static void ramoops_free_przs(struct persistent_ram_zone **przs)
 {
int i;
 
-   cxt->max_dump_cnt = 0;
-   if (!cxt->przs)
+   if (!przs)
return;
 
-   for (i = 0; !IS_ERR_OR_NULL(cxt->przs[i]); i++)
-   persistent_ram_free(cxt->przs[i]);
-   kfree(cxt->przs);
+   for (i = 0; i < !IS_ERR_OR_NULL(przs[i]); i++)
+   persistent_ram_free(przs[i]);
+   kfree(przs);
 }
 
-static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
-phys_addr_t *paddr, size_t dump_mem_sz)
+static int __ramoops_init_prz(struct device *dev, struct ramoops_context *cxt,
+ struct persistent_ram_zone **prz,
+ phys_addr_t *paddr, size_t sz, u32 sig, bool zap);
+
+static int ramoops_init_dprzs(struct device *dev, struct ramoops_context *cxt,
+ phys_addr_t *paddr, size_t dump_mem_sz)
 {
int err = -ENOMEM;
int i;
@@ -402,29 +405,24 @@ static int ramoops_init_przs(struct device *dev, struct 
ramoops_context *cxt,
if (!cxt->max_dump_cnt)
return -ENOMEM;
 
-   cxt->przs = kzalloc(sizeof(*cxt->przs) * cxt->max_dump_cnt,
+   cxt->dprzs = kcalloc(cxt->max_dump_cnt, sizeof(*cxt->dprzs),
 GFP_KERNEL);
-   if (!cxt->przs) {
+   if (!cxt->dprzs) {
dev_err(dev, "failed to initialize a prz array for dumps\n");
goto fail_prz;
}
 
for (i = 0; i < cxt->max_dump_cnt; i++) {
-   cxt->przs[i] = persistent_ram_new(*paddr, cxt->record_size, 0,
- >ecc_info,
- cxt->memtype);
-   if (IS_ERR(cxt->przs[i])) {
-   err = PTR_ERR(cxt->przs[i]);
-   dev_err(dev, "failed to request mem region 
(0x%zx@0x%llx): %d\n",
-   cxt->record_size, (unsigned long long)*paddr, 
err);
+   err = __ramoops_init_prz(dev, cxt, >dprzs[i], paddr,
+cxt->record_size, 0, false);
+   if (err)
goto fail_prz;
-   }
- 

[PATCH v2 0/5] pstore: ramoops: support multiple pmsg instances

2016-07-24 Thread Nobuhiro Iwamatsu
The following series implements multiple pmsg. This feature allows
userspace program to control individual content aging or priority.

If a pstore backend module(e.g. ramoops) requires the multiple pmsg
instances when registering itself to pstore, multiple /dev/pmsg[ID]
are created. Writes to each /dev/pmsg[ID] are isolated each other. After
reboot, the contents are available in /sys/fs/pstore/pmsg-[backend]-[ID].

In addition, we add multiple pmsg support for ramoops. We can
specify multiple pmsg area size by its module parameter as follows.

 pmsg_size=0x1000,0x2000,...

I did check the operation of this feature on CycloneV (socfpga) Helio board.

v2:
  Rebase to v4.7.
  Fix compile error by ramoops_free_przs function.

Hiraku Toyooka (5):
  ramoops: use persistent_ram_free() instead of kfree() for freeing prz
  ramoops: introduce generic init/free functions for prz
  pstore: support multiple pmsg instances
  ramoops: support multiple pmsg instances
  selftests/pstore: add testcases for multiple pmsg instances

 Documentation/ramoops.txt  |  22 +++
 fs/pstore/pmsg.c   |  20 +-
 fs/pstore/ram.c| 215 -
 include/linux/pstore.h |   1 +
 include/linux/pstore_ram.h |   8 +-
 tools/testing/selftests/pstore/common_tests|  21 +-
 .../selftests/pstore/pstore_post_reboot_tests  |  27 +--
 tools/testing/selftests/pstore/pstore_tests|  16 +-
 8 files changed, 257 insertions(+), 73 deletions(-)

-- 
2.8.1




[PATCH v2 4/5] ramoops: support multiple pmsg instances

2016-07-24 Thread Nobuhiro Iwamatsu
From: Hiraku Toyooka 

This enables ramoops to deal with multiple pmsg instances.
A User can configure the size of each buffers by its module parameter
as follows.

  pmsg_size=0x1000,0x2000,...

Then, the ramoops allocates multiple buffers and tells the number
of buffers to pstore to create multiple /dev/pmsg[ID].

Signed-off-by: Hiraku Toyooka 
Signed-off-by: Nobuhiro Iwamatsu 
Cc: Mark Salyzyn 
Cc: Seiji Aguchi 
---
 Documentation/ramoops.txt  |  22 +++
 fs/pstore/ram.c| 146 ++---
 include/linux/pstore_ram.h |   8 ++-
 3 files changed, 153 insertions(+), 23 deletions(-)

diff --git a/Documentation/ramoops.txt b/Documentation/ramoops.txt
index 5d86756..cff6ac7 100644
--- a/Documentation/ramoops.txt
+++ b/Documentation/ramoops.txt
@@ -126,3 +126,25 @@ file. Here is an example of usage:
  0 811d9c54  8101a7a0  __const_udelay <- 
native_machine_emergency_restart+0x110/0x1e0
  0 811d9c34  811d9c80  __delay <- __const_udelay+0x30/0x40
  0 811d9d14  811d9c3f  delay_tsc <- __delay+0xf/0x20
+
+6. Pmsg support
+
+Ramoops supports pmsg - logging userspace mesages in persistent store. By
+default, one pmsg area becomes available in ramoops. You can write data into
+/dev/pmsg0, e.g.:
+
+ # echo foo > /dev/pmsg0
+
+After reboot, the stored data can be read from pmsg-ramoops-0 on the pstore
+filesystem.
+
+You can specify size of the pmsg area by additional kernel command line, e.g.:
+
+ "ramoops.pmsg_size=0x1000"
+
+You can also use multiple pmsg areas, e.g.:
+
+ "ramoops.pmsg_size=0x1000,0x2000,..."
+
+Then, pmsg0, pmsg1, ... will appear on /dev. This is useful to control
+individual content aging or priority.
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 288c5d0..2bf893f 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -51,8 +51,8 @@ static ulong ramoops_ftrace_size = MIN_MEM_SIZE;
 module_param_named(ftrace_size, ramoops_ftrace_size, ulong, 0400);
 MODULE_PARM_DESC(ftrace_size, "size of ftrace log");
 
-static ulong ramoops_pmsg_size = MIN_MEM_SIZE;
-module_param_named(pmsg_size, ramoops_pmsg_size, ulong, 0400);
+static char *ramoops_pmsg_size_str;
+module_param_named(pmsg_size, ramoops_pmsg_size_str, charp, 0400);
 MODULE_PARM_DESC(pmsg_size, "size of user space message log");
 
 static unsigned long long mem_address;
@@ -86,14 +86,14 @@ struct ramoops_context {
struct persistent_ram_zone **dprzs;
struct persistent_ram_zone *cprz;
struct persistent_ram_zone *fprz;
-   struct persistent_ram_zone *mprz;
+   struct persistent_ram_zone **mprzs;
phys_addr_t phys_addr;
unsigned long size;
unsigned int memtype;
size_t record_size;
size_t console_size;
size_t ftrace_size;
-   size_t pmsg_size;
+   size_t *pmsg_size;
int dump_oops;
struct persistent_ram_ecc_info ecc_info;
unsigned int max_dump_cnt;
@@ -103,6 +103,7 @@ struct ramoops_context {
unsigned int console_read_cnt;
unsigned int ftrace_read_cnt;
unsigned int pmsg_read_cnt;
+   unsigned int num_pmsg;
struct pstore_info pstore;
 };
 
@@ -220,9 +221,10 @@ static ssize_t ramoops_pstore_read(u64 *id, enum 
pstore_type_id *type,
if (!prz_ok(prz))
prz = ramoops_get_next_prz(>fprz, >ftrace_read_cnt,
   1, id, type, PSTORE_TYPE_FTRACE, 0);
-   if (!prz_ok(prz))
-   prz = ramoops_get_next_prz(>mprz, >pmsg_read_cnt,
-  1, id, type, PSTORE_TYPE_PMSG, 0);
+   while (cxt->pmsg_read_cnt < cxt->num_pmsg && !prz)
+   prz = ramoops_get_next_prz(cxt->mprzs, >pmsg_read_cnt,
+  cxt->num_pmsg, id, type,
+  PSTORE_TYPE_PMSG, 0);
if (!prz_ok(prz))
return 0;
 
@@ -286,9 +288,11 @@ static int notrace ramoops_pstore_write_buf(enum 
pstore_type_id type,
persistent_ram_write(cxt->fprz, buf, size);
return 0;
} else if (type == PSTORE_TYPE_PMSG) {
-   if (!cxt->mprz)
+   if (part >= cxt->num_pmsg)
+   return -EINVAL;
+   if (!cxt->mprzs || !cxt->mprzs[part])
return -ENOMEM;
-   persistent_ram_write(cxt->mprz, buf, size);
+   persistent_ram_write(cxt->mprzs[part], buf, size);
return 0;
}
 
@@ -348,7 +352,9 @@ static int ramoops_pstore_erase(enum pstore_type_id type, 
u64 id, int count,
prz = cxt->fprz;
break;
case PSTORE_TYPE_PMSG:
-   prz = cxt->mprz;
+   if (id >= cxt->num_pmsg)
+   return -EINVAL;
+   prz = cxt->mprzs[id];
break;
default:
return -EINVAL;
@@ -426,6 +432,37 @@ fail_prz:
return 

Re: linux-next: build failure after merge of the sh tree

2016-07-24 Thread Rich Felker
On Sun, Jul 24, 2016 at 05:55:01PM +1000, Stephen Rothwell wrote:
> Hi Rich,
> 
> After merging the sh tree, today's linux-next build (powerpc allyesconfig)
> failed like this:
> 
> drivers/clocksource/jcore-pit.c:145:20: error: conflicting types for 
> 'timer_interrupt'
>  static irqreturn_t timer_interrupt(int irq, void *dev_id)
> ^
> In file included from arch/powerpc/include/asm/irqflags.h:11:0,
>  from include/linux/irqflags.h:15,
>  from include/linux/spinlock.h:53,
>  from include/linux/mmzone.h:7,
>  from include/linux/gfp.h:5,
>  from include/linux/slab.h:14,
>  from drivers/clocksource/jcore-pit.c:12:
> arch/powerpc/include/asm/hw_irq.h:36:13: note: previous declaration of 
> 'timer_interrupt' was here
>  extern void timer_interrupt(struct pt_regs *);
>  ^
> 
> Caused by commit
> 
>   e0aa0655c60b ("clocksource: add J-Core timer/clocksource driver")
> 
> I added this fix patch:
> 
> From: Stephen Rothwell 
> Date: Sun, 24 Jul 2016 17:42:19 +1000
> Subject: [PATCH] clocksource: make J-Core timer_interrupt more unique
> 
> Signed-off-by: Stephen Rothwell 
> ---
>  drivers/clocksource/jcore-pit.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clocksource/jcore-pit.c b/drivers/clocksource/jcore-pit.c
> index b9d693bcb41e..373b9f954a5c 100644
> --- a/drivers/clocksource/jcore-pit.c
> +++ b/drivers/clocksource/jcore-pit.c
> @@ -142,7 +142,7 @@ static int jcore_pit_cpu_notify(struct notifier_block 
> *self,
>   return NOTIFY_OK;
>  }
>  
> -static irqreturn_t timer_interrupt(int irq, void *dev_id)
> +static irqreturn_t jcore_timer_interrupt(int irq, void *dev_id)
>  {
>   struct jcore_pit *pit = this_cpu_ptr(dev_id);
>  
> @@ -224,7 +224,7 @@ static void __init jcore_pit_init(struct device_node 
> *node)
>   goto out;
>   }
>  
> - err = request_irq(pit_irq, timer_interrupt,
> + err = request_irq(pit_irq, jcore_timer_interrupt,
>   IRQF_TIMER | IRQF_PERCPU, "jcore_pit", pit_percpu);
>   if (err) {
>   pr_err("pit irq request failed: %d\n", err);
> -- 

If it's acceptable I'll rebase this change into sh for-next and the
patch I send to the subsystem maintainer.

Rich


Re: linux-next: manual merge of the tip tree with the sh tree

2016-07-24 Thread Rich Felker
On Sun, Jul 24, 2016 at 03:13:42PM +1000, Stephen Rothwell wrote:
> Hi all,
> 
> Today's linux-next merge of the tip tree got a conflict in:
> 
>   arch/sh/include/asm/spinlock.h
> 
> between commit:
> 
>   2da83dfce7df ("sh: add J2 atomics using the cas.l instruction")
> 
> from the sh tree and commit:
> 
>   726328d92a42 ("locking/spinlock, arch: Update and fix spin_unlock_wait() 
> implementations")
> 
> from the tip tree.
> 
> I fixed it up (I used this file from the sh tree and then added the merge
> fix patch below) and can carry the fix as necessary. This is now fixed
> as far as linux-next is concerned, but any non trivial conflicts should
> be mentioned to your upstream maintainer when your tree is submitted for
> merging.  You may also want to consider cooperating with the maintainer
> of the conflicting tree to minimise any particularly complex conflicts.

Assuming the J2 SMP changes go upstream this merge window, should I
simply cite this conflict and your patch when sending the pull request
to Linux, or include the merge fix patch myself?

Rich


Re: linux-next: build failure after merge of the sh tree

2016-07-24 Thread Rich Felker
On Sun, Jul 24, 2016 at 05:55:01PM +1000, Stephen Rothwell wrote:
> Hi Rich,
> 
> After merging the sh tree, today's linux-next build (powerpc allyesconfig)
> failed like this:
> 
> drivers/clocksource/jcore-pit.c:145:20: error: conflicting types for 
> 'timer_interrupt'
>  static irqreturn_t timer_interrupt(int irq, void *dev_id)
> ^
> In file included from arch/powerpc/include/asm/irqflags.h:11:0,
>  from include/linux/irqflags.h:15,
>  from include/linux/spinlock.h:53,
>  from include/linux/mmzone.h:7,
>  from include/linux/gfp.h:5,
>  from include/linux/slab.h:14,
>  from drivers/clocksource/jcore-pit.c:12:
> arch/powerpc/include/asm/hw_irq.h:36:13: note: previous declaration of 
> 'timer_interrupt' was here
>  extern void timer_interrupt(struct pt_regs *);
>  ^
> 
> Caused by commit
> 
>   e0aa0655c60b ("clocksource: add J-Core timer/clocksource driver")
> 
> I added this fix patch:
> 
> From: Stephen Rothwell 
> Date: Sun, 24 Jul 2016 17:42:19 +1000
> Subject: [PATCH] clocksource: make J-Core timer_interrupt more unique
> 
> Signed-off-by: Stephen Rothwell 
> ---
>  drivers/clocksource/jcore-pit.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clocksource/jcore-pit.c b/drivers/clocksource/jcore-pit.c
> index b9d693bcb41e..373b9f954a5c 100644
> --- a/drivers/clocksource/jcore-pit.c
> +++ b/drivers/clocksource/jcore-pit.c
> @@ -142,7 +142,7 @@ static int jcore_pit_cpu_notify(struct notifier_block 
> *self,
>   return NOTIFY_OK;
>  }
>  
> -static irqreturn_t timer_interrupt(int irq, void *dev_id)
> +static irqreturn_t jcore_timer_interrupt(int irq, void *dev_id)
>  {
>   struct jcore_pit *pit = this_cpu_ptr(dev_id);
>  
> @@ -224,7 +224,7 @@ static void __init jcore_pit_init(struct device_node 
> *node)
>   goto out;
>   }
>  
> - err = request_irq(pit_irq, timer_interrupt,
> + err = request_irq(pit_irq, jcore_timer_interrupt,
>   IRQF_TIMER | IRQF_PERCPU, "jcore_pit", pit_percpu);
>   if (err) {
>   pr_err("pit irq request failed: %d\n", err);
> -- 

If it's acceptable I'll rebase this change into sh for-next and the
patch I send to the subsystem maintainer.

Rich


Re: linux-next: manual merge of the tip tree with the sh tree

2016-07-24 Thread Rich Felker
On Sun, Jul 24, 2016 at 03:13:42PM +1000, Stephen Rothwell wrote:
> Hi all,
> 
> Today's linux-next merge of the tip tree got a conflict in:
> 
>   arch/sh/include/asm/spinlock.h
> 
> between commit:
> 
>   2da83dfce7df ("sh: add J2 atomics using the cas.l instruction")
> 
> from the sh tree and commit:
> 
>   726328d92a42 ("locking/spinlock, arch: Update and fix spin_unlock_wait() 
> implementations")
> 
> from the tip tree.
> 
> I fixed it up (I used this file from the sh tree and then added the merge
> fix patch below) and can carry the fix as necessary. This is now fixed
> as far as linux-next is concerned, but any non trivial conflicts should
> be mentioned to your upstream maintainer when your tree is submitted for
> merging.  You may also want to consider cooperating with the maintainer
> of the conflicting tree to minimise any particularly complex conflicts.

Assuming the J2 SMP changes go upstream this merge window, should I
simply cite this conflict and your patch when sending the pull request
to Linux, or include the merge fix patch myself?

Rich


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

2016-07-24 Thread Rich Felker
On Sun, Jul 24, 2016 at 11:00:12AM +1000, Stephen Rothwell wrote:
> Hi Rich,
> 
> After merging the sh tree, today's linux-next build (x86_64
> allmodconfig) produced this warning:
> 
> WARNING: modpost: missing MODULE_LICENSE() in drivers/spi/spi-jcore.o
> 
> Introduced by commit
> 
>   8c7f438f0661 ("spi: add driver for J-Core SPI controller")

Thanks. I'll make that change for sending to the subsystem maintainer
and include it in my next rebase of for-next.

Rich


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

2016-07-24 Thread Rich Felker
On Sun, Jul 24, 2016 at 11:00:12AM +1000, Stephen Rothwell wrote:
> Hi Rich,
> 
> After merging the sh tree, today's linux-next build (x86_64
> allmodconfig) produced this warning:
> 
> WARNING: modpost: missing MODULE_LICENSE() in drivers/spi/spi-jcore.o
> 
> Introduced by commit
> 
>   8c7f438f0661 ("spi: add driver for J-Core SPI controller")

Thanks. I'll make that change for sending to the subsystem maintainer
and include it in my next rebase of for-next.

Rich


[PATCH 14/14] module.h: remove extable.h include now users have migrated

2016-07-24 Thread Paul Gortmaker
With hopefully most/all users of module.h that were looking for
exception table functions moved over to the new extable.h header,
we can remove the back-compat include that let us transition
without introducing build regressions.

Cc: Rusty Russell 
Cc: Andrew Morton 
Cc: Linus Torvalds 
Signed-off-by: Paul Gortmaker 
---
 include/linux/module.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/linux/module.h b/include/linux/module.h
index f95ed243a4de..1974eadcb308 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -18,7 +18,6 @@
 #include 
 #include 
 #include 
-#include  /* only as arch move module.h -> extable.h */
 #include 
 
 #include 
-- 
2.8.4



[RFC/PATCH 00/14] split exception table content out of module.h into extable.h

2016-07-24 Thread Paul Gortmaker
[RFC: Not looking for detailed review given the merge window is open.
 As long as nobody thinks the general idea is horrible, I'll expand into
 more fringe arch and resend in 2wks and get it added then to linux-next.]

While doing an audit looking for unnecessary instances of module.h
inclusion across arch/x86/ I found a significant number of includes
of module.h were for things like search_exception_table and friends.

For historical reasons (i.e. pre-git) the exception table stuff was
buried in the middle of the module.h file.  So we have core kernel
files that are completely non-modular (both arch specific and arch
independent) that are just including module.h for this.

The converse is also true, in that conventional drivers, be they for
filesystems or actual hardware peripherals or similar, do not
normally care about the exception tables.

Here we fork the exception table content out of module.h into a new
extable.h file.  The gain here is that module.h gets a bit smaller;
a win for all modular drivers that we build for allmodconfig.  Also
most core files that only need exception table stuff get to shed an
include of module.h that brings in lots of extra stuff and just
looks generally out of place.  They use the tiny extable.h instead.

We temporarily include extable.h into the module.h itself.  Then we
will work our way across the arch independent and arch specific
files needing just exception table content, and move them off
module.h and onto extable.h

Once that is done, we can remove the extable.h from module.h and in
doing it like this, we avoid introducing build failures into the git
history.

We have the option of taking this final one line commit and pushing
it out a complete release if we want to open up a bigger window for
converting some of the more fringe archtectures.

I've converted about a dozen architectures here w/o issue; that
largely reflects what I currently have toolchains for.  Build
testing seems necessary in all instances, since the odds are high
that the module.h presence was hiding implicit use of other headers,
as was the case for s390.

Paul.
-- 

Cc: Andrew Morton 
Cc: Benjamin Herrenschmidt 
Cc: Catalin Marinas 
Cc: Chris Metcalf 
Cc: "David S. Miller" 
Cc: Geert Uytterhoeven 
Cc: Heiko Carstens 
Cc: Helge Deller 
Cc: "H. Peter Anvin" 
Cc: Ingo Molnar 
Cc: Ivan Kokshaysky 
Cc: "James E.J. Bottomley" 
Cc: Linus Torvalds 
Cc: Martin Schwidefsky 
Cc: Matt Turner 
Cc: Michael Ellerman 
Cc: Paul Mackerras 
Cc: Ralf Baechle 
Cc: Richard Henderson 
Cc: Russell King 
Cc: Rusty Russell 
Cc: Thomas Gleixner 
Cc: Will Deacon 
Cc: linux-al...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-m...@linux-mips.org
Cc: linux-par...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-s...@vger.kernel.org
Cc: x...@kernel.org
Cc: sparcli...@vger.kernel.org

Paul Gortmaker (14):
  exceptions: fork exception table content from module.h into extable.h
  x86: migrate exception table users off module.h and onto extable.h
  arm: migrate exception table users off module.h and onto extable.h
  arm64: migrate exception table users off module.h and onto extable.h
  mips: migrate exception table users off module.h and onto extable.h
  sparc: migrate exception table users off module.h and onto extable.h
  powerpc: migrate exception table users off module.h and onto extable.h
  m68k: migrate exception table users off module.h and onto extable.h
  s390: migrate exception table users off module.h and onto extable.h
  tile: migrate exception table users off module.h and onto extable.h
  alpha: migrate exception table users off module.h and onto extable.h
  parisc: migrate exception table users off module.h and onto extable.h
  core: migrate exception table users off module.h and onto extable.h
  module.h: remove extable.h include now users have migrated

 arch/alpha/kernel/traps.c  |  2 +-
 arch/alpha/mm/fault.c  |  2 +-
 arch/arm/mm/extable.c  |  2 +-
 arch/arm/mm/fault.c|  2 +-
 arch/arm64/kernel/probes/kprobes.c |  2 +-
 arch/arm64/mm/extable.c|  2 +-
 arch/arm64/mm/fault.c  |  2 +-
 arch/m68k/kernel/signal.c  |  2 +-
 arch/mips/kernel/module.c  |  1 +
 arch/mips/kernel/traps.c   |  2 +-
 arch/mips/mm/extable.c |  2 +-
 arch/parisc/mm/fault.c |  2 +-
 arch/powerpc/kernel/kprobes.c  |  2 +-
 arch/powerpc/mm/fault.c

[PATCH 11/14] alpha: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: Richard Henderson 
Cc: Ivan Kokshaysky 
Cc: Matt Turner 
Cc: linux-al...@vger.kernel.org
Signed-off-by: Paul Gortmaker 
---
 arch/alpha/kernel/traps.c | 2 +-
 arch/alpha/mm/fault.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
index 74aceead06e9..7cf05aa482d5 100644
--- a/arch/alpha/kernel/traps.c
+++ b/arch/alpha/kernel/traps.c
@@ -13,7 +13,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 
diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
index 83e9eee57a55..47948b4dd157 100644
--- a/arch/alpha/mm/fault.c
+++ b/arch/alpha/mm/fault.c
@@ -22,7 +22,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 extern void die_if_kernel(char *,struct pt_regs *,long, unsigned long *);
-- 
2.8.4



[PATCH 10/14] tile: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: Chris Metcalf 
Signed-off-by: Paul Gortmaker 
---
 arch/tile/kernel/unaligned.c | 2 +-
 arch/tile/mm/extable.c   | 2 +-
 arch/tile/mm/fault.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/tile/kernel/unaligned.c b/arch/tile/kernel/unaligned.c
index 9772a3554282..4fe78c5b8394 100644
--- a/arch/tile/kernel/unaligned.c
+++ b/arch/tile/kernel/unaligned.c
@@ -22,7 +22,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/tile/mm/extable.c b/arch/tile/mm/extable.c
index 4fb0acb9d154..aeaf20c7aaa4 100644
--- a/arch/tile/mm/extable.c
+++ b/arch/tile/mm/extable.c
@@ -12,7 +12,7 @@
  *   more details.
  */
 
-#include 
+#include 
 #include 
 #include 
 
diff --git a/arch/tile/mm/fault.c b/arch/tile/mm/fault.c
index beba986589e5..709f8e9ba3e9 100644
--- a/arch/tile/mm/fault.c
+++ b/arch/tile/mm/fault.c
@@ -29,7 +29,7 @@
 #include 
 #include  /* For unblank_screen() */
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH 08/14] m68k: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
This file was only including module.h for exception table related
functions.  We've now separated that content out into its own file
"extable.h" so now move over to that and avoid all the extra header
content in module.h that we don't really need to compile this.

Cc: Geert Uytterhoeven 
Cc: linux-m...@lists.linux-m68k.org
Signed-off-by: Paul Gortmaker 
---
 arch/m68k/kernel/signal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/m68k/kernel/signal.c b/arch/m68k/kernel/signal.c
index 2dcee3a88867..db775322b485 100644
--- a/arch/m68k/kernel/signal.c
+++ b/arch/m68k/kernel/signal.c
@@ -42,7 +42,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 #include 
-- 
2.8.4



[PATCH 14/14] module.h: remove extable.h include now users have migrated

2016-07-24 Thread Paul Gortmaker
With hopefully most/all users of module.h that were looking for
exception table functions moved over to the new extable.h header,
we can remove the back-compat include that let us transition
without introducing build regressions.

Cc: Rusty Russell 
Cc: Andrew Morton 
Cc: Linus Torvalds 
Signed-off-by: Paul Gortmaker 
---
 include/linux/module.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/linux/module.h b/include/linux/module.h
index f95ed243a4de..1974eadcb308 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -18,7 +18,6 @@
 #include 
 #include 
 #include 
-#include  /* only as arch move module.h -> extable.h */
 #include 
 
 #include 
-- 
2.8.4



[RFC/PATCH 00/14] split exception table content out of module.h into extable.h

2016-07-24 Thread Paul Gortmaker
[RFC: Not looking for detailed review given the merge window is open.
 As long as nobody thinks the general idea is horrible, I'll expand into
 more fringe arch and resend in 2wks and get it added then to linux-next.]

While doing an audit looking for unnecessary instances of module.h
inclusion across arch/x86/ I found a significant number of includes
of module.h were for things like search_exception_table and friends.

For historical reasons (i.e. pre-git) the exception table stuff was
buried in the middle of the module.h file.  So we have core kernel
files that are completely non-modular (both arch specific and arch
independent) that are just including module.h for this.

The converse is also true, in that conventional drivers, be they for
filesystems or actual hardware peripherals or similar, do not
normally care about the exception tables.

Here we fork the exception table content out of module.h into a new
extable.h file.  The gain here is that module.h gets a bit smaller;
a win for all modular drivers that we build for allmodconfig.  Also
most core files that only need exception table stuff get to shed an
include of module.h that brings in lots of extra stuff and just
looks generally out of place.  They use the tiny extable.h instead.

We temporarily include extable.h into the module.h itself.  Then we
will work our way across the arch independent and arch specific
files needing just exception table content, and move them off
module.h and onto extable.h

Once that is done, we can remove the extable.h from module.h and in
doing it like this, we avoid introducing build failures into the git
history.

We have the option of taking this final one line commit and pushing
it out a complete release if we want to open up a bigger window for
converting some of the more fringe archtectures.

I've converted about a dozen architectures here w/o issue; that
largely reflects what I currently have toolchains for.  Build
testing seems necessary in all instances, since the odds are high
that the module.h presence was hiding implicit use of other headers,
as was the case for s390.

Paul.
-- 

Cc: Andrew Morton 
Cc: Benjamin Herrenschmidt 
Cc: Catalin Marinas 
Cc: Chris Metcalf 
Cc: "David S. Miller" 
Cc: Geert Uytterhoeven 
Cc: Heiko Carstens 
Cc: Helge Deller 
Cc: "H. Peter Anvin" 
Cc: Ingo Molnar 
Cc: Ivan Kokshaysky 
Cc: "James E.J. Bottomley" 
Cc: Linus Torvalds 
Cc: Martin Schwidefsky 
Cc: Matt Turner 
Cc: Michael Ellerman 
Cc: Paul Mackerras 
Cc: Ralf Baechle 
Cc: Richard Henderson 
Cc: Russell King 
Cc: Rusty Russell 
Cc: Thomas Gleixner 
Cc: Will Deacon 
Cc: linux-al...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-m...@linux-mips.org
Cc: linux-par...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-s...@vger.kernel.org
Cc: x...@kernel.org
Cc: sparcli...@vger.kernel.org

Paul Gortmaker (14):
  exceptions: fork exception table content from module.h into extable.h
  x86: migrate exception table users off module.h and onto extable.h
  arm: migrate exception table users off module.h and onto extable.h
  arm64: migrate exception table users off module.h and onto extable.h
  mips: migrate exception table users off module.h and onto extable.h
  sparc: migrate exception table users off module.h and onto extable.h
  powerpc: migrate exception table users off module.h and onto extable.h
  m68k: migrate exception table users off module.h and onto extable.h
  s390: migrate exception table users off module.h and onto extable.h
  tile: migrate exception table users off module.h and onto extable.h
  alpha: migrate exception table users off module.h and onto extable.h
  parisc: migrate exception table users off module.h and onto extable.h
  core: migrate exception table users off module.h and onto extable.h
  module.h: remove extable.h include now users have migrated

 arch/alpha/kernel/traps.c  |  2 +-
 arch/alpha/mm/fault.c  |  2 +-
 arch/arm/mm/extable.c  |  2 +-
 arch/arm/mm/fault.c|  2 +-
 arch/arm64/kernel/probes/kprobes.c |  2 +-
 arch/arm64/mm/extable.c|  2 +-
 arch/arm64/mm/fault.c  |  2 +-
 arch/m68k/kernel/signal.c  |  2 +-
 arch/mips/kernel/module.c  |  1 +
 arch/mips/kernel/traps.c   |  2 +-
 arch/mips/mm/extable.c |  2 +-
 arch/parisc/mm/fault.c |  2 +-
 arch/powerpc/kernel/kprobes.c  |  2 +-
 arch/powerpc/mm/fault.c|  2 +-
 arch/s390/kernel/early.c   |  2 +-
 arch/s390/kernel/kprobes.c |  2 ++
 arch/s390/kernel/traps.c   |  3 ++-
 arch/s390/mm/fault.c   |  2 +-
 arch/sparc/kernel/kprobes.c|  2 +-
 arch/sparc/kernel/traps_64.c   |  2 +-
 arch/sparc/kernel/unaligned_64.c   |  2 +-
 arch/sparc/mm/fault_64.c   |  2 +-
 arch/sparc/mm/init_64.c|  2 +-
 arch/tile/kernel/unaligned.c   |  2 +-
 arch/tile/mm/extable.c |  2 +-
 

[PATCH 11/14] alpha: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: Richard Henderson 
Cc: Ivan Kokshaysky 
Cc: Matt Turner 
Cc: linux-al...@vger.kernel.org
Signed-off-by: Paul Gortmaker 
---
 arch/alpha/kernel/traps.c | 2 +-
 arch/alpha/mm/fault.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
index 74aceead06e9..7cf05aa482d5 100644
--- a/arch/alpha/kernel/traps.c
+++ b/arch/alpha/kernel/traps.c
@@ -13,7 +13,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 
diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
index 83e9eee57a55..47948b4dd157 100644
--- a/arch/alpha/mm/fault.c
+++ b/arch/alpha/mm/fault.c
@@ -22,7 +22,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 extern void die_if_kernel(char *,struct pt_regs *,long, unsigned long *);
-- 
2.8.4



[PATCH 10/14] tile: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: Chris Metcalf 
Signed-off-by: Paul Gortmaker 
---
 arch/tile/kernel/unaligned.c | 2 +-
 arch/tile/mm/extable.c   | 2 +-
 arch/tile/mm/fault.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/tile/kernel/unaligned.c b/arch/tile/kernel/unaligned.c
index 9772a3554282..4fe78c5b8394 100644
--- a/arch/tile/kernel/unaligned.c
+++ b/arch/tile/kernel/unaligned.c
@@ -22,7 +22,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/tile/mm/extable.c b/arch/tile/mm/extable.c
index 4fb0acb9d154..aeaf20c7aaa4 100644
--- a/arch/tile/mm/extable.c
+++ b/arch/tile/mm/extable.c
@@ -12,7 +12,7 @@
  *   more details.
  */
 
-#include 
+#include 
 #include 
 #include 
 
diff --git a/arch/tile/mm/fault.c b/arch/tile/mm/fault.c
index beba986589e5..709f8e9ba3e9 100644
--- a/arch/tile/mm/fault.c
+++ b/arch/tile/mm/fault.c
@@ -29,7 +29,7 @@
 #include 
 #include  /* For unblank_screen() */
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH 08/14] m68k: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
This file was only including module.h for exception table related
functions.  We've now separated that content out into its own file
"extable.h" so now move over to that and avoid all the extra header
content in module.h that we don't really need to compile this.

Cc: Geert Uytterhoeven 
Cc: linux-m...@lists.linux-m68k.org
Signed-off-by: Paul Gortmaker 
---
 arch/m68k/kernel/signal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/m68k/kernel/signal.c b/arch/m68k/kernel/signal.c
index 2dcee3a88867..db775322b485 100644
--- a/arch/m68k/kernel/signal.c
+++ b/arch/m68k/kernel/signal.c
@@ -42,7 +42,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 #include 
-- 
2.8.4



[PATCH 03/14] arm: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: Russell King 
Cc: linux-arm-ker...@lists.infradead.org
Signed-off-by: Paul Gortmaker 
---
 arch/arm/mm/extable.c | 2 +-
 arch/arm/mm/fault.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mm/extable.c b/arch/arm/mm/extable.c
index 312e15e6d00b..f436f7439e46 100644
--- a/arch/arm/mm/extable.c
+++ b/arch/arm/mm/extable.c
@@ -1,7 +1,7 @@
 /*
  *  linux/arch/arm/mm/extable.c
  */
-#include 
+#include 
 #include 
 
 int fixup_exception(struct pt_regs *regs)
diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
index 3a2e678b8d30..94de590db99e 100644
--- a/arch/arm/mm/fault.c
+++ b/arch/arm/mm/fault.c
@@ -8,7 +8,7 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
-#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH 04/14] arm64: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: Catalin Marinas 
Cc: Will Deacon 
Cc: linux-arm-ker...@lists.infradead.org
Signed-off-by: Paul Gortmaker 
---
 arch/arm64/kernel/probes/kprobes.c | 2 +-
 arch/arm64/mm/extable.c| 2 +-
 arch/arm64/mm/fault.c  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/kernel/probes/kprobes.c 
b/arch/arm64/kernel/probes/kprobes.c
index bf9768588288..9c1866ef3271 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -19,7 +19,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm64/mm/extable.c b/arch/arm64/mm/extable.c
index 81acd4706878..c9f118cd812b 100644
--- a/arch/arm64/mm/extable.c
+++ b/arch/arm64/mm/extable.c
@@ -2,7 +2,7 @@
  * Based on arch/arm/mm/extable.c
  */
 
-#include 
+#include 
 #include 
 
 int fixup_exception(struct pt_regs *regs)
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index c8beaa0da7df..427f2fd49463 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -18,7 +18,7 @@
  * along with this program.  If not, see .
  */
 
-#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH 09/14] s390: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

The additions of uaccess.h are to deal with implict includes like:

arch/s390/kernel/traps.c: In function 'do_report_trap':
arch/s390/kernel/traps.c:56:4: error: implicit declaration of function 
'extable_fixup' [-Werror=implicit-function-declaration]
arch/s390/kernel/traps.c: In function 'illegal_op':
arch/s390/kernel/traps.c:173:3: error: implicit declaration of function 
'get_user' [-Werror=implicit-function-declaration]

Cc: Martin Schwidefsky 
Cc: Heiko Carstens 
Cc: linux-s...@vger.kernel.org
Signed-off-by: Paul Gortmaker 
---
 arch/s390/kernel/early.c   | 2 +-
 arch/s390/kernel/kprobes.c | 2 ++
 arch/s390/kernel/traps.c   | 3 ++-
 arch/s390/mm/fault.c   | 2 +-
 4 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/s390/kernel/early.c b/arch/s390/kernel/early.c
index 717b03aa16b5..2374c5b46bbc 100644
--- a/arch/s390/kernel/early.c
+++ b/arch/s390/kernel/early.c
@@ -13,7 +13,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/s390/kernel/kprobes.c b/arch/s390/kernel/kprobes.c
index 250f5972536a..4871c7c3ccde 100644
--- a/arch/s390/kernel/kprobes.c
+++ b/arch/s390/kernel/kprobes.c
@@ -26,12 +26,14 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 DEFINE_PER_CPU(struct kprobe *, current_kprobe);
diff --git a/arch/s390/kernel/traps.c b/arch/s390/kernel/traps.c
index dd97a3e8a34a..d0539f76fd24 100644
--- a/arch/s390/kernel/traps.c
+++ b/arch/s390/kernel/traps.c
@@ -14,11 +14,12 @@
  */
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include "entry.h"
 
diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c
index a58bca62a93b..cca73881e672 100644
--- a/arch/s390/mm/fault.c
+++ b/arch/s390/mm/fault.c
@@ -24,7 +24,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH 13/14] core: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were including module.h for exception table related
functions.  We've now separated that content out into its own file
"extable.h" so now move over to that and where possible, avoid all
the extra header content in module.h that we don't really need to
compile these non-modular files.

Note:
   init/main.c still needs module.h for __init_or_module
   kernel/extable.c still needs module.h for is_module_text_address

...and so we don't get the benefit of removing module.h from the cpp
feed for these two files, unlike the almost universal 1:1 exchange
of module.h for extable.h we were able to do in the arch dirs.

Cc: Rusty Russell 
Cc: Andrew Morton 
Cc: Linus Torvalds 
Signed-off-by: Paul Gortmaker 
---
 init/main.c  | 1 +
 kernel/extable.c | 1 +
 kernel/module.c  | 1 +
 3 files changed, 3 insertions(+)

diff --git a/init/main.c b/init/main.c
index 9a9a25570f72..42fa8368d4a9 100644
--- a/init/main.c
+++ b/init/main.c
@@ -12,6 +12,7 @@
 #define DEBUG  /* Enable initcall_debug */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/kernel/extable.c b/kernel/extable.c
index e820ccee9846..55038378d882 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -17,6 +17,7 @@
 */
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/kernel/module.c b/kernel/module.c
index e70a2faf71d9..536ab4b72761 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -17,6 +17,7 @@
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH 03/14] arm: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: Russell King 
Cc: linux-arm-ker...@lists.infradead.org
Signed-off-by: Paul Gortmaker 
---
 arch/arm/mm/extable.c | 2 +-
 arch/arm/mm/fault.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mm/extable.c b/arch/arm/mm/extable.c
index 312e15e6d00b..f436f7439e46 100644
--- a/arch/arm/mm/extable.c
+++ b/arch/arm/mm/extable.c
@@ -1,7 +1,7 @@
 /*
  *  linux/arch/arm/mm/extable.c
  */
-#include 
+#include 
 #include 
 
 int fixup_exception(struct pt_regs *regs)
diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
index 3a2e678b8d30..94de590db99e 100644
--- a/arch/arm/mm/fault.c
+++ b/arch/arm/mm/fault.c
@@ -8,7 +8,7 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
-#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH 04/14] arm64: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: Catalin Marinas 
Cc: Will Deacon 
Cc: linux-arm-ker...@lists.infradead.org
Signed-off-by: Paul Gortmaker 
---
 arch/arm64/kernel/probes/kprobes.c | 2 +-
 arch/arm64/mm/extable.c| 2 +-
 arch/arm64/mm/fault.c  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/kernel/probes/kprobes.c 
b/arch/arm64/kernel/probes/kprobes.c
index bf9768588288..9c1866ef3271 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -19,7 +19,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/arm64/mm/extable.c b/arch/arm64/mm/extable.c
index 81acd4706878..c9f118cd812b 100644
--- a/arch/arm64/mm/extable.c
+++ b/arch/arm64/mm/extable.c
@@ -2,7 +2,7 @@
  * Based on arch/arm/mm/extable.c
  */
 
-#include 
+#include 
 #include 
 
 int fixup_exception(struct pt_regs *regs)
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index c8beaa0da7df..427f2fd49463 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -18,7 +18,7 @@
  * along with this program.  If not, see .
  */
 
-#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH 09/14] s390: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

The additions of uaccess.h are to deal with implict includes like:

arch/s390/kernel/traps.c: In function 'do_report_trap':
arch/s390/kernel/traps.c:56:4: error: implicit declaration of function 
'extable_fixup' [-Werror=implicit-function-declaration]
arch/s390/kernel/traps.c: In function 'illegal_op':
arch/s390/kernel/traps.c:173:3: error: implicit declaration of function 
'get_user' [-Werror=implicit-function-declaration]

Cc: Martin Schwidefsky 
Cc: Heiko Carstens 
Cc: linux-s...@vger.kernel.org
Signed-off-by: Paul Gortmaker 
---
 arch/s390/kernel/early.c   | 2 +-
 arch/s390/kernel/kprobes.c | 2 ++
 arch/s390/kernel/traps.c   | 3 ++-
 arch/s390/mm/fault.c   | 2 +-
 4 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/s390/kernel/early.c b/arch/s390/kernel/early.c
index 717b03aa16b5..2374c5b46bbc 100644
--- a/arch/s390/kernel/early.c
+++ b/arch/s390/kernel/early.c
@@ -13,7 +13,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/s390/kernel/kprobes.c b/arch/s390/kernel/kprobes.c
index 250f5972536a..4871c7c3ccde 100644
--- a/arch/s390/kernel/kprobes.c
+++ b/arch/s390/kernel/kprobes.c
@@ -26,12 +26,14 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 DEFINE_PER_CPU(struct kprobe *, current_kprobe);
diff --git a/arch/s390/kernel/traps.c b/arch/s390/kernel/traps.c
index dd97a3e8a34a..d0539f76fd24 100644
--- a/arch/s390/kernel/traps.c
+++ b/arch/s390/kernel/traps.c
@@ -14,11 +14,12 @@
  */
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include "entry.h"
 
diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c
index a58bca62a93b..cca73881e672 100644
--- a/arch/s390/mm/fault.c
+++ b/arch/s390/mm/fault.c
@@ -24,7 +24,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH 13/14] core: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were including module.h for exception table related
functions.  We've now separated that content out into its own file
"extable.h" so now move over to that and where possible, avoid all
the extra header content in module.h that we don't really need to
compile these non-modular files.

Note:
   init/main.c still needs module.h for __init_or_module
   kernel/extable.c still needs module.h for is_module_text_address

...and so we don't get the benefit of removing module.h from the cpp
feed for these two files, unlike the almost universal 1:1 exchange
of module.h for extable.h we were able to do in the arch dirs.

Cc: Rusty Russell 
Cc: Andrew Morton 
Cc: Linus Torvalds 
Signed-off-by: Paul Gortmaker 
---
 init/main.c  | 1 +
 kernel/extable.c | 1 +
 kernel/module.c  | 1 +
 3 files changed, 3 insertions(+)

diff --git a/init/main.c b/init/main.c
index 9a9a25570f72..42fa8368d4a9 100644
--- a/init/main.c
+++ b/init/main.c
@@ -12,6 +12,7 @@
 #define DEBUG  /* Enable initcall_debug */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/kernel/extable.c b/kernel/extable.c
index e820ccee9846..55038378d882 100644
--- a/kernel/extable.c
+++ b/kernel/extable.c
@@ -17,6 +17,7 @@
 */
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/kernel/module.c b/kernel/module.c
index e70a2faf71d9..536ab4b72761 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -17,6 +17,7 @@
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH 12/14] parisc: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
This file was only including module.h for exception table related
functions.  We've now separated that content out into its own file
"extable.h" so now move over to that and avoid all the extra header
content in module.h that we don't really need to compile this file.

Cc: "James E.J. Bottomley" 
Cc: Helge Deller 
Cc: linux-par...@vger.kernel.org
Signed-off-by: Paul Gortmaker 
---
 arch/parisc/mm/fault.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
index 163af2c31d76..a67519b79504 100644
--- a/arch/parisc/mm/fault.c
+++ b/arch/parisc/mm/fault.c
@@ -14,7 +14,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 #include 
-- 
2.8.4



[PATCH 02/14] x86: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: "H. Peter Anvin" 
Cc: x...@kernel.org
Signed-off-by: Paul Gortmaker 
---
 arch/x86/kernel/kprobes/core.c | 2 +-
 arch/x86/kernel/kprobes/opt.c  | 2 +-
 arch/x86/mm/extable.c  | 2 +-
 arch/x86/mm/fault.c| 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index 7847e5c0e0b5..28cee019209c 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -45,7 +45,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
index 4425f593f0ec..3bb4c5f021f6 100644
--- a/arch/x86/kernel/kprobes/opt.c
+++ b/arch/x86/kernel/kprobes/opt.c
@@ -24,7 +24,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
index 832b98f822be..79ae939970d3 100644
--- a/arch/x86/mm/extable.c
+++ b/arch/x86/mm/extable.c
@@ -1,4 +1,4 @@
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index dc8023060456..79ae05477d94 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -5,7 +5,7 @@
  */
 #include/* test_thread_flag(), ...  */
 #include   /* oops_begin/end, ...  */
-#include   /* search_exception_table   */
+#include  /* search_exception_table   */
 #include  /* max_low_pfn  */
 #include  /* NOKPROBE_SYMBOL, ... */
 #include/* kmmio_handler, ...   */
-- 
2.8.4



[PATCH 07/14] powerpc: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: linuxppc-...@lists.ozlabs.org
Signed-off-by: Paul Gortmaker 
---
 arch/powerpc/kernel/kprobes.c | 2 +-
 arch/powerpc/mm/fault.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index 3ed8ec09b5c9..e785cc9e1ecd 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -29,7 +29,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index a4db22f65021..bb1ffc559f38 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -26,7 +26,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH 12/14] parisc: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
This file was only including module.h for exception table related
functions.  We've now separated that content out into its own file
"extable.h" so now move over to that and avoid all the extra header
content in module.h that we don't really need to compile this file.

Cc: "James E.J. Bottomley" 
Cc: Helge Deller 
Cc: linux-par...@vger.kernel.org
Signed-off-by: Paul Gortmaker 
---
 arch/parisc/mm/fault.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
index 163af2c31d76..a67519b79504 100644
--- a/arch/parisc/mm/fault.c
+++ b/arch/parisc/mm/fault.c
@@ -14,7 +14,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 #include 
-- 
2.8.4



[PATCH 02/14] x86: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: "H. Peter Anvin" 
Cc: x...@kernel.org
Signed-off-by: Paul Gortmaker 
---
 arch/x86/kernel/kprobes/core.c | 2 +-
 arch/x86/kernel/kprobes/opt.c  | 2 +-
 arch/x86/mm/extable.c  | 2 +-
 arch/x86/mm/fault.c| 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index 7847e5c0e0b5..28cee019209c 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -45,7 +45,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
index 4425f593f0ec..3bb4c5f021f6 100644
--- a/arch/x86/kernel/kprobes/opt.c
+++ b/arch/x86/kernel/kprobes/opt.c
@@ -24,7 +24,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
index 832b98f822be..79ae939970d3 100644
--- a/arch/x86/mm/extable.c
+++ b/arch/x86/mm/extable.c
@@ -1,4 +1,4 @@
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index dc8023060456..79ae05477d94 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -5,7 +5,7 @@
  */
 #include/* test_thread_flag(), ...  */
 #include   /* oops_begin/end, ...  */
-#include   /* search_exception_table   */
+#include  /* search_exception_table   */
 #include  /* max_low_pfn  */
 #include  /* NOKPROBE_SYMBOL, ... */
 #include/* kmmio_handler, ...   */
-- 
2.8.4



[PATCH 07/14] powerpc: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: linuxppc-...@lists.ozlabs.org
Signed-off-by: Paul Gortmaker 
---
 arch/powerpc/kernel/kprobes.c | 2 +-
 arch/powerpc/mm/fault.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index 3ed8ec09b5c9..e785cc9e1ecd 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -29,7 +29,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index a4db22f65021..bb1ffc559f38 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -26,7 +26,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH 05/14] mips: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: Ralf Baechle 
Cc: linux-m...@linux-mips.org
Signed-off-by: Paul Gortmaker 
---
 arch/mips/kernel/module.c | 1 +
 arch/mips/kernel/traps.c  | 2 +-
 arch/mips/mm/extable.c| 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c
index 79850e376ef6..94627a3a6a0d 100644
--- a/arch/mips/kernel/module.c
+++ b/arch/mips/kernel/module.c
@@ -20,6 +20,7 @@
 
 #undef DEBUG
 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index 6fb4704bd156..b4522e3a0562 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -20,7 +20,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/mips/mm/extable.c b/arch/mips/mm/extable.c
index 9d25d2ba4b9e..e474fa2efed4 100644
--- a/arch/mips/mm/extable.c
+++ b/arch/mips/mm/extable.c
@@ -5,7 +5,7 @@
  *
  * Copyright (C) 1997, 99, 2001 - 2004 Ralf Baechle 
  */
-#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH 01/14] exceptions: fork exception table content from module.h into extable.h

2016-07-24 Thread Paul Gortmaker
For historical reasons (i.e. pre-git) the exception table stuff was
buried in the middle of the module.h file.  I noticed this while
doing an audit for needless includes of module.h and found core
kernel files (both arch specific and arch independent) were just
including module.h for this.

The converse is also true, in that conventional drivers, be they
for filesystems or actual hardware peripherals or similar, do not
normally care about the exception tables.

Here we fork the exception table content out of module.h into a
new file called extable.h -- and temporarily include it into the
module.h itself.

Then we will work our way across the arch independent and arch
specific files needing just exception table content, and move
them off module.h and onto extable.h

Once that is done, we can remove the extable.h from module.h
and in doing it like this, we avoid introducing build failures
into the git history.

The gain here is that module.h gets a bit smaller, across all
modular drivers that we build for allmodconfig.  Also the core
files that only need exception table stuff don't have an include
of module.h that brings in lots of extra stuff and just looks
generally out of place.

Cc: Rusty Russell 
Cc: Andrew Morton 
Cc: Linus Torvalds 
Signed-off-by: Paul Gortmaker 
---
 include/linux/extable.h | 30 ++
 include/linux/module.h  | 27 ++-
 2 files changed, 32 insertions(+), 25 deletions(-)
 create mode 100644 include/linux/extable.h

diff --git a/include/linux/extable.h b/include/linux/extable.h
new file mode 100644
index ..2c71dccd1bc3
--- /dev/null
+++ b/include/linux/extable.h
@@ -0,0 +1,30 @@
+#ifndef _LINUX_EXTABLE_H
+#define _LINUX_EXTABLE_H
+
+struct module;
+struct exception_table_entry;
+
+const struct exception_table_entry *
+search_extable(const struct exception_table_entry *first,
+  const struct exception_table_entry *last,
+  unsigned long value);
+void sort_extable(struct exception_table_entry *start,
+ struct exception_table_entry *finish);
+void sort_main_extable(void);
+void trim_init_extable(struct module *m);
+
+/* Given an address, look for it in the exception tables */
+const struct exception_table_entry *search_exception_tables(unsigned long add);
+
+#ifdef CONFIG_MODULES
+/* For extable.c to search modules' exception tables. */
+const struct exception_table_entry *search_module_extables(unsigned long addr);
+#else
+static inline const struct exception_table_entry *
+search_module_extables(unsigned long addr)
+{
+   return NULL;
+}
+#endif /*CONFIG_MODULES*/
+
+#endif /* _LINUX_EXTABLE_H */
diff --git a/include/linux/module.h b/include/linux/module.h
index f777164c238b..f95ed243a4de 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include  /* only as arch move module.h -> extable.h */
 #include 
 
 #include 
@@ -37,6 +38,7 @@ struct modversion_info {
 };
 
 struct module;
+struct exception_table_entry;
 
 struct module_kobject {
struct kobject kobj;
@@ -155,18 +157,6 @@ extern void cleanup_module(void);
 #define __INITRODATA_OR_MODULE __INITRODATA
 #endif /*CONFIG_MODULES*/
 
-/* Archs provide a method of finding the correct exception table. */
-struct exception_table_entry;
-
-const struct exception_table_entry *
-search_extable(const struct exception_table_entry *first,
-  const struct exception_table_entry *last,
-  unsigned long value);
-void sort_extable(struct exception_table_entry *start,
- struct exception_table_entry *finish);
-void sort_main_extable(void);
-void trim_init_extable(struct module *m);
-
 /* Generic info of form tag = "info" */
 #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
 
@@ -268,9 +258,6 @@ extern const typeof(name) 
__mod_##type##__##name##_device_table \
  * files require multiple MODULE_FIRMWARE() specifiers */
 #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
 
-/* Given an address, look for it in the exception tables */
-const struct exception_table_entry *search_exception_tables(unsigned long add);
-
 struct notifier_block;
 
 #ifdef CONFIG_MODULES
@@ -630,9 +617,6 @@ const char *module_address_lookup(unsigned long addr,
 int lookup_module_symbol_name(unsigned long addr, char *symname);
 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, 
unsigned long *offset, char *modname, char *name);
 
-/* For extable.c to search modules' exception tables. */
-const struct exception_table_entry *search_module_extables(unsigned long addr);
-
 int register_module_notifier(struct notifier_block *nb);
 int unregister_module_notifier(struct notifier_block *nb);
 
@@ -657,13 +641,6 @@ static inline bool is_livepatch_module(struct module *mod)
 
 #else /* 

[PATCH 06/14] sparc: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: "David S. Miller" 
Cc: sparcli...@vger.kernel.org
Signed-off-by: Paul Gortmaker 
---
 arch/sparc/kernel/kprobes.c  | 2 +-
 arch/sparc/kernel/traps_64.c | 2 +-
 arch/sparc/kernel/unaligned_64.c | 2 +-
 arch/sparc/mm/fault_64.c | 2 +-
 arch/sparc/mm/init_64.c  | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/sparc/kernel/kprobes.c b/arch/sparc/kernel/kprobes.c
index cd83be527586..b0377db12d83 100644
--- a/arch/sparc/kernel/kprobes.c
+++ b/arch/sparc/kernel/kprobes.c
@@ -5,7 +5,7 @@
 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
index d21cd625c0de..4094a51b1970 100644
--- a/arch/sparc/kernel/traps_64.c
+++ b/arch/sparc/kernel/traps_64.c
@@ -8,7 +8,7 @@
  * I like traps on v9, :
  */
 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
index 9aacb9159262..52c00d90d4b4 100644
--- a/arch/sparc/kernel/unaligned_64.c
+++ b/arch/sparc/kernel/unaligned_64.c
@@ -11,7 +11,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
index 6c43b924a7a2..0e9773ca7ff1 100644
--- a/arch/sparc/mm/fault_64.c
+++ b/arch/sparc/mm/fault_64.c
@@ -14,7 +14,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
index aec508e37490..96680a687799 100644
--- a/arch/sparc/mm/init_64.c
+++ b/arch/sparc/mm/init_64.c
@@ -5,7 +5,7 @@
  *  Copyright (C) 1997-1999 Jakub Jelinek (j...@sunsite.mff.cuni.cz)
  */
  
-#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH 05/14] mips: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: Ralf Baechle 
Cc: linux-m...@linux-mips.org
Signed-off-by: Paul Gortmaker 
---
 arch/mips/kernel/module.c | 1 +
 arch/mips/kernel/traps.c  | 2 +-
 arch/mips/mm/extable.c| 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c
index 79850e376ef6..94627a3a6a0d 100644
--- a/arch/mips/kernel/module.c
+++ b/arch/mips/kernel/module.c
@@ -20,6 +20,7 @@
 
 #undef DEBUG
 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index 6fb4704bd156..b4522e3a0562 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -20,7 +20,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/mips/mm/extable.c b/arch/mips/mm/extable.c
index 9d25d2ba4b9e..e474fa2efed4 100644
--- a/arch/mips/mm/extable.c
+++ b/arch/mips/mm/extable.c
@@ -5,7 +5,7 @@
  *
  * Copyright (C) 1997, 99, 2001 - 2004 Ralf Baechle 
  */
-#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH 01/14] exceptions: fork exception table content from module.h into extable.h

2016-07-24 Thread Paul Gortmaker
For historical reasons (i.e. pre-git) the exception table stuff was
buried in the middle of the module.h file.  I noticed this while
doing an audit for needless includes of module.h and found core
kernel files (both arch specific and arch independent) were just
including module.h for this.

The converse is also true, in that conventional drivers, be they
for filesystems or actual hardware peripherals or similar, do not
normally care about the exception tables.

Here we fork the exception table content out of module.h into a
new file called extable.h -- and temporarily include it into the
module.h itself.

Then we will work our way across the arch independent and arch
specific files needing just exception table content, and move
them off module.h and onto extable.h

Once that is done, we can remove the extable.h from module.h
and in doing it like this, we avoid introducing build failures
into the git history.

The gain here is that module.h gets a bit smaller, across all
modular drivers that we build for allmodconfig.  Also the core
files that only need exception table stuff don't have an include
of module.h that brings in lots of extra stuff and just looks
generally out of place.

Cc: Rusty Russell 
Cc: Andrew Morton 
Cc: Linus Torvalds 
Signed-off-by: Paul Gortmaker 
---
 include/linux/extable.h | 30 ++
 include/linux/module.h  | 27 ++-
 2 files changed, 32 insertions(+), 25 deletions(-)
 create mode 100644 include/linux/extable.h

diff --git a/include/linux/extable.h b/include/linux/extable.h
new file mode 100644
index ..2c71dccd1bc3
--- /dev/null
+++ b/include/linux/extable.h
@@ -0,0 +1,30 @@
+#ifndef _LINUX_EXTABLE_H
+#define _LINUX_EXTABLE_H
+
+struct module;
+struct exception_table_entry;
+
+const struct exception_table_entry *
+search_extable(const struct exception_table_entry *first,
+  const struct exception_table_entry *last,
+  unsigned long value);
+void sort_extable(struct exception_table_entry *start,
+ struct exception_table_entry *finish);
+void sort_main_extable(void);
+void trim_init_extable(struct module *m);
+
+/* Given an address, look for it in the exception tables */
+const struct exception_table_entry *search_exception_tables(unsigned long add);
+
+#ifdef CONFIG_MODULES
+/* For extable.c to search modules' exception tables. */
+const struct exception_table_entry *search_module_extables(unsigned long addr);
+#else
+static inline const struct exception_table_entry *
+search_module_extables(unsigned long addr)
+{
+   return NULL;
+}
+#endif /*CONFIG_MODULES*/
+
+#endif /* _LINUX_EXTABLE_H */
diff --git a/include/linux/module.h b/include/linux/module.h
index f777164c238b..f95ed243a4de 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include  /* only as arch move module.h -> extable.h */
 #include 
 
 #include 
@@ -37,6 +38,7 @@ struct modversion_info {
 };
 
 struct module;
+struct exception_table_entry;
 
 struct module_kobject {
struct kobject kobj;
@@ -155,18 +157,6 @@ extern void cleanup_module(void);
 #define __INITRODATA_OR_MODULE __INITRODATA
 #endif /*CONFIG_MODULES*/
 
-/* Archs provide a method of finding the correct exception table. */
-struct exception_table_entry;
-
-const struct exception_table_entry *
-search_extable(const struct exception_table_entry *first,
-  const struct exception_table_entry *last,
-  unsigned long value);
-void sort_extable(struct exception_table_entry *start,
- struct exception_table_entry *finish);
-void sort_main_extable(void);
-void trim_init_extable(struct module *m);
-
 /* Generic info of form tag = "info" */
 #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
 
@@ -268,9 +258,6 @@ extern const typeof(name) 
__mod_##type##__##name##_device_table \
  * files require multiple MODULE_FIRMWARE() specifiers */
 #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
 
-/* Given an address, look for it in the exception tables */
-const struct exception_table_entry *search_exception_tables(unsigned long add);
-
 struct notifier_block;
 
 #ifdef CONFIG_MODULES
@@ -630,9 +617,6 @@ const char *module_address_lookup(unsigned long addr,
 int lookup_module_symbol_name(unsigned long addr, char *symname);
 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, 
unsigned long *offset, char *modname, char *name);
 
-/* For extable.c to search modules' exception tables. */
-const struct exception_table_entry *search_module_extables(unsigned long addr);
-
 int register_module_notifier(struct notifier_block *nb);
 int unregister_module_notifier(struct notifier_block *nb);
 
@@ -657,13 +641,6 @@ static inline bool is_livepatch_module(struct module *mod)
 
 #else /* !CONFIG_MODULES... */
 
-/* Given an address, look for it in the exception tables. */
-static inline const struct 

[PATCH 06/14] sparc: migrate exception table users off module.h and onto extable.h

2016-07-24 Thread Paul Gortmaker
These files were only including module.h for exception table
related functions.  We've now separated that content out into its
own file "extable.h" so now move over to that and avoid all the
extra header content in module.h that we don't really need to compile
these files.

Cc: "David S. Miller" 
Cc: sparcli...@vger.kernel.org
Signed-off-by: Paul Gortmaker 
---
 arch/sparc/kernel/kprobes.c  | 2 +-
 arch/sparc/kernel/traps_64.c | 2 +-
 arch/sparc/kernel/unaligned_64.c | 2 +-
 arch/sparc/mm/fault_64.c | 2 +-
 arch/sparc/mm/init_64.c  | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/sparc/kernel/kprobes.c b/arch/sparc/kernel/kprobes.c
index cd83be527586..b0377db12d83 100644
--- a/arch/sparc/kernel/kprobes.c
+++ b/arch/sparc/kernel/kprobes.c
@@ -5,7 +5,7 @@
 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
index d21cd625c0de..4094a51b1970 100644
--- a/arch/sparc/kernel/traps_64.c
+++ b/arch/sparc/kernel/traps_64.c
@@ -8,7 +8,7 @@
  * I like traps on v9, :
  */
 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
index 9aacb9159262..52c00d90d4b4 100644
--- a/arch/sparc/kernel/unaligned_64.c
+++ b/arch/sparc/kernel/unaligned_64.c
@@ -11,7 +11,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
index 6c43b924a7a2..0e9773ca7ff1 100644
--- a/arch/sparc/mm/fault_64.c
+++ b/arch/sparc/mm/fault_64.c
@@ -14,7 +14,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
index aec508e37490..96680a687799 100644
--- a/arch/sparc/mm/init_64.c
+++ b/arch/sparc/mm/init_64.c
@@ -5,7 +5,7 @@
  *  Copyright (C) 1997-1999 Jakub Jelinek (j...@sunsite.mff.cuni.cz)
  */
  
-#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.8.4



[PATCH v3 7/9] hwmon: (core) Add fan attribute support to new API

2016-07-24 Thread Guenter Roeck
Acked-by: Punit Agrawal 
Reviewed-by: Jonathan Cameron 
Signed-off-by: Guenter Roeck 
---
v3: No change
v2: No change

 drivers/hwmon/hwmon.c | 16 
 include/linux/hwmon.h | 27 +++
 2 files changed, 43 insertions(+)

diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 2dd4e0acfe12..4729d4742ab7 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -372,6 +372,20 @@ static const char * const hwmon_humidity_attr_templates[] 
= {
[hwmon_humidity_fault] = "humidity%d_fault",
 };
 
+static const char * const hwmon_fan_attr_templates[] = {
+   [hwmon_fan_input] = "fan%d_input",
+   [hwmon_fan_label] = "fan%d_label",
+   [hwmon_fan_min] = "fan%d_min",
+   [hwmon_fan_max] = "fan%d_max",
+   [hwmon_fan_div] = "fan%d_div",
+   [hwmon_fan_pulses] = "fan%d_pulses",
+   [hwmon_fan_target] = "fan%d_target",
+   [hwmon_fan_alarm] = "fan%d_alarm",
+   [hwmon_fan_min_alarm] = "fan%d_min_alarm",
+   [hwmon_fan_max_alarm] = "fan%d_max_alarm",
+   [hwmon_fan_fault] = "fan%d_fault",
+};
+
 static const char * const *__templates[] = {
[hwmon_chip] = hwmon_chip_attr_templates,
[hwmon_temp] = hwmon_temp_attr_templates,
@@ -380,6 +394,7 @@ static const char * const *__templates[] = {
[hwmon_power] = hwmon_power_attr_templates,
[hwmon_energy] = hwmon_energy_attr_templates,
[hwmon_humidity] = hwmon_humidity_attr_templates,
+   [hwmon_fan] = hwmon_fan_attr_templates,
 };
 
 static const int __templates_size[] = {
@@ -390,6 +405,7 @@ static const int __templates_size[] = {
[hwmon_power] = ARRAY_SIZE(hwmon_power_attr_templates),
[hwmon_energy] = ARRAY_SIZE(hwmon_energy_attr_templates),
[hwmon_humidity] = ARRAY_SIZE(hwmon_humidity_attr_templates),
+   [hwmon_fan] = ARRAY_SIZE(hwmon_fan_attr_templates),
 };
 
 static int hwmon_num_channel_attrs(const struct hwmon_channel_info *info)
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index 57d92f1d779b..74e89d45ff67 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -27,6 +27,7 @@ enum hwmon_sensor_types {
hwmon_power,
hwmon_energy,
hwmon_humidity,
+   hwmon_fan,
 };
 
 enum hwmon_chip_attributes {
@@ -245,6 +246,32 @@ enum hwmon_humidity_attributes {
 #define HWMON_H_ALARM  BIT(hwmon_humidity_alarm)
 #define HWMON_H_FAULT  BIT(hwmon_humidity_fault)
 
+enum hwmon_fan_attributes {
+   hwmon_fan_input,
+   hwmon_fan_label,
+   hwmon_fan_min,
+   hwmon_fan_max,
+   hwmon_fan_div,
+   hwmon_fan_pulses,
+   hwmon_fan_target,
+   hwmon_fan_alarm,
+   hwmon_fan_min_alarm,
+   hwmon_fan_max_alarm,
+   hwmon_fan_fault,
+};
+
+#define HWMON_F_INPUT  BIT(hwmon_fan_input)
+#define HWMON_F_LABEL  BIT(hwmon_fan_label)
+#define HWMON_F_MINBIT(hwmon_fan_min)
+#define HWMON_F_MAXBIT(hwmon_fan_max)
+#define HWMON_F_DIVBIT(hwmon_fan_div)
+#define HWMON_F_PULSES BIT(hwmon_fan_pulses)
+#define HWMON_F_TARGET BIT(hwmon_fan_target)
+#define HWMON_F_ALARM  BIT(hwmon_fan_alarm)
+#define HWMON_F_MIN_ALARM  BIT(hwmon_fan_min_alarm)
+#define HWMON_F_MAX_ALARM  BIT(hwmon_fan_max_alarm)
+#define HWMON_F_FAULT  BIT(hwmon_fan_fault)
+
 /**
  * struct hwmon_ops - hwmon device operations
  * @is_visible: Callback to return attribute visibility. Mandatory.
-- 
2.5.0



[PATCH v3 9/9] hwmon: (core) Add basic pwm attribute support to new API

2016-07-24 Thread Guenter Roeck
Add basic pwm attribute support (no auto attributes) to new API.

Reviewed-by: Jonathan Cameron 
Signed-off-by: Guenter Roeck 
---
v2: No change
v2: Added patch

 Documentation/hwmon/hwmon-kernel-api.txt |  2 ++
 drivers/hwmon/hwmon.c|  9 +
 include/linux/hwmon.h| 13 +
 3 files changed, 24 insertions(+)

diff --git a/Documentation/hwmon/hwmon-kernel-api.txt 
b/Documentation/hwmon/hwmon-kernel-api.txt
index f60a29ce7592..ef9d74947f5c 100644
--- a/Documentation/hwmon/hwmon-kernel-api.txt
+++ b/Documentation/hwmon/hwmon-kernel-api.txt
@@ -168,6 +168,7 @@ It contains following fields:
   * hwmon_energy   Energy sensor
   * hwmon_humidity Humidity sensor
   * hwmon_fan  Fan speed sensor
+  * hwmon_pwm  PWM control
 
 * config: Pointer to a 0-terminated list of configuration values for each
   sensor of the given type. Each value is a combination of bit values
@@ -230,6 +231,7 @@ HWMON_P_Power attributes, for use with 
hwmon_power.
 HWMON_E_   Energy attributes, for use with hwmon_energy.
 HWMON_H_   Humidity attributes, for use with hwmon_humidity.
 HWMON_F_   Fan speed attributes, for use with hwmon_fan.
+HWMON_PWM_ PWM control attributes, for use with hwmon_pwm.
 
 Driver callback functions
 -
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 4729d4742ab7..fade170977e8 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -386,6 +386,13 @@ static const char * const hwmon_fan_attr_templates[] = {
[hwmon_fan_fault] = "fan%d_fault",
 };
 
+static const char * const hwmon_pwm_attr_templates[] = {
+   [hwmon_pwm_input] = "pwm%d",
+   [hwmon_pwm_enable] = "pwm%d_enable",
+   [hwmon_pwm_mode] = "pwm%d_mode",
+   [hwmon_pwm_freq] = "pwm%d_freq",
+};
+
 static const char * const *__templates[] = {
[hwmon_chip] = hwmon_chip_attr_templates,
[hwmon_temp] = hwmon_temp_attr_templates,
@@ -395,6 +402,7 @@ static const char * const *__templates[] = {
[hwmon_energy] = hwmon_energy_attr_templates,
[hwmon_humidity] = hwmon_humidity_attr_templates,
[hwmon_fan] = hwmon_fan_attr_templates,
+   [hwmon_pwm] = hwmon_pwm_attr_templates,
 };
 
 static const int __templates_size[] = {
@@ -406,6 +414,7 @@ static const int __templates_size[] = {
[hwmon_energy] = ARRAY_SIZE(hwmon_energy_attr_templates),
[hwmon_humidity] = ARRAY_SIZE(hwmon_humidity_attr_templates),
[hwmon_fan] = ARRAY_SIZE(hwmon_fan_attr_templates),
+   [hwmon_pwm] = ARRAY_SIZE(hwmon_pwm_attr_templates),
 };
 
 static int hwmon_num_channel_attrs(const struct hwmon_channel_info *info)
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index 74e89d45ff67..9d2f8bde7d12 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -28,6 +28,7 @@ enum hwmon_sensor_types {
hwmon_energy,
hwmon_humidity,
hwmon_fan,
+   hwmon_pwm,
 };
 
 enum hwmon_chip_attributes {
@@ -272,6 +273,18 @@ enum hwmon_fan_attributes {
 #define HWMON_F_MAX_ALARM  BIT(hwmon_fan_max_alarm)
 #define HWMON_F_FAULT  BIT(hwmon_fan_fault)
 
+enum hwmon_pwm_attributes {
+   hwmon_pwm_input,
+   hwmon_pwm_enable,
+   hwmon_pwm_mode,
+   hwmon_pwm_freq,
+};
+
+#define HWMON_PWM_INPUTBIT(hwmon_pwm_input)
+#define HWMON_PWM_ENABLE   BIT(hwmon_pwm_enable)
+#define HWMON_PWM_MODE BIT(hwmon_pwm_mode)
+#define HWMON_PWM_FREQ BIT(hwmon_pwm_freq)
+
 /**
  * struct hwmon_ops - hwmon device operations
  * @is_visible: Callback to return attribute visibility. Mandatory.
-- 
2.5.0



[PATCH v3 7/9] hwmon: (core) Add fan attribute support to new API

2016-07-24 Thread Guenter Roeck
Acked-by: Punit Agrawal 
Reviewed-by: Jonathan Cameron 
Signed-off-by: Guenter Roeck 
---
v3: No change
v2: No change

 drivers/hwmon/hwmon.c | 16 
 include/linux/hwmon.h | 27 +++
 2 files changed, 43 insertions(+)

diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 2dd4e0acfe12..4729d4742ab7 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -372,6 +372,20 @@ static const char * const hwmon_humidity_attr_templates[] 
= {
[hwmon_humidity_fault] = "humidity%d_fault",
 };
 
+static const char * const hwmon_fan_attr_templates[] = {
+   [hwmon_fan_input] = "fan%d_input",
+   [hwmon_fan_label] = "fan%d_label",
+   [hwmon_fan_min] = "fan%d_min",
+   [hwmon_fan_max] = "fan%d_max",
+   [hwmon_fan_div] = "fan%d_div",
+   [hwmon_fan_pulses] = "fan%d_pulses",
+   [hwmon_fan_target] = "fan%d_target",
+   [hwmon_fan_alarm] = "fan%d_alarm",
+   [hwmon_fan_min_alarm] = "fan%d_min_alarm",
+   [hwmon_fan_max_alarm] = "fan%d_max_alarm",
+   [hwmon_fan_fault] = "fan%d_fault",
+};
+
 static const char * const *__templates[] = {
[hwmon_chip] = hwmon_chip_attr_templates,
[hwmon_temp] = hwmon_temp_attr_templates,
@@ -380,6 +394,7 @@ static const char * const *__templates[] = {
[hwmon_power] = hwmon_power_attr_templates,
[hwmon_energy] = hwmon_energy_attr_templates,
[hwmon_humidity] = hwmon_humidity_attr_templates,
+   [hwmon_fan] = hwmon_fan_attr_templates,
 };
 
 static const int __templates_size[] = {
@@ -390,6 +405,7 @@ static const int __templates_size[] = {
[hwmon_power] = ARRAY_SIZE(hwmon_power_attr_templates),
[hwmon_energy] = ARRAY_SIZE(hwmon_energy_attr_templates),
[hwmon_humidity] = ARRAY_SIZE(hwmon_humidity_attr_templates),
+   [hwmon_fan] = ARRAY_SIZE(hwmon_fan_attr_templates),
 };
 
 static int hwmon_num_channel_attrs(const struct hwmon_channel_info *info)
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index 57d92f1d779b..74e89d45ff67 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -27,6 +27,7 @@ enum hwmon_sensor_types {
hwmon_power,
hwmon_energy,
hwmon_humidity,
+   hwmon_fan,
 };
 
 enum hwmon_chip_attributes {
@@ -245,6 +246,32 @@ enum hwmon_humidity_attributes {
 #define HWMON_H_ALARM  BIT(hwmon_humidity_alarm)
 #define HWMON_H_FAULT  BIT(hwmon_humidity_fault)
 
+enum hwmon_fan_attributes {
+   hwmon_fan_input,
+   hwmon_fan_label,
+   hwmon_fan_min,
+   hwmon_fan_max,
+   hwmon_fan_div,
+   hwmon_fan_pulses,
+   hwmon_fan_target,
+   hwmon_fan_alarm,
+   hwmon_fan_min_alarm,
+   hwmon_fan_max_alarm,
+   hwmon_fan_fault,
+};
+
+#define HWMON_F_INPUT  BIT(hwmon_fan_input)
+#define HWMON_F_LABEL  BIT(hwmon_fan_label)
+#define HWMON_F_MINBIT(hwmon_fan_min)
+#define HWMON_F_MAXBIT(hwmon_fan_max)
+#define HWMON_F_DIVBIT(hwmon_fan_div)
+#define HWMON_F_PULSES BIT(hwmon_fan_pulses)
+#define HWMON_F_TARGET BIT(hwmon_fan_target)
+#define HWMON_F_ALARM  BIT(hwmon_fan_alarm)
+#define HWMON_F_MIN_ALARM  BIT(hwmon_fan_min_alarm)
+#define HWMON_F_MAX_ALARM  BIT(hwmon_fan_max_alarm)
+#define HWMON_F_FAULT  BIT(hwmon_fan_fault)
+
 /**
  * struct hwmon_ops - hwmon device operations
  * @is_visible: Callback to return attribute visibility. Mandatory.
-- 
2.5.0



[PATCH v3 9/9] hwmon: (core) Add basic pwm attribute support to new API

2016-07-24 Thread Guenter Roeck
Add basic pwm attribute support (no auto attributes) to new API.

Reviewed-by: Jonathan Cameron 
Signed-off-by: Guenter Roeck 
---
v2: No change
v2: Added patch

 Documentation/hwmon/hwmon-kernel-api.txt |  2 ++
 drivers/hwmon/hwmon.c|  9 +
 include/linux/hwmon.h| 13 +
 3 files changed, 24 insertions(+)

diff --git a/Documentation/hwmon/hwmon-kernel-api.txt 
b/Documentation/hwmon/hwmon-kernel-api.txt
index f60a29ce7592..ef9d74947f5c 100644
--- a/Documentation/hwmon/hwmon-kernel-api.txt
+++ b/Documentation/hwmon/hwmon-kernel-api.txt
@@ -168,6 +168,7 @@ It contains following fields:
   * hwmon_energy   Energy sensor
   * hwmon_humidity Humidity sensor
   * hwmon_fan  Fan speed sensor
+  * hwmon_pwm  PWM control
 
 * config: Pointer to a 0-terminated list of configuration values for each
   sensor of the given type. Each value is a combination of bit values
@@ -230,6 +231,7 @@ HWMON_P_Power attributes, for use with 
hwmon_power.
 HWMON_E_   Energy attributes, for use with hwmon_energy.
 HWMON_H_   Humidity attributes, for use with hwmon_humidity.
 HWMON_F_   Fan speed attributes, for use with hwmon_fan.
+HWMON_PWM_ PWM control attributes, for use with hwmon_pwm.
 
 Driver callback functions
 -
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 4729d4742ab7..fade170977e8 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -386,6 +386,13 @@ static const char * const hwmon_fan_attr_templates[] = {
[hwmon_fan_fault] = "fan%d_fault",
 };
 
+static const char * const hwmon_pwm_attr_templates[] = {
+   [hwmon_pwm_input] = "pwm%d",
+   [hwmon_pwm_enable] = "pwm%d_enable",
+   [hwmon_pwm_mode] = "pwm%d_mode",
+   [hwmon_pwm_freq] = "pwm%d_freq",
+};
+
 static const char * const *__templates[] = {
[hwmon_chip] = hwmon_chip_attr_templates,
[hwmon_temp] = hwmon_temp_attr_templates,
@@ -395,6 +402,7 @@ static const char * const *__templates[] = {
[hwmon_energy] = hwmon_energy_attr_templates,
[hwmon_humidity] = hwmon_humidity_attr_templates,
[hwmon_fan] = hwmon_fan_attr_templates,
+   [hwmon_pwm] = hwmon_pwm_attr_templates,
 };
 
 static const int __templates_size[] = {
@@ -406,6 +414,7 @@ static const int __templates_size[] = {
[hwmon_energy] = ARRAY_SIZE(hwmon_energy_attr_templates),
[hwmon_humidity] = ARRAY_SIZE(hwmon_humidity_attr_templates),
[hwmon_fan] = ARRAY_SIZE(hwmon_fan_attr_templates),
+   [hwmon_pwm] = ARRAY_SIZE(hwmon_pwm_attr_templates),
 };
 
 static int hwmon_num_channel_attrs(const struct hwmon_channel_info *info)
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index 74e89d45ff67..9d2f8bde7d12 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -28,6 +28,7 @@ enum hwmon_sensor_types {
hwmon_energy,
hwmon_humidity,
hwmon_fan,
+   hwmon_pwm,
 };
 
 enum hwmon_chip_attributes {
@@ -272,6 +273,18 @@ enum hwmon_fan_attributes {
 #define HWMON_F_MAX_ALARM  BIT(hwmon_fan_max_alarm)
 #define HWMON_F_FAULT  BIT(hwmon_fan_fault)
 
+enum hwmon_pwm_attributes {
+   hwmon_pwm_input,
+   hwmon_pwm_enable,
+   hwmon_pwm_mode,
+   hwmon_pwm_freq,
+};
+
+#define HWMON_PWM_INPUTBIT(hwmon_pwm_input)
+#define HWMON_PWM_ENABLE   BIT(hwmon_pwm_enable)
+#define HWMON_PWM_MODE BIT(hwmon_pwm_mode)
+#define HWMON_PWM_FREQ BIT(hwmon_pwm_freq)
+
 /**
  * struct hwmon_ops - hwmon device operations
  * @is_visible: Callback to return attribute visibility. Mandatory.
-- 
2.5.0



[PATCH v3 6/9] hwmon: (core) Add energy and humidity attribute support to new API

2016-07-24 Thread Guenter Roeck
Acked-by: Punit Agrawal 
Reviewed-by: Jonathan Cameron 
Signed-off-by: Guenter Roeck 
---
v3: No change

 drivers/hwmon/hwmon.c | 20 
 include/linux/hwmon.h | 29 +
 2 files changed, 49 insertions(+)

diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 85f4e27548cb..2dd4e0acfe12 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -356,12 +356,30 @@ static const char * const hwmon_power_attr_templates[] = {
[hwmon_power_crit_alarm] = "power%d_crit_alarm",
 };
 
+static const char * const hwmon_energy_attr_templates[] = {
+   [hwmon_energy_input] = "energy%d_input",
+   [hwmon_energy_label] = "energy%d_label",
+};
+
+static const char * const hwmon_humidity_attr_templates[] = {
+   [hwmon_humidity_input] = "humidity%d_input",
+   [hwmon_humidity_label] = "humidity%d_label",
+   [hwmon_humidity_min] = "humidity%d_min",
+   [hwmon_humidity_min_hyst] = "humidity%d_min_hyst",
+   [hwmon_humidity_max] = "humidity%d_max",
+   [hwmon_humidity_max_hyst] = "humidity%d_max_hyst",
+   [hwmon_humidity_alarm] = "humidity%d_alarm",
+   [hwmon_humidity_fault] = "humidity%d_fault",
+};
+
 static const char * const *__templates[] = {
[hwmon_chip] = hwmon_chip_attr_templates,
[hwmon_temp] = hwmon_temp_attr_templates,
[hwmon_in] = hwmon_in_attr_templates,
[hwmon_curr] = hwmon_curr_attr_templates,
[hwmon_power] = hwmon_power_attr_templates,
+   [hwmon_energy] = hwmon_energy_attr_templates,
+   [hwmon_humidity] = hwmon_humidity_attr_templates,
 };
 
 static const int __templates_size[] = {
@@ -370,6 +388,8 @@ static const int __templates_size[] = {
[hwmon_in] = ARRAY_SIZE(hwmon_in_attr_templates),
[hwmon_curr] = ARRAY_SIZE(hwmon_curr_attr_templates),
[hwmon_power] = ARRAY_SIZE(hwmon_power_attr_templates),
+   [hwmon_energy] = ARRAY_SIZE(hwmon_energy_attr_templates),
+   [hwmon_humidity] = ARRAY_SIZE(hwmon_humidity_attr_templates),
 };
 
 static int hwmon_num_channel_attrs(const struct hwmon_channel_info *info)
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index d7e432ef7c2a..57d92f1d779b 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -26,6 +26,7 @@ enum hwmon_sensor_types {
hwmon_curr,
hwmon_power,
hwmon_energy,
+   hwmon_humidity,
 };
 
 enum hwmon_chip_attributes {
@@ -216,6 +217,34 @@ enum hwmon_power_attributes {
 #define HWMON_P_MAX_ALARM  BIT(hwmon_power_max_alarm)
 #define HWMON_P_CRIT_ALARM BIT(hwmon_power_crit_alarm)
 
+enum hwmon_energy_attributes {
+   hwmon_energy_input,
+   hwmon_energy_label,
+};
+
+#define HWMON_E_INPUT  BIT(hwmon_energy_input)
+#define HWMON_E_LABEL  BIT(hwmon_energy_label)
+
+enum hwmon_humidity_attributes {
+   hwmon_humidity_input,
+   hwmon_humidity_label,
+   hwmon_humidity_min,
+   hwmon_humidity_min_hyst,
+   hwmon_humidity_max,
+   hwmon_humidity_max_hyst,
+   hwmon_humidity_alarm,
+   hwmon_humidity_fault,
+};
+
+#define HWMON_H_INPUT  BIT(hwmon_humidity_input)
+#define HWMON_H_LABEL  BIT(hwmon_humidity_label)
+#define HWMON_H_MINBIT(hwmon_humidity_min)
+#define HWMON_H_MIN_HYST   BIT(hwmon_humidity_min_hyst)
+#define HWMON_H_MAXBIT(hwmon_humidity_max)
+#define HWMON_H_MAX_HYST   BIT(hwmon_humidity_max_hyst)
+#define HWMON_H_ALARM  BIT(hwmon_humidity_alarm)
+#define HWMON_H_FAULT  BIT(hwmon_humidity_fault)
+
 /**
  * struct hwmon_ops - hwmon device operations
  * @is_visible: Callback to return attribute visibility. Mandatory.
-- 
2.5.0



[PATCH v3 5/9] hwmon: (core) Add power attribute support to new API

2016-07-24 Thread Guenter Roeck
Acked-by: Punit Agrawal 
Reviewed-by: Jonathan Cameron 
Signed-off-by: Guenter Roeck 
---
v3: No change
v2: No change

 drivers/hwmon/hwmon.c | 30 
 include/linux/hwmon.h | 54 +++
 2 files changed, 84 insertions(+)

diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 9229229a99a5..85f4e27548cb 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -261,6 +261,7 @@ static const char * const hwmon_chip_attr_templates[] = {
[hwmon_chip_temp_reset_history] = "temp_reset_history",
[hwmon_chip_in_reset_history] = "in_reset_history",
[hwmon_chip_curr_reset_history] = "curr_reset_history",
+   [hwmon_chip_power_reset_history] = "power_reset_history",
[hwmon_chip_update_interval] = "update_interval",
[hwmon_chip_alarms] = "alarms",
 };
@@ -328,11 +329,39 @@ static const char * const hwmon_curr_attr_templates[] = {
[hwmon_curr_crit_alarm] = "curr%d_crit_alarm",
 };
 
+static const char * const hwmon_power_attr_templates[] = {
+   [hwmon_power_average] = "power%d_average",
+   [hwmon_power_average_interval] = "power%d_average_interval",
+   [hwmon_power_average_interval_max] = "power%d_interval_max",
+   [hwmon_power_average_interval_min] = "power%d_interval_min",
+   [hwmon_power_average_highest] = "power%d_average_highest",
+   [hwmon_power_average_lowest] = "power%d_average_lowest",
+   [hwmon_power_average_max] = "power%d_average_max",
+   [hwmon_power_average_min] = "power%d_average_min",
+   [hwmon_power_input] = "power%d_input",
+   [hwmon_power_input_highest] = "power%d_input_highest",
+   [hwmon_power_input_lowest] = "power%d_input_lowest",
+   [hwmon_power_reset_history] = "power%d_reset_history",
+   [hwmon_power_accuracy] = "power%d_accuracy",
+   [hwmon_power_cap] = "power%d_cap",
+   [hwmon_power_cap_hyst] = "power%d_cap_hyst",
+   [hwmon_power_cap_max] = "power%d_cap_max",
+   [hwmon_power_cap_min] = "power%d_cap_min",
+   [hwmon_power_max] = "power%d_max",
+   [hwmon_power_crit] = "power%d_crit",
+   [hwmon_power_label] = "power%d_label",
+   [hwmon_power_alarm] = "power%d_alarm",
+   [hwmon_power_cap_alarm] = "power%d_cap_alarm",
+   [hwmon_power_max_alarm] = "power%d_max_alarm",
+   [hwmon_power_crit_alarm] = "power%d_crit_alarm",
+};
+
 static const char * const *__templates[] = {
[hwmon_chip] = hwmon_chip_attr_templates,
[hwmon_temp] = hwmon_temp_attr_templates,
[hwmon_in] = hwmon_in_attr_templates,
[hwmon_curr] = hwmon_curr_attr_templates,
+   [hwmon_power] = hwmon_power_attr_templates,
 };
 
 static const int __templates_size[] = {
@@ -340,6 +369,7 @@ static const int __templates_size[] = {
[hwmon_temp] = ARRAY_SIZE(hwmon_temp_attr_templates),
[hwmon_in] = ARRAY_SIZE(hwmon_in_attr_templates),
[hwmon_curr] = ARRAY_SIZE(hwmon_curr_attr_templates),
+   [hwmon_power] = ARRAY_SIZE(hwmon_power_attr_templates),
 };
 
 static int hwmon_num_channel_attrs(const struct hwmon_channel_info *info)
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index 8781c2253b1d..d7e432ef7c2a 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -32,6 +32,7 @@ enum hwmon_chip_attributes {
hwmon_chip_temp_reset_history,
hwmon_chip_in_reset_history,
hwmon_chip_curr_reset_history,
+   hwmon_chip_power_reset_history,
hwmon_chip_register_tz,
hwmon_chip_update_interval,
hwmon_chip_alarms,
@@ -40,6 +41,7 @@ enum hwmon_chip_attributes {
 #define HWMON_C_TEMP_RESET_HISTORY BIT(hwmon_chip_temp_reset_history)
 #define HWMON_C_IN_RESET_HISTORY   BIT(hwmon_chip_in_reset_history)
 #define HWMON_C_CURR_RESET_HISTORY BIT(hwmon_chip_curr_reset_history)
+#define HWMON_C_POWER_RESET_HISTORYBIT(hwmon_chip_power_reset_history)
 #define HWMON_C_REGISTER_TZBIT(hwmon_chip_register_tz)
 #define HWMON_C_UPDATE_INTERVALBIT(hwmon_chip_update_interval)
 #define HWMON_C_ALARMS BIT(hwmon_chip_alarms)
@@ -162,6 +164,58 @@ enum hwmon_curr_attributes {
 #define HWMON_C_LCRIT_ALARMBIT(hwmon_curr_lcrit_alarm)
 #define HWMON_C_CRIT_ALARM BIT(hwmon_curr_crit_alarm)
 
+enum hwmon_power_attributes {
+   hwmon_power_average,
+   hwmon_power_average_interval,
+   hwmon_power_average_interval_max,
+   hwmon_power_average_interval_min,
+   hwmon_power_average_highest,
+   hwmon_power_average_lowest,
+   hwmon_power_average_max,
+   hwmon_power_average_min,
+   hwmon_power_input,
+   hwmon_power_input_highest,
+   hwmon_power_input_lowest,
+   hwmon_power_reset_history,
+   hwmon_power_accuracy,
+   hwmon_power_cap,
+   hwmon_power_cap_hyst,
+   hwmon_power_cap_max,
+   hwmon_power_cap_min,
+

[PATCH v3 2/9] hwmon: (core) New hwmon registration API

2016-07-24 Thread Guenter Roeck
Up to now, each hwmon driver has to implement its own sysfs attributes.
This requires a lot of template code, and distracts from the driver's core
function to read and write chip registers.

To be able to reduce driver complexity, move sensor attribute handling
and thermal zone registration into hwmon core. By using the new API,
driver code and data size is typically reduced by 20-70%, depending
on driver complexity and the number of sysfs attributes supported.

With this patch, the new API only supports thermal sensors. Support for
other sensor types will be added with subsequent patches.

Acked-by: Punit Agrawal 
Reviewed-by: Jonathan Cameron 
Signed-off-by: Guenter Roeck 
---
v3:
- Thermal registration depends on IS_REACHABLE(CONFIG_THERMAL) and
  CONFIG_THERMAL_OF.
v2:
- Document callback function parameters of struct hwmon_ops in
  include/linux/hwmon.h.
- Clarify that the is_visible() callback is mandatory.
- Initialize device attribute read/write callback functions unconditionally.
- If an attribute has no template string, treat it as invisible, not as
  error. Affected are virtual attributes such as HWMON_C_REGISTER_TZ.
- Added newline to improve readability.

Review comments not addressed:
- Stick with u32 for attribute masks. We could use u64, but it is currently
  not needed, and changing it later would be straightforward.
- Do not use for_each_set_bit() to walk attribute masks.
  for_each_set_bit() expects a pointer to an unsigned long as argument,
  which would make it difficult to switch to u64 attribute masks if/when
  needed.

 drivers/hwmon/hwmon.c | 485 +++---
 include/linux/hwmon.h | 148 +++
 2 files changed, 606 insertions(+), 27 deletions(-)

diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 649a68d119b4..3e4cc442a089 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -12,6 +12,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include 
 #include 
 #include 
 #include 
@@ -21,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define HWMON_ID_PREFIX "hwmon"
 #define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d"
@@ -28,9 +30,35 @@
 struct hwmon_device {
const char *name;
struct device dev;
+   const struct hwmon_chip_info *chip;
+
+   struct attribute_group group;
+   const struct attribute_group **groups;
 };
+
 #define to_hwmon_device(d) container_of(d, struct hwmon_device, dev)
 
+struct hwmon_device_attribute {
+   struct device_attribute dev_attr;
+   const struct hwmon_ops *ops;
+   enum hwmon_sensor_types type;
+   u32 attr;
+   int index;
+};
+
+#define to_hwmon_attr(d) \
+   container_of(d, struct hwmon_device_attribute, dev_attr)
+
+/*
+ * Thermal zone information
+ * In addition to the reference to the hwmon device,
+ * also provides the sensor index.
+ */
+struct hwmon_thermal_data {
+   struct hwmon_device *hwdev; /* Reference to hwmon device */
+   int index;  /* sensor index */
+};
+
 static ssize_t
 show_name(struct device *dev, struct device_attribute *attr, char *buf)
 {
@@ -78,25 +106,286 @@ static struct class hwmon_class = {
 
 static DEFINE_IDA(hwmon_ida);
 
-/**
- * hwmon_device_register_with_groups - register w/ hwmon
- * @dev: the parent device
- * @name: hwmon name attribute
- * @drvdata: driver data to attach to created device
- * @groups: List of attribute groups to create
- *
- * hwmon_device_unregister() must be called when the device is no
- * longer needed.
- *
- * Returns the pointer to the new device.
- */
-struct device *
-hwmon_device_register_with_groups(struct device *dev, const char *name,
- void *drvdata,
- const struct attribute_group **groups)
+/* Thermal zone handling */
+
+#if IS_REACHABLE(CONFIG_THERMAL) && defined(CONFIG_THERMAL_OF)
+static int hwmon_thermal_get_temp(void *data, int *temp)
+{
+   struct hwmon_thermal_data *tdata = data;
+   struct hwmon_device *hwdev = tdata->hwdev;
+   int ret;
+   long t;
+
+   ret = hwdev->chip->ops->read(>dev, hwmon_temp, hwmon_temp_input,
+tdata->index, );
+   if (ret < 0)
+   return ret;
+
+   *temp = t;
+
+   return 0;
+}
+
+static struct thermal_zone_of_device_ops hwmon_thermal_ops = {
+   .get_temp = hwmon_thermal_get_temp,
+};
+
+static int hwmon_thermal_add_sensor(struct device *dev,
+   struct hwmon_device *hwdev, int index)
+{
+   struct hwmon_thermal_data *tdata;
+
+   tdata = devm_kzalloc(dev, sizeof(*tdata), GFP_KERNEL);
+   if (!tdata)
+   return -ENOMEM;
+
+   tdata->hwdev = hwdev;
+   tdata->index = index;
+
+   devm_thermal_zone_of_sensor_register(>dev, index, tdata,
+_thermal_ops);
+
+   return 0;

[PATCH v3 0/9] hwmon: New hwmon registration API

2016-07-24 Thread Guenter Roeck
Up to now, each hwmon driver has to implement its own sysfs attributes.
This requires a lot of template code, and distracts from the driver's
core function to read and write chip registers.

To be able to reduce driver complexity, move sensor attribute handling
and thermal zone registration into the hwmon core. By using the new API,
driver size is typically reduced by 20-50% depending on driver complexity
and the number of sysfs attributes supported.

The first patch of the series is preparatory; it reorders include files
in the hwmon core to make it easier to add or remove individual include
files.

The second patch of the series introduces the API as well as support
for temperature sensor attributes. Subsequent patches introduce support
for voltage, current, power, energy, humidity, fan speed, and basic pwm
attributes.

The series was tested by converting several drivers (lm75, lm90, tmp102,
tmp421, ltc4245, nct7904, max31790) to the new API. Testing was done with
real chips as well as with the hwmon driver module test code available
at https://github.com/groeck/module-tests.

v3:
- Thermal registration depends on IS_REACHABLE(CONFIG_THERMAL) and
  CONFIG_THERMAL_OF.
v2:
- Add patch 1/9 (order include files alphabetically).
- Add patch 9/9 (pwm support).
- Document callback function parameters of struct hwmon_ops in
  include/linux/hwmon.h.
- Clarify that the is_visible() callback is mandatory.
- If an attribute has no template string, treat it as invisible, not as
  error. Affected are virtual attributes such as HWMON_C_REGISTER_TZ.
- Initialize device attribute read/write callback functions unconditionally.
- Cosmetic changes, including typo fixes and added newlines for readability.


[PATCH v3 6/9] hwmon: (core) Add energy and humidity attribute support to new API

2016-07-24 Thread Guenter Roeck
Acked-by: Punit Agrawal 
Reviewed-by: Jonathan Cameron 
Signed-off-by: Guenter Roeck 
---
v3: No change

 drivers/hwmon/hwmon.c | 20 
 include/linux/hwmon.h | 29 +
 2 files changed, 49 insertions(+)

diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 85f4e27548cb..2dd4e0acfe12 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -356,12 +356,30 @@ static const char * const hwmon_power_attr_templates[] = {
[hwmon_power_crit_alarm] = "power%d_crit_alarm",
 };
 
+static const char * const hwmon_energy_attr_templates[] = {
+   [hwmon_energy_input] = "energy%d_input",
+   [hwmon_energy_label] = "energy%d_label",
+};
+
+static const char * const hwmon_humidity_attr_templates[] = {
+   [hwmon_humidity_input] = "humidity%d_input",
+   [hwmon_humidity_label] = "humidity%d_label",
+   [hwmon_humidity_min] = "humidity%d_min",
+   [hwmon_humidity_min_hyst] = "humidity%d_min_hyst",
+   [hwmon_humidity_max] = "humidity%d_max",
+   [hwmon_humidity_max_hyst] = "humidity%d_max_hyst",
+   [hwmon_humidity_alarm] = "humidity%d_alarm",
+   [hwmon_humidity_fault] = "humidity%d_fault",
+};
+
 static const char * const *__templates[] = {
[hwmon_chip] = hwmon_chip_attr_templates,
[hwmon_temp] = hwmon_temp_attr_templates,
[hwmon_in] = hwmon_in_attr_templates,
[hwmon_curr] = hwmon_curr_attr_templates,
[hwmon_power] = hwmon_power_attr_templates,
+   [hwmon_energy] = hwmon_energy_attr_templates,
+   [hwmon_humidity] = hwmon_humidity_attr_templates,
 };
 
 static const int __templates_size[] = {
@@ -370,6 +388,8 @@ static const int __templates_size[] = {
[hwmon_in] = ARRAY_SIZE(hwmon_in_attr_templates),
[hwmon_curr] = ARRAY_SIZE(hwmon_curr_attr_templates),
[hwmon_power] = ARRAY_SIZE(hwmon_power_attr_templates),
+   [hwmon_energy] = ARRAY_SIZE(hwmon_energy_attr_templates),
+   [hwmon_humidity] = ARRAY_SIZE(hwmon_humidity_attr_templates),
 };
 
 static int hwmon_num_channel_attrs(const struct hwmon_channel_info *info)
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index d7e432ef7c2a..57d92f1d779b 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -26,6 +26,7 @@ enum hwmon_sensor_types {
hwmon_curr,
hwmon_power,
hwmon_energy,
+   hwmon_humidity,
 };
 
 enum hwmon_chip_attributes {
@@ -216,6 +217,34 @@ enum hwmon_power_attributes {
 #define HWMON_P_MAX_ALARM  BIT(hwmon_power_max_alarm)
 #define HWMON_P_CRIT_ALARM BIT(hwmon_power_crit_alarm)
 
+enum hwmon_energy_attributes {
+   hwmon_energy_input,
+   hwmon_energy_label,
+};
+
+#define HWMON_E_INPUT  BIT(hwmon_energy_input)
+#define HWMON_E_LABEL  BIT(hwmon_energy_label)
+
+enum hwmon_humidity_attributes {
+   hwmon_humidity_input,
+   hwmon_humidity_label,
+   hwmon_humidity_min,
+   hwmon_humidity_min_hyst,
+   hwmon_humidity_max,
+   hwmon_humidity_max_hyst,
+   hwmon_humidity_alarm,
+   hwmon_humidity_fault,
+};
+
+#define HWMON_H_INPUT  BIT(hwmon_humidity_input)
+#define HWMON_H_LABEL  BIT(hwmon_humidity_label)
+#define HWMON_H_MINBIT(hwmon_humidity_min)
+#define HWMON_H_MIN_HYST   BIT(hwmon_humidity_min_hyst)
+#define HWMON_H_MAXBIT(hwmon_humidity_max)
+#define HWMON_H_MAX_HYST   BIT(hwmon_humidity_max_hyst)
+#define HWMON_H_ALARM  BIT(hwmon_humidity_alarm)
+#define HWMON_H_FAULT  BIT(hwmon_humidity_fault)
+
 /**
  * struct hwmon_ops - hwmon device operations
  * @is_visible: Callback to return attribute visibility. Mandatory.
-- 
2.5.0



[PATCH v3 5/9] hwmon: (core) Add power attribute support to new API

2016-07-24 Thread Guenter Roeck
Acked-by: Punit Agrawal 
Reviewed-by: Jonathan Cameron 
Signed-off-by: Guenter Roeck 
---
v3: No change
v2: No change

 drivers/hwmon/hwmon.c | 30 
 include/linux/hwmon.h | 54 +++
 2 files changed, 84 insertions(+)

diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 9229229a99a5..85f4e27548cb 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -261,6 +261,7 @@ static const char * const hwmon_chip_attr_templates[] = {
[hwmon_chip_temp_reset_history] = "temp_reset_history",
[hwmon_chip_in_reset_history] = "in_reset_history",
[hwmon_chip_curr_reset_history] = "curr_reset_history",
+   [hwmon_chip_power_reset_history] = "power_reset_history",
[hwmon_chip_update_interval] = "update_interval",
[hwmon_chip_alarms] = "alarms",
 };
@@ -328,11 +329,39 @@ static const char * const hwmon_curr_attr_templates[] = {
[hwmon_curr_crit_alarm] = "curr%d_crit_alarm",
 };
 
+static const char * const hwmon_power_attr_templates[] = {
+   [hwmon_power_average] = "power%d_average",
+   [hwmon_power_average_interval] = "power%d_average_interval",
+   [hwmon_power_average_interval_max] = "power%d_interval_max",
+   [hwmon_power_average_interval_min] = "power%d_interval_min",
+   [hwmon_power_average_highest] = "power%d_average_highest",
+   [hwmon_power_average_lowest] = "power%d_average_lowest",
+   [hwmon_power_average_max] = "power%d_average_max",
+   [hwmon_power_average_min] = "power%d_average_min",
+   [hwmon_power_input] = "power%d_input",
+   [hwmon_power_input_highest] = "power%d_input_highest",
+   [hwmon_power_input_lowest] = "power%d_input_lowest",
+   [hwmon_power_reset_history] = "power%d_reset_history",
+   [hwmon_power_accuracy] = "power%d_accuracy",
+   [hwmon_power_cap] = "power%d_cap",
+   [hwmon_power_cap_hyst] = "power%d_cap_hyst",
+   [hwmon_power_cap_max] = "power%d_cap_max",
+   [hwmon_power_cap_min] = "power%d_cap_min",
+   [hwmon_power_max] = "power%d_max",
+   [hwmon_power_crit] = "power%d_crit",
+   [hwmon_power_label] = "power%d_label",
+   [hwmon_power_alarm] = "power%d_alarm",
+   [hwmon_power_cap_alarm] = "power%d_cap_alarm",
+   [hwmon_power_max_alarm] = "power%d_max_alarm",
+   [hwmon_power_crit_alarm] = "power%d_crit_alarm",
+};
+
 static const char * const *__templates[] = {
[hwmon_chip] = hwmon_chip_attr_templates,
[hwmon_temp] = hwmon_temp_attr_templates,
[hwmon_in] = hwmon_in_attr_templates,
[hwmon_curr] = hwmon_curr_attr_templates,
+   [hwmon_power] = hwmon_power_attr_templates,
 };
 
 static const int __templates_size[] = {
@@ -340,6 +369,7 @@ static const int __templates_size[] = {
[hwmon_temp] = ARRAY_SIZE(hwmon_temp_attr_templates),
[hwmon_in] = ARRAY_SIZE(hwmon_in_attr_templates),
[hwmon_curr] = ARRAY_SIZE(hwmon_curr_attr_templates),
+   [hwmon_power] = ARRAY_SIZE(hwmon_power_attr_templates),
 };
 
 static int hwmon_num_channel_attrs(const struct hwmon_channel_info *info)
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index 8781c2253b1d..d7e432ef7c2a 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -32,6 +32,7 @@ enum hwmon_chip_attributes {
hwmon_chip_temp_reset_history,
hwmon_chip_in_reset_history,
hwmon_chip_curr_reset_history,
+   hwmon_chip_power_reset_history,
hwmon_chip_register_tz,
hwmon_chip_update_interval,
hwmon_chip_alarms,
@@ -40,6 +41,7 @@ enum hwmon_chip_attributes {
 #define HWMON_C_TEMP_RESET_HISTORY BIT(hwmon_chip_temp_reset_history)
 #define HWMON_C_IN_RESET_HISTORY   BIT(hwmon_chip_in_reset_history)
 #define HWMON_C_CURR_RESET_HISTORY BIT(hwmon_chip_curr_reset_history)
+#define HWMON_C_POWER_RESET_HISTORYBIT(hwmon_chip_power_reset_history)
 #define HWMON_C_REGISTER_TZBIT(hwmon_chip_register_tz)
 #define HWMON_C_UPDATE_INTERVALBIT(hwmon_chip_update_interval)
 #define HWMON_C_ALARMS BIT(hwmon_chip_alarms)
@@ -162,6 +164,58 @@ enum hwmon_curr_attributes {
 #define HWMON_C_LCRIT_ALARMBIT(hwmon_curr_lcrit_alarm)
 #define HWMON_C_CRIT_ALARM BIT(hwmon_curr_crit_alarm)
 
+enum hwmon_power_attributes {
+   hwmon_power_average,
+   hwmon_power_average_interval,
+   hwmon_power_average_interval_max,
+   hwmon_power_average_interval_min,
+   hwmon_power_average_highest,
+   hwmon_power_average_lowest,
+   hwmon_power_average_max,
+   hwmon_power_average_min,
+   hwmon_power_input,
+   hwmon_power_input_highest,
+   hwmon_power_input_lowest,
+   hwmon_power_reset_history,
+   hwmon_power_accuracy,
+   hwmon_power_cap,
+   hwmon_power_cap_hyst,
+   hwmon_power_cap_max,
+   hwmon_power_cap_min,
+   hwmon_power_max,
+   hwmon_power_crit,
+   

[PATCH v3 2/9] hwmon: (core) New hwmon registration API

2016-07-24 Thread Guenter Roeck
Up to now, each hwmon driver has to implement its own sysfs attributes.
This requires a lot of template code, and distracts from the driver's core
function to read and write chip registers.

To be able to reduce driver complexity, move sensor attribute handling
and thermal zone registration into hwmon core. By using the new API,
driver code and data size is typically reduced by 20-70%, depending
on driver complexity and the number of sysfs attributes supported.

With this patch, the new API only supports thermal sensors. Support for
other sensor types will be added with subsequent patches.

Acked-by: Punit Agrawal 
Reviewed-by: Jonathan Cameron 
Signed-off-by: Guenter Roeck 
---
v3:
- Thermal registration depends on IS_REACHABLE(CONFIG_THERMAL) and
  CONFIG_THERMAL_OF.
v2:
- Document callback function parameters of struct hwmon_ops in
  include/linux/hwmon.h.
- Clarify that the is_visible() callback is mandatory.
- Initialize device attribute read/write callback functions unconditionally.
- If an attribute has no template string, treat it as invisible, not as
  error. Affected are virtual attributes such as HWMON_C_REGISTER_TZ.
- Added newline to improve readability.

Review comments not addressed:
- Stick with u32 for attribute masks. We could use u64, but it is currently
  not needed, and changing it later would be straightforward.
- Do not use for_each_set_bit() to walk attribute masks.
  for_each_set_bit() expects a pointer to an unsigned long as argument,
  which would make it difficult to switch to u64 attribute masks if/when
  needed.

 drivers/hwmon/hwmon.c | 485 +++---
 include/linux/hwmon.h | 148 +++
 2 files changed, 606 insertions(+), 27 deletions(-)

diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 649a68d119b4..3e4cc442a089 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -12,6 +12,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include 
 #include 
 #include 
 #include 
@@ -21,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define HWMON_ID_PREFIX "hwmon"
 #define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d"
@@ -28,9 +30,35 @@
 struct hwmon_device {
const char *name;
struct device dev;
+   const struct hwmon_chip_info *chip;
+
+   struct attribute_group group;
+   const struct attribute_group **groups;
 };
+
 #define to_hwmon_device(d) container_of(d, struct hwmon_device, dev)
 
+struct hwmon_device_attribute {
+   struct device_attribute dev_attr;
+   const struct hwmon_ops *ops;
+   enum hwmon_sensor_types type;
+   u32 attr;
+   int index;
+};
+
+#define to_hwmon_attr(d) \
+   container_of(d, struct hwmon_device_attribute, dev_attr)
+
+/*
+ * Thermal zone information
+ * In addition to the reference to the hwmon device,
+ * also provides the sensor index.
+ */
+struct hwmon_thermal_data {
+   struct hwmon_device *hwdev; /* Reference to hwmon device */
+   int index;  /* sensor index */
+};
+
 static ssize_t
 show_name(struct device *dev, struct device_attribute *attr, char *buf)
 {
@@ -78,25 +106,286 @@ static struct class hwmon_class = {
 
 static DEFINE_IDA(hwmon_ida);
 
-/**
- * hwmon_device_register_with_groups - register w/ hwmon
- * @dev: the parent device
- * @name: hwmon name attribute
- * @drvdata: driver data to attach to created device
- * @groups: List of attribute groups to create
- *
- * hwmon_device_unregister() must be called when the device is no
- * longer needed.
- *
- * Returns the pointer to the new device.
- */
-struct device *
-hwmon_device_register_with_groups(struct device *dev, const char *name,
- void *drvdata,
- const struct attribute_group **groups)
+/* Thermal zone handling */
+
+#if IS_REACHABLE(CONFIG_THERMAL) && defined(CONFIG_THERMAL_OF)
+static int hwmon_thermal_get_temp(void *data, int *temp)
+{
+   struct hwmon_thermal_data *tdata = data;
+   struct hwmon_device *hwdev = tdata->hwdev;
+   int ret;
+   long t;
+
+   ret = hwdev->chip->ops->read(>dev, hwmon_temp, hwmon_temp_input,
+tdata->index, );
+   if (ret < 0)
+   return ret;
+
+   *temp = t;
+
+   return 0;
+}
+
+static struct thermal_zone_of_device_ops hwmon_thermal_ops = {
+   .get_temp = hwmon_thermal_get_temp,
+};
+
+static int hwmon_thermal_add_sensor(struct device *dev,
+   struct hwmon_device *hwdev, int index)
+{
+   struct hwmon_thermal_data *tdata;
+
+   tdata = devm_kzalloc(dev, sizeof(*tdata), GFP_KERNEL);
+   if (!tdata)
+   return -ENOMEM;
+
+   tdata->hwdev = hwdev;
+   tdata->index = index;
+
+   devm_thermal_zone_of_sensor_register(>dev, index, tdata,
+_thermal_ops);
+
+   return 0;
+}
+#else
+static int hwmon_thermal_add_sensor(struct device 

[PATCH v3 0/9] hwmon: New hwmon registration API

2016-07-24 Thread Guenter Roeck
Up to now, each hwmon driver has to implement its own sysfs attributes.
This requires a lot of template code, and distracts from the driver's
core function to read and write chip registers.

To be able to reduce driver complexity, move sensor attribute handling
and thermal zone registration into the hwmon core. By using the new API,
driver size is typically reduced by 20-50% depending on driver complexity
and the number of sysfs attributes supported.

The first patch of the series is preparatory; it reorders include files
in the hwmon core to make it easier to add or remove individual include
files.

The second patch of the series introduces the API as well as support
for temperature sensor attributes. Subsequent patches introduce support
for voltage, current, power, energy, humidity, fan speed, and basic pwm
attributes.

The series was tested by converting several drivers (lm75, lm90, tmp102,
tmp421, ltc4245, nct7904, max31790) to the new API. Testing was done with
real chips as well as with the hwmon driver module test code available
at https://github.com/groeck/module-tests.

v3:
- Thermal registration depends on IS_REACHABLE(CONFIG_THERMAL) and
  CONFIG_THERMAL_OF.
v2:
- Add patch 1/9 (order include files alphabetically).
- Add patch 9/9 (pwm support).
- Document callback function parameters of struct hwmon_ops in
  include/linux/hwmon.h.
- Clarify that the is_visible() callback is mandatory.
- If an attribute has no template string, treat it as invisible, not as
  error. Affected are virtual attributes such as HWMON_C_REGISTER_TZ.
- Initialize device attribute read/write callback functions unconditionally.
- Cosmetic changes, including typo fixes and added newlines for readability.


[PATCH v3 4/9] hwmon: (core) Add current attribute support to new API

2016-07-24 Thread Guenter Roeck
Acked-by: Punit Agrawal 
Reviewed-by: Jonathan Cameron 
Signed-off-by: Guenter Roeck 
---
v3: No change
v2: No change

 drivers/hwmon/hwmon.c | 21 +
 include/linux/hwmon.h | 36 
 2 files changed, 57 insertions(+)

diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 7697dfa92558..9229229a99a5 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -260,6 +260,7 @@ static struct attribute *hwmon_genattr(struct device *dev,
 static const char * const hwmon_chip_attr_templates[] = {
[hwmon_chip_temp_reset_history] = "temp_reset_history",
[hwmon_chip_in_reset_history] = "in_reset_history",
+   [hwmon_chip_curr_reset_history] = "curr_reset_history",
[hwmon_chip_update_interval] = "update_interval",
[hwmon_chip_alarms] = "alarms",
 };
@@ -309,16 +310,36 @@ static const char * const hwmon_in_attr_templates[] = {
[hwmon_in_crit_alarm] = "in%d_crit_alarm",
 };
 
+static const char * const hwmon_curr_attr_templates[] = {
+   [hwmon_curr_input] = "curr%d_input",
+   [hwmon_curr_min] = "curr%d_min",
+   [hwmon_curr_max] = "curr%d_max",
+   [hwmon_curr_lcrit] = "curr%d_lcrit",
+   [hwmon_curr_crit] = "curr%d_crit",
+   [hwmon_curr_average] = "curr%d_average",
+   [hwmon_curr_lowest] = "curr%d_lowest",
+   [hwmon_curr_highest] = "curr%d_highest",
+   [hwmon_curr_reset_history] = "curr%d_reset_history",
+   [hwmon_curr_label] = "curr%d_label",
+   [hwmon_curr_alarm] = "curr%d_alarm",
+   [hwmon_curr_min_alarm] = "curr%d_min_alarm",
+   [hwmon_curr_max_alarm] = "curr%d_max_alarm",
+   [hwmon_curr_lcrit_alarm] = "curr%d_lcrit_alarm",
+   [hwmon_curr_crit_alarm] = "curr%d_crit_alarm",
+};
+
 static const char * const *__templates[] = {
[hwmon_chip] = hwmon_chip_attr_templates,
[hwmon_temp] = hwmon_temp_attr_templates,
[hwmon_in] = hwmon_in_attr_templates,
+   [hwmon_curr] = hwmon_curr_attr_templates,
 };
 
 static const int __templates_size[] = {
[hwmon_chip] = ARRAY_SIZE(hwmon_chip_attr_templates),
[hwmon_temp] = ARRAY_SIZE(hwmon_temp_attr_templates),
[hwmon_in] = ARRAY_SIZE(hwmon_in_attr_templates),
+   [hwmon_curr] = ARRAY_SIZE(hwmon_curr_attr_templates),
 };
 
 static int hwmon_num_channel_attrs(const struct hwmon_channel_info *info)
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index a01b8e3fc6f3..8781c2253b1d 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -31,6 +31,7 @@ enum hwmon_sensor_types {
 enum hwmon_chip_attributes {
hwmon_chip_temp_reset_history,
hwmon_chip_in_reset_history,
+   hwmon_chip_curr_reset_history,
hwmon_chip_register_tz,
hwmon_chip_update_interval,
hwmon_chip_alarms,
@@ -38,6 +39,7 @@ enum hwmon_chip_attributes {
 
 #define HWMON_C_TEMP_RESET_HISTORY BIT(hwmon_chip_temp_reset_history)
 #define HWMON_C_IN_RESET_HISTORY   BIT(hwmon_chip_in_reset_history)
+#define HWMON_C_CURR_RESET_HISTORY BIT(hwmon_chip_curr_reset_history)
 #define HWMON_C_REGISTER_TZBIT(hwmon_chip_register_tz)
 #define HWMON_C_UPDATE_INTERVALBIT(hwmon_chip_update_interval)
 #define HWMON_C_ALARMS BIT(hwmon_chip_alarms)
@@ -126,6 +128,40 @@ enum hwmon_in_attributes {
 #define HWMON_I_LCRIT_ALARMBIT(hwmon_in_lcrit_alarm)
 #define HWMON_I_CRIT_ALARM BIT(hwmon_in_crit_alarm)
 
+enum hwmon_curr_attributes {
+   hwmon_curr_input,
+   hwmon_curr_min,
+   hwmon_curr_max,
+   hwmon_curr_lcrit,
+   hwmon_curr_crit,
+   hwmon_curr_average,
+   hwmon_curr_lowest,
+   hwmon_curr_highest,
+   hwmon_curr_reset_history,
+   hwmon_curr_label,
+   hwmon_curr_alarm,
+   hwmon_curr_min_alarm,
+   hwmon_curr_max_alarm,
+   hwmon_curr_lcrit_alarm,
+   hwmon_curr_crit_alarm,
+};
+
+#define HWMON_C_INPUT  BIT(hwmon_curr_input)
+#define HWMON_C_MINBIT(hwmon_curr_min)
+#define HWMON_C_MAXBIT(hwmon_curr_max)
+#define HWMON_C_LCRIT  BIT(hwmon_curr_lcrit)
+#define HWMON_C_CRIT   BIT(hwmon_curr_crit)
+#define HWMON_C_AVERAGEBIT(hwmon_curr_average)
+#define HWMON_C_LOWEST BIT(hwmon_curr_lowest)
+#define HWMON_C_HIGHESTBIT(hwmon_curr_highest)
+#define HWMON_C_RESET_HISTORY  BIT(hwmon_curr_reset_history)
+#define HWMON_C_LABEL  BIT(hwmon_curr_label)
+#define HWMON_C_ALARM  BIT(hwmon_curr_alarm)
+#define HWMON_C_MIN_ALARM  BIT(hwmon_curr_min_alarm)
+#define HWMON_C_MAX_ALARM  BIT(hwmon_curr_max_alarm)
+#define HWMON_C_LCRIT_ALARMBIT(hwmon_curr_lcrit_alarm)
+#define HWMON_C_CRIT_ALARM BIT(hwmon_curr_crit_alarm)
+
 /**
  * struct hwmon_ops - hwmon device operations
  * @is_visible: Callback to return attribute visibility. Mandatory.
-- 
2.5.0



[PATCH v3 8/9] hwmon: (core) Document new kernel API

2016-07-24 Thread Guenter Roeck
Describe the new registration API function as well as the data
structures it requires.

Acked-by: Punit Agrawal 
Reviewed-by: Jonathan Cameron 
Signed-off-by: Guenter Roeck 
---
v3: No change
v2: Fixed typos

 Documentation/hwmon/hwmon-kernel-api.txt | 229 ++-
 1 file changed, 227 insertions(+), 2 deletions(-)

diff --git a/Documentation/hwmon/hwmon-kernel-api.txt 
b/Documentation/hwmon/hwmon-kernel-api.txt
index 2ecdbfc85ecf..f60a29ce7592 100644
--- a/Documentation/hwmon/hwmon-kernel-api.txt
+++ b/Documentation/hwmon/hwmon-kernel-api.txt
@@ -34,6 +34,19 @@ devm_hwmon_device_register_with_groups(struct device *dev,
   const char *name, void *drvdata,
   const struct attribute_group **groups);
 
+struct device *
+hwmon_device_register_with_info(struct device *dev,
+   const char *name, void *drvdata,
+   const struct hwmon_chip_info *info,
+   const struct attribute_group **groups);
+
+struct device *
+devm_hwmon_device_register_with_info(struct device *dev,
+const char *name,
+void *drvdata,
+const struct hwmon_chip_info *info,
+const struct attribute_group **groups);
+
 void hwmon_device_unregister(struct device *dev);
 void devm_hwmon_device_unregister(struct device *dev);
 
@@ -60,15 +73,227 @@ devm_hwmon_device_register_with_groups is similar to
 hwmon_device_register_with_groups. However, it is device managed, meaning the
 hwmon device does not have to be removed explicitly by the removal function.
 
+hwmon_device_register_with_info is the most comprehensive and preferred means
+to register a hardware monitoring device. It creates the standard sysfs
+attributes in the hardware monitoring core, letting the driver focus on reading
+from and writing to the chip instead of having to bother with sysfs attributes.
+Its parameters are described in more detail below.
+
+devm_hwmon_device_register_with_info is similar to
+hwmon_device_register_with_info. However, it is device managed, meaning the
+hwmon device does not have to be removed explicitly by the removal function.
+
 hwmon_device_unregister deregisters a registered hardware monitoring device.
 The parameter of this function is the pointer to the registered hardware
 monitoring device structure. This function must be called from the driver
 remove function if the hardware monitoring device was registered with
-hwmon_device_register or with hwmon_device_register_with_groups.
+hwmon_device_register, hwmon_device_register_with_groups, or
+hwmon_device_register_with_info.
 
 devm_hwmon_device_unregister does not normally have to be called. It is only
 needed for error handling, and only needed if the driver probe fails after
-the call to devm_hwmon_device_register_with_groups.
+the call to devm_hwmon_device_register_with_groups and if the automatic
+(device managed) removal would be too late.
+
+Using devm_hwmon_device_register_with_info()
+
+
+hwmon_device_register_with_info() registers a hardware monitoring device.
+The parameters to this function are
+
+struct device *dev Pointer to parent device
+const char *name   Device name
+void *drvdata  Driver private data
+const struct hwmon_chip_info *info
+   Pointer to chip description.
+const struct attribute_group **groups
+   Null-terminated list of additional sysfs attribute
+   groups.
+
+This function returns a pointer to the created hardware monitoring device
+on success and a negative error code for failure.
+
+The hwmon_chip_info structure looks as follows.
+
+struct hwmon_chip_info {
+   const struct hwmon_ops *ops;
+   const struct hwmon_channel_info **info;
+};
+
+It contains the following fields:
+
+* ops: Pointer to device operations.
+* info: NULL-terminated list of device channel descriptors.
+
+The list of hwmon operations is defined as:
+
+struct hwmon_ops {
+   umode_t (*is_visible)(const void *, enum hwmon_sensor_types type,
+ u32 attr, int);
+   int (*read)(struct device *, enum hwmon_sensor_types type,
+   u32 attr, int, long *);
+   int (*write)(struct device *, enum hwmon_sensor_types type,
+u32 attr, int, long);
+};
+
+It defines the following operations.
+
+* is_visible: Pointer to a function to return the file mode for each supported
+  attribute. This function is mandatory.
+
+* read: Pointer to a function for reading a value from the chip. This function
+  is optional, but must be provided if any readable attributes exist.
+
+* write: Pointer to a function for writing a value to the chip. This 

[PATCH v3 4/9] hwmon: (core) Add current attribute support to new API

2016-07-24 Thread Guenter Roeck
Acked-by: Punit Agrawal 
Reviewed-by: Jonathan Cameron 
Signed-off-by: Guenter Roeck 
---
v3: No change
v2: No change

 drivers/hwmon/hwmon.c | 21 +
 include/linux/hwmon.h | 36 
 2 files changed, 57 insertions(+)

diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 7697dfa92558..9229229a99a5 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -260,6 +260,7 @@ static struct attribute *hwmon_genattr(struct device *dev,
 static const char * const hwmon_chip_attr_templates[] = {
[hwmon_chip_temp_reset_history] = "temp_reset_history",
[hwmon_chip_in_reset_history] = "in_reset_history",
+   [hwmon_chip_curr_reset_history] = "curr_reset_history",
[hwmon_chip_update_interval] = "update_interval",
[hwmon_chip_alarms] = "alarms",
 };
@@ -309,16 +310,36 @@ static const char * const hwmon_in_attr_templates[] = {
[hwmon_in_crit_alarm] = "in%d_crit_alarm",
 };
 
+static const char * const hwmon_curr_attr_templates[] = {
+   [hwmon_curr_input] = "curr%d_input",
+   [hwmon_curr_min] = "curr%d_min",
+   [hwmon_curr_max] = "curr%d_max",
+   [hwmon_curr_lcrit] = "curr%d_lcrit",
+   [hwmon_curr_crit] = "curr%d_crit",
+   [hwmon_curr_average] = "curr%d_average",
+   [hwmon_curr_lowest] = "curr%d_lowest",
+   [hwmon_curr_highest] = "curr%d_highest",
+   [hwmon_curr_reset_history] = "curr%d_reset_history",
+   [hwmon_curr_label] = "curr%d_label",
+   [hwmon_curr_alarm] = "curr%d_alarm",
+   [hwmon_curr_min_alarm] = "curr%d_min_alarm",
+   [hwmon_curr_max_alarm] = "curr%d_max_alarm",
+   [hwmon_curr_lcrit_alarm] = "curr%d_lcrit_alarm",
+   [hwmon_curr_crit_alarm] = "curr%d_crit_alarm",
+};
+
 static const char * const *__templates[] = {
[hwmon_chip] = hwmon_chip_attr_templates,
[hwmon_temp] = hwmon_temp_attr_templates,
[hwmon_in] = hwmon_in_attr_templates,
+   [hwmon_curr] = hwmon_curr_attr_templates,
 };
 
 static const int __templates_size[] = {
[hwmon_chip] = ARRAY_SIZE(hwmon_chip_attr_templates),
[hwmon_temp] = ARRAY_SIZE(hwmon_temp_attr_templates),
[hwmon_in] = ARRAY_SIZE(hwmon_in_attr_templates),
+   [hwmon_curr] = ARRAY_SIZE(hwmon_curr_attr_templates),
 };
 
 static int hwmon_num_channel_attrs(const struct hwmon_channel_info *info)
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index a01b8e3fc6f3..8781c2253b1d 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -31,6 +31,7 @@ enum hwmon_sensor_types {
 enum hwmon_chip_attributes {
hwmon_chip_temp_reset_history,
hwmon_chip_in_reset_history,
+   hwmon_chip_curr_reset_history,
hwmon_chip_register_tz,
hwmon_chip_update_interval,
hwmon_chip_alarms,
@@ -38,6 +39,7 @@ enum hwmon_chip_attributes {
 
 #define HWMON_C_TEMP_RESET_HISTORY BIT(hwmon_chip_temp_reset_history)
 #define HWMON_C_IN_RESET_HISTORY   BIT(hwmon_chip_in_reset_history)
+#define HWMON_C_CURR_RESET_HISTORY BIT(hwmon_chip_curr_reset_history)
 #define HWMON_C_REGISTER_TZBIT(hwmon_chip_register_tz)
 #define HWMON_C_UPDATE_INTERVALBIT(hwmon_chip_update_interval)
 #define HWMON_C_ALARMS BIT(hwmon_chip_alarms)
@@ -126,6 +128,40 @@ enum hwmon_in_attributes {
 #define HWMON_I_LCRIT_ALARMBIT(hwmon_in_lcrit_alarm)
 #define HWMON_I_CRIT_ALARM BIT(hwmon_in_crit_alarm)
 
+enum hwmon_curr_attributes {
+   hwmon_curr_input,
+   hwmon_curr_min,
+   hwmon_curr_max,
+   hwmon_curr_lcrit,
+   hwmon_curr_crit,
+   hwmon_curr_average,
+   hwmon_curr_lowest,
+   hwmon_curr_highest,
+   hwmon_curr_reset_history,
+   hwmon_curr_label,
+   hwmon_curr_alarm,
+   hwmon_curr_min_alarm,
+   hwmon_curr_max_alarm,
+   hwmon_curr_lcrit_alarm,
+   hwmon_curr_crit_alarm,
+};
+
+#define HWMON_C_INPUT  BIT(hwmon_curr_input)
+#define HWMON_C_MINBIT(hwmon_curr_min)
+#define HWMON_C_MAXBIT(hwmon_curr_max)
+#define HWMON_C_LCRIT  BIT(hwmon_curr_lcrit)
+#define HWMON_C_CRIT   BIT(hwmon_curr_crit)
+#define HWMON_C_AVERAGEBIT(hwmon_curr_average)
+#define HWMON_C_LOWEST BIT(hwmon_curr_lowest)
+#define HWMON_C_HIGHESTBIT(hwmon_curr_highest)
+#define HWMON_C_RESET_HISTORY  BIT(hwmon_curr_reset_history)
+#define HWMON_C_LABEL  BIT(hwmon_curr_label)
+#define HWMON_C_ALARM  BIT(hwmon_curr_alarm)
+#define HWMON_C_MIN_ALARM  BIT(hwmon_curr_min_alarm)
+#define HWMON_C_MAX_ALARM  BIT(hwmon_curr_max_alarm)
+#define HWMON_C_LCRIT_ALARMBIT(hwmon_curr_lcrit_alarm)
+#define HWMON_C_CRIT_ALARM BIT(hwmon_curr_crit_alarm)
+
 /**
  * struct hwmon_ops - hwmon device operations
  * @is_visible: Callback to return attribute visibility. Mandatory.
-- 
2.5.0



[PATCH v3 8/9] hwmon: (core) Document new kernel API

2016-07-24 Thread Guenter Roeck
Describe the new registration API function as well as the data
structures it requires.

Acked-by: Punit Agrawal 
Reviewed-by: Jonathan Cameron 
Signed-off-by: Guenter Roeck 
---
v3: No change
v2: Fixed typos

 Documentation/hwmon/hwmon-kernel-api.txt | 229 ++-
 1 file changed, 227 insertions(+), 2 deletions(-)

diff --git a/Documentation/hwmon/hwmon-kernel-api.txt 
b/Documentation/hwmon/hwmon-kernel-api.txt
index 2ecdbfc85ecf..f60a29ce7592 100644
--- a/Documentation/hwmon/hwmon-kernel-api.txt
+++ b/Documentation/hwmon/hwmon-kernel-api.txt
@@ -34,6 +34,19 @@ devm_hwmon_device_register_with_groups(struct device *dev,
   const char *name, void *drvdata,
   const struct attribute_group **groups);
 
+struct device *
+hwmon_device_register_with_info(struct device *dev,
+   const char *name, void *drvdata,
+   const struct hwmon_chip_info *info,
+   const struct attribute_group **groups);
+
+struct device *
+devm_hwmon_device_register_with_info(struct device *dev,
+const char *name,
+void *drvdata,
+const struct hwmon_chip_info *info,
+const struct attribute_group **groups);
+
 void hwmon_device_unregister(struct device *dev);
 void devm_hwmon_device_unregister(struct device *dev);
 
@@ -60,15 +73,227 @@ devm_hwmon_device_register_with_groups is similar to
 hwmon_device_register_with_groups. However, it is device managed, meaning the
 hwmon device does not have to be removed explicitly by the removal function.
 
+hwmon_device_register_with_info is the most comprehensive and preferred means
+to register a hardware monitoring device. It creates the standard sysfs
+attributes in the hardware monitoring core, letting the driver focus on reading
+from and writing to the chip instead of having to bother with sysfs attributes.
+Its parameters are described in more detail below.
+
+devm_hwmon_device_register_with_info is similar to
+hwmon_device_register_with_info. However, it is device managed, meaning the
+hwmon device does not have to be removed explicitly by the removal function.
+
 hwmon_device_unregister deregisters a registered hardware monitoring device.
 The parameter of this function is the pointer to the registered hardware
 monitoring device structure. This function must be called from the driver
 remove function if the hardware monitoring device was registered with
-hwmon_device_register or with hwmon_device_register_with_groups.
+hwmon_device_register, hwmon_device_register_with_groups, or
+hwmon_device_register_with_info.
 
 devm_hwmon_device_unregister does not normally have to be called. It is only
 needed for error handling, and only needed if the driver probe fails after
-the call to devm_hwmon_device_register_with_groups.
+the call to devm_hwmon_device_register_with_groups and if the automatic
+(device managed) removal would be too late.
+
+Using devm_hwmon_device_register_with_info()
+
+
+hwmon_device_register_with_info() registers a hardware monitoring device.
+The parameters to this function are
+
+struct device *dev Pointer to parent device
+const char *name   Device name
+void *drvdata  Driver private data
+const struct hwmon_chip_info *info
+   Pointer to chip description.
+const struct attribute_group **groups
+   Null-terminated list of additional sysfs attribute
+   groups.
+
+This function returns a pointer to the created hardware monitoring device
+on success and a negative error code for failure.
+
+The hwmon_chip_info structure looks as follows.
+
+struct hwmon_chip_info {
+   const struct hwmon_ops *ops;
+   const struct hwmon_channel_info **info;
+};
+
+It contains the following fields:
+
+* ops: Pointer to device operations.
+* info: NULL-terminated list of device channel descriptors.
+
+The list of hwmon operations is defined as:
+
+struct hwmon_ops {
+   umode_t (*is_visible)(const void *, enum hwmon_sensor_types type,
+ u32 attr, int);
+   int (*read)(struct device *, enum hwmon_sensor_types type,
+   u32 attr, int, long *);
+   int (*write)(struct device *, enum hwmon_sensor_types type,
+u32 attr, int, long);
+};
+
+It defines the following operations.
+
+* is_visible: Pointer to a function to return the file mode for each supported
+  attribute. This function is mandatory.
+
+* read: Pointer to a function for reading a value from the chip. This function
+  is optional, but must be provided if any readable attributes exist.
+
+* write: Pointer to a function for writing a value to the chip. This function 
is
+  optional, but must be provided if any writeable 

  1   2   3   4   5   >