ia64/linux-2.6.18-xen.hg

annotate mm/highmem.c @ 749:2892ca2b9c17

linux/x86: cleanup IO-APIC code

- get 32-bit code in sync with 64-bit wrt ExtINT pin detection being
unnecessary
- eliminate build warnings resulting from c/s 725

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Nov 28 13:31:21 2008 +0000 (2008-11-28)
parents 7128fe32720e
children
rev   line source
ian@0 1 /*
ian@0 2 * High memory handling common code and variables.
ian@0 3 *
ian@0 4 * (C) 1999 Andrea Arcangeli, SuSE GmbH, andrea@suse.de
ian@0 5 * Gerhard Wichert, Siemens AG, Gerhard.Wichert@pdb.siemens.de
ian@0 6 *
ian@0 7 *
ian@0 8 * Redesigned the x86 32-bit VM architecture to deal with
ian@0 9 * 64-bit physical space. With current x86 CPUs this
ian@0 10 * means up to 64 Gigabytes physical RAM.
ian@0 11 *
ian@0 12 * Rewrote high memory support to move the page cache into
ian@0 13 * high memory. Implemented permanent (schedulable) kmaps
ian@0 14 * based on Linus' idea.
ian@0 15 *
ian@0 16 * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com>
ian@0 17 */
ian@0 18
ian@0 19 #include <linux/mm.h>
ian@0 20 #include <linux/module.h>
ian@0 21 #include <linux/swap.h>
ian@0 22 #include <linux/bio.h>
ian@0 23 #include <linux/pagemap.h>
ian@0 24 #include <linux/mempool.h>
ian@0 25 #include <linux/blkdev.h>
ian@0 26 #include <linux/init.h>
ian@0 27 #include <linux/hash.h>
ian@0 28 #include <linux/highmem.h>
ian@0 29 #include <linux/blktrace_api.h>
ian@0 30 #include <asm/tlbflush.h>
ian@0 31
ian@0 32 static mempool_t *page_pool, *isa_page_pool;
ian@0 33
ian@0 34 static void *mempool_alloc_pages_isa(gfp_t gfp_mask, void *data)
ian@0 35 {
ian@0 36 return mempool_alloc_pages(gfp_mask | GFP_DMA, data);
ian@0 37 }
ian@0 38
ian@0 39 /*
ian@0 40 * Virtual_count is not a pure "count".
ian@0 41 * 0 means that it is not mapped, and has not been mapped
ian@0 42 * since a TLB flush - it is usable.
ian@0 43 * 1 means that there are no users, but it has been mapped
ian@0 44 * since the last TLB flush - so we can't use it.
ian@0 45 * n means that there are (n-1) current users of it.
ian@0 46 */
ian@0 47 #ifdef CONFIG_HIGHMEM
ian@0 48
ian@0 49 static int pkmap_count[LAST_PKMAP];
ian@0 50 static unsigned int last_pkmap_nr;
ian@0 51 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(kmap_lock);
ian@0 52
ian@0 53 pte_t * pkmap_page_table;
ian@0 54
ian@0 55 static DECLARE_WAIT_QUEUE_HEAD(pkmap_map_wait);
ian@0 56
ian@0 57 static void flush_all_zero_pkmaps(void)
ian@0 58 {
ian@0 59 int i;
ian@0 60
ian@0 61 flush_cache_kmaps();
ian@0 62
ian@0 63 for (i = 0; i < LAST_PKMAP; i++) {
ian@0 64 struct page *page;
ian@0 65
ian@0 66 /*
ian@0 67 * zero means we don't have anything to do,
ian@0 68 * >1 means that it is still in use. Only
ian@0 69 * a count of 1 means that it is free but
ian@0 70 * needs to be unmapped
ian@0 71 */
ian@0 72 if (pkmap_count[i] != 1)
ian@0 73 continue;
ian@0 74 pkmap_count[i] = 0;
ian@0 75
ian@0 76 /* sanity check */
ian@0 77 BUG_ON(pte_none(pkmap_page_table[i]));
ian@0 78
ian@0 79 /*
ian@0 80 * Don't need an atomic fetch-and-clear op here;
ian@0 81 * no-one has the page mapped, and cannot get at
ian@0 82 * its virtual address (and hence PTE) without first
ian@0 83 * getting the kmap_lock (which is held here).
ian@0 84 * So no dangers, even with speculative execution.
ian@0 85 */
ian@0 86 page = pte_page(pkmap_page_table[i]);
ian@0 87 pte_clear(&init_mm, (unsigned long)page_address(page),
ian@0 88 &pkmap_page_table[i]);
ian@0 89
ian@0 90 set_page_address(page, NULL);
ian@0 91 }
ian@0 92 flush_tlb_kernel_range(PKMAP_ADDR(0), PKMAP_ADDR(LAST_PKMAP));
ian@0 93 }
ian@0 94
ian@0 95 static inline unsigned long map_new_virtual(struct page *page)
ian@0 96 {
ian@0 97 unsigned long vaddr;
ian@0 98 int count;
ian@0 99
ian@0 100 start:
ian@0 101 count = LAST_PKMAP;
ian@0 102 /* Find an empty entry */
ian@0 103 for (;;) {
ian@0 104 last_pkmap_nr = (last_pkmap_nr + 1) & LAST_PKMAP_MASK;
ian@0 105 if (!last_pkmap_nr) {
ian@0 106 flush_all_zero_pkmaps();
ian@0 107 count = LAST_PKMAP;
ian@0 108 }
ian@0 109 if (!pkmap_count[last_pkmap_nr])
ian@0 110 break; /* Found a usable entry */
ian@0 111 if (--count)
ian@0 112 continue;
ian@0 113
ian@0 114 /*
ian@0 115 * Sleep for somebody else to unmap their entries
ian@0 116 */
ian@0 117 {
ian@0 118 DECLARE_WAITQUEUE(wait, current);
ian@0 119
ian@0 120 __set_current_state(TASK_UNINTERRUPTIBLE);
ian@0 121 add_wait_queue(&pkmap_map_wait, &wait);
ian@0 122 spin_unlock(&kmap_lock);
ian@0 123 schedule();
ian@0 124 remove_wait_queue(&pkmap_map_wait, &wait);
ian@0 125 spin_lock(&kmap_lock);
ian@0 126
ian@0 127 /* Somebody else might have mapped it while we slept */
ian@0 128 if (page_address(page))
ian@0 129 return (unsigned long)page_address(page);
ian@0 130
ian@0 131 /* Re-start */
ian@0 132 goto start;
ian@0 133 }
ian@0 134 }
ian@0 135 vaddr = PKMAP_ADDR(last_pkmap_nr);
ian@0 136 set_pte_at(&init_mm, vaddr,
ian@0 137 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
ian@0 138
ian@0 139 pkmap_count[last_pkmap_nr] = 1;
ian@0 140 set_page_address(page, (void *)vaddr);
ian@0 141
ian@0 142 return vaddr;
ian@0 143 }
ian@0 144
ian@26 145 #ifdef CONFIG_XEN
ian@26 146 void kmap_flush_unused(void)
ian@26 147 {
ian@26 148 spin_lock(&kmap_lock);
ian@26 149 flush_all_zero_pkmaps();
ian@26 150 spin_unlock(&kmap_lock);
ian@26 151 }
ian@26 152
ian@26 153 EXPORT_SYMBOL(kmap_flush_unused);
ian@26 154 #endif
ian@26 155
ian@0 156 void fastcall *kmap_high(struct page *page)
ian@0 157 {
ian@0 158 unsigned long vaddr;
ian@0 159
ian@0 160 /*
ian@0 161 * For highmem pages, we can't trust "virtual" until
ian@0 162 * after we have the lock.
ian@0 163 *
ian@0 164 * We cannot call this from interrupts, as it may block
ian@0 165 */
ian@0 166 spin_lock(&kmap_lock);
ian@0 167 vaddr = (unsigned long)page_address(page);
ian@0 168 if (!vaddr)
ian@0 169 vaddr = map_new_virtual(page);
ian@0 170 pkmap_count[PKMAP_NR(vaddr)]++;
ian@0 171 BUG_ON(pkmap_count[PKMAP_NR(vaddr)] < 2);
ian@0 172 spin_unlock(&kmap_lock);
ian@0 173 return (void*) vaddr;
ian@0 174 }
ian@0 175
ian@0 176 EXPORT_SYMBOL(kmap_high);
ian@0 177
ian@0 178 void fastcall kunmap_high(struct page *page)
ian@0 179 {
ian@0 180 unsigned long vaddr;
ian@0 181 unsigned long nr;
ian@0 182 int need_wakeup;
ian@0 183
ian@0 184 spin_lock(&kmap_lock);
ian@0 185 vaddr = (unsigned long)page_address(page);
ian@0 186 BUG_ON(!vaddr);
ian@0 187 nr = PKMAP_NR(vaddr);
ian@0 188
ian@0 189 /*
ian@0 190 * A count must never go down to zero
ian@0 191 * without a TLB flush!
ian@0 192 */
ian@0 193 need_wakeup = 0;
ian@0 194 switch (--pkmap_count[nr]) {
ian@0 195 case 0:
ian@0 196 BUG();
ian@0 197 case 1:
ian@0 198 /*
ian@0 199 * Avoid an unnecessary wake_up() function call.
ian@0 200 * The common case is pkmap_count[] == 1, but
ian@0 201 * no waiters.
ian@0 202 * The tasks queued in the wait-queue are guarded
ian@0 203 * by both the lock in the wait-queue-head and by
ian@0 204 * the kmap_lock. As the kmap_lock is held here,
ian@0 205 * no need for the wait-queue-head's lock. Simply
ian@0 206 * test if the queue is empty.
ian@0 207 */
ian@0 208 need_wakeup = waitqueue_active(&pkmap_map_wait);
ian@0 209 }
ian@0 210 spin_unlock(&kmap_lock);
ian@0 211
ian@0 212 /* do wake-up, if needed, race-free outside of the spin lock */
ian@0 213 if (need_wakeup)
ian@0 214 wake_up(&pkmap_map_wait);
ian@0 215 }
ian@0 216
ian@0 217 EXPORT_SYMBOL(kunmap_high);
ian@0 218
ian@0 219 #define POOL_SIZE 64
ian@0 220
ian@0 221 static __init int init_emergency_pool(void)
ian@0 222 {
ian@0 223 struct sysinfo i;
ian@0 224 si_meminfo(&i);
ian@0 225 si_swapinfo(&i);
ian@0 226
ian@0 227 if (!i.totalhigh)
ian@0 228 return 0;
ian@0 229
ian@0 230 page_pool = mempool_create_page_pool(POOL_SIZE, 0);
ian@0 231 BUG_ON(!page_pool);
ian@0 232 printk("highmem bounce pool size: %d pages\n", POOL_SIZE);
ian@0 233
ian@0 234 return 0;
ian@0 235 }
ian@0 236
ian@0 237 __initcall(init_emergency_pool);
ian@0 238
ian@0 239 /*
ian@0 240 * highmem version, map in to vec
ian@0 241 */
ian@0 242 static void bounce_copy_vec(struct bio_vec *to, unsigned char *vfrom)
ian@0 243 {
ian@0 244 unsigned long flags;
ian@0 245 unsigned char *vto;
ian@0 246
ian@0 247 local_irq_save(flags);
ian@0 248 vto = kmap_atomic(to->bv_page, KM_BOUNCE_READ);
ian@0 249 memcpy(vto + to->bv_offset, vfrom, to->bv_len);
ian@0 250 kunmap_atomic(vto, KM_BOUNCE_READ);
ian@0 251 local_irq_restore(flags);
ian@0 252 }
ian@0 253
ian@0 254 #else /* CONFIG_HIGHMEM */
ian@0 255
ian@0 256 #define bounce_copy_vec(to, vfrom) \
ian@0 257 memcpy(page_address((to)->bv_page) + (to)->bv_offset, vfrom, (to)->bv_len)
ian@0 258
ian@0 259 #endif
ian@0 260
ian@0 261 #define ISA_POOL_SIZE 16
ian@0 262
ian@0 263 /*
ian@0 264 * gets called "every" time someone init's a queue with BLK_BOUNCE_ISA
ian@0 265 * as the max address, so check if the pool has already been created.
ian@0 266 */
ian@0 267 int init_emergency_isa_pool(void)
ian@0 268 {
ian@0 269 if (isa_page_pool)
ian@0 270 return 0;
ian@0 271
ian@0 272 isa_page_pool = mempool_create(ISA_POOL_SIZE, mempool_alloc_pages_isa,
ian@0 273 mempool_free_pages, (void *) 0);
ian@0 274 BUG_ON(!isa_page_pool);
ian@0 275
ian@0 276 printk("isa bounce pool size: %d pages\n", ISA_POOL_SIZE);
ian@0 277 return 0;
ian@0 278 }
ian@0 279
ian@0 280 /*
ian@0 281 * Simple bounce buffer support for highmem pages. Depending on the
ian@0 282 * queue gfp mask set, *to may or may not be a highmem page. kmap it
ian@0 283 * always, it will do the Right Thing
ian@0 284 */
ian@0 285 static void copy_to_high_bio_irq(struct bio *to, struct bio *from)
ian@0 286 {
ian@0 287 unsigned char *vfrom;
ian@0 288 struct bio_vec *tovec, *fromvec;
ian@0 289 int i;
ian@0 290
ian@0 291 __bio_for_each_segment(tovec, to, i, 0) {
ian@0 292 fromvec = from->bi_io_vec + i;
ian@0 293
ian@0 294 /*
ian@0 295 * not bounced
ian@0 296 */
ian@0 297 if (tovec->bv_page == fromvec->bv_page)
ian@0 298 continue;
ian@0 299
ian@0 300 /*
ian@0 301 * fromvec->bv_offset and fromvec->bv_len might have been
ian@0 302 * modified by the block layer, so use the original copy,
ian@0 303 * bounce_copy_vec already uses tovec->bv_len
ian@0 304 */
ian@0 305 vfrom = page_address(fromvec->bv_page) + tovec->bv_offset;
ian@0 306
ian@0 307 flush_dcache_page(tovec->bv_page);
ian@0 308 bounce_copy_vec(tovec, vfrom);
ian@0 309 }
ian@0 310 }
ian@0 311
ian@0 312 static void bounce_end_io(struct bio *bio, mempool_t *pool, int err)
ian@0 313 {
ian@0 314 struct bio *bio_orig = bio->bi_private;
ian@0 315 struct bio_vec *bvec, *org_vec;
ian@0 316 int i;
ian@0 317
ian@0 318 if (test_bit(BIO_EOPNOTSUPP, &bio->bi_flags))
ian@0 319 set_bit(BIO_EOPNOTSUPP, &bio_orig->bi_flags);
ian@0 320
ian@0 321 /*
ian@0 322 * free up bounce indirect pages used
ian@0 323 */
ian@0 324 __bio_for_each_segment(bvec, bio, i, 0) {
ian@0 325 org_vec = bio_orig->bi_io_vec + i;
ian@0 326 if (bvec->bv_page == org_vec->bv_page)
ian@0 327 continue;
ian@0 328
ian@0 329 dec_zone_page_state(bvec->bv_page, NR_BOUNCE);
ian@0 330 mempool_free(bvec->bv_page, pool);
ian@0 331 }
ian@0 332
ian@0 333 bio_endio(bio_orig, bio_orig->bi_size, err);
ian@0 334 bio_put(bio);
ian@0 335 }
ian@0 336
ian@0 337 static int bounce_end_io_write(struct bio *bio, unsigned int bytes_done, int err)
ian@0 338 {
ian@0 339 if (bio->bi_size)
ian@0 340 return 1;
ian@0 341
ian@0 342 bounce_end_io(bio, page_pool, err);
ian@0 343 return 0;
ian@0 344 }
ian@0 345
ian@0 346 static int bounce_end_io_write_isa(struct bio *bio, unsigned int bytes_done, int err)
ian@0 347 {
ian@0 348 if (bio->bi_size)
ian@0 349 return 1;
ian@0 350
ian@0 351 bounce_end_io(bio, isa_page_pool, err);
ian@0 352 return 0;
ian@0 353 }
ian@0 354
ian@0 355 static void __bounce_end_io_read(struct bio *bio, mempool_t *pool, int err)
ian@0 356 {
ian@0 357 struct bio *bio_orig = bio->bi_private;
ian@0 358
ian@0 359 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
ian@0 360 copy_to_high_bio_irq(bio_orig, bio);
ian@0 361
ian@0 362 bounce_end_io(bio, pool, err);
ian@0 363 }
ian@0 364
ian@0 365 static int bounce_end_io_read(struct bio *bio, unsigned int bytes_done, int err)
ian@0 366 {
ian@0 367 if (bio->bi_size)
ian@0 368 return 1;
ian@0 369
ian@0 370 __bounce_end_io_read(bio, page_pool, err);
ian@0 371 return 0;
ian@0 372 }
ian@0 373
ian@0 374 static int bounce_end_io_read_isa(struct bio *bio, unsigned int bytes_done, int err)
ian@0 375 {
ian@0 376 if (bio->bi_size)
ian@0 377 return 1;
ian@0 378
ian@0 379 __bounce_end_io_read(bio, isa_page_pool, err);
ian@0 380 return 0;
ian@0 381 }
ian@0 382
ian@0 383 static void __blk_queue_bounce(request_queue_t *q, struct bio **bio_orig,
ian@0 384 mempool_t *pool)
ian@0 385 {
ian@0 386 struct page *page;
ian@0 387 struct bio *bio = NULL;
ian@0 388 int i, rw = bio_data_dir(*bio_orig);
ian@0 389 struct bio_vec *to, *from;
ian@0 390
ian@0 391 bio_for_each_segment(from, *bio_orig, i) {
ian@0 392 page = from->bv_page;
ian@0 393
ian@0 394 /*
ian@0 395 * is destination page below bounce pfn?
ian@0 396 */
ian@0 397 if (page_to_pfn(page) < q->bounce_pfn)
ian@0 398 continue;
ian@0 399
ian@0 400 /*
ian@0 401 * irk, bounce it
ian@0 402 */
ian@0 403 if (!bio)
ian@0 404 bio = bio_alloc(GFP_NOIO, (*bio_orig)->bi_vcnt);
ian@0 405
ian@0 406 to = bio->bi_io_vec + i;
ian@0 407
ian@0 408 to->bv_page = mempool_alloc(pool, q->bounce_gfp);
ian@0 409 to->bv_len = from->bv_len;
ian@0 410 to->bv_offset = from->bv_offset;
ian@0 411 inc_zone_page_state(to->bv_page, NR_BOUNCE);
ian@0 412
ian@0 413 if (rw == WRITE) {
ian@0 414 char *vto, *vfrom;
ian@0 415
ian@0 416 flush_dcache_page(from->bv_page);
ian@0 417 vto = page_address(to->bv_page) + to->bv_offset;
ian@0 418 vfrom = kmap(from->bv_page) + from->bv_offset;
ian@0 419 memcpy(vto, vfrom, to->bv_len);
ian@0 420 kunmap(from->bv_page);
ian@0 421 }
ian@0 422 }
ian@0 423
ian@0 424 /*
ian@0 425 * no pages bounced
ian@0 426 */
ian@0 427 if (!bio)
ian@0 428 return;
ian@0 429
ian@0 430 /*
ian@0 431 * at least one page was bounced, fill in possible non-highmem
ian@0 432 * pages
ian@0 433 */
ian@0 434 __bio_for_each_segment(from, *bio_orig, i, 0) {
ian@0 435 to = bio_iovec_idx(bio, i);
ian@0 436 if (!to->bv_page) {
ian@0 437 to->bv_page = from->bv_page;
ian@0 438 to->bv_len = from->bv_len;
ian@0 439 to->bv_offset = from->bv_offset;
ian@0 440 }
ian@0 441 }
ian@0 442
ian@0 443 bio->bi_bdev = (*bio_orig)->bi_bdev;
ian@0 444 bio->bi_flags |= (1 << BIO_BOUNCED);
ian@0 445 bio->bi_sector = (*bio_orig)->bi_sector;
ian@0 446 bio->bi_rw = (*bio_orig)->bi_rw;
ian@0 447
ian@0 448 bio->bi_vcnt = (*bio_orig)->bi_vcnt;
ian@0 449 bio->bi_idx = (*bio_orig)->bi_idx;
ian@0 450 bio->bi_size = (*bio_orig)->bi_size;
ian@0 451
ian@0 452 if (pool == page_pool) {
ian@0 453 bio->bi_end_io = bounce_end_io_write;
ian@0 454 if (rw == READ)
ian@0 455 bio->bi_end_io = bounce_end_io_read;
ian@0 456 } else {
ian@0 457 bio->bi_end_io = bounce_end_io_write_isa;
ian@0 458 if (rw == READ)
ian@0 459 bio->bi_end_io = bounce_end_io_read_isa;
ian@0 460 }
ian@0 461
ian@0 462 bio->bi_private = *bio_orig;
ian@0 463 *bio_orig = bio;
ian@0 464 }
ian@0 465
ian@0 466 void blk_queue_bounce(request_queue_t *q, struct bio **bio_orig)
ian@0 467 {
ian@0 468 mempool_t *pool;
ian@0 469
ian@0 470 /*
keir@417 471 * Data-less bio, nothing to bounce
keir@417 472 */
keir@417 473 if (bio_empty_barrier(*bio_orig))
keir@417 474 return;
keir@417 475
keir@417 476 /*
ian@0 477 * for non-isa bounce case, just check if the bounce pfn is equal
ian@0 478 * to or bigger than the highest pfn in the system -- in that case,
ian@0 479 * don't waste time iterating over bio segments
ian@0 480 */
ian@0 481 if (!(q->bounce_gfp & GFP_DMA)) {
ian@0 482 if (q->bounce_pfn >= blk_max_pfn)
ian@0 483 return;
ian@0 484 pool = page_pool;
ian@0 485 } else {
ian@0 486 BUG_ON(!isa_page_pool);
ian@0 487 pool = isa_page_pool;
ian@0 488 }
ian@0 489
ian@0 490 blk_add_trace_bio(q, *bio_orig, BLK_TA_BOUNCE);
ian@0 491
ian@0 492 /*
ian@0 493 * slow path
ian@0 494 */
ian@0 495 __blk_queue_bounce(q, bio_orig, pool);
ian@0 496 }
ian@0 497
ian@0 498 EXPORT_SYMBOL(blk_queue_bounce);
ian@0 499
ian@0 500 #if defined(HASHED_PAGE_VIRTUAL)
ian@0 501
ian@0 502 #define PA_HASH_ORDER 7
ian@0 503
ian@0 504 /*
ian@0 505 * Describes one page->virtual association
ian@0 506 */
ian@0 507 struct page_address_map {
ian@0 508 struct page *page;
ian@0 509 void *virtual;
ian@0 510 struct list_head list;
ian@0 511 };
ian@0 512
ian@0 513 /*
ian@0 514 * page_address_map freelist, allocated from page_address_maps.
ian@0 515 */
ian@0 516 static struct list_head page_address_pool; /* freelist */
ian@0 517 static spinlock_t pool_lock; /* protects page_address_pool */
ian@0 518
ian@0 519 /*
ian@0 520 * Hash table bucket
ian@0 521 */
ian@0 522 static struct page_address_slot {
ian@0 523 struct list_head lh; /* List of page_address_maps */
ian@0 524 spinlock_t lock; /* Protect this bucket's list */
ian@0 525 } ____cacheline_aligned_in_smp page_address_htable[1<<PA_HASH_ORDER];
ian@0 526
ian@0 527 static struct page_address_slot *page_slot(struct page *page)
ian@0 528 {
ian@0 529 return &page_address_htable[hash_ptr(page, PA_HASH_ORDER)];
ian@0 530 }
ian@0 531
ian@0 532 void *page_address(struct page *page)
ian@0 533 {
ian@0 534 unsigned long flags;
ian@0 535 void *ret;
ian@0 536 struct page_address_slot *pas;
ian@0 537
ian@0 538 if (!PageHighMem(page))
ian@0 539 return lowmem_page_address(page);
ian@0 540
ian@0 541 pas = page_slot(page);
ian@0 542 ret = NULL;
ian@0 543 spin_lock_irqsave(&pas->lock, flags);
ian@0 544 if (!list_empty(&pas->lh)) {
ian@0 545 struct page_address_map *pam;
ian@0 546
ian@0 547 list_for_each_entry(pam, &pas->lh, list) {
ian@0 548 if (pam->page == page) {
ian@0 549 ret = pam->virtual;
ian@0 550 goto done;
ian@0 551 }
ian@0 552 }
ian@0 553 }
ian@0 554 done:
ian@0 555 spin_unlock_irqrestore(&pas->lock, flags);
ian@0 556 return ret;
ian@0 557 }
ian@0 558
ian@0 559 EXPORT_SYMBOL(page_address);
ian@0 560
ian@0 561 void set_page_address(struct page *page, void *virtual)
ian@0 562 {
ian@0 563 unsigned long flags;
ian@0 564 struct page_address_slot *pas;
ian@0 565 struct page_address_map *pam;
ian@0 566
ian@0 567 BUG_ON(!PageHighMem(page));
ian@0 568
ian@0 569 pas = page_slot(page);
ian@0 570 if (virtual) { /* Add */
ian@0 571 BUG_ON(list_empty(&page_address_pool));
ian@0 572
ian@0 573 spin_lock_irqsave(&pool_lock, flags);
ian@0 574 pam = list_entry(page_address_pool.next,
ian@0 575 struct page_address_map, list);
ian@0 576 list_del(&pam->list);
ian@0 577 spin_unlock_irqrestore(&pool_lock, flags);
ian@0 578
ian@0 579 pam->page = page;
ian@0 580 pam->virtual = virtual;
ian@0 581
ian@0 582 spin_lock_irqsave(&pas->lock, flags);
ian@0 583 list_add_tail(&pam->list, &pas->lh);
ian@0 584 spin_unlock_irqrestore(&pas->lock, flags);
ian@0 585 } else { /* Remove */
ian@0 586 spin_lock_irqsave(&pas->lock, flags);
ian@0 587 list_for_each_entry(pam, &pas->lh, list) {
ian@0 588 if (pam->page == page) {
ian@0 589 list_del(&pam->list);
ian@0 590 spin_unlock_irqrestore(&pas->lock, flags);
ian@0 591 spin_lock_irqsave(&pool_lock, flags);
ian@0 592 list_add_tail(&pam->list, &page_address_pool);
ian@0 593 spin_unlock_irqrestore(&pool_lock, flags);
ian@0 594 goto done;
ian@0 595 }
ian@0 596 }
ian@0 597 spin_unlock_irqrestore(&pas->lock, flags);
ian@0 598 }
ian@0 599 done:
ian@0 600 return;
ian@0 601 }
ian@0 602
ian@0 603 static struct page_address_map page_address_maps[LAST_PKMAP];
ian@0 604
ian@0 605 void __init page_address_init(void)
ian@0 606 {
ian@0 607 int i;
ian@0 608
ian@0 609 INIT_LIST_HEAD(&page_address_pool);
ian@0 610 for (i = 0; i < ARRAY_SIZE(page_address_maps); i++)
ian@0 611 list_add(&page_address_maps[i].list, &page_address_pool);
ian@0 612 for (i = 0; i < ARRAY_SIZE(page_address_htable); i++) {
ian@0 613 INIT_LIST_HEAD(&page_address_htable[i].lh);
ian@0 614 spin_lock_init(&page_address_htable[i].lock);
ian@0 615 }
ian@0 616 spin_lock_init(&pool_lock);
ian@0 617 }
ian@0 618
ian@0 619 #endif /* defined(CONFIG_HIGHMEM) && !defined(WANT_PAGE_VIRTUAL) */