/******************************************************************************1* grant_table.c2* x86 specific part3*4* Granting foreign access to our memory reservation.5*6* Copyright (c) 2005-2006, Christopher Clark7* Copyright (c) 2004-2005, K A Fraser8* Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>9* VA Linux Systems Japan. Split out x86 specific part.10*11* This program is free software; you can redistribute it and/or12* modify it under the terms of the GNU General Public License version 213* as published by the Free Software Foundation; or, when distributed14* separately from the Linux kernel or incorporated into other15* software packages, subject to the following license:16*17* Permission is hereby granted, free of charge, to any person obtaining a copy18* of this source file (the "Software"), to deal in the Software without19* restriction, including without limitation the rights to use, copy, modify,20* merge, publish, distribute, sublicense, and/or sell copies of the Software,21* and to permit persons to whom the Software is furnished to do so, subject to22* the following conditions:23*24* The above copyright notice and this permission notice shall be included in25* all copies or substantial portions of the Software.26*27* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR28* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,29* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE30* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER31* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING32* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS33* IN THE SOFTWARE.34*/3536#include <linux/sched.h>37#include <linux/mm.h>38#include <linux/vmalloc.h>3940#include <xen/interface/xen.h>41#include <xen/page.h>42#include <xen/grant_table.h>4344#include <asm/pgtable.h>4546static int map_pte_fn(pte_t *pte, struct page *pmd_page,47unsigned long addr, void *data)48{49unsigned long **frames = (unsigned long **)data;5051set_pte_at(&init_mm, addr, pte, mfn_pte((*frames)[0], PAGE_KERNEL));52(*frames)++;53return 0;54}5556static int unmap_pte_fn(pte_t *pte, struct page *pmd_page,57unsigned long addr, void *data)58{5960set_pte_at(&init_mm, addr, pte, __pte(0));61return 0;62}6364int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes,65unsigned long max_nr_gframes,66struct grant_entry **__shared)67{68int rc;69struct grant_entry *shared = *__shared;7071if (shared == NULL) {72struct vm_struct *area =73xen_alloc_vm_area(PAGE_SIZE * max_nr_gframes);74BUG_ON(area == NULL);75shared = area->addr;76*__shared = shared;77}7879rc = apply_to_page_range(&init_mm, (unsigned long)shared,80PAGE_SIZE * nr_gframes,81map_pte_fn, &frames);82return rc;83}8485void arch_gnttab_unmap_shared(struct grant_entry *shared,86unsigned long nr_gframes)87{88apply_to_page_range(&init_mm, (unsigned long)shared,89PAGE_SIZE * nr_gframes, unmap_pte_fn, NULL);90}919293