Re: [PATCH] macintosh: Delete an unnecessary check before the function call "of_node_put"

2015-06-30 Thread SF Markus Elfring
Am 04.02.2015 um 21:36 schrieb SF Markus Elfring:
> From: Markus Elfring 
> Date: Wed, 4 Feb 2015 21:32:27 +0100
> 
> The of_node_put() function tests whether its argument is NULL and then
> returns immediately. Thus the test around the call is not needed.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring 
> ---
>  drivers/macintosh/smu.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
> index 10ae69b..d531f80 100644
> --- a/drivers/macintosh/smu.c
> +++ b/drivers/macintosh/smu.c
> @@ -557,8 +557,7 @@ int __init smu_init (void)
>   return 0;
>  
>  fail_msg_node:
> - if (smu->msg_node)
> - of_node_put(smu->msg_node);
> + of_node_put(smu->msg_node);
>  fail_db_node:
>   of_node_put(smu->db_node);
>  fail_bootmem:
> 

Would you like to integrate this update suggestion
into another source code repository?

Regards,
Markus
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 0/5] BHRB fixes, improvements and cleanups

2015-06-30 Thread Anshuman Khandual
The five generic patches from BHRB SW branch filter enablement
series have been separated and grouped together in this series. These
patches are required to be applied before using the upcoming V10 of the
BHRB SW branch filter patch series.

Anshuman Khandual (5):
  powerpc/perf: Drop the branch sample when 'from' cannot be fetched
  powerpc/perf: Change type of the bhrb_users variable
  powerpc/perf: Replace last usage of get_cpu_var with this_cpu_ptr
  powerpc/perf: Change name & type of 'pred' in power_pmu_bhrb_read
  powerpc/perf: Re organize PMU branch filter processing on POWER8

 arch/powerpc/perf/core-book3s.c | 29 +++--
 arch/powerpc/perf/power8-pmu.c  | 22 +++---
 2 files changed, 22 insertions(+), 29 deletions(-)

-- 
2.1.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 5/5] powerpc/perf: Re organize PMU branch filter processing on POWER8

2015-06-30 Thread Anshuman Khandual
This patch does some code re-arrangements to make it clear that kernel
ignores any separate privilege level branch filter request and does not
support any combinations of HW PMU branch filters.

Signed-off-by: Anshuman Khandual 
---
 arch/powerpc/perf/power8-pmu.c | 22 +++---
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/perf/power8-pmu.c b/arch/powerpc/perf/power8-pmu.c
index 396351d..a6c6a2c 100644
--- a/arch/powerpc/perf/power8-pmu.c
+++ b/arch/powerpc/perf/power8-pmu.c
@@ -656,8 +656,6 @@ static int power8_generic_events[] = {
 
 static u64 power8_bhrb_filter_map(u64 branch_sample_type)
 {
-   u64 pmu_bhrb_filter = 0;
-
/* BHRB and regular PMU events share the same privilege state
 * filter configuration. BHRB is always recorded along with a
 * regular PMU event. As the privilege state filter is handled
@@ -665,21 +663,15 @@ static u64 power8_bhrb_filter_map(u64 branch_sample_type)
 * PMU event, we ignore any separate BHRB specific request.
 */
 
-   /* No branch filter requested */
-   if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY)
-   return pmu_bhrb_filter;
-
-   /* Invalid branch filter options - HW does not support */
-   if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_RETURN)
-   return -1;
+   /* Ignore user, kernel, hv bits */
+   branch_sample_type &= ~PERF_SAMPLE_BRANCH_PLM_ALL;
 
-   if (branch_sample_type & PERF_SAMPLE_BRANCH_IND_CALL)
-   return -1;
+   /* No branch filter requested */
+   if (branch_sample_type == PERF_SAMPLE_BRANCH_ANY)
+   return 0;
 
-   if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_CALL) {
-   pmu_bhrb_filter |= POWER8_MMCRA_IFM1;
-   return pmu_bhrb_filter;
-   }
+   if (branch_sample_type == PERF_SAMPLE_BRANCH_ANY_CALL)
+   return POWER8_MMCRA_IFM1;
 
/* Every thing else is unsupported */
return -1;
-- 
2.1.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 2/5] powerpc/perf: Change type of the bhrb_users variable

2015-06-30 Thread Anshuman Khandual
This patch just changes data type of bhrb_users variable from
int to unsigned int because it never contains a negative value.

Reported-by: Daniel Axtens 
Signed-off-by: Anshuman Khandual 
---
 arch/powerpc/perf/core-book3s.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index b0c2d53..f9ecd93 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -53,7 +53,7 @@ struct cpu_hw_events {
 
/* BHRB bits */
u64 bhrb_filter;/* BHRB HW branch 
filter */
-   int bhrb_users;
+   unsigned intbhrb_users;
void*bhrb_context;
struct  perf_branch_stack   bhrb_stack;
struct  perf_branch_entry   bhrb_entries[BHRB_MAX_ENTRIES];
@@ -369,8 +369,8 @@ static void power_pmu_bhrb_disable(struct perf_event *event)
if (!ppmu->bhrb_nr)
return;
 
+   WARN_ON_ONCE(!cpuhw->bhrb_users);
cpuhw->bhrb_users--;
-   WARN_ON_ONCE(cpuhw->bhrb_users < 0);
perf_sched_cb_dec(event->ctx->pmu);
 
if (!cpuhw->disabled && !cpuhw->bhrb_users) {
-- 
2.1.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 1/5] powerpc/perf: Drop the branch sample when 'from' cannot be fetched

2015-06-30 Thread Anshuman Khandual
BHRB (Branch History Rolling Buffer) is a rolling buffer. Hence we
might end up in a situation where we have read one target address
but when we try to read the next entry indicating the from address
of the target address, the buffer just overflows. In this case, the
captured from address will be zero which indicates the end of the
buffer.

This patch drops the entire branch record which would have
otherwise confused the user space tools.

Signed-off-by: Anshuman Khandual 
---
 arch/powerpc/perf/core-book3s.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index d90893b..b0c2d53 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -461,7 +461,6 @@ static void power_pmu_bhrb_read(struct cpu_hw_events *cpuhw)
 *In this case we need to read the instruction from
 *memory to determine the target/to address.
 */
-
if (val & BHRB_TARGET) {
/* Target branches use two entries
 * (ie. computed gotos/XL form)
@@ -472,6 +471,8 @@ static void power_pmu_bhrb_read(struct cpu_hw_events *cpuhw)
 
/* Get from address in next entry */
val = read_bhrb(r_index++);
+   if (!val)
+   break;
addr = val & BHRB_EA;
if (val & BHRB_TARGET) {
/* Shouldn't have two targets in a
-- 
2.1.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 4/5] powerpc/perf: Change name & type of 'pred' in power_pmu_bhrb_read

2015-06-30 Thread Anshuman Khandual
Branch record attributes 'mispred' and 'predicted' are single bit
fields as defined in the perf ABI. Hence the data type of the field
'pred' used during BHRB processing should be changed from integer
to bool. This patch also changes the name of the variable from 'pred'
to 'mispred' making the logical inversion process more meaningful
and readable.

Reported-by: Daniel Axtens 
Signed-off-by: Anshuman Khandual 
---
 arch/powerpc/perf/core-book3s.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index 57f2c78..ddc0424 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -426,7 +426,8 @@ static void power_pmu_bhrb_read(struct cpu_hw_events *cpuhw)
 {
u64 val;
u64 addr;
-   int r_index, u_index, pred;
+   int r_index, u_index;
+   bool mispred;
 
r_index = 0;
u_index = 0;
@@ -438,7 +439,7 @@ static void power_pmu_bhrb_read(struct cpu_hw_events *cpuhw)
break;
else {
addr = val & BHRB_EA;
-   pred = val & BHRB_PREDICTION;
+   mispred = val & BHRB_PREDICTION;
 
if (!addr)
/* invalid entry */
@@ -466,8 +467,9 @@ static void power_pmu_bhrb_read(struct cpu_hw_events *cpuhw)
 * (ie. computed gotos/XL form)
 */
cpuhw->bhrb_entries[u_index].to = addr;
-   cpuhw->bhrb_entries[u_index].mispred = pred;
-   cpuhw->bhrb_entries[u_index].predicted = ~pred;
+   cpuhw->bhrb_entries[u_index].mispred = mispred;
+   cpuhw->bhrb_entries[u_index].predicted =
+   ~mispred;
 
/* Get from address in next entry */
val = read_bhrb(r_index++);
@@ -487,8 +489,9 @@ static void power_pmu_bhrb_read(struct cpu_hw_events *cpuhw)
cpuhw->bhrb_entries[u_index].from = addr;
cpuhw->bhrb_entries[u_index].to =
power_pmu_bhrb_to(addr);
-   cpuhw->bhrb_entries[u_index].mispred = pred;
-   cpuhw->bhrb_entries[u_index].predicted = ~pred;
+   cpuhw->bhrb_entries[u_index].mispred = mispred;
+   cpuhw->bhrb_entries[u_index].predicted =
+   ~mispred;
}
u_index++;
 
-- 
2.1.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 3/5] powerpc/perf: Replace last usage of get_cpu_var with this_cpu_ptr

2015-06-30 Thread Anshuman Khandual
The commit 69111bac42f5ce ("powerpc: Replace __get_cpu_var uses")
replaced all usage of get_cpu_var with this_cpu_ptr inside core
perf event handling on powerpc. But it skipped one of them which
is being replaced with this patch.

Reported-by: Daniel Axtens 
Signed-off-by: Anshuman Khandual 
---
 arch/powerpc/perf/core-book3s.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index f9ecd93..57f2c78 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -1840,20 +1840,17 @@ static int power_pmu_event_init(struct perf_event 
*event)
if (check_excludes(ctrs, cflags, n, 1))
return -EINVAL;
 
-   cpuhw = &get_cpu_var(cpu_hw_events);
+   cpuhw = this_cpu_ptr(&cpu_hw_events);
err = power_check_constraints(cpuhw, events, cflags, n + 1);
 
if (has_branch_stack(event)) {
cpuhw->bhrb_filter = ppmu->bhrb_filter_map(
event->attr.branch_sample_type);
 
-   if (cpuhw->bhrb_filter == -1) {
-   put_cpu_var(cpu_hw_events);
+   if (cpuhw->bhrb_filter == -1)
return -EOPNOTSUPP;
-   }
}
 
-   put_cpu_var(cpu_hw_events);
if (err)
return -EINVAL;
 
-- 
2.1.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V10 7/8] powerpc/perf: Enable privilege mode SW branch filters

2015-06-30 Thread Anshuman Khandual
This patch enables privilege mode SW branch filters. Also modifies
POWER8 PMU branch filter configuration so that the privilege mode
branch filter implemented as part of base PMU event configuration
is reflected in bhrb filter mask. As a result, the SW will skip and
not try to process the privilege mode branch filters itself.

Signed-off-by: Anshuman Khandual 
---
 arch/powerpc/include/asm/perf_event_server.h |  3 +++
 arch/powerpc/perf/core-book3s.c  | 37 ++--
 arch/powerpc/perf/power8-pmu.c   | 13 --
 3 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/include/asm/perf_event_server.h 
b/arch/powerpc/include/asm/perf_event_server.h
index cb7ca1a..23d68d3 100644
--- a/arch/powerpc/include/asm/perf_event_server.h
+++ b/arch/powerpc/include/asm/perf_event_server.h
@@ -85,6 +85,9 @@ extern unsigned long int read_bhrb(int n);
for ((x) = PERF_SAMPLE_BRANCH_USER; \
(x) < PERF_SAMPLE_BRANCH_MAX; (x) <<= 1)
 
+#define POWER_ADDR_USER0
+#define POWER_ADDR_KERNEL  1
+
 /*
  * Only override the default definitions in include/linux/perf_event.h
  * if we have hardware PMU support.
diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index 59defc5..4ae2225 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define BHRB_MAX_ENTRIES   32
 #define BHRB_TARGET0x0002
@@ -474,10 +475,10 @@ static bool check_instruction(unsigned int *addr, u64 
sw_filter)
  * Access the instruction contained in the address and then check
  * whether it complies with the applicable SW branch filters.
  */
