2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
14 * TILE-Gx IORPC support for kernel I/O drivers.
17 #include <linux/mmzone.h>
18 #include <linux/module.h>
20 #include <gxio/iorpc_globals.h>
21 #include <gxio/kiorpc.h>
24 #define TRACE(FMT, ...) pr_info(SIMPLE_MSG_LINE FMT, ## __VA_ARGS__)
29 /* Create kernel-VA-space MMIO mapping for an on-chip IO device. */
30 void __iomem
*iorpc_ioremap(int hv_fd
, resource_size_t offset
,
33 pgprot_t mmio_base
, prot
= { 0 };
37 /* Look up the shim's lotar and base PA. */
38 err
= __iorpc_get_mmio_base(hv_fd
, &mmio_base
);
40 TRACE("get_mmio_base() failure: %d\n", err
);
44 /* Make sure the HV driver approves of our offset and size. */
45 err
= __iorpc_check_mmio_offset(hv_fd
, offset
, size
);
47 TRACE("check_mmio_offset() failure: %d\n", err
);
52 * mmio_base contains a base pfn and homing coordinates. Turn
53 * it into an MMIO pgprot and offset pfn.
55 prot
= hv_pte_set_lotar(prot
, hv_pte_get_lotar(mmio_base
));
56 pfn
= pte_pfn(mmio_base
) + PFN_DOWN(offset
);
58 return ioremap_prot(PFN_PHYS(pfn
), size
, prot
);
61 EXPORT_SYMBOL(iorpc_ioremap
);