gpu/drm, x86, PAT: PAT support for io_mapping_*
Make io_mapping_create_wc and io_mapping_free go through PAT to make sure that there are no memory type aliases. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com> Cc: Dave Airlie <airlied@redhat.com> Cc: Jesse Barnes <jbarnes@virtuousgeek.org> Cc: Eric Anholt <eric@anholt.net> Cc: Keith Packard <keithp@keithp.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
parent
7880f74645
commit
17581ad812
3 changed files with 48 additions and 5 deletions
|
@ -24,7 +24,10 @@
|
||||||
#include <asm/tlbflush.h>
|
#include <asm/tlbflush.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
is_io_mapping_possible(resource_size_t base, unsigned long size);
|
reserve_io_memtype_wc(u64 base, unsigned long size, pgprot_t *prot);
|
||||||
|
|
||||||
|
void
|
||||||
|
free_io_memtype(u64 base, unsigned long size);
|
||||||
|
|
||||||
void *
|
void *
|
||||||
iomap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot);
|
iomap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot);
|
||||||
|
|
|
@ -21,13 +21,13 @@
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
|
|
||||||
#ifdef CONFIG_X86_PAE
|
#ifdef CONFIG_X86_PAE
|
||||||
int
|
static int
|
||||||
is_io_mapping_possible(resource_size_t base, unsigned long size)
|
is_io_mapping_possible(resource_size_t base, unsigned long size)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
int
|
static int
|
||||||
is_io_mapping_possible(resource_size_t base, unsigned long size)
|
is_io_mapping_possible(resource_size_t base, unsigned long size)
|
||||||
{
|
{
|
||||||
/* There is no way to map greater than 1 << 32 address without PAE */
|
/* There is no way to map greater than 1 << 32 address without PAE */
|
||||||
|
@ -38,6 +38,44 @@ is_io_mapping_possible(resource_size_t base, unsigned long size)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int
|
||||||
|
reserve_io_memtype_wc(u64 base, unsigned long size, pgprot_t *prot)
|
||||||
|
{
|
||||||
|
unsigned long ret_flag;
|
||||||
|
|
||||||
|
if (!is_io_mapping_possible(base, size))
|
||||||
|
goto out_err;
|
||||||
|
|
||||||
|
if (!pat_enabled) {
|
||||||
|
*prot = pgprot_noncached(PAGE_KERNEL);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reserve_memtype(base, base + size, _PAGE_CACHE_WC, &ret_flag))
|
||||||
|
goto out_err;
|
||||||
|
|
||||||
|
if (ret_flag == _PAGE_CACHE_WB)
|
||||||
|
goto out_free;
|
||||||
|
|
||||||
|
if (kernel_map_sync_memtype(base, size, ret_flag))
|
||||||
|
goto out_free;
|
||||||
|
|
||||||
|
*prot = __pgprot(__PAGE_KERNEL | ret_flag);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
out_free:
|
||||||
|
free_memtype(base, base + size);
|
||||||
|
out_err:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
free_io_memtype(u64 base, unsigned long size)
|
||||||
|
{
|
||||||
|
if (pat_enabled)
|
||||||
|
free_memtype(base, base + size);
|
||||||
|
}
|
||||||
|
|
||||||
/* Map 'pfn' using fixed map 'type' and protections 'prot'
|
/* Map 'pfn' using fixed map 'type' and protections 'prot'
|
||||||
*/
|
*/
|
||||||
void *
|
void *
|
||||||
|
|
|
@ -49,8 +49,9 @@ static inline struct io_mapping *
|
||||||
io_mapping_create_wc(resource_size_t base, unsigned long size)
|
io_mapping_create_wc(resource_size_t base, unsigned long size)
|
||||||
{
|
{
|
||||||
struct io_mapping *iomap;
|
struct io_mapping *iomap;
|
||||||
|
pgprot_t prot;
|
||||||
|
|
||||||
if (!is_io_mapping_possible(base, size))
|
if (!reserve_io_memtype_wc(base, size, &prot))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
iomap = kmalloc(sizeof(*iomap), GFP_KERNEL);
|
iomap = kmalloc(sizeof(*iomap), GFP_KERNEL);
|
||||||
|
@ -59,13 +60,14 @@ io_mapping_create_wc(resource_size_t base, unsigned long size)
|
||||||
|
|
||||||
iomap->base = base;
|
iomap->base = base;
|
||||||
iomap->size = size;
|
iomap->size = size;
|
||||||
iomap->prot = pgprot_writecombine(__pgprot(__PAGE_KERNEL));
|
iomap->prot = prot;
|
||||||
return iomap;
|
return iomap;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
io_mapping_free(struct io_mapping *mapping)
|
io_mapping_free(struct io_mapping *mapping)
|
||||||
{
|
{
|
||||||
|
free_io_memtype(mapping->base, mapping->size);
|
||||||
kfree(mapping);
|
kfree(mapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue