diff mbox

pseries: Implements h_read hcall

Message ID 1360925975-12691-1-git-send-email-erlon.cruz@fit-tecnologia.org.br
State New
Headers show

Commit Message

Erlon Cruz Feb. 15, 2013, 10:59 a.m. UTC
From: Erlon Cruz <erlon.cruz@br.flextronics.com>

This h_call is useful for DLPAR in future amongst other things. Given an index
it fetches the corresponding PTE stored in the htab.

Signed-off-by: Erlon Cruz <erlon.cruz@br.flextronics.com>
---
 hw/spapr_hcall.c |   34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

Comments

Alexander Graf Feb. 15, 2013, 11:55 a.m. UTC | #1
On 15.02.2013, at 11:59, Erlon Cruz wrote:

> From: Erlon Cruz <erlon.cruz@br.flextronics.com>
> 
> This h_call is useful for DLPAR in future amongst other things. Given an index
> it fetches the corresponding PTE stored in the htab.
> 
> Signed-off-by: Erlon Cruz <erlon.cruz@br.flextronics.com>

Looks good to me, but I'd like an ack from David.


Alex

> ---
> hw/spapr_hcall.c |   34 ++++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
> 
> diff --git a/hw/spapr_hcall.c b/hw/spapr_hcall.c
> index 2889742..1065277 100644
> --- a/hw/spapr_hcall.c
> +++ b/hw/spapr_hcall.c
> @@ -323,6 +323,39 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>     return H_SUCCESS;
> }
> 
> +static target_ulong h_read(PowerPCCPU *cpu, sPAPREnvironment *spapr,
> +                            target_ulong opcode, target_ulong *args)
> +{
> +    CPUPPCState *env = &cpu->env;
> +    target_ulong flags = args[0];
> +    target_ulong pte_index = args[1];
> +    target_ulong v[4], r[4];
> +    uint8_t *hpte;
> +    int i, ridx, n_entries = 1;
> +
> +    if ((pte_index * HASH_PTE_SIZE_64) & ~env->htab_mask) {
> +        return H_PARAMETER;
> +    }
> +
> +    if (flags & H_READ_4) {
> +        /* Clear the two low order bits */
> +        pte_index &= ~(3ULL);
> +        n_entries = 4;
> +    }
> +
> +    hpte = env->external_htab + (pte_index * HASH_PTE_SIZE_64);
> +
> +    for (i = 0, ridx = 0; i < n_entries; i++) {
> +        v[i] = ldq_p(hpte);
> +        r[i] = ldq_p(hpte + (HASH_PTE_SIZE_64/2));
> +        args[ridx++] = v[i];
> +        args[ridx++] = r[i];
> +        hpte += HASH_PTE_SIZE_64;
> +    }
> +
> +    return H_SUCCESS;
> +}
> +
> static target_ulong h_set_dabr(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>                                target_ulong opcode, target_ulong *args)
> {
> @@ -714,6 +747,7 @@ static void hypercall_register_types(void)
>     spapr_register_hypercall(H_ENTER, h_enter);
>     spapr_register_hypercall(H_REMOVE, h_remove);
>     spapr_register_hypercall(H_PROTECT, h_protect);
> +    spapr_register_hypercall(H_READ, h_read);
> 
>     /* hcall-bulk */
>     spapr_register_hypercall(H_BULK_REMOVE, h_bulk_remove);
> -- 
> 1.7.9.5
>
David Gibson Feb. 16, 2013, 11:46 p.m. UTC | #2
On Fri, Feb 15, 2013 at 08:59:35AM -0200, Erlon Cruz wrote:
> From: Erlon Cruz <erlon.cruz@br.flextronics.com>
> 
> This h_call is useful for DLPAR in future amongst other things. Given an index
> it fetches the corresponding PTE stored in the htab.
> 
> Signed-off-by: Erlon Cruz <erlon.cruz@br.flextronics.com>
> ---
>  hw/spapr_hcall.c |   34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/hw/spapr_hcall.c b/hw/spapr_hcall.c
> index 2889742..1065277 100644
> --- a/hw/spapr_hcall.c
> +++ b/hw/spapr_hcall.c
> @@ -323,6 +323,39 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>      return H_SUCCESS;
>  }
>  
> +static target_ulong h_read(PowerPCCPU *cpu, sPAPREnvironment *spapr,
> +                            target_ulong opcode, target_ulong *args)
> +{
> +    CPUPPCState *env = &cpu->env;
> +    target_ulong flags = args[0];
> +    target_ulong pte_index = args[1];
> +    target_ulong v[4], r[4];
> +    uint8_t *hpte;
> +    int i, ridx, n_entries = 1;
> +
> +    if ((pte_index * HASH_PTE_SIZE_64) & ~env->htab_mask) {
> +        return H_PARAMETER;
> +    }
> +
> +    if (flags & H_READ_4) {
> +        /* Clear the two low order bits */
> +        pte_index &= ~(3ULL);
> +        n_entries = 4;
> +    }
> +
> +    hpte = env->external_htab + (pte_index * HASH_PTE_SIZE_64);
> +
> +    for (i = 0, ridx = 0; i < n_entries; i++) {
> +        v[i] = ldq_p(hpte);
> +        r[i] = ldq_p(hpte + (HASH_PTE_SIZE_64/2));

There's no need for the v and r arrays.  You can just need temporaries
for one entry as you store them one-by-one into args.

Otherwise looks good.
Erlon Cruz Feb. 17, 2013, 2:42 a.m. UTC | #3
I left them only to make it easy to read and keep the same sintax used
in the other functions.

On Sat, Feb 16, 2013 at 9:46 PM, David Gibson <dwg@au1.ibm.com> wrote:
> On Fri, Feb 15, 2013 at 08:59:35AM -0200, Erlon Cruz wrote:
>> From: Erlon Cruz <erlon.cruz@br.flextronics.com>
>>
>> This h_call is useful for DLPAR in future amongst other things. Given an index
>> it fetches the corresponding PTE stored in the htab.
>>
>> Signed-off-by: Erlon Cruz <erlon.cruz@br.flextronics.com>
>> ---
>>  hw/spapr_hcall.c |   34 ++++++++++++++++++++++++++++++++++
>>  1 file changed, 34 insertions(+)
>>
>> diff --git a/hw/spapr_hcall.c b/hw/spapr_hcall.c
>> index 2889742..1065277 100644
>> --- a/hw/spapr_hcall.c
>> +++ b/hw/spapr_hcall.c
>> @@ -323,6 +323,39 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>>      return H_SUCCESS;
>>  }
>>
>> +static target_ulong h_read(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>> +                            target_ulong opcode, target_ulong *args)
>> +{
>> +    CPUPPCState *env = &cpu->env;
>> +    target_ulong flags = args[0];
>> +    target_ulong pte_index = args[1];
>> +    target_ulong v[4], r[4];
>> +    uint8_t *hpte;
>> +    int i, ridx, n_entries = 1;
>> +
>> +    if ((pte_index * HASH_PTE_SIZE_64) & ~env->htab_mask) {
>> +        return H_PARAMETER;
>> +    }
>> +
>> +    if (flags & H_READ_4) {
>> +        /* Clear the two low order bits */
>> +        pte_index &= ~(3ULL);
>> +        n_entries = 4;
>> +    }
>> +
>> +    hpte = env->external_htab + (pte_index * HASH_PTE_SIZE_64);
>> +
>> +    for (i = 0, ridx = 0; i < n_entries; i++) {
>> +        v[i] = ldq_p(hpte);
>> +        r[i] = ldq_p(hpte + (HASH_PTE_SIZE_64/2));
>
> There's no need for the v and r arrays.  You can just need temporaries
> for one entry as you store them one-by-one into args.
>
> Otherwise looks good.
>
> --
> David Gibson                    | I'll have my music baroque, and my code
> david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
>                                 | _way_ _around_!
> http://www.ozlabs.org/~dgibson
David Gibson Feb. 17, 2013, 4:53 a.m. UTC | #4
On Sat, Feb 16, 2013 at 11:42:35PM -0300, Erlon Cruz wrote:
> I left them only to make it easy to read and keep the same sintax used
> in the other functions.

I don't see how having the arrays helps either of those goals.
Andreas Färber Feb. 17, 2013, 11:06 a.m. UTC | #5
Am 15.02.2013 11:59, schrieb Erlon Cruz:
> From: Erlon Cruz <erlon.cruz@br.flextronics.com>
> 
> This h_call is useful for DLPAR in future amongst other things. Given an index
> it fetches the corresponding PTE stored in the htab.
> 
> Signed-off-by: Erlon Cruz <erlon.cruz@br.flextronics.com>
> ---
>  hw/spapr_hcall.c |   34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/hw/spapr_hcall.c b/hw/spapr_hcall.c
> index 2889742..1065277 100644
> --- a/hw/spapr_hcall.c
> +++ b/hw/spapr_hcall.c
> @@ -323,6 +323,39 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>      return H_SUCCESS;
>  }
>  
> +static target_ulong h_read(PowerPCCPU *cpu, sPAPREnvironment *spapr,
> +                            target_ulong opcode, target_ulong *args)

Indentation is one-off.

Andreas

> +{
> +    CPUPPCState *env = &cpu->env;
> +    target_ulong flags = args[0];
> +    target_ulong pte_index = args[1];
> +    target_ulong v[4], r[4];
> +    uint8_t *hpte;
> +    int i, ridx, n_entries = 1;
> +
> +    if ((pte_index * HASH_PTE_SIZE_64) & ~env->htab_mask) {
> +        return H_PARAMETER;
> +    }
> +
> +    if (flags & H_READ_4) {
> +        /* Clear the two low order bits */
> +        pte_index &= ~(3ULL);
> +        n_entries = 4;
> +    }
> +
> +    hpte = env->external_htab + (pte_index * HASH_PTE_SIZE_64);
> +
> +    for (i = 0, ridx = 0; i < n_entries; i++) {
> +        v[i] = ldq_p(hpte);
> +        r[i] = ldq_p(hpte + (HASH_PTE_SIZE_64/2));
> +        args[ridx++] = v[i];
> +        args[ridx++] = r[i];
> +        hpte += HASH_PTE_SIZE_64;
> +    }
> +
> +    return H_SUCCESS;
> +}
> +
>  static target_ulong h_set_dabr(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>                                 target_ulong opcode, target_ulong *args)
>  {
> @@ -714,6 +747,7 @@ static void hypercall_register_types(void)
>      spapr_register_hypercall(H_ENTER, h_enter);
>      spapr_register_hypercall(H_REMOVE, h_remove);
>      spapr_register_hypercall(H_PROTECT, h_protect);
> +    spapr_register_hypercall(H_READ, h_read);
>  
>      /* hcall-bulk */
>      spapr_register_hypercall(H_BULK_REMOVE, h_bulk_remove);
diff mbox

Patch

diff --git a/hw/spapr_hcall.c b/hw/spapr_hcall.c
index 2889742..1065277 100644
--- a/hw/spapr_hcall.c
+++ b/hw/spapr_hcall.c
@@ -323,6 +323,39 @@  static target_ulong h_protect(PowerPCCPU *cpu, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
+static target_ulong h_read(PowerPCCPU *cpu, sPAPREnvironment *spapr,
+                            target_ulong opcode, target_ulong *args)
+{
+    CPUPPCState *env = &cpu->env;
+    target_ulong flags = args[0];
+    target_ulong pte_index = args[1];
+    target_ulong v[4], r[4];
+    uint8_t *hpte;
+    int i, ridx, n_entries = 1;
+
+    if ((pte_index * HASH_PTE_SIZE_64) & ~env->htab_mask) {
+        return H_PARAMETER;
+    }
+
+    if (flags & H_READ_4) {
+        /* Clear the two low order bits */
+        pte_index &= ~(3ULL);
+        n_entries = 4;
+    }
+
+    hpte = env->external_htab + (pte_index * HASH_PTE_SIZE_64);
+
+    for (i = 0, ridx = 0; i < n_entries; i++) {
+        v[i] = ldq_p(hpte);
+        r[i] = ldq_p(hpte + (HASH_PTE_SIZE_64/2));
+        args[ridx++] = v[i];
+        args[ridx++] = r[i];
+        hpte += HASH_PTE_SIZE_64;
+    }
+
+    return H_SUCCESS;
+}
+
 static target_ulong h_set_dabr(PowerPCCPU *cpu, sPAPREnvironment *spapr,
                                target_ulong opcode, target_ulong *args)
 {
@@ -714,6 +747,7 @@  static void hypercall_register_types(void)
     spapr_register_hypercall(H_ENTER, h_enter);
     spapr_register_hypercall(H_REMOVE, h_remove);
     spapr_register_hypercall(H_PROTECT, h_protect);
+    spapr_register_hypercall(H_READ, h_read);
 
     /* hcall-bulk */
     spapr_register_hypercall(H_BULK_REMOVE, h_bulk_remove);