freebsd-dev/sys/xen/xen-os.h
Roger Pau Monné 2f9ec994bc xen: Code cleanup and small bug fixes
xen/hypervisor.h:
 - Remove unused helpers: MULTI_update_va_mapping, is_initial_xendomain,
   is_running_on_xen
 - Remove unused define CONFIG_X86_PAE
 - Remove unused variable xen_start_info: note that it's used inpcifront
   which is not built at all
 - Remove forward declaration of HYPERVISOR_crash

xen/xen-os.h:
 - Remove unused define CONFIG_X86_PAE
 - Drop unused helpers: test_and_clear_bit, clear_bit,
   force_evtchn_callback
 - Implement a generic version (based on ofed/include/linux/bitops.h) of
   set_bit and test_bit and prefix them by xen_ to avoid any use by other
   code than Xen. Note that It would be worth to investigate a generic
   implementation in FreeBSD.
 - Replace barrier() by __compiler_membar()
 - Replace cpu_relax() by cpu_spinwait(): it's exactly the same as rep;nop
   = pause

xen/xen_intr.h:
 - Move the prototype of xen_intr_handle_upcall in it: Use by all the
   platform

x86/xen/xen_intr.c:
 - Use BITSET* for the enabledbits: Avoid to use custom helpers
 - test_bit/set_bit has been renamed to xen_test_bit/xen_set_bit
 - Don't export the variable xen_intr_pcpu

dev/xen/blkback/blkback.c:
 - Fix the string format when XBB_DEBUG is enabled: host_addr is typed
   uint64_t

dev/xen/balloon/balloon.c:
 - Remove set but not used variable
 - Use the correct type for frame_list: xen_pfn_t represents the frame
   number on any architecture

dev/xen/control/control.c:
 - Return BUS_PROBE_WILDCARD in xs_probe: Returning 0 in a probe callback
   means the driver can handle this device. If by any chance xenstore is the
   first driver, every new device with the driver is unset will use
   xenstore.

dev/xen/grant-table/grant_table.c:
 - Remove unused cmpxchg
 - Drop unused include opt_pmap.h: Doesn't exist on ARM64 and it doesn't
   contain anything required for the code on x86

dev/xen/netfront/netfront.c:
 - Use the correct type for rx_pfn_array: xen_pfn_t represents the frame
   number on any architecture

dev/xen/netback/netback.c:
 - Use the correct type for gmfn: xen_pfn_t represents the frame number on
   any architecture

dev/xen/xenstore/xenstore.c:
 - Return BUS_PROBE_WILDCARD in xctrl_probe: Returning 0 in a probe callback
   means the driver can handle this device. If by any chance xenstore is the
  first driver, every new device with the driver is unset will use xenstore.

Note that with the changes, x86/include/xen/xen-os.h doesn't contain anymore
arch-specific code. Although, a new series will add some helpers that differ
between x86 and ARM64, so I've kept the headers for now.

Submitted by:		Julien Grall <julien.grall@citrix.com>
Reviewed by:		royger
Differential Revision:	https://reviews.freebsd.org/D3921
Sponsored by:		Citrix Systems R&D
2015-10-21 10:44:07 +00:00

140 lines
3.7 KiB
C

/******************************************************************************
* xen/xen-os.h
*
* Random collection of macros and definition
*
* Copyright (c) 2003, 2004 Keir Fraser (on behalf of the Xen team)
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* $FreeBSD$
*/
#ifndef _XEN_XEN_OS_H_
#define _XEN_XEN_OS_H_
#if !defined(__XEN_INTERFACE_VERSION__)
#define __XEN_INTERFACE_VERSION__ 0x00030208
#endif
#define GRANT_REF_INVALID 0xffffffff
#ifdef LOCORE
#define __ASSEMBLY__
#endif
#include <machine/xen/xen-os.h>
#include <xen/interface/xen.h>
/* Everything below this point is not included by assembler (.S) files. */
#ifndef __ASSEMBLY__
extern shared_info_t *HYPERVISOR_shared_info;
extern start_info_t *HYPERVISOR_start_info;
/* XXX: we need to get rid of this and use HYPERVISOR_start_info directly */
extern char *console_page;
extern int xen_disable_pv_disks;
extern int xen_disable_pv_nics;
enum xen_domain_type {
XEN_NATIVE, /* running on bare hardware */
XEN_PV_DOMAIN, /* running in a PV domain */
XEN_HVM_DOMAIN, /* running in a Xen hvm domain */
};
extern enum xen_domain_type xen_domain_type;
static inline int
xen_domain(void)
{
return (xen_domain_type != XEN_NATIVE);
}
static inline int
xen_pv_domain(void)
{
return (xen_domain_type == XEN_PV_DOMAIN);
}
static inline int
xen_hvm_domain(void)
{
return (xen_domain_type == XEN_HVM_DOMAIN);
}
static inline bool
xen_initial_domain(void)
{
return (xen_domain() && HYPERVISOR_start_info != NULL &&
(HYPERVISOR_start_info->flags & SIF_INITDOMAIN) != 0);
}
/*
* Based on ofed/include/linux/bitops.h
*
* Those helpers are prefixed by xen_ because xen-os.h is widely included
* and we don't want the other drivers using them.
*
*/
#define NBPL (NBBY * sizeof(long))
static inline bool
xen_test_bit(int bit, volatile long *addr)
{
unsigned long mask = 1UL << (bit % NBPL);
return !!(atomic_load_acq_long(&addr[bit / NBPL]) & mask);
}
static inline void
xen_set_bit(int bit, volatile long *addr)
{
atomic_set_long(&addr[bit / NBPL], 1UL << (bit % NBPL));
}
#undef NPBL
/*
* Functions to allocate/free unused memory in order
* to map memory from other domains.
*/
struct resource *xenmem_alloc(device_t dev, int *res_id, size_t size);
int xenmem_free(device_t dev, int res_id, struct resource *res);
/* Debug/emergency function, prints directly to hypervisor console */
void xc_printf(const char *, ...) __printflike(1, 2);
#ifndef xen_mb
#define xen_mb() mb()
#endif
#ifndef xen_rmb
#define xen_rmb() rmb()
#endif
#ifndef xen_wmb
#define xen_wmb() wmb()
#endif
#endif /* !__ASSEMBLY__ */
#endif /* _XEN_XEN_OS_H_ */