Changeset ae318d3 in mainline for kernel/generic/src/ddi/ddi.c
- Timestamp:
- 2009-02-16T18:50:48Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 06da55b
- Parents:
- 17f168e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/ddi/ddi.c
r17f168e rae318d3 48 48 #include <synch/spinlock.h> 49 49 #include <syscall/copy.h> 50 #include <adt/ btree.h>50 #include <adt/list.h> 51 51 #include <arch.h> 52 52 #include <align.h> … … 56 56 SPINLOCK_INITIALIZE(parea_lock); 57 57 58 /** B+tree with enabled physical memory areas. */ 59 static btree_t parea_btree; 58 /** List with enabled physical memory areas. */ 59 static LIST_INITIALIZE(parea_head); 60 61 /** Physical memory area for devices. */ 62 static parea_t dev_area; 60 63 61 64 /** Initialize DDI. */ 62 65 void ddi_init(void) 63 66 { 64 btree_create(&parea_btree); 67 hw_area(&dev_area.pbase, &dev_area.frames); 68 ddi_parea_register(&dev_area); 65 69 } 66 70 … … 75 79 { 76 80 ipl_t ipl; 77 81 78 82 ipl = interrupts_disable(); 79 83 spinlock_lock(&parea_lock); … … 81 85 /* 82 86 * TODO: we should really check for overlaps here. 83 * However, we should be safe because the kernel is pretty sane and84 * memory of different devices doesn't overlap.85 */86 btree_insert(&parea_btree, (btree_key_t) parea->pbase, parea, NULL);87 87 * However, we should be safe because the kernel is pretty sane. 88 */ 89 link_initialize(&parea->link); 90 list_append(&parea->link, &parea_head); 91 88 92 spinlock_unlock(&parea_lock); 89 interrupts_restore(ipl); 93 interrupts_restore(ipl); 90 94 } 91 95 … … 98 102 * 99 103 * @return 0 on success, EPERM if the caller lacks capabilities to use this 100 * 101 * 102 * 103 */ 104 static int ddi_physmem_map(uintptr_t pf, uintptr_t vp, count_t pages, int flags)104 * syscall, ENOENT if there is no task matching the specified ID or the 105 * physical address space is not enabled for mapping and ENOMEM if there 106 * was a problem in creating address space area. 107 */ 108 static int ddi_physmem_map(uintptr_t pf, uintptr_t vp, pfn_t pages, int flags) 105 109 { 106 110 ipl_t ipl; 107 111 cap_t caps; 108 112 mem_backend_data_t backend_data; 109 113 110 114 backend_data.base = pf; 111 115 backend_data.frames = pages; … … 117 121 if (!(caps & CAP_MEM_MANAGER)) 118 122 return EPERM; 119 123 120 124 ipl = interrupts_disable(); 121 125 122 126 /* 123 127 * Check if the physical memory area is enabled for mapping. 124 * If the architecture supports virtually indexed caches, intercept125 * attempts to create an illegal address alias.126 128 */ 127 129 spinlock_lock(&parea_lock); 128 parea_t *parea; 129 btree_node_t *nodep; 130 parea = (parea_t *) btree_search(&parea_btree, (btree_key_t) pf, &nodep); 131 if (!parea || parea->frames < pages || ((flags & AS_AREA_CACHEABLE) && 132 !parea->cacheable) || (!(flags & AS_AREA_CACHEABLE) && 133 parea->cacheable)) { 130 131 bool fnd = false; 132 link_t *cur; 133 134 for (cur = parea_head.next; cur != &parea_head; cur = cur->next) { 135 parea_t *parea = list_get_instance(cur, parea_t, link); 136 if ((parea->pbase <= pf) && (ADDR2PFN(pf - parea->pbase) + pages <= parea->frames)) { 137 fnd = true; 138 break; 139 } 140 } 141 142 spinlock_unlock(&parea_lock); 143 144 if (!fnd) { 134 145 /* 135 * This physical memory area cannot be mapped.146 * Physical memory area cannot be mapped. 136 147 */ 137 spinlock_unlock(&parea_lock);138 148 interrupts_restore(ipl); 139 149 return ENOENT; 140 150 } 141 spinlock_unlock(&parea_lock); 142 151 143 152 spinlock_lock(&TASK->lock); 144 153 … … 227 236 return (unative_t) ddi_physmem_map(ALIGN_DOWN((uintptr_t) phys_base, 228 237 FRAME_SIZE), ALIGN_DOWN((uintptr_t) virt_base, PAGE_SIZE), 229 ( count_t) pages, (int) flags);238 (pfn_t) pages, (int) flags); 230 239 } 231 240 … … 259 268 unative_t sys_preempt_control(int enable) 260 269 { 261 262 263 264 265 266 267 270 if (!cap_get(TASK) & CAP_PREEMPT_CONTROL) 271 return EPERM; 272 if (enable) 273 preemption_enable(); 274 else 275 preemption_disable(); 276 return 0; 268 277 } 269 278
Note:
See TracChangeset
for help on using the changeset viewer.