Re: [PATCH 1/3] extcon: Add documentation for EXTCON_CHG_USB_* and EXTCON_USB_*

2016-12-20 Thread Baolin Wang
Hi,

On 21 December 2016 at 15:58, Chanwoo Choi  wrote:
> Hi,
>
> On 2016년 12월 21일 16:53, Baolin Wang wrote:
>> Hi,
>>
>> On 21 December 2016 at 15:20, Chanwoo Choi  wrote:
>>> Hi,
>>>
>>> On 2016년 12월 21일 15:10, Baolin Wang wrote:
 Current there is both "EXTCON_USB" and "EXTCON_CHG_USB_SDP" which
 both seem to suggest a standard downstream port. But there is no
 documentation describing how these relate.

 Thus add documentation to describe EXTCON_CHG_USB_SDP should always
 appear together with EXTCON_USB, and EXTCON_CHG_USB_ACA would normally
 appear with EXTCON_USB_HOST.

 Signed-off-by: Baolin Wang 
 ---
  include/linux/extcon.h |9 -
  1 file changed, 8 insertions(+), 1 deletion(-)

 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
 index b871c0c..6498b05 100644
 --- a/include/linux/extcon.h
 +++ b/include/linux/extcon.h
 @@ -46,7 +46,14 @@
  #define EXTCON_USB   1
  #define EXTCON_USB_HOST  2

 -/* Charging external connector */
 +/*
 + * Charging external connector
 + *
 + * When one SDP charger connector was reported, we should also report
 + * the USB connector, which means EXTCON_CHG_USB_SDP should always
 + * appear together with EXTCON_USB. The same as ACA charger connector,
 + * EXTCON_CHG_USB_ACA should always appear with EXTCON_USB_HOST.
 + */
>>>
>>> Looks good to me.
>>> But, you use the different word for ACA as following:
>>> I think that 'would normally' is proper in descritpion.
>>
>> Okay, I will change to 'would normally' in next version patch. Thanks.
>
> Don't need to send next patch. I modify it and apply it. Thanks.

Okay, Thanks a lot.

-- 
Baolin.wang
Best Regards


Re: [PATCH 1/3] extcon: Add documentation for EXTCON_CHG_USB_* and EXTCON_USB_*

2016-12-20 Thread Baolin Wang
Hi,

On 21 December 2016 at 15:58, Chanwoo Choi  wrote:
> Hi,
>
> On 2016년 12월 21일 16:53, Baolin Wang wrote:
>> Hi,
>>
>> On 21 December 2016 at 15:20, Chanwoo Choi  wrote:
>>> Hi,
>>>
>>> On 2016년 12월 21일 15:10, Baolin Wang wrote:
 Current there is both "EXTCON_USB" and "EXTCON_CHG_USB_SDP" which
 both seem to suggest a standard downstream port. But there is no
 documentation describing how these relate.

 Thus add documentation to describe EXTCON_CHG_USB_SDP should always
 appear together with EXTCON_USB, and EXTCON_CHG_USB_ACA would normally
 appear with EXTCON_USB_HOST.

 Signed-off-by: Baolin Wang 
 ---
  include/linux/extcon.h |9 -
  1 file changed, 8 insertions(+), 1 deletion(-)

 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
 index b871c0c..6498b05 100644
 --- a/include/linux/extcon.h
 +++ b/include/linux/extcon.h
 @@ -46,7 +46,14 @@
  #define EXTCON_USB   1
  #define EXTCON_USB_HOST  2

 -/* Charging external connector */
 +/*
 + * Charging external connector
 + *
 + * When one SDP charger connector was reported, we should also report
 + * the USB connector, which means EXTCON_CHG_USB_SDP should always
 + * appear together with EXTCON_USB. The same as ACA charger connector,
 + * EXTCON_CHG_USB_ACA should always appear with EXTCON_USB_HOST.
 + */
>>>
>>> Looks good to me.
>>> But, you use the different word for ACA as following:
>>> I think that 'would normally' is proper in descritpion.
>>
>> Okay, I will change to 'would normally' in next version patch. Thanks.
>
> Don't need to send next patch. I modify it and apply it. Thanks.

Okay, Thanks a lot.

-- 
Baolin.wang
Best Regards


Re: [PATCH RFC 1/1] mm, page_alloc: fix incorrect zone_statistics data

2016-12-20 Thread Michal Hocko
On Tue 20-12-16 14:54:35, Mel Gorman wrote:
> On Tue, Dec 20, 2016 at 03:35:02PM +0100, Michal Hocko wrote:
> > On Tue 20-12-16 14:28:45, Mel Gorman wrote:
> > > On Tue, Dec 20, 2016 at 02:26:43PM +0100, Michal Hocko wrote:
> > > > On Tue 20-12-16 13:10:40, Mel Gorman wrote:
> > > > > On Tue, Dec 20, 2016 at 10:18:14AM +0100, Michal Hocko wrote:
> > > > > > On Mon 12-12-16 13:59:07, Jia He wrote:
> > > > > > > In commit b9f00e147f27 ("mm, page_alloc: reduce branches in
> > > > > > > zone_statistics"), it reconstructed codes to reduce the branch 
> > > > > > > miss rate.
> > > > > > > Compared with the original logic, it assumed if !(flag & 
> > > > > > > __GFP_OTHER_NODE)
> > > > > > >  z->node would not be equal to preferred_zone->node. That seems 
> > > > > > > to be
> > > > > > > incorrect.
> > > > > > 
> > > > > > I am sorry but I have hard time following the changelog. It is clear
> > > > > > that you are trying to fix a missed NUMA_{HIT,OTHER} accounting
> > > > > > but it is not really clear when such thing happens. You are adding
> > > > > > preferred_zone->node check. preferred_zone is the first zone in the
> > > > > > requested zonelist. So for the most allocations it is a node from 
> > > > > > the
> > > > > > local node. But if something request an explicit numa node (without
> > > > > > __GFP_OTHER_NODE which would be the majority I suspect) then we 
> > > > > > could
> > > > > > indeed end up accounting that as a NUMA_MISS, NUMA_FOREIGN so the
> > > > > > referenced patch indeed caused an unintended change of accounting 
> > > > > > AFAIU.
> > > > > > 
> > > > > 
> > > > > This is a similar concern to what I had. If the preferred zone, which 
> > > > > is
> > > > > the first valid usable zone, is not a "hit" for the statistics then I
> > > > > don't know what "hit" is meant to mean.
> > > > 
> > > > But the first valid usable zone is defined based on the requested numa
> > > > node. Unless the requested node is memoryless then we should have a hit,
> > > > no?
> > > > 
> > > 
> > > Should be. If the local node is memoryless then there would be a 
> > > difference
> > > between hit and whether it's local or not but that to me is a little
> > > useless. A local vs remote page allocated has a specific meaning and
> > > consequence. It's hard to see how hit can be meaningfully interpreted if
> > > there are memoryless nodes. I don't have a strong objection to the patch
> > > so I didn't nak it, I'm just not convinced it matters.
> > 
> > So what do you think about
> > http://lkml.kernel.org/r/20161220091814.gc3...@dhcp22.suse.cz
> > 
> 
> This doesn't appear to resolve for me and I've 30 minutes left before
> being offline for 4 days so didn't go digging. 

OK, it seems that it didn't go to the lkml so it didn't get to the
archive indexed by the message id. I will send the two patches as a
reply to this email for reference.

-- 
Michal Hocko
SUSE Labs


Re: [PATCH RFC 1/1] mm, page_alloc: fix incorrect zone_statistics data

2016-12-20 Thread Michal Hocko
On Tue 20-12-16 14:54:35, Mel Gorman wrote:
> On Tue, Dec 20, 2016 at 03:35:02PM +0100, Michal Hocko wrote:
> > On Tue 20-12-16 14:28:45, Mel Gorman wrote:
> > > On Tue, Dec 20, 2016 at 02:26:43PM +0100, Michal Hocko wrote:
> > > > On Tue 20-12-16 13:10:40, Mel Gorman wrote:
> > > > > On Tue, Dec 20, 2016 at 10:18:14AM +0100, Michal Hocko wrote:
> > > > > > On Mon 12-12-16 13:59:07, Jia He wrote:
> > > > > > > In commit b9f00e147f27 ("mm, page_alloc: reduce branches in
> > > > > > > zone_statistics"), it reconstructed codes to reduce the branch 
> > > > > > > miss rate.
> > > > > > > Compared with the original logic, it assumed if !(flag & 
> > > > > > > __GFP_OTHER_NODE)
> > > > > > >  z->node would not be equal to preferred_zone->node. That seems 
> > > > > > > to be
> > > > > > > incorrect.
> > > > > > 
> > > > > > I am sorry but I have hard time following the changelog. It is clear
> > > > > > that you are trying to fix a missed NUMA_{HIT,OTHER} accounting
> > > > > > but it is not really clear when such thing happens. You are adding
> > > > > > preferred_zone->node check. preferred_zone is the first zone in the
> > > > > > requested zonelist. So for the most allocations it is a node from 
> > > > > > the
> > > > > > local node. But if something request an explicit numa node (without
> > > > > > __GFP_OTHER_NODE which would be the majority I suspect) then we 
> > > > > > could
> > > > > > indeed end up accounting that as a NUMA_MISS, NUMA_FOREIGN so the
> > > > > > referenced patch indeed caused an unintended change of accounting 
> > > > > > AFAIU.
> > > > > > 
> > > > > 
> > > > > This is a similar concern to what I had. If the preferred zone, which 
> > > > > is
> > > > > the first valid usable zone, is not a "hit" for the statistics then I
> > > > > don't know what "hit" is meant to mean.
> > > > 
> > > > But the first valid usable zone is defined based on the requested numa
> > > > node. Unless the requested node is memoryless then we should have a hit,
> > > > no?
> > > > 
> > > 
> > > Should be. If the local node is memoryless then there would be a 
> > > difference
> > > between hit and whether it's local or not but that to me is a little
> > > useless. A local vs remote page allocated has a specific meaning and
> > > consequence. It's hard to see how hit can be meaningfully interpreted if
> > > there are memoryless nodes. I don't have a strong objection to the patch
> > > so I didn't nak it, I'm just not convinced it matters.
> > 
> > So what do you think about
> > http://lkml.kernel.org/r/20161220091814.gc3...@dhcp22.suse.cz
> > 
> 
> This doesn't appear to resolve for me and I've 30 minutes left before
> being offline for 4 days so didn't go digging. 

OK, it seems that it didn't go to the lkml so it didn't get to the
archive indexed by the message id. I will send the two patches as a
reply to this email for reference.

-- 
Michal Hocko
SUSE Labs


Re: [PATCH 1/3] extcon: Add documentation for EXTCON_CHG_USB_* and EXTCON_USB_*

2016-12-20 Thread Chanwoo Choi
Hi,

On 2016년 12월 21일 16:53, Baolin Wang wrote:
> Hi,
> 
> On 21 December 2016 at 15:20, Chanwoo Choi  wrote:
>> Hi,
>>
>> On 2016년 12월 21일 15:10, Baolin Wang wrote:
>>> Current there is both "EXTCON_USB" and "EXTCON_CHG_USB_SDP" which
>>> both seem to suggest a standard downstream port. But there is no
>>> documentation describing how these relate.
>>>
>>> Thus add documentation to describe EXTCON_CHG_USB_SDP should always
>>> appear together with EXTCON_USB, and EXTCON_CHG_USB_ACA would normally
>>> appear with EXTCON_USB_HOST.
>>>
>>> Signed-off-by: Baolin Wang 
>>> ---
>>>  include/linux/extcon.h |9 -
>>>  1 file changed, 8 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/include/linux/extcon.h b/include/linux/extcon.h
>>> index b871c0c..6498b05 100644
>>> --- a/include/linux/extcon.h
>>> +++ b/include/linux/extcon.h
>>> @@ -46,7 +46,14 @@
>>>  #define EXTCON_USB   1
>>>  #define EXTCON_USB_HOST  2
>>>
>>> -/* Charging external connector */
>>> +/*
>>> + * Charging external connector
>>> + *
>>> + * When one SDP charger connector was reported, we should also report
>>> + * the USB connector, which means EXTCON_CHG_USB_SDP should always
>>> + * appear together with EXTCON_USB. The same as ACA charger connector,
>>> + * EXTCON_CHG_USB_ACA should always appear with EXTCON_USB_HOST.
>>> + */
>>
>> Looks good to me.
>> But, you use the different word for ACA as following:
>> I think that 'would normally' is proper in descritpion.
> 
> Okay, I will change to 'would normally' in next version patch. Thanks.

Don't need to send next patch. I modify it and apply it. Thanks.

-- 
Regards,
Chanwoo Choi


Re: [PATCH 1/3] extcon: Add documentation for EXTCON_CHG_USB_* and EXTCON_USB_*

2016-12-20 Thread Chanwoo Choi
Hi,

On 2016년 12월 21일 16:53, Baolin Wang wrote:
> Hi,
> 
> On 21 December 2016 at 15:20, Chanwoo Choi  wrote:
>> Hi,
>>
>> On 2016년 12월 21일 15:10, Baolin Wang wrote:
>>> Current there is both "EXTCON_USB" and "EXTCON_CHG_USB_SDP" which
>>> both seem to suggest a standard downstream port. But there is no
>>> documentation describing how these relate.
>>>
>>> Thus add documentation to describe EXTCON_CHG_USB_SDP should always
>>> appear together with EXTCON_USB, and EXTCON_CHG_USB_ACA would normally
>>> appear with EXTCON_USB_HOST.
>>>
>>> Signed-off-by: Baolin Wang 
>>> ---
>>>  include/linux/extcon.h |9 -
>>>  1 file changed, 8 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/include/linux/extcon.h b/include/linux/extcon.h
>>> index b871c0c..6498b05 100644
>>> --- a/include/linux/extcon.h
>>> +++ b/include/linux/extcon.h
>>> @@ -46,7 +46,14 @@
>>>  #define EXTCON_USB   1
>>>  #define EXTCON_USB_HOST  2
>>>
>>> -/* Charging external connector */
>>> +/*
>>> + * Charging external connector
>>> + *
>>> + * When one SDP charger connector was reported, we should also report
>>> + * the USB connector, which means EXTCON_CHG_USB_SDP should always
>>> + * appear together with EXTCON_USB. The same as ACA charger connector,
>>> + * EXTCON_CHG_USB_ACA should always appear with EXTCON_USB_HOST.
>>> + */
>>
>> Looks good to me.
>> But, you use the different word for ACA as following:
>> I think that 'would normally' is proper in descritpion.
> 
> Okay, I will change to 'would normally' in next version patch. Thanks.

Don't need to send next patch. I modify it and apply it. Thanks.

-- 
Regards,
Chanwoo Choi


Re: [PATCH 3/3] phy: rockchip-inno-usb2: Set EXTCON_USB when EXTCON_CHG_USB_SDP was set

2016-12-20 Thread Baolin Wang
Hi,

On 21 December 2016 at 15:29, Chanwoo Choi  wrote:
> Hi,
>
> On 2016년 12월 21일 15:10, Baolin Wang wrote:
>> According to the documentation, we should set the EXTCON_USB when
>> one SDP charger connector was reported.
>>
>> Signed-off-by: Baolin Wang 
>> ---
>>  drivers/phy/phy-rockchip-inno-usb2.c |7 ++-
>>  1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/phy/phy-rockchip-inno-usb2.c 
>> b/drivers/phy/phy-rockchip-inno-usb2.c
>> index 2f99ec9..71fbe0f 100644
>> --- a/drivers/phy/phy-rockchip-inno-usb2.c
>> +++ b/drivers/phy/phy-rockchip-inno-usb2.c
>> @@ -595,9 +595,14 @@ static void rockchip_usb2phy_otg_sm_work(struct 
>> work_struct *work)
>>   if (rport->vbus_attached != vbus_attach) {
>>   rport->vbus_attached = vbus_attach;
>>
>> - if (notify_charger && rphy->edev)
>> + if (notify_charger && rphy->edev) {
>>   extcon_set_cable_state_(rphy->edev,
>>   cable, vbus_attach);
>> + if (cable == EXTCON_CHG_USB_SDP)
>> + extcon_set_cable_state_(rphy->edev,
>> + EXTCON_USB,
>> + vbus_attach);
>> + }
>>   }
>>   break;
>>   case OTG_STATE_B_PERIPHERAL:
>>
>
> Looks good to me. But I prefer to use the 'extcon_set_state_sync' intead of 
> extcon_set_cable_state_().
> Reviewed-by: Chanwoo Choi 
>
> I sent the patches[1] for extcon API to alter the deprecated API.
> If you possible, I'd like you to alter the extcon API instead of deprecated 
> API.

Okay, I will change to extcon_set_state_sync() in next version patch. Thanks.

> [1] https://patchwork.kernel.org/patch/9453645/
> - extcon_set_cable_state_() -> extcon_set_state_sync()
> - extcon_get_cable_state_() -> extcon_get_state()
> - Use devm_extcon_register_notifier() instead of extcon_register_notifier().
>
> --
> Regards,
> Chanwoo Choi



-- 
Baolin.wang
Best Regards


Re: [PATCH 3/3] phy: rockchip-inno-usb2: Set EXTCON_USB when EXTCON_CHG_USB_SDP was set

2016-12-20 Thread Baolin Wang
Hi,

On 21 December 2016 at 15:29, Chanwoo Choi  wrote:
> Hi,
>
> On 2016년 12월 21일 15:10, Baolin Wang wrote:
>> According to the documentation, we should set the EXTCON_USB when
>> one SDP charger connector was reported.
>>
>> Signed-off-by: Baolin Wang 
>> ---
>>  drivers/phy/phy-rockchip-inno-usb2.c |7 ++-
>>  1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/phy/phy-rockchip-inno-usb2.c 
>> b/drivers/phy/phy-rockchip-inno-usb2.c
>> index 2f99ec9..71fbe0f 100644
>> --- a/drivers/phy/phy-rockchip-inno-usb2.c
>> +++ b/drivers/phy/phy-rockchip-inno-usb2.c
>> @@ -595,9 +595,14 @@ static void rockchip_usb2phy_otg_sm_work(struct 
>> work_struct *work)
>>   if (rport->vbus_attached != vbus_attach) {
>>   rport->vbus_attached = vbus_attach;
>>
>> - if (notify_charger && rphy->edev)
>> + if (notify_charger && rphy->edev) {
>>   extcon_set_cable_state_(rphy->edev,
>>   cable, vbus_attach);
>> + if (cable == EXTCON_CHG_USB_SDP)
>> + extcon_set_cable_state_(rphy->edev,
>> + EXTCON_USB,
>> + vbus_attach);
>> + }
>>   }
>>   break;
>>   case OTG_STATE_B_PERIPHERAL:
>>
>
> Looks good to me. But I prefer to use the 'extcon_set_state_sync' intead of 
> extcon_set_cable_state_().
> Reviewed-by: Chanwoo Choi 
>
> I sent the patches[1] for extcon API to alter the deprecated API.
> If you possible, I'd like you to alter the extcon API instead of deprecated 
> API.

Okay, I will change to extcon_set_state_sync() in next version patch. Thanks.

> [1] https://patchwork.kernel.org/patch/9453645/
> - extcon_set_cable_state_() -> extcon_set_state_sync()
> - extcon_get_cable_state_() -> extcon_get_state()
> - Use devm_extcon_register_notifier() instead of extcon_register_notifier().
>
> --
> Regards,
> Chanwoo Choi



-- 
Baolin.wang
Best Regards


Re: [PATCH 2/3] extcon: axp288: Set EXTCON_USB when EXTCON_CHG_USB_SDP was set

2016-12-20 Thread Baolin Wang
Hi,

On 21 December 2016 at 15:22, Chanwoo Choi  wrote:
> Hi,
>
> On 2016년 12월 21일 15:10, Baolin Wang wrote:
>> According to the documentation, we should set the EXTCON_USB when
>> one SDP charger connector was reported.
>>
>> Signed-off-by: Baolin Wang 
>> ---
>>  drivers/extcon/extcon-axp288.c |7 ++-
>>  1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
>> index 42f41e8..4490726 100644
>> --- a/drivers/extcon/extcon-axp288.c
>> +++ b/drivers/extcon/extcon-axp288.c
>> @@ -102,6 +102,7 @@ enum axp288_extcon_irq {
>>  };
>>
>>  static const unsigned int axp288_extcon_cables[] = {
>> + EXTCON_USB,
>>   EXTCON_CHG_USB_SDP,
>>   EXTCON_CHG_USB_CDP,
>>   EXTCON_CHG_USB_DCP,
>> @@ -225,8 +226,12 @@ static int axp288_handle_chrg_det_event(struct 
>> axp288_extcon_info *info)
>>   vbus_attach ? USB_EVENT_VBUS : USB_EVENT_NONE, NULL);
>>   }
>>
>> - if (notify_charger)
>> + if (notify_charger) {
>>   extcon_set_state_sync(info->edev, cable, vbus_attach);
>> + if (cable == EXTCON_CHG_USB_SDP)
>> + extcon_set_state_sync(info->edev, EXTCON_USB,
>> +   vbus_attach);
>> + }
>>
>>   /* Clear the flags on disconnect event */
>>   if (!vbus_attach)
>>
>
> The extcon-axp288.c driver has some patches on extcon-next[1] branch.
> [1] 
> https://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/log/?h=extcon-next
>
> I rework your patch on extcon-next branch as following:
> If you ok, I'll merge it for v4.11.

It is okay for me. Thanks.

>
> commit 1a96f92bdfab86d0b634e56092f543cad348fd0b
> Refs: extcon-next, extcon-next-for-4.10-15-g1a96f92bdfab
> Author: Baolin Wang 
> AuthorDate: Wed Dec 21 15:51:26 2016 +0900
> Commit: Chanwoo Choi 
> CommitDate: Wed Dec 21 15:52:00 2016 +0900
>
> extcon: axp288: Set EXTCON_USB when EXTCON_CHG_USB_SDP was set
>
> According to the documentation, we should set the EXTCON_USB when
> one SDP charger connector was reported.
>
> Signed-off-by: Baolin Wang 
> Signed-off-by: Chanwoo Choi 
> ---
>  drivers/extcon/extcon-axp288.c | 8 
>  1 file changed, 8 insertions(+)
>
> diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
> index 3e145e2a4860..f4fd03e58e37 100644
> --- a/drivers/extcon/extcon-axp288.c
> +++ b/drivers/extcon/extcon-axp288.c
> @@ -96,6 +96,7 @@ enum axp288_extcon_irq {
> EXTCON_CHG_USB_SDP,
> EXTCON_CHG_USB_CDP,
> EXTCON_CHG_USB_DCP,
> +   EXTCON_USB,
> EXTCON_NONE,
>  };
>
> @@ -206,8 +207,15 @@ static int axp288_handle_chrg_det_event(struct 
> axp288_extcon_info *info)
> : EXTCON_GPIO_MUX_SEL_PMIC);
>
> extcon_set_state_sync(info->edev, info->previous_cable, false);
> +   if (info->previous_cable == EXTCON_CHG_USB_SDP)
> +   extcon_set_state_sync(info->edev, EXTCON_USB, false);
> +
> if (vbus_attach) {
> extcon_set_state_sync(info->edev, cable, vbus_attach);
> +   if (cable == EXTCON_CHG_USB_SDP)
> +   extcon_set_state_sync(info->edev, EXTCON_USB,
> +   vbus_attach);
> +
> info->previous_cable = cable;
> }
>
> --
> Regards,
> Chanwoo Choi



-- 
Baolin.wang
Best Regards


Re: [PATCH 2/3] extcon: axp288: Set EXTCON_USB when EXTCON_CHG_USB_SDP was set

2016-12-20 Thread Baolin Wang
Hi,

On 21 December 2016 at 15:22, Chanwoo Choi  wrote:
> Hi,
>
> On 2016년 12월 21일 15:10, Baolin Wang wrote:
>> According to the documentation, we should set the EXTCON_USB when
>> one SDP charger connector was reported.
>>
>> Signed-off-by: Baolin Wang 
>> ---
>>  drivers/extcon/extcon-axp288.c |7 ++-
>>  1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
>> index 42f41e8..4490726 100644
>> --- a/drivers/extcon/extcon-axp288.c
>> +++ b/drivers/extcon/extcon-axp288.c
>> @@ -102,6 +102,7 @@ enum axp288_extcon_irq {
>>  };
>>
>>  static const unsigned int axp288_extcon_cables[] = {
>> + EXTCON_USB,
>>   EXTCON_CHG_USB_SDP,
>>   EXTCON_CHG_USB_CDP,
>>   EXTCON_CHG_USB_DCP,
>> @@ -225,8 +226,12 @@ static int axp288_handle_chrg_det_event(struct 
>> axp288_extcon_info *info)
>>   vbus_attach ? USB_EVENT_VBUS : USB_EVENT_NONE, NULL);
>>   }
>>
>> - if (notify_charger)
>> + if (notify_charger) {
>>   extcon_set_state_sync(info->edev, cable, vbus_attach);
>> + if (cable == EXTCON_CHG_USB_SDP)
>> + extcon_set_state_sync(info->edev, EXTCON_USB,
>> +   vbus_attach);
>> + }
>>
>>   /* Clear the flags on disconnect event */
>>   if (!vbus_attach)
>>
>
> The extcon-axp288.c driver has some patches on extcon-next[1] branch.
> [1] 
> https://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/log/?h=extcon-next
>
> I rework your patch on extcon-next branch as following:
> If you ok, I'll merge it for v4.11.

It is okay for me. Thanks.

>
> commit 1a96f92bdfab86d0b634e56092f543cad348fd0b
> Refs: extcon-next, extcon-next-for-4.10-15-g1a96f92bdfab
> Author: Baolin Wang 
> AuthorDate: Wed Dec 21 15:51:26 2016 +0900
> Commit: Chanwoo Choi 
> CommitDate: Wed Dec 21 15:52:00 2016 +0900
>
> extcon: axp288: Set EXTCON_USB when EXTCON_CHG_USB_SDP was set
>
> According to the documentation, we should set the EXTCON_USB when
> one SDP charger connector was reported.
>
> Signed-off-by: Baolin Wang 
> Signed-off-by: Chanwoo Choi 
> ---
>  drivers/extcon/extcon-axp288.c | 8 
>  1 file changed, 8 insertions(+)
>
> diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
> index 3e145e2a4860..f4fd03e58e37 100644
> --- a/drivers/extcon/extcon-axp288.c
> +++ b/drivers/extcon/extcon-axp288.c
> @@ -96,6 +96,7 @@ enum axp288_extcon_irq {
> EXTCON_CHG_USB_SDP,
> EXTCON_CHG_USB_CDP,
> EXTCON_CHG_USB_DCP,
> +   EXTCON_USB,
> EXTCON_NONE,
>  };
>
> @@ -206,8 +207,15 @@ static int axp288_handle_chrg_det_event(struct 
> axp288_extcon_info *info)
> : EXTCON_GPIO_MUX_SEL_PMIC);
>
> extcon_set_state_sync(info->edev, info->previous_cable, false);
> +   if (info->previous_cable == EXTCON_CHG_USB_SDP)
> +   extcon_set_state_sync(info->edev, EXTCON_USB, false);
> +
> if (vbus_attach) {
> extcon_set_state_sync(info->edev, cable, vbus_attach);
> +   if (cable == EXTCON_CHG_USB_SDP)
> +   extcon_set_state_sync(info->edev, EXTCON_USB,
> +   vbus_attach);
> +
> info->previous_cable = cable;
> }
>
> --
> Regards,
> Chanwoo Choi



-- 
Baolin.wang
Best Regards


Re: [PATCH 1/3] extcon: Add documentation for EXTCON_CHG_USB_* and EXTCON_USB_*

2016-12-20 Thread Baolin Wang
Hi,

On 21 December 2016 at 15:20, Chanwoo Choi  wrote:
> Hi,
>
> On 2016년 12월 21일 15:10, Baolin Wang wrote:
>> Current there is both "EXTCON_USB" and "EXTCON_CHG_USB_SDP" which
>> both seem to suggest a standard downstream port. But there is no
>> documentation describing how these relate.
>>
>> Thus add documentation to describe EXTCON_CHG_USB_SDP should always
>> appear together with EXTCON_USB, and EXTCON_CHG_USB_ACA would normally
>> appear with EXTCON_USB_HOST.
>>
>> Signed-off-by: Baolin Wang 
>> ---
>>  include/linux/extcon.h |9 -
>>  1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/linux/extcon.h b/include/linux/extcon.h
>> index b871c0c..6498b05 100644
>> --- a/include/linux/extcon.h
>> +++ b/include/linux/extcon.h
>> @@ -46,7 +46,14 @@
>>  #define EXTCON_USB   1
>>  #define EXTCON_USB_HOST  2
>>
>> -/* Charging external connector */
>> +/*
>> + * Charging external connector
>> + *
>> + * When one SDP charger connector was reported, we should also report
>> + * the USB connector, which means EXTCON_CHG_USB_SDP should always
>> + * appear together with EXTCON_USB. The same as ACA charger connector,
>> + * EXTCON_CHG_USB_ACA should always appear with EXTCON_USB_HOST.
>> + */
>
> Looks good to me.
> But, you use the different word for ACA as following:
> I think that 'would normally' is proper in descritpion.

Okay, I will change to 'would normally' in next version patch. Thanks.

>
> - commit msg : EXTCON_CHG_USB_ACA would normally appear with EXTCON_USB_HOST.
> - description: EXTCON_CHG_USB_ACA should always appear with EXTCON_USB_HOST.
>
>>  #define EXTCON_CHG_USB_SDP   5   /* Standard Downstream Port */
>>  #define EXTCON_CHG_USB_DCP   6   /* Dedicated Charging Port */
>>  #define EXTCON_CHG_USB_CDP   7   /* Charging Downstream Port */
>>
>
> --
> Regards,
> Chanwoo Choi



-- 
Baolin.wang
Best Regards


Re: [PATCH 1/3] extcon: Add documentation for EXTCON_CHG_USB_* and EXTCON_USB_*

2016-12-20 Thread Baolin Wang
Hi,

On 21 December 2016 at 15:20, Chanwoo Choi  wrote:
> Hi,
>
> On 2016년 12월 21일 15:10, Baolin Wang wrote:
>> Current there is both "EXTCON_USB" and "EXTCON_CHG_USB_SDP" which
>> both seem to suggest a standard downstream port. But there is no
>> documentation describing how these relate.
>>
>> Thus add documentation to describe EXTCON_CHG_USB_SDP should always
>> appear together with EXTCON_USB, and EXTCON_CHG_USB_ACA would normally
>> appear with EXTCON_USB_HOST.
>>
>> Signed-off-by: Baolin Wang 
>> ---
>>  include/linux/extcon.h |9 -
>>  1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/linux/extcon.h b/include/linux/extcon.h
>> index b871c0c..6498b05 100644
>> --- a/include/linux/extcon.h
>> +++ b/include/linux/extcon.h
>> @@ -46,7 +46,14 @@
>>  #define EXTCON_USB   1
>>  #define EXTCON_USB_HOST  2
>>
>> -/* Charging external connector */
>> +/*
>> + * Charging external connector
>> + *
>> + * When one SDP charger connector was reported, we should also report
>> + * the USB connector, which means EXTCON_CHG_USB_SDP should always
>> + * appear together with EXTCON_USB. The same as ACA charger connector,
>> + * EXTCON_CHG_USB_ACA should always appear with EXTCON_USB_HOST.
>> + */
>
> Looks good to me.
> But, you use the different word for ACA as following:
> I think that 'would normally' is proper in descritpion.

Okay, I will change to 'would normally' in next version patch. Thanks.

>
> - commit msg : EXTCON_CHG_USB_ACA would normally appear with EXTCON_USB_HOST.
> - description: EXTCON_CHG_USB_ACA should always appear with EXTCON_USB_HOST.
>
>>  #define EXTCON_CHG_USB_SDP   5   /* Standard Downstream Port */
>>  #define EXTCON_CHG_USB_DCP   6   /* Dedicated Charging Port */
>>  #define EXTCON_CHG_USB_CDP   7   /* Charging Downstream Port */
>>
>
> --
> Regards,
> Chanwoo Choi



-- 
Baolin.wang
Best Regards


[PATCH] pci: add kernel config option for disabling common PCI quirks

2016-12-20 Thread John Crispin
From: Gabor Juhos 

These quirks do not effect small small plastic routers. These routers tend
to have very little flash space. This patch adds a new option that allows
us to build a kernel without including the common quirks, thus saving us
valuable flash space.

When building an image for a MIPS/Ralink router with this option enabled
it will reduce the size of an uncompressed uImage by 12KB.

Signed-off-by: John Crispin 
Signed-off-by: Gabor Juhos 
---
Hi Bjorn,

This patch has been lingering inside the OpenWrt for some years. I am not
sure if this is the best way to remove the quirks from the build. Let me
know if you prefer a different way of solving this.

John

 drivers/pci/Kconfig  |   10 ++
 drivers/pci/quirks.c |6 ++
 2 files changed, 16 insertions(+)

diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 6555eb7..967bcd5 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -71,6 +71,16 @@ config XEN_PCIDEV_FRONTEND
   The PCI device frontend driver allows the kernel to import arbitrary
   PCI devices from a PCI backend to support PCI driver domains.
 
+config PCI_DISABLE_COMMON_QUIRKS
+   bool "PCI disable common quirks"
+   depends on PCI
+default n
+   help
+ Say Y here if you do not wish to include the common quirks inside
+ your kernel This is usefull for devices with scarce memory.
+
+ If you don't know what to do here, say N.
+
 config HT_IRQ
bool "Interrupts on hypertransport devices"
default y
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index c232729..afe181e 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -41,6 +41,7 @@ static void quirk_mmio_always_on(struct pci_dev *dev)
 DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_ANY_ID, PCI_ANY_ID,
PCI_CLASS_BRIDGE_HOST, 8, quirk_mmio_always_on);
 
