Commit aa3ecf38 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'for-linus-4.10-rc0-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip

Pull xen updates from Juergen Gross:
 "Xen features and fixes for 4.10

  These are some fixes, a move of some arm related headers to share them
  between arm and arm64 and a series introducing a helper to make code
  more readable.

  The most notable change is David stepping down as maintainer of the
  Xen hypervisor interface. This results in me sending you the pull
  requests for Xen related code from now on"

* tag 'for-linus-4.10-rc0-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip: (29 commits)
  xen/balloon: Only mark a page as managed when it is released
  xenbus: fix deadlock on writes to /proc/xen/xenbus
  xen/scsifront: don't request a slot on the ring until request is ready
  xen/x86: Increase xen_e820_map to E820_X_MAX possible entries
  x86: Make E820_X_MAX unconditionally larger than E820MAX
  xen/pci: Bubble up error and fix description.
  xen: xenbus: set error code on failure
  xen: set error code on failures
  arm/xen: Use alloc_percpu rather than __alloc_percpu
  arm/arm64: xen: Move shared architecture headers to include/xen/arm
  xen/events: use xen_vcpu_id mapping for EVTCHNOP_status
  xen/gntdev: Use VM_MIXEDMAP instead of VM_IO to avoid NUMA balancing
  xen-scsifront: Add a missing call to kfree
  MAINTAINERS: update XEN HYPERVISOR INTERFACE
  xenfs: Use proc_create_mount_point() to create /proc/xen
  xen-platform: use builtin_pci_driver
  xen-netback: fix error handling output
  xen: make use of xenbus_read_unsigned() in xenbus
  xen: make use of xenbus_read_unsigned() in xen-pciback
  xen: make use of xenbus_read_unsigned() in xen-fbfront
  ...
