Line data Source code
1 0 : /* 2 : * Copyright (c) 2021 EPAM Systems 3 : * 4 : * SPDX-License-Identifier: Apache-2.0 5 : */ 6 : #ifndef __XEN_GENERIC_H__ 7 : #define __XEN_GENERIC_H__ 8 : 9 : #include <zephyr/xen/public/xen.h> 10 : 11 0 : #define XEN_PAGE_SIZE 4096 12 0 : #define XEN_PAGE_SHIFT 12 13 : 14 0 : #define XEN_PFN_UP(x) (unsigned long)(((x) + XEN_PAGE_SIZE-1) >> XEN_PAGE_SHIFT) 15 0 : #define XEN_PFN_DOWN(x) (unsigned long)((x) >> XEN_PAGE_SHIFT) 16 0 : #define XEN_PFN_PHYS(x) ((unsigned long)(x) << XEN_PAGE_SHIFT) 17 0 : #define XEN_PHYS_PFN(x) (unsigned long)((x) >> XEN_PAGE_SHIFT) 18 : 19 0 : #define xen_to_phys(x) ((unsigned long) (x)) 20 0 : #define xen_to_virt(x) ((void *) (x)) 21 : 22 0 : #define xen_virt_to_gfn(_virt) (XEN_PFN_DOWN(xen_to_phys(_virt))) 23 0 : #define xen_gfn_to_virt(_gfn) (xen_to_virt(XEN_PFN_PHYS(_gfn))) 24 : 25 : /* 26 : * Atomically exchange value on "ptr" position. If value on "ptr" contains 27 : * "old", then store and return "new". Otherwise, return the "old" value. 28 : */ 29 0 : #define synch_cmpxchg(ptr, old, new) \ 30 : ({ __typeof__(*ptr) stored = old; \ 31 : __atomic_compare_exchange_n(ptr, &stored, new, 0, __ATOMIC_SEQ_CST, \ 32 : __ATOMIC_SEQ_CST) ? new : old; \ 33 : }) 34 : 35 : #endif /* __XEN_GENERIC_H__ */