+#ifndef CONFIG_PCI_DISABLE_COMMON_QUIRKS
 /* The Mellanox Tavor device gives false positive parity errors
  * Mark this device with a broken_parity_status, to allow
  * PCI scanning code to "skip" this now blacklisted device.
@@ -3015,6 +3016,7 @@ static void quirk_intel_mc_errata(struct pci_dev *dev)
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65f9, quirk_intel_mc_errata);
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65fa, quirk_intel_mc_errata);
 
+#endif /* !CONFIG_PCI_DISABLE_COMMON_QUIRKS */
 
 /*
  * Ivytown NTB BAR sizes are misreported by the hardware due to an erratum.  To
@@ -3071,6 +3073,8 @@ static void fixup_debug_report(struct pci_dev *dev, 
ktime_t calltime,
}
 }
 
+#ifndef CONFIG_PCI_DISABLE_COMMON_QUIRKS
+
 /*
  * Some BIOS implementations leave the Intel GPU interrupts enabled,
  * even though no one is handling them (f.e. i915 driver is never loaded).
@@ -3105,6 +3109,8 @@ static void disable_igfx_irq(struct pci_dev *dev)
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x010a, disable_igfx_irq);
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0152, disable_igfx_irq);
 
+#endif /* !CONFIG_PCI_DISABLE_COMMON_QUIRKS */
+
 /*
  * PCI devices which are on Intel chips can skip the 10ms delay
  * before entering D3 mode.
-- 
1.7.10.4



[PATCH] pci: add kernel config option for disabling common PCI quirks

2016-12-20 Thread John Crispin
From: Gabor Juhos 

These quirks do not effect small small plastic routers. These routers tend
to have very little flash space. This patch adds a new option that allows
us to build a kernel without including the common quirks, thus saving us
valuable flash space.

When building an image for a MIPS/Ralink router with this option enabled
it will reduce the size of an uncompressed uImage by 12KB.

Signed-off-by: John Crispin 
Signed-off-by: Gabor Juhos 
---
Hi Bjorn,

This patch has been lingering inside the OpenWrt for some years. I am not
sure if this is the best way to remove the quirks from the build. Let me
know if you prefer a different way of solving this.

John

 drivers/pci/Kconfig  |   10 ++
 drivers/pci/quirks.c |6 ++
 2 files changed, 16 insertions(+)

diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 6555eb7..967bcd5 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -71,6 +71,16 @@ config XEN_PCIDEV_FRONTEND
   The PCI device frontend driver allows the kernel to import arbitrary
   PCI devices from a PCI backend to support PCI driver domains.
 
+config PCI_DISABLE_COMMON_QUIRKS
+   bool "PCI disable common quirks"
+   depends on PCI
+default n
+   help
+ Say Y here if you do not wish to include the common quirks inside
+ your kernel This is usefull for devices with scarce memory.
+
+ If you don't know what to do here, say N.
+
 config HT_IRQ
bool "Interrupts on hypertransport devices"
default y
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index c232729..afe181e 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -41,6 +41,7 @@ static void quirk_mmio_always_on(struct pci_dev *dev)
 DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_ANY_ID, PCI_ANY_ID,
PCI_CLASS_BRIDGE_HOST, 8, quirk_mmio_always_on);
 
+#ifndef CONFIG_PCI_DISABLE_COMMON_QUIRKS
 /* The Mellanox Tavor device gives false positive parity errors
  * Mark this device with a broken_parity_status, to allow
  * PCI scanning code to "skip" this now blacklisted device.
@@ -3015,6 +3016,7 @@ static void quirk_intel_mc_errata(struct pci_dev *dev)
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65f9, quirk_intel_mc_errata);
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65fa, quirk_intel_mc_errata);
 
+#endif /* !CONFIG_PCI_DISABLE_COMMON_QUIRKS */
 
 /*
  * Ivytown NTB BAR sizes are misreported by the hardware due to an erratum.  To
@@ -3071,6 +3073,8 @@ static void fixup_debug_report(struct pci_dev *dev, 
ktime_t calltime,
}
 }
 
+#ifndef CONFIG_PCI_DISABLE_COMMON_QUIRKS
+
 /*
  * Some BIOS implementations leave the Intel GPU interrupts enabled,
  * even though no one is handling them (f.e. i915 driver is never loaded).
@@ -3105,6 +3109,8 @@ static void disable_igfx_irq(struct pci_dev *dev)
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x010a, disable_igfx_irq);
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0152, disable_igfx_irq);
 
+#endif /* !CONFIG_PCI_DISABLE_COMMON_QUIRKS */
+
 /*
  * PCI devices which are on Intel chips can skip the 10ms delay
  * before entering D3 mode.
-- 
1.7.10.4



Re: [PATCH V2 2/2] mm/memblock.c: check return value of memblock_reserve() in memblock_virt_alloc_internal()

2016-12-20 Thread Michal Hocko
On Tue 20-12-16 16:48:23, Wei Yang wrote:
> On Mon, Dec 19, 2016 at 04:21:57PM +0100, Michal Hocko wrote:
> >On Sun 18-12-16 14:47:50, Wei Yang wrote:
> >> memblock_reserve() may fail in case there is not enough regions.
> >
> >Have you seen this happenning in the real setups or this is a by-review
> >driven change?
> 
> This is a by-review driven change.
> 
> >[...]
> >>  again:
> >>alloc = memblock_find_in_range_node(size, align, min_addr, max_addr,
> >>nid, flags);
> >> -  if (alloc)
> >> +  if (alloc && !memblock_reserve(alloc, size))
> >>goto done;

So how exactly does the reserve fail when memblock_find_in_range_node
found a suitable range for the given size?

> >>  
> >>if (nid != NUMA_NO_NODE) {
> >>alloc = memblock_find_in_range_node(size, align, min_addr,
> >>max_addr, NUMA_NO_NODE,
> >>flags);
> >> -  if (alloc)
> >> +  if (alloc && !memblock_reserve(alloc, size))
> >>goto done;
> >>}
> >
> >This doesn't look right. You can end up leaking the first allocated
> >range.
> >
> 
> Hmm... why?
> 
> If first memblock_reserve() succeed, it will jump to done, so that no 2nd
> allocation.
> If the second executes, it means the first allocation failed.
> memblock_find_in_range_node() doesn't modify the memblock, it just tell you
> there is a proper memory region available.

yes, my bad. I have missed this. Sorry about the confusion.

-- 
Michal Hocko
SUSE Labs


Re: [PATCH V2 2/2] mm/memblock.c: check return value of memblock_reserve() in memblock_virt_alloc_internal()

2016-12-20 Thread Michal Hocko
On Tue 20-12-16 16:48:23, Wei Yang wrote:
> On Mon, Dec 19, 2016 at 04:21:57PM +0100, Michal Hocko wrote:
> >On Sun 18-12-16 14:47:50, Wei Yang wrote:
> >> memblock_reserve() may fail in case there is not enough regions.
> >
> >Have you seen this happenning in the real setups or this is a by-review
> >driven change?
> 
> This is a by-review driven change.
> 
> >[...]
> >>  again:
> >>alloc = memblock_find_in_range_node(size, align, min_addr, max_addr,
> >>nid, flags);
> >> -  if (alloc)
> >> +  if (alloc && !memblock_reserve(alloc, size))
> >>goto done;

So how exactly does the reserve fail when memblock_find_in_range_node
found a suitable range for the given size?

> >>  
> >>if (nid != NUMA_NO_NODE) {
> >>alloc = memblock_find_in_range_node(size, align, min_addr,
> >>max_addr, NUMA_NO_NODE,
> >>flags);
> >> -  if (alloc)
> >> +  if (alloc && !memblock_reserve(alloc, size))
> >>goto done;
> >>}
> >
> >This doesn't look right. You can end up leaking the first allocated
> >range.
> >
> 
> Hmm... why?
> 
> If first memblock_reserve() succeed, it will jump to done, so that no 2nd
> allocation.
> If the second executes, it means the first allocation failed.
> memblock_find_in_range_node() doesn't modify the memblock, it just tell you
> there is a proper memory region available.

yes, my bad. I have missed this. Sorry about the confusion.

-- 
Michal Hocko
SUSE Labs


Re: [PATCH] scsi: do not requeue requests unaligned with device sector size

2016-12-20 Thread Christoph Hellwig
On Tue, Dec 20, 2016 at 12:02:27AM -0200, Mauricio Faria de Oliveira wrote:
> When a SCSI command (e.g., read operation) is partially completed
> with good status and residual bytes (i.e., not all the bytes from
> the specified transfer length were transferred) the SCSI midlayer
> will update the request/bios with the completed bytes and requeue
> the request in order to complete the remainder/pending bytes.
> 
> However, when the device sector size is greater than the 512-byte
> default/kernel sector size, alignment restrictions and validation
> apply (both to the starting logical block address, and the number
> of logical blocks to transfer) -- values must be multiples of the
> device sector size, otherwise the kernel fails the request in the
> preparation stage (e.g., sd_setup_read_write_cmnd() at sd.c file):

How do you even get an unaligned residual count?  Except for SES
processor devices (which will only issue BLOCK_PC commands) this is
not allowed by SPC:

"The residual count shall be reported in bytes if the peripheral device
 type in the destination target descriptor is 03h (i.e., processor device),
 and in destination device blocks for all other device type codes."


Re: [PATCH] scsi: do not requeue requests unaligned with device sector size

2016-12-20 Thread Christoph Hellwig
On Tue, Dec 20, 2016 at 12:02:27AM -0200, Mauricio Faria de Oliveira wrote:
> When a SCSI command (e.g., read operation) is partially completed
> with good status and residual bytes (i.e., not all the bytes from
> the specified transfer length were transferred) the SCSI midlayer
> will update the request/bios with the completed bytes and requeue
> the request in order to complete the remainder/pending bytes.
> 
> However, when the device sector size is greater than the 512-byte
> default/kernel sector size, alignment restrictions and validation
> apply (both to the starting logical block address, and the number
> of logical blocks to transfer) -- values must be multiples of the
> device sector size, otherwise the kernel fails the request in the
> preparation stage (e.g., sd_setup_read_write_cmnd() at sd.c file):

How do you even get an unaligned residual count?  Except for SES
processor devices (which will only issue BLOCK_PC commands) this is
not allowed by SPC:

"The residual count shall be reported in bytes if the peripheral device
 type in the destination target descriptor is 03h (i.e., processor device),
 and in destination device blocks for all other device type codes."


Re: [PATCH V2 1/2] mm/memblock.c: trivial code refine in memblock_is_region_memory()

2016-12-20 Thread Michal Hocko
On Tue 20-12-16 16:35:40, Wei Yang wrote:
> On Mon, Dec 19, 2016 at 04:15:14PM +0100, Michal Hocko wrote:
> >On Sun 18-12-16 14:47:49, Wei Yang wrote:
> >> The base address is already guaranteed to be in the region by
> >> memblock_search().
> >
> 
> Hi, Michal
> 
> Nice to receive your comment.
> 
> >First of all the way how the check is removed is the worst possible...
> >Apart from that it is really not clear to me why checking the base
> >is not needed. You are mentioning memblock_search but what about other
> >callers? adjust_range_page_size_mask e.g...
> >
> 
> Hmm... the memblock_search() is called by memblock_is_region_memory(). Maybe I
> paste the whole function here would clarify the change.
> 
> int __init_memblock memblock_is_region_memory(phys_addr_t base, phys_addr_t 
> size)
> {
>   int idx = memblock_search(, base);
>   phys_addr_t end = base + memblock_cap_size(base, );
> 
>   if (idx == -1)
>   return 0;
>   return memblock.memory.regions[idx].base <= base &&
>   (memblock.memory.regions[idx].base +
>memblock.memory.regions[idx].size) >= end;
> }

Ohh, my bad. I thought that memblock_search is calling
memblock_is_region_memory. I didn't notice this is other way around.
Then I agree that the check for the base is not needed and can be
removed.
-- 
Michal Hocko
SUSE Labs


Re: [PATCH V2 1/2] mm/memblock.c: trivial code refine in memblock_is_region_memory()

2016-12-20 Thread Michal Hocko
On Tue 20-12-16 16:35:40, Wei Yang wrote:
> On Mon, Dec 19, 2016 at 04:15:14PM +0100, Michal Hocko wrote:
> >On Sun 18-12-16 14:47:49, Wei Yang wrote:
> >> The base address is already guaranteed to be in the region by
> >> memblock_search().
> >
> 
> Hi, Michal
> 
> Nice to receive your comment.
> 
> >First of all the way how the check is removed is the worst possible...
> >Apart from that it is really not clear to me why checking the base
> >is not needed. You are mentioning memblock_search but what about other
> >callers? adjust_range_page_size_mask e.g...
> >
> 
> Hmm... the memblock_search() is called by memblock_is_region_memory(). Maybe I
> paste the whole function here would clarify the change.
> 
> int __init_memblock memblock_is_region_memory(phys_addr_t base, phys_addr_t 
> size)
> {
>   int idx = memblock_search(, base);
>   phys_addr_t end = base + memblock_cap_size(base, );
> 
>   if (idx == -1)
>   return 0;
>   return memblock.memory.regions[idx].base <= base &&
>   (memblock.memory.regions[idx].base +
>memblock.memory.regions[idx].size) >= end;
> }

Ohh, my bad. I thought that memblock_search is calling
memblock_is_region_memory. I didn't notice this is other way around.
Then I agree that the check for the base is not needed and can be
removed.
-- 
Michal Hocko
SUSE Labs


RE: [PATCH] acpi: Fix format string type mistakes

2016-12-20 Thread Zheng, Lv
Hi, Kees and Emese

I just helped to back port the commit here:
https://github.com/acpica/acpica/pull/196/commits/5e64857f
If you can see something wrong in it, please let me know.

Thanks and best regards
Lv

> From: Devel [mailto:devel-boun...@acpica.org] On Behalf Of Zheng, Lv
> Subject: Re: [Devel] [PATCH] acpi: Fix format string type mistakes
> 
> Hi,
> 
> > From: Kees Cook [mailto:keesc...@chromium.org]
> > Subject: [PATCH] acpi: Fix format string type mistakes
> >
> > From: Emese Revfy 
> >
> > This adds the missing __printf attribute which allows compile time
> > format string checking (and will be used by the coming initify gcc
> > plugin). Additionally, this fixes the warnings exposed by the attribute.
> >
> > Signed-off-by: Emese Revfy 
> > [kees: split scsi/acpi, merged attr and fix, new commit messages]
> > Signed-off-by: Kees Cook 
> > ---
> >  drivers/acpi/acpica/dbhistry.c |  2 +-
> >  drivers/acpi/acpica/dbinput.c  | 10 ++---
> >  drivers/acpi/acpica/dbstats.c  | 88 
> > +-
> >  drivers/acpi/acpica/utdebug.c  |  2 +-
> >  include/acpi/acpiosxf.h|  3 +-
> >  5 files changed, 53 insertions(+), 52 deletions(-)
> >
> > diff --git a/drivers/acpi/acpica/dbhistry.c b/drivers/acpi/acpica/dbhistry.c
> > index 46bd65d38df9..ec9da4830f6a 100644
> > --- a/drivers/acpi/acpica/dbhistry.c
> > +++ b/drivers/acpi/acpica/dbhistry.c
> > @@ -155,7 +155,7 @@ void acpi_db_display_history(void)
> >
> > for (i = 0; i < acpi_gbl_num_history; i++) {
> > if (acpi_gbl_history_buffer[history_index].command) {
> > -   acpi_os_printf("%3ld %s\n",
> > +   acpi_os_printf("%3u %s\n",
> >acpi_gbl_history_buffer[history_index].
> >cmd_num,
> >acpi_gbl_history_buffer[history_index].
> > diff --git a/drivers/acpi/acpica/dbinput.c b/drivers/acpi/acpica/dbinput.c
> > index 068214f9cc9d..43be06bdb790 100644
> > --- a/drivers/acpi/acpica/dbinput.c
> > +++ b/drivers/acpi/acpica/dbinput.c
> > @@ -608,7 +608,7 @@ static u32 acpi_db_get_line(char *input_buffer)
> > (acpi_gbl_db_parsed_buf, sizeof(acpi_gbl_db_parsed_buf),
> >  input_buffer)) {
> > acpi_os_printf
> > -   ("Buffer overflow while parsing input line (max %u 
> > characters)\n",
> > +   ("Buffer overflow while parsing input line (max %lu 
> > characters)\n",
> >  sizeof(acpi_gbl_db_parsed_buf));
> > return (0);
> > }
> > @@ -864,24 +864,24 @@ acpi_db_command_dispatch(char *input_buffer,
> >
> > if (param_count == 0) {
> > acpi_os_printf
> > -   ("Current debug level for file output is:
> > %8.8lX\n",
> > +   ("Current debug level for file output is:
> > %8.8X\n",
> >  acpi_gbl_db_debug_level);
> > acpi_os_printf
> > -   ("Current debug level for console output is: 
> > %8.8lX\n",
> > +   ("Current debug level for console output is: 
> > %8.8X\n",
> >  acpi_gbl_db_console_debug_level);
> > } else if (param_count == 2) {
> > temp = acpi_gbl_db_console_debug_level;
> > acpi_gbl_db_console_debug_level =
> > strtoul(acpi_gbl_db_args[1], NULL, 16);
> > acpi_os_printf
> > -   ("Debug Level for console output was %8.8lX, now 
> > %8.8lX\n",
> > +   ("Debug Level for console output was %8.8X, now 
> > %8.8X\n",
> >  temp, acpi_gbl_db_console_debug_level);
> > } else {
> > temp = acpi_gbl_db_debug_level;
> > acpi_gbl_db_debug_level =
> > strtoul(acpi_gbl_db_args[1], NULL, 16);
> > acpi_os_printf
> > -   ("Debug Level for file output was %8.8lX, now 
> > %8.8lX\n",
> > +   ("Debug Level for file output was %8.8X, now 
> > %8.8X\n",
> >  temp, acpi_gbl_db_debug_level);
> > }
> > break;
> > diff --git a/drivers/acpi/acpica/dbstats.c b/drivers/acpi/acpica/dbstats.c
> > index a414e1fa6f9d..de7023024b12 100644
> > --- a/drivers/acpi/acpica/dbstats.c
> > +++ b/drivers/acpi/acpica/dbstats.c
> > @@ -377,17 +377,17 @@ acpi_status acpi_db_display_statistics(char *type_arg)
> >"ACPI_TYPE", "NODES", "OBJECTS");
> >
> > for (i = 0; i < ACPI_TYPE_NS_NODE_MAX; i++) {
> > -   acpi_os_printf("%16.16s % 10ld% 10ld\n",
> > +   acpi_os_printf("%16.16s % 10d% 10d\n",
> >acpi_ut_get_type_name(i),
> >   

RE: [PATCH] acpi: Fix format string type mistakes

2016-12-20 Thread Zheng, Lv
Hi, Kees and Emese

I just helped to back port the commit here:
https://github.com/acpica/acpica/pull/196/commits/5e64857f
If you can see something wrong in it, please let me know.

Thanks and best regards
Lv

> From: Devel [mailto:devel-boun...@acpica.org] On Behalf Of Zheng, Lv
> Subject: Re: [Devel] [PATCH] acpi: Fix format string type mistakes
> 
> Hi,
> 
> > From: Kees Cook [mailto:keesc...@chromium.org]
> > Subject: [PATCH] acpi: Fix format string type mistakes
> >
> > From: Emese Revfy 
> >
> > This adds the missing __printf attribute which allows compile time
> > format string checking (and will be used by the coming initify gcc
> > plugin). Additionally, this fixes the warnings exposed by the attribute.
> >
> > Signed-off-by: Emese Revfy 
> > [kees: split scsi/acpi, merged attr and fix, new commit messages]
> > Signed-off-by: Kees Cook 
> > ---
> >  drivers/acpi/acpica/dbhistry.c |  2 +-
> >  drivers/acpi/acpica/dbinput.c  | 10 ++---
> >  drivers/acpi/acpica/dbstats.c  | 88 
> > +-
> >  drivers/acpi/acpica/utdebug.c  |  2 +-
> >  include/acpi/acpiosxf.h|  3 +-
> >  5 files changed, 53 insertions(+), 52 deletions(-)
> >
> > diff --git a/drivers/acpi/acpica/dbhistry.c b/drivers/acpi/acpica/dbhistry.c
> > index 46bd65d38df9..ec9da4830f6a 100644
> > --- a/drivers/acpi/acpica/dbhistry.c
> > +++ b/drivers/acpi/acpica/dbhistry.c
> > @@ -155,7 +155,7 @@ void acpi_db_display_history(void)
> >
> > for (i = 0; i < acpi_gbl_num_history; i++) {
> > if (acpi_gbl_history_buffer[history_index].command) {
> > -   acpi_os_printf("%3ld %s\n",
> > +   acpi_os_printf("%3u %s\n",
> >acpi_gbl_history_buffer[history_index].
> >cmd_num,
> >acpi_gbl_history_buffer[history_index].
> > diff --git a/drivers/acpi/acpica/dbinput.c b/drivers/acpi/acpica/dbinput.c
> > index 068214f9cc9d..43be06bdb790 100644
> > --- a/drivers/acpi/acpica/dbinput.c
> > +++ b/drivers/acpi/acpica/dbinput.c
> > @@ -608,7 +608,7 @@ static u32 acpi_db_get_line(char *input_buffer)
> > (acpi_gbl_db_parsed_buf, sizeof(acpi_gbl_db_parsed_buf),
> >  input_buffer)) {
> > acpi_os_printf
> > -   ("Buffer overflow while parsing input line (max %u 
> > characters)\n",
> > +   ("Buffer overflow while parsing input line (max %lu 
> > characters)\n",
> >  sizeof(acpi_gbl_db_parsed_buf));
> > return (0);
> > }
> > @@ -864,24 +864,24 @@ acpi_db_command_dispatch(char *input_buffer,
> >
> > if (param_count == 0) {
> > acpi_os_printf
> > -   ("Current debug level for file output is:
> > %8.8lX\n",
> > +   ("Current debug level for file output is:
> > %8.8X\n",
> >  acpi_gbl_db_debug_level);
> > acpi_os_printf
> > -   ("Current debug level for console output is: 
> > %8.8lX\n",
> > +   ("Current debug level for console output is: 
> > %8.8X\n",
> >  acpi_gbl_db_console_debug_level);
> > } else if (param_count == 2) {
> > temp = acpi_gbl_db_console_debug_level;
> > acpi_gbl_db_console_debug_level =
> > strtoul(acpi_gbl_db_args[1], NULL, 16);
> > acpi_os_printf
> > -   ("Debug Level for console output was %8.8lX, now 
> > %8.8lX\n",
> > +   ("Debug Level for console output was %8.8X, now 
> > %8.8X\n",
> >  temp, acpi_gbl_db_console_debug_level);
> > } else {
> > temp = acpi_gbl_db_debug_level;
> > acpi_gbl_db_debug_level =
> > strtoul(acpi_gbl_db_args[1], NULL, 16);
> > acpi_os_printf
> > -   ("Debug Level for file output was %8.8lX, now 
> > %8.8lX\n",
> > +   ("Debug Level for file output was %8.8X, now 
> > %8.8X\n",
> >  temp, acpi_gbl_db_debug_level);
> > }
> > break;
> > diff --git a/drivers/acpi/acpica/dbstats.c b/drivers/acpi/acpica/dbstats.c
> > index a414e1fa6f9d..de7023024b12 100644
> > --- a/drivers/acpi/acpica/dbstats.c
> > +++ b/drivers/acpi/acpica/dbstats.c
> > @@ -377,17 +377,17 @@ acpi_status acpi_db_display_statistics(char *type_arg)
> >"ACPI_TYPE", "NODES", "OBJECTS");
> >
> > for (i = 0; i < ACPI_TYPE_NS_NODE_MAX; i++) {
> > -   acpi_os_printf("%16.16s % 10ld% 10ld\n",
> > +   acpi_os_printf("%16.16s % 10d% 10d\n",
> >acpi_ut_get_type_name(i),
> >acpi_gbl_node_type_count[i],
> >  

Re: OOM: Better, but still there on

2016-12-20 Thread Michal Hocko
TL;DR
there is another version of the debugging patch. Just revert the
previous one and apply this one instead. It's still not clear what
is going on but I suspect either some misaccounting or unexpeted
pages on the LRU lists. I have added one more tracepoint, so please
enable also mm_vmscan_inactive_list_is_low.

Hopefully the additional data will tell us more.

On Tue 20-12-16 03:08:29, Nils Holland wrote:
> On Mon, Dec 19, 2016 at 02:45:34PM +0100, Michal Hocko wrote:
> 
> > Unfortunatelly shrink_active_list doesn't have any tracepoint so we do
> > not know whether we managed to rotate those pages. If they are referenced
> > quickly enough we might just keep refaulting them... Could you try to apply
> > the followin diff on top what you have currently. It should add some more
> > tracepoint data which might tell us more. We can reduce the amount of
> > tracing data by enabling only mm_vmscan_lru_isolate,
> > mm_vmscan_lru_shrink_inactive and mm_vmscan_lru_shrink_active.
> 
> So, the results are in! I applied your patch and rebuild the kernel,
> then I rebooted the machine, set up tracing so that only the three
> events you mentioned were being traced, and captured the output over
> the network.
> 
> Things went a bit different this time: The trace events started to
> appear after a while and a whole lot of them were generated, but
> suddenly they stopped. A short while later, we get

It is possible that you are hitting multiple issues so it would be
great to focus at one at the time. The underlying problem might be
same/similar in the end but this is hard to tell now. Could you try to
reproduce and provide data for the OOM killer situation as well?
 
> [ 1661.485568] btrfs-transacti: page alloction stalls for 611058ms, order:0, 
> mode:0x2420048(GFP_NOFS|__GFP_HARDWALL|__GFP_MOVABLE)
> 
> along with a backtrace and memory information, and then there was
> silence.

> When I walked up to the machine, it had completely died; it
> wouldn't turn on its screen on key press any more, blindly trying to
> reboot via SysRequest had no effect, but the caps lock LED also wasn't
> blinking, like it normally does when a kernel panic occurs. Good
> question what state it was in. The OOM reaper didn't really seem to
> kick in and kill processes this time, it seems.
> 
> The complete capture is up at:
> 
> http://ftp.tisys.org/pub/misc/teela_2016-12-20.log.xz

This is the stall report:
[ 1661.485568] btrfs-transacti: page alloction stalls for 611058ms, order:0, 
mode:0x2420048(GFP_NOFS|__GFP_HARDWALL|__GFP_MOVABLE)
[ 1661.485859] CPU: 1 PID: 1950 Comm: btrfs-transacti Not tainted 4.9.0-gentoo 
#4

pid 1950 is trying to allocate for a _long_ time. Considering that this
is the only stall report, this means that reclaim took really long so we
didn't get to the page allocator for that long. It sounds really crazy!

$ xzgrep -w 1950 teela_2016-12-20.log.xz | grep mm_vmscan_lru_shrink_inactive | 
sed 's@.*nr_reclaimed=\([0-9\]*\).*@\1@' | sort | uniq -c
509 0
  1 1
  1 10
  5 11
  1 12
  1 14
  1 16
  2 19
  5 2
  1 22
  2 23
  1 25
  3 28
  2 3
  1 4
  4 5

It barely managed to reclaim something. While it has tried a lot. It
had hard times to actually isolate anything:

$ xzgrep -w 1950 teela_2016-12-20.log.xz | grep mm_vmscan_lru_isolate: | sed 
's@.*nr_taken=@@' | sort | uniq -c
   8284 0 file=1
  8 11 file=1
  4 14 file=1
  1 1 file=1
  7 23 file=1
  1 25 file=1
  9 2 file=1
501 32 file=1
  1 3 file=1
  7 5 file=1
  1 6 file=1

a typical mm_vmscan_lru_isolate looks as follows

btrfs-transacti-1950  [001] d...  1368.508008: mm_vmscan_lru_isolate: 
isolate_mode=0 classzone=1 order=0 nr_requested=32 nr_scanned=266727 nr_taken=0 
file=1

so the whole inactive lru has been scanned it seems. But we couldn't
isolate a single page. There are two possibilities here. Either we skip
them all because they are from the highmem zone or we fail to
__isolate_lru_page them. Counters will not tell us because nr_scanned
includes skipped pages. I have updated the debugging patch to make this
distinction. I suspect we are skipping all of them...
The later option would be really surprising because the only way to fail
__isolate_lru_page with the 0 isolate_mode is if get_page_unless_zero(page)
fails which would mean we would have pages with 0 reference count on the
LRU list.

The stall message is from a later time so the situation might have
changed but
[ 1661.490170] Node 0   active_anon:139296kBinactive_anon:432kB 
active_file:1088996kB   inactive_file:1114524kB
[ 1661.490745] DMA  active_anon:0kB inactive_anon:0kB   
active_file:9540kB  inactive_file:0kB
[ 1661.491528] Normal   active_anon:0kB inactive_anon:0kB   
active_file:530560kBinactive_file:452kB
[ 1661.513077] HighMem  active_anon:139296kBinactive_anon:432kB 
active_file:548896kBinactive_file:1114068kB

suggests our inactive 

Re: OOM: Better, but still there on

2016-12-20 Thread Michal Hocko
TL;DR
there is another version of the debugging patch. Just revert the
previous one and apply this one instead. It's still not clear what
is going on but I suspect either some misaccounting or unexpeted
pages on the LRU lists. I have added one more tracepoint, so please
enable also mm_vmscan_inactive_list_is_low.

Hopefully the additional data will tell us more.

On Tue 20-12-16 03:08:29, Nils Holland wrote:
> On Mon, Dec 19, 2016 at 02:45:34PM +0100, Michal Hocko wrote:
> 
> > Unfortunatelly shrink_active_list doesn't have any tracepoint so we do
> > not know whether we managed to rotate those pages. If they are referenced
> > quickly enough we might just keep refaulting them... Could you try to apply
> > the followin diff on top what you have currently. It should add some more
> > tracepoint data which might tell us more. We can reduce the amount of
> > tracing data by enabling only mm_vmscan_lru_isolate,
> > mm_vmscan_lru_shrink_inactive and mm_vmscan_lru_shrink_active.
> 
> So, the results are in! I applied your patch and rebuild the kernel,
> then I rebooted the machine, set up tracing so that only the three
> events you mentioned were being traced, and captured the output over
> the network.
> 
> Things went a bit different this time: The trace events started to
> appear after a while and a whole lot of them were generated, but
> suddenly they stopped. A short while later, we get

It is possible that you are hitting multiple issues so it would be
great to focus at one at the time. The underlying problem might be
same/similar in the end but this is hard to tell now. Could you try to
reproduce and provide data for the OOM killer situation as well?
 
> [ 1661.485568] btrfs-transacti: page alloction stalls for 611058ms, order:0, 
> mode:0x2420048(GFP_NOFS|__GFP_HARDWALL|__GFP_MOVABLE)
> 
> along with a backtrace and memory information, and then there was
> silence.

> When I walked up to the machine, it had completely died; it
> wouldn't turn on its screen on key press any more, blindly trying to
> reboot via SysRequest had no effect, but the caps lock LED also wasn't
> blinking, like it normally does when a kernel panic occurs. Good
> question what state it was in. The OOM reaper didn't really seem to
> kick in and kill processes this time, it seems.
> 
> The complete capture is up at:
> 
> http://ftp.tisys.org/pub/misc/teela_2016-12-20.log.xz

This is the stall report:
[ 1661.485568] btrfs-transacti: page alloction stalls for 611058ms, order:0, 
mode:0x2420048(GFP_NOFS|__GFP_HARDWALL|__GFP_MOVABLE)
[ 1661.485859] CPU: 1 PID: 1950 Comm: btrfs-transacti Not tainted 4.9.0-gentoo 
#4

pid 1950 is trying to allocate for a _long_ time. Considering that this
is the only stall report, this means that reclaim took really long so we
didn't get to the page allocator for that long. It sounds really crazy!

$ xzgrep -w 1950 teela_2016-12-20.log.xz | grep mm_vmscan_lru_shrink_inactive | 
sed 's@.*nr_reclaimed=\([0-9\]*\).*@\1@' | sort | uniq -c
509 0
  1 1
  1 10
  5 11
  1 12
  1 14
  1 16
  2 19
  5 2
  1 22
  2 23
  1 25
  3 28
  2 3
  1 4
  4 5

It barely managed to reclaim something. While it has tried a lot. It
had hard times to actually isolate anything:

$ xzgrep -w 1950 teela_2016-12-20.log.xz | grep mm_vmscan_lru_isolate: | sed 
's@.*nr_taken=@@' | sort | uniq -c
   8284 0 file=1
  8 11 file=1
  4 14 file=1
  1 1 file=1
  7 23 file=1
  1 25 file=1
  9 2 file=1
501 32 file=1
  1 3 file=1
  7 5 file=1
  1 6 file=1

a typical mm_vmscan_lru_isolate looks as follows

btrfs-transacti-1950  [001] d...  1368.508008: mm_vmscan_lru_isolate: 
isolate_mode=0 classzone=1 order=0 nr_requested=32 nr_scanned=266727 nr_taken=0 
file=1

so the whole inactive lru has been scanned it seems. But we couldn't
isolate a single page. There are two possibilities here. Either we skip
them all because they are from the highmem zone or we fail to
__isolate_lru_page them. Counters will not tell us because nr_scanned
includes skipped pages. I have updated the debugging patch to make this
distinction. I suspect we are skipping all of them...
The later option would be really surprising because the only way to fail
__isolate_lru_page with the 0 isolate_mode is if get_page_unless_zero(page)
fails which would mean we would have pages with 0 reference count on the
LRU list.

The stall message is from a later time so the situation might have
changed but
[ 1661.490170] Node 0   active_anon:139296kBinactive_anon:432kB 
active_file:1088996kB   inactive_file:1114524kB
[ 1661.490745] DMA  active_anon:0kB inactive_anon:0kB   
active_file:9540kB  inactive_file:0kB
[ 1661.491528] Normal   active_anon:0kB inactive_anon:0kB   
active_file:530560kBinactive_file:452kB
[ 1661.513077] HighMem  active_anon:139296kBinactive_anon:432kB 
active_file:548896kBinactive_file:1114068kB

suggests our inactive 

Re: [PATCH V2 2/3] mtd: spi-nor: add support for macronix mx25u3235f

2016-12-20 Thread John Crispin


On 21/12/2016 08:33, Marek Vasut wrote:
> On 12/21/2016 08:23 AM, John Crispin wrote:
>> From: André Valentin 
>>
>> This patch adds support for a new macronix spi flash chip. We have had this
>> patch inside our tree for a while and people are actively using routers
>> with this chip.
>>
>> Signed-off-by: John Crispin 
>> Signed-off-by: André Valentin 
>> ---
>> Changes in V2
>> * add description
>> * add SECT_4K
>> * fix indenting
> 
> Are you SURE this chip can do sect_4k ? The datasheet seems to imply
> that, but I wonder why it wasn't in V1 of this patch then ? Esp. if
> people are actively using this chip ...

i checked the datasheet just now and it says 4K sectors are supported.
generally we cannot runtime test every patch that we receive but need to
rely on the testing of the submitter. lets see what André has to say.

John
> 
>>  drivers/mtd/spi-nor/spi-nor.c |1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
>> index 171adb3..bfff159 100644
>> --- a/drivers/mtd/spi-nor/spi-nor.c
>> +++ b/drivers/mtd/spi-nor/spi-nor.c
>> @@ -868,6 +868,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, 
>> loff_t ofs, uint64_t len)
>>  { "mx25l3205d",  INFO(0xc22016, 0, 64 * 1024,  64, SECT_4K) },
>>  { "mx25l3255e",  INFO(0xc29e16, 0, 64 * 1024,  64, SECT_4K) },
>>  { "mx25l6405d",  INFO(0xc22017, 0, 64 * 1024, 128, SECT_4K) },
>> +{ "mx25u3235f",  INFO(0xc22536, 0, 64 * 1024,  64, SECT_4K) },
>>  { "mx25u6435f",  INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) },
>>  { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
>>  { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
>>
> 
> 


Re: [PATCH V2 2/3] mtd: spi-nor: add support for macronix mx25u3235f

2016-12-20 Thread John Crispin


On 21/12/2016 08:33, Marek Vasut wrote:
> On 12/21/2016 08:23 AM, John Crispin wrote:
>> From: André Valentin 
>>
>> This patch adds support for a new macronix spi flash chip. We have had this
>> patch inside our tree for a while and people are actively using routers
>> with this chip.
>>
>> Signed-off-by: John Crispin 
>> Signed-off-by: André Valentin 
>> ---
>> Changes in V2
>> * add description
>> * add SECT_4K
>> * fix indenting
> 
> Are you SURE this chip can do sect_4k ? The datasheet seems to imply
> that, but I wonder why it wasn't in V1 of this patch then ? Esp. if
> people are actively using this chip ...

i checked the datasheet just now and it says 4K sectors are supported.
generally we cannot runtime test every patch that we receive but need to
rely on the testing of the submitter. lets see what André has to say.

John
> 
>>  drivers/mtd/spi-nor/spi-nor.c |1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
>> index 171adb3..bfff159 100644
>> --- a/drivers/mtd/spi-nor/spi-nor.c
>> +++ b/drivers/mtd/spi-nor/spi-nor.c
>> @@ -868,6 +868,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, 
>> loff_t ofs, uint64_t len)
>>  { "mx25l3205d",  INFO(0xc22016, 0, 64 * 1024,  64, SECT_4K) },
>>  { "mx25l3255e",  INFO(0xc29e16, 0, 64 * 1024,  64, SECT_4K) },
>>  { "mx25l6405d",  INFO(0xc22017, 0, 64 * 1024, 128, SECT_4K) },
>> +{ "mx25u3235f",  INFO(0xc22536, 0, 64 * 1024,  64, SECT_4K) },
>>  { "mx25u6435f",  INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) },
>>  { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
>>  { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
>>
> 
> 


Re: [PATCH V2 2/3] mtd: spi-nor: add support for macronix mx25u3235f

2016-12-20 Thread Marek Vasut
On 12/21/2016 08:23 AM, John Crispin wrote:
> From: André Valentin 
> 
> This patch adds support for a new macronix spi flash chip. We have had this
> patch inside our tree for a while and people are actively using routers
> with this chip.
> 
> Signed-off-by: John Crispin 
> Signed-off-by: André Valentin 
> ---
> Changes in V2
> * add description
> * add SECT_4K
> * fix indenting

Are you SURE this chip can do sect_4k ? The datasheet seems to imply
that, but I wonder why it wasn't in V1 of this patch then ? Esp. if
people are actively using this chip ...

>  drivers/mtd/spi-nor/spi-nor.c |1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 171adb3..bfff159 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -868,6 +868,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t 
> ofs, uint64_t len)
>   { "mx25l3205d",  INFO(0xc22016, 0, 64 * 1024,  64, SECT_4K) },
>   { "mx25l3255e",  INFO(0xc29e16, 0, 64 * 1024,  64, SECT_4K) },
>   { "mx25l6405d",  INFO(0xc22017, 0, 64 * 1024, 128, SECT_4K) },
> + { "mx25u3235f",  INFO(0xc22536, 0, 64 * 1024,  64, SECT_4K) },
>   { "mx25u6435f",  INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) },
>   { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
>   { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
> 


-- 
Best regards,
Marek Vasut


Re: [PATCH V2 2/3] mtd: spi-nor: add support for macronix mx25u3235f

2016-12-20 Thread Marek Vasut
On 12/21/2016 08:23 AM, John Crispin wrote:
> From: André Valentin 
> 
> This patch adds support for a new macronix spi flash chip. We have had this
> patch inside our tree for a while and people are actively using routers
> with this chip.
> 
> Signed-off-by: John Crispin 
> Signed-off-by: André Valentin 
> ---
> Changes in V2
> * add description
> * add SECT_4K
> * fix indenting

Are you SURE this chip can do sect_4k ? The datasheet seems to imply
that, but I wonder why it wasn't in V1 of this patch then ? Esp. if
people are actively using this chip ...

>  drivers/mtd/spi-nor/spi-nor.c |1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 171adb3..bfff159 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -868,6 +868,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t 
> ofs, uint64_t len)
>   { "mx25l3205d",  INFO(0xc22016, 0, 64 * 1024,  64, SECT_4K) },
>   { "mx25l3255e",  INFO(0xc29e16, 0, 64 * 1024,  64, SECT_4K) },
>   { "mx25l6405d",  INFO(0xc22017, 0, 64 * 1024, 128, SECT_4K) },
> + { "mx25u3235f",  INFO(0xc22536, 0, 64 * 1024,  64, SECT_4K) },
>   { "mx25u6435f",  INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) },
>   { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
>   { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
> 


-- 
Best regards,
Marek Vasut


Re: [PATCH V2 1/3] mtd: spi-nor: add support for macronix mx25u25635f

2016-12-20 Thread Marek Vasut
On 12/21/2016 08:23 AM, John Crispin wrote:
> From: Ash Benz 
> 
> This patch adds support for a new macronix spi flash chip.


> We have had this
> patch inside our tree for a while and people are actively using routers
> with this chip.

I think this information shouldn't be part of the commit message, it's
just unrelated to this change.

> Signed-off-by: John Crispin 
> Signed-off-by: Ash Benz 
> ---
> Changes in V2
> * add description
> 
>  drivers/mtd/spi-nor/spi-nor.c |1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index d0fc165..171adb3 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -872,6 +872,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t 
> ofs, uint64_t len)
>   { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
>   { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
>   { "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512, 0) },
> + { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, 0) },
>   { "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
>   { "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024, SPI_NOR_QUAD_READ) 
> },
>   { "mx66l1g55g",  INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) 
> },
> 


-- 
Best regards,
Marek Vasut


Re: [PATCH V2 1/3] mtd: spi-nor: add support for macronix mx25u25635f

2016-12-20 Thread Marek Vasut
On 12/21/2016 08:23 AM, John Crispin wrote:
> From: Ash Benz 
> 
> This patch adds support for a new macronix spi flash chip.


> We have had this
> patch inside our tree for a while and people are actively using routers
> with this chip.

I think this information shouldn't be part of the commit message, it's
just unrelated to this change.

> Signed-off-by: John Crispin 
> Signed-off-by: Ash Benz 
> ---
> Changes in V2
> * add description
> 
>  drivers/mtd/spi-nor/spi-nor.c |1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index d0fc165..171adb3 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -872,6 +872,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t 
> ofs, uint64_t len)
>   { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
>   { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
>   { "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512, 0) },
> + { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, 0) },
>   { "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
>   { "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024, SPI_NOR_QUAD_READ) 
> },
>   { "mx66l1g55g",  INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) 
> },
> 


-- 
Best regards,
Marek Vasut


Re: [PATCH 02/15] hyperv: uapi-fy synic event flags definitions

2016-12-20 Thread Roman Kagan
On Tue, Dec 20, 2016 at 09:24:53AM -0800, Stephen Hemminger wrote:
> On Tue, 20 Dec 2016 18:55:49 +0300
> Roman Kagan  wrote:
> 
> > Move definitions related to the Hyper-V SynIC event flags to a header
> > where they can be consumed by userspace.
> > 
> > While doing so, also clean up their use by switching to standard bitops
> > and struct-based dereferencing.  The latter is also done for message
> > pages.
> > 
> > Signed-off-by: Roman Kagan 
> > ---
> >  arch/x86/include/uapi/asm/hyperv.h | 13 +
> >  drivers/hv/hyperv_vmbus.h  | 24 ++--
> >  drivers/hv/channel_mgmt.c  | 10 +++
> >  drivers/hv/connection.c| 47 ++-
> >  drivers/hv/vmbus_drv.c | 57 
> > ++
> >  5 files changed, 54 insertions(+), 97 deletions(-)
> > 
> > diff --git a/arch/x86/include/uapi/asm/hyperv.h 
> > b/arch/x86/include/uapi/asm/hyperv.h
> > index 6098ab5..af542a3 100644
> > --- a/arch/x86/include/uapi/asm/hyperv.h
> > +++ b/arch/x86/include/uapi/asm/hyperv.h
> > @@ -363,4 +363,17 @@ struct hv_timer_message_payload {
> >  #define HV_STIMER_AUTOENABLE   (1ULL << 3)
> >  #define HV_STIMER_SINT(config) (__u8)(((config) >> 16) & 0x0F)
> >  
> > +/* Define synthetic interrupt controller flag constants. */
> > +#define HV_EVENT_FLAGS_COUNT   (256 * 8)
> > +
> > +/* Define the synthetic interrupt controller event flags format. */
> > +struct hv_synic_event_flags {
> > +   __u64 flags[HV_EVENT_FLAGS_COUNT / 64];
> > +};
> > +
> > +/* Define the synthetic interrupt flags page layout. */
> > +struct hv_synic_event_flags_page {
> > +   struct hv_synic_event_flags sintevent_flags[HV_SYNIC_SINT_COUNT];
> > +};
> > +
> >  #endif
> 
> How are these going to be exposed to user space?
> 
> They should really be unsigned long since there is no guarantee of atomic 
> operation
> on 64 bit values on 32 bit architectures.

