diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2009-03-02 10:50:59 +0000 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2009-03-02 10:50:59 +0000 |
commit | 6976b9a7c20dce349dccfb0eec658af5fa9af3c5 (patch) | |
tree | dbb16b8d0a9c693f4e6744bf95a75c3ad87df46c /extras/mini-os/arch/x86/ioremap.c | |
parent | 8e3feb5145bbde1f01d001ce9574f67de87173f7 (diff) | |
download | xen-6976b9a7c20dce349dccfb0eec658af5fa9af3c5.tar.gz xen-6976b9a7c20dce349dccfb0eec658af5fa9af3c5.tar.bz2 xen-6976b9a7c20dce349dccfb0eec658af5fa9af3c5.zip |
minios: add ioremap/iounmap
Add ioremap and iounmap functions to minios. Also move some unmapping
code from and clean up mem_test.
Signed-off-by: Rolf Neugebauer <rolf.neugebauer@netronome.com>
Acked-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Diffstat (limited to 'extras/mini-os/arch/x86/ioremap.c')
-rw-r--r-- | extras/mini-os/arch/x86/ioremap.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/extras/mini-os/arch/x86/ioremap.c b/extras/mini-os/arch/x86/ioremap.c new file mode 100644 index 0000000000..d94f4e72a7 --- /dev/null +++ b/extras/mini-os/arch/x86/ioremap.c @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2009, Netronome Systems, Inc. + * + * 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. + */ + + +#include <types.h> +#include <lib.h> +#include <xmalloc.h> +#include <mm.h> +#include <ioremap.h> + +/* Map a physical address range into virtual address space with provided + * flags. Return a virtual address range it is mapped to. */ +static void *__do_ioremap(unsigned long phys_addr, unsigned long size, + unsigned long prot) +{ + unsigned long va; + unsigned long mfns, mfn; + unsigned long num_pages, offset; + int i; + + /* allow non page aligned addresses but for mapping we need to align them */ + offset = (phys_addr & ~PAGE_MASK); + num_pages = (offset + size + PAGE_SIZE - 1) / PAGE_SIZE; + phys_addr &= PAGE_MASK; + mfns = mfn = phys_addr >> PAGE_SHIFT; + + /* sanity checks on list of MFNs */ + for ( i = 0; i < num_pages; i++, mfn++ ) + { + if ( mfn_is_ram(mfn) ) + { + printk("ioremap: mfn 0x%ulx is RAM\n", mfn); + goto mfn_invalid; + } + } + va = (unsigned long)map_frames_ex(&mfns, num_pages, 0, 1, 1, + DOMID_IO, 0, prot); + return (void *)(va + offset); + +mfn_invalid: + return NULL; +} + +void *ioremap(unsigned long phys_addr, unsigned long size) +{ + return __do_ioremap(phys_addr, size, IO_PROT); +} + +void *ioremap_nocache(unsigned long phys_addr, unsigned long size) +{ + return __do_ioremap(phys_addr, size, IO_PROT_NOCACHE); +} + +/* Un-map the io-remapped region. Currently no list of existing mappings is + * maintained, so the caller has to supply the size */ +void iounmap(void *virt_addr, unsigned long size) +{ + unsigned long num_pages; + unsigned long va = (unsigned long)virt_addr; + + /* work out number of frames to unmap */ + num_pages = ((va & ~PAGE_MASK) + size + PAGE_SIZE - 1) / PAGE_SIZE; + + unmap_frames(va & PAGE_MASK, num_pages); +} + + + +/* -*- Mode:C; c-basic-offset:4; tab-width:4 indent-tabs-mode:nil -*- */ |