| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 1 | /* | 
| Dean Nelson | e4a064d | 2008-04-25 15:22:19 -0500 | [diff] [blame] | 2 |  * Copyright (C) 2001-2008 Silicon Graphics, Inc.  All rights reserved. | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 3 |  * | 
 | 4 |  * This program is free software; you can redistribute it and/or modify it | 
 | 5 |  * under the terms of version 2 of the GNU General Public License | 
 | 6 |  * as published by the Free Software Foundation. | 
 | 7 |  * | 
 | 8 |  * A simple uncached page allocator using the generic allocator. This | 
 | 9 |  * allocator first utilizes the spare (spill) pages found in the EFI | 
 | 10 |  * memmap and will then start converting cached pages to uncached ones | 
 | 11 |  * at a granule at a time. Node awareness is implemented by having a | 
 | 12 |  * pool of pages per node. | 
 | 13 |  */ | 
 | 14 |  | 
 | 15 | #include <linux/types.h> | 
 | 16 | #include <linux/kernel.h> | 
 | 17 | #include <linux/module.h> | 
 | 18 | #include <linux/init.h> | 
 | 19 | #include <linux/errno.h> | 
 | 20 | #include <linux/string.h> | 
 | 21 | #include <linux/slab.h> | 
 | 22 | #include <linux/efi.h> | 
 | 23 | #include <linux/genalloc.h> | 
 | 24 | #include <asm/page.h> | 
 | 25 | #include <asm/pal.h> | 
 | 26 | #include <asm/system.h> | 
 | 27 | #include <asm/pgtable.h> | 
 | 28 | #include <asm/atomic.h> | 
 | 29 | #include <asm/tlbflush.h> | 
 | 30 | #include <asm/sn/arch.h> | 
 | 31 |  | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 32 |  | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 33 | extern void __init efi_memmap_walk_uc(efi_freemem_callback_t, void *); | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 34 |  | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 35 | struct uncached_pool { | 
 | 36 | 	struct gen_pool *pool; | 
 | 37 | 	struct mutex add_chunk_mutex;	/* serialize adding a converted chunk */ | 
 | 38 | 	int nchunks_added;		/* #of converted chunks added to pool */ | 
 | 39 | 	atomic_t status;		/* smp called function's return status*/ | 
 | 40 | }; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 41 |  | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 42 | #define MAX_CONVERTED_CHUNKS_PER_NODE	2 | 
 | 43 |  | 
 | 44 | struct uncached_pool uncached_pools[MAX_NUMNODES]; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 45 |  | 
 | 46 |  | 
 | 47 | static void uncached_ipi_visibility(void *data) | 
 | 48 | { | 
 | 49 | 	int status; | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 50 | 	struct uncached_pool *uc_pool = (struct uncached_pool *)data; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 51 |  | 
 | 52 | 	status = ia64_pal_prefetch_visibility(PAL_VISIBILITY_PHYSICAL); | 
 | 53 | 	if ((status != PAL_VISIBILITY_OK) && | 
 | 54 | 	    (status != PAL_VISIBILITY_OK_REMOTE_NEEDED)) | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 55 | 		atomic_inc(&uc_pool->status); | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 56 | } | 
 | 57 |  | 
 | 58 |  | 
 | 59 | static void uncached_ipi_mc_drain(void *data) | 
 | 60 | { | 
 | 61 | 	int status; | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 62 | 	struct uncached_pool *uc_pool = (struct uncached_pool *)data; | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 63 |  | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 64 | 	status = ia64_pal_mc_drain(); | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 65 | 	if (status != PAL_STATUS_SUCCESS) | 
 | 66 | 		atomic_inc(&uc_pool->status); | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 67 | } | 
 | 68 |  | 
 | 69 |  | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 70 | /* | 
 | 71 |  * Add a new chunk of uncached memory pages to the specified pool. | 
 | 72 |  * | 
 | 73 |  * @pool: pool to add new chunk of uncached memory to | 
 | 74 |  * @nid: node id of node to allocate memory from, or -1 | 
 | 75 |  * | 
 | 76 |  * This is accomplished by first allocating a granule of cached memory pages | 
 | 77 |  * and then converting them to uncached memory pages. | 
 | 78 |  */ | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 79 | static int uncached_add_chunk(struct uncached_pool *uc_pool, int nid) | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 80 | { | 
 | 81 | 	struct page *page; | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 82 | 	int status, i, nchunks_added = uc_pool->nchunks_added; | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 83 | 	unsigned long c_addr, uc_addr; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 84 |  | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 85 | 	if (mutex_lock_interruptible(&uc_pool->add_chunk_mutex) != 0) | 
 | 86 | 		return -1;	/* interrupted by a signal */ | 
 | 87 |  | 
 | 88 | 	if (uc_pool->nchunks_added > nchunks_added) { | 
 | 89 | 		/* someone added a new chunk while we were waiting */ | 
 | 90 | 		mutex_unlock(&uc_pool->add_chunk_mutex); | 
 | 91 | 		return 0; | 
 | 92 | 	} | 
 | 93 |  | 
 | 94 | 	if (uc_pool->nchunks_added >= MAX_CONVERTED_CHUNKS_PER_NODE) { | 
 | 95 | 		mutex_unlock(&uc_pool->add_chunk_mutex); | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 96 | 		return -1; | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 97 | 	} | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 98 |  | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 99 | 	/* attempt to allocate a granule's worth of cached memory pages */ | 
 | 100 |  | 
| Christoph Lameter | 980128f | 2006-09-25 23:31:46 -0700 | [diff] [blame] | 101 | 	page = alloc_pages_node(nid, GFP_KERNEL | __GFP_ZERO | GFP_THISNODE, | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 102 | 				IA64_GRANULE_SHIFT-PAGE_SHIFT); | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 103 | 	if (!page) { | 
 | 104 | 		mutex_unlock(&uc_pool->add_chunk_mutex); | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 105 | 		return -1; | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 106 | 	} | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 107 |  | 
 | 108 | 	/* convert the memory pages from cached to uncached */ | 
 | 109 |  | 
 | 110 | 	c_addr = (unsigned long)page_address(page); | 
 | 111 | 	uc_addr = c_addr - PAGE_OFFSET + __IA64_UNCACHED_OFFSET; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 112 |  | 
 | 113 | 	/* | 
 | 114 | 	 * There's a small race here where it's possible for someone to | 
 | 115 | 	 * access the page through /dev/mem halfway through the conversion | 
 | 116 | 	 * to uncached - not sure it's really worth bothering about | 
 | 117 | 	 */ | 
 | 118 | 	for (i = 0; i < (IA64_GRANULE_SIZE / PAGE_SIZE); i++) | 
 | 119 | 		SetPageUncached(&page[i]); | 
 | 120 |  | 
| Jan Beulich | 285fbd6 | 2007-12-19 12:30:30 -0800 | [diff] [blame] | 121 | 	flush_tlb_kernel_range(uc_addr, uc_addr + IA64_GRANULE_SIZE); | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 122 |  | 
 | 123 | 	status = ia64_pal_prefetch_visibility(PAL_VISIBILITY_PHYSICAL); | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 124 | 	if (status == PAL_VISIBILITY_OK_REMOTE_NEEDED) { | 
 | 125 | 		atomic_set(&uc_pool->status, 0); | 
| Jens Axboe | 8691e5a | 2008-06-06 11:18:06 +0200 | [diff] [blame] | 126 | 		status = smp_call_function(uncached_ipi_visibility, uc_pool, 1); | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 127 | 		if (status || atomic_read(&uc_pool->status)) | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 128 | 			goto failed; | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 129 | 	} else if (status != PAL_VISIBILITY_OK) | 
 | 130 | 		goto failed; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 131 |  | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 132 | 	preempt_disable(); | 
 | 133 |  | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 134 | 	if (ia64_platform_is("sn2")) | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 135 | 		sn_flush_all_caches(uc_addr, IA64_GRANULE_SIZE); | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 136 | 	else | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 137 | 		flush_icache_range(uc_addr, uc_addr + IA64_GRANULE_SIZE); | 
 | 138 |  | 
 | 139 | 	/* flush the just introduced uncached translation from the TLB */ | 
 | 140 | 	local_flush_tlb_all(); | 
 | 141 |  | 
 | 142 | 	preempt_enable(); | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 143 |  | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 144 | 	status = ia64_pal_mc_drain(); | 
 | 145 | 	if (status != PAL_STATUS_SUCCESS) | 
 | 146 | 		goto failed; | 
 | 147 | 	atomic_set(&uc_pool->status, 0); | 
| Jens Axboe | 8691e5a | 2008-06-06 11:18:06 +0200 | [diff] [blame] | 148 | 	status = smp_call_function(uncached_ipi_mc_drain, uc_pool, 1); | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 149 | 	if (status || atomic_read(&uc_pool->status)) | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 150 | 		goto failed; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 151 |  | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 152 | 	/* | 
 | 153 | 	 * The chunk of memory pages has been converted to uncached so now we | 
 | 154 | 	 * can add it to the pool. | 
 | 155 | 	 */ | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 156 | 	status = gen_pool_add(uc_pool->pool, uc_addr, IA64_GRANULE_SIZE, nid); | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 157 | 	if (status) | 
 | 158 | 		goto failed; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 159 |  | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 160 | 	uc_pool->nchunks_added++; | 
 | 161 | 	mutex_unlock(&uc_pool->add_chunk_mutex); | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 162 | 	return 0; | 
 | 163 |  | 
 | 164 | 	/* failed to convert or add the chunk so give it back to the kernel */ | 
 | 165 | failed: | 
 | 166 | 	for (i = 0; i < (IA64_GRANULE_SIZE / PAGE_SIZE); i++) | 
 | 167 | 		ClearPageUncached(&page[i]); | 
 | 168 |  | 
 | 169 | 	free_pages(c_addr, IA64_GRANULE_SHIFT-PAGE_SHIFT); | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 170 | 	mutex_unlock(&uc_pool->add_chunk_mutex); | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 171 | 	return -1; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 172 | } | 
 | 173 |  | 
 | 174 |  | 
 | 175 | /* | 
 | 176 |  * uncached_alloc_page | 
 | 177 |  * | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 178 |  * @starting_nid: node id of node to start with, or -1 | 
| Dean Nelson | e4a064d | 2008-04-25 15:22:19 -0500 | [diff] [blame] | 179 |  * @n_pages: number of contiguous pages to allocate | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 180 |  * | 
| Dean Nelson | e4a064d | 2008-04-25 15:22:19 -0500 | [diff] [blame] | 181 |  * Allocate the specified number of contiguous uncached pages on the | 
 | 182 |  * the requested node. If not enough contiguous uncached pages are available | 
 | 183 |  * on the requested node, roundrobin starting with the next higher node. | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 184 |  */ | 