Indeed, absolutely.  These are bitmaps and should be unsigned long[], of
course.  I'll fix it in the next iteration.

Thanks,
Roman.


Re: [PATCH 02/15] hyperv: uapi-fy synic event flags definitions

2016-12-20 Thread Roman Kagan
On Tue, Dec 20, 2016 at 09:24:53AM -0800, Stephen Hemminger wrote:
> On Tue, 20 Dec 2016 18:55:49 +0300
> Roman Kagan  wrote:
> 
> > Move definitions related to the Hyper-V SynIC event flags to a header
> > where they can be consumed by userspace.
> > 
> > While doing so, also clean up their use by switching to standard bitops
> > and struct-based dereferencing.  The latter is also done for message
> > pages.
> > 
> > Signed-off-by: Roman Kagan 
> > ---
> >  arch/x86/include/uapi/asm/hyperv.h | 13 +
> >  drivers/hv/hyperv_vmbus.h  | 24 ++--
> >  drivers/hv/channel_mgmt.c  | 10 +++
> >  drivers/hv/connection.c| 47 ++-
> >  drivers/hv/vmbus_drv.c | 57 
> > ++
> >  5 files changed, 54 insertions(+), 97 deletions(-)
> > 
> > diff --git a/arch/x86/include/uapi/asm/hyperv.h 
> > b/arch/x86/include/uapi/asm/hyperv.h
> > index 6098ab5..af542a3 100644
> > --- a/arch/x86/include/uapi/asm/hyperv.h
> > +++ b/arch/x86/include/uapi/asm/hyperv.h
> > @@ -363,4 +363,17 @@ struct hv_timer_message_payload {
> >  #define HV_STIMER_AUTOENABLE   (1ULL << 3)
> >  #define HV_STIMER_SINT(config) (__u8)(((config) >> 16) & 0x0F)
> >  
> > +/* Define synthetic interrupt controller flag constants. */
> > +#define HV_EVENT_FLAGS_COUNT   (256 * 8)
> > +
> > +/* Define the synthetic interrupt controller event flags format. */
> > +struct hv_synic_event_flags {
> > +   __u64 flags[HV_EVENT_FLAGS_COUNT / 64];
> > +};
> > +
> > +/* Define the synthetic interrupt flags page layout. */
> > +struct hv_synic_event_flags_page {
> > +   struct hv_synic_event_flags sintevent_flags[HV_SYNIC_SINT_COUNT];
> > +};
> > +
> >  #endif
> 
> How are these going to be exposed to user space?
> 
> They should really be unsigned long since there is no guarantee of atomic 
> operation
> on 64 bit values on 32 bit architectures.

Indeed, absolutely.  These are bitmaps and should be unsigned long[], of
course.  I'll fix it in the next iteration.

Thanks,
Roman.


Re: [PATCH 3/3] phy: rockchip-inno-usb2: Set EXTCON_USB when EXTCON_CHG_USB_SDP was set

2016-12-20 Thread Chanwoo Choi
Hi,

On 2016년 12월 21일 15:10, Baolin Wang wrote:
> According to the documentation, we should set the EXTCON_USB when
> one SDP charger connector was reported.
> 
> Signed-off-by: Baolin Wang 
> ---
>  drivers/phy/phy-rockchip-inno-usb2.c |7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/phy/phy-rockchip-inno-usb2.c 
> b/drivers/phy/phy-rockchip-inno-usb2.c
> index 2f99ec9..71fbe0f 100644
> --- a/drivers/phy/phy-rockchip-inno-usb2.c
> +++ b/drivers/phy/phy-rockchip-inno-usb2.c
> @@ -595,9 +595,14 @@ static void rockchip_usb2phy_otg_sm_work(struct 
> work_struct *work)
>   if (rport->vbus_attached != vbus_attach) {
>   rport->vbus_attached = vbus_attach;
>  
> - if (notify_charger && rphy->edev)
> + if (notify_charger && rphy->edev) {
>   extcon_set_cable_state_(rphy->edev,
>   cable, vbus_attach);
> + if (cable == EXTCON_CHG_USB_SDP)
> + extcon_set_cable_state_(rphy->edev,
> + EXTCON_USB,
> + vbus_attach);
> + }
>   }
>   break;
>   case OTG_STATE_B_PERIPHERAL:
> 

Looks good to me. But I prefer to use the 'extcon_set_state_sync' intead of 
extcon_set_cable_state_().
Reviewed-by: Chanwoo Choi 

I sent the patches[1] for extcon API to alter the deprecated API.
If you possible, I'd like you to alter the extcon API instead of deprecated API.
[1] https://patchwork.kernel.org/patch/9453645/
- extcon_set_cable_state_() -> extcon_set_state_sync()
- extcon_get_cable_state_() -> extcon_get_state()
- Use devm_extcon_register_notifier() instead of extcon_register_notifier().

-- 
Regards,
Chanwoo Choi


Re: [PATCH 3/3] phy: rockchip-inno-usb2: Set EXTCON_USB when EXTCON_CHG_USB_SDP was set

2016-12-20 Thread Chanwoo Choi
Hi,

On 2016년 12월 21일 15:10, Baolin Wang wrote:
> According to the documentation, we should set the EXTCON_USB when
> one SDP charger connector was reported.
> 
> Signed-off-by: Baolin Wang 
> ---
>  drivers/phy/phy-rockchip-inno-usb2.c |7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/phy/phy-rockchip-inno-usb2.c 
> b/drivers/phy/phy-rockchip-inno-usb2.c
> index 2f99ec9..71fbe0f 100644
> --- a/drivers/phy/phy-rockchip-inno-usb2.c
> +++ b/drivers/phy/phy-rockchip-inno-usb2.c
> @@ -595,9 +595,14 @@ static void rockchip_usb2phy_otg_sm_work(struct 
> work_struct *work)
>   if (rport->vbus_attached != vbus_attach) {
>   rport->vbus_attached = vbus_attach;
>  
> - if (notify_charger && rphy->edev)
> + if (notify_charger && rphy->edev) {
>   extcon_set_cable_state_(rphy->edev,
>   cable, vbus_attach);
> + if (cable == EXTCON_CHG_USB_SDP)
> + extcon_set_cable_state_(rphy->edev,
> + EXTCON_USB,
> + vbus_attach);
> + }
>   }
>   break;
>   case OTG_STATE_B_PERIPHERAL:
> 

Looks good to me. But I prefer to use the 'extcon_set_state_sync' intead of 
extcon_set_cable_state_().
Reviewed-by: Chanwoo Choi 

I sent the patches[1] for extcon API to alter the deprecated API.
If you possible, I'd like you to alter the extcon API instead of deprecated API.
[1] https://patchwork.kernel.org/patch/9453645/
- extcon_set_cable_state_() -> extcon_set_state_sync()
- extcon_get_cable_state_() -> extcon_get_state()
- Use devm_extcon_register_notifier() instead of extcon_register_notifier().

-- 
Regards,
Chanwoo Choi


[PATCH V2 2/3] mtd: spi-nor: add support for macronix mx25u3235f

2016-12-20 Thread John Crispin
From: André Valentin 

This patch adds support for a new macronix spi flash chip. We have had this
patch inside our tree for a while and people are actively using routers
with this chip.

Signed-off-by: John Crispin 
Signed-off-by: André Valentin 
---
Changes in V2
* add description
* add SECT_4K
* fix indenting

 drivers/mtd/spi-nor/spi-nor.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 171adb3..bfff159 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -868,6 +868,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t 
ofs, uint64_t len)
{ "mx25l3205d",  INFO(0xc22016, 0, 64 * 1024,  64, SECT_4K) },
{ "mx25l3255e",  INFO(0xc29e16, 0, 64 * 1024,  64, SECT_4K) },
{ "mx25l6405d",  INFO(0xc22017, 0, 64 * 1024, 128, SECT_4K) },
+   { "mx25u3235f",  INFO(0xc22536, 0, 64 * 1024,  64, SECT_4K) },
{ "mx25u6435f",  INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) },
{ "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
{ "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
-- 
1.7.10.4



[PATCH V2 2/3] mtd: spi-nor: add support for macronix mx25u3235f

2016-12-20 Thread John Crispin
From: André Valentin 

This patch adds support for a new macronix spi flash chip. We have had this
patch inside our tree for a while and people are actively using routers
with this chip.

Signed-off-by: John Crispin 
Signed-off-by: André Valentin 
---
Changes in V2
* add description
* add SECT_4K
* fix indenting

 drivers/mtd/spi-nor/spi-nor.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 171adb3..bfff159 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -868,6 +868,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t 
ofs, uint64_t len)
{ "mx25l3205d",  INFO(0xc22016, 0, 64 * 1024,  64, SECT_4K) },
{ "mx25l3255e",  INFO(0xc29e16, 0, 64 * 1024,  64, SECT_4K) },
{ "mx25l6405d",  INFO(0xc22017, 0, 64 * 1024, 128, SECT_4K) },
+   { "mx25u3235f",  INFO(0xc22536, 0, 64 * 1024,  64, SECT_4K) },
{ "mx25u6435f",  INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) },
{ "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
{ "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
-- 
1.7.10.4



[PATCH V2 3/3] mtd: spi-nor: add support for ESMT_f25l32qa and ESMT_f25l64qa

2016-12-20 Thread John Crispin
From: "Larry D. Pinney" 

Add Support for the ESMT_F25L32QA and ESMT_F25L64QA
These are 4MB and 8MB SPI NOR Chips from Elite Semiconductor Memory
Technology

Acked-by: Marek Vasut 
Signed-off-by: John Crispin 
Signed-off-by: Larry D. Pinney 
---
 drivers/mtd/spi-nor/spi-nor.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index bfff159..2b150b5 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -821,6 +821,8 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t 
ofs, uint64_t len)
 
/* ESMT */
{ "f25l32pa", INFO(0x8c2016, 0, 64 * 1024, 64, SECT_4K) },
+   { "f25l32qa", INFO(0x8c4116, 0, 64 * 1024, 64, SECT_4K) },
+   { "f25l64qa", INFO(0x8c4117, 0, 64 * 1024, 128, SECT_4K) },
 
/* Everspin */
{ "mr25h256", CAT25_INFO( 32 * 1024, 1, 256, 2, SPI_NOR_NO_ERASE | 
SPI_NOR_NO_FR) },
-- 
1.7.10.4



[PATCH V2 3/3] mtd: spi-nor: add support for ESMT_f25l32qa and ESMT_f25l64qa

2016-12-20 Thread John Crispin
From: "Larry D. Pinney" 

Add Support for the ESMT_F25L32QA and ESMT_F25L64QA
These are 4MB and 8MB SPI NOR Chips from Elite Semiconductor Memory
Technology

Acked-by: Marek Vasut 
Signed-off-by: John Crispin 
Signed-off-by: Larry D. Pinney 
---
 drivers/mtd/spi-nor/spi-nor.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index bfff159..2b150b5 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -821,6 +821,8 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t 
ofs, uint64_t len)
 
/* ESMT */
{ "f25l32pa", INFO(0x8c2016, 0, 64 * 1024, 64, SECT_4K) },
+   { "f25l32qa", INFO(0x8c4116, 0, 64 * 1024, 64, SECT_4K) },
+   { "f25l64qa", INFO(0x8c4117, 0, 64 * 1024, 128, SECT_4K) },
 
/* Everspin */
{ "mr25h256", CAT25_INFO( 32 * 1024, 1, 256, 2, SPI_NOR_NO_ERASE | 
SPI_NOR_NO_FR) },
-- 
1.7.10.4



[PATCH V2 1/3] mtd: spi-nor: add support for macronix mx25u25635f

2016-12-20 Thread John Crispin
From: Ash Benz 

This patch adds support for a new macronix spi flash chip. We have had this
patch inside our tree for a while and people are actively using routers
with this chip.

Signed-off-by: John Crispin 
Signed-off-by: Ash Benz 
---
Changes in V2
* add description

 drivers/mtd/spi-nor/spi-nor.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index d0fc165..171adb3 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -872,6 +872,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t 
ofs, uint64_t len)
{ "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
{ "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
{ "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512, 0) },
+   { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, 0) },
{ "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
{ "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024, SPI_NOR_QUAD_READ) 
},
{ "mx66l1g55g",  INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) 
},
-- 
1.7.10.4



[PATCH V2 1/3] mtd: spi-nor: add support for macronix mx25u25635f

2016-12-20 Thread John Crispin
From: Ash Benz 

This patch adds support for a new macronix spi flash chip. We have had this
patch inside our tree for a while and people are actively using routers
with this chip.

Signed-off-by: John Crispin 
Signed-off-by: Ash Benz 
---
Changes in V2
* add description

 drivers/mtd/spi-nor/spi-nor.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index d0fc165..171adb3 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -872,6 +872,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t 
ofs, uint64_t len)
{ "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
{ "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
{ "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512, 0) },
+   { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, 0) },
{ "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
{ "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024, SPI_NOR_QUAD_READ) 
},
{ "mx66l1g55g",  INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) 
},
-- 
1.7.10.4



[PATCH V2 0/3] mtd: spi-nor: add some new chip ids

2016-12-20 Thread John Crispin
These have been lingering inside the owrt and lede trees for a while.

André Valentin (1):
  mtd: spi-nor: add support for macronix mx25u3235f

Ash Benz (1):
  mtd: spi-nor: add support for macronix mx25u25635f

Larry D. Pinney (1):
  mtd: spi-nor: add support for ESMT_f25l32qa and ESMT_f25l64qa

 drivers/mtd/spi-nor/spi-nor.c |4 
 1 file changed, 4 insertions(+)

-- 
1.7.10.4



[PATCH V2 0/3] mtd: spi-nor: add some new chip ids

2016-12-20 Thread John Crispin
These have been lingering inside the owrt and lede trees for a while.

André Valentin (1):
  mtd: spi-nor: add support for macronix mx25u3235f

Ash Benz (1):
  mtd: spi-nor: add support for macronix mx25u25635f

Larry D. Pinney (1):
  mtd: spi-nor: add support for ESMT_f25l32qa and ESMT_f25l64qa

 drivers/mtd/spi-nor/spi-nor.c |4 
 1 file changed, 4 insertions(+)

-- 
1.7.10.4



Re: [PATCH 2/3] extcon: axp288: Set EXTCON_USB when EXTCON_CHG_USB_SDP was set

2016-12-20 Thread Chanwoo Choi
Hi,

On 2016년 12월 21일 15:10, Baolin Wang wrote:
> According to the documentation, we should set the EXTCON_USB when
> one SDP charger connector was reported.
> 
> Signed-off-by: Baolin Wang 
> ---
>  drivers/extcon/extcon-axp288.c |7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
> index 42f41e8..4490726 100644
> --- a/drivers/extcon/extcon-axp288.c
> +++ b/drivers/extcon/extcon-axp288.c
> @@ -102,6 +102,7 @@ enum axp288_extcon_irq {
>  };
>  
>  static const unsigned int axp288_extcon_cables[] = {
> + EXTCON_USB,
>   EXTCON_CHG_USB_SDP,
>   EXTCON_CHG_USB_CDP,
>   EXTCON_CHG_USB_DCP,
> @@ -225,8 +226,12 @@ static int axp288_handle_chrg_det_event(struct 
> axp288_extcon_info *info)
>   vbus_attach ? USB_EVENT_VBUS : USB_EVENT_NONE, NULL);
>   }
>  
> - if (notify_charger)
> + if (notify_charger) {
>   extcon_set_state_sync(info->edev, cable, vbus_attach);
> + if (cable == EXTCON_CHG_USB_SDP)
> + extcon_set_state_sync(info->edev, EXTCON_USB,
> +   vbus_attach);
> + }
>  
>   /* Clear the flags on disconnect event */
>   if (!vbus_attach)
> 

The extcon-axp288.c driver has some patches on extcon-next[1] branch.
[1] 
https://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/log/?h=extcon-next

I rework your patch on extcon-next branch as following:
If you ok, I'll merge it for v4.11.

commit 1a96f92bdfab86d0b634e56092f543cad348fd0b
Refs: extcon-next, extcon-next-for-4.10-15-g1a96f92bdfab
Author: Baolin Wang 
AuthorDate: Wed Dec 21 15:51:26 2016 +0900
Commit: Chanwoo Choi 
CommitDate: Wed Dec 21 15:52:00 2016 +0900

extcon: axp288: Set EXTCON_USB when EXTCON_CHG_USB_SDP was set

According to the documentation, we should set the EXTCON_USB when
one SDP charger connector was reported.

Signed-off-by: Baolin Wang 
Signed-off-by: Chanwoo Choi 
---
 drivers/extcon/extcon-axp288.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
index 3e145e2a4860..f4fd03e58e37 100644
--- a/drivers/extcon/extcon-axp288.c
+++ b/drivers/extcon/extcon-axp288.c
@@ -96,6 +96,7 @@ enum axp288_extcon_irq {
EXTCON_CHG_USB_SDP,
EXTCON_CHG_USB_CDP,
EXTCON_CHG_USB_DCP,
+   EXTCON_USB,
EXTCON_NONE,
 };

@@ -206,8 +207,15 @@ static int axp288_handle_chrg_det_event(struct 
axp288_extcon_info *info)
: EXTCON_GPIO_MUX_SEL_PMIC);

extcon_set_state_sync(info->edev, info->previous_cable, false);
+   if (info->previous_cable == EXTCON_CHG_USB_SDP)
+   extcon_set_state_sync(info->edev, EXTCON_USB, false);
+
if (vbus_attach) {
extcon_set_state_sync(info->edev, cable, vbus_attach);
+   if (cable == EXTCON_CHG_USB_SDP)
+   extcon_set_state_sync(info->edev, EXTCON_USB,
+   vbus_attach);
+
info->previous_cable = cable;
}

-- 
Regards,
Chanwoo Choi


Re: [PATCH 2/3] extcon: axp288: Set EXTCON_USB when EXTCON_CHG_USB_SDP was set

2016-12-20 Thread Chanwoo Choi
Hi,

On 2016년 12월 21일 15:10, Baolin Wang wrote:
> According to the documentation, we should set the EXTCON_USB when
> one SDP charger connector was reported.
> 
> Signed-off-by: Baolin Wang 
> ---
>  drivers/extcon/extcon-axp288.c |7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
> index 42f41e8..4490726 100644
> --- a/drivers/extcon/extcon-axp288.c
> +++ b/drivers/extcon/extcon-axp288.c
> @@ -102,6 +102,7 @@ enum axp288_extcon_irq {
>  };
>  
>  static const unsigned int axp288_extcon_cables[] = {
> + EXTCON_USB,
>   EXTCON_CHG_USB_SDP,
>   EXTCON_CHG_USB_CDP,
>   EXTCON_CHG_USB_DCP,
> @@ -225,8 +226,12 @@ static int axp288_handle_chrg_det_event(struct 
> axp288_extcon_info *info)
>   vbus_attach ? USB_EVENT_VBUS : USB_EVENT_NONE, NULL);
>   }
>  
> - if (notify_charger)
> + if (notify_charger) {
>   extcon_set_state_sync(info->edev, cable, vbus_attach);
> + if (cable == EXTCON_CHG_USB_SDP)
> + extcon_set_state_sync(info->edev, EXTCON_USB,
> +   vbus_attach);
> + }
>  
>   /* Clear the flags on disconnect event */
>   if (!vbus_attach)
> 

The extcon-axp288.c driver has some patches on extcon-next[1] branch.
[1] 
https://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/log/?h=extcon-next

I rework your patch on extcon-next branch as following:
If you ok, I'll merge it for v4.11.

commit 1a96f92bdfab86d0b634e56092f543cad348fd0b
Refs: extcon-next, extcon-next-for-4.10-15-g1a96f92bdfab
Author: Baolin Wang 
AuthorDate: Wed Dec 21 15:51:26 2016 +0900
Commit: Chanwoo Choi 
CommitDate: Wed Dec 21 15:52:00 2016 +0900

extcon: axp288: Set EXTCON_USB when EXTCON_CHG_USB_SDP was set

According to the documentation, we should set the EXTCON_USB when
one SDP charger connector was reported.

Signed-off-by: Baolin Wang 
Signed-off-by: Chanwoo Choi 
---
 drivers/extcon/extcon-axp288.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
index 3e145e2a4860..f4fd03e58e37 100644
--- a/drivers/extcon/extcon-axp288.c
+++ b/drivers/extcon/extcon-axp288.c
@@ -96,6 +96,7 @@ enum axp288_extcon_irq {
EXTCON_CHG_USB_SDP,
EXTCON_CHG_USB_CDP,
EXTCON_CHG_USB_DCP,
+   EXTCON_USB,
EXTCON_NONE,
 };

@@ -206,8 +207,15 @@ static int axp288_handle_chrg_det_event(struct 
axp288_extcon_info *info)
: EXTCON_GPIO_MUX_SEL_PMIC);

extcon_set_state_sync(info->edev, info->previous_cable, false);
+   if (info->previous_cable == EXTCON_CHG_USB_SDP)
+   extcon_set_state_sync(info->edev, EXTCON_USB, false);
+
if (vbus_attach) {
extcon_set_state_sync(info->edev, cable, vbus_attach);
+   if (cable == EXTCON_CHG_USB_SDP)
+   extcon_set_state_sync(info->edev, EXTCON_USB,
+   vbus_attach);
+
info->previous_cable = cable;
}

-- 
Regards,
Chanwoo Choi


Re: [PATCH] kernel: sys: fix out of place EXPORT_SYMBOL call

2016-12-20 Thread Michal Hocko
On Tue 20-12-16 14:39:19, Thomas Casey wrote:
> Fixes two instances of EXPORT_SYMBOL not being called immediately after
> the initialization of its argument

What does this fix actually?

> Signed-off-by: Thomas Casey 
> ---
>  kernel/sys.c | 6 ++
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/sys.c b/kernel/sys.c
> index 9758892a2d09..8afd3e341f9b 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -110,9 +110,8 @@
>   */
>  
>  int overflowuid = DEFAULT_OVERFLOWUID;
> -int overflowgid = DEFAULT_OVERFLOWGID;
> -
>  EXPORT_SYMBOL(overflowuid);
> +int overflowgid = DEFAULT_OVERFLOWGID;
>  EXPORT_SYMBOL(overflowgid);
>  
>  /*
> @@ -121,9 +120,8 @@ EXPORT_SYMBOL(overflowgid);
>   */
>  
>  int fs_overflowuid = DEFAULT_FS_OVERFLOWUID;
> -int fs_overflowgid = DEFAULT_FS_OVERFLOWUID;
> -
>  EXPORT_SYMBOL(fs_overflowuid);
> +int fs_overflowgid = DEFAULT_FS_OVERFLOWUID;
>  EXPORT_SYMBOL(fs_overflowgid);
>  
>  /*
> -- 
> 2.11.0
> 

-- 
Michal Hocko
SUSE Labs


Re: [PATCH] kernel: sys: fix out of place EXPORT_SYMBOL call

2016-12-20 Thread Michal Hocko
On Tue 20-12-16 14:39:19, Thomas Casey wrote:
> Fixes two instances of EXPORT_SYMBOL not being called immediately after
> the initialization of its argument

What does this fix actually?

> Signed-off-by: Thomas Casey 
> ---
>  kernel/sys.c | 6 ++
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/sys.c b/kernel/sys.c
> index 9758892a2d09..8afd3e341f9b 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -110,9 +110,8 @@
>   */
>  
>  int overflowuid = DEFAULT_OVERFLOWUID;
> -int overflowgid = DEFAULT_OVERFLOWGID;
> -
>  EXPORT_SYMBOL(overflowuid);
> +int overflowgid = DEFAULT_OVERFLOWGID;
>  EXPORT_SYMBOL(overflowgid);
>  
>  /*
> @@ -121,9 +120,8 @@ EXPORT_SYMBOL(overflowgid);
>   */
>  
>  int fs_overflowuid = DEFAULT_FS_OVERFLOWUID;
> -int fs_overflowgid = DEFAULT_FS_OVERFLOWUID;
> -
>  EXPORT_SYMBOL(fs_overflowuid);
> +int fs_overflowgid = DEFAULT_FS_OVERFLOWUID;
>  EXPORT_SYMBOL(fs_overflowgid);
>  
>  /*
> -- 
> 2.11.0
> 

-- 
Michal Hocko
SUSE Labs


Re: [PATCH 1/3] extcon: Add documentation for EXTCON_CHG_USB_* and EXTCON_USB_*

2016-12-20 Thread Chanwoo Choi
Hi,

On 2016년 12월 21일 15:10, Baolin Wang wrote:
> Current there is both "EXTCON_USB" and "EXTCON_CHG_USB_SDP" which
> both seem to suggest a standard downstream port. But there is no
> documentation describing how these relate.
> 
> Thus add documentation to describe EXTCON_CHG_USB_SDP should always
> appear together with EXTCON_USB, and EXTCON_CHG_USB_ACA would normally
> appear with EXTCON_USB_HOST.
> 
> Signed-off-by: Baolin Wang 
> ---
>  include/linux/extcon.h |9 -
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/extcon.h b/include/linux/extcon.h
> index b871c0c..6498b05 100644
> --- a/include/linux/extcon.h
> +++ b/include/linux/extcon.h
> @@ -46,7 +46,14 @@
>  #define EXTCON_USB   1
>  #define EXTCON_USB_HOST  2
>  
> -/* Charging external connector */
> +/*
> + * Charging external connector
> + *
> + * When one SDP charger connector was reported, we should also report
> + * the USB connector, which means EXTCON_CHG_USB_SDP should always
> + * appear together with EXTCON_USB. The same as ACA charger connector,
> + * EXTCON_CHG_USB_ACA should always appear with EXTCON_USB_HOST.
> + */

Looks good to me.
But, you use the different word for ACA as following:
I think that 'would normally' is proper in descritpion.

- commit msg : EXTCON_CHG_USB_ACA would normally appear with EXTCON_USB_HOST.
- description: EXTCON_CHG_USB_ACA should always appear with EXTCON_USB_HOST.

>  #define EXTCON_CHG_USB_SDP   5   /* Standard Downstream Port */
>  #define EXTCON_CHG_USB_DCP   6   /* Dedicated Charging Port */
>  #define EXTCON_CHG_USB_CDP   7   /* Charging Downstream Port */
> 

-- 
Regards,
Chanwoo Choi


Re: [PATCH 1/3] extcon: Add documentation for EXTCON_CHG_USB_* and EXTCON_USB_*

2016-12-20 Thread Chanwoo Choi
Hi,

On 2016년 12월 21일 15:10, Baolin Wang wrote:
> Current there is both "EXTCON_USB" and "EXTCON_CHG_USB_SDP" which
> both seem to suggest a standard downstream port. But there is no
> documentation describing how these relate.
> 
> Thus add documentation to describe EXTCON_CHG_USB_SDP should always
> appear together with EXTCON_USB, and EXTCON_CHG_USB_ACA would normally
> appear with EXTCON_USB_HOST.
> 
> Signed-off-by: Baolin Wang 
> ---
>  include/linux/extcon.h |9 -
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/extcon.h b/include/linux/extcon.h
> index b871c0c..6498b05 100644
> --- a/include/linux/extcon.h
> +++ b/include/linux/extcon.h
> @@ -46,7 +46,14 @@
>  #define EXTCON_USB   1
>  #define EXTCON_USB_HOST  2
>  
> -/* Charging external connector */
> +/*
> + * Charging external connector
> + *
> + * When one SDP charger connector was reported, we should also report
> + * the USB connector, which means EXTCON_CHG_USB_SDP should always
> + * appear together with EXTCON_USB. The same as ACA charger connector,
> + * EXTCON_CHG_USB_ACA should always appear with EXTCON_USB_HOST.
> + */

Looks good to me.
But, you use the different word for ACA as following:
I think that 'would normally' is proper in descritpion.

- commit msg : EXTCON_CHG_USB_ACA would normally appear with EXTCON_USB_HOST.
- description: EXTCON_CHG_USB_ACA should always appear with EXTCON_USB_HOST.

>  #define EXTCON_CHG_USB_SDP   5   /* Standard Downstream Port */
>  #define EXTCON_CHG_USB_DCP   6   /* Dedicated Charging Port */
>  #define EXTCON_CHG_USB_CDP   7   /* Charging Downstream Port */
> 

-- 
Regards,
Chanwoo Choi


Re: [PATCH v6] soc: qcom: Add SoC info driver

2016-12-20 Thread Imran Khan
On 12/21/2016 4:20 AM, Stephen Boyd wrote:
> On 12/18, Imran Khan wrote:
>>
>> I had discussed this with Bjorn and it was recommended to keep it out of 
>> smem.h. If needed I can move it back there.
> 
> Ok no worries from me then if this has already been discussed.
> 
>>
>> Yes. The numbers used here can have different meaning for different ODMs.
>> But these attributes (hw_patform type/subtype etc.) are outside the
>> generic soc_device_attribute so I think the interpretation of these numbers
>> can very well be ODM specific. We can try to keep only those types here that
>> are relevant for newer platforms but we intend to keep these attributes
>> nonetheless.
> 
> I'll wait to see what the next patch version has. We will
> probably need to have some way to know which ODM the kernel is
> running on, so we can interpret the platform type/subtype fields
> properly. That part seems to be lacking from this patch right
> now. We assume it's always qcom as the ODM, which isn't true.
> 
Now I get this point. So far we don't have any mechanism in the driver that
gives ODM information. As far as generic soc_device_attribute's vendor field
is concerned we use Qualcomm since this will be true for SoC.
For hardware type and sub-types the various relevant values in SMEM are numeric
values and indeed it would be very difficult to estimate how some other ODM
will use the same number.
So for the h/w types and sub-types can we keep the numeric values rather than 
showing strings as attribute values. We can leave the interpretation of these
values to ODM specific code.
Will wait for your feedback so that I can take care of it accordingly in the
next patch set.

Regards,
Imran

-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a\nmember of 
the Code Aurora Forum, hosted by The Linux Foundation


Re: [PATCH v6] soc: qcom: Add SoC info driver

2016-12-20 Thread Imran Khan
On 12/21/2016 4:20 AM, Stephen Boyd wrote:
> On 12/18, Imran Khan wrote:
>>
>> I had discussed this with Bjorn and it was recommended to keep it out of 
>> smem.h. If needed I can move it back there.
> 
> Ok no worries from me then if this has already been discussed.
> 
>>
>> Yes. The numbers used here can have different meaning for different ODMs.
>> But these attributes (hw_patform type/subtype etc.) are outside the
>> generic soc_device_attribute so I think the interpretation of these numbers
>> can very well be ODM specific. We can try to keep only those types here that
>> are relevant for newer platforms but we intend to keep these attributes
>> nonetheless.
> 
> I'll wait to see what the next patch version has. We will
> probably need to have some way to know which ODM the kernel is
> running on, so we can interpret the platform type/subtype fields
> properly. That part seems to be lacking from this patch right
> now. We assume it's always qcom as the ODM, which isn't true.
> 
Now I get this point. So far we don't have any mechanism in the driver that
gives ODM information. As far as generic soc_device_attribute's vendor field
is concerned we use Qualcomm since this will be true for SoC.
For hardware type and sub-types the various relevant values in SMEM are numeric
values and indeed it would be very difficult to estimate how some other ODM
will use the same number.
So for the h/w types and sub-types can we keep the numeric values rather than 
showing strings as attribute values. We can leave the interpretation of these
values to ODM specific code.
Will wait for your feedback so that I can take care of it accordingly in the
next patch set.

Regards,
Imran

-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a\nmember of 
the Code Aurora Forum, hosted by The Linux Foundation


Re: [PATCH 3/3] lib: Update LZ4 compressor module based on LZ4 v1.7.2.

2016-12-20 Thread kbuild test robot
Hi Sven,

