diff mbox

[API-NEXT,PATCHv2,2/2] linux-gen: _ishmphy: adding debug function for pysical address mapping

Message ID 1478875829-35000-3-git-send-email-christophe.milard@linaro.org
State New
Headers show

Commit Message

Christophe Milard Nov. 11, 2016, 2:50 p.m. UTC
_odp_ishmphy_memmap_print() prints the virtual to physical address
mapping of some memory region (defined by virtuall address + length).

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

---
 platform/linux-generic/_ishmphy.c                  | 58 ++++++++++++++++++++++
 platform/linux-generic/include/_ishmphy_internal.h |  5 ++
 2 files changed, 63 insertions(+)

-- 
2.7.4

Comments

Yi He Nov. 14, 2016, 5:02 a.m. UTC | #1
One comment inline:

On 11 November 2016 at 22:50, Christophe Milard <
christophe.milard@linaro.org> wrote:

> _odp_ishmphy_memmap_print() prints the virtual to physical address

> mapping of some memory region (defined by virtuall address + length).

>

> Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

> ---

>  platform/linux-generic/_ishmphy.c                  | 58

> ++++++++++++++++++++++

>  platform/linux-generic/include/_ishmphy_internal.h |  5 ++

>  2 files changed, 63 insertions(+)

>

> diff --git a/platform/linux-generic/_ishmphy.c b/platform/linux-generic/_

> ishmphy.c

> index 8c0f46e..21f6bd1 100644

> --- a/platform/linux-generic/_ishmphy.c

> +++ b/platform/linux-generic/_ishmphy.c

> @@ -265,3 +265,61 @@ int _odp_ishmphy_can_virt_to_phys(void)

>

>         return 1;

>  }

> +

> +/*

> + * dump the physical mapping from virtual address addr, length len.

> + */

> +void _odp_ishmphy_memmap_print(void *curr_addr, uint64_t len)

> +{

> +       int page_sz;

> +       phys_addr_t curr_phy;

> +       phys_addr_t start_phy;

> +       void *start_address = 0;

> +       uint32_t curr_len = 0;

> +       uint32_t pfn_count = 0;

> +

> +       /* get normal page sizes: */

> +       page_sz = odp_sys_page_size();

> +

> +       curr_phy = _odp_ishmphy_virt_to_phys(curr_addr);

> +       if (curr_phy == PHYS_ADDR_INVALID) {

> +               ODP_DBG("Phy Dump failed (permission?).\n");

> +               return;

> +       }

> +

> +       ODP_DBG("Phy Dump:\n");

> +       start_address = curr_addr;

> +       start_phy = curr_phy;

> +

> +       curr_len += page_sz;

> +       curr_addr = (void *)((char *)curr_addr + page_sz);

> +       pfn_count++;

> +       while (curr_len < len) {

> +               if (_odp_ishmphy_virt_to_phys(curr_addr) ==

> +                   curr_phy + page_sz) {

> +                       curr_len += page_sz;

> +                       curr_addr = (void *)((char *)curr_addr + page_sz);

> +                       curr_phy += page_sz;

> +                       pfn_count++;

> +                       continue;

> +               }

> +

> +               ODP_DBG("Virtual: %08" PRIx64 " <-->  Phy: %08" PRIx64

> +                       "   %" PRIu32 " PFNs, %" PRIu32 " bytes\n",

> +                       (uint64_t)start_address, start_phy,

> +                       pfn_count, pfn_count * page_sz);

> +               curr_phy =  _odp_ishmphy_virt_to_phys(curr_addr);

>


Should here check the success or failure of the call? And break in case
failed.


> +               start_address = curr_addr;

> +               start_phy = curr_phy;

> +               pfn_count = 0;

> +               curr_len += page_sz;

> +               curr_addr = (void *)((char *)curr_addr + page_sz);

> +               pfn_count++;

> +       }

> +

> +       if (pfn_count)

> +               ODP_DBG("Virtual: %08" PRIx64 " <-->  Phy: %08" PRIx64

> +                       "   %" PRIu32 " PFNs, %" PRIu32 " bytes\n",

> +                       (uint64_t)start_address, start_phy,

> +                       pfn_count, pfn_count * page_sz);

> +}

> diff --git a/platform/linux-generic/include/_ishmphy_internal.h

> b/platform/linux-generic/include/_ishmphy_internal.h

> index 2022590..c8752c0 100644

> --- a/platform/linux-generic/include/_ishmphy_internal.h

> +++ b/platform/linux-generic/include/_ishmphy_internal.h

