Rev 1178 | Rev 1212 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 1178 | Rev 1191 | ||
|---|---|---|---|
| Line 109... | Line 109... | ||
| 109 | spinlock_unlock(&t->lock); |
109 | spinlock_unlock(&t->lock); |
| 110 | interrupts_restore(ipl); |
110 | interrupts_restore(ipl); |
| 111 | return 0; |
111 | return 0; |
| 112 | } |
112 | } |
| 113 | 113 | ||
| - | 114 | /** Enable range of I/O space for task. |
|
| - | 115 | * |
|
| - | 116 | * @param id Task ID of the destination task. |
|
| - | 117 | * @param ioaddr Starting I/O address. |
|
| - | 118 | * @param size Size of the enabled I/O space.. |
|
| - | 119 | * |
|
| - | 120 | * @return 0 on success, EPERM if the caller lacks capabilities to use this syscall, |
|
| - | 121 | * ENOENT if there is no task matching the specified ID. |
|
| - | 122 | */ |
|
| - | 123 | static int ddi_enable_iospace(task_id_t id, __address ioaddr, size_t size) |
|
| - | 124 | { |
|
| - | 125 | ipl_t ipl; |
|
| - | 126 | cap_t caps; |
|
| - | 127 | task_t *t; |
|
| - | 128 | int rc; |
|
| - | 129 | ||
| - | 130 | /* |
|
| - | 131 | * Make sure the caller is authorised to make this syscall. |
|
| - | 132 | */ |
|
| - | 133 | caps = cap_get(TASK); |
|
| - | 134 | if (!(caps & CAP_IO_MANAGER)) |
|
| - | 135 | return EPERM; |
|
| - | 136 | ||
| - | 137 | ipl = interrupts_disable(); |
|
| - | 138 | spinlock_lock(&tasks_lock); |
|
| - | 139 | ||
| - | 140 | t = task_find_by_id(id); |
|
| - | 141 | ||
| - | 142 | if (!t) { |
|
| - | 143 | /* |
|
| - | 144 | * There is no task with the specified ID. |
|
| - | 145 | */ |
|
| - | 146 | spinlock_unlock(&tasks_lock); |
|
| - | 147 | interrupts_restore(ipl); |
|
| - | 148 | return ENOENT; |
|
| - | 149 | } |
|
| - | 150 | ||
| - | 151 | /* |
|
| - | 152 | * TODO: We are currently lacking support for task destroying. |
|
| - | 153 | * Once it is added to the kernel, we must take care to |
|
| - | 154 | * synchronize in a way that prevents race conditions here. |
|
| - | 155 | */ |
|
| - | 156 | ||
| - | 157 | /* Lock the task and release the lock protecting tasks_btree. */ |
|
| - | 158 | spinlock_lock(&t->lock); |
|
| - | 159 | spinlock_unlock(&tasks_lock); |
|
| - | 160 | ||
| - | 161 | rc = ddi_enable_iospace_arch(t, ioaddr, size); |
|
| - | 162 | ||
| - | 163 | spinlock_unlock(&t->lock); |
|
| - | 164 | interrupts_restore(ipl); |
|
| - | 165 | return rc; |
|
| - | 166 | } |
|
| - | 167 | ||
| 114 | /** Wrapper for SYS_MAP_PHYSMEM syscall. |
168 | /** Wrapper for SYS_MAP_PHYSMEM syscall. |
| 115 | * |
169 | * |
| 116 | * @param User space address of DDI argument structure. |
170 | * @param User space address of memory DDI argument structure. |
| 117 | * |
171 | * |
| 118 | * @return 0 on success, otherwise it returns error code found in errno.h |
172 | * @return 0 on success, otherwise it returns error code found in errno.h |
| 119 | */ |
173 | */ |
| 120 | __native sys_map_physmem(ddi_arg_t *uspace_ddi_arg) |
174 | __native sys_map_physmem(ddi_memarg_t *uspace_mem_arg) |
| 121 | { |
175 | { |
| 122 | ddi_arg_t arg; |
176 | ddi_memarg_t arg; |
| 123 | 177 | ||
| 124 | copy_from_uspace(&arg, uspace_ddi_arg, sizeof(ddi_arg_t)); |
178 | copy_from_uspace(&arg, uspace_mem_arg, sizeof(ddi_memarg_t)); |
| 125 | return (__native) ddi_map_physmem((task_id_t) arg.task_id, ALIGN_DOWN((__address) arg.phys_base, FRAME_SIZE), |
179 | return (__native) ddi_map_physmem((task_id_t) arg.task_id, ALIGN_DOWN((__address) arg.phys_base, FRAME_SIZE), |
| 126 | ALIGN_DOWN((__address) arg.virt_base, PAGE_SIZE), (count_t) arg.pages, |
180 | ALIGN_DOWN((__address) arg.virt_base, PAGE_SIZE), (count_t) arg.pages, |
| 127 | (bool) arg.writable); |
181 | (bool) arg.writable); |
| 128 | } |
182 | } |
| - | 183 | ||
| - | 184 | /** Wrapper for SYS_ENABLE_IOSPACE syscall. |
|
| - | 185 | * |
|
| - | 186 | * @param User space address of DDI argument structure. |
|
| - | 187 | * |
|
| - | 188 | * @return 0 on success, otherwise it returns error code found in errno.h |
|
| - | 189 | */ |
|
| - | 190 | __native sys_enable_iospace(ddi_ioarg_t *uspace_io_arg) |
|
| - | 191 | { |
|
| - | 192 | ddi_ioarg_t arg; |
|
| - | 193 | ||
| - | 194 | copy_from_uspace(&arg, uspace_io_arg, sizeof(ddi_ioarg_t)); |
|
| - | 195 | return (__native) ddi_enable_iospace((task_id_t) arg.task_id, (__address) arg.ioaddr, (size_t) arg.size); |
|
| - | 196 | } |
|