diff mbox

[v6,09/22] arm/p2m: Add helper functions to map memory regions

Message ID 1458207668-12012-10-git-send-email-zhaoshenglong@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Shannon Zhao March 17, 2016, 9:40 a.m. UTC
From: Parth Dixit <parth.dixit@linaro.org>

Create a helper function for mapping with cached attributes and
read-write range.

Signed-off-by: Parth Dixit <parth.dixit@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 xen/arch/arm/p2m.c        | 26 ++++++++++++++++++++++++++
 xen/include/asm-arm/p2m.h | 10 ++++++++++
 2 files changed, 36 insertions(+)

Comments

Julien Grall March 21, 2016, 3:52 p.m. UTC | #1
Title: to map/unmap

On 17/03/2016 09:40, Shannon Zhao wrote:
> diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
> index 433952a..17be6ad 100644
> --- a/xen/include/asm-arm/p2m.h
> +++ b/xen/include/asm-arm/p2m.h
> @@ -144,6 +144,16 @@ int p2m_cache_flush(struct domain *d, xen_pfn_t start_mfn, xen_pfn_t end_mfn);
>   /* Setup p2m RAM mapping for domain d from start-end. */
>   int p2m_populate_ram(struct domain *d, paddr_t start, paddr_t end);
>
> +int map_regions_rw(struct domain *d,
> +                    unsigned long start_gfn,
> +                    unsigned long nr_mfns,
> +                    unsigned long mfn);

 From the commit message, this function will map the region read-write 
and cacheable.

But it's not clear from the name. Please either rename the function or 
document it in the code.

> +
> +int unmap_regions_rw(struct domain *d,
> +                    unsigned long start_gfn,
> +                    unsigned long nr_mfns,
> +                    unsigned long mfn);
> +
>   int guest_physmap_add_entry(struct domain *d,
>                               unsigned long gfn,
>                               unsigned long mfn,
>

Regards,
Shannon Zhao March 22, 2016, 1:05 p.m. UTC | #2
On 2016?03?21? 23:52, Julien Grall wrote:
> Title: to map/unmap
> 
> On 17/03/2016 09:40, Shannon Zhao wrote:
>> diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
>> index 433952a..17be6ad 100644
>> --- a/xen/include/asm-arm/p2m.h
>> +++ b/xen/include/asm-arm/p2m.h
>> @@ -144,6 +144,16 @@ int p2m_cache_flush(struct domain *d, xen_pfn_t
>> start_mfn, xen_pfn_t end_mfn);
>>   /* Setup p2m RAM mapping for domain d from start-end. */
>>   int p2m_populate_ram(struct domain *d, paddr_t start, paddr_t end);
>>
>> +int map_regions_rw(struct domain *d,
>> +                    unsigned long start_gfn,
>> +                    unsigned long nr_mfns,
>> +                    unsigned long mfn);
> 
> From the commit message, this function will map the region read-write
> and cacheable.
> 
> But it's not clear from the name. Please either rename the function or
> document it in the code.
So map_regions_rw_cache?

Thanks,
Julien Grall March 22, 2016, 3:59 p.m. UTC | #3
Hi Shannon,

On 22/03/16 13:05, Shannon Zhao wrote:
> On 2016?03?21? 23:52, Julien Grall wrote:
>> Title: to map/unmap
>>
>> On 17/03/2016 09:40, Shannon Zhao wrote:
>>> diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
>>> index 433952a..17be6ad 100644
>>> --- a/xen/include/asm-arm/p2m.h
>>> +++ b/xen/include/asm-arm/p2m.h
>>> @@ -144,6 +144,16 @@ int p2m_cache_flush(struct domain *d, xen_pfn_t
>>> start_mfn, xen_pfn_t end_mfn);
>>>    /* Setup p2m RAM mapping for domain d from start-end. */
>>>    int p2m_populate_ram(struct domain *d, paddr_t start, paddr_t end);
>>>
>>> +int map_regions_rw(struct domain *d,
>>> +                    unsigned long start_gfn,
>>> +                    unsigned long nr_mfns,
>>> +                    unsigned long mfn);
>>
>>  From the commit message, this function will map the region read-write
>> and cacheable.
>>
>> But it's not clear from the name. Please either rename the function or
>> document it in the code.
> So map_regions_rw_cache?

It sounds good.

Regards,
diff mbox

Patch

diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index a2a9c4b..d206616 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -1218,6 +1218,32 @@  int p2m_populate_ram(struct domain *d,
                              d->arch.p2m.default_access);
 }
 
+int map_regions_rw(struct domain *d,
+                     unsigned long start_gfn,
+                     unsigned long nr,
+                     unsigned long mfn)
+{
+    return apply_p2m_changes(d, INSERT,
+                             pfn_to_paddr(start_gfn),
+                             pfn_to_paddr(start_gfn + nr),
+                             pfn_to_paddr(mfn),
+                             MATTR_MEM, 0, p2m_mmio_direct,
+                             p2m_access_rw);
+}
+
+int unmap_regions_rw(struct domain *d,
+                       unsigned long start_gfn,
+                       unsigned long nr,
+                       unsigned long mfn)
+{
+    return apply_p2m_changes(d, REMOVE,
+                             pfn_to_paddr(start_gfn),
+                             pfn_to_paddr(start_gfn + nr),
+                             pfn_to_paddr(mfn),
+                             MATTR_MEM, 0, p2m_invalid,
+                             p2m_access_rw);
+}
+
 int map_mmio_regions(struct domain *d,
                      unsigned long start_gfn,
                      unsigned long nr,
diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
index 433952a..17be6ad 100644
--- a/xen/include/asm-arm/p2m.h
+++ b/xen/include/asm-arm/p2m.h
@@ -144,6 +144,16 @@  int p2m_cache_flush(struct domain *d, xen_pfn_t start_mfn, xen_pfn_t end_mfn);
 /* Setup p2m RAM mapping for domain d from start-end. */
 int p2m_populate_ram(struct domain *d, paddr_t start, paddr_t end);
 
+int map_regions_rw(struct domain *d,
+                    unsigned long start_gfn,
+                    unsigned long nr_mfns,
+                    unsigned long mfn);
+
+int unmap_regions_rw(struct domain *d,
+                    unsigned long start_gfn,
+                    unsigned long nr_mfns,
+                    unsigned long mfn);
+
 int guest_physmap_add_entry(struct domain *d,
                             unsigned long gfn,
                             unsigned long mfn,