LCOV - code coverage report
Current view: top level - drivers/common/dpaax - dpaax_iova_table.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 13 0.0 %
Date: 2025-03-01 20:23:48 Functions: 0 1 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 10 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2018-2021 NXP
       3                 :            :  */
       4                 :            : 
       5                 :            : #ifndef _DPAAX_IOVA_TABLE_H_
       6                 :            : #define _DPAAX_IOVA_TABLE_H_
       7                 :            : 
       8                 :            : #include <unistd.h>
       9                 :            : #include <stdio.h>
      10                 :            : #include <string.h>
      11                 :            : #include <stdbool.h>
      12                 :            : #include <stdlib.h>
      13                 :            : #include <inttypes.h>
      14                 :            : #include <sys/stat.h>
      15                 :            : #include <sys/types.h>
      16                 :            : #include <dirent.h>
      17                 :            : #include <fcntl.h>
      18                 :            : #include <glob.h>
      19                 :            : #include <errno.h>
      20                 :            : #include <arpa/inet.h>
      21                 :            : 
      22                 :            : #include <rte_compat.h>
      23                 :            : #include <rte_eal.h>
      24                 :            : #include <rte_branch_prediction.h>
      25                 :            : #include <rte_memory.h>
      26                 :            : #include <rte_malloc.h>
      27                 :            : 
      28                 :            : struct dpaax_iovat_element {
      29                 :            :         phys_addr_t start; /**< Start address of block of physical pages */
      30                 :            :         size_t len; /**< Difference of end-start for quick access */
      31                 :            :         uint64_t *pages; /**< VA for each physical page in this block */
      32                 :            : };
      33                 :            : 
      34                 :            : struct dpaax_iova_table {
      35                 :            :         unsigned int count; /**< No. of blocks of contiguous physical pages */
      36                 :            :         struct dpaax_iovat_element entries[];
      37                 :            : };
      38                 :            : 
      39                 :            : /* Pointer to the table, which is common for DPAA/DPAA2 and only a single
      40                 :            :  * instance is required across net/crypto/event drivers. This table is
      41                 :            :  * populated iff devices are found on the bus.
      42                 :            :  */
      43                 :            : extern struct dpaax_iova_table *dpaax_iova_table_p;
      44                 :            : 
      45                 :            : /* Device tree file for memory layout is named 'memory@<addr>' where the 'addr'
      46                 :            :  * is SoC dependent, or even Uboot fixup dependent.
      47                 :            :  */
      48                 :            : #define MEM_NODE_PATH_GLOB "/proc/device-tree/memory[@0-9]*/reg"
      49                 :            : /* For Virtual Machines memory node is at different path (below) */
      50                 :            : #define MEM_NODE_PATH_GLOB_VM "/proc/device-tree/memory/reg"
      51                 :            : /* Device file should be multiple of 16 bytes, each containing 8 byte of addr
      52                 :            :  * and its length. Assuming max of 5 entries.
      53                 :            :  */
      54                 :            : #define MEM_NODE_FILE_LEN ((16 * 5) + 1)
      55                 :            : 
      56                 :            : /* Table is made up of DPAAX_MEM_SPLIT elements for each contiguous zone. This
      57                 :            :  * helps avoid separate handling for cases where more than one size of hugepage
      58                 :            :  * is supported.
      59                 :            :  */
      60                 :            : #define DPAAX_MEM_SPLIT (1<<21)
      61                 :            : #define DPAAX_MEM_SPLIT_MASK ~(DPAAX_MEM_SPLIT - 1) /**< Floor aligned */
      62                 :            : #define DPAAX_MEM_SPLIT_MASK_OFF (DPAAX_MEM_SPLIT - 1) /**< Offset */
      63                 :            : 
      64                 :            : /* APIs exposed */
      65                 :            : __rte_internal
      66                 :            : int dpaax_iova_table_populate(void);
      67                 :            : __rte_internal
      68                 :            : void dpaax_iova_table_depopulate(void);
      69                 :            : __rte_internal
      70                 :            : int dpaax_iova_table_update(phys_addr_t paddr, void *vaddr, size_t length);
      71                 :            : __rte_internal
      72                 :            : void dpaax_iova_table_dump(void);
      73                 :            : 
      74                 :            : static inline void *dpaax_iova_table_get_va(phys_addr_t paddr) __rte_hot;
      75                 :            : 
      76                 :            : static inline void *
      77                 :          0 : dpaax_iova_table_get_va(phys_addr_t paddr) {
      78                 :            :         unsigned int i = 0, index;
      79                 :            :         void *vaddr = 0;
      80                 :          0 :         phys_addr_t paddr_align = paddr & DPAAX_MEM_SPLIT_MASK;
      81                 :          0 :         size_t offset = paddr & DPAAX_MEM_SPLIT_MASK_OFF;
      82                 :            :         struct dpaax_iovat_element *entry;
      83                 :            : 
      84         [ #  # ]:          0 :         if (unlikely(dpaax_iova_table_p == NULL))
      85                 :            :                 return NULL;
      86                 :            : 
      87                 :          0 :         entry = dpaax_iova_table_p->entries;
      88                 :            : 
      89                 :            :         do {
      90         [ #  # ]:          0 :                 if (unlikely(i > dpaax_iova_table_p->count))
      91                 :            :                         break;
      92                 :            : 
      93         [ #  # ]:          0 :                 if (paddr_align < entry[i].start) {
      94                 :            :                         /* Incorrect paddr; Not in memory range */
      95                 :            :                         return NULL;
      96                 :            :                 }
      97                 :            : 
      98         [ #  # ]:          0 :                 if (paddr_align > (entry[i].start + entry[i].len)) {
      99                 :          0 :                         i++;
     100                 :            :                         continue;
     101                 :            :                 }
     102                 :            : 
     103                 :            :                 /* paddr > entry->start && paddr <= entry->(start+len) */
     104                 :          0 :                 index = (paddr_align - entry[i].start)/DPAAX_MEM_SPLIT;
     105                 :            :                 /* paddr is within range, but no vaddr entry ever written
     106                 :            :                  * at index
     107                 :            :                  */
     108         [ #  # ]:          0 :                 if ((void *)(uintptr_t)entry[i].pages[index] == NULL)
     109                 :            :                         return NULL;
     110                 :            : 
     111                 :          0 :                 vaddr = (void *)((uintptr_t)entry[i].pages[index] + offset);
     112                 :          0 :                 break;
     113                 :            :         } while (1);
     114                 :            : 
     115                 :            :         return vaddr;
     116                 :            : }
     117                 :            : 
     118                 :            : #endif /* _DPAAX_IOVA_TABLE_H_ */

Generated by: LCOV version 1.14