| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: pmap.c,v 1.33 2010/11/15 06:06:51 uebayasi Exp $ */ | | 1 | /* $NetBSD: pmap.c,v 1.34 2012/01/30 17:03:58 he Exp $ */ |
2 | /*- | | 2 | /*- |
3 | * Copyright (c) 1997, 1998, 2000 Ben Harris | | 3 | * Copyright (c) 1997, 1998, 2000 Ben Harris |
4 | * All rights reserved. | | 4 | * All rights reserved. |
5 | * | | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions | | 7 | * modification, are permitted provided that the following conditions |
8 | * are met: | | 8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright | | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright | | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the | | 12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. | | 13 | * documentation and/or other materials provided with the distribution. |
14 | * 3. The name of the author may not be used to endorse or promote products | | 14 | * 3. The name of the author may not be used to endorse or promote products |
| @@ -92,30 +92,30 @@ | | | @@ -92,30 +92,30 @@ |
92 | * SVC mode, and pmap_enter() will be explicitly told what to do to | | 92 | * SVC mode, and pmap_enter() will be explicitly told what to do to |
93 | * the referenced/modified bits. | | 93 | * the referenced/modified bits. |
94 | * | | 94 | * |
95 | * Breaking these rules (especially the first) is likely to upset | | 95 | * Breaking these rules (especially the first) is likely to upset |
96 | * referenced/modified emulation. | | 96 | * referenced/modified emulation. |
97 | */ | | 97 | */ |
98 | | | 98 | |
99 | #include "opt_ddb.h" | | 99 | #include "opt_ddb.h" |
100 | #include "opt_uvmhist.h" | | 100 | #include "opt_uvmhist.h" |
101 | #include "arcvideo.h" | | 101 | #include "arcvideo.h" |
102 | | | 102 | |
103 | #include <sys/param.h> | | 103 | #include <sys/param.h> |
104 | | | 104 | |
105 | __KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.33 2010/11/15 06:06:51 uebayasi Exp $"); | | 105 | __KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.34 2012/01/30 17:03:58 he Exp $"); |
106 | | | 106 | |
107 | #include <sys/kernel.h> /* for cold */ | | 107 | #include <sys/kernel.h> /* for cold */ |
108 | #include <sys/malloc.h> | | 108 | #include <sys/kmem.h> |
109 | #include <sys/pool.h> | | 109 | #include <sys/pool.h> |
110 | #include <sys/systm.h> | | 110 | #include <sys/systm.h> |
111 | #include <sys/lwp.h> | | 111 | #include <sys/lwp.h> |
112 | #include <sys/proc.h> | | 112 | #include <sys/proc.h> |
113 | | | 113 | |
114 | #include <uvm/uvm.h> | | 114 | #include <uvm/uvm.h> |
115 | #include <uvm/uvm_stat.h> | | 115 | #include <uvm/uvm_stat.h> |
116 | | | 116 | |
117 | #include <arm/cpuconf.h> | | 117 | #include <arm/cpuconf.h> |
118 | | | 118 | |
119 | #include <machine/intr.h> | | 119 | #include <machine/intr.h> |
120 | #include <machine/machdep.h> | | 120 | #include <machine/machdep.h> |
121 | #include <machine/memcreg.h> | | 121 | #include <machine/memcreg.h> |
| @@ -337,27 +337,27 @@ pmap_init(void) | | | @@ -337,27 +337,27 @@ pmap_init(void) |
337 | */ | | 337 | */ |
338 | void | | 338 | void |
339 | pmap_init2() | | 339 | pmap_init2() |
340 | { | | 340 | { |
341 | struct pmap *pmap; | | 341 | struct pmap *pmap; |
342 | struct pv_entry *new_pv_table, *old_pv_table; | | 342 | struct pv_entry *new_pv_table, *old_pv_table; |
343 | size_t pv_table_size; | | 343 | size_t pv_table_size; |
344 | int lpn; | | 344 | int lpn; |
345 | UVMHIST_FUNC("pmap_init2"); | | 345 | UVMHIST_FUNC("pmap_init2"); |
346 | | | 346 | |
347 | UVMHIST_CALLED(pmaphist); | | 347 | UVMHIST_CALLED(pmaphist); |
348 | /* We can now call malloc(). Rationalise our memory usage. */ | | 348 | /* We can now call malloc(). Rationalise our memory usage. */ |
349 | pv_table_size = physmem * sizeof(struct pv_entry); | | 349 | pv_table_size = physmem * sizeof(struct pv_entry); |
350 | new_pv_table = malloc(pv_table_size, M_VMPMAP, M_WAITOK); | | 350 | new_pv_table = kmem_alloc(pv_table_size, KM_SLEEP); |
351 | memcpy(new_pv_table, pv_table, pv_table_size); | | 351 | memcpy(new_pv_table, pv_table, pv_table_size); |
352 | old_pv_table = pv_table; | | 352 | old_pv_table = pv_table; |
353 | pv_table = new_pv_table; | | 353 | pv_table = new_pv_table; |
354 | | | 354 | |
355 | /* Fix up the kernel pmap to point at new pv_entries. */ | | 355 | /* Fix up the kernel pmap to point at new pv_entries. */ |
356 | pmap = pmap_kernel(); | | 356 | pmap = pmap_kernel(); |
357 | for (lpn = 0; lpn < 1024; lpn++) | | 357 | for (lpn = 0; lpn < 1024; lpn++) |
358 | if (pmap->pm_entries[lpn] == | | 358 | if (pmap->pm_entries[lpn] == |
359 | old_pv_table + pmap->pm_entries[lpn]->pv_ppn) | | 359 | old_pv_table + pmap->pm_entries[lpn]->pv_ppn) |
360 | pmap->pm_entries[lpn] = | | 360 | pmap->pm_entries[lpn] = |
361 | pv_table + pmap->pm_entries[lpn]->pv_ppn; | | 361 | pv_table + pmap->pm_entries[lpn]->pv_ppn; |
362 | | | 362 | |
363 | uvm_pagefree(PHYS_TO_VM_PAGE( | | 363 | uvm_pagefree(PHYS_TO_VM_PAGE( |
| @@ -370,53 +370,54 @@ pmap_init2() | | | @@ -370,53 +370,54 @@ pmap_init2() |
370 | } | | 370 | } |
371 | | | 371 | |
372 | struct pmap * | | 372 | struct pmap * |
373 | pmap_create(void) | | 373 | pmap_create(void) |
374 | { | | 374 | { |
375 | struct pmap *pmap; | | 375 | struct pmap *pmap; |
376 | UVMHIST_FUNC("pmap_create"); | | 376 | UVMHIST_FUNC("pmap_create"); |
377 | | | 377 | |
378 | UVMHIST_CALLED(pmaphist); | | 378 | UVMHIST_CALLED(pmaphist); |
379 | if (!pmap_initialised) | | 379 | if (!pmap_initialised) |
380 | pmap_init2(); | | 380 | pmap_init2(); |
381 | pmap = pool_get(&pmap_pool, PR_WAITOK); | | 381 | pmap = pool_get(&pmap_pool, PR_WAITOK); |
382 | memset(pmap, 0, sizeof(*pmap)); | | 382 | memset(pmap, 0, sizeof(*pmap)); |
383 | pmap->pm_entries = (struct pv_entry **)malloc( | | 383 | pmap->pm_entries = (struct pv_entry **)kmem_zalloc( |
384 | sizeof(struct pv_entry *) * PM_NENTRIES, M_VMPMAP, | | 384 | sizeof(struct pv_entry *) * PM_NENTRIES, |
385 | M_WAITOK | M_ZERO); | | 385 | KM_SLEEP); |
386 | pmap->pm_count = 1; | | 386 | pmap->pm_count = 1; |
387 | return pmap; | | 387 | return pmap; |
388 | } | | 388 | } |
389 | | | 389 | |
390 | void | | 390 | void |
391 | pmap_destroy(pmap_t pmap) | | 391 | pmap_destroy(pmap_t pmap) |
392 | { | | 392 | { |
393 | #ifdef DIAGNOSTIC | | 393 | #ifdef DIAGNOSTIC |
394 | int i; | | 394 | int i; |
395 | #endif | | 395 | #endif |
396 | UVMHIST_FUNC("pmap_destroy"); | | 396 | UVMHIST_FUNC("pmap_destroy"); |
397 | | | 397 | |
398 | UVMHIST_CALLED(pmaphist); | | 398 | UVMHIST_CALLED(pmaphist); |
399 | if (--pmap->pm_count > 0) | | 399 | if (--pmap->pm_count > 0) |
400 | return; | | 400 | return; |
401 | KASSERT((pmap->pm_flags & PM_ACTIVE) == 0); | | 401 | KASSERT((pmap->pm_flags & PM_ACTIVE) == 0); |
402 | KASSERT(pmap->pm_stats.resident_count == 0); | | 402 | KASSERT(pmap->pm_stats.resident_count == 0); |
403 | KASSERT(pmap->pm_stats.wired_count == 0); | | 403 | KASSERT(pmap->pm_stats.wired_count == 0); |
404 | #ifdef DIAGNOSTIC | | 404 | #ifdef DIAGNOSTIC |
405 | for (i = 0; i < 1024; i++) | | 405 | for (i = 0; i < 1024; i++) |
406 | if (pmap->pm_entries[i] != NULL) | | 406 | if (pmap->pm_entries[i] != NULL) |
407 | panic("pmap_destroy: pmap isn't empty"); | | 407 | panic("pmap_destroy: pmap isn't empty"); |
408 | #endif | | 408 | #endif |
409 | free((void *)pmap->pm_entries, M_VMPMAP); | | 409 | kmem_free((void *)pmap->pm_entries, |
| | | 410 | sizeof(struct pv_entry *) * PM_NENTRIES); |
410 | pool_put(&pmap_pool, pmap); | | 411 | pool_put(&pmap_pool, pmap); |
411 | } | | 412 | } |
412 | | | 413 | |
413 | long | | 414 | long |
414 | _pmap_resident_count(pmap_t pmap) | | 415 | _pmap_resident_count(pmap_t pmap) |
415 | { | | 416 | { |
416 | | | 417 | |
417 | return pmap->pm_stats.resident_count; | | 418 | return pmap->pm_stats.resident_count; |
418 | } | | 419 | } |
419 | | | 420 | |
420 | long | | 421 | long |
421 | _pmap_wired_count(pmap_t pmap) | | 422 | _pmap_wired_count(pmap_t pmap) |
422 | { | | 423 | { |
| @@ -521,34 +522,34 @@ pv_update(struct pv_entry *pv) | | | @@ -521,34 +522,34 @@ pv_update(struct pv_entry *pv) |
521 | ppl = MEMC_PPL_RDONLY; | | 522 | ppl = MEMC_PPL_RDONLY; |
522 | else | | 523 | else |
523 | ppl = MEMC_PPL_NOACCESS; | | 524 | ppl = MEMC_PPL_NOACCESS; |
524 | } | | 525 | } |
525 | pv->pv_ppl = ppl; | | 526 | pv->pv_ppl = ppl; |
526 | pv->pv_activate = MEMC_TRANS_ENTRY_32K(pv->pv_ppn, pv->pv_lpn, ppl); | | 527 | pv->pv_activate = MEMC_TRANS_ENTRY_32K(pv->pv_ppn, pv->pv_lpn, ppl); |
527 | pv->pv_deactivate = PMAP_UNMAP_ENTRY_32K(pv->pv_ppn); | | 528 | pv->pv_deactivate = PMAP_UNMAP_ENTRY_32K(pv->pv_ppn); |
528 | } | | 529 | } |
529 | | | 530 | |
530 | | | 531 | |
531 | static struct pv_entry * | | 532 | static struct pv_entry * |
532 | pv_alloc(void) | | 533 | pv_alloc(void) |
533 | { | | 534 | { |
534 | return malloc(sizeof(struct pv_entry), M_VMPMAP, M_NOWAIT | M_ZERO); | | 535 | return kmem_intr_zalloc(sizeof(struct pv_entry), KM_NOSLEEP); |
535 | } | | 536 | } |
536 | | | 537 | |
537 | static void | | 538 | static void |
538 | pv_free(struct pv_entry *pv) | | 539 | pv_free(struct pv_entry *pv) |
539 | { | | 540 | { |
540 | | | 541 | |
541 | free(pv, M_VMPMAP); | | 542 | kmem_intr_free(pv, sizeof(struct pv_entry)); |
542 | } | | 543 | } |
543 | | | 544 | |
544 | static struct pv_entry * | | 545 | static struct pv_entry * |
545 | pv_get(pmap_t pmap, int ppn, int lpn) | | 546 | pv_get(pmap_t pmap, int ppn, int lpn) |
546 | { | | 547 | { |
547 | struct pv_entry *pv; | | 548 | struct pv_entry *pv; |
548 | UVMHIST_FUNC("pv_get"); | | 549 | UVMHIST_FUNC("pv_get"); |
549 | | | 550 | |
550 | UVMHIST_CALLED(pmaphist); | | 551 | UVMHIST_CALLED(pmaphist); |
551 | UVMHIST_LOG(pmaphist, "(pmap=%p, ppn=%d, lpn=%d)", pmap, ppn, lpn, 0); | | 552 | UVMHIST_LOG(pmaphist, "(pmap=%p, ppn=%d, lpn=%d)", pmap, ppn, lpn, 0); |
552 | /* If the head entry's free use that. */ | | 553 | /* If the head entry's free use that. */ |
553 | pv = &pv_table[ppn]; | | 554 | pv = &pv_table[ppn]; |
554 | if (pv->pv_pmap == NULL) { | | 555 | if (pv->pv_pmap == NULL) { |