parents b5cab0da 709613ad
...@@ -13354,7 +13354,6 @@ F: drivers/media/tuners/tuner-xc2028.* ...@@ -13354,7 +13354,6 @@ F: drivers/media/tuners/tuner-xc2028.*
XEN HYPERVISOR INTERFACE XEN HYPERVISOR INTERFACE
M: Boris Ostrovsky <boris.ostrovsky@oracle.com> M: Boris Ostrovsky <boris.ostrovsky@oracle.com>
M: David Vrabel <david.vrabel@citrix.com>
M: Juergen Gross <jgross@suse.com> M: Juergen Gross <jgross@suse.com>
L: xen-devel@lists.xenproject.org (moderated for non-subscribers) L: xen-devel@lists.xenproject.org (moderated for non-subscribers)
T: git git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip.git T: git git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip.git
......
/****************************************************************************** #include <xen/arm/hypercall.h>
* hypercall.h
*
* Linux-specific hypervisor handling.
*
* Stefano Stabellini <stefano.stabellini@eu.citrix.com>, Citrix, 2012
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation; or, when distributed
* separately from the Linux kernel or incorporated into other
* software packages, subject to the following license:
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this source file (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.
*/
#ifndef _ASM_ARM_XEN_HYPERCALL_H
#define _ASM_ARM_XEN_HYPERCALL_H
#include <linux/bug.h>
#include <xen/interface/xen.h>
#include <xen/interface/sched.h>
#include <xen/interface/platform.h>
long privcmd_call(unsigned call, unsigned long a1,
unsigned long a2, unsigned long a3,
unsigned long a4, unsigned long a5);
int HYPERVISOR_xen_version(int cmd, void *arg);
int HYPERVISOR_console_io(int cmd, int count, char *str);
int HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count);
int HYPERVISOR_sched_op(int cmd, void *arg);
int HYPERVISOR_event_channel_op(int cmd, void *arg);
unsigned long HYPERVISOR_hvm_op(int op, void *arg);
int HYPERVISOR_memory_op(unsigned int cmd, void *arg);
int HYPERVISOR_physdev_op(int cmd, void *arg);
int HYPERVISOR_vcpu_op(int cmd, int vcpuid, void *extra_args);
int HYPERVISOR_tmem_op(void *arg);
int HYPERVISOR_vm_assist(unsigned int cmd, unsigned int type);
int HYPERVISOR_platform_op_raw(void *arg);
static inline int HYPERVISOR_platform_op(struct xen_platform_op *op)
{
op->interface_version = XENPF_INTERFACE_VERSION;
return HYPERVISOR_platform_op_raw(op);
}
int HYPERVISOR_multicall(struct multicall_entry *calls, uint32_t nr);
static inline int
HYPERVISOR_suspend(unsigned long start_info_mfn)
{
struct sched_shutdown r = { .reason = SHUTDOWN_suspend };
/* start_info_mfn is unused on ARM */
return HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
}
static inline void
MULTI_update_va_mapping(struct multicall_entry *mcl, unsigned long va,
unsigned int new_val, unsigned long flags)
{
BUG();
}
static inline void
MULTI_mmu_update(struct multicall_entry *mcl, struct mmu_update *req,
int count, int *success_count, domid_t domid)
{
BUG();
}
#endif /* _ASM_ARM_XEN_HYPERCALL_H */
#ifndef _ASM_ARM_XEN_HYPERVISOR_H #include <xen/arm/hypervisor.h>
#define _ASM_ARM_XEN_HYPERVISOR_H
#include <linux/init.h>
extern struct shared_info *HYPERVISOR_shared_info;
extern struct start_info *xen_start_info;
/* Lazy mode for batching updates / context switch */
enum paravirt_lazy_mode {
PARAVIRT_LAZY_NONE,
PARAVIRT_LAZY_MMU,
PARAVIRT_LAZY_CPU,
};
static inline enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
{
return PARAVIRT_LAZY_NONE;
}
extern struct dma_map_ops *xen_dma_ops;
#ifdef CONFIG_XEN
void __init xen_early_init(void);
#else
static inline void xen_early_init(void) { return; }
#endif
#ifdef CONFIG_HOTPLUG_CPU
static inline void xen_arch_register_cpu(int num)
{
}
static inline void xen_arch_unregister_cpu(int num)
{
}
#endif
#endif /* _ASM_ARM_XEN_HYPERVISOR_H */
/****************************************************************************** #include <xen/arm/interface.h>
* Guest OS interface to ARM Xen.
*
* Stefano Stabellini <stefano.stabellini@eu.citrix.com>, Citrix, 2012
*/
#ifndef _ASM_ARM_XEN_INTERFACE_H
#define _ASM_ARM_XEN_INTERFACE_H
#include <linux/types.h>
#define uint64_aligned_t uint64_t __attribute__((aligned(8)))
#define __DEFINE_GUEST_HANDLE(name, type) \
typedef struct { union { type *p; uint64_aligned_t q; }; } \
__guest_handle_ ## name
#define DEFINE_GUEST_HANDLE_STRUCT(name) \
__DEFINE_GUEST_HANDLE(name, struct name)
#define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name)
#define GUEST_HANDLE(name) __guest_handle_ ## name
#define set_xen_guest_handle(hnd, val) \
do { \
if (sizeof(hnd) == 8) \
*(uint64_t *)&(hnd) = 0; \
(hnd).p = val; \
} while (0)
#define __HYPERVISOR_platform_op_raw __HYPERVISOR_platform_op
#ifndef __ASSEMBLY__
/* Explicitly size integers that represent pfns in the interface with
* Xen so that we can have one ABI that works for 32 and 64 bit guests.
* Note that this means that the xen_pfn_t type may be capable of
* representing pfn's which the guest cannot represent in its own pfn
* type. However since pfn space is controlled by the guest this is
* fine since it simply wouldn't be able to create any sure pfns in
* the first place.
*/
typedef uint64_t xen_pfn_t;
#define PRI_xen_pfn "llx"
typedef uint64_t xen_ulong_t;
#define PRI_xen_ulong "llx"
typedef int64_t xen_long_t;
#define PRI_xen_long "llx"
/* Guest handles for primitive C types. */
__DEFINE_GUEST_HANDLE(uchar, unsigned char);
__DEFINE_GUEST_HANDLE(uint, unsigned int);
DEFINE_GUEST_HANDLE(char);
DEFINE_GUEST_HANDLE(int);
DEFINE_GUEST_HANDLE(void);
DEFINE_GUEST_HANDLE(uint64_t);
DEFINE_GUEST_HANDLE(uint32_t);
DEFINE_GUEST_HANDLE(xen_pfn_t);
DEFINE_GUEST_HANDLE(xen_ulong_t);
/* Maximum number of virtual CPUs in multi-processor guests. */
#define MAX_VIRT_CPUS 1
struct arch_vcpu_info { };
struct arch_shared_info { };
/* TODO: Move pvclock definitions some place arch independent */
struct pvclock_vcpu_time_info {
u32 version;
u32 pad0;
u64 tsc_timestamp;
u64 system_time;
u32 tsc_to_system_mul;
s8 tsc_shift;
u8 flags;
u8 pad[2];
} __attribute__((__packed__)); /* 32 bytes */
/* It is OK to have a 12 bytes struct with no padding because it is packed */
struct pvclock_wall_clock {
u32 version;
u32 sec;
u32 nsec;
u32 sec_hi;
} __attribute__((__packed__));
#endif
#endif /* _ASM_ARM_XEN_INTERFACE_H */
#ifndef _ASM_ARM_XEN_PAGE_COHERENT_H #include <xen/arm/page-coherent.h>
#define _ASM_ARM_XEN_PAGE_COHERENT_H
#include <asm/page.h>
#include <linux/dma-mapping.h>
void __xen_dma_map_page(struct device *hwdev, struct page *page,
dma_addr_t dev_addr, unsigned long offset, size_t size,
enum dma_data_direction dir, unsigned long attrs);
void __xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle,
size_t size, enum dma_data_direction dir,
unsigned long attrs);
void __xen_dma_sync_single_for_cpu(struct device *hwdev,
dma_addr_t handle, size_t size, enum dma_data_direction dir);
void __xen_dma_sync_single_for_device(struct device *hwdev,
dma_addr_t handle, size_t size, enum dma_data_direction dir);
static inline void *xen_alloc_coherent_pages(struct device *hwdev, size_t size,
dma_addr_t *dma_handle, gfp_t flags, unsigned long attrs)
{
return __generic_dma_ops(hwdev)->alloc(hwdev, size, dma_handle, flags, attrs);
}
static inline void xen_free_coherent_pages(struct device *hwdev, size_t size,
void *cpu_addr, dma_addr_t dma_handle, unsigned long attrs)
{
__generic_dma_ops(hwdev)->free(hwdev, size, cpu_addr, dma_handle, attrs);
}
static inline void xen_dma_map_page(struct device *hwdev, struct page *page,
dma_addr_t dev_addr, unsigned long offset, size_t size,
enum dma_data_direction dir, unsigned long attrs)
{
unsigned long page_pfn = page_to_xen_pfn(page);
unsigned long dev_pfn = XEN_PFN_DOWN(dev_addr);
unsigned long compound_pages =
(1<<compound_order(page)) * XEN_PFN_PER_PAGE;
bool local = (page_pfn <= dev_pfn) &&
(dev_pfn - page_pfn < compound_pages);
/*
* Dom0 is mapped 1:1, while the Linux page can span across
* multiple Xen pages, it's not possible for it to contain a
* mix of local and foreign Xen pages. So if the first xen_pfn
* == mfn the page is local otherwise it's a foreign page
* grant-mapped in dom0. If the page is local we can safely
* call the native dma_ops function, otherwise we call the xen
* specific function.
*/
if (local)
__generic_dma_ops(hwdev)->map_page(hwdev, page, offset, size, dir, attrs);
else
__xen_dma_map_page(hwdev, page, dev_addr, offset, size, dir, attrs);
}
static inline void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle,
size_t size, enum dma_data_direction dir, unsigned long attrs)
{
unsigned long pfn = PFN_DOWN(handle);
/*
* Dom0 is mapped 1:1, while the Linux page can be spanned accross
* multiple Xen page, it's not possible to have a mix of local and
* foreign Xen page. Dom0 is mapped 1:1, so calling pfn_valid on a
* foreign mfn will always return false. If the page is local we can
* safely call the native dma_ops function, otherwise we call the xen
* specific function.
*/
if (pfn_valid(pfn)) {
if (__generic_dma_ops(hwdev)->unmap_page)
__generic_dma_ops(hwdev)->unmap_page(hwdev, handle, size, dir, attrs);
} else
__xen_dma_unmap_page(hwdev, handle, size, dir, attrs);
}
static inline void xen_dma_sync_single_for_cpu(struct device *hwdev,
dma_addr_t handle, size_t size, enum dma_data_direction dir)
{
unsigned long pfn = PFN_DOWN(handle);
if (pfn_valid(pfn)) {
if (__generic_dma_ops(hwdev)->sync_single_for_cpu)
__generic_dma_ops(hwdev)->sync_single_for_cpu(hwdev, handle, size, dir);
} else
__xen_dma_sync_single_for_cpu(hwdev, handle, size, dir);
}
static inline void xen_dma_sync_single_for_device(struct device *hwdev,
dma_addr_t handle, size_t size, enum dma_data_direction dir)
{
unsigned long pfn = PFN_DOWN(handle);
if (pfn_valid(pfn)) {
if (__generic_dma_ops(hwdev)->sync_single_for_device)
__generic_dma_ops(hwdev)->sync_single_for_device(hwdev, handle, size, dir);
} else
__xen_dma_sync_single_for_device(hwdev, handle, size, dir);
}
#endif /* _ASM_ARM_XEN_PAGE_COHERENT_H */
#ifndef _ASM_ARM_XEN_PAGE_H #include <xen/arm/page.h>
#define _ASM_ARM_XEN_PAGE_H
#include <asm/page.h>
#include <asm/pgtable.h>
#include <linux/pfn.h>
#include <linux/types.h>
#include <linux/dma-mapping.h>
#include <xen/xen.h>
#include <xen/interface/grant_table.h>
#define phys_to_machine_mapping_valid(pfn) (1)
/* Xen machine address */
typedef struct xmaddr {
phys_addr_t maddr;
} xmaddr_t;
/* Xen pseudo-physical address */
typedef struct xpaddr {
phys_addr_t paddr;
} xpaddr_t;
#define XMADDR(x) ((xmaddr_t) { .maddr = (x) })
#define XPADDR(x) ((xpaddr_t) { .paddr = (x) })
#define INVALID_P2M_ENTRY (~0UL)
/*
* The pseudo-physical frame (pfn) used in all the helpers is always based
* on Xen page granularity (i.e 4KB).
*
* A Linux page may be split across multiple non-contiguous Xen page so we
* have to keep track with frame based on 4KB page granularity.
*
* PV drivers should never make a direct usage of those helpers (particularly
* pfn_to_gfn and gfn_to_pfn).
*/
unsigned long __pfn_to_mfn(unsigned long pfn);
extern struct rb_root phys_to_mach;
/* Pseudo-physical <-> Guest conversion */
static inline unsigned long pfn_to_gfn(unsigned long pfn)
{
return pfn;
}
static inline unsigned long gfn_to_pfn(unsigned long gfn)
{
return gfn;
}
/* Pseudo-physical <-> BUS conversion */
static inline unsigned long pfn_to_bfn(unsigned long pfn)
{
unsigned long mfn;
if (phys_to_mach.rb_node != NULL) {
mfn = __pfn_to_mfn(pfn);
if (mfn != INVALID_P2M_ENTRY)
return mfn;
}
return pfn;
}
static inline unsigned long bfn_to_pfn(unsigned long bfn)
{
return bfn;
}
#define bfn_to_local_pfn(bfn) bfn_to_pfn(bfn)
/* VIRT <-> GUEST conversion */
#define virt_to_gfn(v) (pfn_to_gfn(virt_to_phys(v) >> XEN_PAGE_SHIFT))
#define gfn_to_virt(m) (__va(gfn_to_pfn(m) << XEN_PAGE_SHIFT))
/* Only used in PV code. But ARM guests are always HVM. */
static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
{
BUG();
}
/* TODO: this shouldn't be here but it is because the frontend drivers
* are using it (its rolled in headers) even though we won't hit the code path.
* So for right now just punt with this.
*/
static inline pte_t *lookup_address(unsigned long address, unsigned int *level)
{
BUG();
return NULL;
}
extern int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
struct gnttab_map_grant_ref *kmap_ops,
struct page **pages, unsigned int count);
extern int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
struct gnttab_unmap_grant_ref *kunmap_ops,
struct page **pages, unsigned int count);
bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);
bool __set_phys_to_machine_multi(unsigned long pfn, unsigned long mfn,
unsigned long nr_pages);
static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
{
return __set_phys_to_machine(pfn, mfn);
}
#define xen_remap(cookie, size) ioremap_cache((cookie), (size))
#define xen_unmap(cookie) iounmap((cookie))
bool xen_arch_need_swiotlb(struct device *dev,
phys_addr_t phys,
dma_addr_t dev_addr);
unsigned long xen_get_swiotlb_free_pages(unsigned int order);
#endif /* _ASM_ARM_XEN_PAGE_H */
...@@ -372,8 +372,7 @@ static int __init xen_guest_init(void) ...@@ -372,8 +372,7 @@ static int __init xen_guest_init(void)
* for secondary CPUs as they are brought up. * for secondary CPUs as they are brought up.
* For uniformity we use VCPUOP_register_vcpu_info even on cpu0. * For uniformity we use VCPUOP_register_vcpu_info even on cpu0.
*/ */
xen_vcpu_info = __alloc_percpu(sizeof(struct vcpu_info), xen_vcpu_info = alloc_percpu(struct vcpu_info);
sizeof(struct vcpu_info));
if (xen_vcpu_info == NULL) if (xen_vcpu_info == NULL)
return -ENOMEM; return -ENOMEM;
......
#include <../../arm/include/asm/xen/hypercall.h> #include <xen/arm/hypercall.h>
#include <../../arm/include/asm/xen/hypervisor.h> #include <xen/arm/hypervisor.h>
#include <../../arm/include/asm/xen/interface.h> #include <xen/arm/interface.h>
#include <../../arm/include/asm/xen/page-coherent.h> #include <xen/arm/page-coherent.h>
#include <../../arm/include/asm/xen/page.h> #include <xen/arm/page.h>
#ifndef _ASM_X86_E820_H #ifndef _ASM_X86_E820_H
#define _ASM_X86_E820_H #define _ASM_X86_E820_H
#ifdef CONFIG_EFI /*
* E820_X_MAX is the maximum size of the extended E820 table. The extended
* table may contain up to 3 extra E820 entries per possible NUMA node, so we
* make room for 3 * MAX_NUMNODES possible entries, beyond the standard 128.
* Also note that E820_X_MAX *must* be defined before we include uapi/asm/e820.h.
*/
#include <linux/numa.h> #include <linux/numa.h>
#define E820_X_MAX (E820MAX + 3 * MAX_NUMNODES) #define E820_X_MAX (E820MAX + 3 * MAX_NUMNODES)
#else /* ! CONFIG_EFI */
#define E820_X_MAX E820MAX
#endif
#include <uapi/asm/e820.h> #include <uapi/asm/e820.h>
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
/* see comment in arch/x86/kernel/e820.c */ /* see comment in arch/x86/kernel/e820.c */
extern struct e820map *e820; extern struct e820map *e820;
......
...@@ -264,8 +264,8 @@ static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) ...@@ -264,8 +264,8 @@ static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
return 0; return 0;
error: error:
dev_err(&dev->dev, dev_err(&dev->dev, "Failed to create MSI%s! ret=%d!\n",
"Xen PCI frontend has not registered MSI/MSI-X support!\n"); type == PCI_CAP_ID_MSI ? "" : "-X", irq);
return irq; return irq;
} }
......
...@@ -41,7 +41,7 @@ struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata; ...@@ -41,7 +41,7 @@ struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
unsigned long xen_released_pages; unsigned long xen_released_pages;
/* E820 map used during setting up memory. */ /* E820 map used during setting up memory. */
static struct e820entry xen_e820_map[E820MAX] __initdata; static struct e820entry xen_e820_map[E820_X_MAX] __initdata;
static u32 xen_e820_map_entries __initdata; static u32 xen_e820_map_entries __initdata;
/* /*
...@@ -750,7 +750,7 @@ char * __init xen_memory_setup(void) ...@@ -750,7 +750,7 @@ char * __init xen_memory_setup(void)
max_pfn = min(max_pfn, xen_start_info->nr_pages); max_pfn = min(max_pfn, xen_start_info->nr_pages);
mem_end = PFN_PHYS(max_pfn); mem_end = PFN_PHYS(max_pfn);
memmap.nr_entries = E820MAX; memmap.nr_entries = ARRAY_SIZE(xen_e820_map);
set_xen_guest_handle(memmap.buffer, xen_e820_map); set_xen_guest_handle(memmap.buffer, xen_e820_map);
op = xen_initial_domain() ? op = xen_initial_domain() ?
...@@ -923,7 +923,7 @@ char * __init xen_auto_xlated_memory_setup(void) ...@@ -923,7 +923,7 @@ char * __init xen_auto_xlated_memory_setup(void)
int i; int i;
int rc; int rc;
memmap.nr_entries = E820MAX; memmap.nr_entries = ARRAY_SIZE(xen_e820_map);
set_xen_guest_handle(memmap.buffer, xen_e820_map); set_xen_guest_handle(memmap.buffer, xen_e820_map);
rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
......
...@@ -533,13 +533,11 @@ static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info ...@@ -533,13 +533,11 @@ static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info
struct xenbus_device *dev = be->dev; struct xenbus_device *dev = be->dev;
struct xen_blkif *blkif = be->blkif; struct xen_blkif *blkif = be->blkif;
int err; int err;
int state = 0, discard_enable; int state = 0;
struct block_device *bdev = be->blkif->vbd.bdev; struct block_device *bdev = be->blkif->vbd.bdev;
struct request_queue *q = bdev_get_queue(bdev); struct request_queue *q = bdev_get_queue(bdev);
err = xenbus_scanf(XBT_NIL, dev->nodename, "discard-enable", "%d", if (!xenbus_read_unsigned(dev->nodename, "discard-enable", 1))
&discard_enable);
if (err == 1 && !discard_enable)
return; return;
if (blk_queue_discard(q)) { if (blk_queue_discard(q)) {
...@@ -1039,30 +1037,24 @@ static int connect_ring(struct backend_info *be) ...@@ -1039,30 +1037,24 @@ static int connect_ring(struct backend_info *be)
xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol); xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol);
return -ENOSYS; return -ENOSYS;
} }
err = xenbus_scanf(XBT_NIL, dev->otherend, pers_grants = xenbus_read_unsigned(dev->otherend, "feature-persistent",
"feature-persistent", "%u", &pers_grants); 0);
if (err <= 0)
pers_grants = 0;
be->blkif->vbd.feature_gnt_persistent = pers_grants; be->blkif->vbd.feature_gnt_persistent = pers_grants;
be->blkif->vbd.overflow_max_grants = 0; be->blkif->vbd.overflow_max_grants = 0;
/* /*
* Read the number of hardware queues from frontend. * Read the number of hardware queues from frontend.
*/ */
err = xenbus_scanf(XBT_NIL, dev->otherend, "multi-queue-num-queues", requested_num_queues = xenbus_read_unsigned(dev->otherend,
"%u", &requested_num_queues); "multi-queue-num-queues",
if (err < 0) { 1);
requested_num_queues = 1; if (requested_num_queues > xenblk_max_queues
} else { || requested_num_queues == 0) {
if (requested_num_queues > xenblk_max_queues /* Buggy or malicious guest. */
|| requested_num_queues == 0) { xenbus_dev_fatal(dev, err,
/* Buggy or malicious guest. */ "guest requested %u queues, exceeding the maximum of %u.",
xenbus_dev_fatal(dev, err, requested_num_queues, xenblk_max_queues);
"guest requested %u queues, exceeding the maximum of %u.", return -ENOSYS;
requested_num_queues, xenblk_max_queues);
return -ENOSYS;
}
} }
be->blkif->nr_rings = requested_num_queues; be->blkif->nr_rings = requested_num_queues;
if (xen_blkif_alloc_rings(be->blkif)) if (xen_blkif_alloc_rings(be->blkif))
......
...@@ -1758,17 +1758,13 @@ static int talk_to_blkback(struct xenbus_device *dev, ...@@ -1758,17 +1758,13 @@ static int talk_to_blkback(struct xenbus_device *dev,
const char *message = NULL; const char *message = NULL;
struct xenbus_transaction xbt; struct xenbus_transaction xbt;
int err; int err;
unsigned int i, max_page_order = 0; unsigned int i, max_page_order;
unsigned int ring_page_order = 0; unsigned int ring_page_order;
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, max_page_order = xenbus_read_unsigned(info->xbdev->otherend,
"max-ring-page-order", "%u", &max_page_order); "max-ring-page-order", 0);
if (err != 1) ring_page_order = min(xen_blkif_max_ring_order, max_page_order);
info->nr_ring_pages = 1; info->nr_ring_pages = 1 << ring_page_order;
else {
ring_page_order = min(xen_blkif_max_ring_order, max_page_order);
info->nr_ring_pages = 1 << ring_page_order;
}
for (i = 0; i < info->nr_rings; i++) { for (i = 0; i < info->nr_rings; i++) {
struct blkfront_ring_info *rinfo = &info->rinfo[i]; struct blkfront_ring_info *rinfo = &info->rinfo[i];
...@@ -1877,18 +1873,14 @@ static int talk_to_blkback(struct xenbus_device *dev, ...@@ -1877,18 +1873,14 @@ static int talk_to_blkback(struct xenbus_device *dev,
static int negotiate_mq(struct blkfront_info *info) static int negotiate_mq(struct blkfront_info *info)
{ {
unsigned int backend_max_queues = 0; unsigned int backend_max_queues;
int err;
unsigned int i; unsigned int i;
BUG_ON(info->nr_rings); BUG_ON(info->nr_rings);
/* Check if backend supports multiple queues. */ /* Check if backend supports multiple queues. */
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, backend_max_queues = xenbus_read_unsigned(info->xbdev->otherend,
"multi-queue-max-queues", "%u", &backend_max_queues); "multi-queue-max-queues", 1);
if (err < 0)
backend_max_queues = 1;
info->nr_rings = min(backend_max_queues, xen_blkif_max_queues); info->nr_rings = min(backend_max_queues, xen_blkif_max_queues);
/* We need at least one ring. */ /* We need at least one ring. */
if (!info->nr_rings) if (!info->nr_rings)
...@@ -2196,7 +2188,6 @@ static void blkfront_setup_discard(struct blkfront_info *info) ...@@ -2196,7 +2188,6 @@ static void blkfront_setup_discard(struct blkfront_info *info)
int err; int err;
unsigned int discard_granularity; unsigned int discard_granularity;
unsigned int discard_alignment; unsigned int discard_alignment;
unsigned int discard_secure;
info->feature_discard = 1; info->feature_discard = 1;
err = xenbus_gather(XBT_NIL, info->xbdev->otherend, err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
...@@ -2207,10 +2198,9 @@ static void blkfront_setup_discard(struct blkfront_info *info) ...@@ -2207,10 +2198,9 @@ static void blkfront_setup_discard(struct blkfront_info *info)
info->discard_granularity = discard_granularity; info->discard_granularity = discard_granularity;
info->discard_alignment = discard_alignment; info->discard_alignment = discard_alignment;
} }
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, info->feature_secdiscard =
"discard-secure", "%u", &discard_secure); !!xenbus_read_unsigned(info->xbdev->otherend, "discard-secure",
if (err > 0) 0);
info->feature_secdiscard = !!discard_secure;
} }
static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo) static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo)
...@@ -2302,16 +2292,11 @@ static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo) ...@@ -2302,16 +2292,11 @@ static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo)
*/ */
static void blkfront_gather_backend_features(struct blkfront_info *info) static void blkfront_gather_backend_features(struct blkfront_info *info)
{ {
int err;
int barrier, flush, discard, persistent;
unsigned int indirect_segments; unsigned int indirect_segments;
info->feature_flush = 0; info->feature_flush = 0;
info->feature_fua = 0; info->feature_fua = 0;
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
"feature-barrier", "%d", &barrier);
/* /*
* If there's no "feature-barrier" defined, then it means * If there's no "feature-barrier" defined, then it means
* we're dealing with a very old backend which writes * we're dealing with a very old backend which writes
...@@ -2319,7 +2304,7 @@ static void blkfront_gather_backend_features(struct blkfront_info *info) ...@@ -2319,7 +2304,7 @@ static void blkfront_gather_backend_features(struct blkfront_info *info)
* *
* If there are barriers, then we use flush. * If there are barriers, then we use flush.
*/ */
if (err > 0 && barrier) { if (xenbus_read_unsigned(info->xbdev->otherend, "feature-barrier", 0)) {
info->feature_flush = 1; info->feature_flush = 1;
info->feature_fua = 1; info->feature_fua = 1;
} }
...@@ -2328,35 +2313,23 @@ static void blkfront_gather_backend_features(struct blkfront_info *info) ...@@ -2328,35 +2313,23 @@ static void blkfront_gather_backend_features(struct blkfront_info *info)
* And if there is "feature-flush-cache" use that above * And if there is "feature-flush-cache" use that above
* barriers. * barriers.
*/ */
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, if (xenbus_read_unsigned(info->xbdev->otherend, "feature-flush-cache",
"feature-flush-cache", "%d", &flush); 0)) {
if (err > 0 && flush) {
info->feature_flush = 1; info->feature_flush = 1;
info->feature_fua = 0; info->feature_fua = 0;
} }
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, if (xenbus_read_unsigned(info->xbdev->otherend, "feature-discard", 0))
"feature-discard", "%d", &discard);
if (err > 0 && discard)
blkfront_setup_discard(info); blkfront_setup_discard(info);
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, info->feature_persistent =
"feature-persistent", "%d", &persistent); xenbus_read_unsigned(info->xbdev->otherend,
if (err <= 0) "feature-persistent", 0);
info->feature_persistent = 0;
else
info->feature_persistent = persistent;
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, indirect_segments = xenbus_read_unsigned(info->xbdev->otherend,
"feature-max-indirect-segments", "%u", "feature-max-indirect-segments", 0);
&indirect_segments); info->max_indirect_segments = min(indirect_segments,
if (err <= 0) xen_blkif_max_segments);
info->max_indirect_segments = 0;
else
info->max_indirect_segments = min(indirect_segments,
xen_blkif_max_segments);
} }
/* /*
...@@ -2421,11 +2394,9 @@ static void blkfront_connect(struct blkfront_info *info) ...@@ -2421,11 +2394,9 @@ static void blkfront_connect(struct blkfront_info *info)
* provide this. Assume physical sector size to be the same as * provide this. Assume physical sector size to be the same as
* sector_size in that case. * sector_size in that case.
*/ */
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, physical_sector_size = xenbus_read_unsigned(info->xbdev->otherend,
"physical-sector-size", "%u", &physical_sector_size); "physical-sector-size",
if (err != 1) sector_size);
physical_sector_size = sector_size;
blkfront_gather_backend_features(info); blkfront_gather_backend_features(info);
for (i = 0; i < info->nr_rings; i++) { for (i = 0; i < info->nr_rings; i++) {
err = blkfront_setup_indirect(&info->rinfo[i]); err = blkfront_setup_indirect(&info->rinfo[i]);
......
...@@ -337,18 +337,14 @@ static int tpmfront_resume(struct xenbus_device *dev) ...@@ -337,18 +337,14 @@ static int tpmfront_resume(struct xenbus_device *dev)
static void backend_changed(struct xenbus_device *dev, static void backend_changed(struct xenbus_device *dev,
enum xenbus_state backend_state) enum xenbus_state backend_state)
{ {
int val;
switch (backend_state) { switch (backend_state) {
case XenbusStateInitialised: case XenbusStateInitialised:
case XenbusStateConnected: case XenbusStateConnected:
if (dev->state == XenbusStateConnected) if (dev->state == XenbusStateConnected)
break; break;
if (xenbus_scanf(XBT_NIL, dev->otherend, if (!xenbus_read_unsigned(dev->otherend, "feature-protocol-v2",
"feature-protocol-v2", "%d", &val) < 0) 0)) {
val = 0;
if (!val) {
xenbus_dev_fatal(dev, -EINVAL, xenbus_dev_fatal(dev, -EINVAL,
"vTPM protocol 2 required"); "vTPM protocol 2 required");
return; return;
......
...@@ -108,7 +108,8 @@ static irqreturn_t input_handler(int rq, void *dev_id) ...@@ -108,7 +108,8 @@ static irqreturn_t input_handler(int rq, void *dev_id)
static int xenkbd_probe(struct xenbus_device *dev, static int xenkbd_probe(struct xenbus_device *dev,
const struct xenbus_device_id *id) const struct xenbus_device_id *id)
{ {
int ret, i, abs; int ret, i;
unsigned int abs;
struct xenkbd_info *info; struct xenkbd_info *info;
struct input_dev *kbd, *ptr; struct input_dev *kbd, *ptr;
...@@ -127,8 +128,7 @@ static int xenkbd_probe(struct xenbus_device *dev, ...@@ -127,8 +128,7 @@ static int xenkbd_probe(struct xenbus_device *dev,
if (!info->page) if (!info->page)
goto error_nomem; goto error_nomem;
if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-abs-pointer", "%d", &abs) < 0) abs = xenbus_read_unsigned(dev->otherend, "feature-abs-pointer", 0);
abs = 0;
if (abs) { if (abs) {
ret = xenbus_write(XBT_NIL, dev->nodename, ret = xenbus_write(XBT_NIL, dev->nodename,
"request-abs-pointer", "1"); "request-abs-pointer", "1");
...@@ -322,11 +322,8 @@ static void xenkbd_backend_changed(struct xenbus_device *dev, ...@@ -322,11 +322,8 @@ static void xenkbd_backend_changed(struct xenbus_device *dev,
case XenbusStateInitWait: case XenbusStateInitWait:
InitWait: InitWait:
ret = xenbus_scanf(XBT_NIL, info->xbdev->otherend, if (xenbus_read_unsigned(info->xbdev->otherend,
"feature-abs-pointer", "%d", &val); "feature-abs-pointer", 0)) {
if (ret < 0)
val = 0;
if (val) {
ret = xenbus_write(XBT_NIL, info->xbdev->nodename, ret = xenbus_write(XBT_NIL, info->xbdev->nodename,
"request-abs-pointer", "1"); "request-abs-pointer", "1");
if (ret) if (ret)
......
...@@ -785,12 +785,9 @@ static void xen_mcast_ctrl_changed(struct xenbus_watch *watch, ...@@ -785,12 +785,9 @@ static void xen_mcast_ctrl_changed(struct xenbus_watch *watch,
struct xenvif *vif = container_of(watch, struct xenvif, struct xenvif *vif = container_of(watch, struct xenvif,
mcast_ctrl_watch); mcast_ctrl_watch);
struct xenbus_device *dev = xenvif_to_xenbus_device(vif); struct xenbus_device *dev = xenvif_to_xenbus_device(vif);
int val;
if (xenbus_scanf(XBT_NIL, dev->otherend, vif->multicast_control = !!xenbus_read_unsigned(dev->otherend,
"request-multicast-control", "%d", &val) < 0) "request-multicast-control", 0);
val = 0;
vif->multicast_control = !!val;
} }
static int xen_register_mcast_ctrl_watch(struct xenbus_device *dev, static int xen_register_mcast_ctrl_watch(struct xenbus_device *dev,
...@@ -934,14 +931,11 @@ static void connect(struct backend_info *be) ...@@ -934,14 +931,11 @@ static void connect(struct backend_info *be)
/* Check whether the frontend requested multiple queues /* Check whether the frontend requested multiple queues
* and read the number requested. * and read the number requested.
*/ */
err = xenbus_scanf(XBT_NIL, dev->otherend, requested_num_queues = xenbus_read_unsigned(dev->otherend,
"multi-queue-num-queues", "multi-queue-num-queues", 1);
"%u", &requested_num_queues); if (requested_num_queues > xenvif_max_queues) {
if (err < 0) {
requested_num_queues = 1; /* Fall back to single queue */
} else if (requested_num_queues > xenvif_max_queues) {
/* buggy or malicious guest */ /* buggy or malicious guest */
xenbus_dev_fatal(dev, err, xenbus_dev_fatal(dev, -EINVAL,
"guest requested %u queues, exceeding the maximum of %u.", "guest requested %u queues, exceeding the maximum of %u.",
requested_num_queues, xenvif_max_queues); requested_num_queues, xenvif_max_queues);
return; return;
...@@ -1134,7 +1128,7 @@ static int read_xenbus_vif_flags(struct backend_info *be) ...@@ -1134,7 +1128,7 @@ static int read_xenbus_vif_flags(struct backend_info *be)
struct xenvif *vif = be->vif; struct xenvif *vif = be->vif;
struct xenbus_device *dev = be->dev; struct xenbus_device *dev = be->dev;
unsigned int rx_copy; unsigned int rx_copy;
int err, val; int err;
err = xenbus_scanf(XBT_NIL, dev->otherend, "request-rx-copy", "%u", err = xenbus_scanf(XBT_NIL, dev->otherend, "request-rx-copy", "%u",
&rx_copy); &rx_copy);
...@@ -1150,10 +1144,7 @@ static int read_xenbus_vif_flags(struct backend_info *be) ...@@ -1150,10 +1144,7 @@ static int read_xenbus_vif_flags(struct backend_info *be)
if (!rx_copy) if (!rx_copy)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (xenbus_scanf(XBT_NIL, dev->otherend, if (!xenbus_read_unsigned(dev->otherend, "feature-rx-notify", 0)) {
"feature-rx-notify", "%d", &val) < 0)
val = 0;
if (!val) {
/* - Reduce drain timeout to poll more frequently for /* - Reduce drain timeout to poll more frequently for
* Rx requests. * Rx requests.
* - Disable Rx stall detection. * - Disable Rx stall detection.
...@@ -1162,34 +1153,21 @@ static int read_xenbus_vif_flags(struct backend_info *be) ...@@ -1162,34 +1153,21 @@ static int read_xenbus_vif_flags(struct backend_info *be)
be->vif->stall_timeout = 0; be->vif->stall_timeout = 0;
} }
if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-sg", vif->can_sg = !!xenbus_read_unsigned(dev->otherend, "feature-sg", 0);
"%d", &val) < 0)
val = 0;
vif->can_sg = !!val;
vif->gso_mask = 0; vif->gso_mask = 0;
if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-gso-tcpv4", if (xenbus_read_unsigned(dev->otherend, "feature-gso-tcpv4", 0))
"%d", &val) < 0)
val = 0;
if (val)
vif->gso_mask |= GSO_BIT(TCPV4); vif->gso_mask |= GSO_BIT(TCPV4);
if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-gso-tcpv6", if (xenbus_read_unsigned(dev->otherend, "feature-gso-tcpv6", 0))
"%d", &val) < 0)
val = 0;
if (val)
vif->gso_mask |= GSO_BIT(TCPV6); vif->gso_mask |= GSO_BIT(TCPV6);
if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-no-csum-offload", vif->ip_csum = !xenbus_read_unsigned(dev->otherend,
"%d", &val) < 0) "feature-no-csum-offload", 0);
val = 0;
vif->ip_csum = !val;
if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-ipv6-csum-offload", vif->ipv6_csum = !!xenbus_read_unsigned(dev->otherend,
"%d", &val) < 0) "feature-ipv6-csum-offload", 0);
val = 0;
vif->ipv6_csum = !!val;
return 0; return 0;
} }
......
...@@ -1169,43 +1169,23 @@ static netdev_features_t xennet_fix_features(struct net_device *dev, ...@@ -1169,43 +1169,23 @@ static netdev_features_t xennet_fix_features(struct net_device *dev,
netdev_features_t features) netdev_features_t features)
{ {
struct netfront_info *np = netdev_priv(dev); struct netfront_info *np = netdev_priv(dev);
int val;
if (features & NETIF_F_SG) { if (features & NETIF_F_SG &&
if (xenbus_scanf(XBT_NIL, np->xbdev->otherend, "feature-sg", !xenbus_read_unsigned(np->xbdev->otherend, "feature-sg", 0))
"%d", &val) < 0) features &= ~NETIF_F_SG;
val = 0;
if (!val) if (features & NETIF_F_IPV6_CSUM &&
features &= ~NETIF_F_SG; !xenbus_read_unsigned(np->xbdev->otherend,
} "feature-ipv6-csum-offload", 0))
features &= ~NETIF_F_IPV6_CSUM;
if (features & NETIF_F_IPV6_CSUM) {
if (xenbus_scanf(XBT_NIL, np->xbdev->otherend,
"feature-ipv6-csum-offload", "%d", &val) < 0)
val = 0;
if (!val)
features &= ~NETIF_F_IPV6_CSUM;
}
if (features & NETIF_F_TSO) {
if (xenbus_scanf(XBT_NIL, np->xbdev->otherend,
"feature-gso-tcpv4", "%d", &val) < 0)
val = 0;
if (!val) if (features & NETIF_F_TSO &&
features &= ~NETIF_F_TSO; !xenbus_read_unsigned(np->xbdev->otherend, "feature-gso-tcpv4", 0))
} features &= ~NETIF_F_TSO;
if (features & NETIF_F_TSO6) { if (features & NETIF_F_TSO6 &&
if (xenbus_scanf(XBT_NIL, np->xbdev->otherend, !xenbus_read_unsigned(np->xbdev->otherend, "feature-gso-tcpv6", 0))
"feature-gso-tcpv6", "%d", &val) < 0) features &= ~NETIF_F_TSO6;
val = 0;
if (!val)
features &= ~NETIF_F_TSO6;
}
return features; return features;
} }
...@@ -1823,18 +1803,13 @@ static int talk_to_netback(struct xenbus_device *dev, ...@@ -1823,18 +1803,13 @@ static int talk_to_netback(struct xenbus_device *dev,
info->netdev->irq = 0; info->netdev->irq = 0;
/* Check if backend supports multiple queues */ /* Check if backend supports multiple queues */
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, max_queues = xenbus_read_unsigned(info->xbdev->otherend,
"multi-queue-max-queues", "%u", &max_queues); "multi-queue-max-queues", 1);
if (err < 0)
max_queues = 1;
num_queues = min(max_queues, xennet_max_queues); num_queues = min(max_queues, xennet_max_queues);
/* Check feature-split-event-channels */ /* Check feature-split-event-channels */
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, feature_split_evtchn = xenbus_read_unsigned(info->xbdev->otherend,
"feature-split-event-channels", "%u", "feature-split-event-channels", 0);
&feature_split_evtchn);
if (err < 0)
feature_split_evtchn = 0;
/* Read mac addr. */ /* Read mac addr. */
err = xen_net_read_mac(dev, info->netdev->dev_addr); err = xen_net_read_mac(dev, info->netdev->dev_addr);
...@@ -1968,16 +1943,10 @@ static int xennet_connect(struct net_device *dev) ...@@ -1968,16 +1943,10 @@ static int xennet_connect(struct net_device *dev)
struct netfront_info *np = netdev_priv(dev); struct netfront_info *np = netdev_priv(dev);
unsigned int num_queues = 0; unsigned int num_queues = 0;
int err; int err;
unsigned int feature_rx_copy;
unsigned int j = 0; unsigned int j = 0;
struct netfront_queue *queue = NULL; struct netfront_queue *queue = NULL;
err = xenbus_scanf(XBT_NIL, np->xbdev->otherend, if (!xenbus_read_unsigned(np->xbdev->otherend, "feature-rx-copy", 0)) {
"feature-rx-copy", "%u", &feature_rx_copy);
if (err != 1)
feature_rx_copy = 0;
if (!feature_rx_copy) {
dev_info(&dev->dev, dev_info(&dev->dev,
"backend does not support copying receive path\n"); "backend does not support copying receive path\n");
return -ENODEV; return -ENODEV;
......
...@@ -1038,10 +1038,8 @@ static int pcifront_detach_devices(struct pcifront_device *pdev) ...@@ -1038,10 +1038,8 @@ static int pcifront_detach_devices(struct pcifront_device *pdev)
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
} }
err = xenbus_scanf(XBT_NIL, pdev->xdev->otherend, str, "%d", state = xenbus_read_unsigned(pdev->xdev->otherend, str,
&state); XenbusStateUnknown);
if (err != 1)
state = XenbusStateUnknown;
if (state != XenbusStateClosing) if (state != XenbusStateClosing)
continue; continue;
......
This diff is collapsed.
...@@ -633,7 +633,6 @@ static void xenfb_backend_changed(struct xenbus_device *dev, ...@@ -633,7 +633,6 @@ static void xenfb_backend_changed(struct xenbus_device *dev,
enum xenbus_state backend_state) enum xenbus_state backend_state)
{ {
struct xenfb_info *info = dev_get_drvdata(&dev->dev); struct xenfb_info *info = dev_get_drvdata(&dev->dev);
int val;
switch (backend_state) { switch (backend_state) {
case XenbusStateInitialising: case XenbusStateInitialising:
...@@ -657,16 +656,12 @@ static void xenfb_backend_changed(struct xenbus_device *dev, ...@@ -657,16 +656,12 @@ static void xenfb_backend_changed(struct xenbus_device *dev,
if (dev->state != XenbusStateConnected) if (dev->state != XenbusStateConnected)
goto InitWait; /* no InitWait seen yet, fudge it */ goto InitWait; /* no InitWait seen yet, fudge it */
if (xenbus_scanf(XBT_NIL, info->xbdev->otherend, if (xenbus_read_unsigned(info->xbdev->otherend,
"request-update", "%d", &val) < 0) "request-update", 0))
val = 0;
if (val)
info->update_wanted = 1; info->update_wanted = 1;
if (xenbus_scanf(XBT_NIL, dev->otherend, info->feature_resize = xenbus_read_unsigned(dev->otherend,
"feature-resize", "%d", &val) < 0) "feature-resize", 0);
val = 0;
info->feature_resize = val;
break; break;
case XenbusStateClosed: case XenbusStateClosed:
......
...@@ -180,7 +180,6 @@ static void __balloon_append(struct page *page) ...@@ -180,7 +180,6 @@ static void __balloon_append(struct page *page)
static void balloon_append(struct page *page) static void balloon_append(struct page *page)
{ {
__balloon_append(page); __balloon_append(page);
adjust_managed_page_count(page, -1);
} }
/* balloon_retrieve: rescue a page from the balloon, if it is not empty. */ /* balloon_retrieve: rescue a page from the balloon, if it is not empty. */
...@@ -201,8 +200,6 @@ static struct page *balloon_retrieve(bool require_lowmem) ...@@ -201,8 +200,6 @@ static struct page *balloon_retrieve(bool require_lowmem)
else else
balloon_stats.balloon_low--; balloon_stats.balloon_low--;
adjust_managed_page_count(page, 1);
return page; return page;
} }
...@@ -478,7 +475,7 @@ static enum bp_state increase_reservation(unsigned long nr_pages) ...@@ -478,7 +475,7 @@ static enum bp_state increase_reservation(unsigned long nr_pages)
#endif #endif
/* Relinquish the page back to the allocator. */ /* Relinquish the page back to the allocator. */
__free_reserved_page(page); free_reserved_page(page);
} }
balloon_stats.current_pages += rc; balloon_stats.current_pages += rc;
...@@ -509,6 +506,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp) ...@@ -509,6 +506,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
state = BP_EAGAIN; state = BP_EAGAIN;
break; break;
} }
adjust_managed_page_count(page, -1);
scrub_page(page); scrub_page(page);
list_add(&page->lru, &pages); list_add(&page->lru, &pages);
} }
......
...@@ -947,7 +947,7 @@ static int find_virq(unsigned int virq, unsigned int cpu) ...@@ -947,7 +947,7 @@ static int find_virq(unsigned int virq, unsigned int cpu)
continue; continue;
if (status.status != EVTCHNSTAT_virq) if (status.status != EVTCHNSTAT_virq)
continue; continue;
if (status.u.virq == virq && status.vcpu == cpu) { if (status.u.virq == virq && status.vcpu == xen_vcpu_nr(cpu)) {
rc = port; rc = port;
break; break;
} }
......
...@@ -127,18 +127,21 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op, ...@@ -127,18 +127,21 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
struct gntalloc_gref *gref, *next; struct gntalloc_gref *gref, *next;
readonly = !(op->flags & GNTALLOC_FLAG_WRITABLE); readonly = !(op->flags & GNTALLOC_FLAG_WRITABLE);
rc = -ENOMEM;
for (i = 0; i < op->count; i++) { for (i = 0; i < op->count; i++) {
gref = kzalloc(sizeof(*gref), GFP_KERNEL); gref = kzalloc(sizeof(*gref), GFP_KERNEL);
if (!gref) if (!gref) {
rc = -ENOMEM;
goto undo; goto undo;
}
list_add_tail(&gref->next_gref, &queue_gref); list_add_tail(&gref->next_gref, &queue_gref);
list_add_tail(&gref->next_file, &queue_file); list_add_tail(&gref->next_file, &queue_file);
gref->users = 1; gref->users = 1;
gref->file_index = op->index + i * PAGE_SIZE; gref->file_index = op->index + i * PAGE_SIZE;
gref->page = alloc_page(GFP_KERNEL|__GFP_ZERO); gref->page = alloc_page(GFP_KERNEL|__GFP_ZERO);
if (!gref->page) if (!gref->page) {
rc = -ENOMEM;
goto undo; goto undo;
}
/* Grant foreign access to the page. */ /* Grant foreign access to the page. */
rc = gnttab_grant_foreign_access(op->domid, rc = gnttab_grant_foreign_access(op->domid,
......
...@@ -1007,7 +1007,7 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) ...@@ -1007,7 +1007,7 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma)
vma->vm_ops = &gntdev_vmops; vma->vm_ops = &gntdev_vmops;
vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP | VM_IO; vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP | VM_MIXEDMAP;
if (use_ptemod) if (use_ptemod)
vma->vm_flags |= VM_DONTCOPY; vma->vm_flags |= VM_DONTCOPY;
......
...@@ -125,8 +125,4 @@ static struct pci_driver platform_driver = { ...@@ -125,8 +125,4 @@ static struct pci_driver platform_driver = {
.id_table = platform_pci_tbl, .id_table = platform_pci_tbl,
}; };
static int __init platform_pci_init(void) builtin_pci_driver(platform_driver);
{
return pci_register_driver(&platform_driver);
}
device_initcall(platform_pci_init);
...@@ -362,7 +362,7 @@ static int xen_pcibk_reconfigure(struct xen_pcibk_device *pdev) ...@@ -362,7 +362,7 @@ static int xen_pcibk_reconfigure(struct xen_pcibk_device *pdev)
int err = 0; int err = 0;
int num_devs; int num_devs;
int domain, bus, slot, func; int domain, bus, slot, func;
int substate; unsigned int substate;
int i, len; int i, len;
char state_str[64]; char state_str[64];
char dev_str[64]; char dev_str[64];
...@@ -395,10 +395,8 @@ static int xen_pcibk_reconfigure(struct xen_pcibk_device *pdev) ...@@ -395,10 +395,8 @@ static int xen_pcibk_reconfigure(struct xen_pcibk_device *pdev)
"configuration"); "configuration");
goto out; goto out;
} }
err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, state_str, substate = xenbus_read_unsigned(pdev->xdev->nodename, state_str,
"%d", &substate); XenbusStateUnknown);
if (err != 1)
substate = XenbusStateUnknown;
switch (substate) { switch (substate) {
case XenbusStateInitialising: case XenbusStateInitialising:
......
...@@ -538,6 +538,8 @@ static int xenbus_file_open(struct inode *inode, struct file *filp) ...@@ -538,6 +538,8 @@ static int xenbus_file_open(struct inode *inode, struct file *filp)
nonseekable_open(inode, filp); nonseekable_open(inode, filp);
filp->f_mode &= ~FMODE_ATOMIC_POS; /* cdev-style semantics */
u = kzalloc(sizeof(*u), GFP_KERNEL); u = kzalloc(sizeof(*u), GFP_KERNEL);
if (u == NULL) if (u == NULL)
return -ENOMEM; return -ENOMEM;
......
...@@ -702,7 +702,7 @@ device_initcall(xenbus_probe_initcall); ...@@ -702,7 +702,7 @@ device_initcall(xenbus_probe_initcall);
*/ */
static int __init xenstored_local_init(void) static int __init xenstored_local_init(void)
{ {
int err = 0; int err = -ENOMEM;
unsigned long page = 0; unsigned long page = 0;
struct evtchn_alloc_unbound alloc_unbound; struct evtchn_alloc_unbound alloc_unbound;
...@@ -826,7 +826,7 @@ static int __init xenbus_init(void) ...@@ -826,7 +826,7 @@ static int __init xenbus_init(void)
* Create xenfs mountpoint in /proc for compatibility with * Create xenfs mountpoint in /proc for compatibility with
* utilities that expect to find "xenbus" under "/proc/xen". * utilities that expect to find "xenbus" under "/proc/xen".
*/ */
proc_mkdir("xen", NULL); proc_create_mount_point("xen");
#endif #endif
out_error: out_error:
......
...@@ -224,13 +224,7 @@ static int read_frontend_details(struct xenbus_device *xendev) ...@@ -224,13 +224,7 @@ static int read_frontend_details(struct xenbus_device *xendev)
int xenbus_dev_is_online(struct xenbus_device *dev) int xenbus_dev_is_online(struct xenbus_device *dev)
{ {
int rc, val; return !!xenbus_read_unsigned(dev->nodename, "online", 0);
rc = xenbus_scanf(XBT_NIL, dev->nodename, "online", "%d", &val);
if (rc != 1)
val = 0; /* no online node present */
return val;
} }
EXPORT_SYMBOL_GPL(xenbus_dev_is_online); EXPORT_SYMBOL_GPL(xenbus_dev_is_online);
......
...@@ -559,6 +559,21 @@ int xenbus_scanf(struct xenbus_transaction t, ...@@ -559,6 +559,21 @@ int xenbus_scanf(struct xenbus_transaction t,
} }
EXPORT_SYMBOL_GPL(xenbus_scanf); EXPORT_SYMBOL_GPL(xenbus_scanf);
/* Read an (optional) unsigned value. */
unsigned int xenbus_read_unsigned(const char *dir, const char *node,
unsigned int default_val)
{
unsigned int val;
int ret;
ret = xenbus_scanf(XBT_NIL, dir, node, "%u", &val);
if (ret <= 0)
val = default_val;
return val;
}
EXPORT_SYMBOL_GPL(xenbus_read_unsigned);
/* Single printf and write: returns -errno or 0. */ /* Single printf and write: returns -errno or 0. */
int xenbus_printf(struct xenbus_transaction t, int xenbus_printf(struct xenbus_transaction t,
const char *dir, const char *node, const char *fmt, ...) const char *dir, const char *node, const char *fmt, ...)
...@@ -672,7 +687,7 @@ static bool xen_strict_xenbus_quirk(void) ...@@ -672,7 +687,7 @@ static bool xen_strict_xenbus_quirk(void)
} }
static void xs_reset_watches(void) static void xs_reset_watches(void)
{ {
int err, supported = 0; int err;
if (!xen_hvm_domain() || xen_initial_domain()) if (!xen_hvm_domain() || xen_initial_domain())
return; return;
...@@ -680,9 +695,8 @@ static void xs_reset_watches(void) ...@@ -680,9 +695,8 @@ static void xs_reset_watches(void)
if (xen_strict_xenbus_quirk()) if (xen_strict_xenbus_quirk())
return; return;
err = xenbus_scanf(XBT_NIL, "control", if (!xenbus_read_unsigned("control",
"platform-feature-xs_reset_watches", "%d", &supported); "platform-feature-xs_reset_watches", 0))
if (err != 1 || !supported)
return; return;
err = xs_error(xs_single(XBT_NIL, XS_RESET_WATCHES, "", NULL)); err = xs_error(xs_single(XBT_NIL, XS_RESET_WATCHES, "", NULL));
......
...@@ -479,6 +479,7 @@ struct proc_dir_entry *proc_create_mount_point(const char *name) ...@@ -479,6 +479,7 @@ struct proc_dir_entry *proc_create_mount_point(const char *name)
} }
return ent; return ent;
} }
EXPORT_SYMBOL(proc_create_mount_point);
struct proc_dir_entry *proc_create_data(const char *name, umode_t mode, struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
struct proc_dir_entry *parent, struct proc_dir_entry *parent,
......
...@@ -195,7 +195,6 @@ static inline bool is_empty_pde(const struct proc_dir_entry *pde) ...@@ -195,7 +195,6 @@ static inline bool is_empty_pde(const struct proc_dir_entry *pde)
{ {
return S_ISDIR(pde->mode) && !pde->proc_iops; return S_ISDIR(pde->mode) && !pde->proc_iops;
} }
struct proc_dir_entry *proc_create_mount_point(const char *name);
/* /*
* inode.c * inode.c
......
...@@ -21,6 +21,7 @@ extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t, ...@@ -21,6 +21,7 @@ extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
struct proc_dir_entry *, void *); struct proc_dir_entry *, void *);
extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t, extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
struct proc_dir_entry *); struct proc_dir_entry *);
struct proc_dir_entry *proc_create_mount_point(const char *name);
extern struct proc_dir_entry *proc_create_data(const char *, umode_t, extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
struct proc_dir_entry *, struct proc_dir_entry *,
...@@ -56,6 +57,7 @@ static inline struct proc_dir_entry *proc_symlink(const char *name, ...@@ -56,6 +57,7 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
struct proc_dir_entry *parent,const char *dest) { return NULL;} struct proc_dir_entry *parent,const char *dest) { return NULL;}
static inline struct proc_dir_entry *proc_mkdir(const char *name, static inline struct proc_dir_entry *proc_mkdir(const char *name,
struct proc_dir_entry *parent) {return NULL;} struct proc_dir_entry *parent) {return NULL;}
static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
static inline struct proc_dir_entry *proc_mkdir_data(const char *name, static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; } umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
static inline struct proc_dir_entry *proc_mkdir_mode(const char *name, static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
......
/******************************************************************************
* hypercall.h
*
* Linux-specific hypervisor handling.
*
* Stefano Stabellini <stefano.stabellini@eu.citrix.com>, Citrix, 2012
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation; or, when distributed
* separately from the Linux kernel or incorporated into other
* software packages, subject to the following license:
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this source file (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.
*/
#ifndef _ASM_ARM_XEN_HYPERCALL_H
#define _ASM_ARM_XEN_HYPERCALL_H
#include <linux/bug.h>
#include <xen/interface/xen.h>
#include <xen/interface/sched.h>
#include <xen/interface/platform.h>
long privcmd_call(unsigned call, unsigned long a1,
unsigned long a2, unsigned long a3,
unsigned long a4, unsigned long a5);
int HYPERVISOR_xen_version(int cmd, void *arg);
int HYPERVISOR_console_io(int cmd, int count, char *str);
int HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count);
int HYPERVISOR_sched_op(int cmd, void *arg);
int HYPERVISOR_event_channel_op(int cmd, void *arg);
unsigned long HYPERVISOR_hvm_op(int op, void *arg);
int HYPERVISOR_memory_op(unsigned int cmd, void *arg);
int HYPERVISOR_physdev_op(int cmd, void *arg);
int HYPERVISOR_vcpu_op(int cmd, int vcpuid, void *extra_args);
int HYPERVISOR_tmem_op(void *arg);
int HYPERVISOR_vm_assist(unsigned int cmd, unsigned int type);
int HYPERVISOR_platform_op_raw(void *arg);
static inline int HYPERVISOR_platform_op(struct xen_platform_op *op)
{
op->interface_version = XENPF_INTERFACE_VERSION;
return HYPERVISOR_platform_op_raw(op);
}
int HYPERVISOR_multicall(struct multicall_entry *calls, uint32_t nr);
static inline int
HYPERVISOR_suspend(unsigned long start_info_mfn)
{
struct sched_shutdown r = { .reason = SHUTDOWN_suspend };
/* start_info_mfn is unused on ARM */
return HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
}
static inline void
MULTI_update_va_mapping(struct multicall_entry *mcl, unsigned long va,
unsigned int new_val, unsigned long flags)
{
BUG();
}
static inline void
MULTI_mmu_update(struct multicall_entry *mcl, struct mmu_update *req,
int count, int *success_count, domid_t domid)
{
BUG();
}
#endif /* _ASM_ARM_XEN_HYPERCALL_H */
#ifndef _ASM_ARM_XEN_HYPERVISOR_H
#define _ASM_ARM_XEN_HYPERVISOR_H
#include <linux/init.h>
extern struct shared_info *HYPERVISOR_shared_info;
extern struct start_info *xen_start_info;
/* Lazy mode for batching updates / context switch */
enum paravirt_lazy_mode {
PARAVIRT_LAZY_NONE,
PARAVIRT_LAZY_MMU,
PARAVIRT_LAZY_CPU,
};
static inline enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
{
return PARAVIRT_LAZY_NONE;
}
extern struct dma_map_ops *xen_dma_ops;
#ifdef CONFIG_XEN
void __init xen_early_init(void);
#else
static inline void xen_early_init(void) { return; }
#endif
#ifdef CONFIG_HOTPLUG_CPU
static inline void xen_arch_register_cpu(int num)
{
}
static inline void xen_arch_unregister_cpu(int num)
{
}
#endif
#endif /* _ASM_ARM_XEN_HYPERVISOR_H */
/******************************************************************************
* Guest OS interface to ARM Xen.
*
* Stefano Stabellini <stefano.stabellini@eu.citrix.com>, Citrix, 2012
*/
#ifndef _ASM_ARM_XEN_INTERFACE_H
#define _ASM_ARM_XEN_INTERFACE_H
#include <linux/types.h>
#define uint64_aligned_t uint64_t __attribute__((aligned(8)))
#define __DEFINE_GUEST_HANDLE(name, type) \
typedef struct { union { type *p; uint64_aligned_t q; }; } \
__guest_handle_ ## name
#define DEFINE_GUEST_HANDLE_STRUCT(name) \
__DEFINE_GUEST_HANDLE(name, struct name)
#define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name)
#define GUEST_HANDLE(name) __guest_handle_ ## name
#define set_xen_guest_handle(hnd, val) \
do { \
if (sizeof(hnd) == 8) \
*(uint64_t *)&(hnd) = 0; \
(hnd).p = val; \
} while (0)
#define __HYPERVISOR_platform_op_raw __HYPERVISOR_platform_op
#ifndef __ASSEMBLY__
/* Explicitly size integers that represent pfns in the interface with
* Xen so that we can have one ABI that works for 32 and 64 bit guests.
* Note that this means that the xen_pfn_t type may be capable of
* representing pfn's which the guest cannot represent in its own pfn
* type. However since pfn space is controlled by the guest this is
* fine since it simply wouldn't be able to create any sure pfns in
* the first place.
*/
typedef uint64_t xen_pfn_t;
#define PRI_xen_pfn "llx"
typedef uint64_t xen_ulong_t;
#define PRI_xen_ulong "llx"
typedef int64_t xen_long_t;
#define PRI_xen_long "llx"
/* Guest handles for primitive C types. */
__DEFINE_GUEST_HANDLE(uchar, unsigned char);
__DEFINE_GUEST_HANDLE(uint, unsigned int);
DEFINE_GUEST_HANDLE(char);
DEFINE_GUEST_HANDLE(int);
DEFINE_GUEST_HANDLE(void);
DEFINE_GUEST_HANDLE(uint64_t);
DEFINE_GUEST_HANDLE(uint32_t);
DEFINE_GUEST_HANDLE(xen_pfn_t);
DEFINE_GUEST_HANDLE(xen_ulong_t);
/* Maximum number of virtual CPUs in multi-processor guests. */
#define MAX_VIRT_CPUS 1
struct arch_vcpu_info { };
struct arch_shared_info { };
/* TODO: Move pvclock definitions some place arch independent */
struct pvclock_vcpu_time_info {
u32 version;
u32 pad0;
u64 tsc_timestamp;
u64 system_time;
u32 tsc_to_system_mul;
s8 tsc_shift;
u8 flags;
u8 pad[2];
} __attribute__((__packed__)); /* 32 bytes */
/* It is OK to have a 12 bytes struct with no padding because it is packed */
struct pvclock_wall_clock {
u32 version;
u32 sec;
u32 nsec;
u32 sec_hi;
} __attribute__((__packed__));
#endif
#endif /* _ASM_ARM_XEN_INTERFACE_H */
#ifndef _ASM_ARM_XEN_PAGE_COHERENT_H
#define _ASM_ARM_XEN_PAGE_COHERENT_H
#include <asm/page.h>
#include <linux/dma-mapping.h>
void __xen_dma_map_page(struct device *hwdev, struct page *page,
dma_addr_t dev_addr, unsigned long offset, size_t size,
enum dma_data_direction dir, unsigned long attrs);
void __xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle,
size_t size, enum dma_data_direction dir,
unsigned long attrs);
void __xen_dma_sync_single_for_cpu(struct device *hwdev,
dma_addr_t handle, size_t size, enum dma_data_direction dir);
void __xen_dma_sync_single_for_device(struct device *hwdev,
dma_addr_t handle, size_t size, enum dma_data_direction dir);
static inline void *xen_alloc_coherent_pages(struct device *hwdev, size_t size,
dma_addr_t *dma_handle, gfp_t flags, unsigned long attrs)
{
return __generic_dma_ops(hwdev)->alloc(hwdev, size, dma_handle, flags, attrs);
}
static inline void xen_free_coherent_pages(struct device *hwdev, size_t size,
void *cpu_addr, dma_addr_t dma_handle, unsigned long attrs)
{
__generic_dma_ops(hwdev)->free(hwdev, size, cpu_addr, dma_handle, attrs);
}
static inline void xen_dma_map_page(struct device *hwdev, struct page *page,
dma_addr_t dev_addr, unsigned long offset, size_t size,
enum dma_data_direction dir, unsigned long attrs)
{
unsigned long page_pfn = page_to_xen_pfn(page);
unsigned long dev_pfn = XEN_PFN_DOWN(dev_addr);
unsigned long compound_pages =
(1<<compound_order(page)) * XEN_PFN_PER_PAGE;
bool local = (page_pfn <= dev_pfn) &&
(dev_pfn - page_pfn < compound_pages);
/*
* Dom0 is mapped 1:1, while the Linux page can span across
* multiple Xen pages, it's not possible for it to contain a
* mix of local and foreign Xen pages. So if the first xen_pfn
* == mfn the page is local otherwise it's a foreign page
* grant-mapped in dom0. If the page is local we can safely
* call the native dma_ops function, otherwise we call the xen
* specific function.
*/
if (local)
__generic_dma_ops(hwdev)->map_page(hwdev, page, offset, size, dir, attrs);
else
__xen_dma_map_page(hwdev, page, dev_addr, offset, size, dir, attrs);
}
static inline void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle,
size_t size, enum dma_data_direction dir, unsigned long attrs)
{
unsigned long pfn = PFN_DOWN(handle);
/*
* Dom0 is mapped 1:1, while the Linux page can be spanned accross
* multiple Xen page, it's not possible to have a mix of local and
* foreign Xen page. Dom0 is mapped 1:1, so calling pfn_valid on a
* foreign mfn will always return false. If the page is local we can
* safely call the native dma_ops function, otherwise we call the xen
* specific function.
*/
if (pfn_valid(pfn)) {
if (__generic_dma_ops(hwdev)->unmap_page)
__generic_dma_ops(hwdev)->unmap_page(hwdev, handle, size, dir, attrs);
} else
__xen_dma_unmap_page(hwdev, handle, size, dir, attrs);
}
static inline void xen_dma_sync_single_for_cpu(struct device *hwdev,
dma_addr_t handle, size_t size, enum dma_data_direction dir)
{
unsigned long pfn = PFN_DOWN(handle);
if (pfn_valid(pfn)) {
if (__generic_dma_ops(hwdev)->sync_single_for_cpu)
__generic_dma_ops(hwdev)->sync_single_for_cpu(hwdev, handle, size, dir);
} else
__xen_dma_sync_single_for_cpu(hwdev, handle, size, dir);
}
static inline void xen_dma_sync_single_for_device(struct device *hwdev,
dma_addr_t handle, size_t size, enum dma_data_direction dir)
{
unsigned long pfn = PFN_DOWN(handle);
if (pfn_valid(pfn)) {
if (__generic_dma_ops(hwdev)->sync_single_for_device)
__generic_dma_ops(hwdev)->sync_single_for_device(hwdev, handle, size, dir);
} else
__xen_dma_sync_single_for_device(hwdev, handle, size, dir);
}
#endif /* _ASM_ARM_XEN_PAGE_COHERENT_H */
#ifndef _ASM_ARM_XEN_PAGE_H
#define _ASM_ARM_XEN_PAGE_H
#include <asm/page.h>
#include <asm/pgtable.h>
#include <linux/pfn.h>
#include <linux/types.h>
#include <linux/dma-mapping.h>
#include <xen/xen.h>
#include <xen/interface/grant_table.h>
#define phys_to_machine_mapping_valid(pfn) (1)
/* Xen machine address */
typedef struct xmaddr {
phys_addr_t maddr;
} xmaddr_t;
/* Xen pseudo-physical address */
typedef struct xpaddr {
phys_addr_t paddr;
} xpaddr_t;
#define XMADDR(x) ((xmaddr_t) { .maddr = (x) })
#define XPADDR(x) ((xpaddr_t) { .paddr = (x) })
#define INVALID_P2M_ENTRY (~0UL)
/*
* The pseudo-physical frame (pfn) used in all the helpers is always based
* on Xen page granularity (i.e 4KB).
*
* A Linux page may be split across multiple non-contiguous Xen page so we
* have to keep track with frame based on 4KB page granularity.
*
* PV drivers should never make a direct usage of those helpers (particularly
* pfn_to_gfn and gfn_to_pfn).
*/
unsigned long __pfn_to_mfn(unsigned long pfn);
extern struct rb_root phys_to_mach;
/* Pseudo-physical <-> Guest conversion */
static inline unsigned long pfn_to_gfn(unsigned long pfn)
{
return pfn;
}
static inline unsigned long gfn_to_pfn(unsigned long gfn)
{
return gfn;
}
/* Pseudo-physical <-> BUS conversion */
static inline unsigned long pfn_to_bfn(unsigned long pfn)
{
unsigned long mfn;
if (phys_to_mach.rb_node != NULL) {
mfn = __pfn_to_mfn(pfn);
if (mfn != INVALID_P2M_ENTRY)
return mfn;
}
return pfn;
}
static inline unsigned long bfn_to_pfn(unsigned long bfn)
{
return bfn;
}
#define bfn_to_local_pfn(bfn) bfn_to_pfn(bfn)
/* VIRT <-> GUEST conversion */
#define virt_to_gfn(v) (pfn_to_gfn(virt_to_phys(v) >> XEN_PAGE_SHIFT))
#define gfn_to_virt(m) (__va(gfn_to_pfn(m) << XEN_PAGE_SHIFT))
/* Only used in PV code. But ARM guests are always HVM. */
static inline xmaddr_t arbitrary_virt_to_machine(void *vaddr)
{
BUG();
}
/* TODO: this shouldn't be here but it is because the frontend drivers
* are using it (its rolled in headers) even though we won't hit the code path.
* So for right now just punt with this.
*/
static inline pte_t *lookup_address(unsigned long address, unsigned int *level)
{
BUG();
return NULL;
}
extern int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
struct gnttab_map_grant_ref *kmap_ops,
struct page **pages, unsigned int count);
extern int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
struct gnttab_unmap_grant_ref *kunmap_ops,
struct page **pages, unsigned int count);
bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn);
bool __set_phys_to_machine_multi(unsigned long pfn, unsigned long mfn,
unsigned long nr_pages);
static inline bool set_phys_to_machine(unsigned long pfn, unsigned long mfn)
{
return __set_phys_to_machine(pfn, mfn);
}
#define xen_remap(cookie, size) ioremap_cache((cookie), (size))
#define xen_unmap(cookie) iounmap((cookie))
bool xen_arch_need_swiotlb(struct device *dev,
phys_addr_t phys,
dma_addr_t dev_addr);
unsigned long xen_get_swiotlb_free_pages(unsigned int order);
#endif /* _ASM_ARM_XEN_PAGE_H */
...@@ -151,6 +151,10 @@ __scanf(4, 5) ...@@ -151,6 +151,10 @@ __scanf(4, 5)
int xenbus_scanf(struct xenbus_transaction t, int xenbus_scanf(struct xenbus_transaction t,
const char *dir, const char *node, const char *fmt, ...); const char *dir, const char *node, const char *fmt, ...);
/* Read an (optional) unsigned value. */
unsigned int xenbus_read_unsigned(const char *dir, const char *node,
unsigned int default_val);
/* Single printf and write: returns -errno or 0. */ /* Single printf and write: returns -errno or 0. */
__printf(4, 5) __printf(4, 5)
int xenbus_printf(struct xenbus_transaction t, int xenbus_printf(struct xenbus_transaction t,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment