numam-dpdk/drivers/common/dpaax/dpaax_iova_table.h
David Marchand 1094dd940e cleanup compat header inclusions
With symbols going though experimental/stable stages, we accumulated
a lot of discrepancies about inclusion of the rte_compat.h header.

Some headers are including it where unneeded, while others rely on
implicit inclusion.

Fix unneeded inclusions:
$ git grep -l include..rte_compat.h |
  xargs grep -LE '__rte_(internal|experimental)' |
  xargs sed -i -e '/#include..rte_compat.h/d'

Fix missing inclusion, by inserting rte_compat.h before the first
inclusion of a DPDK header:
$ git grep -lE '__rte_(internal|experimental)' |
  xargs grep -L include..rte_compat.h |
  xargs sed -i -e \
    '0,/#include..\(rte_\|.*pmd.h.$\)/{
      s/\(#include..\(rte_\|.*pmd.h.$\)\)/#include <rte_compat.h>\n\1/
    }'

Fix missing inclusion, by inserting rte_compat.h after the last
inclusion of a non DPDK header:
$ for file in $(git grep -lE '__rte_(internal|experimental)' |
  xargs grep -L include..rte_compat.h); do
    tac $file > $file.$$
    sed -i -e \
      '0,/#include../{
        s/\(#include..*$\)/#include <rte_compat.h>\n\n\1/
      }' $file.$$
    tac $file.$$ > $file
    rm $file.$$
  done

Fix missing inclusion, by inserting rte_compat.h after the header guard:
$ git grep -lE '__rte_(internal|experimental)' |
  xargs grep -L include..rte_compat.h |
  xargs sed -i -e \
    '0,/#define/{
      s/\(#define .*$\)/\1\n\n#include <rte_compat.h>/
    }'

And finally, exclude rte_compat.h itself.
$ git checkout lib/eal/include/rte_compat.h

At the end of all this, we have a clean tree:
$ git grep -lE '__rte_(internal|experimental)' |
  xargs grep -L include..rte_compat.h
buildtools/check-symbols.sh
devtools/checkpatches.sh
doc/guides/contributing/abi_policy.rst
doc/guides/rel_notes/release_20_11.rst
lib/eal/include/rte_compat.h

Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
2022-11-15 08:39:14 +01:00

119 lines
3.3 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright 2018-2021 NXP
*/
#ifndef _DPAAX_IOVA_TABLE_H_
#define _DPAAX_IOVA_TABLE_H_
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <fcntl.h>
#include <glob.h>
#include <errno.h>
#include <arpa/inet.h>
#include <rte_compat.h>
#include <rte_eal.h>
#include <rte_branch_prediction.h>
#include <rte_memory.h>
#include <rte_malloc.h>
struct dpaax_iovat_element {
phys_addr_t start; /**< Start address of block of physical pages */
size_t len; /**< Difference of end-start for quick access */
uint64_t *pages; /**< VA for each physical page in this block */
};
struct dpaax_iova_table {
unsigned int count; /**< No. of blocks of contiguous physical pages */
struct dpaax_iovat_element entries[];
};
/* Pointer to the table, which is common for DPAA/DPAA2 and only a single
* instance is required across net/crypto/event drivers. This table is
* populated iff devices are found on the bus.
*/
extern struct dpaax_iova_table *dpaax_iova_table_p;
/* Device tree file for memory layout is named 'memory@<addr>' where the 'addr'
* is SoC dependent, or even Uboot fixup dependent.
*/
#define MEM_NODE_PATH_GLOB "/proc/device-tree/memory[@0-9]*/reg"
/* For Virtual Machines memory node is at different path (below) */
#define MEM_NODE_PATH_GLOB_VM "/proc/device-tree/memory/reg"
/* Device file should be multiple of 16 bytes, each containing 8 byte of addr
* and its length. Assuming max of 5 entries.
*/
#define MEM_NODE_FILE_LEN ((16 * 5) + 1)
/* Table is made up of DPAAX_MEM_SPLIT elements for each contiguous zone. This
* helps avoid separate handling for cases where more than one size of hugepage
* is supported.
*/
#define DPAAX_MEM_SPLIT (1<<21)
#define DPAAX_MEM_SPLIT_MASK ~(DPAAX_MEM_SPLIT - 1) /**< Floor aligned */
#define DPAAX_MEM_SPLIT_MASK_OFF (DPAAX_MEM_SPLIT - 1) /**< Offset */
/* APIs exposed */
__rte_internal
int dpaax_iova_table_populate(void);
__rte_internal
void dpaax_iova_table_depopulate(void);
__rte_internal
int dpaax_iova_table_update(phys_addr_t paddr, void *vaddr, size_t length);
__rte_internal
void dpaax_iova_table_dump(void);
static inline void *dpaax_iova_table_get_va(phys_addr_t paddr) __rte_hot;
static inline void *
dpaax_iova_table_get_va(phys_addr_t paddr) {
unsigned int i = 0, index;
void *vaddr = 0;
phys_addr_t paddr_align = paddr & DPAAX_MEM_SPLIT_MASK;
size_t offset = paddr & DPAAX_MEM_SPLIT_MASK_OFF;
struct dpaax_iovat_element *entry;
if (unlikely(dpaax_iova_table_p == NULL))
return NULL;
entry = dpaax_iova_table_p->entries;
do {
if (unlikely(i > dpaax_iova_table_p->count))
break;
if (paddr_align < entry[i].start) {
/* Incorrect paddr; Not in memory range */
return NULL;
}
if (paddr_align > (entry[i].start + entry[i].len)) {
i++;
continue;
}
/* paddr > entry->start && paddr <= entry->(start+len) */
index = (paddr_align - entry[i].start)/DPAAX_MEM_SPLIT;
/* paddr is within range, but no vaddr entry ever written
* at index
*/
if ((void *)(uintptr_t)entry[i].pages[index] == NULL)
return NULL;
vaddr = (void *)((uintptr_t)entry[i].pages[index] + offset);
break;
} while (1);
return vaddr;
}
#endif /* _DPAAX_IOVA_TABLE_H_ */