| Dean Nelson | e4a064d | 2008-04-25 15:22:19 -0500 | [diff] [blame] | 185 | unsigned long uncached_alloc_page(int starting_nid, int n_pages) | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 186 | { | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 187 | 	unsigned long uc_addr; | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 188 | 	struct uncached_pool *uc_pool; | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 189 | 	int nid; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 190 |  | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 191 | 	if (unlikely(starting_nid >= MAX_NUMNODES)) | 
 | 192 | 		return 0; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 193 |  | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 194 | 	if (starting_nid < 0) | 
 | 195 | 		starting_nid = numa_node_id(); | 
 | 196 | 	nid = starting_nid; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 197 |  | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 198 | 	do { | 
| Christoph Lameter | 2dca53a | 2007-10-16 01:25:33 -0700 | [diff] [blame] | 199 | 		if (!node_state(nid, N_HIGH_MEMORY)) | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 200 | 			continue; | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 201 | 		uc_pool = &uncached_pools[nid]; | 
 | 202 | 		if (uc_pool->pool == NULL) | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 203 | 			continue; | 
 | 204 | 		do { | 
| Dean Nelson | e4a064d | 2008-04-25 15:22:19 -0500 | [diff] [blame] | 205 | 			uc_addr = gen_pool_alloc(uc_pool->pool, | 
 | 206 | 						 n_pages * PAGE_SIZE); | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 207 | 			if (uc_addr != 0) | 
 | 208 | 				return uc_addr; | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 209 | 		} while (uncached_add_chunk(uc_pool, nid) == 0); | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 210 |  | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 211 | 	} while ((nid = (nid + 1) % MAX_NUMNODES) != starting_nid); | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 212 |  | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 213 | 	return 0; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 214 | } | 
 | 215 | EXPORT_SYMBOL(uncached_alloc_page); | 
 | 216 |  | 
 | 217 |  | 
 | 218 | /* | 
 | 219 |  * uncached_free_page | 
 | 220 |  * | 
| Dean Nelson | e4a064d | 2008-04-25 15:22:19 -0500 | [diff] [blame] | 221 |  * @uc_addr: uncached address of first page to free | 
 | 222 |  * @n_pages: number of contiguous pages to free | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 223 |  * | 
| Dean Nelson | e4a064d | 2008-04-25 15:22:19 -0500 | [diff] [blame] | 224 |  * Free the specified number of uncached pages. | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 225 |  */ | 
| Dean Nelson | e4a064d | 2008-04-25 15:22:19 -0500 | [diff] [blame] | 226 | void uncached_free_page(unsigned long uc_addr, int n_pages) | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 227 | { | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 228 | 	int nid = paddr_to_nid(uc_addr - __IA64_UNCACHED_OFFSET); | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 229 | 	struct gen_pool *pool = uncached_pools[nid].pool; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 230 |  | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 231 | 	if (unlikely(pool == NULL)) | 
 | 232 | 		return; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 233 |  | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 234 | 	if ((uc_addr & (0XFUL << 60)) != __IA64_UNCACHED_OFFSET) | 
 | 235 | 		panic("uncached_free_page invalid address %lx\n", uc_addr); | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 236 |  | 
| Dean Nelson | e4a064d | 2008-04-25 15:22:19 -0500 | [diff] [blame] | 237 | 	gen_pool_free(pool, uc_addr, n_pages * PAGE_SIZE); | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 238 | } | 
 | 239 | EXPORT_SYMBOL(uncached_free_page); | 
 | 240 |  | 
 | 241 |  | 
 | 242 | /* | 
 | 243 |  * uncached_build_memmap, | 
 | 244 |  * | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 245 |  * @uc_start: uncached starting address of a chunk of uncached memory | 
 | 246 |  * @uc_end: uncached ending address of a chunk of uncached memory | 
 | 247 |  * @arg: ignored, (NULL argument passed in on call to efi_memmap_walk_uc()) | 
 | 248 |  * | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 249 |  * Called at boot time to build a map of pages that can be used for | 
 | 250 |  * memory special operations. | 
 | 251 |  */ | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 252 | static int __init uncached_build_memmap(unsigned long uc_start, | 
 | 253 | 					unsigned long uc_end, void *arg) | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 254 | { | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 255 | 	int nid = paddr_to_nid(uc_start - __IA64_UNCACHED_OFFSET); | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 256 | 	struct gen_pool *pool = uncached_pools[nid].pool; | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 257 | 	size_t size = uc_end - uc_start; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 258 |  | 
| John Hawkes | 386d1d5 | 2006-01-18 23:46:53 -0800 | [diff] [blame] | 259 | 	touch_softlockup_watchdog(); | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 260 |  | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 261 | 	if (pool != NULL) { | 
 | 262 | 		memset((char *)uc_start, 0, size); | 
 | 263 | 		(void) gen_pool_add(pool, uc_start, size, nid); | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 264 | 	} | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 265 | 	return 0; | 
 | 266 | } | 
 | 267 |  | 
 | 268 |  | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 269 | static int __init uncached_init(void) | 
 | 270 | { | 
 | 271 | 	int nid; | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 272 |  | 
| Christoph Lameter | 2dca53a | 2007-10-16 01:25:33 -0700 | [diff] [blame] | 273 | 	for_each_node_state(nid, N_ONLINE) { | 
| Dean Nelson | eca7994 | 2006-06-28 13:50:09 -0500 | [diff] [blame] | 274 | 		uncached_pools[nid].pool = gen_pool_create(PAGE_SHIFT, nid); | 
 | 275 | 		mutex_init(&uncached_pools[nid].add_chunk_mutex); | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 276 | 	} | 
 | 277 |  | 
| Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 278 | 	efi_memmap_walk_uc(uncached_build_memmap, NULL); | 
| Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 279 | 	return 0; | 
 | 280 | } | 
 | 281 |  | 
 | 282 | __initcall(uncached_init); |