> @@ -32,6 +32,11 @@ int _odp_ishmphy_can_virt_to_phys(void);

>   */

>  phys_addr_t _odp_ishmphy_virt_to_phys(const void *addr);

>

> +/*

> + * dump the physical mapping from virtual address addr, length len.

> + */

> +void _odp_ishmphy_memmap_print(void *addr, uint64_t len);

> +

>  #ifdef __cplusplus

>  }

>  #endif

> --

> 2.7.4

>

>
Christophe Milard Nov. 14, 2016, 7:33 a.m. UTC | #2
On 14 November 2016 at 06:02, Yi He <yi.he@linaro.org> wrote:
> One comment inline:

>

> On 11 November 2016 at 22:50, Christophe Milard

> <christophe.milard@linaro.org> wrote:

>>

>> _odp_ishmphy_memmap_print() prints the virtual to physical address

>> mapping of some memory region (defined by virtuall address + length).

>>

>> Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

>> ---

>>  platform/linux-generic/_ishmphy.c                  | 58

>> ++++++++++++++++++++++

>>  platform/linux-generic/include/_ishmphy_internal.h |  5 ++

>>  2 files changed, 63 insertions(+)

>>

>> diff --git a/platform/linux-generic/_ishmphy.c

>> b/platform/linux-generic/_ishmphy.c

>> index 8c0f46e..21f6bd1 100644

>> --- a/platform/linux-generic/_ishmphy.c

>> +++ b/platform/linux-generic/_ishmphy.c

>> @@ -265,3 +265,61 @@ int _odp_ishmphy_can_virt_to_phys(void)

>>

>>         return 1;

>>  }

>> +

>> +/*

>> + * dump the physical mapping from virtual address addr, length len.

>> + */

>> +void _odp_ishmphy_memmap_print(void *curr_addr, uint64_t len)

>> +{

>> +       int page_sz;

>> +       phys_addr_t curr_phy;

>> +       phys_addr_t start_phy;

>> +       void *start_address = 0;

>> +       uint32_t curr_len = 0;

>> +       uint32_t pfn_count = 0;

>> +

>> +       /* get normal page sizes: */

>> +       page_sz = odp_sys_page_size();

>> +

>> +       curr_phy = _odp_ishmphy_virt_to_phys(curr_addr);

>> +       if (curr_phy == PHYS_ADDR_INVALID) {

>> +               ODP_DBG("Phy Dump failed (permission?).\n");

>> +               return;

>> +       }

>> +

>> +       ODP_DBG("Phy Dump:\n");

>> +       start_address = curr_addr;

>> +       start_phy = curr_phy;

>> +

>> +       curr_len += page_sz;

>> +       curr_addr = (void *)((char *)curr_addr + page_sz);

>> +       pfn_count++;

>> +       while (curr_len < len) {

>> +               if (_odp_ishmphy_virt_to_phys(curr_addr) ==

>> +                   curr_phy + page_sz) {

>> +                       curr_len += page_sz;

>> +                       curr_addr = (void *)((char *)curr_addr + page_sz);

>> +                       curr_phy += page_sz;

>> +                       pfn_count++;

>> +                       continue;

>> +               }

>> +

>> +               ODP_DBG("Virtual: %08" PRIx64 " <-->  Phy: %08" PRIx64

>> +                       "   %" PRIu32 " PFNs, %" PRIu32 " bytes\n",

>> +                       (uint64_t)start_address, start_phy,

>> +                       pfn_count, pfn_count * page_sz);

>> +               curr_phy =  _odp_ishmphy_virt_to_phys(curr_addr);

>

>

> Should here check the success or failure of the call? And break in case

> failed.


hmmm. not sure. The fact that the function is available, that is that
you have the right permission, is tested at start of function.
Now that you have the right permissions, it is likely you want to see
what the function returns (even in case of error), as this is a debug
function anyway.
If the function said just "error", I guess the next debug step would
be to see what lead to the error... i.e. see the real value.
But both behaviour make sense. so If you really prefer a test, I can
put one :-)

Christophe.

>

>>

>> +               start_address = curr_addr;

>> +               start_phy = curr_phy;

>> +               pfn_count = 0;

>> +               curr_len += page_sz;

>> +               curr_addr = (void *)((char *)curr_addr + page_sz);

>> +               pfn_count++;

>> +       }

>> +

>> +       if (pfn_count)

>> +               ODP_DBG("Virtual: %08" PRIx64 " <-->  Phy: %08" PRIx64

>> +                       "   %" PRIu32 " PFNs, %" PRIu32 " bytes\n",

>> +                       (uint64_t)start_address, start_phy,

>> +                       pfn_count, pfn_count * page_sz);

>> +}

>> diff --git a/platform/linux-generic/include/_ishmphy_internal.h

>> b/platform/linux-generic/include/_ishmphy_internal.h

>> index 2022590..c8752c0 100644

>> --- a/platform/linux-generic/include/_ishmphy_internal.h

>> +++ b/platform/linux-generic/include/_ishmphy_internal.h

>> @@ -32,6 +32,11 @@ int _odp_ishmphy_can_virt_to_phys(void);

>>   */

>>  phys_addr_t _odp_ishmphy_virt_to_phys(const void *addr);

>>

>> +/*

>> + * dump the physical mapping from virtual address addr, length len.

>> + */

>> +void _odp_ishmphy_memmap_print(void *addr, uint64_t len);

>> +

>>  #ifdef __cplusplus

>>  }

>>  #endif

>> --

>> 2.7.4

>>

>
diff mbox

Patch

diff --git a/platform/linux-generic/_ishmphy.c b/platform/linux-generic/_ishmphy.c
index 8c0f46e..21f6bd1 100644
--- a/platform/linux-generic/_ishmphy.c
+++ b/platform/linux-generic/_ishmphy.c
@@ -265,3 +265,61 @@  int _odp_ishmphy_can_virt_to_phys(void)
 
 	return 1;
 }
+
+/*
+ * dump the physical mapping from virtual address addr, length len.
+ */
+void _odp_ishmphy_memmap_print(void *curr_addr, uint64_t len)
+{
+	int page_sz;
+	phys_addr_t curr_phy;
+	phys_addr_t start_phy;
+	void *start_address = 0;
+	uint32_t curr_len = 0;
+	uint32_t pfn_count = 0;
+
+	/* get normal page sizes: */
+	page_sz = odp_sys_page_size();
+
+	curr_phy = _odp_ishmphy_virt_to_phys(curr_addr);
+	if (curr_phy == PHYS_ADDR_INVALID) {
+		ODP_DBG("Phy Dump failed (permission?).\n");
+		return;
+	}
+
+	ODP_DBG("Phy Dump:\n");
+	start_address = curr_addr;
+	start_phy = curr_phy;
+
+	curr_len += page_sz;
+	curr_addr = (void *)((char *)curr_addr + page_sz);
+	pfn_count++;
+	while (curr_len < len) {
+		if (_odp_ishmphy_virt_to_phys(curr_addr) ==
+		    curr_phy + page_sz) {
+			curr_len += page_sz;
+			curr_addr = (void *)((char *)curr_addr + page_sz);
+			curr_phy += page_sz;
+			pfn_count++;
+			continue;
+		}
+
+		ODP_DBG("Virtual: %08" PRIx64 " <-->  Phy: %08" PRIx64
+			"   %" PRIu32 " PFNs, %" PRIu32 " bytes\n",
+			(uint64_t)start_address, start_phy,
+			pfn_count, pfn_count * page_sz);
+		curr_phy =  _odp_ishmphy_virt_to_phys(curr_addr);
+		start_address = curr_addr;
+		start_phy = curr_phy;
+		pfn_count = 0;
+		curr_len += page_sz;
+		curr_addr = (void *)((char *)curr_addr + page_sz);
+		pfn_count++;
+	}
+
+	if (pfn_count)
+		ODP_DBG("Virtual: %08" PRIx64 " <-->  Phy: %08" PRIx64
+			"   %" PRIu32 " PFNs, %" PRIu32 " bytes\n",
+			(uint64_t)start_address, start_phy,
+			pfn_count, pfn_count * page_sz);
+}
diff --git a/platform/linux-generic/include/_ishmphy_internal.h b/platform/linux-generic/include/_ishmphy_internal.h
index 2022590..c8752c0 100644
--- a/platform/linux-generic/include/_ishmphy_internal.h
+++ b/platform/linux-generic/include/_ishmphy_internal.h
@@ -32,6 +32,11 @@  int _odp_ishmphy_can_virt_to_phys(void);
  */
 phys_addr_t _odp_ishmphy_virt_to_phys(const void *addr);
 
+/*
+ * dump the physical mapping from virtual address addr, length len.
+ */
+void _odp_ishmphy_memmap_print(void *addr, uint64_t len);
+
 #ifdef __cplusplus
 }
 #endif