[auto build test ERROR on linus/master]
[also build test ERROR on next-20161221]
[cannot apply to v4.9]
[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/Sven-Schmidt/Update-LZ4-compressor-module/20161221-130109
config: x86_64-randconfig-r0-12211341 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All errors (new ones prefixed by >>):

   In file included from /usr/lib/gcc/x86_64-linux-gnu/6/include/stdint.h:11:0,
from 
arch/x86/boot/compressed/../../../../lib/lz4/lz4defs.h:60,
from 
arch/x86/boot/compressed/../../../../lib/lz4/lz4_decompress.c:36,
from 
arch/x86/boot/compressed/../../../../lib/decompress_unlz4.c:13,
from arch/x86/boot/compressed/misc.c:75:
>> /usr/lib/gcc/x86_64-linux-gnu/6/include/stdint-gcc.h:43:24: error: 
>> conflicting types for 'int64_t'
typedef __INT64_TYPE__ int64_t;
   ^~~
   In file included from include/uapi/linux/screen_info.h:4:0,
from include/linux/screen_info.h:4,
from arch/x86/boot/compressed/misc.h:15,
from arch/x86/boot/compressed/misc.c:14:
   include/linux/types.h:113:17: note: previous declaration of 'int64_t' was 
here
typedef  __s64  int64_t;
^~~
   In file included from /usr/lib/gcc/x86_64-linux-gnu/6/include/stdint.h:11:0,
from 
arch/x86/boot/compressed/../../../../lib/lz4/lz4defs.h:60,
from 
arch/x86/boot/compressed/../../../../lib/lz4/lz4_decompress.c:36,
from 
arch/x86/boot/compressed/../../../../lib/decompress_unlz4.c:13,
from arch/x86/boot/compressed/misc.c:75:
>> /usr/lib/gcc/x86_64-linux-gnu/6/include/stdint-gcc.h:55:25: error: 
>> conflicting types for 'uint64_t'
typedef __UINT64_TYPE__ uint64_t;
^~~~
   In file included from include/uapi/linux/screen_info.h:4:0,
from include/linux/screen_info.h:4,
from arch/x86/boot/compressed/misc.h:15,
from arch/x86/boot/compressed/misc.c:14:
   include/linux/types.h:111:17: note: previous declaration of 'uint64_t' was 
here
typedef  __u64  uint64_t;
^~~~

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [PATCH 3/3] lib: Update LZ4 compressor module based on LZ4 v1.7.2.

2016-12-20 Thread kbuild test robot
Hi Sven,

[auto build test ERROR on linus/master]
[also build test ERROR on next-20161221]
[cannot apply to v4.9]
[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/Sven-Schmidt/Update-LZ4-compressor-module/20161221-130109
config: x86_64-randconfig-r0-12211341 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All errors (new ones prefixed by >>):

   In file included from /usr/lib/gcc/x86_64-linux-gnu/6/include/stdint.h:11:0,
from 
arch/x86/boot/compressed/../../../../lib/lz4/lz4defs.h:60,
from 
arch/x86/boot/compressed/../../../../lib/lz4/lz4_decompress.c:36,
from 
arch/x86/boot/compressed/../../../../lib/decompress_unlz4.c:13,
from arch/x86/boot/compressed/misc.c:75:
>> /usr/lib/gcc/x86_64-linux-gnu/6/include/stdint-gcc.h:43:24: error: 
>> conflicting types for 'int64_t'
typedef __INT64_TYPE__ int64_t;
   ^~~
   In file included from include/uapi/linux/screen_info.h:4:0,
from include/linux/screen_info.h:4,
from arch/x86/boot/compressed/misc.h:15,
from arch/x86/boot/compressed/misc.c:14:
   include/linux/types.h:113:17: note: previous declaration of 'int64_t' was 
here
typedef  __s64  int64_t;
^~~
   In file included from /usr/lib/gcc/x86_64-linux-gnu/6/include/stdint.h:11:0,
from 
arch/x86/boot/compressed/../../../../lib/lz4/lz4defs.h:60,
from 
arch/x86/boot/compressed/../../../../lib/lz4/lz4_decompress.c:36,
from 
arch/x86/boot/compressed/../../../../lib/decompress_unlz4.c:13,
from arch/x86/boot/compressed/misc.c:75:
>> /usr/lib/gcc/x86_64-linux-gnu/6/include/stdint-gcc.h:55:25: error: 
>> conflicting types for 'uint64_t'
typedef __UINT64_TYPE__ uint64_t;
^~~~
   In file included from include/uapi/linux/screen_info.h:4:0,
from include/linux/screen_info.h:4,
from arch/x86/boot/compressed/misc.h:15,
from arch/x86/boot/compressed/misc.c:14:
   include/linux/types.h:111:17: note: previous declaration of 'uint64_t' was 
here
typedef  __u64  uint64_t;
^~~~

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [PATCH] openrisc: Define __kernel_size_t to suppress compiler warnings

2016-12-20 Thread Geert Uytterhoeven
On Tue, Dec 20, 2016 at 11:44 PM, Andreas Schwab  wrote:
> On Dez 20 2016, Geert Uytterhoeven  wrote:
>> When I saw this patch, I was already a bit skeptical about it, but I noticed
>> other architectures (e.g. avr32) are doing the same, so I didn't reply.
>>
>> In my experience, "format '%zu' expects argument of type 'size_t', but
>> argument 3 has type 'unsigned int'" happens when using a compiler that
>> was not configured to use the correct type (should be unsigned long) for
>> size_t. Typically this happens when using a compiler not configured for
>> a Linux target.
>
> 32-bit targets typically use unsigned int for size_t.  It is part of the
> ABI, so all compilers must agree.  Since or32 is a out-of-tree port, and
> gcc defaults to unsigned long for size_t, mismatches can happen if
> people are using incomplete patches.

Right, thanks for correcting me!
It should indeed be unsigned int on 32-bit, and unsigned long on 64-bit.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PATCH] openrisc: Define __kernel_size_t to suppress compiler warnings

2016-12-20 Thread Geert Uytterhoeven
On Tue, Dec 20, 2016 at 11:44 PM, Andreas Schwab  wrote:
> On Dez 20 2016, Geert Uytterhoeven  wrote:
>> When I saw this patch, I was already a bit skeptical about it, but I noticed
>> other architectures (e.g. avr32) are doing the same, so I didn't reply.
>>
>> In my experience, "format '%zu' expects argument of type 'size_t', but
>> argument 3 has type 'unsigned int'" happens when using a compiler that
>> was not configured to use the correct type (should be unsigned long) for
>> size_t. Typically this happens when using a compiler not configured for
>> a Linux target.
>
> 32-bit targets typically use unsigned int for size_t.  It is part of the
> ABI, so all compilers must agree.  Since or32 is a out-of-tree port, and
> gcc defaults to unsigned long for size_t, mismatches can happen if
> people are using incomplete patches.

Right, thanks for correcting me!
It should indeed be unsigned int on 32-bit, and unsigned long on 64-bit.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


[PATCH v6 kernel 2/5] virtio-balloon: define new feature bit and head struct

2016-12-20 Thread Liang Li
Add a new feature which supports sending the page information
with range array. The current implementation uses PFNs array,
which is not very efficient. Using ranges can improve the
performance of inflating/deflating significantly.

Signed-off-by: Liang Li 
Cc: Michael S. Tsirkin 
Cc: Paolo Bonzini 
Cc: Cornelia Huck 
Cc: Amit Shah 
Cc: Dave Hansen 
Cc: Andrea Arcangeli 
Cc: David Hildenbrand 
---
 include/uapi/linux/virtio_balloon.h | 12 
 1 file changed, 12 insertions(+)

diff --git a/include/uapi/linux/virtio_balloon.h 
b/include/uapi/linux/virtio_balloon.h
index 343d7dd..2f850bf 100644
--- a/include/uapi/linux/virtio_balloon.h
+++ b/include/uapi/linux/virtio_balloon.h
@@ -34,10 +34,14 @@
 #define VIRTIO_BALLOON_F_MUST_TELL_HOST0 /* Tell before reclaiming 
pages */
 #define VIRTIO_BALLOON_F_STATS_VQ  1 /* Memory Stats virtqueue */
 #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM2 /* Deflate balloon on OOM */
+#define VIRTIO_BALLOON_F_PAGE_RANGE3 /* Send page info with ranges */
 
 /* Size of a PFN in the balloon interface. */
 #define VIRTIO_BALLOON_PFN_SHIFT 12
 
+/* Bits width for the length of the pfn range */
+#define VIRTIO_BALLOON_NR_PFN_BITS 12
+
 struct virtio_balloon_config {
/* Number of pages host wants Guest to give up. */
__u32 num_pages;
@@ -82,4 +86,12 @@ struct virtio_balloon_stat {
__virtio64 val;
 } __attribute__((packed));
 
+/* Response header structure */
+struct virtio_balloon_resp_hdr {
+   __le64 cmd : 8; /* Distinguish different requests type */
+   __le64 flag: 8; /* Mark status for a specific request type */
+   __le64 id : 16; /* Distinguish requests of a specific type */
+   __le64 data_len: 32; /* Length of the following data, in bytes */
+};
+
 #endif /* _LINUX_VIRTIO_BALLOON_H */
-- 
1.9.1



[PATCH v6 kernel 4/5] virtio-balloon: define flags and head for host request vq

2016-12-20 Thread Liang Li
Define the flags and head struct for a new host request virtual
queue. Guest can get requests from host and then responds to them on
this new virtual queue.
Host can make use of this virtual queue to request the guest do some
operations, e.g. drop page cache, synchronize file system, etc.
And the hypervisor can get some of guest's runtime information
through this virtual queue too, e.g. the guest's unused page
information, which can be used for live migration optimization.

Signed-off-by: Liang Li 
Cc: Andrew Morton 
Cc: Mel Gorman 
Cc: Michael S. Tsirkin 
Cc: Paolo Bonzini 
Cc: Cornelia Huck 
Cc: Amit Shah 
Cc: Dave Hansen 
Cc: Andrea Arcangeli 
Cc: David Hildenbrand 
---
 include/uapi/linux/virtio_balloon.h | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/include/uapi/linux/virtio_balloon.h 
b/include/uapi/linux/virtio_balloon.h
index 2f850bf..b367020 100644
--- a/include/uapi/linux/virtio_balloon.h
+++ b/include/uapi/linux/virtio_balloon.h
@@ -35,6 +35,7 @@
 #define VIRTIO_BALLOON_F_STATS_VQ  1 /* Memory Stats virtqueue */
 #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM2 /* Deflate balloon on OOM */
 #define VIRTIO_BALLOON_F_PAGE_RANGE3 /* Send page info with ranges */
+#define VIRTIO_BALLOON_F_HOST_REQ_VQ   4 /* Host request virtqueue */
 
 /* Size of a PFN in the balloon interface. */
 #define VIRTIO_BALLOON_PFN_SHIFT 12
@@ -94,4 +95,25 @@ struct virtio_balloon_resp_hdr {
__le64 data_len: 32; /* Length of the following data, in bytes */
 };
 
+enum virtio_balloon_req_id {
+   /* Get unused page information */
+   BALLOON_GET_UNUSED_PAGES,
+};
+
+enum virtio_balloon_flag {
+   /* Have more data for a request */
+   BALLOON_FLAG_CONT,
+   /* No more data for a request */
+   BALLOON_FLAG_DONE,
+};
+
+struct virtio_balloon_req_hdr {
+   /* Used to distinguish different requests */
+   __le16 cmd;
+   /* Reserved */
+   __le16 reserved[3];
+   /* Request parameter */
+   __le64 param;
+};
+
 #endif /* _LINUX_VIRTIO_BALLOON_H */
-- 
1.9.1



[PATCH v6 kernel 2/5] virtio-balloon: define new feature bit and head struct

2016-12-20 Thread Liang Li
Add a new feature which supports sending the page information
with range array. The current implementation uses PFNs array,
which is not very efficient. Using ranges can improve the
performance of inflating/deflating significantly.

Signed-off-by: Liang Li 
Cc: Michael S. Tsirkin 
Cc: Paolo Bonzini 
Cc: Cornelia Huck 
Cc: Amit Shah 
Cc: Dave Hansen 
Cc: Andrea Arcangeli 
Cc: David Hildenbrand 
---
 include/uapi/linux/virtio_balloon.h | 12 
 1 file changed, 12 insertions(+)

diff --git a/include/uapi/linux/virtio_balloon.h 
b/include/uapi/linux/virtio_balloon.h
index 343d7dd..2f850bf 100644
--- a/include/uapi/linux/virtio_balloon.h
+++ b/include/uapi/linux/virtio_balloon.h
@@ -34,10 +34,14 @@
 #define VIRTIO_BALLOON_F_MUST_TELL_HOST0 /* Tell before reclaiming 
pages */
 #define VIRTIO_BALLOON_F_STATS_VQ  1 /* Memory Stats virtqueue */
 #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM2 /* Deflate balloon on OOM */
+#define VIRTIO_BALLOON_F_PAGE_RANGE3 /* Send page info with ranges */
 
 /* Size of a PFN in the balloon interface. */
 #define VIRTIO_BALLOON_PFN_SHIFT 12
 
+/* Bits width for the length of the pfn range */
+#define VIRTIO_BALLOON_NR_PFN_BITS 12
+
 struct virtio_balloon_config {
/* Number of pages host wants Guest to give up. */
__u32 num_pages;
@@ -82,4 +86,12 @@ struct virtio_balloon_stat {
__virtio64 val;
 } __attribute__((packed));
 
+/* Response header structure */
+struct virtio_balloon_resp_hdr {
+   __le64 cmd : 8; /* Distinguish different requests type */
+   __le64 flag: 8; /* Mark status for a specific request type */
+   __le64 id : 16; /* Distinguish requests of a specific type */
+   __le64 data_len: 32; /* Length of the following data, in bytes */
+};
+
 #endif /* _LINUX_VIRTIO_BALLOON_H */
-- 
1.9.1



[PATCH v6 kernel 4/5] virtio-balloon: define flags and head for host request vq

2016-12-20 Thread Liang Li
Define the flags and head struct for a new host request virtual
queue. Guest can get requests from host and then responds to them on
this new virtual queue.
Host can make use of this virtual queue to request the guest do some
operations, e.g. drop page cache, synchronize file system, etc.
And the hypervisor can get some of guest's runtime information
through this virtual queue too, e.g. the guest's unused page
information, which can be used for live migration optimization.

Signed-off-by: Liang Li 
Cc: Andrew Morton 
Cc: Mel Gorman 
Cc: Michael S. Tsirkin 
Cc: Paolo Bonzini 
Cc: Cornelia Huck 
Cc: Amit Shah 
Cc: Dave Hansen 
Cc: Andrea Arcangeli 
Cc: David Hildenbrand 
---
 include/uapi/linux/virtio_balloon.h | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/include/uapi/linux/virtio_balloon.h 
b/include/uapi/linux/virtio_balloon.h
index 2f850bf..b367020 100644
--- a/include/uapi/linux/virtio_balloon.h
+++ b/include/uapi/linux/virtio_balloon.h
@@ -35,6 +35,7 @@
 #define VIRTIO_BALLOON_F_STATS_VQ  1 /* Memory Stats virtqueue */
 #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM2 /* Deflate balloon on OOM */
 #define VIRTIO_BALLOON_F_PAGE_RANGE3 /* Send page info with ranges */
+#define VIRTIO_BALLOON_F_HOST_REQ_VQ   4 /* Host request virtqueue */
 
 /* Size of a PFN in the balloon interface. */
 #define VIRTIO_BALLOON_PFN_SHIFT 12
@@ -94,4 +95,25 @@ struct virtio_balloon_resp_hdr {
__le64 data_len: 32; /* Length of the following data, in bytes */
 };
 
+enum virtio_balloon_req_id {
+   /* Get unused page information */
+   BALLOON_GET_UNUSED_PAGES,
+};
+
+enum virtio_balloon_flag {
+   /* Have more data for a request */
+   BALLOON_FLAG_CONT,
+   /* No more data for a request */
+   BALLOON_FLAG_DONE,
+};
+
+struct virtio_balloon_req_hdr {
+   /* Used to distinguish different requests */
+   __le16 cmd;
+   /* Reserved */
+   __le16 reserved[3];
+   /* Request parameter */
+   __le64 param;
+};
+
 #endif /* _LINUX_VIRTIO_BALLOON_H */
-- 
1.9.1



[PATCH v6 kernel 5/5] virtio-balloon: tell host vm's unused page info

2016-12-20 Thread Liang Li
This patch contains two parts:

One is to add a new API to mm go get the unused page information.
The virtio balloon driver will use this new API added to get the
unused page info and send it to hypervisor(QEMU) to speed up live
migration. During sending the bitmap, some the pages may be modified
and are used by the guest, this inaccuracy can be corrected by the
dirty page logging mechanism.

One is to add support the request for vm's unused page information,
QEMU can make use of unused page information and the dirty page
logging mechanism to skip the transportation of some of these unused
pages, this is very helpful to reduce the network traffic and speed
up the live migration process.

Signed-off-by: Liang Li 
Cc: Andrew Morton 
Cc: Mel Gorman 
Cc: Michael S. Tsirkin 
Cc: Paolo Bonzini 
Cc: Cornelia Huck 
Cc: Amit Shah 
Cc: Dave Hansen 
Cc: Andrea Arcangeli 
Cc: David Hildenbrand 
---
 drivers/virtio/virtio_balloon.c | 144 ++--
 include/linux/mm.h  |   3 +
 mm/page_alloc.c | 120 +
 3 files changed, 261 insertions(+), 6 deletions(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 03383b3..b67f865 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -56,7 +56,7 @@
 
 struct virtio_balloon {
struct virtio_device *vdev;
-   struct virtqueue *inflate_vq, *deflate_vq, *stats_vq;
+   struct virtqueue *inflate_vq, *deflate_vq, *stats_vq, *req_vq;
 
/* The balloon servicing is delegated to a freezable workqueue. */
struct work_struct update_balloon_stats_work;
@@ -85,6 +85,8 @@ struct virtio_balloon {
unsigned int nr_page_bmap;
/* Used to record the processed pfn range */
unsigned long min_pfn, max_pfn, start_pfn, end_pfn;
+   /* Request header */
+   struct virtio_balloon_req_hdr req_hdr;
/*
 * The pages we've told the Host we're not using are enqueued
 * at vb_dev_info->pages list.
@@ -505,6 +507,80 @@ static void update_balloon_stats(struct virtio_balloon *vb)
pages_to_bytes(available));
 }
 
+static void __send_unused_pages(struct virtio_balloon *vb,
+   unsigned long req_id, unsigned int pos, bool done)
+{
+   struct virtio_balloon_resp_hdr *hdr = vb->resp_hdr;
+   struct virtqueue *vq = vb->req_vq;
+
+   vb->resp_pos = pos;
+   hdr->cmd = BALLOON_GET_UNUSED_PAGES;
+   hdr->id = req_id;
+   if (!done)
+   hdr->flag = BALLOON_FLAG_CONT;
+   else
+   hdr->flag = BALLOON_FLAG_DONE;
+
+   if (pos > 0 || done)
+   send_resp_data(vb, vq, true);
+
+}
+
+static void send_unused_pages(struct virtio_balloon *vb,
+   unsigned long req_id)
+{
+   struct scatterlist sg_in;
+   unsigned int pos = 0;
+   struct virtqueue *vq = vb->req_vq;
+   int ret, order;
+   struct zone *zone = NULL;
+   bool part_fill = false;
+
+   mutex_lock(>balloon_lock);
+
+   for (order = MAX_ORDER - 1; order >= 0; order--) {
+   ret = mark_unused_pages(, order, vb->resp_data,
+vb->resp_buf_size / sizeof(__le64),
+, VIRTIO_BALLOON_NR_PFN_BITS, part_fill);
+   if (ret == -ENOSPC) {
+   if (pos == 0) {
+   void *new_resp_data;
+
+   new_resp_data = kmalloc(2 * vb->resp_buf_size,
+   GFP_KERNEL);
+   if (new_resp_data) {
+   kfree(vb->resp_data);
+   vb->resp_data = new_resp_data;
+   vb->resp_buf_size *= 2;
+   } else {
+   part_fill = true;
+   dev_warn(>vdev->dev,
+"%s: part fill order: %d\n",
+__func__, order);
+   }
+   } else {
+   __send_unused_pages(vb, req_id, pos, false);
+   pos = 0;
+   }
+
+   if (!part_fill) {
+   order++;
+   continue;
+   }
+   } else
+   zone = NULL;
+
+   if (order == 0)
+   __send_unused_pages(vb, req_id, pos, true);
+
+   }
+
+   mutex_unlock(>balloon_lock);
+   

[PATCH v6 kernel 5/5] virtio-balloon: tell host vm's unused page info

2016-12-20 Thread Liang Li
This patch contains two parts:

One is to add a new API to mm go get the unused page information.
The virtio balloon driver will use this new API added to get the
unused page info and send it to hypervisor(QEMU) to speed up live
migration. During sending the bitmap, some the pages may be modified
and are used by the guest, this inaccuracy can be corrected by the
dirty page logging mechanism.

One is to add support the request for vm's unused page information,
QEMU can make use of unused page information and the dirty page
logging mechanism to skip the transportation of some of these unused
pages, this is very helpful to reduce the network traffic and speed
up the live migration process.

Signed-off-by: Liang Li 
Cc: Andrew Morton 
Cc: Mel Gorman 
Cc: Michael S. Tsirkin 
Cc: Paolo Bonzini 
Cc: Cornelia Huck 
Cc: Amit Shah 
Cc: Dave Hansen 
Cc: Andrea Arcangeli 
Cc: David Hildenbrand 
---
 drivers/virtio/virtio_balloon.c | 144 ++--
 include/linux/mm.h  |   3 +
 mm/page_alloc.c | 120 +
 3 files changed, 261 insertions(+), 6 deletions(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 03383b3..b67f865 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -56,7 +56,7 @@
 
 struct virtio_balloon {
struct virtio_device *vdev;
-   struct virtqueue *inflate_vq, *deflate_vq, *stats_vq;
+   struct virtqueue *inflate_vq, *deflate_vq, *stats_vq, *req_vq;
 
/* The balloon servicing is delegated to a freezable workqueue. */
struct work_struct update_balloon_stats_work;
@@ -85,6 +85,8 @@ struct virtio_balloon {
unsigned int nr_page_bmap;
/* Used to record the processed pfn range */
unsigned long min_pfn, max_pfn, start_pfn, end_pfn;
+   /* Request header */
+   struct virtio_balloon_req_hdr req_hdr;
/*
 * The pages we've told the Host we're not using are enqueued
 * at vb_dev_info->pages list.
@@ -505,6 +507,80 @@ static void update_balloon_stats(struct virtio_balloon *vb)
pages_to_bytes(available));
 }
 
+static void __send_unused_pages(struct virtio_balloon *vb,
+   unsigned long req_id, unsigned int pos, bool done)
+{
+   struct virtio_balloon_resp_hdr *hdr = vb->resp_hdr;
+   struct virtqueue *vq = vb->req_vq;
+
+   vb->resp_pos = pos;
+   hdr->cmd = BALLOON_GET_UNUSED_PAGES;
+   hdr->id = req_id;
+   if (!done)
+   hdr->flag = BALLOON_FLAG_CONT;
+   else
+   hdr->flag = BALLOON_FLAG_DONE;
+
+   if (pos > 0 || done)
+   send_resp_data(vb, vq, true);
+
+}
+
+static void send_unused_pages(struct virtio_balloon *vb,
+   unsigned long req_id)
+{
+   struct scatterlist sg_in;
+   unsigned int pos = 0;
+   struct virtqueue *vq = vb->req_vq;
+   int ret, order;
+   struct zone *zone = NULL;
+   bool part_fill = false;
+
+   mutex_lock(>balloon_lock);
+
+   for (order = MAX_ORDER - 1; order >= 0; order--) {
+   ret = mark_unused_pages(, order, vb->resp_data,
+vb->resp_buf_size / sizeof(__le64),
+, VIRTIO_BALLOON_NR_PFN_BITS, part_fill);
+   if (ret == -ENOSPC) {
+   if (pos == 0) {
+   void *new_resp_data;
+
+   new_resp_data = kmalloc(2 * vb->resp_buf_size,
+   GFP_KERNEL);
+   if (new_resp_data) {
+   kfree(vb->resp_data);
+   vb->resp_data = new_resp_data;
+   vb->resp_buf_size *= 2;
+   } else {
+   part_fill = true;
+   dev_warn(>vdev->dev,
+"%s: part fill order: %d\n",
+__func__, order);
+   }
+   } else {
+   __send_unused_pages(vb, req_id, pos, false);
+   pos = 0;
+   }
+
+   if (!part_fill) {
+   order++;
+   continue;
+   }
+   } else
+   zone = NULL;
+
+   if (order == 0)
+   __send_unused_pages(vb, req_id, pos, true);
+
+   }
+
+   mutex_unlock(>balloon_lock);
+   sg_init_one(_in, >req_hdr, sizeof(vb->req_hdr));
+   virtqueue_add_inbuf(vq, _in, 1, >req_hdr, GFP_KERNEL);
+   virtqueue_kick(vq);
+}
+
 /*
  * While most virtqueues communicate guest-initiated requests to the 

[PATCH v6 kernel 1/5] virtio-balloon: rework deflate to add page to a list

2016-12-20 Thread Liang Li
When doing the inflating/deflating operation, the current virtio-balloon
implementation uses an array to save 256 PFNS, then send these PFNS to
host through virtio and process each PFN one by one. This way is not
efficient when inflating/deflating a large mount of memory because too
many times of the following operations:

1. Virtio data transmission
2. Page allocate/free
3. Address translation(GPA->HVA)
4. madvise

The over head of these operations will consume a lot of CPU cycles and
will take a long time to complete, it may impact the QoS of the guest as
well as the host. The overhead will be reduced a lot if batch processing
is used. E.g. If there are several pages whose address are physical
contiguous in the guest, these bulk pages can be processed in one
operation.

The main idea for the optimization is to reduce the above operations as
much as possible. And it can be achieved by using a {pfn|length} array
instead of a PFN array. Comparing with PFN array, {pfn|length} array can
present more pages and is fit for batch processing.

This patch saves the deflated pages to a list instead of the PFN array,
which will allow faster notifications using the {pfn|length} down the
road. balloon_pfn_to_page() can be removed because it's useless.

Signed-off-by: Liang Li 
Signed-off-by: Michael S. Tsirkin 
Cc: Paolo Bonzini 
Cc: Cornelia Huck 
Cc: Amit Shah 
Cc: Dave Hansen 
Cc: Andrea Arcangeli 
Cc: David Hildenbrand 
---
 drivers/virtio/virtio_balloon.c | 22 --
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 181793f..f59cb4f 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -103,12 +103,6 @@ static u32 page_to_balloon_pfn(struct page *page)
return pfn * VIRTIO_BALLOON_PAGES_PER_PAGE;
 }
 
-static struct page *balloon_pfn_to_page(u32 pfn)
-{
-   BUG_ON(pfn % VIRTIO_BALLOON_PAGES_PER_PAGE);
-   return pfn_to_page(pfn / VIRTIO_BALLOON_PAGES_PER_PAGE);
-}
-
 static void balloon_ack(struct virtqueue *vq)
 {
struct virtio_balloon *vb = vq->vdev->priv;
@@ -181,18 +175,16 @@ static unsigned fill_balloon(struct virtio_balloon *vb, 
size_t num)
return num_allocated_pages;
 }
 
-static void release_pages_balloon(struct virtio_balloon *vb)
+static void release_pages_balloon(struct virtio_balloon *vb,
+struct list_head *pages)
 {
-   unsigned int i;
-   struct page *page;
+   struct page *page, *next;
 
-   /* Find pfns pointing at start of each page, get pages and free them. */
-   for (i = 0; i < vb->num_pfns; i += VIRTIO_BALLOON_PAGES_PER_PAGE) {
-   page = balloon_pfn_to_page(virtio32_to_cpu(vb->vdev,
-  vb->pfns[i]));
+   list_for_each_entry_safe(page, next, pages, lru) {
if (!virtio_has_feature(vb->vdev,
VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
adjust_managed_page_count(page, 1);
+   list_del(>lru);
put_page(page); /* balloon reference */
}
 }
@@ -202,6 +194,7 @@ static unsigned leak_balloon(struct virtio_balloon *vb, 
size_t num)
unsigned num_freed_pages;
struct page *page;
struct balloon_dev_info *vb_dev_info = >vb_dev_info;
+   LIST_HEAD(pages);
 
/* We can only do one array worth at a time. */
num = min(num, ARRAY_SIZE(vb->pfns));
@@ -215,6 +208,7 @@ static unsigned leak_balloon(struct virtio_balloon *vb, 
size_t num)
if (!page)
break;
set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
+   list_add(>lru, );
vb->num_pages -= VIRTIO_BALLOON_PAGES_PER_PAGE;
}
 
@@ -226,7 +220,7 @@ static unsigned leak_balloon(struct virtio_balloon *vb, 
size_t num)
 */
if (vb->num_pfns != 0)
tell_host(vb, vb->deflate_vq);
-   release_pages_balloon(vb);
+   release_pages_balloon(vb, );
mutex_unlock(>balloon_lock);
return num_freed_pages;
 }
-- 
1.9.1



[PATCH v6 kernel 1/5] virtio-balloon: rework deflate to add page to a list

2016-12-20 Thread Liang Li
When doing the inflating/deflating operation, the current virtio-balloon
implementation uses an array to save 256 PFNS, then send these PFNS to
host through virtio and process each PFN one by one. This way is not
efficient when inflating/deflating a large mount of memory because too
many times of the following operations:

1. Virtio data transmission
2. Page allocate/free
3. Address translation(GPA->HVA)
4. madvise

The over head of these operations will consume a lot of CPU cycles and
will take a long time to complete, it may impact the QoS of the guest as
well as the host. The overhead will be reduced a lot if batch processing
is used. E.g. If there are several pages whose address are physical
contiguous in the guest, these bulk pages can be processed in one
operation.

The main idea for the optimization is to reduce the above operations as
much as possible. And it can be achieved by using a {pfn|length} array
instead of a PFN array. Comparing with PFN array, {pfn|length} array can
present more pages and is fit for batch processing.

This patch saves the deflated pages to a list instead of the PFN array,
which will allow faster notifications using the {pfn|length} down the
road. balloon_pfn_to_page() can be removed because it's useless.

Signed-off-by: Liang Li 
Signed-off-by: Michael S. Tsirkin 
Cc: Paolo Bonzini 
Cc: Cornelia Huck 
Cc: Amit Shah 
Cc: Dave Hansen 
Cc: Andrea Arcangeli 
Cc: David Hildenbrand 
---
 drivers/virtio/virtio_balloon.c | 22 --
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 181793f..f59cb4f 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -103,12 +103,6 @@ static u32 page_to_balloon_pfn(struct page *page)
return pfn * VIRTIO_BALLOON_PAGES_PER_PAGE;
 }
 
-static struct page *balloon_pfn_to_page(u32 pfn)
-{
-   BUG_ON(pfn % VIRTIO_BALLOON_PAGES_PER_PAGE);
-   return pfn_to_page(pfn / VIRTIO_BALLOON_PAGES_PER_PAGE);
-}
-
 static void balloon_ack(struct virtqueue *vq)
 {
struct virtio_balloon *vb = vq->vdev->priv;
@@ -181,18 +175,16 @@ static unsigned fill_balloon(struct virtio_balloon *vb, 
size_t num)
return num_allocated_pages;
 }
 
-static void release_pages_balloon(struct virtio_balloon *vb)
+static void release_pages_balloon(struct virtio_balloon *vb,
+struct list_head *pages)
 {
-   unsigned int i;
-   struct page *page;
+   struct page *page, *next;
 
-   /* Find pfns pointing at start of each page, get pages and free them. */
-   for (i = 0; i < vb->num_pfns; i += VIRTIO_BALLOON_PAGES_PER_PAGE) {
-   page = balloon_pfn_to_page(virtio32_to_cpu(vb->vdev,
-  vb->pfns[i]));
+   list_for_each_entry_safe(page, next, pages, lru) {
if (!virtio_has_feature(vb->vdev,
VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
adjust_managed_page_count(page, 1);
+   list_del(>lru);
put_page(page); /* balloon reference */
}
 }
@@ -202,6 +194,7 @@ static unsigned leak_balloon(struct virtio_balloon *vb, 
size_t num)
unsigned num_freed_pages;
struct page *page;
struct balloon_dev_info *vb_dev_info = >vb_dev_info;
+   LIST_HEAD(pages);
 
/* We can only do one array worth at a time. */
num = min(num, ARRAY_SIZE(vb->pfns));
@@ -215,6 +208,7 @@ static unsigned leak_balloon(struct virtio_balloon *vb, 
size_t num)
if (!page)
break;
set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
+   list_add(>lru, );
vb->num_pages -= VIRTIO_BALLOON_PAGES_PER_PAGE;
}
 
@@ -226,7 +220,7 @@ static unsigned leak_balloon(struct virtio_balloon *vb, 
size_t num)
 */
if (vb->num_pfns != 0)
tell_host(vb, vb->deflate_vq);
-   release_pages_balloon(vb);
+   release_pages_balloon(vb, );
mutex_unlock(>balloon_lock);
return num_freed_pages;
 }
-- 
1.9.1



[PATCH v6 kernel 3/5] virtio-balloon: speed up inflate/deflate process

2016-12-20 Thread Liang Li
The implementation of the current virtio-balloon is not very
efficient, the time spends on different stages of inflating
the balloon to 7GB of a 8GB idle guest:

a. allocating pages (6.5%)
b. sending PFNs to host (68.3%)
c. address translation (6.1%)
d. madvise (19%)

It takes about 4126ms for the inflating process to complete.
Debugging shows that the bottle neck are the stage b and stage d.

If using {pfn|length} array to send the page info instead of the
PFNs, we can reduce the overhead in stage b quite a lot.
Furthermore, we can do the address translation and call madvise()
with a range of memory, instead of the current page per page way,
the overhead of stage c and stage d can also be reduced a lot.

This patch is the kernel side implementation which is intended to
speed up the inflating & deflating process by adding a new feature
to the virtio-balloon device. With this new feature, inflating the
balloon to 7GB of a 8GB idle guest only takes 590ms, the
performance improvement is about 85%.

TODO: optimize stage a by allocating/freeing a chunk of pages
instead of a single page at a time.

Signed-off-by: Liang Li 
Suggested-by: Michael S. Tsirkin 
Cc: Michael S. Tsirkin 
Cc: Paolo Bonzini 
Cc: Cornelia Huck 
Cc: Amit Shah 
Cc: Dave Hansen 
Cc: Andrea Arcangeli 
Cc: David Hildenbrand 
---
 drivers/virtio/virtio_balloon.c | 348 
 1 file changed, 320 insertions(+), 28 deletions(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index f59cb4f..03383b3 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -42,6 +42,10 @@
 #define OOM_VBALLOON_DEFAULT_PAGES 256
 #define VIRTBALLOON_OOM_NOTIFY_PRIORITY 80
 
+#define BALLOON_BMAP_SIZE  (8 * PAGE_SIZE)
+#define PFNS_PER_BMAP  (BALLOON_BMAP_SIZE * BITS_PER_BYTE)
+#define BALLOON_BMAP_COUNT 32
+
 static int oom_pages = OOM_VBALLOON_DEFAULT_PAGES;
 module_param(oom_pages, int, S_IRUSR | S_IWUSR);
 MODULE_PARM_DESC(oom_pages, "pages to free on OOM");
@@ -67,6 +71,20 @@ struct virtio_balloon {
 
/* Number of balloon pages we've told the Host we're not using. */
unsigned int num_pages;
+   /* Pointer to the response header. */
+   void *resp_hdr;
+   /* Pointer to the start address of response data. */
+   __le64 *resp_data;
+   /* Size of response data buffer. */
+   unsigned int resp_buf_size;
+   /* Pointer offset of the response data. */
+   unsigned int resp_pos;
+   /* Bitmap used to save the pfns info */
+   unsigned long *page_bitmap[BALLOON_BMAP_COUNT];
+   /* Number of split page bitmaps */
+   unsigned int nr_page_bmap;
+   /* Used to record the processed pfn range */
+   unsigned long min_pfn, max_pfn, start_pfn, end_pfn;
/*
 * The pages we've told the Host we're not using are enqueued
 * at vb_dev_info->pages list.
@@ -110,20 +128,180 @@ static void balloon_ack(struct virtqueue *vq)
wake_up(>acked);
 }
 
-static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq)
+static inline void init_bmap_pfn_range(struct virtio_balloon *vb)
 {
-   struct scatterlist sg;
+   vb->min_pfn = ULONG_MAX;
+   vb->max_pfn = 0;
+}
+
+static inline void update_bmap_pfn_range(struct virtio_balloon *vb,
+struct page *page)
+{
+   unsigned long balloon_pfn = page_to_balloon_pfn(page);
+
+   vb->min_pfn = min(balloon_pfn, vb->min_pfn);
+   vb->max_pfn = max(balloon_pfn, vb->max_pfn);
+}
+
+static void extend_page_bitmap(struct virtio_balloon *vb,
+   unsigned long nr_pfn)
+{
+   int i, bmap_count;
+   unsigned long bmap_len;
+
+   bmap_len = ALIGN(nr_pfn, BITS_PER_LONG) / BITS_PER_BYTE;
+   bmap_len = ALIGN(bmap_len, BALLOON_BMAP_SIZE);
+   bmap_count = min((int)(bmap_len / BALLOON_BMAP_SIZE),
+BALLOON_BMAP_COUNT);
+
+   for (i = 1; i < bmap_count; i++) {
+   vb->page_bitmap[i] = kmalloc(BALLOON_BMAP_SIZE, GFP_KERNEL);
+   if (vb->page_bitmap[i])
+   vb->nr_page_bmap++;
+   else
+   break;
+   }
+}
+
+static void free_extended_page_bitmap(struct virtio_balloon *vb)
+{
+   int i, bmap_count = vb->nr_page_bmap;
+
+   for (i = 1; i < bmap_count; i++) {
+   kfree(vb->page_bitmap[i]);
+   vb->page_bitmap[i] = NULL;
+   vb->nr_page_bmap--;
+   }
+}
+
+static void kfree_page_bitmap(struct virtio_balloon *vb)
+{
+   int i;
+
+   for (i = 0; i < vb->nr_page_bmap; i++)
+   kfree(vb->page_bitmap[i]);
+}
+
+static void clear_page_bitmap(struct virtio_balloon *vb)
+{
+   int i;
+
+   for 

[PATCH v6 kernel 0/5] Extend virtio-balloon for fast (de)inflating & fast live migration

2016-12-20 Thread Liang Li
This patch set contains two parts of changes to the virtio-balloon.
 
One is the change for speeding up the inflating & deflating process,
the main idea of this optimization is to use {pfn|length} to present
the page information instead of the PFNs, to reduce the overhead of
virtio data transmission, address translation and madvise(). This can
help to improve the performance by about 85%.
 
Another change is for speeding up live migration. By skipping process
guest's unused pages in the first round of data copy, to reduce needless
data processing, this can help to save quite a lot of CPU cycles and
network bandwidth. We put guest's unused page information in a
{pfn|length} array and send it to host with the virt queue of
virtio-balloon. For an idle guest with 8GB RAM, this can help to shorten
the total live migration time from 2Sec to about 500ms in 10Gbps network
environment. For an guest with quite a lot of page cache and with little
unused pages, it's possible to let the guest drop it's page cache before
live migration, this case can benefit from this new feature too.
 
Changes from v5 to v6:
* Drop the bitmap from the virtio ABI, use {pfn|length} only.
* Enhance the API to get the unused page information from mm. 

Changes from v4 to v5:
* Drop the code to get the max_pfn, use another way instead.
* Simplify the API to get the unused page information from mm. 

Changes from v3 to v4:
* Use the new scheme suggested by Dave Hansen to encode the bitmap.
* Add code which is missed in v3 to handle migrate page. 
* Free the memory for bitmap intime once the operation is done.
* Address some of the comments in v3.

Changes from v2 to v3:
* Change the name of 'free page' to 'unused page'.
* Use the scatter & gather bitmap instead of a 1MB page bitmap.
* Fix overwriting the page bitmap after kicking.
* Some of MST's comments for v2.
 
Changes from v1 to v2:
* Abandon the patch for dropping page cache.
* Put some structures to uapi head file.
* Use a new way to determine the page bitmap size.
* Use a unified way to send the free page information with the bitmap
* Address the issues referred in MST's comments

Liang Li (5):
  virtio-balloon: rework deflate to add page to a list
  virtio-balloon: define new feature bit and head struct
  virtio-balloon: speed up inflate/deflate process
  virtio-balloon: define flags and head for host request vq
  virtio-balloon: tell host vm's unused page info

 drivers/virtio/virtio_balloon.c | 510 
 include/linux/mm.h  |   3 +
 include/uapi/linux/virtio_balloon.h |  34 +++
 mm/page_alloc.c | 120 +
 4 files changed, 621 insertions(+), 46 deletions(-)

-- 
1.9.1



[PATCH v6 kernel 3/5] virtio-balloon: speed up inflate/deflate process

2016-12-20 Thread Liang Li
The implementation of the current virtio-balloon is not very
efficient, the time spends on different stages of inflating
the balloon to 7GB of a 8GB idle guest:

a. allocating pages (6.5%)
b. sending PFNs to host (68.3%)
c. address translation (6.1%)
d. madvise (19%)

It takes about 4126ms for the inflating process to complete.
Debugging shows that the bottle neck are the stage b and stage d.

If using {pfn|length} array to send the page info instead of the
PFNs, we can reduce the overhead in stage b quite a lot.
Furthermore, we can do the address translation and call madvise()
with a range of memory, instead of the current page per page way,
the overhead of stage c and stage d can also be reduced a lot.

This patch is the kernel side implementation which is intended to
speed up the inflating & deflating process by adding a new feature
to the virtio-balloon device. With this new feature, inflating the
balloon to 7GB of a 8GB idle guest only takes 590ms, the
performance improvement is about 85%.

TODO: optimize stage a by allocating/freeing a chunk of pages
instead of a single page at a time.

Signed-off-by: Liang Li 
Suggested-by: Michael S. Tsirkin 
Cc: Michael S. Tsirkin 
Cc: Paolo Bonzini 
Cc: Cornelia Huck 
Cc: Amit Shah 
Cc: Dave Hansen 
Cc: Andrea Arcangeli 
Cc: David Hildenbrand 
---
 drivers/virtio/virtio_balloon.c | 348 
 1 file changed, 320 insertions(+), 28 deletions(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index f59cb4f..03383b3 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -42,6 +42,10 @@
 #define OOM_VBALLOON_DEFAULT_PAGES 256
 #define VIRTBALLOON_OOM_NOTIFY_PRIORITY 80
 
+#define BALLOON_BMAP_SIZE  (8 * PAGE_SIZE)
+#define PFNS_PER_BMAP  (BALLOON_BMAP_SIZE * BITS_PER_BYTE)
+#define BALLOON_BMAP_COUNT 32
+
 static int oom_pages = OOM_VBALLOON_DEFAULT_PAGES;
 module_param(oom_pages, int, S_IRUSR | S_IWUSR);
 MODULE_PARM_DESC(oom_pages, "pages to free on OOM");
@@ -67,6 +71,20 @@ struct virtio_balloon {
 
/* Number of balloon pages we've told the Host we're not using. */
unsigned int num_pages;
+   /* Pointer to the response header. */
+   void *resp_hdr;
+   /* Pointer to the start address of response data. */
+   __le64 *resp_data;
+   /* Size of response data buffer. */
+   unsigned int resp_buf_size;
+   /* Pointer offset of the response data. */
+   unsigned int resp_pos;
+   /* Bitmap used to save the pfns info */
+   unsigned long *page_bitmap[BALLOON_BMAP_COUNT];
+   /* Number of split page bitmaps */
+   unsigned int nr_page_bmap;
+   /* Used to record the processed pfn range */
+   unsigned long min_pfn, max_pfn, start_pfn, end_pfn;
/*
 * The pages we've told the Host we're not using are enqueued
 * at vb_dev_info->pages list.
@@ -110,20 +128,180 @@ static void balloon_ack(struct virtqueue *vq)
wake_up(>acked);
 }
 
-static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq)
+static inline void init_bmap_pfn_range(struct virtio_balloon *vb)
 {
-   struct scatterlist sg;
+   vb->min_pfn = ULONG_MAX;
+   vb->max_pfn = 0;
+}
+
+static inline void update_bmap_pfn_range(struct virtio_balloon *vb,
+struct page *page)
+{
+   unsigned long balloon_pfn = page_to_balloon_pfn(page);
+
+   vb->min_pfn = min(balloon_pfn, vb->min_pfn);
+   vb->max_pfn = max(balloon_pfn, vb->max_pfn);
+}
+
+static void extend_page_bitmap(struct virtio_balloon *vb,
+   unsigned long nr_pfn)
+{
+   int i, bmap_count;
+   unsigned long bmap_len;
+
+   bmap_len = ALIGN(nr_pfn, BITS_PER_LONG) / BITS_PER_BYTE;
+   bmap_len = ALIGN(bmap_len, BALLOON_BMAP_SIZE);
+   bmap_count = min((int)(bmap_len / BALLOON_BMAP_SIZE),
+BALLOON_BMAP_COUNT);
+
+   for (i = 1; i < bmap_count; i++) {
+   vb->page_bitmap[i] = kmalloc(BALLOON_BMAP_SIZE, GFP_KERNEL);
+   if (vb->page_bitmap[i])
+   vb->nr_page_bmap++;
+   else
+   break;
+   }
+}
+
+static void free_extended_page_bitmap(struct virtio_balloon *vb)
+{
+   int i, bmap_count = vb->nr_page_bmap;
+
+   for (i = 1; i < bmap_count; i++) {
+   kfree(vb->page_bitmap[i]);
+   vb->page_bitmap[i] = NULL;
+   vb->nr_page_bmap--;
+   }
+}
+
+static void kfree_page_bitmap(struct virtio_balloon *vb)
+{
+   int i;
+
+   for (i = 0; i < vb->nr_page_bmap; i++)
+   kfree(vb->page_bitmap[i]);
+}
+
+static void clear_page_bitmap(struct virtio_balloon *vb)
+{
+   int i;
+
+   for (i = 0; i < vb->nr_page_bmap; i++)
+   memset(vb->page_bitmap[i], 0, BALLOON_BMAP_SIZE);
+}
+
+static void send_resp_data(struct virtio_balloon *vb, struct virtqueue *vq,
+   

[PATCH v6 kernel 0/5] Extend virtio-balloon for fast (de)inflating & fast live migration

2016-12-20 Thread Liang Li
This patch set contains two parts of changes to the virtio-balloon.
 
One is the change for speeding up the inflating & deflating process,
the main idea of this optimization is to use {pfn|length} to present
the page information instead of the PFNs, to reduce the overhead of
virtio data transmission, address translation and madvise(). This can
help to improve the performance by about 85%.
 
Another change is for speeding up live migration. By skipping process
guest's unused pages in the first round of data copy, to reduce needless
data processing, this can help to save quite a lot of CPU cycles and
network bandwidth. We put guest's unused page information in a
{pfn|length} array and send it to host with the virt queue of
virtio-balloon. For an idle guest with 8GB RAM, this can help to shorten
the total live migration time from 2Sec to about 500ms in 10Gbps network
environment. For an guest with quite a lot of page cache and with little
unused pages, it's possible to let the guest drop it's page cache before
live migration, this case can benefit from this new feature too.
 
Changes from v5 to v6:
* Drop the bitmap from the virtio ABI, use {pfn|length} only.
* Enhance the API to get the unused page information from mm. 

Changes from v4 to v5:
* Drop the code to get the max_pfn, use another way instead.
* Simplify the API to get the unused page information from mm. 

Changes from v3 to v4:
* Use the new scheme suggested by Dave Hansen to encode the bitmap.
* Add code which is missed in v3 to handle migrate page. 
* Free the memory for bitmap intime once the operation is done.
* Address some of the comments in v3.

Changes from v2 to v3:
* Change the name of 'free page' to 'unused page'.
* Use the scatter & gather bitmap instead of a 1MB page bitmap.
* Fix overwriting the page bitmap after kicking.
* Some of MST's comments for v2.
 
Changes from v1 to v2:
* Abandon the patch for dropping page cache.
* Put some structures to uapi head file.
* Use a new way to determine the page bitmap size.
* Use a unified way to send the free page information with the bitmap
* Address the issues referred in MST's comments

Liang Li (5):
  virtio-balloon: rework deflate to add page to a list
  virtio-balloon: define new feature bit and head struct
  virtio-balloon: speed up inflate/deflate process
  virtio-balloon: define flags and head for host request vq
  virtio-balloon: tell host vm's unused page info

 drivers/virtio/virtio_balloon.c | 510 
 include/linux/mm.h  |   3 +
 include/uapi/linux/virtio_balloon.h |  34 +++
 mm/page_alloc.c | 120 +
 4 files changed, 621 insertions(+), 46 deletions(-)

-- 
1.9.1



Re: [PATCH 2/2] usb: host: xhci: Handle the right timeout command

2016-12-20 Thread Lu Baolu
Hi Mathias,

I have some comments for the implementation of
xhci_handle_command_timeout() as well.

On 12/20/2016 11:13 PM, Mathias Nyman wrote:
> On 20.12.2016 09:30, Baolin Wang wrote:
> ...
>
> Alright, I gathered all current work related to xhci races and timeouts
> and put them into a branch:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/mnyman/xhci.git 
> timeout_race_fixes
>
> Its based on 4.9
> It includes a few other patches just to avoid conflicts and  make my life 
> easier
>
> Interesting patches are:
>
> ee4eb91 xhci: remove unnecessary check for pending timer
> 0cba67d xhci: detect stop endpoint race using pending timer instead of 
> counter.
> 4f2535f xhci: Handle command completion and timeout race
> b9d00d7 usb: host: xhci: Fix possible wild pointer when handling abort command
> 529a5a0 usb: xhci: fix possible wild pointer
> 4766555 xhci: Fix race related to abort operation
> de834a3 xhci: Use delayed_work instead of timer for command timeout
> 69973b8 Linux 4.9
>
> The fixes for command queue races will go to usb-linus and stable, the
> reworks for stop ep watchdog timer will go to usb-next.
>
> Still completely untested, (well it compiles)
>
> Felipe gave instructions how to modify dwc3 driver to timeout on address
> devicecommands to test these, I'll try to set that up.
>
> All additional testing is welcome, especially if you can trigger timeouts
> and races
>
> -Mathias
>
>

I post the code below and add my comments in line.

1276 void xhci_handle_command_timeout(struct work_struct *work)
1277 {
1278 struct xhci_hcd *xhci;
1279 int ret;
1280 unsigned long flags;
1281 u64 hw_ring_state;
1282
1283 xhci = container_of(to_delayed_work(work), struct xhci_hcd, 
cmd_timer);
1284
1285 spin_lock_irqsave(>lock, flags);
1286
1287 /*
1288  * If timeout work is pending, or current_cmd is NULL, it means we
1289  * raced with command completion. Command is handled so just 
return.
1290  */
1291 if (!xhci->current_cmd || delayed_work_pending(>cmd_timer)) {
1292 spin_unlock_irqrestore(>lock, flags);
1293 return;
1294 }
1295 /* mark this command to be cancelled */
1296 xhci->current_cmd->status = COMP_CMD_ABORT;
1297
1298 /* Make sure command ring is running before aborting it */
1299 hw_ring_state = xhci_read_64(xhci, >op_regs->cmd_ring);
1300 if ((xhci->cmd_ring_state & CMD_RING_STATE_RUNNING) &&
1301 (hw_ring_state & CMD_RING_RUNNING))  {
1302 /* Prevent new doorbell, and start command abort */
1303 xhci->cmd_ring_state = CMD_RING_STATE_ABORTED;
1304 spin_unlock_irqrestore(>lock, flags);
1305 xhci_dbg(xhci, "Command timeout\n");
1306 ret = xhci_abort_cmd_ring(xhci);
1307 if (unlikely(ret == -ESHUTDOWN)) {
1308 xhci_err(xhci, "Abort command ring failed\n");
1309 xhci_cleanup_command_queue(xhci);
1310 usb_hc_died(xhci_to_hcd(xhci)->primary_hcd);
1311 xhci_dbg(xhci, "xHCI host controller is dead.\n");
1312 }
1313 return;
1314 }
1315
1316 /* host removed. Bail out */
1317 if (xhci->xhc_state & XHCI_STATE_REMOVING) {
1318 spin_unlock_irqrestore(>lock, flags);
1319 xhci_dbg(xhci, "host removed, ring start fail?\n");
1320 xhci_cleanup_command_queue(xhci);
1321 return;
1322 }

I think this part of code should be moved up to line 1295.

1323
1324 /* command timeout on stopped ring, ring can't be aborted */
1325 xhci_dbg(xhci, "Command timeout on stopped ring\n");
1326 xhci_handle_stopped_cmd_ring(xhci, xhci->current_cmd);
1327 spin_unlock_irqrestore(>lock, flags);

This part of code is tricky. I have no idea about in which case should this
code be executed? Anyway, we shouldn't call xhci_handle_stopped_cmd_ring()
here, right?

1328 return;
1329 }

Best regards,
Lu Baolu


Re: [PATCH 2/2] usb: host: xhci: Handle the right timeout command

2016-12-20 Thread Lu Baolu
Hi Mathias,

I have some comments for the implementation of
xhci_handle_command_timeout() as well.

On 12/20/2016 11:13 PM, Mathias Nyman wrote:
> On 20.12.2016 09:30, Baolin Wang wrote:
> ...
>
> Alright, I gathered all current work related to xhci races and timeouts
> and put them into a branch:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/mnyman/xhci.git 
> timeout_race_fixes
>
> Its based on 4.9
> It includes a few other patches just to avoid conflicts and  make my life 
> easier
>
> Interesting patches are:
>
> ee4eb91 xhci: remove unnecessary check for pending timer
> 0cba67d xhci: detect stop endpoint race using pending timer instead of 
> counter.
> 4f2535f xhci: Handle command completion and timeout race
> b9d00d7 usb: host: xhci: Fix possible wild pointer when handling abort command
> 529a5a0 usb: xhci: fix possible wild pointer
> 4766555 xhci: Fix race related to abort operation
> de834a3 xhci: Use delayed_work instead of timer for command timeout
> 69973b8 Linux 4.9
>
> The fixes for command queue races will go to usb-linus and stable, the
> reworks for stop ep watchdog timer will go to usb-next.
>
> Still completely untested, (well it compiles)
>
> Felipe gave instructions how to modify dwc3 driver to timeout on address
> devicecommands to test these, I'll try to set that up.
>
> All additional testing is welcome, especially if you can trigger timeouts
> and races
>
> -Mathias
>
>

I post the code below and add my comments in line.

1276 void xhci_handle_command_timeout(struct work_struct *work)
1277 {
1278 struct xhci_hcd *xhci;
1279 int ret;
1280 unsigned long flags;
1281 u64 hw_ring_state;
1282
1283 xhci = container_of(to_delayed_work(work), struct xhci_hcd, 
cmd_timer);
1284
1285 spin_lock_irqsave(>lock, flags);
1286
1287 /*
1288  * If timeout work is pending, or current_cmd is NULL, it means we
1289  * raced with command completion. Command is handled so just 
return.
1290  */
1291 if (!xhci->current_cmd || delayed_work_pending(>cmd_timer)) {
1292 spin_unlock_irqrestore(>lock, flags);
1293 return;
1294 }
1295 /* mark this command to be cancelled */
1296 xhci->current_cmd->status = COMP_CMD_ABORT;
1297
1298 /* Make sure command ring is running before aborting it */
1299 hw_ring_state = xhci_read_64(xhci, >op_regs->cmd_ring);
1300 if ((xhci->cmd_ring_state & CMD_RING_STATE_RUNNING) &&
1301 (hw_ring_state & CMD_RING_RUNNING))  {
1302 /* Prevent new doorbell, and start command abort */
1303 xhci->cmd_ring_state = CMD_RING_STATE_ABORTED;
1304 spin_unlock_irqrestore(>lock, flags);
1305 xhci_dbg(xhci, "Command timeout\n");
1306 ret = xhci_abort_cmd_ring(xhci);
1307 if (unlikely(ret == -ESHUTDOWN)) {
1308 xhci_err(xhci, "Abort command ring failed\n");
1309 xhci_cleanup_command_queue(xhci);
1310 usb_hc_died(xhci_to_hcd(xhci)->primary_hcd);
1311 xhci_dbg(xhci, "xHCI host controller is dead.\n");
1312 }
1313 return;
1314 }
1315
1316 /* host removed. Bail out */
1317 if (xhci->xhc_state & XHCI_STATE_REMOVING) {
1318 spin_unlock_irqrestore(>lock, flags);
1319 xhci_dbg(xhci, "host removed, ring start fail?\n");
1320 xhci_cleanup_command_queue(xhci);
1321 return;
1322 }

I think this part of code should be moved up to line 1295.

1323
1324 /* command timeout on stopped ring, ring can't be aborted */
1325 xhci_dbg(xhci, "Command timeout on stopped ring\n");
1326 xhci_handle_stopped_cmd_ring(xhci, xhci->current_cmd);
1327 spin_unlock_irqrestore(>lock, flags);

This part of code is tricky. I have no idea about in which case should this
code be executed? Anyway, we shouldn't call xhci_handle_stopped_cmd_ring()
here, right?

1328 return;
1329 }

Best regards,
Lu Baolu


[PATCH v19 14/15] clocksource/drivers/arm_arch_timer: Add GTDT support for memory-mapped timer

2016-12-20 Thread fu . wei
From: Fu Wei 

The patch add memory-mapped timer register support by using the
information provided by the new GTDT driver of ACPI.

Signed-off-by: Fu Wei 
---
 drivers/clocksource/arm_arch_timer.c | 35 ---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 5a0dd54..5d08d3d 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -1065,10 +1065,36 @@ CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, 
"arm,armv7-timer-mem",
   arch_timer_mem_of_init);
 
 #ifdef CONFIG_ACPI_GTDT
-/* Initialize per-processor generic timer */
+static int __init arch_timer_mem_acpi_init(int platform_timer_count)
+{
+   struct arch_timer_mem *timer_mem;
+   int timer_count, i, ret;
+
+   timer_mem = kcalloc(platform_timer_count, sizeof(*timer_mem),
+   GFP_KERNEL);
+   if (!timer_mem)
+   return -ENOMEM;
+
+   ret = acpi_arch_timer_mem_init(timer_mem, _count);
+   if (ret || !timer_count)
+   goto error;
+
+   for (i = 0; i < timer_count; i++) {
+   ret = arch_timer_mem_init(timer_mem);
+   if (!ret)
+   break;
+   timer_mem++;
+   }
+
+error:
+   kfree(timer_mem);
+   return ret;
+}
+
+/* Initialize per-processor generic timer and memory-mapped timer(if present) 
*/
 static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 {
-   int ret;
+   int ret, platform_timer_count;
 
if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
pr_warn("already initialized, skipping\n");
@@ -1077,7 +1103,7 @@ static int __init arch_timer_acpi_init(struct 
acpi_table_header *table)
 
arch_timers_present |= ARCH_TIMER_TYPE_CP15;
 
-   ret = acpi_gtdt_init(table, NULL);
+   ret = acpi_gtdt_init(table, _timer_count);
if (ret) {
pr_err("Failed to init GTDT table.\n");
return ret;
@@ -1110,6 +1136,9 @@ static int __init arch_timer_acpi_init(struct 
acpi_table_header *table)
if (ret)
return ret;
 
+   if (arch_timer_mem_acpi_init(platform_timer_count))
+   pr_err("Failed to initialize memory-mapped timer.\n");
+
return arch_timer_common_init();
 }
 CLOCKSOURCE_ACPI_DECLARE(arch_timer, ACPI_SIG_GTDT, arch_timer_acpi_init);
-- 
2.9.3



[PATCH v19 15/15] acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver

2016-12-20 Thread fu . wei
From: Fu Wei 

This driver adds support for parsing SBSA Generic Watchdog timer
in GTDT, parse all info in SBSA Generic Watchdog Structure in GTDT,
and creating a platform device with that information.

This allows the operating system to obtain device data from the
resource of platform device. The platform device named "sbsa-gwdt"
can be used by the ARM SBSA Generic Watchdog driver.

Signed-off-by: Fu Wei 
Signed-off-by: Hanjun Guo 
Tested-by: Xiongfeng Wang 
---
 drivers/acpi/arm64/gtdt.c | 93 +++
 drivers/watchdog/Kconfig  |  1 +
 2 files changed, 94 insertions(+)

diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
index 91ea6cb..22d3659 100644
--- a/drivers/acpi/arm64/gtdt.c
+++ b/drivers/acpi/arm64/gtdt.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -59,6 +60,13 @@ static inline bool is_timer_block(void *platform_timer)
return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
 }
 
+static inline bool is_watchdog(void *platform_timer)
+{
+   struct acpi_gtdt_header *gh = platform_timer;
+
+   return gh->type == ACPI_GTDT_TYPE_WATCHDOG;
+}
+
 static int __init map_gt_gsi(u32 interrupt, u32 flags)
 {
int trigger, polarity;
@@ -279,3 +287,88 @@ int __init acpi_arch_timer_mem_init(struct arch_timer_mem 
*data,
 
return 0;
 }
+
+/*
+ * Initialize a SBSA generic Watchdog platform device info from GTDT
+ */
+static int __init gtdt_import_sbsa_gwdt(struct acpi_gtdt_watchdog *wd,
+   int index)
+{
+   struct platform_device *pdev;
+   int irq = map_gt_gsi(wd->timer_interrupt, wd->timer_flags);
+   int no_irq = 1;
+
+   /*
+* According to SBSA specification the size of refresh and control
+* frames of SBSA Generic Watchdog is SZ_4K(Offset 0x000 – 0xFFF).
+*/
+   struct resource res[] = {
+   DEFINE_RES_MEM(wd->control_frame_address, SZ_4K),
+   DEFINE_RES_MEM(wd->refresh_frame_address, SZ_4K),
+   DEFINE_RES_IRQ(irq),
+   };
+
+   pr_debug("found a Watchdog (0x%llx/0x%llx gsi:%u flags:0x%x).\n",
+wd->refresh_frame_address, wd->control_frame_address,
+wd->timer_interrupt, wd->timer_flags);
+
+   if (!(wd->refresh_frame_address && wd->control_frame_address)) {
+   pr_err(FW_BUG "failed to get the Watchdog base address.\n");
+   return -EINVAL;
+   }
+
+   if (!wd->timer_interrupt)
+   pr_warn(FW_BUG "failed to get the Watchdog interrupt.\n");
+   else if (irq <= 0)
+   pr_warn("failed to map the Watchdog interrupt.\n");
+   else
+   no_irq = 0;
+
+   /*
+* Add a platform device named "sbsa-gwdt" to match the platform driver.
+* "sbsa-gwdt": SBSA(Server Base System Architecture) Generic Watchdog
+* The platform driver (like drivers/watchdog/sbsa_gwdt.c)can get device
+* info below by matching this name.
+*/
+   pdev = platform_device_register_simple("sbsa-gwdt", index, res,
+  ARRAY_SIZE(res) - no_irq);
+   if (IS_ERR(pdev)) {
+   acpi_unregister_gsi(wd->timer_interrupt);
+   return PTR_ERR(pdev);
+   }
+
+   return 0;
+}
+
+static int __init gtdt_sbsa_gwdt_init(void)
+{
+   int ret, i = 0;
+   void *platform_timer;
+   struct acpi_table_header *table;
+
+   if (acpi_disabled)
+   return 0;
+
+   if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_GTDT, 0, )))
+   return -EINVAL;
+
+   ret = acpi_gtdt_init(table, NULL);
+   if (ret)
+   return ret;
+
+   for_each_platform_timer(platform_timer) {
+   if (is_watchdog(platform_timer)) {
+   ret = gtdt_import_sbsa_gwdt(platform_timer, i);
+   if (ret)
+   break;
+   i++;
+   }
+   }
+
+   if (i)
+   pr_info("found %d SBSA generic Watchdog(s).\n", i);
+
+   return ret;
+}
+
+device_initcall(gtdt_sbsa_gwdt_init);
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 3eb58cb..a95c62d 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -219,6 +219,7 @@ config ARM_SBSA_WATCHDOG
tristate "ARM SBSA Generic Watchdog"
depends on ARM64
depends on ARM_ARCH_TIMER
+   depends on ACPI_GTDT || !ACPI
select WATCHDOG_CORE
help
  ARM SBSA Generic Watchdog has two stage timeouts:
-- 
2.9.3



[PATCH v19 14/15] clocksource/drivers/arm_arch_timer: Add GTDT support for memory-mapped timer

2016-12-20 Thread fu . wei
From: Fu Wei 

The patch add memory-mapped timer register support by using the
information provided by the new GTDT driver of ACPI.

Signed-off-by: Fu Wei 
---
 drivers/clocksource/arm_arch_timer.c | 35 ---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 5a0dd54..5d08d3d 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -1065,10 +1065,36 @@ CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, 
"arm,armv7-timer-mem",
   arch_timer_mem_of_init);
 
 #ifdef CONFIG_ACPI_GTDT
-/* Initialize per-processor generic timer */
+static int __init arch_timer_mem_acpi_init(int platform_timer_count)
+{
+   struct arch_timer_mem *timer_mem;
+   int timer_count, i, ret;
+
+   timer_mem = kcalloc(platform_timer_count, sizeof(*timer_mem),
+   GFP_KERNEL);
+   if (!timer_mem)
+   return -ENOMEM;
+
+   ret = acpi_arch_timer_mem_init(timer_mem, _count);
+   if (ret || !timer_count)
+   goto error;
+
+   for (i = 0; i < timer_count; i++) {
+   ret = arch_timer_mem_init(timer_mem);
+   if (!ret)
+   break;
+   timer_mem++;
+   }
+
+error:
+   kfree(timer_mem);
+   return ret;
+}
+
+/* Initialize per-processor generic timer and memory-mapped timer(if present) 
*/
 static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 {
-   int ret;
+   int ret, platform_timer_count;
 
if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
pr_warn("already initialized, skipping\n");
@@ -1077,7 +1103,7 @@ static int __init arch_timer_acpi_init(struct 
acpi_table_header *table)
 
arch_timers_present |= ARCH_TIMER_TYPE_CP15;
 
-   ret = acpi_gtdt_init(table, NULL);
+   ret = acpi_gtdt_init(table, _timer_count);
if (ret) {
pr_err("Failed to init GTDT table.\n");
return ret;
@@ -1110,6 +1136,9 @@ static int __init arch_timer_acpi_init(struct 
acpi_table_header *table)
if (ret)
return ret;
 
+   if (arch_timer_mem_acpi_init(platform_timer_count))
+   pr_err("Failed to initialize memory-mapped timer.\n");
+
return arch_timer_common_init();
 }
 CLOCKSOURCE_ACPI_DECLARE(arch_timer, ACPI_SIG_GTDT, arch_timer_acpi_init);
-- 
2.9.3



[PATCH v19 15/15] acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver

2016-12-20 Thread fu . wei
From: Fu Wei 

This driver adds support for parsing SBSA Generic Watchdog timer
in GTDT, parse all info in SBSA Generic Watchdog Structure in GTDT,
and creating a platform device with that information.

This allows the operating system to obtain device data from the
resource of platform device. The platform device named "sbsa-gwdt"
can be used by the ARM SBSA Generic Watchdog driver.

Signed-off-by: Fu Wei 
Signed-off-by: Hanjun Guo 
Tested-by: Xiongfeng Wang 
---
 drivers/acpi/arm64/gtdt.c | 93 +++
 drivers/watchdog/Kconfig  |  1 +
 2 files changed, 94 insertions(+)

diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
index 91ea6cb..22d3659 100644
--- a/drivers/acpi/arm64/gtdt.c
+++ b/drivers/acpi/arm64/gtdt.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -59,6 +60,13 @@ static inline bool is_timer_block(void *platform_timer)
return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
 }
 
+static inline bool is_watchdog(void *platform_timer)
+{
+   struct acpi_gtdt_header *gh = platform_timer;
+
+   return gh->type == ACPI_GTDT_TYPE_WATCHDOG;
+}
+
 static int __init map_gt_gsi(u32 interrupt, u32 flags)
 {
int trigger, polarity;
@@ -279,3 +287,88 @@ int __init acpi_arch_timer_mem_init(struct arch_timer_mem 
*data,
 
return 0;
 }
+
+/*
+ * Initialize a SBSA generic Watchdog platform device info from GTDT
+ */
+static int __init gtdt_import_sbsa_gwdt(struct acpi_gtdt_watchdog *wd,
+   int index)
+{
+   struct platform_device *pdev;
+   int irq = map_gt_gsi(wd->timer_interrupt, wd->timer_flags);
+   int no_irq = 1;
+
+   /*
+* According to SBSA specification the size of refresh and control
+* frames of SBSA Generic Watchdog is SZ_4K(Offset 0x000 – 0xFFF).
+*/
+   struct resource res[] = {
+   DEFINE_RES_MEM(wd->control_frame_address, SZ_4K),
+   DEFINE_RES_MEM(wd->refresh_frame_address, SZ_4K),
+   DEFINE_RES_IRQ(irq),
+   };
+
+   pr_debug("found a Watchdog (0x%llx/0x%llx gsi:%u flags:0x%x).\n",
+wd->refresh_frame_address, wd->control_frame_address,
+wd->timer_interrupt, wd->timer_flags);
+
+   if (!(wd->refresh_frame_address && wd->control_frame_address)) {
+   pr_err(FW_BUG "failed to get the Watchdog base address.\n");
+   return -EINVAL;
+   }
+
+   if (!wd->timer_interrupt)
+   pr_warn(FW_BUG "failed to get the Watchdog interrupt.\n");
+   else if (irq <= 0)
+   pr_warn("failed to map the Watchdog interrupt.\n");
+   else
+   no_irq = 0;
+
+   /*
+* Add a platform device named "sbsa-gwdt" to match the platform driver.
+* "sbsa-gwdt": SBSA(Server Base System Architecture) Generic Watchdog
+* The platform driver (like drivers/watchdog/sbsa_gwdt.c)can get device
+* info below by matching this name.
+*/
+   pdev = platform_device_register_simple("sbsa-gwdt", index, res,
+  ARRAY_SIZE(res) - no_irq);
+   if (IS_ERR(pdev)) {
+   acpi_unregister_gsi(wd->timer_interrupt);
+   return PTR_ERR(pdev);
+   }
+
+   return 0;
+}
+
+static int __init gtdt_sbsa_gwdt_init(void)
+{
+   int ret, i = 0;
+   void *platform_timer;
+   struct acpi_table_header *table;
+
+   if (acpi_disabled)
+   return 0;
+
+   if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_GTDT, 0, )))
+   return -EINVAL;
+
+   ret = acpi_gtdt_init(table, NULL);
+   if (ret)
+   return ret;
+
+   for_each_platform_timer(platform_timer) {
+   if (is_watchdog(platform_timer)) {
+   ret = gtdt_import_sbsa_gwdt(platform_timer, i);
+   if (ret)
+   break;
+   i++;
+   }
+   }
+
+   if (i)
+   pr_info("found %d SBSA generic Watchdog(s).\n", i);
+
+   return ret;
+}
+
+device_initcall(gtdt_sbsa_gwdt_init);
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 3eb58cb..a95c62d 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -219,6 +219,7 @@ config ARM_SBSA_WATCHDOG
tristate "ARM SBSA Generic Watchdog"
depends on ARM64
depends on ARM_ARCH_TIMER
+   depends on ACPI_GTDT || !ACPI
select WATCHDOG_CORE
help
  ARM SBSA Generic Watchdog has two stage timeouts:
-- 
2.9.3



[PATCH v19 11/15] acpi/arm64: Add GTDT table parse driver

2016-12-20 Thread fu . wei
From: Fu Wei 

This patch adds support for parsing arch timer info in GTDT,
provides some kernel APIs to parse all the PPIs and
always-on info in GTDT and export them.

By this driver, we can simplify arm_arch_timer drivers, and
separate the ACPI GTDT knowledge from it.

Signed-off-by: Fu Wei 
Signed-off-by: Hanjun Guo 
Acked-by: Rafael J. Wysocki 
Tested-by: Xiongfeng Wang 
---
 arch/arm64/Kconfig  |   1 +
 drivers/acpi/arm64/Kconfig  |   3 +
 drivers/acpi/arm64/Makefile |   1 +
 drivers/acpi/arm64/gtdt.c   | 157 
 include/linux/acpi.h|   6 ++
 5 files changed, 168 insertions(+)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 1117421..ab1ee10 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -2,6 +2,7 @@ config ARM64
def_bool y
select ACPI_CCA_REQUIRED if ACPI
select ACPI_GENERIC_GSI if ACPI
+   select ACPI_GTDT if ACPI
select ACPI_REDUCED_HARDWARE_ONLY if ACPI
select ACPI_MCFG if ACPI
select ACPI_SPCR_TABLE if ACPI
diff --git a/drivers/acpi/arm64/Kconfig b/drivers/acpi/arm64/Kconfig
index 4616da4..5a6f80f 100644
--- a/drivers/acpi/arm64/Kconfig
+++ b/drivers/acpi/arm64/Kconfig
@@ -4,3 +4,6 @@
 
 config ACPI_IORT
bool
+
+config ACPI_GTDT
+   bool
diff --git a/drivers/acpi/arm64/Makefile b/drivers/acpi/arm64/Makefile
index 72331f2..1017def 100644
--- a/drivers/acpi/arm64/Makefile
+++ b/drivers/acpi/arm64/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_ACPI_IORT)+= iort.o
+obj-$(CONFIG_ACPI_GTDT)+= gtdt.o
diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
new file mode 100644
index 000..d93a790
--- /dev/null
+++ b/drivers/acpi/arm64/gtdt.c
@@ -0,0 +1,157 @@
+/*
+ * ARM Specific GTDT table Support
+ *
+ * Copyright (C) 2016, Linaro Ltd.
+ * Author: Daniel Lezcano 
+ * Fu Wei 
+ * Hanjun Guo 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+
+#undef pr_fmt
+#define pr_fmt(fmt) "ACPI GTDT: " fmt
+
+/**
+ * struct acpi_gtdt_descriptor - Store the key info of GTDT for all functions
+ * @gtdt:  The pointer to the struct acpi_table_gtdt of GTDT table.
+ * @gtdt_end:  The pointer to the end of GTDT table.
+ * @platform_timer:The pointer to the start of Platform Timer Structure
+ *
+ * The struct store the key info of GTDT table, it should be initialized by
+ * acpi_gtdt_init.
+ */
+struct acpi_gtdt_descriptor {
+   struct acpi_table_gtdt *gtdt;
+   void *gtdt_end;
+   void *platform_timer;
+};
+
+static struct acpi_gtdt_descriptor acpi_gtdt_desc __initdata;
+
+static int __init map_gt_gsi(u32 interrupt, u32 flags)
+{
+   int trigger, polarity;
+
+   trigger = (flags & ACPI_GTDT_INTERRUPT_MODE) ? ACPI_EDGE_SENSITIVE
+   : ACPI_LEVEL_SENSITIVE;
+
+   polarity = (flags & ACPI_GTDT_INTERRUPT_POLARITY) ? ACPI_ACTIVE_LOW
+   : ACPI_ACTIVE_HIGH;
+
+   return acpi_register_gsi(NULL, interrupt, trigger, polarity);
+}
+
+/**
+ * acpi_gtdt_map_ppi() - Map the PPIs of per-cpu arch_timer.
+ * @type:  the type of PPI.
+ *
+ * Note: Linux on arm64 isn't supported on the secure side.
+ * So we only handle the non-secure timer PPIs,
+ * ARCH_TIMER_PHYS_SECURE_PPI is treated as invalid type.
+ *
+ * Return: the mapped PPI value, 0 if error.
+ */
+int __init acpi_gtdt_map_ppi(int type)
+{
+   struct acpi_table_gtdt *gtdt = acpi_gtdt_desc.gtdt;
+
+   switch (type) {
+   case ARCH_TIMER_PHYS_NONSECURE_PPI:
+   return map_gt_gsi(gtdt->non_secure_el1_interrupt,
+ gtdt->non_secure_el1_flags);
+   case ARCH_TIMER_VIRT_PPI:
+   return map_gt_gsi(gtdt->virtual_timer_interrupt,
+ gtdt->virtual_timer_flags);
+
+   case ARCH_TIMER_HYP_PPI:
+   return map_gt_gsi(gtdt->non_secure_el2_interrupt,
+ gtdt->non_secure_el2_flags);
+   default:
+   pr_err("Failed to map timer interrupt: invalid type.\n");
+   }
+
+   return 0;
+}
+
+/**
+ * acpi_gtdt_c3stop() - Got c3stop info from GTDT according to the type of PPI.
+ * @type:  the type of PPI.
+ *
+ * Return: 1 if the timer can be in deep idle state, 0 otherwise.
+ */
+bool __init acpi_gtdt_c3stop(int type)
+{
+   struct acpi_table_gtdt *gtdt = acpi_gtdt_desc.gtdt;
+
+   switch (type) {
+   case ARCH_TIMER_PHYS_NONSECURE_PPI:
+   return !(gtdt->non_secure_el1_flags & ACPI_GTDT_ALWAYS_ON);
+
+   case ARCH_TIMER_VIRT_PPI:
+   return 

[PATCH v19 13/15] acpi/arm64: Add memory-mapped timer support in GTDT driver

2016-12-20 Thread fu . wei
From: Fu Wei 

On platforms booting with ACPI, architected memory-mapped timers'
configuration data is provided by firmware through the ACPI GTDT
static table.

The clocksource architected timer kernel driver requires a firmware
interface to collect timer configuration and configure its driver.
this infrastructure is present for device tree systems, but it is
missing on systems booting with ACPI.

Implement the kernel infrastructure required to parse the static
ACPI GTDT table so that the architected timer clocksource driver can
make use of it on systems booting with ACPI, therefore enabling
the corresponding timers configuration.

Signed-off-by: Fu Wei 
Signed-off-by: Hanjun Guo 
---
 drivers/acpi/arm64/gtdt.c | 124 ++
 include/linux/acpi.h  |   1 +
 2 files changed, 125 insertions(+)

diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
index d93a790..91ea6cb 100644
--- a/drivers/acpi/arm64/gtdt.c
+++ b/drivers/acpi/arm64/gtdt.c
@@ -37,6 +37,28 @@ struct acpi_gtdt_descriptor {
 
 static struct acpi_gtdt_descriptor acpi_gtdt_desc __initdata;
 
+static inline void *next_platform_timer(void *platform_timer)
+{
+   struct acpi_gtdt_header *gh = platform_timer;
+
+   platform_timer += gh->length;
+   if (platform_timer < acpi_gtdt_desc.gtdt_end)
+   return platform_timer;
+
+   return NULL;
+}
+
+#define for_each_platform_timer(_g)\
+   for (_g = acpi_gtdt_desc.platform_timer; _g;\
+_g = next_platform_timer(_g))
+
+static inline bool is_timer_block(void *platform_timer)
+{
+   struct acpi_gtdt_header *gh = platform_timer;
+
+   return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
+}
+
 static int __init map_gt_gsi(u32 interrupt, u32 flags)
 {
int trigger, polarity;
@@ -155,3 +177,105 @@ int __init acpi_gtdt_init(struct acpi_table_header *table,
 
return ret;
 }
+
+static int __init gtdt_parse_timer_block(struct acpi_gtdt_timer_block *block,
+struct arch_timer_mem *data)
+{
+   int i;
+   struct acpi_gtdt_timer_entry *frame;
+
+   if (!block->timer_count) {
+   pr_err(FW_BUG "GT block present, but frame count is zero.");
+   return -ENODEV;
+   }
+
+   if (block->timer_count > ARCH_TIMER_MEM_MAX_FRAMES) {
+   pr_err(FW_BUG "GT block lists %d frames, ACPI spec only allows 
8\n",
+  block->timer_count);
+   return -EINVAL;
+   }
+
+   data->cntctlbase = (phys_addr_t)block->block_address;
+   /*
+* According to "Table * CNTCTLBase memory map" of
+*  for ARMv8,
+* The size of the CNTCTLBase frame is 4KB(Offset 0x000 – 0xFFC).
+*/
+   data->size = SZ_4K;
+   data->num_frames = block->timer_count;
+
+   frame = (void *)block + block->timer_offset;
+   if (frame + block->timer_count != (void *)block + block->header.length)
+   return -EINVAL;
+
+   /*
+* Get the GT timer Frame data for every GT Block Timer
+*/
+   for (i = 0; i < block->timer_count; i++, frame++) {
+   if (!frame->base_address || !frame->timer_interrupt)
+   return -EINVAL;
+
+   data->frame[i].phys_irq = map_gt_gsi(frame->timer_interrupt,
+frame->timer_flags);
+   if (data->frame[i].phys_irq <= 0) {
+   pr_warn("failed to map physical timer irq in frame 
%d.\n",
+   i);
+   return -EINVAL;
+   }
+
+   data->frame[i].virt_irq =
+   map_gt_gsi(frame->virtual_timer_interrupt,
+  frame->virtual_timer_flags);
+   if (data->frame[i].virt_irq <= 0) {
+   pr_warn("failed to map virtual timer irq in frame 
%d.\n",
+   i);
+   acpi_unregister_gsi(frame->timer_interrupt);
+   return -EINVAL;
+   }
+
+   data->frame[i].frame_nr = frame->frame_number;
+   data->frame[i].cntbase = frame->base_address;
+   /*
+* According to "Table * CNTBaseN memory map" of
+*  for ARMv8,
+* The size of the CNTBaseN frame is 4KB(Offset 0x000 – 0xFFC).
+*/
+   data->frame[i].size = SZ_4K;
+   }
+
+   return 0;
+}
+
+/**
+ * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
+ * @data:  the pointer to the array of struct arch_timer_mem for returning
+ * the result of parsing. The element number of this array should
+ * be platform_timer_count(the total number of platform timers).
+ * @count: The pointer of int variate 

[PATCH v19 12/15] clocksource/drivers/arm_arch_timer: Simplify ACPI support code.

2016-12-20 Thread fu . wei
From: Fu Wei 

The patch update arm_arch_timer driver to use the function
provided by the new GTDT driver of ACPI.
By this way, arm_arch_timer.c can be simplified, and separate
all the ACPI GTDT knowledge from this timer driver.

Signed-off-by: Fu Wei 
Signed-off-by: Hanjun Guo 
Tested-by: Xiongfeng Wang 
---
 drivers/clocksource/arm_arch_timer.c | 46 ++--
 1 file changed, 13 insertions(+), 33 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index b10cc26..5a0dd54 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -1064,59 +1064,36 @@ static int __init arch_timer_mem_of_init(struct 
device_node *np)
 CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem",
   arch_timer_mem_of_init);
 
-#ifdef CONFIG_ACPI
-static int __init map_generic_timer_interrupt(u32 interrupt, u32 flags)
-{
-   int trigger, polarity;
-
-   if (!interrupt)
-   return 0;
-
-   trigger = (flags & ACPI_GTDT_INTERRUPT_MODE) ? ACPI_EDGE_SENSITIVE
-   : ACPI_LEVEL_SENSITIVE;
-
-   polarity = (flags & ACPI_GTDT_INTERRUPT_POLARITY) ? ACPI_ACTIVE_LOW
-   : ACPI_ACTIVE_HIGH;
-
-   return acpi_register_gsi(NULL, interrupt, trigger, polarity);
-}
-
+#ifdef CONFIG_ACPI_GTDT
 /* Initialize per-processor generic timer */
 static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 {
int ret;
-   struct acpi_table_gtdt *gtdt;
 
if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
pr_warn("already initialized, skipping\n");
return -EINVAL;
}
 
-   gtdt = container_of(table, struct acpi_table_gtdt, header);
-
arch_timers_present |= ARCH_TIMER_TYPE_CP15;
 
-   arch_timer_ppi[ARCH_TIMER_PHYS_SECURE_PPI] =
-   map_generic_timer_interrupt(gtdt->secure_el1_interrupt,
-   gtdt->secure_el1_flags);
+   ret = acpi_gtdt_init(table, NULL);
+   if (ret) {
+   pr_err("Failed to init GTDT table.\n");
+   return ret;
+   }
 
arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI] =
-   map_generic_timer_interrupt(gtdt->non_secure_el1_interrupt,
-   gtdt->non_secure_el1_flags);
+   acpi_gtdt_map_ppi(ARCH_TIMER_PHYS_NONSECURE_PPI);
 
arch_timer_ppi[ARCH_TIMER_VIRT_PPI] =
-   map_generic_timer_interrupt(gtdt->virtual_timer_interrupt,
-   gtdt->virtual_timer_flags);
+   acpi_gtdt_map_ppi(ARCH_TIMER_VIRT_PPI);
 
arch_timer_ppi[ARCH_TIMER_HYP_PPI] =
-   map_generic_timer_interrupt(gtdt->non_secure_el2_interrupt,
-   gtdt->non_secure_el2_flags);
+   acpi_gtdt_map_ppi(ARCH_TIMER_HYP_PPI);
 
arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
 
-   /* Get the frequency from CNTFRQ */
-   arch_timer_detect_rate();
-
arch_timer_uses_ppi = arch_timer_select_ppi();
if (!arch_timer_ppi[arch_timer_uses_ppi]) {
pr_err("No interrupt available, giving up\n");
@@ -1124,7 +1101,10 @@ static int __init arch_timer_acpi_init(struct 
acpi_table_header *table)
}
 
/* Always-on capability */
-   arch_timer_c3stop = !(gtdt->non_secure_el1_flags & ACPI_GTDT_ALWAYS_ON);
+   arch_timer_c3stop = acpi_gtdt_c3stop(arch_timer_uses_ppi);
+
+   /* Get the frequency from CNTFRQ */
+   arch_timer_detect_rate();
 
ret = arch_timer_register();
if (ret)
-- 
2.9.3



[PATCH v19 09/15] clocksource/drivers/arm_arch_timer: Introduce some new structs to prepare for GTDT

2016-12-20 Thread fu . wei
From: Fu Wei 

The patch introduce two new structs: arch_timer_mem, arch_timer_mem_frame.
And also introduce a new define: ARCH_TIMER_MEM_MAX_FRAMES

These will be used for refactoring the memory-mapped timer init code to
prepare for GTDT

Signed-off-by: Fu Wei 
---
 include/clocksource/arm_arch_timer.h | 17 +
 1 file changed, 17 insertions(+)

diff --git a/include/clocksource/arm_arch_timer.h 
b/include/clocksource/arm_arch_timer.h
index 48376a5..3403247 100644
--- a/include/clocksource/arm_arch_timer.h
+++ b/include/clocksource/arm_arch_timer.h
@@ -57,6 +57,8 @@ enum arch_timer_spi_nr {
 #define ARCH_TIMER_MEM_PHYS_ACCESS 2
 #define ARCH_TIMER_MEM_VIRT_ACCESS 3
 
+#define ARCH_TIMER_MEM_MAX_FRAMES  8
+
 #define ARCH_TIMER_USR_PCT_ACCESS_EN   (1 << 0) /* physical counter */
 #define ARCH_TIMER_USR_VCT_ACCESS_EN   (1 << 1) /* virtual counter */
 #define ARCH_TIMER_VIRT_EVT_EN (1 << 2)
@@ -72,6 +74,21 @@ struct arch_timer_kvm_info {
int virtual_irq;
 };
 
+struct arch_timer_mem_frame {
+   int frame_nr;
+   phys_addr_t cntbase;
+   size_t size;
+   int phys_irq;
+   int virt_irq;
+};
+
+struct arch_timer_mem {
+   phys_addr_t cntctlbase;
+   size_t size;
+   int num_frames;
+   struct arch_timer_mem_frame frame[ARCH_TIMER_MEM_MAX_FRAMES];
+};
+
 #ifdef CONFIG_ARM_ARCH_TIMER
 
 extern u32 arch_timer_get_rate(void);
-- 
2.9.3



[PATCH v19 07/15] clocksource/drivers/arm_arch_timer: Refactor arch_timer_needs_probing

2016-12-20 Thread fu . wei
From: Fu Wei 

When system init with device-tree, we don't know which node will be
initialized first. And the code in arch_timer_common_init should wait
until per-cpu timer and MMIO timer are both initialized. So we need
arch_timer_needs_probing to detect the init status of system.

But currently the code is dispersed in arch_timer_needs_probing and
arch_timer_common_init. And the function name doesn't specify that
it's only for device-tree. This is somewhat confusing.

This patch move all related code from arch_timer_common_init to
arch_timer_needs_probing, refactor it, and rename it to
arch_timer_needs_of_probing. And make sure that it will be called
only if acpi is disabled.

Signed-off-by: Fu Wei 
---
 drivers/clocksource/arm_arch_timer.c | 34 +++---
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 9a1f138..5f7be04 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -795,15 +795,28 @@ static const struct of_device_id 
arch_timer_mem_of_match[] __initconst = {
{},
 };
 
-static bool __init
-arch_timer_needs_probing(int type, const struct of_device_id *matches)
+static bool __init arch_timer_needs_of_probing(void)
 {
struct device_node *dn;
bool needs_probing = false;
+   unsigned int mask = ARCH_TIMER_TYPE_CP15 | ARCH_TIMER_TYPE_MEM;
 
-   dn = of_find_matching_node(NULL, matches);
-   if (dn && of_device_is_available(dn) && !(arch_timers_present & type))
+   /* We have two timers, and both device-tree nodes are probed. */
+   if ((arch_timers_present & mask) == mask)
+   return false;
+
+   /*
+* Only one type of timer is probed,
+* check if we have another type of timer node in device-tree.
+*/
+   if (arch_timers_present & ARCH_TIMER_TYPE_CP15)
+   dn = of_find_matching_node(NULL, arch_timer_mem_of_match);
+   else
+   dn = of_find_matching_node(NULL, arch_timer_of_match);
+
+   if (dn && of_device_is_available(dn))
needs_probing = true;
+
of_node_put(dn);
 
return needs_probing;
@@ -811,17 +824,8 @@ arch_timer_needs_probing(int type, const struct 
of_device_id *matches)
 
 static int __init arch_timer_common_init(void)
 {
-   unsigned mask = ARCH_TIMER_TYPE_CP15 | ARCH_TIMER_TYPE_MEM;
-
-   /* Wait until both nodes are probed if we have two timers */
-   if ((arch_timers_present & mask) != mask) {
-   if (arch_timer_needs_probing(ARCH_TIMER_TYPE_MEM,
-arch_timer_mem_of_match))
-   return 0;
-   if (arch_timer_needs_probing(ARCH_TIMER_TYPE_CP15,
-arch_timer_of_match))
-   return 0;
-   }
+   if (acpi_disabled && arch_timer_needs_of_probing())
+   return 0;
 
arch_timer_banner(arch_timers_present);
arch_counter_register(arch_timers_present);
-- 
2.9.3



[PATCH v19 09/15] clocksource/drivers/arm_arch_timer: Introduce some new structs to prepare for GTDT

2016-12-20 Thread fu . wei
From: Fu Wei 

The patch introduce two new structs: arch_timer_mem, arch_timer_mem_frame.
And also introduce a new define: ARCH_TIMER_MEM_MAX_FRAMES

These will be used for refactoring the memory-mapped timer init code to
prepare for GTDT

Signed-off-by: Fu Wei 
---
 include/clocksource/arm_arch_timer.h | 17 +
 1 file changed, 17 insertions(+)

diff --git a/include/clocksource/arm_arch_timer.h 
b/include/clocksource/arm_arch_timer.h
index 48376a5..3403247 100644
--- a/include/clocksource/arm_arch_timer.h
+++ b/include/clocksource/arm_arch_timer.h
@@ -57,6 +57,8 @@ enum arch_timer_spi_nr {
 #define ARCH_TIMER_MEM_PHYS_ACCESS 2
 #define ARCH_TIMER_MEM_VIRT_ACCESS 3
 
+#define ARCH_TIMER_MEM_MAX_FRAMES  8
+
 #define ARCH_TIMER_USR_PCT_ACCESS_EN   (1 << 0) /* physical counter */
 #define ARCH_TIMER_USR_VCT_ACCESS_EN   (1 << 1) /* virtual counter */
 #define ARCH_TIMER_VIRT_EVT_EN (1 << 2)
@@ -72,6 +74,21 @@ struct arch_timer_kvm_info {
int virtual_irq;
 };
 
+struct arch_timer_mem_frame {
+   int frame_nr;
+   phys_addr_t cntbase;
+   size_t size;
+   int phys_irq;
+   int virt_irq;
+};
+
+struct arch_timer_mem {
+   phys_addr_t cntctlbase;
+   size_t size;
+   int num_frames;
+   struct arch_timer_mem_frame frame[ARCH_TIMER_MEM_MAX_FRAMES];
+};
+
 #ifdef CONFIG_ARM_ARCH_TIMER
 
 extern u32 arch_timer_get_rate(void);
-- 
2.9.3



[PATCH v19 07/15] clocksource/drivers/arm_arch_timer: Refactor arch_timer_needs_probing

2016-12-20 Thread fu . wei
From: Fu Wei 

When system init with device-tree, we don't know which node will be
initialized first. And the code in arch_timer_common_init should wait
until per-cpu timer and MMIO timer are both initialized. So we need
arch_timer_needs_probing to detect the init status of system.

But currently the code is dispersed in arch_timer_needs_probing and
arch_timer_common_init. And the function name doesn't specify that
it's only for device-tree. This is somewhat confusing.

This patch move all related code from arch_timer_common_init to
arch_timer_needs_probing, refactor it, and rename it to
arch_timer_needs_of_probing. And make sure that it will be called
only if acpi is disabled.

Signed-off-by: Fu Wei 
---
 drivers/clocksource/arm_arch_timer.c | 34 +++---
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 9a1f138..5f7be04 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -795,15 +795,28 @@ static const struct of_device_id 
arch_timer_mem_of_match[] __initconst = {
{},
 };
 
-static bool __init
-arch_timer_needs_probing(int type, const struct of_device_id *matches)
+static bool __init arch_timer_needs_of_probing(void)
 {
struct device_node *dn;
bool needs_probing = false;
+   unsigned int mask = ARCH_TIMER_TYPE_CP15 | ARCH_TIMER_TYPE_MEM;
 
-   dn = of_find_matching_node(NULL, matches);
-   if (dn && of_device_is_available(dn) && !(arch_timers_present & type))
+   /* We have two timers, and both device-tree nodes are probed. */
+   if ((arch_timers_present & mask) == mask)
+   return false;
+
+   /*
+* Only one type of timer is probed,
+* check if we have another type of timer node in device-tree.
+*/
+   if (arch_timers_present & ARCH_TIMER_TYPE_CP15)
+   dn = of_find_matching_node(NULL, arch_timer_mem_of_match);
+   else
+   dn = of_find_matching_node(NULL, arch_timer_of_match);
+
+   if (dn && of_device_is_available(dn))
needs_probing = true;
+
of_node_put(dn);
 
return needs_probing;
@@ -811,17 +824,8 @@ arch_timer_needs_probing(int type, const struct 
of_device_id *matches)
 
 static int __init arch_timer_common_init(void)
 {
-   unsigned mask = ARCH_TIMER_TYPE_CP15 | ARCH_TIMER_TYPE_MEM;
-
-   /* Wait until both nodes are probed if we have two timers */
-   if ((arch_timers_present & mask) != mask) {
-   if (arch_timer_needs_probing(ARCH_TIMER_TYPE_MEM,
-arch_timer_mem_of_match))
-   return 0;
-   if (arch_timer_needs_probing(ARCH_TIMER_TYPE_CP15,
-arch_timer_of_match))
-   return 0;
-   }
+   if (acpi_disabled && arch_timer_needs_of_probing())
+   return 0;
 
arch_timer_banner(arch_timers_present);
arch_counter_register(arch_timers_present);
-- 
2.9.3



[PATCH v19 12/15] clocksource/drivers/arm_arch_timer: Simplify ACPI support code.

2016-12-20 Thread fu . wei
From: Fu Wei 

The patch update arm_arch_timer driver to use the function
provided by the new GTDT driver of ACPI.
By this way, arm_arch_timer.c can be simplified, and separate
all the ACPI GTDT knowledge from this timer driver.

Signed-off-by: Fu Wei 
Signed-off-by: Hanjun Guo 
Tested-by: Xiongfeng Wang 
---
 drivers/clocksource/arm_arch_timer.c | 46 ++--
 1 file changed, 13 insertions(+), 33 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index b10cc26..5a0dd54 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -1064,59 +1064,36 @@ static int __init arch_timer_mem_of_init(struct 
device_node *np)
 CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem",
   arch_timer_mem_of_init);
 
-#ifdef CONFIG_ACPI
-static int __init map_generic_timer_interrupt(u32 interrupt, u32 flags)
-{
-   int trigger, polarity;
-
-   if (!interrupt)
-   return 0;
-
-   trigger = (flags & ACPI_GTDT_INTERRUPT_MODE) ? ACPI_EDGE_SENSITIVE
-   : ACPI_LEVEL_SENSITIVE;
-
-   polarity = (flags & ACPI_GTDT_INTERRUPT_POLARITY) ? ACPI_ACTIVE_LOW
-   : ACPI_ACTIVE_HIGH;
-
-   return acpi_register_gsi(NULL, interrupt, trigger, polarity);
-}
-
+#ifdef CONFIG_ACPI_GTDT
 /* Initialize per-processor generic timer */
 static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 {
int ret;
-   struct acpi_table_gtdt *gtdt;
 
if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
pr_warn("already initialized, skipping\n");
return -EINVAL;
}
 
-   gtdt = container_of(table, struct acpi_table_gtdt, header);
-
arch_timers_present |= ARCH_TIMER_TYPE_CP15;
 
-   arch_timer_ppi[ARCH_TIMER_PHYS_SECURE_PPI] =
-   map_generic_timer_interrupt(gtdt->secure_el1_interrupt,
-   gtdt->secure_el1_flags);
+   ret = acpi_gtdt_init(table, NULL);
+   if (ret) {
+   pr_err("Failed to init GTDT table.\n");
+   return ret;
+   }
 
arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI] =
-   map_generic_timer_interrupt(gtdt->non_secure_el1_interrupt,
-   gtdt->non_secure_el1_flags);
+   acpi_gtdt_map_ppi(ARCH_TIMER_PHYS_NONSECURE_PPI);
 
arch_timer_ppi[ARCH_TIMER_VIRT_PPI] =
-   map_generic_timer_interrupt(gtdt->virtual_timer_interrupt,
-   gtdt->virtual_timer_flags);
+   acpi_gtdt_map_ppi(ARCH_TIMER_VIRT_PPI);
 
arch_timer_ppi[ARCH_TIMER_HYP_PPI] =
-   map_generic_timer_interrupt(gtdt->non_secure_el2_interrupt,
-   gtdt->non_secure_el2_flags);
+   acpi_gtdt_map_ppi(ARCH_TIMER_HYP_PPI);
 
arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
 
-   /* Get the frequency from CNTFRQ */
-   arch_timer_detect_rate();
-
arch_timer_uses_ppi = arch_timer_select_ppi();
if (!arch_timer_ppi[arch_timer_uses_ppi]) {
pr_err("No interrupt available, giving up\n");
@@ -1124,7 +1101,10 @@ static int __init arch_timer_acpi_init(struct 
acpi_table_header *table)
}
 
/* Always-on capability */
-   arch_timer_c3stop = !(gtdt->non_secure_el1_flags & ACPI_GTDT_ALWAYS_ON);
+   arch_timer_c3stop = acpi_gtdt_c3stop(arch_timer_uses_ppi);
+
+   /* Get the frequency from CNTFRQ */
+   arch_timer_detect_rate();
 
ret = arch_timer_register();
if (ret)
-- 
2.9.3



[PATCH v19 11/15] acpi/arm64: Add GTDT table parse driver

2016-12-20 Thread fu . wei
From: Fu Wei 

This patch adds support for parsing arch timer info in GTDT,
provides some kernel APIs to parse all the PPIs and
always-on info in GTDT and export them.

By this driver, we can simplify arm_arch_timer drivers, and
separate the ACPI GTDT knowledge from it.

Signed-off-by: Fu Wei 
Signed-off-by: Hanjun Guo 
Acked-by: Rafael J. Wysocki 
Tested-by: Xiongfeng Wang 
---
 arch/arm64/Kconfig  |   1 +
 drivers/acpi/arm64/Kconfig  |   3 +
 drivers/acpi/arm64/Makefile |   1 +
 drivers/acpi/arm64/gtdt.c   | 157 
 include/linux/acpi.h|   6 ++
 5 files changed, 168 insertions(+)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 1117421..ab1ee10 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -2,6 +2,7 @@ config ARM64
def_bool y
select ACPI_CCA_REQUIRED if ACPI
select ACPI_GENERIC_GSI if ACPI
+   select ACPI_GTDT if ACPI
select ACPI_REDUCED_HARDWARE_ONLY if ACPI
select ACPI_MCFG if ACPI
select ACPI_SPCR_TABLE if ACPI
diff --git a/drivers/acpi/arm64/Kconfig b/drivers/acpi/arm64/Kconfig
index 4616da4..5a6f80f 100644
--- a/drivers/acpi/arm64/Kconfig
+++ b/drivers/acpi/arm64/Kconfig
@@ -4,3 +4,6 @@
 
 config ACPI_IORT
bool
+
+config ACPI_GTDT
+   bool
diff --git a/drivers/acpi/arm64/Makefile b/drivers/acpi/arm64/Makefile
index 72331f2..1017def 100644
--- a/drivers/acpi/arm64/Makefile
+++ b/drivers/acpi/arm64/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_ACPI_IORT)+= iort.o
+obj-$(CONFIG_ACPI_GTDT)+= gtdt.o
diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
new file mode 100644
index 000..d93a790
--- /dev/null
+++ b/drivers/acpi/arm64/gtdt.c
@@ -0,0 +1,157 @@
+/*
+ * ARM Specific GTDT table Support
+ *
+ * Copyright (C) 2016, Linaro Ltd.
+ * Author: Daniel Lezcano 
+ * Fu Wei 
+ * Hanjun Guo 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+
+#undef pr_fmt
+#define pr_fmt(fmt) "ACPI GTDT: " fmt
+
+/**
+ * struct acpi_gtdt_descriptor - Store the key info of GTDT for all functions
+ * @gtdt:  The pointer to the struct acpi_table_gtdt of GTDT table.
+ * @gtdt_end:  The pointer to the end of GTDT table.
+ * @platform_timer:The pointer to the start of Platform Timer Structure
+ *
+ * The struct store the key info of GTDT table, it should be initialized by
+ * acpi_gtdt_init.
+ */
+struct acpi_gtdt_descriptor {
+   struct acpi_table_gtdt *gtdt;
+   void *gtdt_end;
+   void *platform_timer;
+};
+
+static struct acpi_gtdt_descriptor acpi_gtdt_desc __initdata;
+
+static int __init map_gt_gsi(u32 interrupt, u32 flags)
+{
+   int trigger, polarity;
+
+   trigger = (flags & ACPI_GTDT_INTERRUPT_MODE) ? ACPI_EDGE_SENSITIVE
+   : ACPI_LEVEL_SENSITIVE;
+
+   polarity = (flags & ACPI_GTDT_INTERRUPT_POLARITY) ? ACPI_ACTIVE_LOW
+   : ACPI_ACTIVE_HIGH;
+
+   return acpi_register_gsi(NULL, interrupt, trigger, polarity);
+}
+
+/**
+ * acpi_gtdt_map_ppi() - Map the PPIs of per-cpu arch_timer.
+ * @type:  the type of PPI.
+ *
+ * Note: Linux on arm64 isn't supported on the secure side.
+ * So we only handle the non-secure timer PPIs,
+ * ARCH_TIMER_PHYS_SECURE_PPI is treated as invalid type.
+ *
+ * Return: the mapped PPI value, 0 if error.
+ */
+int __init acpi_gtdt_map_ppi(int type)
+{
+   struct acpi_table_gtdt *gtdt = acpi_gtdt_desc.gtdt;
+
+   switch (type) {
+   case ARCH_TIMER_PHYS_NONSECURE_PPI:
+   return map_gt_gsi(gtdt->non_secure_el1_interrupt,
+ gtdt->non_secure_el1_flags);
+   case ARCH_TIMER_VIRT_PPI:
+   return map_gt_gsi(gtdt->virtual_timer_interrupt,
+ gtdt->virtual_timer_flags);
+
+   case ARCH_TIMER_HYP_PPI:
+   return map_gt_gsi(gtdt->non_secure_el2_interrupt,
+ gtdt->non_secure_el2_flags);
+   default:
+   pr_err("Failed to map timer interrupt: invalid type.\n");
+   }
+
+   return 0;
+}
+
+/**
+ * acpi_gtdt_c3stop() - Got c3stop info from GTDT according to the type of PPI.
+ * @type:  the type of PPI.
+ *
+ * Return: 1 if the timer can be in deep idle state, 0 otherwise.
+ */
+bool __init acpi_gtdt_c3stop(int type)
+{
+   struct acpi_table_gtdt *gtdt = acpi_gtdt_desc.gtdt;
+
+   switch (type) {
+   case ARCH_TIMER_PHYS_NONSECURE_PPI:
+   return !(gtdt->non_secure_el1_flags & ACPI_GTDT_ALWAYS_ON);
+
+   case ARCH_TIMER_VIRT_PPI:
+   return !(gtdt->virtual_timer_flags & ACPI_GTDT_ALWAYS_ON);
+
+   case ARCH_TIMER_HYP_PPI:
+   return !(gtdt->non_secure_el2_flags & ACPI_GTDT_ALWAYS_ON);
+
+   default:
+   

[PATCH v19 13/15] acpi/arm64: Add memory-mapped timer support in GTDT driver

2016-12-20 Thread fu . wei
From: Fu Wei 

On platforms booting with ACPI, architected memory-mapped timers'
configuration data is provided by firmware through the ACPI GTDT
static table.

The clocksource architected timer kernel driver requires a firmware
interface to collect timer configuration and configure its driver.
this infrastructure is present for device tree systems, but it is
missing on systems booting with ACPI.

Implement the kernel infrastructure required to parse the static
ACPI GTDT table so that the architected timer clocksource driver can
make use of it on systems booting with ACPI, therefore enabling
the corresponding timers configuration.

Signed-off-by: Fu Wei 
Signed-off-by: Hanjun Guo 
---
 drivers/acpi/arm64/gtdt.c | 124 ++
 include/linux/acpi.h  |   1 +
 2 files changed, 125 insertions(+)

diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c
index d93a790..91ea6cb 100644
--- a/drivers/acpi/arm64/gtdt.c
+++ b/drivers/acpi/arm64/gtdt.c
@@ -37,6 +37,28 @@ struct acpi_gtdt_descriptor {
 
 static struct acpi_gtdt_descriptor acpi_gtdt_desc __initdata;
 
+static inline void *next_platform_timer(void *platform_timer)
+{
+   struct acpi_gtdt_header *gh = platform_timer;
+
+   platform_timer += gh->length;
+   if (platform_timer < acpi_gtdt_desc.gtdt_end)
+   return platform_timer;
+
+   return NULL;
+}
+
+#define for_each_platform_timer(_g)\
+   for (_g = acpi_gtdt_desc.platform_timer; _g;\
+_g = next_platform_timer(_g))
+
+static inline bool is_timer_block(void *platform_timer)
+{
+   struct acpi_gtdt_header *gh = platform_timer;
+
+   return gh->type == ACPI_GTDT_TYPE_TIMER_BLOCK;
+}
+
 static int __init map_gt_gsi(u32 interrupt, u32 flags)
 {
int trigger, polarity;
@@ -155,3 +177,105 @@ int __init acpi_gtdt_init(struct acpi_table_header *table,
 
return ret;
 }
+
+static int __init gtdt_parse_timer_block(struct acpi_gtdt_timer_block *block,
+struct arch_timer_mem *data)
+{
+   int i;
+   struct acpi_gtdt_timer_entry *frame;
+
+   if (!block->timer_count) {
+   pr_err(FW_BUG "GT block present, but frame count is zero.");
+   return -ENODEV;
+   }
+
+   if (block->timer_count > ARCH_TIMER_MEM_MAX_FRAMES) {
+   pr_err(FW_BUG "GT block lists %d frames, ACPI spec only allows 
8\n",
+  block->timer_count);
+   return -EINVAL;
+   }
+
+   data->cntctlbase = (phys_addr_t)block->block_address;
+   /*
+* According to "Table * CNTCTLBase memory map" of
+*  for ARMv8,
+* The size of the CNTCTLBase frame is 4KB(Offset 0x000 – 0xFFC).
+*/
+   data->size = SZ_4K;
+   data->num_frames = block->timer_count;
+
+   frame = (void *)block + block->timer_offset;
+   if (frame + block->timer_count != (void *)block + block->header.length)
+   return -EINVAL;
+
+   /*
+* Get the GT timer Frame data for every GT Block Timer
+*/
+   for (i = 0; i < block->timer_count; i++, frame++) {
+   if (!frame->base_address || !frame->timer_interrupt)
+   return -EINVAL;
+
+   data->frame[i].phys_irq = map_gt_gsi(frame->timer_interrupt,
+frame->timer_flags);
+   if (data->frame[i].phys_irq <= 0) {
+   pr_warn("failed to map physical timer irq in frame 
%d.\n",
+   i);
+   return -EINVAL;
+   }
+
+   data->frame[i].virt_irq =
+   map_gt_gsi(frame->virtual_timer_interrupt,
+  frame->virtual_timer_flags);
+   if (data->frame[i].virt_irq <= 0) {
+   pr_warn("failed to map virtual timer irq in frame 
%d.\n",
+   i);
+   acpi_unregister_gsi(frame->timer_interrupt);
+   return -EINVAL;
+   }
+
+   data->frame[i].frame_nr = frame->frame_number;
+   data->frame[i].cntbase = frame->base_address;
+   /*
+* According to "Table * CNTBaseN memory map" of
+*  for ARMv8,
+* The size of the CNTBaseN frame is 4KB(Offset 0x000 – 0xFFC).
+*/
+   data->frame[i].size = SZ_4K;
+   }
+
+   return 0;
+}
+
+/**
+ * acpi_arch_timer_mem_init() - Get the info of all GT blocks in GTDT table.
+ * @data:  the pointer to the array of struct arch_timer_mem for returning
+ * the result of parsing. The element number of this array should
+ * be platform_timer_count(the total number of platform timers).
+ * @count: The pointer of int variate for returning the number of GT
+ * blocks we have 

[PATCH v19 08/15] clocksource/drivers/arm_arch_timer: move arch_timer_needs_of_probing into DT init call

2016-12-20 Thread fu . wei
From: Fu Wei 

Because arch_timer_needs_of_probing is only for booting with device-tree,
but arch_timer_common_init is a generic init call which shouldn't include
the FW-specific code. It's better to put arch_timer_needs_of_probing into
DT init function.

But for per-cpu timer, the arch_timer_common_init is called from
arch_timer_init. For reaching the goal above, this patch disassemble
arch_timer_init and use arch_timer_register and arch_timer_common_init
directly, just like arch_timer_mem init code is doing.
By this way, all the DT relevant code are only called from DT init call.

Signed-off-by: Fu Wei 
---
 drivers/clocksource/arm_arch_timer.c | 46 
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 5f7be04..9113df8 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -824,9 +824,6 @@ static bool __init arch_timer_needs_of_probing(void)
 
 static int __init arch_timer_common_init(void)
 {
-   if (acpi_disabled && arch_timer_needs_of_probing())
-   return 0;
-
arch_timer_banner(arch_timers_present);
arch_counter_register(arch_timers_present);
return arch_timer_arch_init();
@@ -864,26 +861,9 @@ static enum arch_timer_ppi_nr __init 
arch_timer_select_ppi(void)
return ARCH_TIMER_PHYS_SECURE_PPI;
 }
 
-static int __init arch_timer_init(void)
-{
-   int ret;
-
-   ret = arch_timer_register();
-   if (ret)
-   return ret;
-
-   ret = arch_timer_common_init();
-   if (ret)
-   return ret;
-
-   arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
-
-   return 0;
-}
-
 static int __init arch_timer_of_init(struct device_node *np)
 {
-   int i;
+   int i, ret;
 
if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
pr_warn("multiple nodes in dt, skipping\n");
@@ -894,6 +874,8 @@ static int __init arch_timer_of_init(struct device_node *np)
for (i = ARCH_TIMER_PHYS_SECURE_PPI; i < ARCH_TIMER_MAX_TIMER_PPI; i++)
arch_timer_ppi[i] = irq_of_parse_and_map(np, i);
 
+   arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
+
if (!arch_timer_rate &&
of_property_read_u32(np, "clock-frequency", _timer_rate))
arch_timer_detect_rate();
@@ -928,7 +910,14 @@ static int __init arch_timer_of_init(struct device_node 
*np)
arch_counter_suspend_stop = of_property_read_bool(np,
 
"arm,no-tick-in-suspend");
 
-   return arch_timer_init();
+   ret = arch_timer_register();
+   if (ret)
+   return ret;
+
+   if (arch_timer_needs_of_probing())
+   return 0;
+
+   return arch_timer_common_init();
 }
 CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", 
arch_timer_of_init);
 CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", 
arch_timer_of_init);
@@ -1016,7 +1005,8 @@ static int __init arch_timer_mem_init(struct device_node 
*np)
if (ret)
goto out;
 
-   return arch_timer_common_init();
+   if (!arch_timer_needs_of_probing())
+   ret = arch_timer_common_init();
 out:
iounmap(cntctlbase);
of_node_put(best_frame);
@@ -1045,6 +1035,7 @@ static int __init map_generic_timer_interrupt(u32 
interrupt, u32 flags)
 /* Initialize per-processor generic timer */
 static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 {
+   int ret;
struct acpi_table_gtdt *gtdt;
 
if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
@@ -1072,6 +1063,8 @@ static int __init arch_timer_acpi_init(struct 
acpi_table_header *table)
map_generic_timer_interrupt(gtdt->non_secure_el2_interrupt,
gtdt->non_secure_el2_flags);
 
+   arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
+
/* Get the frequency from CNTFRQ */
arch_timer_detect_rate();
 
@@ -1084,8 +1077,11 @@ static int __init arch_timer_acpi_init(struct 
acpi_table_header *table)
/* Always-on capability */
arch_timer_c3stop = !(gtdt->non_secure_el1_flags & ACPI_GTDT_ALWAYS_ON);
 
-   arch_timer_init();
-   return 0;
+   ret = arch_timer_register();
+   if (ret)
+   return ret;
+
+   return arch_timer_common_init();
 }
 CLOCKSOURCE_ACPI_DECLARE(arch_timer, ACPI_SIG_GTDT, arch_timer_acpi_init);
 #endif
-- 
2.9.3



[PATCH v19 10/15] clocksource/drivers/arm_arch_timer: Refactor the timer init code to prepare for GTDT

2016-12-20 Thread fu . wei
From: Fu Wei 

The patch refactor original memory-mapped timer init code:
(1) Refactor "arch_timer_mem_init", make it become a common code for
memory-mapped timer init.
(2) Add a new function "arch_timer_mem_of_init" for DT init.

Signed-off-by: Fu Wei 
---
 drivers/clocksource/arm_arch_timer.c | 135 ---
 1 file changed, 92 insertions(+), 43 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 9113df8..b10cc26 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -922,17 +922,17 @@ static int __init arch_timer_of_init(struct device_node 
*np)
 CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", 
arch_timer_of_init);
 CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", 
arch_timer_of_init);
 
-static int __init arch_timer_mem_init(struct device_node *np)
+static int __init arch_timer_mem_init(struct arch_timer_mem *timer_mem)
 {
-   struct device_node *frame, *best_frame = NULL;
void __iomem *cntctlbase, *base;
-   unsigned int irq, ret = -EINVAL;
+   struct arch_timer_mem_frame *best_frame = NULL;
+   unsigned int irq;
u32 cnttidr;
+   int i, ret;
 
-   arch_timers_present |= ARCH_TIMER_TYPE_MEM;
-   cntctlbase = of_iomap(np, 0);
+   cntctlbase = ioremap(timer_mem->cntctlbase, timer_mem->size);
if (!cntctlbase) {
-   pr_err("Can't find CNTCTLBase\n");
+   pr_err("Can't map CNTCTLBase.\n");
return -ENXIO;
}
 
@@ -942,26 +942,18 @@ static int __init arch_timer_mem_init(struct device_node 
*np)
 * Try to find a virtual capable frame. Otherwise fall back to a
 * physical capable frame.
 */
-   for_each_available_child_of_node(np, frame) {
-   int n;
-   u32 cntacr;
-
-   if (of_property_read_u32(frame, "frame-number", )) {
-   pr_err("Missing frame-number\n");
-   of_node_put(frame);
-   goto out;
-   }
+   for (i = 0; i < timer_mem->num_frames; i++) {
+   u32 cntacr = CNTACR_RFRQ | CNTACR_RWPT | CNTACR_RPCT |
+CNTACR_RWVT | CNTACR_RVOFF | CNTACR_RVCT;
+   int n = timer_mem->frame[i].frame_nr;
 
/* Try enabling everything, and see what sticks */
-   cntacr = CNTACR_RFRQ | CNTACR_RWPT | CNTACR_RPCT |
-CNTACR_RWVT | CNTACR_RVOFF | CNTACR_RVCT;
writel_relaxed(cntacr, cntctlbase + CNTACR(n));
cntacr = readl_relaxed(cntctlbase + CNTACR(n));
 
if ((cnttidr & CNTTIDR_VIRT(n)) &&
!(~cntacr & (CNTACR_RWVT | CNTACR_RVCT))) {
-   of_node_put(best_frame);
-   best_frame = frame;
+   best_frame = _mem->frame[i];
arch_timer_mem_use_virtual = true;
break;
}
@@ -969,51 +961,108 @@ static int __init arch_timer_mem_init(struct device_node 
*np)
if (~cntacr & (CNTACR_RWPT | CNTACR_RPCT))
continue;
 
-   of_node_put(best_frame);
-   best_frame = of_node_get(frame);
+   best_frame = _mem->frame[i];
}
+   iounmap(cntctlbase);
 
-   ret= -ENXIO;
-   base = arch_counter_base = of_io_request_and_map(best_frame, 0,
-"arch_mem_timer");
-   if (IS_ERR(base)) {
-   pr_err("Can't map frame's registers\n");
-   goto out;
+   if (!best_frame) {
+   pr_err("Can't find frame for register\n");
+   return -EINVAL;
}
 
if (arch_timer_mem_use_virtual)
-   irq = irq_of_parse_and_map(best_frame, ARCH_TIMER_VIRT_SPI);
+   irq = best_frame->virt_irq;
else
-   irq = irq_of_parse_and_map(best_frame, ARCH_TIMER_PHYS_SPI);
+   irq = best_frame->phys_irq;
 
-   ret = -EINVAL;
if (!irq) {
pr_err("Frame missing %s irq.\n",
   arch_timer_mem_use_virtual ? "virt" : "phys");
-   goto out;
+   return -EINVAL;
}
 
-   /*
-* Try to determine the frequency from the device tree,
-* if fail, get the frequency from CNTFRQ.
-*/
-   if (!arch_timer_rate &&
-   of_property_read_u32(np, "clock-frequency", _timer_rate))
-   arch_timer_mem_detect_rate(base);
+   if (!request_mem_region(best_frame->cntbase, best_frame->size,
+   "arch_mem_timer"))
+   return -EBUSY;
+
+   base = ioremap(best_frame->cntbase, best_frame->size);
+   if (!base) {
+   pr_err("Can't map frame's 

[PATCH v19 10/15] clocksource/drivers/arm_arch_timer: Refactor the timer init code to prepare for GTDT

2016-12-20 Thread fu . wei
From: Fu Wei 

The patch refactor original memory-mapped timer init code:
(1) Refactor "arch_timer_mem_init", make it become a common code for
memory-mapped timer init.
(2) Add a new function "arch_timer_mem_of_init" for DT init.

Signed-off-by: Fu Wei 
---
 drivers/clocksource/arm_arch_timer.c | 135 ---
 1 file changed, 92 insertions(+), 43 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 9113df8..b10cc26 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -922,17 +922,17 @@ static int __init arch_timer_of_init(struct device_node 
*np)
 CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", 
arch_timer_of_init);
 CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", 
arch_timer_of_init);
 
-static int __init arch_timer_mem_init(struct device_node *np)
+static int __init arch_timer_mem_init(struct arch_timer_mem *timer_mem)
 {
-   struct device_node *frame, *best_frame = NULL;
void __iomem *cntctlbase, *base;
-   unsigned int irq, ret = -EINVAL;
+   struct arch_timer_mem_frame *best_frame = NULL;
+   unsigned int irq;
u32 cnttidr;
+   int i, ret;
 
-   arch_timers_present |= ARCH_TIMER_TYPE_MEM;
-   cntctlbase = of_iomap(np, 0);
+   cntctlbase = ioremap(timer_mem->cntctlbase, timer_mem->size);
if (!cntctlbase) {
-   pr_err("Can't find CNTCTLBase\n");
+   pr_err("Can't map CNTCTLBase.\n");
return -ENXIO;
}
 
@@ -942,26 +942,18 @@ static int __init arch_timer_mem_init(struct device_node 
*np)
 * Try to find a virtual capable frame. Otherwise fall back to a
 * physical capable frame.
 */
-   for_each_available_child_of_node(np, frame) {
-   int n;
-   u32 cntacr;
-
-   if (of_property_read_u32(frame, "frame-number", )) {
-   pr_err("Missing frame-number\n");
-   of_node_put(frame);
-   goto out;
-   }
+   for (i = 0; i < timer_mem->num_frames; i++) {
+   u32 cntacr = CNTACR_RFRQ | CNTACR_RWPT | CNTACR_RPCT |
+CNTACR_RWVT | CNTACR_RVOFF | CNTACR_RVCT;
+   int n = timer_mem->frame[i].frame_nr;
 
/* Try enabling everything, and see what sticks */
-   cntacr = CNTACR_RFRQ | CNTACR_RWPT | CNTACR_RPCT |
-CNTACR_RWVT | CNTACR_RVOFF | CNTACR_RVCT;
writel_relaxed(cntacr, cntctlbase + CNTACR(n));
cntacr = readl_relaxed(cntctlbase + CNTACR(n));
 
if ((cnttidr & CNTTIDR_VIRT(n)) &&
!(~cntacr & (CNTACR_RWVT | CNTACR_RVCT))) {
-   of_node_put(best_frame);
-   best_frame = frame;
+   best_frame = _mem->frame[i];
arch_timer_mem_use_virtual = true;
break;
}
@@ -969,51 +961,108 @@ static int __init arch_timer_mem_init(struct device_node 
*np)
if (~cntacr & (CNTACR_RWPT | CNTACR_RPCT))
continue;
 
-   of_node_put(best_frame);
-   best_frame = of_node_get(frame);
+   best_frame = _mem->frame[i];
}
+   iounmap(cntctlbase);
 
-   ret= -ENXIO;
-   base = arch_counter_base = of_io_request_and_map(best_frame, 0,
-"arch_mem_timer");
-   if (IS_ERR(base)) {
-   pr_err("Can't map frame's registers\n");
-   goto out;
+   if (!best_frame) {
+   pr_err("Can't find frame for register\n");
+   return -EINVAL;
}
 
if (arch_timer_mem_use_virtual)
-   irq = irq_of_parse_and_map(best_frame, ARCH_TIMER_VIRT_SPI);
+   irq = best_frame->virt_irq;
else
-   irq = irq_of_parse_and_map(best_frame, ARCH_TIMER_PHYS_SPI);
+   irq = best_frame->phys_irq;
 
-   ret = -EINVAL;
if (!irq) {
pr_err("Frame missing %s irq.\n",
   arch_timer_mem_use_virtual ? "virt" : "phys");
-   goto out;
+   return -EINVAL;
}
 
-   /*
-* Try to determine the frequency from the device tree,
-* if fail, get the frequency from CNTFRQ.
-*/
-   if (!arch_timer_rate &&
-   of_property_read_u32(np, "clock-frequency", _timer_rate))
-   arch_timer_mem_detect_rate(base);
+   if (!request_mem_region(best_frame->cntbase, best_frame->size,
+   "arch_mem_timer"))
+   return -EBUSY;
+
+   base = ioremap(best_frame->cntbase, best_frame->size);
+   if (!base) {
+   pr_err("Can't map frame's registers\n");
+   return -ENXIO;

[PATCH v19 08/15] clocksource/drivers/arm_arch_timer: move arch_timer_needs_of_probing into DT init call

2016-12-20 Thread fu . wei
From: Fu Wei 

Because arch_timer_needs_of_probing is only for booting with device-tree,
but arch_timer_common_init is a generic init call which shouldn't include
the FW-specific code. It's better to put arch_timer_needs_of_probing into
DT init function.

But for per-cpu timer, the arch_timer_common_init is called from
arch_timer_init. For reaching the goal above, this patch disassemble
arch_timer_init and use arch_timer_register and arch_timer_common_init
directly, just like arch_timer_mem init code is doing.
By this way, all the DT relevant code are only called from DT init call.

Signed-off-by: Fu Wei 
---
 drivers/clocksource/arm_arch_timer.c | 46 
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 5f7be04..9113df8 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -824,9 +824,6 @@ static bool __init arch_timer_needs_of_probing(void)
 
 static int __init arch_timer_common_init(void)
 {
-   if (acpi_disabled && arch_timer_needs_of_probing())
-   return 0;
-
arch_timer_banner(arch_timers_present);
arch_counter_register(arch_timers_present);
return arch_timer_arch_init();
@@ -864,26 +861,9 @@ static enum arch_timer_ppi_nr __init 
arch_timer_select_ppi(void)
return ARCH_TIMER_PHYS_SECURE_PPI;
 }
 
-static int __init arch_timer_init(void)
-{
-   int ret;
-
-   ret = arch_timer_register();
-   if (ret)
-   return ret;
-
-   ret = arch_timer_common_init();
-   if (ret)
-   return ret;
-
-   arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
-
-   return 0;
-}
-
 static int __init arch_timer_of_init(struct device_node *np)
 {
-   int i;
+   int i, ret;
 
if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
pr_warn("multiple nodes in dt, skipping\n");
@@ -894,6 +874,8 @@ static int __init arch_timer_of_init(struct device_node *np)
for (i = ARCH_TIMER_PHYS_SECURE_PPI; i < ARCH_TIMER_MAX_TIMER_PPI; i++)
arch_timer_ppi[i] = irq_of_parse_and_map(np, i);
 
+   arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
+
if (!arch_timer_rate &&
of_property_read_u32(np, "clock-frequency", _timer_rate))
arch_timer_detect_rate();
@@ -928,7 +910,14 @@ static int __init arch_timer_of_init(struct device_node 
*np)
arch_counter_suspend_stop = of_property_read_bool(np,
 
"arm,no-tick-in-suspend");
 
-   return arch_timer_init();
+   ret = arch_timer_register();
+   if (ret)
+   return ret;
+
+   if (arch_timer_needs_of_probing())
+   return 0;
+
+   return arch_timer_common_init();
 }
 CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", 
arch_timer_of_init);
 CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", 
arch_timer_of_init);
@@ -1016,7 +1005,8 @@ static int __init arch_timer_mem_init(struct device_node 
*np)
if (ret)
goto out;
 
-   return arch_timer_common_init();
+   if (!arch_timer_needs_of_probing())
+   ret = arch_timer_common_init();
 out:
iounmap(cntctlbase);
of_node_put(best_frame);
@@ -1045,6 +1035,7 @@ static int __init map_generic_timer_interrupt(u32 
interrupt, u32 flags)
 /* Initialize per-processor generic timer */
 static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 {
+   int ret;
struct acpi_table_gtdt *gtdt;
 
if (arch_timers_present & ARCH_TIMER_TYPE_CP15) {
@@ -1072,6 +1063,8 @@ static int __init arch_timer_acpi_init(struct 
acpi_table_header *table)
map_generic_timer_interrupt(gtdt->non_secure_el2_interrupt,
gtdt->non_secure_el2_flags);
 
+   arch_timer_kvm_info.virtual_irq = arch_timer_ppi[ARCH_TIMER_VIRT_PPI];
+
/* Get the frequency from CNTFRQ */
arch_timer_detect_rate();
 
@@ -1084,8 +1077,11 @@ static int __init arch_timer_acpi_init(struct 
acpi_table_header *table)
/* Always-on capability */
arch_timer_c3stop = !(gtdt->non_secure_el1_flags & ACPI_GTDT_ALWAYS_ON);
 
-   arch_timer_init();
-   return 0;
+   ret = arch_timer_register();
+   if (ret)
+   return ret;
+
+   return arch_timer_common_init();
 }
 CLOCKSOURCE_ACPI_DECLARE(arch_timer, ACPI_SIG_GTDT, arch_timer_acpi_init);
 #endif
-- 
2.9.3



[PATCH v19 04/15] clocksource/drivers/arm_arch_timer: rename some enums and defines.

2016-12-20 Thread fu . wei
From: Fu Wei 

Rename some enums and defines, to unify the format of enums and defines
in arm_arch_timer.h, also update all the users of these enums and defines:
drivers/clocksource/arm_arch_timer.c
virt/kvm/arm/hyp/timer-sr.c

No functional change.

Signed-off-by: Fu Wei 
Tested-by: Xiongfeng Wang 
---
 drivers/clocksource/arm_arch_timer.c | 111 ++-
 include/clocksource/arm_arch_timer.h |  24 
 virt/kvm/arm/hyp/timer-sr.c  |   6 +-
 3 files changed, 73 insertions(+), 68 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 7203f95..c7b4e50 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -66,11 +66,11 @@ struct arch_timer {
 #define to_arch_timer(e) container_of(e, struct arch_timer, evt)
 
 static u32 arch_timer_rate;
-static int arch_timer_ppi[MAX_TIMER_PPI];
+static int arch_timer_ppi[ARCH_TIMER_MAX_TIMER_PPI];
 
 static struct clock_event_device __percpu *arch_timer_evt;
 
-static enum arch_timer_ppi_nr arch_timer_uses_ppi = VIRT_PPI;
+static enum arch_timer_ppi_nr arch_timer_uses_ppi = ARCH_TIMER_VIRT_PPI;
 static bool arch_timer_c3stop;
 static bool arch_timer_mem_use_virtual;
 static bool arch_counter_suspend_stop;
@@ -341,7 +341,7 @@ static void fsl_a008585_set_sne(struct clock_event_device 
*clk)
if (!static_branch_unlikely(_timer_read_ool_enabled))
return;
 
-   if (arch_timer_uses_ppi == VIRT_PPI)
+   if (arch_timer_uses_ppi == ARCH_TIMER_VIRT_PPI)
clk->set_next_event = fsl_a008585_set_next_event_virt;
else
clk->set_next_event = fsl_a008585_set_next_event_phys;
@@ -353,7 +353,7 @@ static void __arch_timer_setup(unsigned type,
 {
clk->features = CLOCK_EVT_FEAT_ONESHOT;
 
-   if (type == ARCH_CP15_TIMER) {
+   if (type == ARCH_TIMER_TYPE_CP15) {
if (arch_timer_c3stop)
clk->features |= CLOCK_EVT_FEAT_C3STOP;
clk->name = "arch_sys_timer";
@@ -361,14 +361,14 @@ static void __arch_timer_setup(unsigned type,
clk->cpumask = cpumask_of(smp_processor_id());
clk->irq = arch_timer_ppi[arch_timer_uses_ppi];
switch (arch_timer_uses_ppi) {
-   case VIRT_PPI:
+   case ARCH_TIMER_VIRT_PPI:
clk->set_state_shutdown = arch_timer_shutdown_virt;
clk->set_state_oneshot_stopped = 
arch_timer_shutdown_virt;
clk->set_next_event = arch_timer_set_next_event_virt;
break;
-   case PHYS_SECURE_PPI:
-   case PHYS_NONSECURE_PPI:
-   case HYP_PPI:
+   case ARCH_TIMER_PHYS_SECURE_PPI:
+   case ARCH_TIMER_PHYS_NONSECURE_PPI:
+   case ARCH_TIMER_HYP_PPI:
clk->set_state_shutdown = arch_timer_shutdown_phys;
clk->set_state_oneshot_stopped = 
arch_timer_shutdown_phys;
clk->set_next_event = arch_timer_set_next_event_phys;
@@ -448,8 +448,8 @@ static void arch_counter_set_user_access(void)
 
 static bool arch_timer_has_nonsecure_ppi(void)
 {
-   return (arch_timer_uses_ppi == PHYS_SECURE_PPI &&
-   arch_timer_ppi[PHYS_NONSECURE_PPI]);
+   return (arch_timer_uses_ppi == ARCH_TIMER_PHYS_SECURE_PPI &&
+   arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI]);
 }
 
 static u32 check_ppi_trigger(int irq)
@@ -470,14 +470,15 @@ static int arch_timer_starting_cpu(unsigned int cpu)
struct clock_event_device *clk = this_cpu_ptr(arch_timer_evt);
u32 flags;
 
-   __arch_timer_setup(ARCH_CP15_TIMER, clk);
+   __arch_timer_setup(ARCH_TIMER_TYPE_CP15, clk);
 
flags = check_ppi_trigger(arch_timer_ppi[arch_timer_uses_ppi]);
enable_percpu_irq(arch_timer_ppi[arch_timer_uses_ppi], flags);
 
if (arch_timer_has_nonsecure_ppi()) {
-   flags = check_ppi_trigger(arch_timer_ppi[PHYS_NONSECURE_PPI]);
-   enable_percpu_irq(arch_timer_ppi[PHYS_NONSECURE_PPI], flags);
+   flags = 
check_ppi_trigger(arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI]);
+   enable_percpu_irq(arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI],
+ flags);
}
 
arch_counter_set_user_access();
@@ -514,16 +515,17 @@ arch_timer_detect_rate(void __iomem *cntbase, struct 
device_node *np)
 static void arch_timer_banner(unsigned type)
 {
pr_info("%s%s%s timer(s) running at %lu.%02luMHz (%s%s%s).\n",
-   type & ARCH_CP15_TIMER ? "cp15" : "",
-   type == (ARCH_CP15_TIMER | ARCH_MEM_TIMER) ?  " and " : "",
-   type & ARCH_MEM_TIMER ? "mmio" : "",
+   type & ARCH_TIMER_TYPE_CP15 ? "cp15" : "",
+   type == 

[PATCH v19 04/15] clocksource/drivers/arm_arch_timer: rename some enums and defines.

2016-12-20 Thread fu . wei
From: Fu Wei 

Rename some enums and defines, to unify the format of enums and defines
in arm_arch_timer.h, also update all the users of these enums and defines:
drivers/clocksource/arm_arch_timer.c
virt/kvm/arm/hyp/timer-sr.c

No functional change.

Signed-off-by: Fu Wei 
Tested-by: Xiongfeng Wang 
---
 drivers/clocksource/arm_arch_timer.c | 111 ++-
 include/clocksource/arm_arch_timer.h |  24 
 virt/kvm/arm/hyp/timer-sr.c  |   6 +-
 3 files changed, 73 insertions(+), 68 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 7203f95..c7b4e50 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -66,11 +66,11 @@ struct arch_timer {
 #define to_arch_timer(e) container_of(e, struct arch_timer, evt)
 
 static u32 arch_timer_rate;
-static int arch_timer_ppi[MAX_TIMER_PPI];
+static int arch_timer_ppi[ARCH_TIMER_MAX_TIMER_PPI];
 
 static struct clock_event_device __percpu *arch_timer_evt;
 
-static enum arch_timer_ppi_nr arch_timer_uses_ppi = VIRT_PPI;
+static enum arch_timer_ppi_nr arch_timer_uses_ppi = ARCH_TIMER_VIRT_PPI;
 static bool arch_timer_c3stop;
 static bool arch_timer_mem_use_virtual;
 static bool arch_counter_suspend_stop;
@@ -341,7 +341,7 @@ static void fsl_a008585_set_sne(struct clock_event_device 
*clk)
if (!static_branch_unlikely(_timer_read_ool_enabled))
return;
 
-   if (arch_timer_uses_ppi == VIRT_PPI)
+   if (arch_timer_uses_ppi == ARCH_TIMER_VIRT_PPI)
clk->set_next_event = fsl_a008585_set_next_event_virt;
else
clk->set_next_event = fsl_a008585_set_next_event_phys;
@@ -353,7 +353,7 @@ static void __arch_timer_setup(unsigned type,
 {
clk->features = CLOCK_EVT_FEAT_ONESHOT;
 
-   if (type == ARCH_CP15_TIMER) {
+   if (type == ARCH_TIMER_TYPE_CP15) {
if (arch_timer_c3stop)
clk->features |= CLOCK_EVT_FEAT_C3STOP;
clk->name = "arch_sys_timer";
@@ -361,14 +361,14 @@ static void __arch_timer_setup(unsigned type,
clk->cpumask = cpumask_of(smp_processor_id());
clk->irq = arch_timer_ppi[arch_timer_uses_ppi];
switch (arch_timer_uses_ppi) {
-   case VIRT_PPI:
+   case ARCH_TIMER_VIRT_PPI:
clk->set_state_shutdown = arch_timer_shutdown_virt;
clk->set_state_oneshot_stopped = 
arch_timer_shutdown_virt;
clk->set_next_event = arch_timer_set_next_event_virt;
break;
-   case PHYS_SECURE_PPI:
-   case PHYS_NONSECURE_PPI:
-   case HYP_PPI:
+   case ARCH_TIMER_PHYS_SECURE_PPI:
+   case ARCH_TIMER_PHYS_NONSECURE_PPI:
+   case ARCH_TIMER_HYP_PPI:
clk->set_state_shutdown = arch_timer_shutdown_phys;
clk->set_state_oneshot_stopped = 
arch_timer_shutdown_phys;
clk->set_next_event = arch_timer_set_next_event_phys;
@@ -448,8 +448,8 @@ static void arch_counter_set_user_access(void)
 
 static bool arch_timer_has_nonsecure_ppi(void)
 {
-   return (arch_timer_uses_ppi == PHYS_SECURE_PPI &&
-   arch_timer_ppi[PHYS_NONSECURE_PPI]);
+   return (arch_timer_uses_ppi == ARCH_TIMER_PHYS_SECURE_PPI &&
+   arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI]);
 }
 
 static u32 check_ppi_trigger(int irq)
@@ -470,14 +470,15 @@ static int arch_timer_starting_cpu(unsigned int cpu)
struct clock_event_device *clk = this_cpu_ptr(arch_timer_evt);
u32 flags;
 
-   __arch_timer_setup(ARCH_CP15_TIMER, clk);
+   __arch_timer_setup(ARCH_TIMER_TYPE_CP15, clk);
 
flags = check_ppi_trigger(arch_timer_ppi[arch_timer_uses_ppi]);
enable_percpu_irq(arch_timer_ppi[arch_timer_uses_ppi], flags);
 
if (arch_timer_has_nonsecure_ppi()) {
-   flags = check_ppi_trigger(arch_timer_ppi[PHYS_NONSECURE_PPI]);
-   enable_percpu_irq(arch_timer_ppi[PHYS_NONSECURE_PPI], flags);
+   flags = 
check_ppi_trigger(arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI]);
+   enable_percpu_irq(arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI],
+ flags);
}
 
arch_counter_set_user_access();
@@ -514,16 +515,17 @@ arch_timer_detect_rate(void __iomem *cntbase, struct 
device_node *np)
 static void arch_timer_banner(unsigned type)
 {
pr_info("%s%s%s timer(s) running at %lu.%02luMHz (%s%s%s).\n",
-   type & ARCH_CP15_TIMER ? "cp15" : "",
-   type == (ARCH_CP15_TIMER | ARCH_MEM_TIMER) ?  " and " : "",
-   type & ARCH_MEM_TIMER ? "mmio" : "",
+   type & ARCH_TIMER_TYPE_CP15 ? "cp15" : "",
+   type == (ARCH_TIMER_TYPE_CP15 | ARCH_TIMER_TYPE_MEM) ?
+   

[PATCH v19 03/15] clocksource/drivers/arm_arch_timer: Improve printk relevant code

2016-12-20 Thread fu . wei
From: Fu Wei 

This patch defines pr_fmt(fmt) for all pr_* functions,
then the pr_* doesn't need to add "arch_timer:" everytime.

According to the suggestion from checkpatch.pl:
(1) delete some Blank Spaces in arch_timer_banner;
(2) delete a redundant Tab in a bland line of arch_timer_init(void)

No functional change.

Signed-off-by: Fu Wei 
Acked-by: Mark Rutland 
Tested-by: Xiongfeng Wang 
---
 drivers/clocksource/arm_arch_timer.c | 49 ++--
 1 file changed, 25 insertions(+), 24 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 9aba1c0..7203f95 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -32,6 +32,9 @@
 
 #include 
 
+#undef pr_fmt
+#define pr_fmt(fmt) "arch_timer: " fmt
+
 #define CNTTIDR0x08
 #define CNTTIDR_VIRT(n)(BIT(1) << ((n) * 4))
 
@@ -505,22 +508,22 @@ arch_timer_detect_rate(void __iomem *cntbase, struct 
device_node *np)
 
/* Check the timer frequency. */
if (arch_timer_rate == 0)
-   pr_warn("Architected timer frequency not available\n");
+   pr_warn("frequency not available\n");
 }
 
 static void arch_timer_banner(unsigned type)
 {
-   pr_info("Architected %s%s%s timer(s) running at %lu.%02luMHz 
(%s%s%s).\n",
-type & ARCH_CP15_TIMER ? "cp15" : "",
-type == (ARCH_CP15_TIMER | ARCH_MEM_TIMER) ?  " and " : "",
-type & ARCH_MEM_TIMER ? "mmio" : "",
-(unsigned long)arch_timer_rate / 100,
-(unsigned long)(arch_timer_rate / 1) % 100,
-type & ARCH_CP15_TIMER ?
-(arch_timer_uses_ppi == VIRT_PPI) ? "virt" : "phys" :
+   pr_info("%s%s%s timer(s) running at %lu.%02luMHz (%s%s%s).\n",
+   type & ARCH_CP15_TIMER ? "cp15" : "",
+   type == (ARCH_CP15_TIMER | ARCH_MEM_TIMER) ?  " and " : "",
+   type & ARCH_MEM_TIMER ? "mmio" : "",
+   (unsigned long)arch_timer_rate / 100,
+   (unsigned long)(arch_timer_rate / 1) % 100,
+   type & ARCH_CP15_TIMER ?
+   (arch_timer_uses_ppi == VIRT_PPI) ? "virt" : "phys" :
"",
-type == (ARCH_CP15_TIMER | ARCH_MEM_TIMER) ?  "/" : "",
-type & ARCH_MEM_TIMER ?
+   type == (ARCH_CP15_TIMER | ARCH_MEM_TIMER) ?  "/" : "",
+   type & ARCH_MEM_TIMER ?
arch_timer_mem_use_virtual ? "virt" : "phys" :
"");
 }
@@ -621,8 +624,7 @@ static void __init arch_counter_register(unsigned type)
 
 static void arch_timer_stop(struct clock_event_device *clk)
 {
-   pr_debug("arch_timer_teardown disable IRQ%d cpu #%d\n",
-clk->irq, smp_processor_id());
+   pr_debug("disable IRQ%d cpu #%d\n", clk->irq, smp_processor_id());
 
disable_percpu_irq(arch_timer_ppi[arch_timer_uses_ppi]);
if (arch_timer_has_nonsecure_ppi())
@@ -715,8 +717,7 @@ static int __init arch_timer_register(void)
}
 
if (err) {
-   pr_err("arch_timer: can't register interrupt %d (%d)\n",
-  ppi, err);
+   pr_err("can't register interrupt %d (%d)\n", ppi, err);
goto out_free;
}
 
@@ -769,7 +770,7 @@ static int __init arch_timer_mem_register(void __iomem 
*base, unsigned int irq)
 
ret = request_irq(irq, func, IRQF_TIMER, "arch_mem_timer", >evt);
if (ret) {
-   pr_err("arch_timer: Failed to request mem timer irq\n");
+   pr_err("Failed to request mem timer irq\n");
kfree(t);
}
 
@@ -847,7 +848,7 @@ static int __init arch_timer_init(void)
}
 
if (!has_ppi) {
-   pr_warn("arch_timer: No interrupt available, giving 
up\n");
+   pr_warn("No interrupt available, giving up\n");
return -EINVAL;
}
}
@@ -861,7 +862,7 @@ static int __init arch_timer_init(void)
return ret;
 
arch_timer_kvm_info.virtual_irq = arch_timer_ppi[VIRT_PPI];
-   
+
return 0;
 }
 
@@ -870,7 +871,7 @@ static int __init arch_timer_of_init(struct device_node *np)
int i;
 
if (arch_timers_present & ARCH_CP15_TIMER) {
-   pr_warn("arch_timer: multiple nodes in dt, skipping\n");
+   pr_warn("multiple nodes in dt, skipping\n");
return 0;
}
 
@@ -918,7 +919,7 @@ static int __init arch_timer_mem_init(struct device_node 
*np)
arch_timers_present |= ARCH_MEM_TIMER;
cntctlbase = of_iomap(np, 0);
if (!cntctlbase) {
-   pr_err("arch_timer: Can't find CNTCTLBase\n");
+   

[PATCH v19 05/15] clocksource/drivers/arm_arch_timer: rework PPI determination

2016-12-20 Thread fu . wei
From: Fu Wei 

Currently, the arch timer driver uses ARCH_TIMER_PHYS_SECURE_PPI to
mean the driver will use the secure PPI *and* potentialy also use the
non-secure PPI. This is somewhat confusing.

For arm64, where it never makes sense to use the secure PPI, this
means we must always request the useless secure PPI, adding to the
confusion. For ACPI, where we may not even have a valid secure PPI
number, this is additionally problematic. We need the driver to be
able to use *only* the non-secure PPI.

The logic to choose which PPI to use is intertwined with other logic
in arch_timer_init(). This patch factors the PPI determination out
into a new function named arch_timer_select_ppi, and then reworks it
so that we can handle having only a non-secure PPI.

This patch also moves arch_timer_ppi verification out to caller,
because we can verify the configuration from device-tree for ARM by this
way.

Meanwhile, because we will select ARCH_TIMER_PHYS_NONSECURE_PPI for ARM64,
the logic in arch_timer_register also need to be updated.

Signed-off-by: Fu Wei 
Tested-by: Xiongfeng Wang 
---
 drivers/clocksource/arm_arch_timer.c | 77 +---
 1 file changed, 46 insertions(+), 31 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index c7b4e50..c7b4482 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -702,7 +702,7 @@ static int __init arch_timer_register(void)
case ARCH_TIMER_PHYS_NONSECURE_PPI:
err = request_percpu_irq(ppi, arch_timer_handler_phys,
 "arch_timer", arch_timer_evt);
-   if (!err && arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI]) {
+   if (!err && arch_timer_has_nonsecure_ppi()) {
ppi = arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI];
err = request_percpu_irq(ppi, arch_timer_handler_phys,
 "arch_timer", arch_timer_evt);
@@ -824,39 +824,41 @@ static int __init arch_timer_common_init(void)
return arch_timer_arch_init();
 }
 
-static int __init arch_timer_init(void)
+/**
+ * arch_timer_select_ppi() - Select suitable PPI for the current system.
+ *
+ * If HYP mode is available, we know that the physical timer
+ * has been configured to be accessible from PL1. Use it, so
+ * that a guest can use the virtual timer instead.
+ *
+ * On ARMv8.1 with VH extensions, the kernel runs in HYP. VHE
+ * accesses to CNTP_*_EL1 registers are silently redirected to
+ * their CNTHP_*_EL2 counterparts, and use a different PPI
+ * number.
+ *
+ * If no interrupt provided for virtual timer, we'll have to
+ * stick to the physical timer. It'd better be accessible...
+ * For arm64 we never use the secure interrupt.
+ *
+ * Return: a suitable PPI type for the current system.
+ */
+static enum arch_timer_ppi_nr __init arch_timer_select_ppi(void)
 {
-   int ret;
-   /*
-* If HYP mode is available, we know that the physical timer
-* has been configured to be accessible from PL1. Use it, so
-* that a guest can use the virtual timer instead.
-*
-* If no interrupt provided for virtual timer, we'll have to
-* stick to the physical timer. It'd better be accessible...
-*
-* On ARMv8.1 with VH extensions, the kernel runs in HYP. VHE
-* accesses to CNTP_*_EL1 registers are silently redirected to
-* their CNTHP_*_EL2 counterparts, and use a different PPI
-* number.
-*/
-   if (is_hyp_mode_available() || !arch_timer_ppi[ARCH_TIMER_VIRT_PPI]) {
-   bool has_ppi;
+   if (is_hyp_mode_available() && is_kernel_in_hyp_mode())
+   return ARCH_TIMER_HYP_PPI;
 
-   if (is_kernel_in_hyp_mode()) {
-   arch_timer_uses_ppi = ARCH_TIMER_HYP_PPI;
-   has_ppi = !!arch_timer_ppi[ARCH_TIMER_HYP_PPI];
-   } else {
-   arch_timer_uses_ppi = ARCH_TIMER_PHYS_SECURE_PPI;
-   has_ppi = (!!arch_timer_ppi[ARCH_TIMER_PHYS_SECURE_PPI] 
||
-  
!!arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI]);
-   }
+   if (arch_timer_ppi[ARCH_TIMER_VIRT_PPI])
+   return ARCH_TIMER_VIRT_PPI;
 
-   if (!has_ppi) {
-   pr_warn("No interrupt available, giving up\n");
-   return -EINVAL;
-   }
-   }
+   if (IS_ENABLED(CONFIG_ARM64))
+   return ARCH_TIMER_PHYS_NONSECURE_PPI;
+
+   return ARCH_TIMER_PHYS_SECURE_PPI;
+}
+
+static int __init arch_timer_init(void)
+{
+   int ret;
 
ret = arch_timer_register();
if (ret)
@@ -904,6 +906,13 @@ static int __init arch_timer_of_init(struct device_node 
*np)
if 

[PATCH v19 06/15] clocksource/drivers/arm_arch_timer: Rework counter frequency detection.

2016-12-20 Thread fu . wei
From: Fu Wei 

Currently, the counter frequency detection call(arch_timer_detect_rate)
combines all the ways to get counter frequency: device-tree property,
system coprocessor register, MMIO timer. But in the most of use cases,
we don't need all the ways to try:
For example, reading device-tree property will be needed only when
system boot with device-tree, getting frequency from MMIO timer register
will beneeded only when we init MMIO timer.

This patch separates paths to determine frequency:
Separate out device-tree code, keep them in device-tree init function.
Separate out the MMIO frequency and the sysreg frequency detection call,
and use the appropriate one for the counter.

Signed-off-by: Fu Wei 
Tested-by: Xiongfeng Wang 
---
 drivers/clocksource/arm_arch_timer.c | 49 +++-
 1 file changed, 31 insertions(+), 18 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index c7b4482..9a1f138 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -488,27 +488,31 @@ static int arch_timer_starting_cpu(unsigned int cpu)
return 0;
 }
 
-static void
-arch_timer_detect_rate(void __iomem *cntbase, struct device_node *np)
+static void arch_timer_detect_rate(void)
 {
-   /* Who has more than one independent system counter? */
-   if (arch_timer_rate)
-   return;
+   /*
+* Try to get the timer frequency from
+* cntfrq_el0(system coprocessor register).
+*/
+   if (!arch_timer_rate)
+   arch_timer_rate = arch_timer_get_cntfrq();
+
+   /* Check the timer frequency. */
+   if (!arch_timer_rate)
+   pr_warn("frequency not available\n");
+}
 
+static void arch_timer_mem_detect_rate(void __iomem *cntbase)
+{
/*
-* Try to determine the frequency from the device tree or CNTFRQ,
-* if ACPI is enabled, get the frequency from CNTFRQ ONLY.
+* Try to determine the frequency from
+* CNTFRQ in memory-mapped timer.
 */
-   if (!acpi_disabled ||
-   of_property_read_u32(np, "clock-frequency", _timer_rate)) {
-   if (cntbase)
-   arch_timer_rate = readl_relaxed(cntbase + CNTFRQ);
-   else
-   arch_timer_rate = arch_timer_get_cntfrq();
-   }
+   if (!arch_timer_rate)
+   arch_timer_rate = readl_relaxed(cntbase + CNTFRQ);
 
/* Check the timer frequency. */
-   if (arch_timer_rate == 0)
+   if (!arch_timer_rate)
pr_warn("frequency not available\n");
 }
 
@@ -886,7 +890,9 @@ static int __init arch_timer_of_init(struct device_node *np)
for (i = ARCH_TIMER_PHYS_SECURE_PPI; i < ARCH_TIMER_MAX_TIMER_PPI; i++)
arch_timer_ppi[i] = irq_of_parse_and_map(np, i);
 
-   arch_timer_detect_rate(NULL, np);
+   if (!arch_timer_rate &&
+   of_property_read_u32(np, "clock-frequency", _timer_rate))
+   arch_timer_detect_rate();
 
arch_timer_c3stop = !of_property_read_bool(np, "always-on");
 
@@ -994,7 +1000,14 @@ static int __init arch_timer_mem_init(struct device_node 
*np)
goto out;
}
 
-   arch_timer_detect_rate(base, np);
+   /*
+* Try to determine the frequency from the device tree,
+* if fail, get the frequency from CNTFRQ.
+*/
+   if (!arch_timer_rate &&
+   of_property_read_u32(np, "clock-frequency", _timer_rate))
+   arch_timer_mem_detect_rate(base);
+
ret = arch_timer_mem_register(base, irq);
if (ret)
goto out;
@@ -1056,7 +1069,7 @@ static int __init arch_timer_acpi_init(struct 
acpi_table_header *table)
gtdt->non_secure_el2_flags);
 
/* Get the frequency from CNTFRQ */
-   arch_timer_detect_rate(NULL, NULL);
+   arch_timer_detect_rate();
 
arch_timer_uses_ppi = arch_timer_select_ppi();
if (!arch_timer_ppi[arch_timer_uses_ppi]) {
-- 
2.9.3



[PATCH v19 01/15] clocksource/drivers/arm_arch_timer: Move enums and defines to header file

2016-12-20 Thread fu . wei
From: Fu Wei 

To support the arm_arch_timer via ACPI we need to share defines and enums
between the driver and the ACPI parser code.

Split out the relevant defines and enums into arm_arch_timer.h, and
change "enum ppi_nr" to "enum arch_timer_ppi_nr" to avoid the potential
name clashes.
Also switch "enum ppi_nr" to "enum arch_timer_ppi_nr" in
arm_arch_timer.c.
No functional change.

Signed-off-by: Fu Wei 
Acked-by: Mark Rutland 
Tested-by: Xiongfeng Wang 
---
 drivers/clocksource/arm_arch_timer.c | 13 +
 include/clocksource/arm_arch_timer.h | 12 
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 02fef68..6c8cb01 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -51,8 +51,6 @@
 #define CNTV_TVAL  0x38
 #define CNTV_CTL   0x3c
 
-#define ARCH_CP15_TIMERBIT(0)
-#define ARCH_MEM_TIMER BIT(1)
 static unsigned arch_timers_present __initdata;
 
 static void __iomem *arch_counter_base;
@@ -65,20 +63,11 @@ struct arch_timer {
 #define to_arch_timer(e) container_of(e, struct arch_timer, evt)
 
 static u32 arch_timer_rate;
-
-enum ppi_nr {
-   PHYS_SECURE_PPI,
-   PHYS_NONSECURE_PPI,
-   VIRT_PPI,
-   HYP_PPI,
-   MAX_TIMER_PPI
-};
-
 static int arch_timer_ppi[MAX_TIMER_PPI];
 
 static struct clock_event_device __percpu *arch_timer_evt;
 
-static enum ppi_nr arch_timer_uses_ppi = VIRT_PPI;
+static enum arch_timer_ppi_nr arch_timer_uses_ppi = VIRT_PPI;
 static bool arch_timer_c3stop;
 static bool arch_timer_mem_use_virtual;
 static bool arch_counter_suspend_stop;
diff --git a/include/clocksource/arm_arch_timer.h 
b/include/clocksource/arm_arch_timer.h
index caedb74..557f869 100644
--- a/include/clocksource/arm_arch_timer.h
+++ b/include/clocksource/arm_arch_timer.h
@@ -16,9 +16,13 @@
 #ifndef __CLKSOURCE_ARM_ARCH_TIMER_H
 #define __CLKSOURCE_ARM_ARCH_TIMER_H
 
+#include 
 #include 
 #include 
 
+#define ARCH_CP15_TIMERBIT(0)
+#define ARCH_MEM_TIMER BIT(1)
+
 #define ARCH_TIMER_CTRL_ENABLE (1 << 0)
 #define ARCH_TIMER_CTRL_IT_MASK(1 << 1)
 #define ARCH_TIMER_CTRL_IT_STAT(1 << 2)
@@ -34,6 +38,14 @@ enum arch_timer_reg {
ARCH_TIMER_REG_TVAL,
 };
 
+enum arch_timer_ppi_nr {
+   PHYS_SECURE_PPI,
+   PHYS_NONSECURE_PPI,
+   VIRT_PPI,
+   HYP_PPI,
+   MAX_TIMER_PPI
+};
+
 #define ARCH_TIMER_PHYS_ACCESS 0
 #define ARCH_TIMER_VIRT_ACCESS 1
 #define ARCH_TIMER_MEM_PHYS_ACCESS 2
-- 
2.9.3



[PATCH v19 02/15] clocksource/drivers/arm_arch_timer: Add a new enum for spi type

2016-12-20 Thread fu . wei
From: Fu Wei 

This patch add a new enum "arch_timer_spi_nr" and use it in the driver.
Just for code's readability, no functional change.

Signed-off-by: Fu Wei 
Acked-by: Mark Rutland 
---
 drivers/clocksource/arm_arch_timer.c | 4 ++--
 include/clocksource/arm_arch_timer.h | 6 ++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 6c8cb01..9aba1c0 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -968,9 +968,9 @@ static int __init arch_timer_mem_init(struct device_node 
*np)
}
 
if (arch_timer_mem_use_virtual)
-   irq = irq_of_parse_and_map(best_frame, 1);
+   irq = irq_of_parse_and_map(best_frame, ARCH_TIMER_VIRT_SPI);
else
-   irq = irq_of_parse_and_map(best_frame, 0);
+   irq = irq_of_parse_and_map(best_frame, ARCH_TIMER_PHYS_SPI);
 
ret = -EINVAL;
if (!irq) {
diff --git a/include/clocksource/arm_arch_timer.h 
b/include/clocksource/arm_arch_timer.h
index 557f869..d23c381 100644
--- a/include/clocksource/arm_arch_timer.h
+++ b/include/clocksource/arm_arch_timer.h
@@ -46,6 +46,12 @@ enum arch_timer_ppi_nr {
MAX_TIMER_PPI
 };
 
+enum arch_timer_spi_nr {
+   ARCH_TIMER_PHYS_SPI,
+   ARCH_TIMER_VIRT_SPI,
+   ARCH_TIMER_MAX_TIMER_SPI
+};
+
 #define ARCH_TIMER_PHYS_ACCESS 0
 #define ARCH_TIMER_VIRT_ACCESS 1
 #define ARCH_TIMER_MEM_PHYS_ACCESS 2
-- 
2.9.3



[PATCH v19 06/15] clocksource/drivers/arm_arch_timer: Rework counter frequency detection.

2016-12-20 Thread fu . wei
From: Fu Wei 

Currently, the counter frequency detection call(arch_timer_detect_rate)
combines all the ways to get counter frequency: device-tree property,
system coprocessor register, MMIO timer. But in the most of use cases,
we don't need all the ways to try:
For example, reading device-tree property will be needed only when
system boot with device-tree, getting frequency from MMIO timer register
will beneeded only when we init MMIO timer.

This patch separates paths to determine frequency:
Separate out device-tree code, keep them in device-tree init function.
Separate out the MMIO frequency and the sysreg frequency detection call,
and use the appropriate one for the counter.

Signed-off-by: Fu Wei 
Tested-by: Xiongfeng Wang 
---
 drivers/clocksource/arm_arch_timer.c | 49 +++-
 1 file changed, 31 insertions(+), 18 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index c7b4482..9a1f138 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -488,27 +488,31 @@ static int arch_timer_starting_cpu(unsigned int cpu)
return 0;
 }
 
-static void
-arch_timer_detect_rate(void __iomem *cntbase, struct device_node *np)
+static void arch_timer_detect_rate(void)
 {
-   /* Who has more than one independent system counter? */
-   if (arch_timer_rate)
-   return;
+   /*
+* Try to get the timer frequency from
+* cntfrq_el0(system coprocessor register).
+*/
+   if (!arch_timer_rate)
+   arch_timer_rate = arch_timer_get_cntfrq();
+
+   /* Check the timer frequency. */
+   if (!arch_timer_rate)
+   pr_warn("frequency not available\n");
+}
 
+static void arch_timer_mem_detect_rate(void __iomem *cntbase)
+{
/*
-* Try to determine the frequency from the device tree or CNTFRQ,
-* if ACPI is enabled, get the frequency from CNTFRQ ONLY.
+* Try to determine the frequency from
+* CNTFRQ in memory-mapped timer.
 */
-   if (!acpi_disabled ||
-   of_property_read_u32(np, "clock-frequency", _timer_rate)) {
-   if (cntbase)
-   arch_timer_rate = readl_relaxed(cntbase + CNTFRQ);
-   else
-   arch_timer_rate = arch_timer_get_cntfrq();
-   }
+   if (!arch_timer_rate)
+   arch_timer_rate = readl_relaxed(cntbase + CNTFRQ);
 
/* Check the timer frequency. */
-   if (arch_timer_rate == 0)
+   if (!arch_timer_rate)
pr_warn("frequency not available\n");
 }
 
@@ -886,7 +890,9 @@ static int __init arch_timer_of_init(struct device_node *np)
for (i = ARCH_TIMER_PHYS_SECURE_PPI; i < ARCH_TIMER_MAX_TIMER_PPI; i++)
arch_timer_ppi[i] = irq_of_parse_and_map(np, i);
 
-   arch_timer_detect_rate(NULL, np);
+   if (!arch_timer_rate &&
+   of_property_read_u32(np, "clock-frequency", _timer_rate))
+   arch_timer_detect_rate();
 
arch_timer_c3stop = !of_property_read_bool(np, "always-on");
 
@@ -994,7 +1000,14 @@ static int __init arch_timer_mem_init(struct device_node 
*np)
goto out;
}
 
-   arch_timer_detect_rate(base, np);
+   /*
+* Try to determine the frequency from the device tree,
+* if fail, get the frequency from CNTFRQ.
+*/
+   if (!arch_timer_rate &&
+   of_property_read_u32(np, "clock-frequency", _timer_rate))
+   arch_timer_mem_detect_rate(base);
+
ret = arch_timer_mem_register(base, irq);
if (ret)
goto out;
@@ -1056,7 +1069,7 @@ static int __init arch_timer_acpi_init(struct 
acpi_table_header *table)
gtdt->non_secure_el2_flags);
 
/* Get the frequency from CNTFRQ */
-   arch_timer_detect_rate(NULL, NULL);
+   arch_timer_detect_rate();
 
arch_timer_uses_ppi = arch_timer_select_ppi();
if (!arch_timer_ppi[arch_timer_uses_ppi]) {
-- 
2.9.3



[PATCH v19 01/15] clocksource/drivers/arm_arch_timer: Move enums and defines to header file

2016-12-20 Thread fu . wei
From: Fu Wei 

To support the arm_arch_timer via ACPI we need to share defines and enums
between the driver and the ACPI parser code.

Split out the relevant defines and enums into arm_arch_timer.h, and
change "enum ppi_nr" to "enum arch_timer_ppi_nr" to avoid the potential
name clashes.
Also switch "enum ppi_nr" to "enum arch_timer_ppi_nr" in
arm_arch_timer.c.
No functional change.

Signed-off-by: Fu Wei 
Acked-by: Mark Rutland 
Tested-by: Xiongfeng Wang 
---
 drivers/clocksource/arm_arch_timer.c | 13 +
 include/clocksource/arm_arch_timer.h | 12 
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 02fef68..6c8cb01 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -51,8 +51,6 @@
 #define CNTV_TVAL  0x38
 #define CNTV_CTL   0x3c
 
-#define ARCH_CP15_TIMERBIT(0)
-#define ARCH_MEM_TIMER BIT(1)
 static unsigned arch_timers_present __initdata;
 
 static void __iomem *arch_counter_base;
@@ -65,20 +63,11 @@ struct arch_timer {
 #define to_arch_timer(e) container_of(e, struct arch_timer, evt)
 
 static u32 arch_timer_rate;
-
-enum ppi_nr {
-   PHYS_SECURE_PPI,
-   PHYS_NONSECURE_PPI,
-   VIRT_PPI,
-   HYP_PPI,
-   MAX_TIMER_PPI
-};
-
 static int arch_timer_ppi[MAX_TIMER_PPI];
 
 static struct clock_event_device __percpu *arch_timer_evt;
 
-static enum ppi_nr arch_timer_uses_ppi = VIRT_PPI;
+static enum arch_timer_ppi_nr arch_timer_uses_ppi = VIRT_PPI;
 static bool arch_timer_c3stop;
 static bool arch_timer_mem_use_virtual;
 static bool arch_counter_suspend_stop;
diff --git a/include/clocksource/arm_arch_timer.h 
b/include/clocksource/arm_arch_timer.h
index caedb74..557f869 100644
--- a/include/clocksource/arm_arch_timer.h
+++ b/include/clocksource/arm_arch_timer.h
@@ -16,9 +16,13 @@
 #ifndef __CLKSOURCE_ARM_ARCH_TIMER_H
 #define __CLKSOURCE_ARM_ARCH_TIMER_H
 
+#include 
 #include 
 #include 
 
+#define ARCH_CP15_TIMERBIT(0)
+#define ARCH_MEM_TIMER BIT(1)
+
 #define ARCH_TIMER_CTRL_ENABLE (1 << 0)
 #define ARCH_TIMER_CTRL_IT_MASK(1 << 1)
 #define ARCH_TIMER_CTRL_IT_STAT(1 << 2)
@@ -34,6 +38,14 @@ enum arch_timer_reg {
ARCH_TIMER_REG_TVAL,
 };
 
+enum arch_timer_ppi_nr {
+   PHYS_SECURE_PPI,
+   PHYS_NONSECURE_PPI,
+   VIRT_PPI,
+   HYP_PPI,
+   MAX_TIMER_PPI
+};
+
 #define ARCH_TIMER_PHYS_ACCESS 0
 #define ARCH_TIMER_VIRT_ACCESS 1
 #define ARCH_TIMER_MEM_PHYS_ACCESS 2
-- 
2.9.3



[PATCH v19 02/15] clocksource/drivers/arm_arch_timer: Add a new enum for spi type

2016-12-20 Thread fu . wei
From: Fu Wei 

This patch add a new enum "arch_timer_spi_nr" and use it in the driver.
Just for code's readability, no functional change.

Signed-off-by: Fu Wei 
Acked-by: Mark Rutland 
---
 drivers/clocksource/arm_arch_timer.c | 4 ++--
 include/clocksource/arm_arch_timer.h | 6 ++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 6c8cb01..9aba1c0 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -968,9 +968,9 @@ static int __init arch_timer_mem_init(struct device_node 
*np)
}
 
if (arch_timer_mem_use_virtual)
-   irq = irq_of_parse_and_map(best_frame, 1);
+   irq = irq_of_parse_and_map(best_frame, ARCH_TIMER_VIRT_SPI);
else
-   irq = irq_of_parse_and_map(best_frame, 0);
+   irq = irq_of_parse_and_map(best_frame, ARCH_TIMER_PHYS_SPI);
 
ret = -EINVAL;
if (!irq) {
diff --git a/include/clocksource/arm_arch_timer.h 
b/include/clocksource/arm_arch_timer.h
index 557f869..d23c381 100644
--- a/include/clocksource/arm_arch_timer.h
+++ b/include/clocksource/arm_arch_timer.h
@@ -46,6 +46,12 @@ enum arch_timer_ppi_nr {
MAX_TIMER_PPI
 };
 
+enum arch_timer_spi_nr {
+   ARCH_TIMER_PHYS_SPI,
+   ARCH_TIMER_VIRT_SPI,
+   ARCH_TIMER_MAX_TIMER_SPI
+};
+
 #define ARCH_TIMER_PHYS_ACCESS 0
 #define ARCH_TIMER_VIRT_ACCESS 1
 #define ARCH_TIMER_MEM_PHYS_ACCESS 2
-- 
2.9.3



[PATCH v19 03/15] clocksource/drivers/arm_arch_timer: Improve printk relevant code

2016-12-20 Thread fu . wei
From: Fu Wei 

This patch defines pr_fmt(fmt) for all pr_* functions,
then the pr_* doesn't need to add "arch_timer:" everytime.

According to the suggestion from checkpatch.pl:
(1) delete some Blank Spaces in arch_timer_banner;
(2) delete a redundant Tab in a bland line of arch_timer_init(void)

No functional change.

Signed-off-by: Fu Wei 
Acked-by: Mark Rutland 
Tested-by: Xiongfeng Wang 
---
 drivers/clocksource/arm_arch_timer.c | 49 ++--
 1 file changed, 25 insertions(+), 24 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 9aba1c0..7203f95 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -32,6 +32,9 @@
 
 #include 
 
+#undef pr_fmt
+#define pr_fmt(fmt) "arch_timer: " fmt
+
 #define CNTTIDR0x08
 #define CNTTIDR_VIRT(n)(BIT(1) << ((n) * 4))
 
@@ -505,22 +508,22 @@ arch_timer_detect_rate(void __iomem *cntbase, struct 
device_node *np)
 
/* Check the timer frequency. */
if (arch_timer_rate == 0)
-   pr_warn("Architected timer frequency not available\n");
+   pr_warn("frequency not available\n");
 }
 
 static void arch_timer_banner(unsigned type)
 {
-   pr_info("Architected %s%s%s timer(s) running at %lu.%02luMHz 
(%s%s%s).\n",
-type & ARCH_CP15_TIMER ? "cp15" : "",
-type == (ARCH_CP15_TIMER | ARCH_MEM_TIMER) ?  " and " : "",
-type & ARCH_MEM_TIMER ? "mmio" : "",
-(unsigned long)arch_timer_rate / 100,
-(unsigned long)(arch_timer_rate / 1) % 100,
-type & ARCH_CP15_TIMER ?
-(arch_timer_uses_ppi == VIRT_PPI) ? "virt" : "phys" :
+   pr_info("%s%s%s timer(s) running at %lu.%02luMHz (%s%s%s).\n",
+   type & ARCH_CP15_TIMER ? "cp15" : "",
+   type == (ARCH_CP15_TIMER | ARCH_MEM_TIMER) ?  " and " : "",
+   type & ARCH_MEM_TIMER ? "mmio" : "",
+   (unsigned long)arch_timer_rate / 100,
+   (unsigned long)(arch_timer_rate / 1) % 100,
+   type & ARCH_CP15_TIMER ?
+   (arch_timer_uses_ppi == VIRT_PPI) ? "virt" : "phys" :
"",
-type == (ARCH_CP15_TIMER | ARCH_MEM_TIMER) ?  "/" : "",
-type & ARCH_MEM_TIMER ?
+   type == (ARCH_CP15_TIMER | ARCH_MEM_TIMER) ?  "/" : "",
+   type & ARCH_MEM_TIMER ?
arch_timer_mem_use_virtual ? "virt" : "phys" :
"");
 }
@@ -621,8 +624,7 @@ static void __init arch_counter_register(unsigned type)
 
 static void arch_timer_stop(struct clock_event_device *clk)
 {
-   pr_debug("arch_timer_teardown disable IRQ%d cpu #%d\n",
-clk->irq, smp_processor_id());
+   pr_debug("disable IRQ%d cpu #%d\n", clk->irq, smp_processor_id());
 
disable_percpu_irq(arch_timer_ppi[arch_timer_uses_ppi]);
if (arch_timer_has_nonsecure_ppi())
@@ -715,8 +717,7 @@ static int __init arch_timer_register(void)
}
 
if (err) {
-   pr_err("arch_timer: can't register interrupt %d (%d)\n",
-  ppi, err);
+   pr_err("can't register interrupt %d (%d)\n", ppi, err);
goto out_free;
}
 
@@ -769,7 +770,7 @@ static int __init arch_timer_mem_register(void __iomem 
*base, unsigned int irq)
 
ret = request_irq(irq, func, IRQF_TIMER, "arch_mem_timer", >evt);
if (ret) {
-   pr_err("arch_timer: Failed to request mem timer irq\n");
+   pr_err("Failed to request mem timer irq\n");
kfree(t);
}
 
@@ -847,7 +848,7 @@ static int __init arch_timer_init(void)
}
 
if (!has_ppi) {
-   pr_warn("arch_timer: No interrupt available, giving 
up\n");
+   pr_warn("No interrupt available, giving up\n");
return -EINVAL;
}
}
@@ -861,7 +862,7 @@ static int __init arch_timer_init(void)
return ret;
 
arch_timer_kvm_info.virtual_irq = arch_timer_ppi[VIRT_PPI];
-   
+
return 0;
 }
 
@@ -870,7 +871,7 @@ static int __init arch_timer_of_init(struct device_node *np)
int i;
 
if (arch_timers_present & ARCH_CP15_TIMER) {
-   pr_warn("arch_timer: multiple nodes in dt, skipping\n");
+   pr_warn("multiple nodes in dt, skipping\n");
return 0;
}
 
@@ -918,7 +919,7 @@ static int __init arch_timer_mem_init(struct device_node 
*np)
arch_timers_present |= ARCH_MEM_TIMER;
cntctlbase = of_iomap(np, 0);
if (!cntctlbase) {
-   pr_err("arch_timer: Can't find CNTCTLBase\n");
+   pr_err("Can't find CNTCTLBase\n");
return -ENXIO;
}
 
@@ 

[PATCH v19 05/15] clocksource/drivers/arm_arch_timer: rework PPI determination

2016-12-20 Thread fu . wei
From: Fu Wei 

Currently, the arch timer driver uses ARCH_TIMER_PHYS_SECURE_PPI to
mean the driver will use the secure PPI *and* potentialy also use the
non-secure PPI. This is somewhat confusing.

For arm64, where it never makes sense to use the secure PPI, this
means we must always request the useless secure PPI, adding to the
confusion. For ACPI, where we may not even have a valid secure PPI
number, this is additionally problematic. We need the driver to be
able to use *only* the non-secure PPI.

The logic to choose which PPI to use is intertwined with other logic
in arch_timer_init(). This patch factors the PPI determination out
into a new function named arch_timer_select_ppi, and then reworks it
so that we can handle having only a non-secure PPI.

This patch also moves arch_timer_ppi verification out to caller,
because we can verify the configuration from device-tree for ARM by this
way.

Meanwhile, because we will select ARCH_TIMER_PHYS_NONSECURE_PPI for ARM64,
the logic in arch_timer_register also need to be updated.

Signed-off-by: Fu Wei 
Tested-by: Xiongfeng Wang 
---
 drivers/clocksource/arm_arch_timer.c | 77 +---
 1 file changed, 46 insertions(+), 31 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index c7b4e50..c7b4482 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -702,7 +702,7 @@ static int __init arch_timer_register(void)
case ARCH_TIMER_PHYS_NONSECURE_PPI:
err = request_percpu_irq(ppi, arch_timer_handler_phys,
 "arch_timer", arch_timer_evt);
-   if (!err && arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI]) {
+   if (!err && arch_timer_has_nonsecure_ppi()) {
ppi = arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI];
err = request_percpu_irq(ppi, arch_timer_handler_phys,
 "arch_timer", arch_timer_evt);
@@ -824,39 +824,41 @@ static int __init arch_timer_common_init(void)
return arch_timer_arch_init();
 }
 
-static int __init arch_timer_init(void)
+/**
+ * arch_timer_select_ppi() - Select suitable PPI for the current system.
+ *
+ * If HYP mode is available, we know that the physical timer
+ * has been configured to be accessible from PL1. Use it, so
+ * that a guest can use the virtual timer instead.
+ *
+ * On ARMv8.1 with VH extensions, the kernel runs in HYP. VHE
+ * accesses to CNTP_*_EL1 registers are silently redirected to
+ * their CNTHP_*_EL2 counterparts, and use a different PPI
+ * number.
+ *
+ * If no interrupt provided for virtual timer, we'll have to
+ * stick to the physical timer. It'd better be accessible...
+ * For arm64 we never use the secure interrupt.
+ *
+ * Return: a suitable PPI type for the current system.
+ */
+static enum arch_timer_ppi_nr __init arch_timer_select_ppi(void)
 {
-   int ret;
-   /*
-* If HYP mode is available, we know that the physical timer
-* has been configured to be accessible from PL1. Use it, so
-* that a guest can use the virtual timer instead.
-*
-* If no interrupt provided for virtual timer, we'll have to
-* stick to the physical timer. It'd better be accessible...
-*
-* On ARMv8.1 with VH extensions, the kernel runs in HYP. VHE
-* accesses to CNTP_*_EL1 registers are silently redirected to
-* their CNTHP_*_EL2 counterparts, and use a different PPI
-* number.
-*/
-   if (is_hyp_mode_available() || !arch_timer_ppi[ARCH_TIMER_VIRT_PPI]) {
-   bool has_ppi;
+   if (is_hyp_mode_available() && is_kernel_in_hyp_mode())
+   return ARCH_TIMER_HYP_PPI;
 
-   if (is_kernel_in_hyp_mode()) {
-   arch_timer_uses_ppi = ARCH_TIMER_HYP_PPI;
-   has_ppi = !!arch_timer_ppi[ARCH_TIMER_HYP_PPI];
-   } else {
-   arch_timer_uses_ppi = ARCH_TIMER_PHYS_SECURE_PPI;
-   has_ppi = (!!arch_timer_ppi[ARCH_TIMER_PHYS_SECURE_PPI] 
||
-  
!!arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI]);
-   }
+   if (arch_timer_ppi[ARCH_TIMER_VIRT_PPI])
+   return ARCH_TIMER_VIRT_PPI;
 
-   if (!has_ppi) {
-   pr_warn("No interrupt available, giving up\n");
-   return -EINVAL;
-   }
-   }
+   if (IS_ENABLED(CONFIG_ARM64))
+   return ARCH_TIMER_PHYS_NONSECURE_PPI;
+
+   return ARCH_TIMER_PHYS_SECURE_PPI;
+}
+
+static int __init arch_timer_init(void)
+{
+   int ret;
 
ret = arch_timer_register();
if (ret)
@@ -904,6 +906,13 @@ static int __init arch_timer_of_init(struct device_node 
*np)
if (IS_ENABLED(CONFIG_ARM) &&
of_property_read_bool(np, 

[PATCH v19 00/15] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer

2016-12-20 Thread fu . wei
From: Fu Wei 

This patchset:
(1)Preparation for adding GTDT support in arm_arch_timer:
1. Move some enums and marcos to header file;
2. Add a new enum for spi type;
3. Improve printk relevant code;
4. Rename some enums and defines;
5. Rework PPI determination;
6. Rework counter frequency detection;
7. Refactor arch_timer_needs_probing, move it into DT init call
8. Introduce some new structs and refactor the MMIO timer init code
for reusing some common code.

(2)Introduce ACPI GTDT parser: drivers/acpi/arm64/acpi_gtdt.c
Parse all kinds of timer in GTDT table of ACPI:arch timer,
memory-mapped timer and SBSA Generic Watchdog timer.
This driver can help to simplify all the relevant timer drivers,
and separate all the ACPI GTDT knowledge from them.

(3)Simplify ACPI code for arm_arch_timer

(4)Add GTDT support for ARM memory-mapped timer.

This patchset has been tested on the following platforms with ACPI enabled:
(1)ARM Foundation v8 model

Changelog:
v19: https://lkml.org/lkml/2016/12/21/
 Fix a '\n' missing in a error message in arch_timer_mem_init.
 Add "request_mem_region" for ioremapping cntbase, according to
 f947ee1 clocksource/drivers/arm_arch_timer: Map frame with 
of_io_request_and_map()
 Rebase to 4.9.0-gfb779ff

v18: https://lkml.org/lkml/2016/12/8/446
 Fix 8/15 patch problem of "int ret;" in arch_timer_acpi_init.
 Rebase to 4.9.0-rc8-g9269898

v17: https://lkml.org/lkml/2016/11/25/140
 Take out some cleanups from 4/15.
 Merge 5/15 and 6/15, improve PPI determination code,
 improve commit message.
 Rework counter frequency detection.
 Move arch_timer_needs_of_probing into DT init call.
 Move Platform Timer scan loop back to timer init call to avoid allocating
 and free memory.
 Improve all the exported functions' comment.

v16: https://lkml.org/lkml/2016/11/16/268
 Fix patchset problem about static enum ppi_nr of 01/13 in v15.
 Refactor arch_timer_detect_rate.
 Refactor arch_timer_needs_probing.

v15: https://lkml.org/lkml/2016/11/15/366
 Re-order patches
 Add arm_arch_timer refactoring patches to prepare for GTDT:
 1. rename some  enums and defines, and some cleanups
 2. separate out arch_timer_uses_ppi init code and fix a potential bug
 3. Improve some new structs, refactor the timer init code.
 Since the some structs have been changed, GTDT parser for memory-mapped
 timer and SBSA Generic Watchdog timer have been update.

v14: https://lkml.org/lkml/2016/9/28/573
 Separate memory-mapped timer GTDT support into two patches
 1. Refactor the timer init code to prepare for GTDT
 2. Add GTDT support for memory-mapped timer

v13: http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1231717.html
 Improve arm_arch_timer code for memory-mapped
 timer GTDT support, refactor original memory-mapped timer
 dt support for reusing some common code.

v12: https://lkml.org/lkml/2016/9/13/250
 Rebase to latest Linux 4.8-rc6
 Delete the confusing "skipping" in the error message.

V11: https://lkml.org/lkml/2016/9/6/354
 Rebase to latest Linux 4.8-rc5
 Delete typedef (suggested by checkpatch.pl)

V10: https://lkml.org/lkml/2016/7/26/215
 Drop the "readq" patch.
 Rebase to latest Linux 4.7.

V9: https://lkml.org/lkml/2016/7/25/345
Improve pr_err message in acpi gtdt driver.
Update Commit message for 7/9
shorten the irq mapping function name
Improve GTDT driver for memory-mapped timer

v8: https://lkml.org/lkml/2016/7/19/660
Improve "pr_fmt(fmt)" definition: add "ACPI" in front of "GTDT",
and also improve printk message.
Simplify is_timer_block and is_watchdog.
Merge acpi_gtdt_desc_init and gtdt_arch_timer_init into acpi_gtdt_init();
Delete __init in include/linux/acpi.h for GTDT API
Make ARM64 select GTDT.
Delete "#include " from acpi_gtdt.c
Simplify GT block parse code.

v7: https://lkml.org/lkml/2016/7/13/769
Move the GTDT driver to drivers/acpi/arm64
Add add the ARM64-specific ACPI Support maintainers in MAINTAINERS
Merge 3 patches of GTDT parser driver.
Fix the for_each_platform_timer bug.

v6: https://lkml.org/lkml/2016/6/29/580
split the GTDT driver to 4 parts: basic, arch_timer, memory-mapped timer,
and SBSA Generic Watchdog timer
Improve driver by suggestions and example code from Daniel Lezcano

v5: https://lkml.org/lkml/2016/5/24/356
Sorting out all patches, simplify the API of GTDT driver:
GTDT driver just fills the data struct for arm_arch_timer driver.

v4: https://lists.linaro.org/pipermail/linaro-acpi/2016-March/006667.html
Delete the kvm relevant patches
Separate two patches for sorting out the code for arm_arch_timer.
Improve irq info export code to allow missing irq info in GTDT table.

v3: 

[PATCH v19 00/15] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer

2016-12-20 Thread fu . wei
From: Fu Wei 

This patchset:
(1)Preparation for adding GTDT support in arm_arch_timer:
1. Move some enums and marcos to header file;
2. Add a new enum for spi type;
3. Improve printk relevant code;
4. Rename some enums and defines;
5. Rework PPI determination;
6. Rework counter frequency detection;
7. Refactor arch_timer_needs_probing, move it into DT init call
8. Introduce some new structs and refactor the MMIO timer init code
for reusing some common code.

(2)Introduce ACPI GTDT parser: drivers/acpi/arm64/acpi_gtdt.c
Parse all kinds of timer in GTDT table of ACPI:arch timer,
memory-mapped timer and SBSA Generic Watchdog timer.
This driver can help to simplify all the relevant timer drivers,
and separate all the ACPI GTDT knowledge from them.

(3)Simplify ACPI code for arm_arch_timer

(4)Add GTDT support for ARM memory-mapped timer.

This patchset has been tested on the following platforms with ACPI enabled:
(1)ARM Foundation v8 model

Changelog:
v19: https://lkml.org/lkml/2016/12/21/
 Fix a '\n' missing in a error message in arch_timer_mem_init.
 Add "request_mem_region" for ioremapping cntbase, according to
 f947ee1 clocksource/drivers/arm_arch_timer: Map frame with 
of_io_request_and_map()
 Rebase to 4.9.0-gfb779ff

v18: https://lkml.org/lkml/2016/12/8/446
 Fix 8/15 patch problem of "int ret;" in arch_timer_acpi_init.
 Rebase to 4.9.0-rc8-g9269898

v17: https://lkml.org/lkml/2016/11/25/140
 Take out some cleanups from 4/15.
 Merge 5/15 and 6/15, improve PPI determination code,
 improve commit message.
 Rework counter frequency detection.
 Move arch_timer_needs_of_probing into DT init call.
 Move Platform Timer scan loop back to timer init call to avoid allocating
 and free memory.
 Improve all the exported functions' comment.

v16: https://lkml.org/lkml/2016/11/16/268
 Fix patchset problem about static enum ppi_nr of 01/13 in v15.
 Refactor arch_timer_detect_rate.
 Refactor arch_timer_needs_probing.

v15: https://lkml.org/lkml/2016/11/15/366
 Re-order patches
 Add arm_arch_timer refactoring patches to prepare for GTDT:
 1. rename some  enums and defines, and some cleanups
 2. separate out arch_timer_uses_ppi init code and fix a potential bug
 3. Improve some new structs, refactor the timer init code.
 Since the some structs have been changed, GTDT parser for memory-mapped
 timer and SBSA Generic Watchdog timer have been update.

v14: https://lkml.org/lkml/2016/9/28/573
 Separate memory-mapped timer GTDT support into two patches
 1. Refactor the timer init code to prepare for GTDT
 2. Add GTDT support for memory-mapped timer

v13: http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1231717.html
 Improve arm_arch_timer code for memory-mapped
 timer GTDT support, refactor original memory-mapped timer
 dt support for reusing some common code.

v12: https://lkml.org/lkml/2016/9/13/250
 Rebase to latest Linux 4.8-rc6
 Delete the confusing "skipping" in the error message.

V11: https://lkml.org/lkml/2016/9/6/354
 Rebase to latest Linux 4.8-rc5
 Delete typedef (suggested by checkpatch.pl)

V10: https://lkml.org/lkml/2016/7/26/215
 Drop the "readq" patch.
 Rebase to latest Linux 4.7.

V9: https://lkml.org/lkml/2016/7/25/345
Improve pr_err message in acpi gtdt driver.
Update Commit message for 7/9
shorten the irq mapping function name
Improve GTDT driver for memory-mapped timer

v8: https://lkml.org/lkml/2016/7/19/660
Improve "pr_fmt(fmt)" definition: add "ACPI" in front of "GTDT",
and also improve printk message.
Simplify is_timer_block and is_watchdog.
Merge acpi_gtdt_desc_init and gtdt_arch_timer_init into acpi_gtdt_init();
Delete __init in include/linux/acpi.h for GTDT API
Make ARM64 select GTDT.
Delete "#include " from acpi_gtdt.c
Simplify GT block parse code.

v7: https://lkml.org/lkml/2016/7/13/769
Move the GTDT driver to drivers/acpi/arm64
Add add the ARM64-specific ACPI Support maintainers in MAINTAINERS
Merge 3 patches of GTDT parser driver.
Fix the for_each_platform_timer bug.

v6: https://lkml.org/lkml/2016/6/29/580
split the GTDT driver to 4 parts: basic, arch_timer, memory-mapped timer,
and SBSA Generic Watchdog timer
Improve driver by suggestions and example code from Daniel Lezcano

v5: https://lkml.org/lkml/2016/5/24/356
Sorting out all patches, simplify the API of GTDT driver:
GTDT driver just fills the data struct for arm_arch_timer driver.

v4: https://lists.linaro.org/pipermail/linaro-acpi/2016-March/006667.html
Delete the kvm relevant patches
Separate two patches for sorting out the code for arm_arch_timer.
Improve irq info export code to allow missing irq info in GTDT table.

v3: https://lkml.org/lkml/2016/2/1/658

  1   2   3   4   5   6   7   8   9   10   >