Changeset 6f7071b in mainline for kernel/generic/src/ddi/ddi.c
- Timestamp:
- 2018-11-05T09:13:04Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4a8d0dd1
- Parents:
- 9c26ef0
- git-author:
- Jiri Svoboda <jiri@…> (2018-10-04 18:11:52)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-11-05 09:13:04)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/ddi/ddi.c
r9c26ef0 r6f7071b 49 49 #include <synch/mutex.h> 50 50 #include <syscall/copy.h> 51 #include <adt/ btree.h>51 #include <adt/odict.h> 52 52 #include <arch.h> 53 53 #include <align.h> 54 54 #include <errno.h> 55 #include <mem.h> 55 56 #include <trace.h> 56 57 #include <bitops.h> 57 58 58 /** This lock protects the parea_btree. */ 59 static mutex_t parea_lock; 60 61 /** B+tree with enabled physical memory areas. */ 62 static btree_t parea_btree; 59 /** This lock protects the @c pareas ordered dictionary. */ 60 static mutex_t pareas_lock; 61 62 /** Ordered dictionary of enabled physical memory areas by base address. */ 63 static odict_t pareas; 64 65 static void *pareas_getkey(odlink_t *); 66 static int pareas_cmp(void *, void *); 63 67 64 68 /** Initialize DDI. … … 67 71 void ddi_init(void) 68 72 { 69 btree_create(&parea_btree); 70 mutex_initialize(&parea_lock, MUTEX_PASSIVE); 73 odict_initialize(&pareas, pareas_getkey, pareas_cmp); 74 mutex_initialize(&pareas_lock, MUTEX_PASSIVE); 75 } 76 77 /** Initialize physical area structure. 78 * 79 * This should always be called first on the parea structure before 80 * filling in fields and calling ddi_parea_register. 81 * 82 * @param parea Pointer to physical area structure. 83 * 84 */ 85 void ddi_parea_init(parea_t *parea) 86 { 87 memset(parea, 0, sizeof(parea_t)); 71 88 } 72 89 … … 78 95 void ddi_parea_register(parea_t *parea) 79 96 { 80 mutex_lock(&parea _lock);97 mutex_lock(&pareas_lock); 81 98 82 99 /* 83 100 * We don't check for overlaps here as the kernel is pretty sane. 84 101 */ 85 btree_insert(&parea_btree, (btree_key_t) parea->pbase, parea, NULL);86 87 mutex_unlock(&parea _lock);102 odict_insert(&parea->lpareas, &pareas, NULL); 103 104 mutex_unlock(&pareas_lock); 88 105 } 89 106 … … 129 146 */ 130 147 131 mutex_lock(&parea _lock);132 btree_node_t *nodep;133 parea_t *parea = (parea_t *) btree_search(&parea_btree,134 (btree_key_t) phys, &nodep);148 mutex_lock(&pareas_lock); 149 odlink_t *odlink = odict_find_eq(&pareas, &phys, NULL); 150 parea_t *parea = odlink != NULL ? 151 odict_get_instance(odlink, parea_t, lpareas) : NULL; 135 152 136 153 if ((parea != NULL) && (parea->frames >= pages)) { 137 154 if ((!priv) && (!parea->unpriv)) { 138 mutex_unlock(&parea _lock);155 mutex_unlock(&pareas_lock); 139 156 return EPERM; 140 157 } … … 144 161 145 162 parea = NULL; 146 mutex_unlock(&parea _lock);163 mutex_unlock(&pareas_lock); 147 164 148 165 /* … … 193 210 194 211 if (parea != NULL) 195 mutex_unlock(&parea _lock);212 mutex_unlock(&pareas_lock); 196 213 197 214 return ENOMEM; … … 204 221 if (parea != NULL) { 205 222 parea->mapped = true; 206 mutex_unlock(&parea _lock);223 mutex_unlock(&pareas_lock); 207 224 } 208 225 … … 255 272 } 256 273 274 /** Get key function for the @c pareas ordered dictionary. 275 * 276 * @param odlink Link 277 * @return Pointer to base address cast as 'void *' 278 */ 279 static void *pareas_getkey(odlink_t *odlink) 280 { 281 parea_t *parea = odict_get_instance(odlink, parea_t, lpareas); 282 return (void *) &parea->pbase; 283 } 284 285 /** Key comparison function for the @c pareas ordered dictionary. 286 * 287 * @param a Pointer to parea A base 288 * @param b Pointer to parea B base 289 * @return -1, 0, 1 iff base of A is less than, equal to, greater than B 290 */ 291 static int pareas_cmp(void *a, void *b) 292 { 293 uintptr_t pa = *(uintptr_t *)a; 294 uintptr_t pb = *(uintptr_t *)b; 295 296 if (pa < pb) 297 return -1; 298 else if (pa == pb) 299 return 0; 300 else 301 return +1; 302 } 303 257 304 /** Enable range of I/O space for task. 258 305 * … … 288 335 } 289 336 290 /* Lock the task and release the lock protecting tasks _btree. */337 /* Lock the task and release the lock protecting tasks dictionary. */ 291 338 irq_spinlock_exchange(&tasks_lock, &task->lock); 292 339 errno_t rc = ddi_iospace_enable_arch(task, ioaddr, size); … … 329 376 } 330 377 331 /* Lock the task and release the lock protecting tasks _btree. */378 /* Lock the task and release the lock protecting tasks dictionary. */ 332 379 irq_spinlock_exchange(&tasks_lock, &task->lock); 333 380 errno_t rc = ddi_iospace_disable_arch(task, ioaddr, size);
Note:
See TracChangeset
for help on using the changeset viewer.