Rev 1461 | Rev 1483 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1461 | Rev 1468 | ||
---|---|---|---|
Line 119... | Line 119... | ||
119 | if (flags & FLAG_AS_KERNEL) |
119 | if (flags & FLAG_AS_KERNEL) |
120 | as->asid = ASID_KERNEL; |
120 | as->asid = ASID_KERNEL; |
121 | else |
121 | else |
122 | as->asid = ASID_INVALID; |
122 | as->asid = ASID_INVALID; |
123 | 123 | ||
- | 124 | as->refcount = 0; |
|
124 | as->cpu_refcount = 0; |
125 | as->cpu_refcount = 0; |
125 | as->page_table = page_table_create(flags); |
126 | as->page_table = page_table_create(flags); |
126 | 127 | ||
127 | return as; |
128 | return as; |
128 | } |
129 | } |
129 | 130 | ||
130 | /** Free Adress space */ |
131 | /** Destroy adress space. |
- | 132 | * |
|
- | 133 | * When there are no tasks referencing this address space (i.e. its refcount is zero), |
|
- | 134 | * the address space can be destroyed. |
|
- | 135 | */ |
|
131 | void as_free(as_t *as) |
136 | void as_destroy(as_t *as) |
132 | { |
137 | { |
- | 138 | ipl_t ipl; |
|
- | 139 | bool cond; |
|
- | 140 | ||
133 | ASSERT(as->cpu_refcount == 0); |
141 | ASSERT(as->refcount == 0); |
- | 142 | ||
- | 143 | /* |
|
- | 144 | * Since there is no reference to this area, |
|
- | 145 | * it is safe not to lock its mutex. |
|
- | 146 | */ |
|
- | 147 | ||
- | 148 | ipl = interrupts_disable(); |
|
- | 149 | spinlock_lock(&inactive_as_with_asid_lock); |
|
- | 150 | if (as->asid != ASID_INVALID && as->asid != ASID_KERNEL) { |
|
- | 151 | list_remove(&as->inactive_as_with_asid_link); |
|
- | 152 | asid_put(as->asid); |
|
- | 153 | } |
|
- | 154 | spinlock_unlock(&inactive_as_with_asid_lock); |
|
- | 155 | ||
- | 156 | /* |
|
- | 157 | * Destroy address space areas of the address space. |
|
- | 158 | */ |
|
- | 159 | for (cond = true; cond; ) { |
|
- | 160 | btree_node_t *node; |
|
- | 161 | ||
- | 162 | ASSERT(!list_empty(&as->as_area_btree.leaf_head)); |
|
- | 163 | node = list_get_instance(&as->as_area_btree.leaf_head.next, btree_node_t, leaf_link); |
|
- | 164 | if ((cond = node->keys)) { |
|
- | 165 | as_area_destroy(as, node->key[0]); |
|
- | 166 | btree_remove(&as->as_area_btree, node->key[0], node); |
|
- | 167 | } |
|
- | 168 | } |
|
- | 169 | ||
- | 170 | page_table_destroy(as->page_table); |
|
134 | 171 | ||
135 | /* TODO: free as_areas and other resources held by as */ |
- | |
136 | /* TODO: free page table */ |
172 | interrupts_restore(ipl); |
- | 173 | ||
137 | free(as); |
174 | free(as); |
138 | } |
175 | } |
139 | 176 | ||
140 | /** Create address space area of common attributes. |
177 | /** Create address space area of common attributes. |
141 | * |
178 | * |
Line 838... | Line 875... | ||
838 | ASSERT(as_operations->page_table_create); |
875 | ASSERT(as_operations->page_table_create); |
839 | 876 | ||
840 | return as_operations->page_table_create(flags); |
877 | return as_operations->page_table_create(flags); |
841 | } |
878 | } |
842 | 879 | ||
- | 880 | /** Destroy page table. |
|
- | 881 | * |
|
- | 882 | * Destroy page table in architecture specific way. |
|
- | 883 | * |
|
- | 884 | * @param page_table Physical address of PTL0. |
|
- | 885 | */ |
|
- | 886 | void page_table_destroy(pte_t *page_table) |
|
- | 887 | { |
|
- | 888 | ASSERT(as_operations); |
|
- | 889 | ASSERT(as_operations->page_table_destroy); |
|
- | 890 | ||
- | 891 | as_operations->page_table_destroy(page_table); |
|
- | 892 | } |
|
- | 893 | ||
843 | /** Lock page table. |
894 | /** Lock page table. |
844 | * |
895 | * |
845 | * This function should be called before any page_mapping_insert(), |
896 | * This function should be called before any page_mapping_insert(), |
846 | * page_mapping_remove() and page_mapping_find(). |
897 | * page_mapping_remove() and page_mapping_find(). |
847 | * |
898 | * |