Rev 687 | Rev 755 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
684 | jermar | 1 | /* |
2 | * Copyright (C) 2006 Jakub Jermar |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * - The name of the author may not be used to endorse or promote products |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
29 | #include <genarch/mm/page_ht.h> |
||
30 | #include <mm/page.h> |
||
31 | #include <mm/frame.h> |
||
699 | jermar | 32 | #include <mm/heap.h> |
687 | jermar | 33 | #include <arch/mm/asid.h> |
684 | jermar | 34 | #include <arch/types.h> |
35 | #include <typedefs.h> |
||
36 | #include <arch/asm.h> |
||
699 | jermar | 37 | #include <debug.h> |
684 | jermar | 38 | |
687 | jermar | 39 | static void ht_mapping_insert(__address page, asid_t asid, __address frame, int flags, __address root); |
40 | static pte_t *ht_mapping_find(__address page, asid_t asid, __address root); |
||
684 | jermar | 41 | |
42 | page_operations_t page_ht_operations = { |
||
43 | .mapping_insert = ht_mapping_insert, |
||
44 | .mapping_find = ht_mapping_find |
||
45 | }; |
||
46 | |||
47 | /** Map page to frame using page hash table. |
||
48 | * |
||
49 | * Map virtual address 'page' to physical address 'frame' |
||
50 | * using 'flags'. |
||
51 | * |
||
52 | * @param page Virtual address of the page to be mapped. |
||
687 | jermar | 53 | * @param asid Address space to which page belongs. |
684 | jermar | 54 | * @param frame Physical address of memory frame to which the mapping is done. |
55 | * @param flags Flags to be used for mapping. |
||
699 | jermar | 56 | * @param root Ignored. |
684 | jermar | 57 | */ |
699 | jermar | 58 | void ht_mapping_insert(__address page, asid_t asid, __address frame, int flags, __address root) |
684 | jermar | 59 | { |
699 | jermar | 60 | pte_t *t, *u = NULL; |
61 | |||
62 | t = HT_HASH(page, asid); |
||
63 | if (!HT_SLOT_EMPTY(t)) { |
||
64 | u = (pte_t *) malloc(sizeof(pte_t)); /* FIXME: use slab allocator for this */ |
||
65 | if (!u) |
||
66 | panic("could not allocate memory for hash table\n"); |
||
67 | *u = *t; |
||
68 | } |
||
69 | HT_SET_NEXT(t, u); |
||
70 | HT_SET_RECORD(t, page, asid, frame, flags); |
||
684 | jermar | 71 | } |
72 | |||
73 | /** Find mapping for virtual page in page hash table. |
||
74 | * |
||
75 | * Find mapping for virtual page. |
||
76 | * |
||
77 | * @param page Virtual page. |
||
687 | jermar | 78 | * @param asid Address space to wich page belongs. |
699 | jermar | 79 | * @param root Ignored. |
684 | jermar | 80 | * |
699 | jermar | 81 | * @return NULL if there is no such mapping; requested mapping otherwise. |
684 | jermar | 82 | */ |
687 | jermar | 83 | pte_t *ht_mapping_find(__address page, asid_t asid, __address root) |
684 | jermar | 84 | { |
699 | jermar | 85 | pte_t *t; |
86 | |||
87 | t = HT_HASH(page, asid); |
||
88 | while (!HT_COMPARE(page, asid, t) && HT_GET_NEXT(t)) |
||
89 | t = HT_GET_NEXT(t); |
||
90 | |||
91 | return HT_COMPARE(page, asid, t) ? t : NULL; |
||
684 | jermar | 92 | } |