-static bool keep_branch(u64 from, u64 sw_filter)
+static bool keep_branch(u64 from, u64 to, u64 sw_filter)
 {
unsigned int instr;
-   bool ret;
+   bool to_plm, ret, select_branch;
 
/*
 * The "from" branch for every branch record has to go
@@ -487,6 +488,37 @@ static bool keep_branch(u64 from, u64 sw_filter)
if (sw_filter == 0)
return true;
 
+   to_plm = is_kernel_addr(to) ? POWER_ADDR_KERNEL : POWER_ADDR_USER;
+
+   /*
+* XXX: Applying the privilege mode SW branch filters first on
+* the 'TO' address creates an AND semantic with other SW branch
+* filters which are ORed with each other being applied on the
+* 'FROM' address there after.
+*/
+   if (sw_filter & PERF_SAMPLE_BRANCH_PLM_ALL) {
+   select_branch = false;
+
+   if (sw_filter & PERF_SAMPLE_BRANCH_USER) {
+   if (to_plm == POWER_ADDR_USER)
+   select_branch = true;
+   }
+
+   if (sw_filter & PERF_SAMPLE_BRANCH_KERNEL) {
+   if (to_plm == POWER_ADDR_KERNEL)
+   select_branch = true;
+   }
+
+   if (sw_filter & PERF_SAMPLE_BRANCH_HV) {
+   if (cpu_has_feature(CPU_FTR_HVMODE)
+   && (to_plm == POWER_ADDR_KERNEL))
+   select_branch = true;
+   }
+
+   if (!select_branch)
+   return false;
+   }
+
if (is_kernel_addr(from)) {
return check_instruction((unsigned int *) from, sw_filter);
} else {
@@ -577,6 +609,7 @@ static void power_pmu_bhrb_read(struct cpu_hw_events *cpuhw)
 
/* Apply SW branch filters and drop the entry if required */
if (!keep_branch(cpuhw->bhrb_entries[u_index].from,
+   cpuhw->bhrb_entries[u_index].to,
cpuhw->bhrb_sw_filter))
u_index--;
u_index++;
diff --git a/arch/powerpc/perf/power8-pmu.c b/arch/powerpc/perf/power8-pmu.c
index 8fccf6c..b56afc6 100644
--- a/arch/powerpc/perf/power8-pmu.c
+++ b/arch/powerpc/perf/power8-pmu.c
@@ -670,9 +670,19 @@ static u64 power8_bhrb_filter_map(u64 branch_sample_type, 
u64 *bhrb_filter)
 * filter configuration. BHRB is always recorded along with a
 * regular PMU event. As the privilege state filter is handled
 * in the basic PMC configuration of the accompanying regular
-* PMU event, we ignore any separate BHRB specific request.
+* PMU event, we ignore any separate BHRB specific request. But
+* this needs to be communicated with the branch filter mask.
 */
 
+   if (branch_sample_type & PERF_SAMPLE_BRANCH_USER)
+   *bhrb_filter |= PERF_SAMPLE_BRANCH_USER;
+
+   if (branch_sample_type & PERF_SAMPLE_BRANCH_KERNEL)
+   *bhrb_filter |= PERF_SAMPLE_BRANCH_KERNEL;
+
+   if (branch_sample_type & PERF_SAMPLE_BRANCH_HV)
+   *bhrb_filter |= PERF_SAMPLE_BRANCH_HV;
+
  

[PATCH V10 4/8] powerpc/lib: Add new branch analysis support functions

2015-06-30 Thread Anshuman Khandual
Generic powerpc branch analysis support added in the code patching
library which will help the subsequent patch on SW based filtering
of branch records in perf.

Signed-off-by: Anshuman Khandual 
---
 arch/powerpc/include/asm/code-patching.h | 15 
 arch/powerpc/lib/code-patching.c | 60 
 2 files changed, 75 insertions(+)

diff --git a/arch/powerpc/include/asm/code-patching.h 
b/arch/powerpc/include/asm/code-patching.h
index 840a550..0a6f0d8 100644
--- a/arch/powerpc/include/asm/code-patching.h
+++ b/arch/powerpc/include/asm/code-patching.h
@@ -22,6 +22,16 @@
 #define BRANCH_SET_LINK0x1
 #define BRANCH_ABSOLUTE0x2
 
+#define XL_FORM_LR  0x4C20
+#define XL_FORM_CTR 0x4C000420
+#define XL_FORM_TAR 0x4C000460
+
+#define BO_ALWAYS0x0280
+#define BO_CTR   0x0200
+#define BO_CRBI_OFF  0x0080
+#define BO_CRBI_ON   0x0180
+#define BO_CRBI_HINT 0x0040
+
 unsigned int create_branch(const unsigned int *addr,
   unsigned long target, int flags);
 unsigned int create_cond_branch(const unsigned int *addr,
@@ -99,4 +109,9 @@ static inline unsigned long ppc_global_function_entry(void 
*func)
 #endif
 }
 
+bool instr_is_return_branch(unsigned int instr);
+bool instr_is_conditional_branch(unsigned int instr);
+bool instr_is_func_call(unsigned int instr);
+bool instr_is_indirect_func_call(unsigned int instr);
+
 #endif /* _ASM_POWERPC_CODE_PATCHING_H */
diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index d5edbeb..46fbcca 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -87,6 +87,66 @@ static int instr_is_branch_bform(unsigned int instr)
return branch_opcode(instr) == 16;
 }
 
+static bool instr_is_branch_xlform(unsigned int instr)
+{
+   return branch_opcode(instr) == 19;
+}
+
+static bool is_xlform_lr(unsigned int instr)
+{
+   return (instr & XL_FORM_LR) == XL_FORM_LR;
+}
+
+static bool is_bo_always(unsigned int instr)
+{
+   return (instr & BO_ALWAYS) == BO_ALWAYS;
+}
+
+static bool is_branch_link_set(unsigned int instr)
+{
+   return (instr & BRANCH_SET_LINK) == BRANCH_SET_LINK;
+}
+
+bool instr_is_return_branch(unsigned int instr)
+{
+   /*
+* Conditional and unconditional branch to LR register
+* without seting the link register.
+*/
+   if (is_xlform_lr(instr) && !is_branch_link_set(instr))
+   return true;
+
+   return false;
+}
+
+bool instr_is_conditional_branch(unsigned int instr)
+{
+   /* I-form instruction - excluded */
+   if (instr_is_branch_iform(instr))
+   return false;
+
+   /* B-form or XL-form instruction */
+   if (instr_is_branch_bform(instr) || instr_is_branch_xlform(instr))  {
+
+   /* Not branch always */
+   if (!is_bo_always(instr))
+   return true;
+   }
+   return false;
+}
+
+bool instr_is_func_call(unsigned int instr)
+{
+   /* LR should be set */
+   return is_branch_link_set(instr);
+}
+
+bool instr_is_indirect_func_call(unsigned int instr)
+{
+   /* XL-form instruction with LR set */
+   return (instr_is_branch_xlform(instr) && is_branch_link_set(instr));
+}
+
 int instr_is_relative_branch(unsigned int instr)
 {
if (instr & BRANCH_ABSOLUTE)
-- 
2.1.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V10 0/8] powerpc/perf: Enable SW branch filters

2015-06-30 Thread Anshuman Khandual
This is the continuation (rebased and reworked) of the series
posted at https://lkml.org/lkml/2014/5/5/153 (which is V6). I remember
to have incremented the version count for the re-send of the first four
patches of the series to Peter Z for generic review which got pulled in
last year. These patches here are the remaining powerpc part of the
original series.

NOTE: This patch series is logical extension and also dependent on the
series posted at https://patchwork.ozlabs.org/patch/489544/

Changes in V10
==
(1) The patch series is split into two groups now for easier review
(2) Changed the 'check_excludes' function as suggested by Daniel
(3) Using logical inversion of 'mispred' inside 'insert_branch' function 
(4) Made 'insert_branch' function inline and changed its last argument

Changes in V9 (https://patchwork.ozlabs.org/patch/484242/)
=
(1) Changed some of the commit messages and fixed some typos
(2) Variable 'bhrb_users' type changed from int to unsigned int
(3) Replaced the last usage of 'get_cpu_var' with 'this_cpu_ptr'
(4) Conditional checks for 'cpuhw->bhrb_users' changed to test against zero
(5) Updated in-code documentation inside 'check_excludes' function
(6) Changed the name & type of 'pred' variable in 'power_pmu_bhrb_read'
(7) Changed the name of 'tmp' to 'to_addr' inside 'power_pmu_bhrb_read'
(8) Changed return values for branch instruction analysis functions
(9) Changed the name of 'flag' variable to 'select_branch' inside 'keep_branch'
(10) Fixed one nested conditional statement inside 'keep_branch' function
(11) Changed function name from 'update_branch_entry' to 'insert_branch'
(12) Fixed copyright and license statements for new selftest related files
(13) Improved helper assembly functions with some macro definitions
(14) Improved the core test program at various places
(15) Added .gitignore file for the new test case

Changes in V8 (http://patchwork.ozlabs.org/patch/481848/)
=
(1) Fixed BHRB privilege mode branch filter request processing
(2) Dropped branch records where 'from' cannot be fetched
(3) Added in-code documenation at various places in the patch series
(4) Added one comprehensive seltest case to verify all the filters

Changes in V7
=
(1) Incremented the version count while requesting pull for generic changes

Changes in V6 (https://lkml.org/lkml/2014/5/5/153)
=
(1) Rebased the patchset against the master
(2) Added "Reviewed-by: Andi Kleen" in the first four patches in the series 
which changes the
generic or X86 perf code. [https://lkml.org/lkml/2014/4/7/130]

Changes in V5 (https://lkml.org/lkml/2014/3/7/101)
=
(1) Added a precursor patch to cleanup the indentation problem in 
power_pmu_bhrb_read
(2) Added a precursor patch to re-arrange P8 PMU BHRB filter config which 
improved the clarity
(3) Merged the previous 10th patch into the 8th patch
(4) Moved SW based branch analysis code from core perf into code-patching 
library as suggested by Michael
(5) Simplified the logic in branch analysis library
(6) Fixed some ambiguities in documentation at various places
(7) Added some more in-code documentation blocks at various places
(8) Renamed some local variable and function names
(9) Fixed some indentation and white space errors in the code
(10) Implemented almost all the review comments and suggestions made by Michael 
Ellerman on V4 patchset
(11) Enabled privilege mode SW branch filter
(12) Simplified and generalized the SW implemented conditional branch filter
(13) PERF_SAMPLE_BRANCH_COND filter is now supported only through SW 
implementation
(14) Adjusted other patches to deal with the above changes

Changes in V4 (https://lkml.org/lkml/2013/12/4/168)
=
(1) Changed the commit message for patch (01/10)
(2) Changed the patch (02/10) to accommodate review comments from Michael 
Ellerman
(3) Rebased the patchset against latest Linus's tree

Changes in V3 (https://lkml.org/lkml/2013/10/16/59)
=
(1) Split the SW branch filter enablement into multiple patches
(2) Added PMU neutral SW branch filtering code, PMU specific HW branch 
filtering code
(3) Added new instruction analysis functionality into powerpc code-patching 
library
(4) Changed name for some of the functions
(5) Fixed couple of spelling mistakes
(6) Changed code documentation in multiple places

Changes in V2 (https://lkml.org/lkml/2013/8/30/10)
=
(1) Enabled PPC64 SW branch filtering support
(2) Incorporated changes required for all previous comments


Anshuman Khandual (8):
  powerpc/perf: Restore privilege level filter support for BHRB
  powerpc/perf: Re organize BHRB processing
  powerpc/perf: Change the name of HW PMU branch filter tracking variable
  powerpc/lib: Add new branch analysis support functions
  powerpc/perf: Enable SW filtering in branch stack sampling framework
  powerpc/perf: Change POWER8 PMU configuration to work with SW filters
  powerpc/perf: Enable privilege mode SW branch 

[PATCH V10 2/8] powerpc/perf: Re organize BHRB processing

2015-06-30 Thread Anshuman Khandual
This patch cleans up some existing indentation problem in code and
re organizes the BHRB processing code with an helper function named
'update_branch_entry' making it more readable. This patch does not
change any functionality.

Signed-off-by: Anshuman Khandual 
---
 arch/powerpc/perf/core-book3s.c | 109 
 1 file changed, 54 insertions(+), 55 deletions(-)

diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index b7710b9..6935660 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -421,11 +421,19 @@ static __u64 power_pmu_bhrb_to(u64 addr)
return target - (unsigned long)&instr + addr;
 }
 
+static inline void insert_branch(struct cpu_hw_events *cpuhw,
+   int index, u64 from, u64 to, bool mispred)
+{
+   cpuhw->bhrb_entries[index].from = from;
+   cpuhw->bhrb_entries[index].to = to;
+   cpuhw->bhrb_entries[index].mispred = mispred;
+   cpuhw->bhrb_entries[index].predicted = !mispred;
+}
+
 /* Processing BHRB entries */
 static void power_pmu_bhrb_read(struct cpu_hw_events *cpuhw)
 {
-   u64 val;
-   u64 addr;
+   u64 val, addr, to_addr;
int r_index, u_index;
bool mispred;
 
@@ -437,65 +445,56 @@ static void power_pmu_bhrb_read(struct cpu_hw_events 
*cpuhw)
if (!val)
/* Terminal marker: End of valid BHRB entries */
break;
-   else {
-   addr = val & BHRB_EA;
-   mispred = val & BHRB_PREDICTION;
 
-   if (!addr)
-   /* invalid entry */
-   continue;
+   addr = val & BHRB_EA;
+   mispred = val & BHRB_PREDICTION;
+
+   if (!addr)
+   /* invalid entry */
+   continue;
 
-   /* Branches are read most recent first (ie. mfbhrb 0 is
-* the most recent branch).
-* There are two types of valid entries:
-* 1) a target entry which is the to address of a
-*computed goto like a blr,bctr,btar.  The next
-*entry read from the bhrb will be branch
-*corresponding to this target (ie. the actual
-*blr/bctr/btar instruction).
-* 2) a from address which is an actual branch.  If a
-*target entry proceeds this, then this is the
-*matching branch for that target.  If this is not
-*following a target entry, then this is a branch
-*where the target is given as an immediate field
-*in the instruction (ie. an i or b form branch).
-*In this case we need to read the instruction from
-*memory to determine the target/to address.
+   /* Branches are read most recent first (ie. mfbhrb 0 is
+* the most recent branch).
+* There are two types of valid entries:
+* 1) a target entry which is the to address of a
+*computed goto like a blr,bctr,btar.  The next
+*entry read from the bhrb will be branch
+*corresponding to this target (ie. the actual
+*blr/bctr/btar instruction).
+* 2) a from address which is an actual branch.  If a
+*target entry proceeds this, then this is the
+*matching branch for that target.  If this is not
+*following a target entry, then this is a branch
+*where the target is given as an immediate field
+*in the instruction (ie. an i or b form branch).
+*In this case we need to read the instruction from
+*memory to determine the target/to address.
+*/
+   if (val & BHRB_TARGET) {
+   /* Target branches use two entries
+* (ie. computed gotos/XL form)
 */
+   to_addr = addr;
+
+   /* Get from address in next entry */
+   val = read_bhrb(r_index++);
+   if (!val)
+   break;
+   addr = val & BHRB_EA;
if (val & BHRB_TARGET) {
-   /* Target branches use two entries
-* (ie. computed gotos/XL form)
-*/
-   cpuhw->bhrb_entries[u_index].to = addr;
-   cpuhw->bhrb_entries[u_index].mispred = mispred;
-   

[PATCH V10 5/8] powerpc/perf: Enable SW filtering in branch stack sampling framework

2015-06-30 Thread Anshuman Khandual
This patch enables SW based post processing of BHRB captured branches
to be able to meet more user defined branch filtration criteria in perf
branch stack sampling framework. These changes increase the number of
branch filters and their valid combinations on any powerpc64 server
platform with BHRB support. Find the summary of code changes here.

(1) struct cpu_hw_event

Introduced two new variables track various filter values and mask

(a) bhrb_sw_filter  Tracks SW implemented branch filter flags
(b) bhrb_filter Tracks both (SW and HW) branch filter flags

(2) Event creation

Kernel will figure out supported BHRB branch filters through a PMU
call back 'bhrb_filter_map'. This function will find out how many of
the requested branch filters can be supported in the PMU HW. It will
not try to invalidate any branch filter combinations. Event creation
will not error out because of lack of HW based branch filters.
Meanwhile it will track the overall supported branch filters in the
'bhrb_filter' variable.

Once the PMU call back returns kernel will process the user branch
filter request against available SW filters (bhrb_sw_filter_map) while
looking at the 'bhrb_filter'. During this phase all the branch filters
which are still pending from the user requested list will have to be
supported in SW failing which the event creation will error out.

(3) SW branch filter

During the BHRB data capture inside the PMU interrupt context, each
of the captured 'perf_branch_entry.from' will be checked for compliance
with applicable SW branch filters. If the entry does not conform to the
filter requirements, it will be discarded from the final perf branch
stack buffer.

(4) Supported SW based branch filters

(a) PERF_SAMPLE_BRANCH_ANY_RETURN
(b) PERF_SAMPLE_BRANCH_IND_CALL
(c) PERF_SAMPLE_BRANCH_ANY_CALL
(d) PERF_SAMPLE_BRANCH_COND

Please refer the patch to understand the classification of instructions
into these branch filter categories.

(5) Multiple branch filter semantics

Book3 sever implementation follows the same OR semantics (as implemented
in x86) while dealing with multiple branch filters at any point of time.
SW branch filter analysis is carried on the data set captured in the PMU
HW. So the resulting set of data (after applying the SW filters) will
inherently be an AND with the HW captured set. Hence any combination of
HW and SW branch filters will be invalid. HW based branch filters are
more efficient and faster compared to SW implemented branch filters. So
at first the PMU should decide whether it can support all the requested
branch filters itself or not. In case it can support all the branch
filters in an OR manner, we dont apply any SW branch filter on top of the
HW captured set (which is the final set). This preserves the OR semantic
of multiple branch filters as required. But in case where the PMU cannot
support all the requested branch filters in an OR manner, it should not
apply any it's filters and leave it upto the SW to handle them all. Its
the PMU code's responsibility to uphold this protocol to be able to
conform to the overall OR semantic of perf branch stack sampling framework.

Signed-off-by: Anshuman Khandual 
---
 arch/powerpc/include/asm/perf_event_server.h |   7 +-
 arch/powerpc/perf/core-book3s.c  | 188 ++-
 arch/powerpc/perf/power8-pmu.c   |   2 +-
 3 files changed, 191 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/perf_event_server.h 
b/arch/powerpc/include/asm/perf_event_server.h
index 8146221..cb7ca1a 100644
--- a/arch/powerpc/include/asm/perf_event_server.h
+++ b/arch/powerpc/include/asm/perf_event_server.h
@@ -38,7 +38,8 @@ struct power_pmu {
unsigned long *valp);
int (*get_alternatives)(u64 event_id, unsigned int flags,
u64 alt[]);
-   u64 (*bhrb_filter_map)(u64 branch_sample_type);
+   u64 (*bhrb_filter_map)(u64 branch_sample_type,
+   u64 *bhrb_filter);
void(*config_bhrb)(u64 pmu_bhrb_filter);
void(*disable_pmc)(unsigned int pmc, unsigned long mmcr[]);
int (*limited_pmc_event)(u64 event_id);
@@ -80,6 +81,10 @@ extern unsigned long perf_misc_flags(struct pt_regs *regs);
 extern unsigned long perf_instruction_pointer(struct pt_regs *regs);
 extern unsigned long int read_bhrb(int n);
 
+#define for_each_branch_sample_type(x) \
+   for ((x) = PERF_SAMPLE_BRANCH_USER; \
+   (x) < PERF_SAMPLE_BRANCH_MAX; (x) <<= 1)
+
 /*
  * Only override the default definitions in include/linux/perf_event.h
  * if we have hardware PMU support.
diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index ef0ff05..59defc5 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -53,6 +53,8 @@ struct cpu_hw_events {
 

[PATCH V10 8/8] selftests/powerpc: Add test for BHRB branch filters (HW & SW)

2015-06-30 Thread Anshuman Khandual
This patch adds a test for verifying that all the branch stack
sampling filters supported on powerpc work correctly. It also
adds some assembly helper functions in this regard. This patch
extends the generic event description to handle kernel mapped
ring buffers.

Signed-off-by: Anshuman Khandual 
---
 tools/testing/selftests/powerpc/pmu/Makefile   |  11 +-
 .../testing/selftests/powerpc/pmu/bhrb/.gitignore  |   1 +
 tools/testing/selftests/powerpc/pmu/bhrb/Makefile  |  13 +
 .../selftests/powerpc/pmu/bhrb/bhrb_filters.c  | 535 +
 .../selftests/powerpc/pmu/bhrb/bhrb_filters.h  |  15 +
 .../selftests/powerpc/pmu/bhrb/bhrb_filters_asm.S  | 263 ++
 tools/testing/selftests/powerpc/pmu/event.h|   5 +
 7 files changed, 841 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/powerpc/pmu/bhrb/.gitignore
 create mode 100644 tools/testing/selftests/powerpc/pmu/bhrb/Makefile
 create mode 100644 tools/testing/selftests/powerpc/pmu/bhrb/bhrb_filters.c
 create mode 100644 tools/testing/selftests/powerpc/pmu/bhrb/bhrb_filters.h
 create mode 100644 tools/testing/selftests/powerpc/pmu/bhrb/bhrb_filters_asm.S

diff --git a/tools/testing/selftests/powerpc/pmu/Makefile 
b/tools/testing/selftests/powerpc/pmu/Makefile
index a9099d9..2e103fd 100644
--- a/tools/testing/selftests/powerpc/pmu/Makefile
+++ b/tools/testing/selftests/powerpc/pmu/Makefile
@@ -4,7 +4,7 @@ noarg:
 TEST_PROGS := count_instructions l3_bank_test per_event_excludes
 EXTRA_SOURCES := ../harness.c event.c lib.c
 
-all: $(TEST_PROGS) ebb
+all: $(TEST_PROGS) ebb bhrb
 
 $(TEST_PROGS): $(EXTRA_SOURCES)
 
@@ -18,25 +18,32 @@ DEFAULT_RUN_TESTS := $(RUN_TESTS)
 override define RUN_TESTS
$(DEFAULT_RUN_TESTS)
$(MAKE) -C ebb run_tests
+   $(MAKE) -C bhrb run_tests
 endef
 
 DEFAULT_EMIT_TESTS := $(EMIT_TESTS)
 override define EMIT_TESTS
$(DEFAULT_EMIT_TESTS)
$(MAKE) -s -C ebb emit_tests
+   $(MAKE) -s -C bhrb emit_tests
 endef
 
 DEFAULT_INSTALL_RULE := $(INSTALL_RULE)
 override define INSTALL_RULE
$(DEFAULT_INSTALL_RULE)
$(MAKE) -C ebb install
+   $(MAKE) -C bhrb install
 endef
 
 clean:
rm -f $(TEST_PROGS) loop.o
$(MAKE) -C ebb clean
+   $(MAKE) -C bhrb clean
 
 ebb:
$(MAKE) -k -C $@ all
 
-.PHONY: all run_tests clean ebb
+bhrb:
+   $(MAKE) -k -C $@ all
+
+.PHONY: all run_tests clean ebb bhrb
diff --git a/tools/testing/selftests/powerpc/pmu/bhrb/.gitignore 
b/tools/testing/selftests/powerpc/pmu/bhrb/.gitignore
new file mode 100644
index 000..47c1049
--- /dev/null
+++ b/tools/testing/selftests/powerpc/pmu/bhrb/.gitignore
@@ -0,0 +1 @@
+bhrb_filters
diff --git a/tools/testing/selftests/powerpc/pmu/bhrb/Makefile 
b/tools/testing/selftests/powerpc/pmu/bhrb/Makefile
new file mode 100644
index 000..61c032a
--- /dev/null
+++ b/tools/testing/selftests/powerpc/pmu/bhrb/Makefile
@@ -0,0 +1,13 @@
+noarg:
+   $(MAKE) -C ../../
+
+TEST_PROGS := bhrb_filters
+
+all: $(TEST_PROGS)
+
+$(TEST_PROGS): ../../harness.c ../event.c ../lib.c bhrb_filters_asm.S
+
+include ../../../lib.mk
+
+clean:
+   rm -f $(TEST_PROGS)
diff --git a/tools/testing/selftests/powerpc/pmu/bhrb/bhrb_filters.c 
b/tools/testing/selftests/powerpc/pmu/bhrb/bhrb_filters.c
new file mode 100644
index 000..84e9b9a
--- /dev/null
+++ b/tools/testing/selftests/powerpc/pmu/bhrb/bhrb_filters.c
@@ -0,0 +1,535 @@
+/*
+ * BHRB filter test (HW & SW)
+ *
+ * Copyright (C) 2015 Anshuman Khandual, IBM Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "bhrb_filters.h"
+#include "utils.h"
+#include "../event.h"
+#include "../lib.h"
+
+/* Memory barriers */
+#definesmp_mb(){ asm volatile ("sync" : : : "memory"); }
+
+/* Fetched address counts */
+#define ALL_MAX32
+#define CALL_MAX   12
+#define RET_MAX10
+#define COND_MAX   8
+#define IND_MAX4
+
+/* Test tunables */
+#define LOOP_COUNT 10
+#define SAMPLE_PERIOD  1
+
+static int branch_test_set[] = {
+   PERF_SAMPLE_BRANCH_ANY_CALL,/* Single filters */
+   PERF_SAMPLE_BRANCH_ANY_RETURN,
+   PERF_SAMPLE_BRANCH_COND,
+   PERF_SAMPLE_BRANCH_IND_CALL,
+   PERF_SAMPLE_BRANCH_ANY,
+
+   PERF_SAMPLE_BRANCH_ANY_CALL |   /* Double filters */
+   PERF_SAMPLE_BRANCH_ANY_RETURN,
+   PERF_SAMPLE_BRANCH_ANY_CALL |
+   PERF_SAMPLE_BRANCH_COND,
+   PERF_SAMPLE_BRANCH_ANY_CALL |
+   PERF_SAMPLE_BRANCH_IND_CALL,
+   PERF_SAMPLE_BRANCH_ANY_CALL |
+   PERF_SAMPLE_BRANCH_ANY,
+
+   PERF_SAMPLE_B

[PATCH V10 1/8] powerpc/perf: Restore privilege level filter support for BHRB

2015-06-30 Thread Anshuman Khandual
'commit 9de5cb0f6df8 ("powerpc/perf: Add per-event excludes on Power8")'
broke the PMU based BHRB privilege level filter. BHRB depends on the
same MMCR0 bits for privilege level filter which was used to freeze all
the PMCs as a group. Once we moved to individual event based privilege
filters through MMCR2 register on POWER8, event associated privilege
filters are no longer applicable to the BHRB captured branches.

This patch solves the problem by restoring to the previous method of
privilege level filters for the event in case BHRB based branch stack
sampling is requested. This patch also changes 'check_excludes' for
the same reason.

Signed-off-by: Anshuman Khandual 
---
 arch/powerpc/perf/core-book3s.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index ddc0424..b7710b9 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -942,7 +942,7 @@ static int power_check_constraints(struct cpu_hw_events 
*cpuhw,
  * added events.
  */
 static int check_excludes(struct perf_event **ctrs, unsigned int cflags[],
- int n_prev, int n_new)
+ int n_prev, int n_new, unsigned int bhrb_users)
 {
int eu = 0, ek = 0, eh = 0;
int i, n, first;
@@ -951,9 +951,10 @@ static int check_excludes(struct perf_event **ctrs, 
unsigned int cflags[],
/*
 * If the PMU we're on supports per event exclude settings then we
 * don't need to do any of this logic. NB. This assumes no PMU has both
-* per event exclude and limited PMCs.
+* per event exclude and limited PMCs. But again if the event has also
+* requested for branch stack sampling, then process the logic here.
 */
-   if (ppmu->flags & PPMU_ARCH_207S)
+   if ((ppmu->flags & PPMU_ARCH_207S) && !bhrb_users)
return 0;
 
n = n_prev + n_new;
@@ -1271,7 +1272,7 @@ static void power_pmu_enable(struct pmu *pmu)
goto out;
}
 
-   if (!(ppmu->flags & PPMU_ARCH_207S)) {
+   if (!(ppmu->flags & PPMU_ARCH_207S) || cpuhw->bhrb_users) {
/*
 * Add in MMCR0 freeze bits corresponding to the attr.exclude_*
 * bits for the first event. We have already checked that all
@@ -1296,7 +1297,7 @@ static void power_pmu_enable(struct pmu *pmu)
mtspr(SPRN_MMCR1, cpuhw->mmcr[1]);
mtspr(SPRN_MMCR0, (cpuhw->mmcr[0] & ~(MMCR0_PMC1CE | MMCR0_PMCjCE))
| MMCR0_FC);
-   if (ppmu->flags & PPMU_ARCH_207S)
+   if ((ppmu->flags & PPMU_ARCH_207S) && !cpuhw->bhrb_users)
mtspr(SPRN_MMCR2, cpuhw->mmcr[3]);
 
/*
@@ -1448,7 +1449,8 @@ static int power_pmu_add(struct perf_event *event, int 
ef_flags)
if (cpuhw->group_flag & PERF_EVENT_TXN)
goto nocheck;
 
-   if (check_excludes(cpuhw->event, cpuhw->flags, n0, 1))
+   if (check_excludes(cpuhw->event, cpuhw->flags,
+   n0, 1, cpuhw->bhrb_users))
goto out;
if (power_check_constraints(cpuhw, cpuhw->events, cpuhw->flags, n0 + 1))
goto out;
@@ -1627,7 +1629,7 @@ static int power_pmu_commit_txn(struct pmu *pmu)
return -EAGAIN;
cpuhw = this_cpu_ptr(&cpu_hw_events);
n = cpuhw->n_events;
-   if (check_excludes(cpuhw->event, cpuhw->flags, 0, n))
+   if (check_excludes(cpuhw->event, cpuhw->flags, 0, n, cpuhw->bhrb_users))
return -EAGAIN;
i = power_check_constraints(cpuhw, cpuhw->events, cpuhw->flags, n);
if (i < 0)
@@ -1840,10 +1842,10 @@ static int power_pmu_event_init(struct perf_event 
*event)
events[n] = ev;
ctrs[n] = event;
cflags[n] = flags;
-   if (check_excludes(ctrs, cflags, n, 1))
+   cpuhw = this_cpu_ptr(&cpu_hw_events);
+   if (check_excludes(ctrs, cflags, n, 1, cpuhw->bhrb_users))
return -EINVAL;
 
-   cpuhw = this_cpu_ptr(&cpu_hw_events);
err = power_check_constraints(cpuhw, events, cflags, n + 1);
 
if (has_branch_stack(event)) {
-- 
2.1.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V10 3/8] powerpc/perf: Change the name of HW PMU branch filter tracking variable

2015-06-30 Thread Anshuman Khandual
This patch simply changes the name of the variable from 'bhrb_filter' to
'bhrb_hw_filter' in order to add one more variable which will track SW
filters in generic powerpc book3s code which will be implemented in the
subsequent patch. This patch does not change any functionality.

Signed-off-by: Anshuman Khandual 
---
 arch/powerpc/perf/core-book3s.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index 6935660..ef0ff05 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -52,7 +52,7 @@ struct cpu_hw_events {
int n_txn_start;
 
/* BHRB bits */
-   u64 bhrb_filter;/* BHRB HW branch 
filter */
+   u64 bhrb_hw_filter; /* BHRB HW filter */
unsigned intbhrb_users;
void*bhrb_context;
struct  perf_branch_stack   bhrb_stack;
@@ -1357,7 +1357,7 @@ static void power_pmu_enable(struct pmu *pmu)
 
mb();
if (cpuhw->bhrb_users)
-   ppmu->config_bhrb(cpuhw->bhrb_filter);
+   ppmu->config_bhrb(cpuhw->bhrb_hw_filter);
 
write_mmcr0(cpuhw, mmcr0);
 
@@ -1465,7 +1465,7 @@ nocheck:
  out:
if (has_branch_stack(event)) {
power_pmu_bhrb_enable(event);
-   cpuhw->bhrb_filter = ppmu->bhrb_filter_map(
+   cpuhw->bhrb_hw_filter = ppmu->bhrb_filter_map(
event->attr.branch_sample_type);
}
 
@@ -1848,10 +1848,10 @@ static int power_pmu_event_init(struct perf_event 
*event)
err = power_check_constraints(cpuhw, events, cflags, n + 1);
 
if (has_branch_stack(event)) {
-   cpuhw->bhrb_filter = ppmu->bhrb_filter_map(
+   cpuhw->bhrb_hw_filter = ppmu->bhrb_filter_map(
event->attr.branch_sample_type);
 
-   if (cpuhw->bhrb_filter == -1)
+   if (cpuhw->bhrb_hw_filter == -1)
return -EOPNOTSUPP;
}
 
-- 
2.1.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V10 6/8] powerpc/perf: Change POWER8 PMU configuration to work with SW filters

2015-06-30 Thread Anshuman Khandual
The kernel now supports SW based branch filters for book3s systems with
some specific requirements while dealing with HW supported branch filters
in order to achieve overall OR semantics prevailing in perf branch stack
sampling framework. This patch adapts the BHRB branch filter configuration
to meet those protocols. POWER8 PMU can only handle one HW based branch
filter request at any point of time. For all other combinations PMU will
pass it on to the SW.

Signed-off-by: Anshuman Khandual 
---
 arch/powerpc/perf/power8-pmu.c | 51 --
 1 file changed, 44 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/perf/power8-pmu.c b/arch/powerpc/perf/power8-pmu.c
index 5e17cb5..8fccf6c 100644
--- a/arch/powerpc/perf/power8-pmu.c
+++ b/arch/powerpc/perf/power8-pmu.c
@@ -656,6 +656,16 @@ static int power8_generic_events[] = {
 
 static u64 power8_bhrb_filter_map(u64 branch_sample_type, u64 *bhrb_filter)
 {
+   u64 x, pmu_bhrb_filter;
+
+   pmu_bhrb_filter = 0;
+   *bhrb_filter = 0;
+
+   if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY) {
+   *bhrb_filter = PERF_SAMPLE_BRANCH_ANY;
+   return pmu_bhrb_filter;
+   }
+
/* BHRB and regular PMU events share the same privilege state
 * filter configuration. BHRB is always recorded along with a
 * regular PMU event. As the privilege state filter is handled
@@ -666,15 +676,42 @@ static u64 power8_bhrb_filter_map(u64 branch_sample_type, 
u64 *bhrb_filter)
/* Ignore user, kernel, hv bits */
branch_sample_type &= ~PERF_SAMPLE_BRANCH_PLM_ALL;
 
-   /* No branch filter requested */
-   if (branch_sample_type == PERF_SAMPLE_BRANCH_ANY)
-   return 0;
+   /*
+* POWER8 does not support ORing of PMU HW branch filters. Hence
+* if multiple branch filters are requested which may include filters
+* supported in PMU, still go ahead and clear the PMU based HW branch
+* filter component as in this case all the filters will be processed
+* in SW.
+*/
 
-   if (branch_sample_type == PERF_SAMPLE_BRANCH_ANY_CALL)
-   return POWER8_MMCRA_IFM1;
+   for_each_branch_sample_type(x) {
+   /* Ignore privilege branch filters */
+   if ((x == PERF_SAMPLE_BRANCH_USER)
+   || (x == PERF_SAMPLE_BRANCH_KERNEL)
+   || (x == PERF_SAMPLE_BRANCH_HV))
+   continue;
+
+   if (!(branch_sample_type & x))
+   continue;
+
+   /* Supported individual PMU branch filters */
+   if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_CALL) {
+   branch_sample_type &= ~PERF_SAMPLE_BRANCH_ANY_CALL;
+   if (branch_sample_type) {
+   /* Multiple filters will be processed in SW */
+   pmu_bhrb_filter = 0;
+   *bhrb_filter = 0;
+   return pmu_bhrb_filter;
+   } else {
+   /* Individual filter will be processed in HW */
+   pmu_bhrb_filter |= POWER8_MMCRA_IFM1;
+   *bhrb_filter|= PERF_SAMPLE_BRANCH_ANY_CALL;
+   return pmu_bhrb_filter;
+   }
+   }
+   }
 
-   /* Every thing else is unsupported */
-   return -1;
+   return pmu_bhrb_filter;
 }
 
 static void power8_config_bhrb(u64 pmu_bhrb_filter)
-- 
2.1.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH RESEND] Update kernel math-emu code from current glibc soft-fp

2015-06-30 Thread Joseph Myers
On Tue, 30 Jun 2015, Michael Ellerman wrote:

> Is there some way you can imagine of splitting this up into smaller chunks, so
> that different arches can merge the pieces separately?

Well, it could be split as:

1. Rename include/math-emu to math-emu-old and update architectures for 
the renaming (mechanically).

2. Add new include/math-emu.

3,4,5,6,7. Move each architecture from math-emu-old to math-emu.

8. Remove math-emu-old.

You still have patch 1 affecting all five architectures, but with the 
per-architecture changes being much simpler.

-- 
Joseph S. Myers
jos...@codesourcery.com
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH SLOF v3 0/5] GPT fixes/cleanup and LVM support with FAT

2015-06-30 Thread Nikunj A Dadhania
Following patchset implements some improvements and cleanup for the
GPT booting code:

patch 1: Simplify the gpt detection code with lesser scopes and add
 comments.

patch 2: Introduce 8byte LE helpers: x@-le and x!-le

patch 3: Rename block / read-sector to indicate it a allocated buffer

patch 4: As we need to detect FAT partition, implement a helper that
 can be used both from GPT code and "fat-bootblock?"

patch 5: Implement GPT FAT for LVM suport and make GPT detection code
 robust

Changelog V2:
* Optimize gpt detection code
* Fixed stack comments
* Rename verify-gpt-partition, as it was doing more than that. Added
  comments.

Nikunj A Dadhania (5):
  disk-label: simplify gpt-prep-partition? routine
  introduce 8-byte LE helpers
  disk-label: rename confusing "block" word
  disk-label: introduce helper to check fat filesystem
  disk-label: add support for booting from GPT FAT partition

 slof/fs/little-endian.fs   |   6 ++
 slof/fs/packages/disk-label.fs | 211 ++---
 2 files changed, 138 insertions(+), 79 deletions(-)

-- 
2.4.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH SLOF v3 1/5] disk-label: simplify gpt-prep-partition? routine

2015-06-30 Thread Nikunj A Dadhania
Signed-off-by: Nikunj A Dadhania 
Reviewed-by: Thomas Huth 
---
 slof/fs/packages/disk-label.fs | 41 +++--
 1 file changed, 15 insertions(+), 26 deletions(-)

diff --git a/slof/fs/packages/disk-label.fs b/slof/fs/packages/disk-label.fs
index fe1c25e..f1f083a 100644
--- a/slof/fs/packages/disk-label.fs
+++ b/slof/fs/packages/disk-label.fs
@@ -352,42 +352,31 @@ CONSTANT /gpt-part-entry
drop 0
 ;
 
-\ Check for GPT PReP partition GUID
-9E1A2D38 CONSTANT GPT-PREP-PARTITION-1
-C612 CONSTANT GPT-PREP-PARTITION-2
-4316 CONSTANT GPT-PREP-PARTITION-3
-AA26 CONSTANT GPT-PREP-PARTITION-4
-8B49521E5A8B CONSTANT GPT-PREP-PARTITION-5
+\ Check for GPT PReP partition GUID. Only first 3 blocks are
+\ byte-swapped treating last two blocks as contigous for simplifying
+\ comparison
+9E1A2D38CONSTANT GPT-PREP-PARTITION-1
+C612CONSTANT GPT-PREP-PARTITION-2
+4316CONSTANT GPT-PREP-PARTITION-3
+AA268B49521E5A8BCONSTANT GPT-PREP-PARTITION-4
 
 : gpt-prep-partition? ( -- true|false )
-   block gpt-part-entry>part-type-guid l@-le GPT-PREP-PARTITION-1 = IF
-  block gpt-part-entry>part-type-guid 4 + w@-le
-  GPT-PREP-PARTITION-2 = IF
- block gpt-part-entry>part-type-guid 6 + w@-le
- GPT-PREP-PARTITION-3 = IF
-block gpt-part-entry>part-type-guid 8 + w@
-GPT-PREP-PARTITION-4 = IF
-   block gpt-part-entry>part-type-guid a + w@
-   block gpt-part-entry>part-type-guid c + l@ swap lxjoin
-   GPT-PREP-PARTITION-5 = IF
-   TRUE EXIT
-   THEN
-THEN
- THEN
-  THEN
-   THEN
-   FALSE
+   block gpt-part-entry>part-type-guid
+   dup l@-le GPT-PREP-PARTITION-1 <> IF drop false EXIT THEN
+   dup 4 + w@-le GPT-PREP-PARTITION-2 <> IF drop false EXIT THEN
+   dup 6 + w@-le GPT-PREP-PARTITION-3 <> IF drop false EXIT THEN
+   8 + x@GPT-PREP-PARTITION-4 =
 ;
 
 : load-from-gpt-prep-partition ( addr -- size )
-   no-gpt? IF drop FALSE EXIT THEN
+   no-gpt? IF drop false EXIT THEN
debug-disk-label? IF
   cr ." GPT partition found " cr
THEN
1 read-sector block gpt>part-entry-lba l@-le
block-size * to seek-pos
block gpt>part-entry-size l@-le to gpt-part-size
-   block gpt>num-part-entry l@-le dup 0= IF FALSE EXIT THEN
+   block gpt>num-part-entry l@-le dup 0= IF false EXIT THEN
1+ 1 ?DO
   seek-pos 0 seek drop
   block gpt-part-size read drop gpt-prep-partition? IF
@@ -405,7 +394,7 @@ AA26 CONSTANT GPT-PREP-PARTITION-4
   THEN
   seek-pos gpt-part-size i * + to seek-pos
LOOP
-   FALSE
+   false
 ;
 
 \ Extract the boot loader path from a bootinfo.txt file
-- 
2.4.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH SLOF v3 2/5] introduce 8-byte LE helpers

2015-06-30 Thread Nikunj A Dadhania
Signed-off-by: Nikunj A Dadhania 
Reviewed-by: Thomas Huth 
---
 slof/fs/little-endian.fs   | 6 ++
 slof/fs/packages/disk-label.fs | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/slof/fs/little-endian.fs b/slof/fs/little-endian.fs
index f2e4e8d..6b4779e 100644
--- a/slof/fs/little-endian.fs
+++ b/slof/fs/little-endian.fs
@@ -17,6 +17,9 @@ here c@ ef = CONSTANT ?littleendian
 
 ?bigendian [IF]
 
+: x!-le >r xbflip r> x! ;
+: x@-le x@ xbflip ;
+
 : l!-le  >r lbflip r> l! ;
 : l@-le  l@ lbflip ;
 
@@ -47,6 +50,9 @@ here c@ ef = CONSTANT ?littleendian
 
 [ELSE]
 
+: x!-le x! ;
+: x@-le x@ ;
+
 : l!-le  l! ;
 : l@-le  l@ ;
 
diff --git a/slof/fs/packages/disk-label.fs b/slof/fs/packages/disk-label.fs
index f1f083a..b346774 100644
--- a/slof/fs/packages/disk-label.fs
+++ b/slof/fs/packages/disk-label.fs
@@ -383,8 +383,8 @@ AA268B49521E5A8BCONSTANT GPT-PREP-PARTITION-4
  debug-disk-label? IF
 ." GPT PReP partition found " cr
  THEN
- block gpt-part-entry>first-lba x@ xbflip
- block gpt-part-entry>last-lba x@ xbflip
+ block gpt-part-entry>first-lba x@-le
+ block gpt-part-entry>last-lba x@-le
  over - 1+ ( addr offset len )
  swap  ( addr len offset )
  block-size * to part-offset
-- 
2.4.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH SLOF v3 3/5] disk-label: rename confusing "block" word

2015-06-30 Thread Nikunj A Dadhania
"block" word is not a block number, actually its an allocated host
address.  Rename it to disk-buf along with a associated
size(disk-buf-size=4096) for using during allocation/free.

Also renaming the helper routine read-sector to read-disk-buf. This
routine assumes the address to be disk-buf and only takes sector number
as argument.

Signed-off-by: Nikunj A Dadhania 
Reviewed-by: Thomas Huth 
---
 slof/fs/packages/disk-label.fs | 78 ++
 1 file changed, 41 insertions(+), 37 deletions(-)

diff --git a/slof/fs/packages/disk-label.fs b/slof/fs/packages/disk-label.fs
index b346774..e5a0546 100644
--- a/slof/fs/packages/disk-label.fs
+++ b/slof/fs/packages/disk-label.fs
@@ -33,7 +33,8 @@ s" disk-label" device-name
 0 INSTANCE VALUE dos-logical-partitions
 
 0 INSTANCE VALUE block-size
-0 INSTANCE VALUE block
+0 INSTANCE VALUE disk-buf
+d# 4096VALUE disk-buf-size
 
 0 INSTANCE VALUE args
 0 INSTANCE VALUE args-len
@@ -126,11 +127,11 @@ CONSTANT /gpt-part-entry
 ;
 
 
-\ read sector to array "block"
-: read-sector ( sector-number -- )
+\ read sector to array "disk-buf"
+: read-disk-buf ( sector-number -- )
\ block-size is 0x200 on disks, 0x800 on cdrom drives
block-size * 0 seek drop  \ seek to sector
-   block block-size read drop\ read sector
+   disk-buf block-size read drop\ read sector
 ;
 
 : (.part-entry) ( part-entry )
@@ -149,35 +150,35 @@ CONSTANT /gpt-part-entry
 
 : (.name) r@ begin cell - dup @  = UNTIL xt>name cr type space ;
 
-: init-block ( -- )
+: init-disk-buf ( -- )
s" block-size" ['] $call-parent CATCH IF ABORT" parent has no block-size." 
THEN
to block-size
-   d# 4096 alloc-mem
-   dup d# 4096 erase
-   to block
+   disk-buf-size alloc-mem
+   dup disk-buf-size erase
+   to disk-buf
debug-disk-label? IF
-  ." init-block: block-size=" block-size .d ." block=0x" block u. cr
+  ." init-disk-buf: block-size=" block-size .d ." disk-buf=0x" disk-buf u. 
cr
THEN
 ;
 
 : partition>part-entry ( partition -- part-entry )
-   1- /partition-entry * block mbr>partition-table +
+   1- /partition-entry * disk-buf mbr>partition-table +
 ;
 
 : partition>start-sector ( partition -- sector-offset )
partition>part-entry part-entry>sector-offset l@-le
 ;
 
-\ This word returns true if the currently loaded block has _NO_ MBR magic
+\ This word returns true if the currently loaded disk-buf has _NO_ MBR magic
 : no-mbr? ( -- true|false )
-   0 read-sector
+   0 read-disk-buf
1 partition>part-entry part-entry>id c@ ee = IF TRUE EXIT THEN \ GPT 
partition found
-   block mbr>magic w@-le aa55 <>
+   disk-buf mbr>magic w@-le aa55 <>
 ;
 
-\ This word returns true if the currently loaded block has _NO_ GPT partition 
id
+\ This word returns true if the currently loaded disk-buf has _NO_ GPT 
partition id
 : no-gpt? ( -- true|false )
-   0 read-sector
+   0 read-disk-buf
1 partition>part-entry part-entry>id c@ ee <>
 ;
 
@@ -197,7 +198,7 @@ CONSTANT /gpt-part-entry
  part-entry>sector-offset l@-le( current sector )
  dup to part-start to lpart-start  ( current )
  BEGIN
-part-start read-sector  \ read EBR
+part-start read-disk-buf  \ read EBR
 1 partition>start-sector IF
\ ." Logical Partition found at " part-start .d cr
1+
@@ -240,7 +241,7 @@ CONSTANT /gpt-part-entry
 part-entry>sector-offset l@-le( log-part current sector )
 dup to part-start to lpart-start  ( log-part current )
 BEGIN
-   part-start read-sector \ read EBR
+   part-start read-disk-buf \ read EBR
1 partition>start-sector IF\ first partition entry
   1+ 2dup = IF( log-part current )
  2drop
@@ -306,13 +307,13 @@ CONSTANT /gpt-part-entry
 : has-iso9660-filesystem  ( -- TRUE|FALSE )
\ Seek to the beginning of logical 2048-byte sector 16
\ refer to Chapter C.11.1 in PAPR 2.0 Spec
-   \ was: 10 read-sector, but this might cause trouble if you
+   \ was: 10 read-disk-buf, but this might cause trouble if you
\ try booting an ISO image from a device with 512b sectors.
10 800 * 0 seek drop  \ seek to sector
-   block 800 read drop   \ read sector
+   disk-buf 800 read drop   \ read sector
\ Check for CD-ROM volume magic:
-   block c@ 1 =
-   block 1+ 5 s" CD001"  str=
+   disk-buf c@ 1 =
+   disk-buf 1+ 5 s" CD001"  str=
and
dup IF 800 to block-size THEN
 ;
@@ -361,7 +362,7 @@ C612CONSTANT GPT-PREP-PARTITION-2
 AA268B49521E5A8BCONSTANT GPT-PREP-PARTITION-4
 
 : gpt-prep-partition? ( -- true|false )
-   block gpt-part-entry>part-type-guid
+   disk-buf gpt-part-entry>part-type-guid
dup l@-le GPT-PREP-PARTITION-1 <> IF drop false EXIT THEN
dup 4 + w@-le GPT-PREP-PARTITION-2 <> IF drop false EXIT THEN
dup 6 +

[PATCH SLOF v3 4/5] disk-label: introduce helper to check fat filesystem

2015-06-30 Thread Nikunj A Dadhania
Signed-off-by: Nikunj A Dadhania 
Reviewed-by: Thomas Huth 
---
 slof/fs/packages/disk-label.fs | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/slof/fs/packages/disk-label.fs b/slof/fs/packages/disk-label.fs
index e5a0546..347dc5d 100644
--- a/slof/fs/packages/disk-label.fs
+++ b/slof/fs/packages/disk-label.fs
@@ -321,6 +321,14 @@ CONSTANT /gpt-part-entry
 
 \ Load from first active DOS boot partition.
 
+: fat-bootblock? ( addr -- flag )
+   \ byte 0-2 of the bootblock is a jump instruction in
+   \ all FAT filesystems.
+   \ e9 and eb are jump instructions in x86 assembler.
+   dup c@ e9 = IF drop true EXIT THEN
+   dup c@ eb = swap 2+ c@ 90 = and
+;
+
 \ NOTE: block-size is always 512 bytes for DOS partition tables.
 
 : load-from-dos-boot-partition ( addr -- size )
@@ -548,14 +556,7 @@ AA268B49521E5A8BCONSTANT GPT-PREP-PARTITION-4
 : try-dos-files ( -- found? )
no-mbr? IF false EXIT THEN
 
-   \ disk-buf 0 byte 0-2 is a jump instruction in all FAT
-   \ filesystems.
-   \ e9 and eb are jump instructions in x86 assembler.
-   disk-buf c@ e9 <> IF
-  disk-buf c@ eb <>
-  disk-buf 2+ c@ 90 <> or
-  IF false EXIT THEN
-   THEN
+   disk-buf fat-bootblock? 0= IF false EXIT THEN
s" fat-files" (interpose-filesystem)
true
 ;
-- 
2.4.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH SLOF v3 5/5] disk-label: add support for booting from GPT FAT partition

2015-06-30 Thread Nikunj A Dadhania
For a GPT+LVM combination disk, older bootloader that does not support
LVM, cannot load kernel from LVM.

The patch adds support to read from BASIC_DATA UUID partitions for the
case that the OS installer has installed the CHRP-BOOT config on a FAT
file system.

Makes GPT detection robust
* Check for Protective MBR Magic
* Check for valid GPT Signature
* Boundary check for allocated block size before reading into the
  buffer

Signed-off-by: Nikunj A Dadhania 
---
 slof/fs/packages/disk-label.fs | 99 +-
 1 file changed, 79 insertions(+), 20 deletions(-)

diff --git a/slof/fs/packages/disk-label.fs b/slof/fs/packages/disk-label.fs
index 347dc5d..5267ddb 100644
--- a/slof/fs/packages/disk-label.fs
+++ b/slof/fs/packages/disk-label.fs
@@ -179,7 +179,8 @@ CONSTANT /gpt-part-entry
 \ This word returns true if the currently loaded disk-buf has _NO_ GPT 
partition id
 : no-gpt? ( -- true|false )
0 read-disk-buf
-   1 partition>part-entry part-entry>id c@ ee <>
+   1 partition>part-entry part-entry>id c@ ee <> IF true EXIT THEN
+   disk-buf mbr>magic w@-le aa55 <>
 ;
 
 : pc-extended-partition? ( part-entry-addr -- true|false )
@@ -267,7 +268,10 @@ CONSTANT /gpt-part-entry
 
 : try-dos-partition ( -- okay? )
\ Read partition table and check magic.
-   no-mbr? IF cr ." No DOS disk-label found." cr false EXIT THEN
+   no-mbr? IF
+   debug-disk-label? IF cr ." No DOS disk-label found." cr THEN
+   false EXIT
+   THEN
 
count-dos-logical-partitions TO dos-logical-partitions
 
@@ -377,28 +381,82 @@ AA268B49521E5A8BCONSTANT GPT-PREP-PARTITION-4
8 + x@GPT-PREP-PARTITION-4 =
 ;
 
-: load-from-gpt-prep-partition ( addr -- size )
-   no-gpt? IF drop false EXIT THEN
-   debug-disk-label? IF
-  cr ." GPT partition found " cr
-   THEN
-   1 read-disk-buf disk-buf gpt>part-entry-lba l@-le
+\ Check for GPT MSFT BASIC DATA GUID - fat based
+EBD0A0A2CONSTANT GPT-BASIC-DATA-PARTITION-1
+B9E5CONSTANT GPT-BASIC-DATA-PARTITION-2
+4433CONSTANT GPT-BASIC-DATA-PARTITION-3
+87C068B6B72699C7CONSTANT GPT-BASIC-DATA-PARTITION-4
+
+: gpt-basic-data-partition? ( -- true|false )
+   disk-buf gpt-part-entry>part-type-guid
+   dup l@-le GPT-BASIC-DATA-PARTITION-1 <> IF drop false EXIT THEN
+   dup 4 + w@-le GPT-BASIC-DATA-PARTITION-2 <> IF drop false EXIT THEN
+   dup 6 + w@-le GPT-BASIC-DATA-PARTITION-3 <> IF drop false EXIT THEN
+   8 + x@GPT-BASIC-DATA-PARTITION-4 =
+;
+
+\
+\ GPT Signature
+\ ("EFI PART", 45h 46h 49h 20h 50h 41h 52h 54h)
+\
+4546492050415254 CONSTANT GPT-SIGNATURE
+
+\ The routine checks whether the protective MBR has GPT ID and then
+\ reads the gpt data from the sector. Also set the seek position and
+\ the partition size used in caller routines.
+
+: get-gpt-partition ( -- true|false )
+   no-gpt? IF false EXIT THEN
+   debug-disk-label? IF cr ." GPT partition found " cr  THEN
+   1 read-disk-buf
+   disk-buf gpt>part-entry-lba x@-le
block-size * to seek-pos
disk-buf gpt>part-entry-size l@-le to gpt-part-size
-   disk-buf gpt>num-part-entry l@-le dup 0= IF false EXIT THEN
+   gpt-part-size disk-buf-size > IF
+  cr ." GPT part size exceeds buffer allocated " cr
+  false exit
+   THEN
+   disk-buf gpt>signature x@ GPT-SIGNATURE =
+;
+
+: load-from-gpt-prep-partition ( addr -- size )
+   get-gpt-partition 0= IF false EXIT THEN
+   disk-buf gpt>num-part-entry l@-le dup 0= IF false exit THEN
1+ 1 ?DO
   seek-pos 0 seek drop
   disk-buf gpt-part-size read drop gpt-prep-partition? IF
- debug-disk-label? IF
-." GPT PReP partition found " cr
- THEN
- disk-buf gpt-part-entry>first-lba x@-le
- disk-buf gpt-part-entry>last-lba x@-le
- over - 1+ ( addr offset len )
- swap  ( addr len offset )
- block-size * to part-offset
- 0 0 seek drop ( addr len )
- block-size * read ( size )
+ debug-disk-label? IF  ." GPT PReP partition found " cr THEN
+ disk-buf gpt-part-entry>first-lba x@-le ( addr first-lba )
+ disk-buf gpt-part-entry>last-lba x@-le  ( addr first-lba last-lba)
+ over - 1+( addr first-lba blocks )
+ swap ( addr blocks first-lba )
+ block-size * to part-offset  ( addr blocks )
+ 0 0 seek drop( addr blocks )
+ block-size * read( size )
+ UNLOOP EXIT
+ THEN
+ seek-pos gpt-part-size i * + to seek-pos
+   LOOP
+   false
+;
+
+: try-gpt-dos-partition ( -- true|false )
+   get-gpt-partition 0= IF false EXIT THEN
+   disk-buf gpt>num-part-entry l@-le dup 0= IF false EXIT THEN
+   1+ 1 ?DO
+  seek-pos 0 seek drop
+  disk-buf gpt-part-size read drop
+  gpt-basic-data-partition? IF
+ debug-disk-label? IF ." GPT BASIC DATA partition

Re: [PATCH SLOF v3 5/5] disk-label: add support for booting from GPT FAT partition

2015-06-30 Thread Thomas Huth

Sorry, every time I look at this gpt stuff, my eyes stumble
over something new ...

On Tue, 30 Jun 2015 16:31:21 +0530
Nikunj A Dadhania  wrote:

> For a GPT+LVM combination disk, older bootloader that does not support
> LVM, cannot load kernel from LVM.
> 
> The patch adds support to read from BASIC_DATA UUID partitions for the
> case that the OS installer has installed the CHRP-BOOT config on a FAT
> file system.
> 
> Makes GPT detection robust
> * Check for Protective MBR Magic
> * Check for valid GPT Signature
> * Boundary check for allocated block size before reading into the
>   buffer
> 
> Signed-off-by: Nikunj A Dadhania 
> ---
>  slof/fs/packages/disk-label.fs | 99 
> +-
>  1 file changed, 79 insertions(+), 20 deletions(-)
> 
> diff --git a/slof/fs/packages/disk-label.fs b/slof/fs/packages/disk-label.fs
> index 347dc5d..5267ddb 100644
> --- a/slof/fs/packages/disk-label.fs
> +++ b/slof/fs/packages/disk-label.fs
...
> +\ The routine checks whether the protective MBR has GPT ID and then
> +\ reads the gpt data from the sector. Also set the seek position and
> +\ the partition size used in caller routines.
> +
> +: get-gpt-partition ( -- true|false )
> +   no-gpt? IF false EXIT THEN
> +   debug-disk-label? IF cr ." GPT partition found " cr  THEN
> +   1 read-disk-buf
> +   disk-buf gpt>part-entry-lba x@-le
> block-size * to seek-pos
> disk-buf gpt>part-entry-size l@-le to gpt-part-size
> -   disk-buf gpt>num-part-entry l@-le dup 0= IF false EXIT THEN
> +   gpt-part-size disk-buf-size > IF
> +  cr ." GPT part size exceeds buffer allocated " cr
> +  false exit
> +   THEN
> +   disk-buf gpt>signature x@ GPT-SIGNATURE =
> +;
> +
> +: load-from-gpt-prep-partition ( addr -- size )
> +   get-gpt-partition 0= IF false EXIT THEN
> +   disk-buf gpt>num-part-entry l@-le dup 0= IF false exit THEN
> 1+ 1 ?DO
>seek-pos 0 seek drop
>disk-buf gpt-part-size read drop gpt-prep-partition? IF
> - debug-disk-label? IF
> -." GPT PReP partition found " cr
> - THEN
> - disk-buf gpt-part-entry>first-lba x@-le
> - disk-buf gpt-part-entry>last-lba x@-le
> - over - 1+ ( addr offset len )
> - swap  ( addr len offset )
> - block-size * to part-offset
> - 0 0 seek drop ( addr len )
> - block-size * read ( size )
> + debug-disk-label? IF  ." GPT PReP partition found " cr THEN
> + disk-buf gpt-part-entry>first-lba x@-le ( addr first-lba )
> + disk-buf gpt-part-entry>last-lba x@-le  ( addr first-lba last-lba)
> + over - 1+( addr first-lba blocks )
> + swap ( addr blocks first-lba )
> + block-size * to part-offset  ( addr blocks )
> + 0 0 seek drop( addr blocks )
> + block-size * read( size )
> + UNLOOP EXIT
> + THEN
> + seek-pos gpt-part-size i * + to seek-pos

Is this the right way to update the seek pos? Looks somewhat suspicious
to me, shouldn't this rather be:

seek-pos gpt-part-size + to seek-pos

or maybe if you store the base value somewhere instead, something like:

seek-pos-base gpt-part-size i * + to seek-pos

?

> +   LOOP
> +   false
> +;
> +
> +: try-gpt-dos-partition ( -- true|false )
> +   get-gpt-partition 0= IF false EXIT THEN
> +   disk-buf gpt>num-part-entry l@-le dup 0= IF false EXIT THEN
> +   1+ 1 ?DO
> +  seek-pos 0 seek drop
> +  disk-buf gpt-part-size read drop
> +  gpt-basic-data-partition? IF
> + debug-disk-label? IF ." GPT BASIC DATA partition found " cr THEN
> + disk-buf gpt-part-entry>first-lba x@-le   ( first-lba )
> + dup to part-start  ( first-lba )
> + disk-buf gpt-part-entry>last-lba x@-le( first-lba last-lba )
> + over - 1+  ( first-lba s1 )
> + block-size * to part-size  ( first-lba )
> + block-size * to part-offset( )
> + 0 0 seek drop
> + disk-buf block-size read drop
> + disk-buf fat-bootblock?( true|false )
>   UNLOOP EXIT
>THEN
>seek-pos gpt-part-size i * + to seek-pos

dito (so this bug was likely there before?)

 Thomas
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH SLOF v3 5/5] disk-label: add support for booting from GPT FAT partition

2015-06-30 Thread Nikunj A Dadhania
Thomas Huth  writes:

> Sorry, every time I look at this gpt stuff, my eyes stumble
> over something new ...

No worries :-)

> On Tue, 30 Jun 2015 16:31:21 +0530
> Nikunj A Dadhania  wrote:
>
>> For a GPT+LVM combination disk, older bootloader that does not support
>> LVM, cannot load kernel from LVM.
>> 
>> The patch adds support to read from BASIC_DATA UUID partitions for the
>> case that the OS installer has installed the CHRP-BOOT config on a FAT
>> file system.
>> 
>> Makes GPT detection robust
>> * Check for Protective MBR Magic
>> * Check for valid GPT Signature
>> * Boundary check for allocated block size before reading into the
>>   buffer
>> 
>> Signed-off-by: Nikunj A Dadhania 
>> ---
>>  slof/fs/packages/disk-label.fs | 99 
>> +-
>>  1 file changed, 79 insertions(+), 20 deletions(-)
>> 
>> diff --git a/slof/fs/packages/disk-label.fs b/slof/fs/packages/disk-label.fs
>> index 347dc5d..5267ddb 100644
>> --- a/slof/fs/packages/disk-label.fs
>> +++ b/slof/fs/packages/disk-label.fs
> ...
>> +\ The routine checks whether the protective MBR has GPT ID and then
>> +\ reads the gpt data from the sector. Also set the seek position and
>> +\ the partition size used in caller routines.
>> +
>> +: get-gpt-partition ( -- true|false )
>> +   no-gpt? IF false EXIT THEN
>> +   debug-disk-label? IF cr ." GPT partition found " cr  THEN
>> +   1 read-disk-buf
>> +   disk-buf gpt>part-entry-lba x@-le
>> block-size * to seek-pos
>> disk-buf gpt>part-entry-size l@-le to gpt-part-size
>> -   disk-buf gpt>num-part-entry l@-le dup 0= IF false EXIT THEN
>> +   gpt-part-size disk-buf-size > IF
>> +  cr ." GPT part size exceeds buffer allocated " cr
>> +  false exit
>> +   THEN
>> +   disk-buf gpt>signature x@ GPT-SIGNATURE =
>> +;
>> +
>> +: load-from-gpt-prep-partition ( addr -- size )
>> +   get-gpt-partition 0= IF false EXIT THEN
>> +   disk-buf gpt>num-part-entry l@-le dup 0= IF false exit THEN
>> 1+ 1 ?DO
>>seek-pos 0 seek drop
>>disk-buf gpt-part-size read drop gpt-prep-partition? IF
>> - debug-disk-label? IF
>> -." GPT PReP partition found " cr
>> - THEN
>> - disk-buf gpt-part-entry>first-lba x@-le
>> - disk-buf gpt-part-entry>last-lba x@-le
>> - over - 1+ ( addr offset len )
>> - swap  ( addr len offset )
>> - block-size * to part-offset
>> - 0 0 seek drop ( addr len )
>> - block-size * read ( size )
>> + debug-disk-label? IF  ." GPT PReP partition found " cr THEN
>> + disk-buf gpt-part-entry>first-lba x@-le ( addr first-lba )
>> + disk-buf gpt-part-entry>last-lba x@-le  ( addr first-lba last-lba)
>> + over - 1+( addr first-lba blocks )
>> + swap ( addr blocks first-lba )
>> + block-size * to part-offset  ( addr blocks )
>> + 0 0 seek drop( addr blocks )
>> + block-size * read( size )
>> + UNLOOP EXIT
>> + THEN
>> + seek-pos gpt-part-size i * + to seek-pos
>
> Is this the right way to update the seek pos?

Good catch !! its jumping ahead, should go in the order of 128byte
(gpt-part-size)

> Looks somewhat suspicious
> to me, shouldn't this rather be:
>
>   seek-pos gpt-part-size + to seek-pos

Would use this. Updated patch attached.

> or maybe if you store the base value somewhere instead, something like:
>
>   seek-pos-base gpt-part-size i * + to seek-pos
>
> ?
>
>> +   LOOP
>> +   false
>> +;
>> +
>> +: try-gpt-dos-partition ( -- true|false )
>> +   get-gpt-partition 0= IF false EXIT THEN
>> +   disk-buf gpt>num-part-entry l@-le dup 0= IF false EXIT THEN
>> +   1+ 1 ?DO
>> +  seek-pos 0 seek drop
>> +  disk-buf gpt-part-size read drop
>> +  gpt-basic-data-partition? IF
>> + debug-disk-label? IF ." GPT BASIC DATA partition found " cr THEN
>> + disk-buf gpt-part-entry>first-lba x@-le   ( first-lba )
>> + dup to part-start  ( first-lba )
>> + disk-buf gpt-part-entry>last-lba x@-le( first-lba last-lba 
>> )
>> + over - 1+  ( first-lba s1 )
>> + block-size * to part-size  ( first-lba )
>> + block-size * to part-offset( )
>> + 0 0 seek drop
>> + disk-buf block-size read drop
>> + disk-buf fat-bootblock?( true|false )
>>   UNLOOP EXIT
>>THEN
>>seek-pos gpt-part-size i * + to seek-pos
>
> dito (so this bug was likely there before?)

Seems was working because it happens to be the first partition. If not
would have failed.


disk-label: add support for booting from GPT FAT partition

For a GPT+LVM combination disk, older bootloader that does not support
LVM, cannot 

[PATCH v2] powerpc32: rearrange instructions order in ip_fast_csum()

2015-06-30 Thread Christophe Leroy
On PPC_8xx, lwz has a 2 cycles latency, and branching also takes
2 cycles. On some other powerpc, lwz has 3 cycles.

As the size of the header is minimum 5 words, we can unroll the loop
for the first words to reduce number of branching, and we can re-order
the instructions to limit loading latency.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/lib/checksum_32.S | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/lib/checksum_32.S b/arch/powerpc/lib/checksum_32.S
index 9c48ee0..6fbadfe 100644
--- a/arch/powerpc/lib/checksum_32.S
+++ b/arch/powerpc/lib/checksum_32.S
@@ -27,13 +27,16 @@
 _GLOBAL(ip_fast_csum)
lwz r0,0(r3)
lwzur5,4(r3)
-   addic.  r4,r4,-2
+   lwzur6,4(r3)
+   lwzur7,4(r3)
+   addir4,r4,-4
addcr0,r0,r5
mtctr   r4
-   blelr-
-1: lwzur4,4(r3)
-   adder0,r0,r4
+   adder0,r0,r6
+1: adder0,r0,r7
+   lwzur7,4(r3)
bdnz1b
+   adder0,r0,r7
addze   r0,r0   /* add in final carry */
rlwinm  r3,r0,16,0,31   /* fold two halves together */
add r3,r0,r3
-- 
2.1.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 0/2] powerpc32: Optimise csum_partial()

2015-06-30 Thread Christophe Leroy
The purpose of this patchset is to optimise csum_partial() on powerpc32.
In the first part, we remove some unneccessary instructions
In the second part, we partially unloop the main loop

Christophe Leroy (2):
  Optimise a few instructions in csum_partial()
  Optimise csum_partial() loop

 arch/powerpc/lib/checksum_32.S | 53 +-
 1 file changed, 32 insertions(+), 21 deletions(-)

-- 
2.1.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 1/2] powerpc32: optimise a few instructions in csum_partial()

2015-06-30 Thread Christophe Leroy
r5 does contain the value to be updated, so lets use r5 all way long
for that. It makes the code more readable.

To avoid confusion, it is better to use adde instead of addc

The first addition is useless. Its only purpose is to clear carry.
As r4 is a signed int that is always positive, this can be done by
using srawi instead of srwi

Let's also remove the comment about dcbz having no overhead as it
is not correct on all powerpc, at least on MPC8xx

In the last part, in our situation, the remaining quantity of bytes
to be proceeded is between 0 and 3. Therefore, we can base that part
on the value of bit 31 and bit 30 of r4 instead of anding r4 with 3
then proceding on comparisons and substractions.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/lib/checksum_32.S | 37 +
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/lib/checksum_32.S b/arch/powerpc/lib/checksum_32.S
index 7b95a68..2e4879c 100644
--- a/arch/powerpc/lib/checksum_32.S
+++ b/arch/powerpc/lib/checksum_32.S
@@ -64,35 +64,32 @@ _GLOBAL(csum_tcpudp_magic)
  * csum_partial(buff, len, sum)
  */
 _GLOBAL(csum_partial)
-   addic   r0,r5,0
subir3,r3,4
-   srwi.   r6,r4,2
+   srawi.  r6,r4,2 /* Divide len by 4 and also clear carry */
beq 3f  /* if we're doing < 4 bytes */
-   andi.   r5,r3,2 /* Align buffer to longword boundary */
+   andi.   r0,r3,2 /* Align buffer to longword boundary */
beq+1f
-   lhz r5,4(r3)/* do 2 bytes to get aligned */
-   addir3,r3,2
+   lhz r0,4(r3)/* do 2 bytes to get aligned */
subir4,r4,2
-   addcr0,r0,r5
+   addir3,r3,2
srwi.   r6,r4,2 /* # words to do */
+   adder5,r5,r0
beq 3f
 1: mtctr   r6
-2: lwzur5,4(r3)/* the bdnz has zero overhead, so it should */
-   adder0,r0,r5/* be unnecessary to unroll this loop */
+2: lwzur0,4(r3)
+   adder5,r5,r0
bdnz2b
-   andi.   r4,r4,3
-3: cmpwi   0,r4,2
-   blt+4f
-   lhz r5,4(r3)
+3: andi.   r0,r4,2
+   beq+4f
+   lhz r0,4(r3)
addir3,r3,2
-   subir4,r4,2
-   adder0,r0,r5
-4: cmpwi   0,r4,1
-   bne+5f
-   lbz r5,4(r3)
-   slwir5,r5,8 /* Upper byte of word */
-   adder0,r0,r5
-5: addze   r3,r0   /* add in final carry */
+   adder5,r5,r0
+4: andi.   r0,r4,1
+   beq+5f
+   lbz r0,4(r3)
+   slwir0,r0,8 /* Upper byte of word */
+   adder5,r5,r0
+5: addze   r3,r5   /* add in final carry */
blr
 
 /*
-- 
2.1.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 2/2] powerpc32: optimise csum_partial() loop

2015-06-30 Thread Christophe Leroy
On the 8xx, load latency is 2 cycles and taking branches also takes
2 cycles. So let's unroll the loop.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/lib/checksum_32.S | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/lib/checksum_32.S b/arch/powerpc/lib/checksum_32.S
index 2e4879c..9c48ee0 100644
--- a/arch/powerpc/lib/checksum_32.S
+++ b/arch/powerpc/lib/checksum_32.S
@@ -75,10 +75,24 @@ _GLOBAL(csum_partial)
srwi.   r6,r4,2 /* # words to do */
adder5,r5,r0
beq 3f
-1: mtctr   r6
+1: andi.   r6,r6,3 /* Prepare to handle words 4 by 4 */
+   beq 21f
+   mtctr   r6
 2: lwzur0,4(r3)
adder5,r5,r0
bdnz2b
+21:srwi.   r6,r4,4 /* # blocks of 4 words to do */
+   beq 3f
+   mtctr   r6
+22:lwzur0,4(r3)
+   lwzur6,4(r3)
+   lwzur7,4(r3)
+   lwzur8,4(r3)
+   adder5,r5,r0
+   adder5,r5,r6
+   adder5,r5,r7
+   adder5,r5,r8
+   bdnz22b
 3: andi.   r0,r4,2
beq+4f
lhz r0,4(r3)
-- 
2.1.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH] Fix pSeries boot failure, by returning interrupt controller node when an interrupt-map property doesn't exist

2015-06-30 Thread Grant Likely
On Tue, 30 Jun 2015 13:23:33 +1000
, Benjamin Herrenschmidt 
 wrote:
> On Mon, 2015-06-29 at 18:50 -0500, Jeremy Linton wrote:
> > This is a reformat of the patch attached to "pSeries boot failure due
> > to wrong interrupt controller".
> > 
> > It allows of_irq_parse_raw() to return the node pointer of the
> > interrupt controller, rather than the parent bus. This allows
> > ics_rtas_host_match() to detect that the controller is a legacy 8259
> > and avoid using xics. This avoids an RTAS assertion/crash during early
> > kernel bootstrapping
> > 
> > Signed-off-by: Jeremy Linton 
> 
> Reviewed-by: Benjamin Herrenschmidt 
> ---
> 
> Rob, do you want to take this or should we ?

Merged, thanks.

Jeremy, please check your mailer configuration. The patch was mangled
and would not apply. I had to fix it up manually.

Also, does this patch need to be backported into stable? What commit
introduced this bug, and which kernel does it first appear in?

Thanks,
g.

> 
> > ---
> >  drivers/of/irq.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/drivers/of/irq.c b/drivers/of/irq.c
> > index 1a79806..cb4b9ae 100644
> > --- a/drivers/of/irq.c
> > +++ b/drivers/of/irq.c
> > @@ -252,8 +252,6 @@ int of_irq_parse_raw(const __be32 *addr, struct
> > of_phandle_args *out_irq)
> >  * Successfully parsed an interrrupt-map translation; copy 
> > new
> >  * interrupt specifier into the out_irq structure
> >  */
> > -   out_irq->np = newpar;
> > -
> > match_array = imap - newaddrsize - newintsize;
> > for (i = 0; i < newintsize; i++)
> > out_irq->args[i] = be32_to_cpup(imap - newintsize + 
> > i);
> > @@ -262,6 +260,7 @@ int of_irq_parse_raw(const __be32 *addr, struct
> > of_phandle_args *out_irq)
> > 
> > skiplevel:
> > /* Iterate again with new parent */
> > +   out_irq->np = newpar;
> > pr_debug(" -> new parent: %s\n", of_node_full_name(newpar));
> > of_node_put(ipar);
> > ipar = newpar;
> > --
> > 1.8.1.4
> 
> 

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH] Fix pSeries boot failure, by returning interrupt controller node when an interrupt-map property doesn't exist

2015-06-30 Thread Jeremy Linton
On 6/30/2015 11:01 AM, Grant Likely wrote:
> Merged, thanks.
Thanks!

> Jeremy, please check your mailer configuration. The patch was mangled
> and would not apply. I had to fix it up manually.

Sorry about that, I will see about creating a better setup (aka not 
gmail/web
client) for patches I send from home.

> Also, does this patch need to be backported into stable? What commit
> introduced this bug, and which kernel does it first appear in?

I didn't bisect the problem so i'm not 100% sure, but I think the 
commit that
caused this was 2361613206e66ce59cc0e08efa8d98ec15b84ed1 AKA 3.13. For me I
don't need stable, I just pulled the machine forward on a whim in order to build
some other things. I will try to do that more frequently due to the fact that
the bug existed for a little over a year..



___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH SLOF v3 5/5] disk-label: add support for booting from GPT FAT partition

2015-06-30 Thread Thomas Huth
On Tue, 30 Jun 2015 17:54:14 +0530
Nikunj A Dadhania  wrote:
> 
> disk-label: add support for booting from GPT FAT partition
> 
> For a GPT+LVM combination disk, older bootloader that does not support
> LVM, cannot load kernel from LVM.
> 
> The patch adds support to read from BASIC_DATA UUID partitions for the
> case that the OS installer has installed the CHRP-BOOT config on a FAT
> file system.
> 
> Makes GPT detection robust
> * Fix bug in seek-pos updation code
> * Check for Protective MBR Magic
> * Check for valid GPT Signature
> * Boundary check for allocated block size before reading into the
>   buffer
> 
> Signed-off-by: Nikunj A Dadhania 
> 
> diff --git a/slof/fs/packages/disk-label.fs b/slof/fs/packages/disk-label.fs
> index 347dc5d..fa5df27 100644
> --- a/slof/fs/packages/disk-label.fs
> +++ b/slof/fs/packages/disk-label.fs
> @@ -179,7 +179,8 @@ CONSTANT /gpt-part-entry
>  \ This word returns true if the currently loaded disk-buf has _NO_ GPT 
> partition id
>  : no-gpt? ( -- true|false )
> 0 read-disk-buf
> -   1 partition>part-entry part-entry>id c@ ee <>
> +   1 partition>part-entry part-entry>id c@ ee <> IF true EXIT THEN
> +   disk-buf mbr>magic w@-le aa55 <>
>  ;
>  
>  : pc-extended-partition? ( part-entry-addr -- true|false )
> @@ -267,7 +268,10 @@ CONSTANT /gpt-part-entry
>  
>  : try-dos-partition ( -- okay? )
> \ Read partition table and check magic.
> -   no-mbr? IF cr ." No DOS disk-label found." cr false EXIT THEN
> +   no-mbr? IF
> +   debug-disk-label? IF cr ." No DOS disk-label found." cr THEN
> +   false EXIT
> +   THEN
>  
> count-dos-logical-partitions TO dos-logical-partitions
>  
> @@ -377,31 +381,85 @@ AA268B49521E5A8BCONSTANT GPT-PREP-PARTITION-4
> 8 + x@GPT-PREP-PARTITION-4 =
>  ;
>  
> -: load-from-gpt-prep-partition ( addr -- size )
> -   no-gpt? IF drop false EXIT THEN
> -   debug-disk-label? IF
> -  cr ." GPT partition found " cr
> -   THEN
> -   1 read-disk-buf disk-buf gpt>part-entry-lba l@-le
> +\ Check for GPT MSFT BASIC DATA GUID - fat based
> +EBD0A0A2CONSTANT GPT-BASIC-DATA-PARTITION-1
> +B9E5CONSTANT GPT-BASIC-DATA-PARTITION-2
> +4433CONSTANT GPT-BASIC-DATA-PARTITION-3
> +87C068B6B72699C7CONSTANT GPT-BASIC-DATA-PARTITION-4
> +
> +: gpt-basic-data-partition? ( -- true|false )
> +   disk-buf gpt-part-entry>part-type-guid
> +   dup l@-le GPT-BASIC-DATA-PARTITION-1 <> IF drop false EXIT THEN
> +   dup 4 + w@-le GPT-BASIC-DATA-PARTITION-2 <> IF drop false EXIT THEN
> +   dup 6 + w@-le GPT-BASIC-DATA-PARTITION-3 <> IF drop false EXIT THEN
> +   8 + x@GPT-BASIC-DATA-PARTITION-4 =
> +;
> +
> +\
> +\ GPT Signature
> +\ ("EFI PART", 45h 46h 49h 20h 50h 41h 52h 54h)
> +\
> +4546492050415254 CONSTANT GPT-SIGNATURE
> +
> +\ The routine checks whether the protective MBR has GPT ID and then
> +\ reads the gpt data from the sector. Also set the seek position and
> +\ the partition size used in caller routines.
> +
> +: get-gpt-partition ( -- true|false )
> +   no-gpt? IF false EXIT THEN
> +   debug-disk-label? IF cr ." GPT partition found " cr  THEN
> +   1 read-disk-buf
> +   disk-buf gpt>part-entry-lba x@-le
> block-size * to seek-pos
> disk-buf gpt>part-entry-size l@-le to gpt-part-size
> -   disk-buf gpt>num-part-entry l@-le dup 0= IF false EXIT THEN
> +   gpt-part-size disk-buf-size > IF
> +  cr ." GPT part size exceeds buffer allocated " cr
> +  false exit
> +   THEN
> +   disk-buf gpt>signature x@ GPT-SIGNATURE =
> +;
> +
> +: load-from-gpt-prep-partition ( addr -- size )
> +   get-gpt-partition 0= IF false EXIT THEN
> +   disk-buf gpt>num-part-entry l@-le dup 0= IF false exit THEN
> 1+ 1 ?DO
>seek-pos 0 seek drop
>disk-buf gpt-part-size read drop gpt-prep-partition? IF
> - debug-disk-label? IF
> -." GPT PReP partition found " cr
> - THEN
> - disk-buf gpt-part-entry>first-lba x@-le
> - disk-buf gpt-part-entry>last-lba x@-le
> - over - 1+ ( addr offset len )
> - swap  ( addr len offset )
> - block-size * to part-offset
> - 0 0 seek drop ( addr len )
> - block-size * read ( size )
> + debug-disk-label? IF  ." GPT PReP partition found " cr THEN
> + disk-buf gpt-part-entry>first-lba x@-le ( addr first-lba )
> + disk-buf gpt-part-entry>last-lba x@-le  ( addr first-lba last-lba)
> + over - 1+( addr first-lba blocks )
> + swap ( addr blocks first-lba )
> + block-size * to part-offset  ( addr blocks )
> + 0 0 seek drop( addr blocks )
> + block-size * read( size )
> + UNLOOP EXIT
> + THEN
> + seek-pos gpt-part-size + to seek-pos
> +   LOOP
> +   fa

Re: [PATCH v5 42/42] pci/hotplug: PowerPC PowerNV PCI hotplug driver

2015-06-30 Thread Grant Likely
On Thu,  4 Jun 2015 16:42:11 +1000
, Gavin Shan 
 wrote:
> The patch intends to add standalone driver to support PCI hotplug
> for PowerPC PowerNV platform, which runs on top of skiboot firmware.
> The firmware identified hotpluggable slots and marked their device
> tree node with proper "ibm,slot-pluggable" and "ibm,reset-by-firmware".
> The driver simply scans device-tree to create/register PCI hotplug slot
> accordingly.
> 
> If the skiboot firmware doesn't support slot status retrieval, the PCI
> slot device node shouldn't have property "ibm,reset-by-firmware". In
> that case, none of valid PCI slots will be detected from device tree.
> The skiboot firmware doesn't export the capability to access attention
> LEDs yet and it's something for TBD.
> 
> Signed-off-by: Gavin Shan 
> ---
> v5:
>   * Use OF OVERLAY to update the device-tree
>   * Removed unnecessary header files
>   * More meaningful return value from powernv_php_register_one()
>   * Use pnv_pci_hotplug_notifier_{register, unregister}()
>   * Decimal values for slot's states
>   * Removed struct powernv_php_slot::release()
>   * Merged two bool arguments to one for powernv_php_slot_enable()
>   * Rename release_device_nodes_info() to remove_device_nodes_info()
>   * Don't check on "!len" in slot_power_on_handler()
>   * Handle return value in get_adapter_status() as suggested by aik
>   * Drop invalid attention status in set_attention_status()
>   * Renaming functions
>   * Fixed coding style and added entry in MAINTAINERS reported by
> checkpatch.pl
> ---
>  MAINTAINERS|   6 +
>  drivers/pci/hotplug/Kconfig|  12 +
>  drivers/pci/hotplug/Makefile   |   4 +
>  drivers/pci/hotplug/powernv_php.c  | 140 +++
>  drivers/pci/hotplug/powernv_php.h  |  90 
>  drivers/pci/hotplug/powernv_php_slot.c | 732 
> +
>  6 files changed, 984 insertions(+)
>  create mode 100644 drivers/pci/hotplug/powernv_php.c
>  create mode 100644 drivers/pci/hotplug/powernv_php.h
>  create mode 100644 drivers/pci/hotplug/powernv_php_slot.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index e308718..f5e1dce 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -7481,6 +7481,12 @@ L: linux-...@vger.kernel.org
>  S:   Supported
>  F:   Documentation/PCI/pci-error-recovery.txt
>  
> +PCI HOTPLUG DRIVER FOR POWERNV PLATFORM
> +M:   Gavin Shan 
> +L:   linux-...@vger.kernel.org
> +S:   Supported
> +F:   drivers/pci/hotplug/powernv_php*
> +
>  PCI SUBSYSTEM
>  M:   Bjorn Helgaas 
>  L:   linux-...@vger.kernel.org
> diff --git a/drivers/pci/hotplug/Kconfig b/drivers/pci/hotplug/Kconfig
> index df8caec..ef55dae 100644
> --- a/drivers/pci/hotplug/Kconfig
> +++ b/drivers/pci/hotplug/Kconfig
> @@ -113,6 +113,18 @@ config HOTPLUG_PCI_SHPC
>  
> When in doubt, say N.
>  
> +config HOTPLUG_PCI_POWERNV
> + tristate "PowerPC PowerNV PCI Hotplug driver"
> + depends on PPC_POWERNV && EEH
> + help
> +   Say Y here if you run PowerPC PowerNV platform that supports
> +  PCI Hotplug
> +
> +   To compile this driver as a module, choose M here: the
> +   module will be called powernv-php.
> +
> +   When in doubt, say N.
> +
>  config HOTPLUG_PCI_RPA
>   tristate "RPA PCI Hotplug driver"
>   depends on PPC_PSERIES && EEH
> diff --git a/drivers/pci/hotplug/Makefile b/drivers/pci/hotplug/Makefile
> index 4a9aa08..a69665e 100644
> --- a/drivers/pci/hotplug/Makefile
> +++ b/drivers/pci/hotplug/Makefile
> @@ -14,6 +14,7 @@ obj-$(CONFIG_HOTPLUG_PCI_PCIE)  += pciehp.o
>  obj-$(CONFIG_HOTPLUG_PCI_CPCI_ZT5550)+= cpcihp_zt5550.o
>  obj-$(CONFIG_HOTPLUG_PCI_CPCI_GENERIC)   += cpcihp_generic.o
>  obj-$(CONFIG_HOTPLUG_PCI_SHPC)   += shpchp.o
> +obj-$(CONFIG_HOTPLUG_PCI_POWERNV)+= powernv-php.o
>  obj-$(CONFIG_HOTPLUG_PCI_RPA)+= rpaphp.o
>  obj-$(CONFIG_HOTPLUG_PCI_RPA_DLPAR)  += rpadlpar_io.o
>  obj-$(CONFIG_HOTPLUG_PCI_SGI)+= sgi_hotplug.o
> @@ -50,6 +51,9 @@ ibmphp-objs :=  ibmphp_core.o   \
>  acpiphp-objs :=  acpiphp_core.o  \
>   acpiphp_glue.o
>  
> +powernv-php-objs :=  powernv_php.o   \
> + powernv_php_slot.o
> +
>  rpaphp-objs  :=  rpaphp_core.o   \
>   rpaphp_pci.o\
>   rpaphp_slot.o
> diff --git a/drivers/pci/hotplug/powernv_php.c 
> b/drivers/pci/hotplug/powernv_php.c
> new file mode 100644
> index 000..4cbff7a
> --- /dev/null
> +++ b/drivers/pci/hotplug/powernv_php.c
> @@ -0,0 +1,140 @@
> +/*
> + * PCI Hotplug Driver for PowerPC PowerNV platform.
> + *
> + * Copyright Gavin Shan, IBM Corporation 2015.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the Lice

Re: [PATCH v5 40/42] drivers/of: Allow to specify root node in of_fdt_unflatten_tree()

2015-06-30 Thread Grant Likely
On Thu,  4 Jun 2015 16:42:09 +1000
, Gavin Shan 
 wrote:
> The patch introduces one more argument to of_fdt_unflatten_tree()
> to specify the root node for the FDT blob, which is going to be
> unflattened. In the result, the function can be used to unflatten
> FDT blob, which represents device sub-tree in subsequent patches.
> 
> Signed-off-by: Gavin Shan 

In principle, looks okay. There are going to be lifecycle issues though
because nodes allocated from unflatten_dt_node cannot be cleanly freed
because they aren't allocated in the same way as OF_DYNAMIC nodes are
allocated.

It may be time to dump the special allocation of fdt.c entirely and
treat all nodes the same way, with name and properties all allocated
with normal kmallocs Investigation is needed to figure out if this
is feasible.

Comments below.

> ---
> v5:
>   * Newly introduced
> ---
>  drivers/of/fdt.c   | 26 ++
>  drivers/of/unittest.c  |  2 +-
>  include/linux/of_fdt.h |  3 ++-
>  3 files changed, 21 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index b87c157..b6a6c59 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -380,9 +380,16 @@ static void *unflatten_dt_node(void *blob,
>  struct device_node **nodepp,
>  bool dryrun)
>  {
> + unsigned long fpsize = 0;
> +
> + if (dad)
> + fpsize = strlen(of_node_full_name(dad));
> + else
> + fpsize = 0;

The 'else' is redundant. Better yet:

unsigned long fpsize = dad ? strlen(of_node_full_name(dad)) : 0;

>   cur_node_depth = 1;
>   return __unflatten_dt_node(blob, mem, poffset,
> -dad, nodepp, 0, dryrun);
> +dad, nodepp, fpsize, dryrun);
>  }
>  
>  /**
> @@ -393,13 +400,15 @@ static void *unflatten_dt_node(void *blob,
>   * pointers of the nodes so the normal device-tree walking functions
>   * can be used.
>   * @blob: The blob to expand
> + * @dad: The root node of the created device_node tree
>   * @mynodes: The device_node tree created by the call
>   * @dt_alloc: An allocator that provides a virtual address to memory
>   * for the resulting tree
>   */
>  static void __unflatten_device_tree(void *blob,
> -  struct device_node **mynodes,
> -  void * (*dt_alloc)(u64 size, u64 align))
> + struct device_node *dad,
> + struct device_node **mynodes,
> + void * (*dt_alloc)(u64 size, u64 align))

Same comment as before, don't reflow the indentation unless you really
need to.

>  {
>   unsigned long size;
>   int start;
> @@ -425,7 +434,7 @@ static void __unflatten_device_tree(void *blob,
>   /* First pass, scan for size */
>   start = 0;
>   size = (unsigned long)unflatten_dt_node(blob, NULL, &start,
> - NULL, NULL, true);
> + dad, NULL, true);
>   size = ALIGN(size, 4);
>  
>   pr_debug("  size is %lx, allocating...\n", size);
> @@ -440,7 +449,7 @@ static void __unflatten_device_tree(void *blob,
>  
>   /* Second pass, do actual unflattening */
>   start = 0;
> - unflatten_dt_node(blob, mem, &start, NULL, mynodes, false);
> + unflatten_dt_node(blob, mem, &start, dad, mynodes, false);
>   if (be32_to_cpup(mem + size) != 0xdeadbeef)
>   pr_warning("End of tree marker overwritten: %08x\n",
>  be32_to_cpup(mem + size));
> @@ -462,9 +471,10 @@ static void *kernel_tree_alloc(u64 size, u64 align)
>   * can be used.
>   */
>  void of_fdt_unflatten_tree(unsigned long *blob,
> - struct device_node **mynodes)
> +struct device_node *dad,
> +struct device_node **mynodes)
>  {
> - __unflatten_device_tree(blob, mynodes, &kernel_tree_alloc);
> + __unflatten_device_tree(blob, dad, mynodes, &kernel_tree_alloc);
>  }
>  EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree);
>  
> @@ -1095,7 +1105,7 @@ bool __init early_init_dt_scan(void *params)
>   */
>  void __init unflatten_device_tree(void)
>  {
> - __unflatten_device_tree(initial_boot_params, &of_root,
> + __unflatten_device_tree(initial_boot_params, NULL, &of_root,
>   early_init_dt_alloc_memory_arch);
>  
>   /* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */
> diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
> index 1801634..2270830 100644
> --- a/drivers/of/unittest.c
> +++ b/drivers/of/unittest.c
> @@ -907,7 +907,7 @@ static int __init unittest_data_add(void)
>   "not running tests\n", __func__);
>   return -ENOMEM;
>   }
> - of_fdt_unflatten_tree(unittest_data, &unittest_data_node);
> + of_fdt_unflatten_tree(unittest_da

Re: [PATCH v5 39/42] drivers/of: Unflatten nodes equal or deeper than specified level

2015-06-30 Thread Grant Likely
On Thu,  4 Jun 2015 16:42:08 +1000
, Gavin Shan 
 wrote:
> unflatten_dt_node() is called recursively to unflatten FDT nodes
> with the assumption that FDT blob has only one root node, which
> isn't true when the FDT blob represents device sub-tree. The
> patch improves the function to supporting device sub-tree that
> have multiple root nodes:
> 
>* Rename original unflatten_dt_node() to __unflatten_dt_node().
>* Wrapper unflatten_dt_node() calls __unflatten_dt_node() with
>  adjusted current node depth to 1 to avoid underflow.
> 
> Signed-off-by: Gavin Shan 
> ---
> v5:
>   * Split from PATCH[v4 19/21]
>   * Fixed "line over 80 characters" from checkpatch.pl
> ---
>  drivers/of/fdt.c | 56 
> ++--
>  1 file changed, 38 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index cde35c5d01..b87c157 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -28,6 +28,8 @@
>  #include   /* for COMMAND_LINE_SIZE */
>  #include 
>  
> +static int cur_node_depth;
> +

k! We'll never be able to call this concurrently this way. That will
create theoretical race conditions in the overlay code. (actually, you
didn't introduce this problem, see below...)

>  /*
>   * of_fdt_limit_memory - limit the number of regions in the /memory node
>   * @limit: maximum entries
> @@ -161,27 +163,26 @@ static void *unflatten_dt_alloc(void **mem, unsigned 
> long size,
>  }
>  
>  /**
> - * unflatten_dt_node - Alloc and populate a device_node from the flat tree
> + * __unflatten_dt_node - Alloc and populate a device_node from the flat tree
>   * @blob: The parent device tree blob
>   * @mem: Memory chunk to use for allocating device nodes and properties
>   * @p: pointer to node in flat tree
>   * @dad: Parent struct device_node
>   * @fpsize: Size of the node path up at the current depth.
>   */
> -static void * unflatten_dt_node(void *blob,
> - void *mem,
> - int *poffset,
> - struct device_node *dad,
> - struct device_node **nodepp,
> - unsigned long fpsize,
> - bool dryrun)
> +static void *__unflatten_dt_node(void *blob,
> +  void *mem,
> +  int *poffset,
> +  struct device_node *dad,
> +  struct device_node **nodepp,
> +  unsigned long fpsize,
> +  bool dryrun)

nitpick: If you resist the temptation to reflow indentation, then the
diffstat is smaller.

>  {
>   const __be32 *p;
>   struct device_node *np;
>   struct property *pp, **prev_pp = NULL;
>   const char *pathp;
>   unsigned int l, allocl;
> - static int depth = 0;

H.. looks like the race condition is already there. Well that's no
good. If you move *depth into the parameters to unflatten_dt_node(), then
you can solve both problems at once without having to create a __
version of the function. That will be a cleaner solution overall.

>   int old_depth;
>   int offset;
>   int has_name = 0;
> @@ -334,13 +335,19 @@ static void * unflatten_dt_node(void *blob,
>   np->type = "";
>   }
>  
> - old_depth = depth;
> - *poffset = fdt_next_node(blob, *poffset, &depth);
> - if (depth < 0)
> - depth = 0;
> - while (*poffset > 0 && depth > old_depth)
> - mem = unflatten_dt_node(blob, mem, poffset, np, NULL,
> - fpsize, dryrun);
> + old_depth = cur_node_depth;
> + *poffset = fdt_next_node(blob, *poffset, &cur_node_depth);
> + while (*poffset > 0) {

What is the reasoning here? Why change to looking for poffset > 0?

> + if (cur_node_depth < old_depth)
> + break;
> +
> + if (cur_node_depth == old_depth)
> + mem = __unflatten_dt_node(blob, mem, poffset,
> +   dad, NULL, fpsize, dryrun);
> + else if (cur_node_depth > old_depth)
> + mem = __unflatten_dt_node(blob, mem, poffset,
> +   np, NULL, fpsize, dryrun);

Ditto here, please describe the purpose of the new logic.

> + }
>  
>   if (*poffset < 0 && *poffset != -FDT_ERR_NOTFOUND)
>   pr_err("unflatten: error %d processing FDT\n", *poffset);
> @@ -366,6 +373,18 @@ static void * unflatten_dt_node(void *blob,
>   return mem;
>  }
>  
> +static void *unflatten_dt_node(void *blob,
> +void *mem,
> +int *poffset,
> +struct device_node *dad,
> +struct device_node **nodepp,
> +bool dryrun)
> +{
> + cur_node_depth =

[HELP/RFC] Moving ppc8xx microcode patch from micropatch.c to firmware

2015-06-30 Thread christophe leroy
I'm trying to move the 3 microcode patches included in 
arch/powerpc/sysdev/micropatch.c into the firmware directory in order to 
use request_firmware() and then be able to add additional micropatch 
that I need to relocate SMC2 on my MPC885.


I have written the below patch in order to test the principle, but the 
firmware never gets included in my kernel, allthough I have set the 
below CONFIG items:


# CONFIG_NO_UCODE_PATCH is not set
CONFIG_USB_SOF_UCODE_PATCH=y
# CONFIG_I2C_SPI_UCODE_PATCH is not set
# CONFIG_I2C_SPI_SMC1_UCODE_PATCH is not set
CONFIG_UCODE_PATCH=y
#
# Generic Driver Options
#
# CONFIG_UEVENT_HELPER is not set
CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=y
# CONFIG_STANDALONE is not set
# CONFIG_PREVENT_FIRMWARE_BUILD is not set
CONFIG_FW_LOADER=y
CONFIG_FIRMWARE_IN_KERNEL=y
CONFIG_EXTRA_FIRMWARE=""
CONFIG_FW_LOADER_USER_HELPER=y
CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y

Can anybody help in finding what's wrong there ?

Christophe

---
 arch/powerpc/sysdev/micropatch.c | 655 
++-

 firmware/Makefile|   3 +
 firmware/freescale/i2c_spi.bin.ihex  | 257 
 firmware/freescale/i2c_spi_smc1.bin.ihex | 257 
 firmware/freescale/usb_sof.bin.ihex  | 513 
 5 files changed, 1065 insertions(+), 620 deletions(-)
 create mode 100644 firmware/freescale/i2c_spi.bin.ihex
 create mode 100644 firmware/freescale/i2c_spi_smc1.bin.ihex
 create mode 100644 firmware/freescale/usb_sof.bin.ihex

diff --git a/arch/powerpc/sysdev/micropatch.c 
b/arch/powerpc/sysdev/micropatch.c

index 6727dc5..c24780c 100644
--- a/arch/powerpc/sysdev/micropatch.c
+++ b/arch/powerpc/sysdev/micropatch.c
@@ -12,6 +12,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -19,652 +21,69 @@
 #include 
 #include 

-/*
- * I2C/SPI relocation patch arrays.
- */
-
-#ifdef CONFIG_I2C_SPI_UCODE_PATCH
-
-static uint patch_2000[] __initdata = {
-0x7FFFEFD9,
-0x3FFD,
-0x7FFB49F7,
-0x7FF9,
-0x5FEFADF7,
-0x5F89ADF7,
-0x5FEFAFF7,
-0x5F89AFF7,
-0x3A9CFBC8,
-0xE7C0EDF0,
-0x77C1E1BB,
-0xF4DC7F1D,
-0xABAD932F,
-0x4E08FDCF,
-0x6E0FAFF8,
-0x7CCF76CF,
-0xFD1FF9CF,
-0xABF88DC6,
-0xAB5679F7,
-0xB0937383,
-0xDFCE79F7,
-0xB091E6BB,
-0xE5BBE74F,
-0xB3FA6F0F,
-0x6FFB76CE,
-0xEE0DF9CF,
-0x2BFBEFEF,
-0xCFEEF9CF,
-0x76CEAD24,
-0x90B2DF9A,
-0x7FDDD0BF,
-0x4BF847FD,
-0x7CCF76CE,
-0xCFEF7E1F,
-0x7F1D7DFD,
-0xF0B6EF71,
-0x7FC177C1,
-0xFBC86079,
-0xE722FBC8,
-0x5FFFDFFF,
-0x5FB2FFFB,
-0xFBC8F3C8,
-0x94A67F01,
-0x7F1D5F39,
-0xAFE85F5E,
-0xFFDFDF96,
-0xCB9FAF7D,
-0x5FC1AFED,
-0x8C1C5FC1,
-0xAFDD5FC3,
-0xDF9A7EFD,
-0xB0B25FB2,
-0xFFFEABAD,
-0x5FB2FFFE,
-0x5FCE600B,
-0xE6BB600B,
-0x5FCEDFC6,
-0x27FBEFDF,
-0x5FC8CFDE,
-0x3A9CE7C0,
-0xEDF0F3C8,
-0x7F0154CD,
-0x7F1D2D3D,
-0x363A7570,
-0x7E0AF1CE,
-0x37EF2E68,
-0x7FEE10EC,
-0xADF8EFDE,
-0xCFEAE52F,
-0x7D0FE12B,
-0xF1CE5F65,
-0x7E0A4DF8,
-0xCFEA5F72,
-0x7D0BEFEE,
-0xCFEA5F74,
-0xE522EFDE,
-0x5F74CFDA,
-0x0B627385,
-0xDF627E0A,
-0x30D8145B,
-0xB3C8,
-0x5FFFDFFF,
-0xA7F85F5E,
-0xBFFE7F7D,
-0x10D31450,
-0x5F36BFFF,
-0xAF785F5E,
-0xBFFDA7F8,
-0x5F36BFFE,
-0x77FD30C0,
-0x4E08FDCF,
-0xE5FF6E0F,
-0xAFF87E1F,
-0x7E0FFD1F,
-0xF1CF5F1B,
-0xABF80D5E,
-0x5F5EFFEF,
-0x79F730A2,
-0xAFDD5F34,
-0x47F85F34,
-0xAFED7FDD,
-0x50B24978,
-0x47FD7F1D,
-0x7DFD70AD,
-0xEF717EC1,
-0x6BA47F01,
-0x2D267EFD,
-0x30DE5F5E,
-0xFFFD5F5E,
-0xFFEF5F5E,
-0xFFDF0CA0,
-0xAFED0A9E,
-0xAFDD0C3A,
-0x5F3AAFBD,
-0x7FBDB082,
-0x5F8247F8
-};
-
-static uint patch_2f00[] __initdata = {
-0x3E303430,
-0x34343737,
-0xABF7BF9B,
-0x994B4FBD,
-0xBD599493,
-0x349FFF37,
-0xFB9B177D,
-0xD9936956,
-0xBBFDD697,
-0xBDD2FD11,
-0x31DB9BB3,
-0x63139637,
-0x93733693,
-0x193137F7,
-0x331737AF,
-0x7BB9B999,
-0xBB197957,
-0x7FDFD3D5,
-0x73B773F7,
-0x37933B99,
-0x1D115316,
-0x99315315,
-0x31694BF4,
-0xFBDBD359,
-0x31497353,
-0x76956D69,
-0x7B9D9693,
-0x13131979,
-0x79376935
-};
-#endif
-
-/*
- * I2C/SPI/SMC1 relocation patch arrays.
- */
-
-#ifdef CONFIG_I2C_SPI_SMC1_UCODE_PATCH
+MODULE_FIRMWARE("freescale/i2c_spi.bin");
+MODULE_FIRMWARE("freescale/i2c_spi_smc1.bin");
+MODULE_FIRMWARE("freescale/usb_sof.bin");

-static uint patch_2000[] __initdata = {
-0x3fff,
-0x3ffd,
-0x3ffb,
-0x3ff9,
-0x5f13eff8,
-0x5eb5eff8,
-0x5f88adf7,
-0x5fefadf7,
-0x3a9cfbc8,
-0x77cae1bb,
-0xf4de7fad,
-0xabae9330,
-0x4e08f

Re: [PATCH v5 40/42] drivers/of: Allow to specify root node in of_fdt_unflatten_tree()

2015-06-30 Thread Benjamin Herrenschmidt
On Tue, 2015-06-30 at 19:06 +0100, Grant Likely wrote:
> It may be time to dump the special allocation of fdt.c entirely and
> treat all nodes the same way, with name and properties all allocated
> with normal kmallocs Investigation is needed to figure out if this
> is feasible.

kmalloc isn't available early enough

Cheers,
Ben.


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH RESEND] Update kernel math-emu code from current glibc soft-fp

2015-06-30 Thread Michael Ellerman
On Tue, 2015-06-30 at 10:48 +, Joseph Myers wrote:
> On Tue, 30 Jun 2015, Michael Ellerman wrote:
> 
> > Is there some way you can imagine of splitting this up into smaller chunks, 
> > so
> > that different arches can merge the pieces separately?
> 
> Well, it could be split as:
> 
> 1. Rename include/math-emu to math-emu-old and update architectures for 
> the renaming (mechanically).
> 
> 2. Add new include/math-emu.
> 
> 3,4,5,6,7. Move each architecture from math-emu-old to math-emu.
> 
> 8. Remove math-emu-old.
> 
> You still have patch 1 affecting all five architectures, but with the 
> per-architecture changes being much simpler.

OK. That's obviously a bit more churn, but I think it's probably the best
approach. Unless someone else has a better idea?

cheers


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH v5 42/42] pci/hotplug: PowerPC PowerNV PCI hotplug driver

2015-06-30 Thread Gavin Shan
On Tue, Jun 30, 2015 at 07:18:04PM +0100, Grant Likely wrote:
>On Thu,  4 Jun 2015 16:42:11 +1000
>, Gavin Shan 
> wrote:
>> The patch intends to add standalone driver to support PCI hotplug
>> for PowerPC PowerNV platform, which runs on top of skiboot firmware.
>> The firmware identified hotpluggable slots and marked their device
>> tree node with proper "ibm,slot-pluggable" and "ibm,reset-by-firmware".
>> The driver simply scans device-tree to create/register PCI hotplug slot
>> accordingly.
>> 
>> If the skiboot firmware doesn't support slot status retrieval, the PCI
>> slot device node shouldn't have property "ibm,reset-by-firmware". In
>> that case, none of valid PCI slots will be detected from device tree.
>> The skiboot firmware doesn't export the capability to access attention
>> LEDs yet and it's something for TBD.
>> 
>> Signed-off-by: Gavin Shan 
>> ---
>> v5:
>>   * Use OF OVERLAY to update the device-tree
>>   * Removed unnecessary header files
>>   * More meaningful return value from powernv_php_register_one()
>>   * Use pnv_pci_hotplug_notifier_{register, unregister}()
>>   * Decimal values for slot's states
>>   * Removed struct powernv_php_slot::release()
>>   * Merged two bool arguments to one for powernv_php_slot_enable()
>>   * Rename release_device_nodes_info() to remove_device_nodes_info()
>>   * Don't check on "!len" in slot_power_on_handler()
>>   * Handle return value in get_adapter_status() as suggested by aik
>>   * Drop invalid attention status in set_attention_status()
>>   * Renaming functions
>>   * Fixed coding style and added entry in MAINTAINERS reported by
>> checkpatch.pl
>> ---
>>  MAINTAINERS|   6 +
>>  drivers/pci/hotplug/Kconfig|  12 +
>>  drivers/pci/hotplug/Makefile   |   4 +
>>  drivers/pci/hotplug/powernv_php.c  | 140 +++
>>  drivers/pci/hotplug/powernv_php.h  |  90 
>>  drivers/pci/hotplug/powernv_php_slot.c | 732 
>> +
>>  6 files changed, 984 insertions(+)
>>  create mode 100644 drivers/pci/hotplug/powernv_php.c
>>  create mode 100644 drivers/pci/hotplug/powernv_php.h
>>  create mode 100644 drivers/pci/hotplug/powernv_php_slot.c
>> 
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index e308718..f5e1dce 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -7481,6 +7481,12 @@ L:linux-...@vger.kernel.org
>>  S:  Supported
>>  F:  Documentation/PCI/pci-error-recovery.txt
>>  
>> +PCI HOTPLUG DRIVER FOR POWERNV PLATFORM
>> +M:  Gavin Shan 
>> +L:  linux-...@vger.kernel.org
>> +S:  Supported
>> +F:  drivers/pci/hotplug/powernv_php*
>> +
>>  PCI SUBSYSTEM
>>  M:  Bjorn Helgaas 
>>  L:  linux-...@vger.kernel.org
>> diff --git a/drivers/pci/hotplug/Kconfig b/drivers/pci/hotplug/Kconfig
>> index df8caec..ef55dae 100644
>> --- a/drivers/pci/hotplug/Kconfig
>> +++ b/drivers/pci/hotplug/Kconfig
>> @@ -113,6 +113,18 @@ config HOTPLUG_PCI_SHPC
>>  
>>When in doubt, say N.
>>  
>> +config HOTPLUG_PCI_POWERNV
>> +tristate "PowerPC PowerNV PCI Hotplug driver"
>> +depends on PPC_POWERNV && EEH
>> +help
>> +  Say Y here if you run PowerPC PowerNV platform that supports
>> +  PCI Hotplug
>> +
>> +  To compile this driver as a module, choose M here: the
>> +  module will be called powernv-php.
>> +
>> +  When in doubt, say N.
>> +
>>  config HOTPLUG_PCI_RPA
>>  tristate "RPA PCI Hotplug driver"
>>  depends on PPC_PSERIES && EEH
>> diff --git a/drivers/pci/hotplug/Makefile b/drivers/pci/hotplug/Makefile
>> index 4a9aa08..a69665e 100644
>> --- a/drivers/pci/hotplug/Makefile
>> +++ b/drivers/pci/hotplug/Makefile
>> @@ -14,6 +14,7 @@ obj-$(CONFIG_HOTPLUG_PCI_PCIE) += pciehp.o
>>  obj-$(CONFIG_HOTPLUG_PCI_CPCI_ZT5550)   += cpcihp_zt5550.o
>>  obj-$(CONFIG_HOTPLUG_PCI_CPCI_GENERIC)  += cpcihp_generic.o
>>  obj-$(CONFIG_HOTPLUG_PCI_SHPC)  += shpchp.o
>> +obj-$(CONFIG_HOTPLUG_PCI_POWERNV)   += powernv-php.o
>>  obj-$(CONFIG_HOTPLUG_PCI_RPA)   += rpaphp.o
>>  obj-$(CONFIG_HOTPLUG_PCI_RPA_DLPAR) += rpadlpar_io.o
>>  obj-$(CONFIG_HOTPLUG_PCI_SGI)   += sgi_hotplug.o
>> @@ -50,6 +51,9 @@ ibmphp-objs:=  ibmphp_core.o   \
>>  acpiphp-objs:=  acpiphp_core.o  \
>>  acpiphp_glue.o
>>  
>> +powernv-php-objs:=  powernv_php.o   \
>> +powernv_php_slot.o
>> +
>>  rpaphp-objs :=  rpaphp_core.o   \
>>  rpaphp_pci.o\
>>  rpaphp_slot.o
>> diff --git a/drivers/pci/hotplug/powernv_php.c 
>> b/drivers/pci/hotplug/powernv_php.c
>> new file mode 100644
>> index 000..4cbff7a
>> --- /dev/null
>> +++ b/drivers/pci/hotplug/powernv_php.c
>> @@ -0,0 +1,140 @@
>> +/*
>> + * PCI Hotplug Driver for PowerPC PowerNV platform.
>> + *
>> + * Copyright Gavin Shan, IBM Corporation 2015.
>> + *
>> + * This program is free software; you can redis

[PATCH] powerpc/powernv: Fix race in updating core_idle_state

2015-06-30 Thread Shreyas B. Prabhu
core_idle_state is maintained for each core. It uses 0-7 bits to track
whether a thread in the core has entered fastsleep or winkle. 8th bit is
used as a lock bit.
The lock bit is set in these 2 scenarios-
 - The thread is first in subcore to wakeup from sleep/winkle.
 - If its the last thread in the core about to enter sleep/winkle

While the lock bit is set, if any other thread in the core wakes up, it
loops until the lock bit is cleared before proceeding in the wakeup
path. This helps prevent race conditions w.r.t fastsleep workaround and
prevents threads from switching to process context before core/subcore
resources are restored.

But, in the path to sleep/winkle entry, we currently don't check for
lock-bit. This exposes us to following race when running with subcore
on-

First thread in the subcoreaAnother thread in the same
waking up   core entering sleep/winkle

lwarx   r15,0,r14
ori r15,r15,PNV_CORE_IDLE_LOCK_BIT
stwcx.  r15,0,r14
[Code to restore subcore state]

lwarx   r15,0,r14
[clear thread bit]
stwcx.  r15,0,r14

andi.   r15,r15,PNV_CORE_IDLE_THREAD_BITS
stw r15,0(r14)

Here, after the thread entering sleep clears its thread bit in
core_idle_state, the value is overwritten by the thread waking up.
This patch fixes the above race by looping on the lock bit even while
entering the idle states.

Signed-off-by: Shreyas B. Prabhu 
---
 arch/powerpc/kernel/idle_power7.S | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/powerpc/kernel/idle_power7.S 
b/arch/powerpc/kernel/idle_power7.S
index ccde8f0..48c7d4f 100644
--- a/arch/powerpc/kernel/idle_power7.S
+++ b/arch/powerpc/kernel/idle_power7.S
@@ -144,12 +144,26 @@ power7_enter_nap_mode:
bge cr3,2f
IDLE_STATE_ENTER_SEQ(PPC_NAP)
/* No return */
+
+core_idle_lock_held_entry:
+   HMT_LOW
+core_idle_lock_loop_entry:
+   lwz r15,0(r14)
+   andi.   r9,r15,PNV_CORE_IDLE_LOCK_BIT
+   bne core_idle_lock_loop_entry
+   HMT_MEDIUM
+   b   lwarx_loop1
+
 2:
/* Sleep or winkle */
lbz r7,PACA_THREAD_MASK(r13)
ld  r14,PACA_CORE_IDLE_STATE_PTR(r13)
 lwarx_loop1:
lwarx   r15,0,r14
+
+   andi.   r9,r15,PNV_CORE_IDLE_LOCK_BIT
+   bne core_idle_lock_held_entry
+
andcr15,r15,r7  /* Clear thread bit */
 
andi.   r15,r15,PNV_CORE_IDLE_THREAD_BITS
-- 
1.9.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev