Changes in / [7de1988c:ddd0499d] in mainline
- Files:
-
- 7 added
- 52 edited
Legend:
- Unmodified
- Added
- Removed
-
.bzrignore
r7de1988c rddd0499d 265 265 uspace/app/corecfg/corecfg 266 266 uspace/dist/app/corecfg 267 uspace/dist/srv/rfb 268 uspace/srv/hid/rfb/rfb 269 uspace/dist/srv/dhcp 270 uspace/srv/net/dhcp/dhcp -
boot/Makefile.common
r7de1988c rddd0499d 112 112 $(USPACE_PATH)/srv/hid/remcons/remcons \ 113 113 $(USPACE_PATH)/srv/hid/isdv4_tablet/isdv4_tablet \ 114 $(USPACE_PATH)/srv/hid/rfb/rfb \ 115 $(USPACE_PATH)/srv/net/dhcp/dhcp \ 114 116 $(USPACE_PATH)/srv/net/dnsrsrv/dnsrsrv \ 115 117 $(USPACE_PATH)/srv/net/ethip/ethip \ -
kernel/arch/abs32le/include/arch/mm/frame.h
r7de1988c rddd0499d 39 39 #define FRAME_SIZE (1 << FRAME_WIDTH) 40 40 41 #define FRAME_LOWPRIO 0 42 41 43 #include <typedefs.h> 42 44 -
kernel/arch/amd64/include/arch/mm/frame.h
r7de1988c rddd0499d 39 39 #define FRAME_SIZE (1 << FRAME_WIDTH) 40 40 41 #define FRAME_LOWPRIO 0x1000 42 41 43 #ifndef __ASM__ 42 44 -
kernel/arch/amd64/src/ddi/ddi.c
r7de1988c rddd0499d 68 68 */ 69 69 70 void *store = malloc(bitmap_size(elements , 0), FRAME_ATOMIC);70 void *store = malloc(bitmap_size(elements), FRAME_ATOMIC); 71 71 if (!store) 72 72 return ENOMEM; 73 73 74 74 bitmap_t oldiomap; 75 bitmap_initialize(&oldiomap, task->arch.iomap.elements, 0,75 bitmap_initialize(&oldiomap, task->arch.iomap.elements, 76 76 task->arch.iomap.bits); 77 77 78 bitmap_initialize(&task->arch.iomap, elements, 0,store);78 bitmap_initialize(&task->arch.iomap, elements, store); 79 79 80 80 /* … … 129 129 130 130 bitmap_t iomap; 131 bitmap_initialize(&iomap, TSS_IOMAP_SIZE * 8, 0,131 bitmap_initialize(&iomap, TSS_IOMAP_SIZE * 8, 132 132 CPU->arch.tss->iomap); 133 133 bitmap_copy(&iomap, &TASK->arch.iomap, elements); … … 157 157 158 158 descriptor_t *gdt_p = (descriptor_t *) cpugdtr.base; 159 size_t size = bitmap_size(elements , 0);159 size_t size = bitmap_size(elements); 160 160 gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + size); 161 161 gdtr_load(&cpugdtr); -
kernel/arch/amd64/src/proc/task.c
r7de1988c rddd0499d 46 46 { 47 47 task->arch.iomapver = 0; 48 bitmap_initialize(&task->arch.iomap, 0, 0,NULL);48 bitmap_initialize(&task->arch.iomap, 0, NULL); 49 49 } 50 50 -
kernel/arch/arm32/include/arch/mm/frame.h
r7de1988c rddd0499d 39 39 #define FRAME_WIDTH 12 /* 4KB frames */ 40 40 #define FRAME_SIZE (1 << FRAME_WIDTH) 41 42 #define FRAME_LOWPRIO 0 41 43 42 44 #ifndef __ASM__ -
kernel/arch/ia32/include/arch/mm/frame.h
r7de1988c rddd0499d 39 39 #define FRAME_SIZE (1 << FRAME_WIDTH) 40 40 41 #define FRAME_LOWPRIO 0x1000 42 41 43 #ifndef __ASM__ 42 44 -
kernel/arch/ia32/src/ddi/ddi.c
r7de1988c rddd0499d 68 68 */ 69 69 70 void *store = malloc(bitmap_size(elements , 0), FRAME_ATOMIC);70 void *store = malloc(bitmap_size(elements), FRAME_ATOMIC); 71 71 if (!store) 72 72 return ENOMEM; 73 73 74 74 bitmap_t oldiomap; 75 bitmap_initialize(&oldiomap, task->arch.iomap.elements, 0,75 bitmap_initialize(&oldiomap, task->arch.iomap.elements, 76 76 task->arch.iomap.bits); 77 77 78 bitmap_initialize(&task->arch.iomap, elements, 0,store);78 bitmap_initialize(&task->arch.iomap, elements, store); 79 79 80 80 /* … … 129 129 130 130 bitmap_t iomap; 131 bitmap_initialize(&iomap, TSS_IOMAP_SIZE * 8, 0,131 bitmap_initialize(&iomap, TSS_IOMAP_SIZE * 8, 132 132 CPU->arch.tss->iomap); 133 133 bitmap_copy(&iomap, &TASK->arch.iomap, elements); … … 157 157 158 158 descriptor_t *gdt_p = (descriptor_t *) cpugdtr.base; 159 size_t size = bitmap_size(elements , 0);159 size_t size = bitmap_size(elements); 160 160 gdt_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + size); 161 161 gdtr_load(&cpugdtr); -
kernel/arch/ia32/src/proc/task.c
r7de1988c rddd0499d 46 46 { 47 47 task->arch.iomapver = 0; 48 bitmap_initialize(&task->arch.iomap, 0, 0,NULL);48 bitmap_initialize(&task->arch.iomap, 0, NULL); 49 49 } 50 50 -
kernel/arch/ia64/include/arch/mm/frame.h
r7de1988c rddd0499d 39 39 #define FRAME_SIZE (1 << FRAME_WIDTH) 40 40 41 #define FRAME_LOWPRIO 0 42 41 43 #ifndef __ASM__ 42 44 -
kernel/arch/ia64/src/ddi/ddi.c
r7de1988c rddd0499d 1 1 /* 2 2 * Copyright (c) 2006 Jakub Jermar 3 * Copyright (c) 2008 Jakub vana3 * Copyright (c) 2008 Jakub Vana 4 4 * All rights reserved. 5 5 * … … 60 60 return ENOMEM; 61 61 62 void *store = malloc(bitmap_size(IO_MEMMAP_PAGES , 0), 0);62 void *store = malloc(bitmap_size(IO_MEMMAP_PAGES), 0); 63 63 if (store == NULL) 64 64 return ENOMEM; 65 65 66 bitmap_initialize(task->arch.iomap, IO_MEMMAP_PAGES, 0,store);66 bitmap_initialize(task->arch.iomap, IO_MEMMAP_PAGES, store); 67 67 bitmap_clear_range(task->arch.iomap, 0, IO_MEMMAP_PAGES); 68 68 } -
kernel/arch/mips32/include/arch/mm/frame.h
r7de1988c rddd0499d 39 39 #define FRAME_SIZE (1 << FRAME_WIDTH) 40 40 41 #define FRAME_LOWPRIO 0 42 41 43 #ifndef __ASM__ 42 44 -
kernel/arch/mips64/include/arch/mm/frame.h
r7de1988c rddd0499d 39 39 #define FRAME_SIZE (1 << FRAME_WIDTH) 40 40 41 #define FRAME_LOWPRIO 0 42 41 43 #ifndef __ASM__ 42 44 -
kernel/arch/ppc32/include/arch/mm/frame.h
r7de1988c rddd0499d 39 39 #define FRAME_SIZE (1 << FRAME_WIDTH) 40 40 41 #define FRAME_LOWPRIO 0 42 41 43 #ifndef __ASM__ 42 44 -
kernel/arch/sparc64/include/arch/mm/sun4u/frame.h
r7de1988c rddd0499d 27 27 */ 28 28 29 /** @addtogroup sparc64mm 29 /** @addtogroup sparc64mm 30 30 * @{ 31 31 */ … … 41 41 * Therefore, the kernel uses 8K only internally on the TLB and TSB levels. 42 42 */ 43 #define MMU_FRAME_WIDTH 13/* 8K */44 #define MMU_FRAME_SIZE 43 #define MMU_FRAME_WIDTH 13 /* 8K */ 44 #define MMU_FRAME_SIZE (1 << MMU_FRAME_WIDTH) 45 45 46 46 /* … … 49 49 * each 16K page with a pair of adjacent 8K pages. 50 50 */ 51 #define FRAME_WIDTH 14 /* 16K */ 52 #define FRAME_SIZE (1 << FRAME_WIDTH) 51 #define FRAME_WIDTH 14 /* 16K */ 52 #define FRAME_SIZE (1 << FRAME_WIDTH) 53 54 #define FRAME_LOWPRIO 0 53 55 54 56 #ifndef __ASM__ -
kernel/arch/sparc64/include/arch/mm/sun4v/frame.h
r7de1988c rddd0499d 27 27 */ 28 28 29 /** @addtogroup sparc64mm 29 /** @addtogroup sparc64mm 30 30 * @{ 31 31 */ … … 36 36 #define KERN_sparc64_sun4v_FRAME_H_ 37 37 38 #define MMU_FRAME_WIDTH 13/* 8K */39 #define MMU_FRAME_SIZE 38 #define MMU_FRAME_WIDTH 13 /* 8K */ 39 #define MMU_FRAME_SIZE (1 << MMU_FRAME_WIDTH) 40 40 41 #define FRAME_WIDTH 13 42 #define FRAME_SIZE (1 << FRAME_WIDTH) 41 #define FRAME_WIDTH 13 42 #define FRAME_SIZE (1 << FRAME_WIDTH) 43 44 #define FRAME_LOWPRIO 0 43 45 44 46 #endif -
kernel/generic/include/adt/bitmap.h
r7de1988c rddd0499d 44 44 size_t elements; 45 45 uint8_t *bits; 46 47 size_t block_size; 48 uint8_t *blocks; 46 size_t next_fit; 49 47 } bitmap_t; 50 48 … … 52 50 unsigned int value) 53 51 { 54 if (element < bitmap->elements) { 55 /* 56 * The 2nd level bitmap is conservative. 57 * Make sure we update it properly. 58 */ 59 60 if (value) { 61 bitmap->bits[element / BITMAP_ELEMENT] |= 62 (1 << (element & BITMAP_REMAINER)); 63 } else { 64 bitmap->bits[element / BITMAP_ELEMENT] &= 65 ~(1 << (element & BITMAP_REMAINER)); 66 67 if (bitmap->block_size > 0) { 68 size_t block = element / bitmap->block_size; 69 70 bitmap->blocks[block / BITMAP_ELEMENT] &= 71 ~(1 << (block & BITMAP_REMAINER)); 72 } 73 } 52 if (element >= bitmap->elements) 53 return; 54 55 size_t byte = element / BITMAP_ELEMENT; 56 uint8_t mask = 1 << (element & BITMAP_REMAINER); 57 58 if (value) { 59 bitmap->bits[byte] |= mask; 60 } else { 61 bitmap->bits[byte] &= ~mask; 62 bitmap->next_fit = byte; 74 63 } 75 64 } … … 80 69 return 0; 81 70 82 return !!((bitmap->bits)[element / BITMAP_ELEMENT] & 83 (1 << (element & BITMAP_REMAINER))); 71 size_t byte = element / BITMAP_ELEMENT; 72 uint8_t mask = 1 << (element & BITMAP_REMAINER); 73 74 return !!((bitmap->bits)[byte] & mask); 84 75 } 85 76 86 extern size_t bitmap_size(size_t , size_t);87 extern void bitmap_initialize(bitmap_t *, size_t, size_t,void *);77 extern size_t bitmap_size(size_t); 78 extern void bitmap_initialize(bitmap_t *, size_t, void *); 88 79 89 80 extern void bitmap_set_range(bitmap_t *, size_t, size_t); 90 81 extern void bitmap_clear_range(bitmap_t *, size_t, size_t); 91 82 92 extern int bitmap_allocate_range(bitmap_t *, size_t, size_t, size_t, size_t *);93 extern void bitmap_free_range(bitmap_t *, size_t, size_t);83 extern int bitmap_allocate_range(bitmap_t *, size_t, size_t, size_t, size_t, 84 size_t *); 94 85 extern void bitmap_copy(bitmap_t *, bitmap_t *, size_t); 95 86 -
kernel/generic/include/mm/frame.h
r7de1988c rddd0499d 131 131 extern void frame_init(void); 132 132 extern bool frame_adjust_zone_bounds(bool, uintptr_t *, size_t *); 133 extern uintptr_t frame_alloc_generic(size_t, frame_flags_t, uintptr_t, size_t *); 133 extern uintptr_t frame_alloc_generic(size_t, frame_flags_t, uintptr_t, 134 size_t *); 134 135 extern uintptr_t frame_alloc(size_t, frame_flags_t, uintptr_t); 135 extern uintptr_t frame_alloc_noreserve(size_t, frame_flags_t, uintptr_t);136 136 extern void frame_free_generic(uintptr_t, size_t, frame_flags_t); 137 137 extern void frame_free(uintptr_t, size_t); -
kernel/generic/src/adt/bitmap.c
r7de1988c rddd0499d 37 37 * setting and clearing ranges of bits and for finding ranges 38 38 * of unset bits. 39 *40 * The bitmap ADT can optionally implement a two-level hierarchy41 * for faster range searches. The second level bitmap (of blocks)42 * is not precise, but conservative. This means that if the block43 * bit is set, it guarantees that all bits in the block are set.44 * But if the block bit is unset, nothing can be said about the45 * bits in the block.46 *47 39 */ 48 40 … … 56 48 #define ALL_ZEROES 0x00 57 49 50 /** Unchecked version of bitmap_get() 51 * 52 * This version of bitmap_get() does not do any boundary checks. 53 * 54 * @param bitmap Bitmap to access. 55 * @param element Element to access. 56 * 57 * @return Bit value of the element in the bitmap. 58 * 59 */ 60 static unsigned int bitmap_get_fast(bitmap_t *bitmap, size_t element) 61 { 62 size_t byte = element / BITMAP_ELEMENT; 63 uint8_t mask = 1 << (element & BITMAP_REMAINER); 64 65 return !!((bitmap->bits)[byte] & mask); 66 } 67 58 68 /** Get bitmap size 59 69 * … … 61 71 * 62 72 * @param elements Number bits stored in bitmap. 63 * @param block_size Block size of the 2nd level bitmap.64 * If set to zero, no 2nd level is used.65 73 * 66 74 * @return Size (in bytes) required for the bitmap. 67 75 * 68 76 */ 69 size_t bitmap_size(size_t elements , size_t block_size)77 size_t bitmap_size(size_t elements) 70 78 { 71 79 size_t size = elements / BITMAP_ELEMENT; … … 74 82 size++; 75 83 76 if (block_size > 0) {77 size += elements / block_size;78 79 if ((elements % block_size) != 0)80 size++;81 }82 83 84 return size; 84 85 } … … 90 91 * @param bitmap Bitmap structure. 91 92 * @param elements Number of bits stored in bitmap. 92 * @param block_size Block size of the 2nd level bitmap.93 * If set to zero, no 2nd level is used.94 93 * @param data Address of the memory used to hold the map. 95 94 * The optional 2nd level bitmap follows the 1st … … 97 96 * 98 97 */ 99 void bitmap_initialize(bitmap_t *bitmap, size_t elements, size_t block_size, 100 void *data) 98 void bitmap_initialize(bitmap_t *bitmap, size_t elements, void *data) 101 99 { 102 100 bitmap->elements = elements; 103 101 bitmap->bits = (uint8_t *) data; 104 105 if (block_size > 0) { 106 bitmap->block_size = block_size; 107 bitmap->blocks = bitmap->bits + 108 bitmap_size(elements, 0); 109 } else { 110 bitmap->block_size = 0; 111 bitmap->blocks = NULL; 112 } 113 } 114 115 static void bitmap_set_range_internal(uint8_t *bits, size_t start, size_t count) 116 { 117 if (count == 0) 118 return; 119 120 size_t aligned_start = ALIGN_UP(start, BITMAP_ELEMENT); 121 122 /* Leading unaligned bits */ 123 size_t lub = min(aligned_start - start, count); 124 125 /* Aligned middle bits */ 126 size_t amb = (count > lub) ? (count - lub) : 0; 127 128 /* Trailing aligned bits */ 129 size_t tab = amb % BITMAP_ELEMENT; 130 131 if (start + count < aligned_start) { 132 /* Set bits in the middle of byte. */ 133 bits[start / BITMAP_ELEMENT] |= 134 ((1 << lub) - 1) << (start & BITMAP_REMAINER); 135 return; 136 } 137 138 if (lub) { 139 /* Make sure to set any leading unaligned bits. */ 140 bits[start / BITMAP_ELEMENT] |= 141 ~((1 << (BITMAP_ELEMENT - lub)) - 1); 142 } 143 144 size_t i; 145 146 for (i = 0; i < amb / BITMAP_ELEMENT; i++) { 147 /* The middle bits can be set byte by byte. */ 148 bits[aligned_start / BITMAP_ELEMENT + i] = ALL_ONES; 149 } 150 151 if (tab) { 152 /* Make sure to set any trailing aligned bits. */ 153 bits[aligned_start / BITMAP_ELEMENT + i] |= (1 << tab) - 1; 154 } 102 bitmap->next_fit = 0; 155 103 } 156 104 … … 166 114 ASSERT(start + count <= bitmap->elements); 167 115 168 bitmap_set_range_internal(bitmap->bits, start, count);169 170 if (bitmap->block_size > 0) {171 size_t aligned_start = ALIGN_UP(start, bitmap->block_size);172 173 /* Leading unaligned bits */174 size_t lub = min(aligned_start - start, count);175 176 /* Aligned middle bits */177 size_t amb = (count > lub) ? (count - lub) : 0;178 179 size_t aligned_size = amb / bitmap->block_size;180 181 bitmap_set_range_internal(bitmap->blocks, aligned_start,182 aligned_size);183 }184 }185 186 static void bitmap_clear_range_internal(uint8_t *bits, size_t start,187 size_t count)188 {189 116 if (count == 0) 190 117 return; 191 118 119 size_t start_byte = start / BITMAP_ELEMENT; 192 120 size_t aligned_start = ALIGN_UP(start, BITMAP_ELEMENT); 193 121 … … 202 130 203 131 if (start + count < aligned_start) { 204 /* Set bits in the middle of byte */205 bit s[start / BITMAP_ELEMENT] &=206 ~(((1 << lub) - 1) << (start & BITMAP_REMAINER));132 /* Set bits in the middle of byte. */ 133 bitmap->bits[start_byte] |= 134 ((1 << lub) - 1) << (start & BITMAP_REMAINER); 207 135 return; 208 136 } 209 137 210 138 if (lub) { 211 /* Make sure to clearany leading unaligned bits. */212 bit s[start / BITMAP_ELEMENT] &=213 (1 << (BITMAP_ELEMENT - lub)) - 1;139 /* Make sure to set any leading unaligned bits. */ 140 bitmap->bits[start_byte] |= 141 ~((1 << (BITMAP_ELEMENT - lub)) - 1); 214 142 } 215 143 … … 217 145 218 146 for (i = 0; i < amb / BITMAP_ELEMENT; i++) { 219 /* The middle bits can be cleared byte by byte. */ 220 bits[aligned_start / BITMAP_ELEMENT + i] = ALL_ZEROES; 147 /* The middle bits can be set byte by byte. */ 148 bitmap->bits[aligned_start / BITMAP_ELEMENT + i] = 149 ALL_ONES; 221 150 } 222 151 223 152 if (tab) { 224 /* Make sure to clear any trailing aligned bits. */ 225 bits[aligned_start / BITMAP_ELEMENT + i] &= ~((1 << tab) - 1); 153 /* Make sure to set any trailing aligned bits. */ 154 bitmap->bits[aligned_start / BITMAP_ELEMENT + i] |= 155 (1 << tab) - 1; 226 156 } 227 157 } … … 238 168 ASSERT(start + count <= bitmap->elements); 239 169 240 bitmap_clear_range_internal(bitmap->bits, start, count); 241 242 if (bitmap->block_size > 0) { 243 size_t aligned_start = start / bitmap->block_size; 244 245 size_t aligned_end = (start + count) / bitmap->block_size; 246 247 if (((start + count) % bitmap->block_size) != 0) 248 aligned_end++; 249 250 size_t aligned_size = aligned_end - aligned_start; 251 252 bitmap_clear_range_internal(bitmap->blocks, aligned_start, 253 aligned_size); 254 } 170 if (count == 0) 171 return; 172 173 size_t start_byte = start / BITMAP_ELEMENT; 174 size_t aligned_start = ALIGN_UP(start, BITMAP_ELEMENT); 175 176 /* Leading unaligned bits */ 177 size_t lub = min(aligned_start - start, count); 178 179 /* Aligned middle bits */ 180 size_t amb = (count > lub) ? (count - lub) : 0; 181 182 /* Trailing aligned bits */ 183 size_t tab = amb % BITMAP_ELEMENT; 184 185 if (start + count < aligned_start) { 186 /* Set bits in the middle of byte */ 187 bitmap->bits[start_byte] &= 188 ~(((1 << lub) - 1) << (start & BITMAP_REMAINER)); 189 return; 190 } 191 192 if (lub) { 193 /* Make sure to clear any leading unaligned bits. */ 194 bitmap->bits[start_byte] &= 195 (1 << (BITMAP_ELEMENT - lub)) - 1; 196 } 197 198 size_t i; 199 200 for (i = 0; i < amb / BITMAP_ELEMENT; i++) { 201 /* The middle bits can be cleared byte by byte. */ 202 bitmap->bits[aligned_start / BITMAP_ELEMENT + i] = 203 ALL_ZEROES; 204 } 205 206 if (tab) { 207 /* Make sure to clear any trailing aligned bits. */ 208 bitmap->bits[aligned_start / BITMAP_ELEMENT + i] &= 209 ~((1 << tab) - 1); 210 } 211 212 bitmap->next_fit = start_byte; 255 213 } 256 214 … … 300 258 * @param count Number of continuous zero bits to find. 301 259 * @param base Address of the first bit in the bitmap. 260 * @param prefered Prefered address to start searching from. 302 261 * @param constraint Constraint for the address of the first zero bit. 303 262 * @param index Place to store the index of the first zero … … 311 270 */ 312 271 int bitmap_allocate_range(bitmap_t *bitmap, size_t count, size_t base, 313 size_t constraint, size_t *index)272 size_t prefered, size_t constraint, size_t *index) 314 273 { 315 274 if (count == 0) 316 275 return false; 317 276 277 size_t size = bitmap_size(bitmap->elements); 278 size_t next_fit = bitmap->next_fit; 279 318 280 /* 319 * This is a trivial implementation that should be320 * optimized further.281 * Adjust the next-fit value according to the address 282 * the caller prefers to start the search at. 321 283 */ 322 323 for (size_t i = 0; i < bitmap->elements; i++) { 324 if (!constraint_satisfy(i, base, constraint)) 284 if ((prefered > base) && (prefered < base + bitmap->elements)) { 285 size_t prefered_fit = (prefered - base) / BITMAP_ELEMENT; 286 287 if (prefered_fit > next_fit) 288 next_fit = prefered_fit; 289 } 290 291 for (size_t pos = 0; pos < size; pos++) { 292 size_t byte = (next_fit + pos) % size; 293 294 /* Skip if the current byte has all bits set */ 295 if (bitmap->bits[byte] == ALL_ONES) 325 296 continue; 326 297 327 if (!bitmap_get(bitmap, i)) { 328 bool continuous = true; 298 size_t byte_bit = byte * BITMAP_ELEMENT; 299 300 for (size_t bit = 0; bit < BITMAP_ELEMENT; bit++) { 301 size_t i = byte_bit + bit; 329 302 330 for (size_t j = 1; j < count; j++) { 331 if ((i + j >= bitmap->elements) || 332 (bitmap_get(bitmap, i + j))) { 333 continuous = false; 334 break; 335 } 336 } 303 if (i >= bitmap->elements) 304 break; 337 305 338 if (continuous) { 339 if (index != NULL) { 340 bitmap_set_range(bitmap, i, count); 341 *index = i; 306 if (!constraint_satisfy(i, base, constraint)) 307 continue; 308 309 if (!bitmap_get_fast(bitmap, i)) { 310 size_t continuous = 1; 311 312 for (size_t j = 1; j < count; j++) { 313 if ((i + j < bitmap->elements) && 314 (!bitmap_get_fast(bitmap, i + j))) 315 continuous++; 316 else 317 break; 342 318 } 343 319 344 return true; 320 if (continuous == count) { 321 if (index != NULL) { 322 bitmap_set_range(bitmap, i, count); 323 bitmap->next_fit = i / BITMAP_ELEMENT; 324 *index = i; 325 } 326 327 return true; 328 } else 329 i += continuous; 345 330 } 346 331 } 347 348 332 } 349 333 … … 351 335 } 352 336 353 /** Clear range of set bits.354 *355 * This is essentially bitmap_clear_range(), but it also356 * checks whether all the cleared bits are actually set.357 *358 * @param bitmap Bitmap structure.359 * @param start Starting bit.360 * @param count Number of bits to clear.361 *362 */363 void bitmap_free_range(bitmap_t *bitmap, size_t start, size_t count)364 {365 /*366 * This is a trivial implementation that should be367 * optimized further.368 */369 370 for (size_t i = 0; i < count; i++) {371 if (!bitmap_get(bitmap, start + i))372 panic("Freeing a bitmap range that is not set");373 }374 375 bitmap_clear_range(bitmap, start, count);376 }377 378 337 /** @} 379 338 */ -
kernel/generic/src/ddi/ddi.c
r7de1988c rddd0499d 329 329 330 330 size_t frames = SIZE2FRAMES(size); 331 *phys = frame_alloc _noreserve(frames, 0, constraint);331 *phys = frame_alloc(frames, FRAME_NO_RESERVE, constraint); 332 332 if (*phys == 0) 333 333 return ENOMEM; -
kernel/generic/src/mm/frame.c
r7de1988c rddd0499d 60 60 #include <config.h> 61 61 #include <str.h> 62 63 #define BITMAP_BLOCK_SIZE 102464 62 65 63 zones_t zones; … … 236 234 * the bitmap if the last argument is NULL. 237 235 */ 236 238 237 return ((zone->flags & ZONE_AVAILABLE) && 239 238 bitmap_allocate_range(&zone->bitmap, count, zone->base, 240 constraint, NULL)); 239 FRAME_LOWPRIO, constraint, NULL)); 240 } 241 242 /** Find a zone that can allocate specified number of frames 243 * 244 * This function searches among all zones. Assume interrupts are 245 * disabled and zones lock is locked. 246 * 247 * @param count Number of free frames we are trying to find. 248 * @param flags Required flags of the zone. 249 * @param constraint Indication of bits that cannot be set in the 250 * physical frame number of the first allocated frame. 251 * @param hint Preferred zone. 252 * 253 * @return Zone that can allocate specified number of frames. 254 * @return -1 if no zone can satisfy the request. 255 * 256 */ 257 NO_TRACE static size_t find_free_zone_all(size_t count, zone_flags_t flags, 258 pfn_t constraint, size_t hint) 259 { 260 for (size_t pos = 0; pos < zones.count; pos++) { 261 size_t i = (pos + hint) % zones.count; 262 263 /* Check whether the zone meets the search criteria. */ 264 if (!ZONE_FLAGS_MATCH(zones.info[i].flags, flags)) 265 continue; 266 267 /* Check if the zone can satisfy the allocation request. */ 268 if (zone_can_alloc(&zones.info[i], count, constraint)) 269 return i; 270 } 271 272 return (size_t) -1; 273 } 274 275 /** Check if frame range priority memory 276 * 277 * @param pfn Starting frame. 278 * @param count Number of frames. 279 * 280 * @return True if the range contains only priority memory. 281 * 282 */ 283 NO_TRACE static bool is_high_priority(pfn_t base, size_t count) 284 { 285 return (base + count <= FRAME_LOWPRIO); 286 } 287 288 /** Find a zone that can allocate specified number of frames 289 * 290 * This function ignores zones that contain only high-priority 291 * memory. Assume interrupts are disabled and zones lock is locked. 292 * 293 * @param count Number of free frames we are trying to find. 294 * @param flags Required flags of the zone. 295 * @param constraint Indication of bits that cannot be set in the 296 * physical frame number of the first allocated frame. 297 * @param hint Preferred zone. 298 * 299 * @return Zone that can allocate specified number of frames. 300 * @return -1 if no low-priority zone can satisfy the request. 301 * 302 */ 303 NO_TRACE static size_t find_free_zone_lowprio(size_t count, zone_flags_t flags, 304 pfn_t constraint, size_t hint) 305 { 306 for (size_t pos = 0; pos < zones.count; pos++) { 307 size_t i = (pos + hint) % zones.count; 308 309 /* Skip zones containing only high-priority memory. */ 310 if (is_high_priority(zones.info[i].base, zones.info[i].count)) 311 continue; 312 313 /* Check whether the zone meets the search criteria. */ 314 if (!ZONE_FLAGS_MATCH(zones.info[i].flags, flags)) 315 continue; 316 317 /* Check if the zone can satisfy the allocation request. */ 318 if (zone_can_alloc(&zones.info[i], count, constraint)) 319 return i; 320 } 321 322 return (size_t) -1; 241 323 } 242 324 … … 250 332 * @param constraint Indication of bits that cannot be set in the 251 333 * physical frame number of the first allocated frame. 252 * @param hind Preferred zone. 334 * @param hint Preferred zone. 335 * 336 * @return Zone that can allocate specified number of frames. 337 * @return -1 if no zone can satisfy the request. 253 338 * 254 339 */ … … 259 344 hint = 0; 260 345 261 size_t i = hint; 262 do { 263 /* 264 * Check whether the zone meets the search criteria. 265 */ 266 if (ZONE_FLAGS_MATCH(zones.info[i].flags, flags)) { 267 /* 268 * Check if the zone can satisfy the allocation request. 269 */ 270 if (zone_can_alloc(&zones.info[i], count, constraint)) 271 return i; 272 } 273 274 i++; 275 if (i >= zones.count) 276 i = 0; 277 278 } while (i != hint); 279 280 return (size_t) -1; 346 /* 347 * Prefer zones with low-priority memory over 348 * zones with high-priority memory. 349 */ 350 351 size_t znum = find_free_zone_lowprio(count, flags, constraint, hint); 352 if (znum != (size_t) -1) 353 return znum; 354 355 /* Take all zones into account */ 356 return find_free_zone_all(count, flags, constraint, hint); 281 357 } 282 358 … … 314 390 size_t index; 315 391 int avail = bitmap_allocate_range(&zone->bitmap, count, zone->base, 316 constraint, &index);392 FRAME_LOWPRIO, constraint, &index); 317 393 318 394 ASSERT(avail); … … 352 428 353 429 if (!--frame->refcount) { 354 bitmap_ free_range(&zone->bitmap, index, 1);430 bitmap_set(&zone->bitmap, index, 0); 355 431 356 432 /* Update zone information. */ … … 410 486 411 487 bitmap_initialize(&zones.info[z1].bitmap, zones.info[z1].count, 412 BITMAP_BLOCK_SIZE, confdata + 413 (sizeof(frame_t) * zones.info[z1].count)); 488 confdata + (sizeof(frame_t) * zones.info[z1].count)); 414 489 bitmap_clear_range(&zones.info[z1].bitmap, 0, zones.info[z1].count); 415 490 … … 578 653 */ 579 654 580 bitmap_initialize(&zone->bitmap, count, BITMAP_BLOCK_SIZE,581 confdata +(sizeof(frame_t) * count));655 bitmap_initialize(&zone->bitmap, count, confdata + 656 (sizeof(frame_t) * count)); 582 657 bitmap_clear_range(&zone->bitmap, 0, count); 583 658 … … 591 666 frame_initialize(&zone->frames[i]); 592 667 } else { 593 bitmap_initialize(&zone->bitmap, 0, 0,NULL);668 bitmap_initialize(&zone->bitmap, 0, NULL); 594 669 zone->frames = NULL; 595 670 } … … 605 680 size_t zone_conf_size(size_t count) 606 681 { 607 return (count * sizeof(frame_t) + 608 bitmap_size(count, BITMAP_BLOCK_SIZE)); 682 return (count * sizeof(frame_t) + bitmap_size(count)); 609 683 } 610 684 … … 887 961 } 888 962 889 uintptr_t frame_alloc_noreserve(size_t count, frame_flags_t flags,890 uintptr_t constraint)891 {892 return frame_alloc_generic(count, flags | FRAME_NO_RESERVE, constraint,893 NULL);894 }895 896 963 /** Free frames of physical memory. 897 964 * … … 1141 1208 /* 1142 1209 * Because printing may require allocation of memory, we may not hold 1143 * the frame allocator locks when printing zone statistics. 1210 * the frame allocator locks when printing zone statistics. Therefore, 1144 1211 * we simply gather the statistics under the protection of the locks and 1145 1212 * print the statistics when the locks have been released. … … 1150 1217 */ 1151 1218 1219 size_t free_lowmem = 0; 1220 size_t free_highmem = 0; 1221 size_t free_highprio = 0; 1222 1152 1223 for (size_t i = 0;; i++) { 1153 1224 irq_spinlock_lock(&zones.lock, true); … … 1158 1229 } 1159 1230 1160 uintptr_t base = PFN2ADDR(zones.info[i].base); 1231 pfn_t fbase = zones.info[i].base; 1232 uintptr_t base = PFN2ADDR(fbase); 1161 1233 size_t count = zones.info[i].count; 1162 1234 zone_flags_t flags = zones.info[i].flags; … … 1164 1236 size_t busy_count = zones.info[i].busy_count; 1165 1237 1238 bool available = ((flags & ZONE_AVAILABLE) != 0); 1239 bool lowmem = ((flags & ZONE_LOWMEM) != 0); 1240 bool highmem = ((flags & ZONE_HIGHMEM) != 0); 1241 bool highprio = is_high_priority(fbase, count); 1242 1243 if (available) { 1244 if (lowmem) 1245 free_lowmem += free_count; 1246 1247 if (highmem) 1248 free_highmem += free_count; 1249 1250 if (highprio) { 1251 free_highprio += free_count; 1252 } else { 1253 /* 1254 * Walk all frames of the zone and examine 1255 * all high priority memory to get accurate 1256 * statistics. 1257 */ 1258 1259 for (size_t index = 0; index < count; index++) { 1260 if (is_high_priority(fbase + index, 0)) { 1261 if (!bitmap_get(&zones.info[i].bitmap, index)) 1262 free_highprio++; 1263 } else 1264 break; 1265 } 1266 } 1267 } 1268 1166 1269 irq_spinlock_unlock(&zones.lock, true); 1167 1168 bool available = ((flags & ZONE_AVAILABLE) != 0);1169 1270 1170 1271 printf("%-4zu", i); … … 1191 1292 printf("\n"); 1192 1293 } 1294 1295 printf("\n"); 1296 1297 uint64_t size; 1298 const char *size_suffix; 1299 1300 bin_order_suffix(FRAMES2SIZE(free_lowmem), &size, &size_suffix, 1301 false); 1302 printf("Available low memory: %zu frames (%" PRIu64 " %s)\n", 1303 free_lowmem, size, size_suffix); 1304 1305 bin_order_suffix(FRAMES2SIZE(free_highmem), &size, &size_suffix, 1306 false); 1307 printf("Available high memory: %zu frames (%" PRIu64 " %s)\n", 1308 free_highmem, size, size_suffix); 1309 1310 bin_order_suffix(FRAMES2SIZE(free_highprio), &size, &size_suffix, 1311 false); 1312 printf("Available high priority: %zu frames (%" PRIu64 " %s)\n", 1313 free_highprio, size, size_suffix); 1193 1314 } 1194 1315 … … 1216 1337 } 1217 1338 1218 uintptr_t base = PFN2ADDR(zones.info[znum].base); 1339 size_t free_lowmem = 0; 1340 size_t free_highmem = 0; 1341 size_t free_highprio = 0; 1342 1343 pfn_t fbase = zones.info[znum].base; 1344 uintptr_t base = PFN2ADDR(fbase); 1219 1345 zone_flags_t flags = zones.info[znum].flags; 1220 1346 size_t count = zones.info[znum].count; … … 1222 1348 size_t busy_count = zones.info[znum].busy_count; 1223 1349 1350 bool available = ((flags & ZONE_AVAILABLE) != 0); 1351 bool lowmem = ((flags & ZONE_LOWMEM) != 0); 1352 bool highmem = ((flags & ZONE_HIGHMEM) != 0); 1353 bool highprio = is_high_priority(fbase, count); 1354 1355 if (available) { 1356 if (lowmem) 1357 free_lowmem = free_count; 1358 1359 if (highmem) 1360 free_highmem = free_count; 1361 1362 if (highprio) { 1363 free_highprio = free_count; 1364 } else { 1365 /* 1366 * Walk all frames of the zone and examine 1367 * all high priority memory to get accurate 1368 * statistics. 1369 */ 1370 1371 for (size_t index = 0; index < count; index++) { 1372 if (is_high_priority(fbase + index, 0)) { 1373 if (!bitmap_get(&zones.info[znum].bitmap, index)) 1374 free_highprio++; 1375 } else 1376 break; 1377 } 1378 } 1379 } 1380 1224 1381 irq_spinlock_unlock(&zones.lock, true); 1225 1226 bool available = ((flags & ZONE_AVAILABLE) != 0);1227 1382 1228 1383 uint64_t size; 1229 1384 const char *size_suffix; 1385 1230 1386 bin_order_suffix(FRAMES2SIZE(count), &size, &size_suffix, false); 1231 1387 1232 printf("Zone number: %zu\n", znum);1233 printf("Zone base address: %p\n", (void *) base);1234 printf("Zone size: %zu frames (%" PRIu64 " %s)\n", count,1388 printf("Zone number: %zu\n", znum); 1389 printf("Zone base address: %p\n", (void *) base); 1390 printf("Zone size: %zu frames (%" PRIu64 " %s)\n", count, 1235 1391 size, size_suffix); 1236 printf("Zone flags: %c%c%c%c%c\n",1392 printf("Zone flags: %c%c%c%c%c\n", 1237 1393 available ? 'A' : '-', 1238 1394 (flags & ZONE_RESERVED) ? 'R' : '-', … … 1244 1400 bin_order_suffix(FRAMES2SIZE(busy_count), &size, &size_suffix, 1245 1401 false); 1246 printf("Allocated space: %zu frames (%" PRIu64 " %s)\n",1402 printf("Allocated space: %zu frames (%" PRIu64 " %s)\n", 1247 1403 busy_count, size, size_suffix); 1404 1248 1405 bin_order_suffix(FRAMES2SIZE(free_count), &size, &size_suffix, 1249 1406 false); 1250 printf("Available space: %zu frames (%" PRIu64 " %s)\n",1407 printf("Available space: %zu frames (%" PRIu64 " %s)\n", 1251 1408 free_count, size, size_suffix); 1409 1410 bin_order_suffix(FRAMES2SIZE(free_lowmem), &size, &size_suffix, 1411 false); 1412 printf("Available low memory: %zu frames (%" PRIu64 " %s)\n", 1413 free_lowmem, size, size_suffix); 1414 1415 bin_order_suffix(FRAMES2SIZE(free_highmem), &size, &size_suffix, 1416 false); 1417 printf("Available high memory: %zu frames (%" PRIu64 " %s)\n", 1418 free_highmem, size, size_suffix); 1419 1420 bin_order_suffix(FRAMES2SIZE(free_highprio), &size, &size_suffix, 1421 false); 1422 printf("Available high priority: %zu frames (%" PRIu64 " %s)\n", 1423 free_highprio, size, size_suffix); 1252 1424 } 1253 1425 } -
uspace/Makefile
r7de1988c rddd0499d 90 90 srv/devman \ 91 91 srv/loader \ 92 srv/net/dhcp \ 92 93 srv/net/dnsrsrv \ 93 94 srv/net/ethip \ … … 121 122 srv/hid/remcons \ 122 123 srv/hw/char/s3c24xx_uart \ 124 srv/hid/rfb \ 123 125 drv/audio/sb16 \ 124 126 drv/infrastructure/root \ -
uspace/app/sportdmp/sportdmp.c
r7de1988c rddd0499d 44 44 sysarg_t baud = 9600; 45 45 service_id_t svc_id; 46 46 47 47 int arg = 1; 48 48 int rc; 49 49 50 50 if (argc > arg && str_test_prefix(argv[arg], "--baud=")) { 51 51 size_t arg_offset = str_lsize(argv[arg], 7); … … 65 65 arg++; 66 66 } 67 67 68 68 if (argc > arg) { 69 69 rc = loc_service_get_id(argv[arg], &svc_id, 0); … … 77 77 else { 78 78 category_id_t serial_cat_id; 79 79 80 80 rc = loc_category_get_id("serial", &serial_cat_id, 0); 81 81 if (rc != EOK) { … … 84 84 return 1; 85 85 } 86 86 87 87 service_id_t *svc_ids; 88 88 size_t svc_count; 89 90 rc = loc_category_get_svcs(serial_cat_id, &svc_ids, &svc_count); if (rc != EOK) { 89 90 rc = loc_category_get_svcs(serial_cat_id, &svc_ids, &svc_count); 91 if (rc != EOK) { 91 92 fprintf(stderr, "Failed getting list of services\n"); 92 93 return 1; 93 94 } 94 95 95 96 if (svc_count == 0) { 96 97 fprintf(stderr, "No service in category 'serial'\n"); … … 98 99 return 1; 99 100 } 100 101 101 102 svc_id = svc_ids[0]; 102 103 free(svc_ids); 103 104 } 104 105 105 106 if (argc > arg) { 106 107 fprintf(stderr, "Too many arguments\n"); … … 108 109 return 1; 109 110 } 110 111 111 112 112 113 async_sess_t *sess = loc_service_connect(EXCHANGE_SERIALIZE, svc_id, 113 114 IPC_FLAG_BLOCKING); … … 115 116 fprintf(stderr, "Failed connecting to service\n"); 116 117 } 117 118 118 119 async_exch_t *exch = async_exchange_begin(sess); 119 120 rc = async_req_4_0(exch, SERIAL_SET_COM_PROPS, baud, 120 121 SERIAL_NO_PARITY, 8, 1); 121 122 async_exchange_end(exch); 122 123 123 124 if (rc != EOK) { 124 125 fprintf(stderr, "Failed setting serial properties\n"); 125 126 return 2; 126 127 } 127 128 128 129 uint8_t *buf = (uint8_t *) malloc(BUF_SIZE); 129 130 if (buf == NULL) { … … 131 132 return 3; 132 133 } 133 134 134 135 while (true) { 135 136 ssize_t read = char_dev_read(sess, buf, BUF_SIZE); … … 144 145 fflush(stdout); 145 146 } 146 147 147 148 free(buf); 148 149 return 0; 149 150 } 151 -
uspace/drv/audio/sb16/dsp.c
r7de1988c rddd0499d 180 180 void *buffer = NULL; 181 181 182 int ret = dmamem_map_anonymous(size, DMAMEM_16MiB ,182 int ret = dmamem_map_anonymous(size, DMAMEM_16MiB | 0x0000ffff, 183 183 AS_AREA_WRITE | AS_AREA_READ, 0, &pa, &buffer); 184 184 if (ret != EOK) { -
uspace/lib/c/generic/inet.c
r7de1988c rddd0499d 111 111 112 112 ipc_call_t answer; 113 aid_t req = async_send_ 3(exch, INET_SEND, dgram->tos, ttl, df,114 &answer);113 aid_t req = async_send_4(exch, INET_SEND, dgram->iplink, dgram->tos, 114 ttl, df, &answer); 115 115 116 116 int rc = async_data_write_start(exch, &dgram->src, sizeof(inet_addr_t)); -
uspace/lib/c/generic/inet/addr.c
r7de1988c rddd0499d 47 47 #error The architecture must be either big-endian or little-endian. 48 48 #endif 49 50 const addr32_t addr32_broadcast_all_hosts = 0xffffffff; 49 51 50 52 const addr48_t addr48_broadcast = { -
uspace/lib/c/generic/net/socket_client.c
r7de1988c rddd0499d 923 923 * message. 924 924 */ 925 int send(int socket_id, void *data, size_t datalength, int flags)925 int send(int socket_id, const void *data, size_t datalength, int flags) 926 926 { 927 927 /* Without the address */ -
uspace/lib/c/include/inet/addr.h
r7de1988c rddd0499d 68 68 } inet_naddr_t; 69 69 70 extern const addr32_t addr32_broadcast_all_hosts; 70 71 extern const addr48_t addr48_broadcast; 71 72 -
uspace/lib/c/include/inet/inet.h
r7de1988c rddd0499d 37 37 38 38 #include <inet/addr.h> 39 #include <ipc/loc.h> 39 40 #include <sys/types.h> 40 41 … … 42 43 43 44 typedef struct { 45 /** Local IP link service ID (optional) */ 46 service_id_t iplink; 44 47 inet_addr_t src; 45 48 inet_addr_t dest; -
uspace/lib/c/include/ipc/socket.h
r7de1988c rddd0499d 198 198 #define SOCKET_GET_OPT_NAME(call) \ 199 199 ({ \ 200 int opt_name = (int) IPC_GET_ARG 4(call); \200 int opt_name = (int) IPC_GET_ARG2(call); \ 201 201 opt_name; \ 202 202 }) -
uspace/lib/c/include/net/socket.h
r7de1988c rddd0499d 57 57 extern int connect(int, const struct sockaddr *, socklen_t); 58 58 extern int closesocket(int); 59 extern int send(int, void *, size_t, int);59 extern int send(int, const void *, size_t, int); 60 60 extern int sendto(int, const void *, size_t, int, const struct sockaddr *, 61 61 socklen_t); -
uspace/lib/c/include/net/socket_codes.h
r7de1988c rddd0499d 75 75 typedef int32_t socklen_t; 76 76 77 /* Socket options */ 78 79 enum { 80 SOL_SOCKET = 1, 81 82 /* IP link to transmit on */ 83 SO_IPLINK 84 }; 85 77 86 #endif 78 87 -
uspace/srv/fs/mfs/mfs_rw.c
r7de1988c rddd0499d 104 104 bool write_mode, uint32_t w_block) 105 105 { 106 int r,nr_direct;106 int nr_direct; 107 107 int ptrs_per_block; 108 uint32_t *ind_zone, *ind2_zone; 108 uint32_t *ind_zone = NULL, *ind2_zone = NULL; 109 int r = EOK; 109 110 110 111 struct mfs_ino_info *ino_i = mnode->ino_i; … … 130 131 ino_i->dirty = true; 131 132 } 132 return EOK;133 goto out; 133 134 } 134 135 … … 142 143 r = alloc_zone_and_clear(inst, &zone); 143 144 if (r != EOK) 144 return r;145 goto out; 145 146 146 147 ino_i->i_izone[0] = zone; … … 149 150 /* Sparse block */ 150 151 *b = 0; 151 return EOK;152 goto out; 152 153 } 153 154 } … … 155 156 r = read_ind_zone(inst, ino_i->i_izone[0], &ind_zone); 156 157 if (r != EOK) 157 return r;158 goto out; 158 159 159 160 *b = ind_zone[rblock]; … … 163 164 } 164 165 165 goto out _free_ind1;166 goto out; 166 167 } 167 168 … … 176 177 r = alloc_zone_and_clear(inst, &zone); 177 178 if (r != EOK) 178 return r;179 goto out; 179 180 180 181 ino_i->i_izone[1] = zone; … … 183 184 /* Sparse block */ 184 185 *b = 0; 185 return EOK;186 goto out; 186 187 } 187 188 } … … 189 190 r = read_ind_zone(inst, ino_i->i_izone[1], &ind_zone); 190 191 if (r != EOK) 191 return r;192 goto out; 192 193 193 194 /* … … 203 204 r = alloc_zone_and_clear(inst, &zone); 204 205 if (r != EOK) 205 goto out _free_ind1;206 goto out; 206 207 207 208 ind_zone[ind2_off] = zone; … … 209 210 } else { 210 211 /* Sparse block */ 211 r = EOK;212 212 *b = 0; 213 goto out _free_ind1;213 goto out; 214 214 } 215 215 } … … 217 217 r = read_ind_zone(inst, ind_zone[ind2_off], &ind2_zone); 218 218 if (r != EOK) 219 goto out _free_ind1;219 goto out; 220 220 221 221 *b = ind2_zone[rblock - (ind2_off * ptrs_per_block)]; … … 225 225 } 226 226 227 r = EOK; 228 227 out: 229 228 free(ind2_zone); 230 out_free_ind1:231 229 free(ind_zone); 232 230 return r; -
uspace/srv/hid/compositor/compositor.c
r7de1988c rddd0499d 143 143 static LIST_INITIALIZE(viewport_list); 144 144 145 static FIBRIL_MUTEX_INITIALIZE(discovery_mtx); 146 145 147 /** Input server proxy */ 146 148 static input_t *input; … … 2114 2116 } 2115 2117 2118 static int discover_viewports(void) 2119 { 2120 /* Create viewports and connect them to visualizers. */ 2121 category_id_t cat_id; 2122 int rc = loc_category_get_id("visualizer", &cat_id, IPC_FLAG_BLOCKING); 2123 if (rc != EOK) { 2124 printf("%s: Failed to get visualizer category.\n", NAME); 2125 return -1; 2126 } 2127 2128 service_id_t *svcs; 2129 size_t svcs_cnt = 0; 2130 rc = loc_category_get_svcs(cat_id, &svcs, &svcs_cnt); 2131 if (rc != EOK || svcs_cnt == 0) { 2132 printf("%s: Failed to get visualizer category services.\n", NAME); 2133 return -1; 2134 } 2135 2136 fibril_mutex_lock(&viewport_list_mtx); 2137 for (size_t i = 0; i < svcs_cnt; ++i) { 2138 bool exists = false; 2139 list_foreach(viewport_list, link, viewport_t, vp) { 2140 if (vp->dsid == svcs[i]) { 2141 exists = true; 2142 break; 2143 } 2144 } 2145 2146 if (exists) 2147 continue; 2148 2149 char *svc_name; 2150 rc = loc_service_get_name(svcs[i], &svc_name); 2151 if (rc == EOK) { 2152 viewport_t *vp = viewport_create(svc_name); 2153 if (vp != NULL) { 2154 list_append(&vp->link, &viewport_list); 2155 } 2156 } 2157 } 2158 fibril_mutex_unlock(&viewport_list_mtx); 2159 2160 /* TODO damage only newly added viewports */ 2161 comp_damage(0, 0, UINT32_MAX, UINT32_MAX); 2162 return EOK; 2163 } 2164 2165 static void category_change_cb(void) 2166 { 2167 fibril_mutex_lock(&discovery_mtx); 2168 discover_viewports(); 2169 fibril_mutex_unlock(&discovery_mtx); 2170 } 2171 2116 2172 static int compositor_srv_init(char *input_svc, char *name) 2117 2173 { … … 2165 2221 } 2166 2222 2167 /* Create viewports and connect them to visualizers. */ 2168 category_id_t cat_id; 2169 rc = loc_category_get_id("visualizer", &cat_id, IPC_FLAG_BLOCKING); 2223 rc = loc_register_cat_change_cb(category_change_cb); 2170 2224 if (rc != EOK) { 2171 printf("%s: Failed to get visualizer category.\n", NAME);2225 printf("%s: Failed to register category change callback\n", NAME); 2172 2226 input_disconnect(); 2173 return -1; 2174 } 2175 2176 service_id_t *svcs; 2177 size_t svcs_cnt = 0; 2178 rc = loc_category_get_svcs(cat_id, &svcs, &svcs_cnt); 2179 if (rc != EOK || svcs_cnt == 0) { 2180 printf("%s: Failed to get visualizer category services.\n", NAME); 2227 return rc; 2228 } 2229 2230 rc = discover_viewports(); 2231 if (rc != EOK) { 2181 2232 input_disconnect(); 2182 return -1; 2183 } 2184 2185 for (size_t i = 0; i < svcs_cnt; ++i) { 2186 char *svc_name; 2187 rc = loc_service_get_name(svcs[i], &svc_name); 2188 if (rc == EOK) { 2189 viewport_t *vp = viewport_create(svc_name); 2190 if (vp != NULL) { 2191 list_append(&vp->link, &viewport_list); 2192 } 2193 } 2233 return rc; 2194 2234 } 2195 2235 … … 2203 2243 comp_damage(0, 0, UINT32_MAX, UINT32_MAX); 2204 2244 2245 2205 2246 return EOK; 2206 2247 } -
uspace/srv/net/dnsrsrv/dnsrsrv.c
r7de1988c rddd0499d 60 60 rc = transport_init(); 61 61 if (rc != EOK) { 62 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing t arnsport.");62 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing transport."); 63 63 return EIO; 64 64 } -
uspace/srv/net/ethip/arp.c
r7de1988c rddd0499d 98 98 addr48_t mac_addr) 99 99 { 100 /* Broadcast address */ 101 if (ip_addr == addr32_broadcast_all_hosts) { 102 addr48(addr48_broadcast, mac_addr); 103 return EOK; 104 } 105 100 106 int rc = atrans_lookup(ip_addr, mac_addr); 101 107 if (rc == EOK) -
uspace/srv/net/ethip/ethip_nic.c
r7de1988c rddd0499d 202 202 } 203 203 204 rc = nic_broadcast_set_mode(nic->sess, NIC_BROADCAST_ACCEPTED); 205 if (rc != EOK) { 206 log_msg(LOG_DEFAULT, LVL_ERROR, "Error enabling " 207 "reception of broadcast frames on '%s'.", nic->svc_name); 208 goto error; 209 } 210 204 211 log_msg(LOG_DEFAULT, LVL_DEBUG, "Initialized IP link service,"); 205 212 -
uspace/srv/net/inetsrv/icmp.c
r7de1988c rddd0499d 105 105 reply->checksum = host2uint16_t_be(checksum); 106 106 107 rdgram.iplink = 0; 107 108 rdgram.src = dgram->dest; 108 109 rdgram.dest = dgram->src; … … 171 172 inet_addr_set(sdu->dest, &dgram.dest); 172 173 174 dgram.iplink = 0; 173 175 dgram.tos = ICMP_TOS; 174 176 dgram.data = rdata; -
uspace/srv/net/inetsrv/inet_link.c
r7de1988c rddd0499d 235 235 inet_addrobj_t *addr = NULL; 236 236 237 /* XXX FIXME Cannot rely on loopback being the first IP link service!! */ 237 238 if (first_link) { 238 239 addr = inet_addrobj_new(); … … 240 241 inet_naddr(&addr->naddr, 127, 0, 0, 1, 24); 241 242 first_link = false; 242 } else {243 /*244 * FIXME245 * Setting static IPv4 address for testing purposes:246 * 10.0.2.15/24247 */248 addr = inet_addrobj_new();249 250 inet_naddr(&addr->naddr, 10, 0, 2, 15, 24);251 243 } 252 244 -
uspace/srv/net/inetsrv/inetsrv.c
r7de1988c rddd0499d 68 68 }; 69 69 70 static inet_addr_t broadcast4_all_hosts = { 71 .family = AF_INET, 72 .addr = 0xffffffff 73 }; 74 70 75 static inet_addr_t multicast_all_nodes = { 71 76 .family = AF_INET6, … … 119 124 } 120 125 121 inet_sroute_t *sroute = inet_sroute_new();122 if (sroute == NULL) {123 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed creating default route (%d).", rc);124 return ENOMEM;125 }126 127 inet_naddr(&sroute->dest, 0, 0, 0, 0, 0);128 inet_addr(&sroute->router, 10, 0, 2, 2);129 sroute->name = str_dup("default");130 inet_sroute_add(sroute);131 132 126 rc = inet_link_discovery_start(); 133 127 if (rc != EOK) … … 186 180 { 187 181 inet_dir_t dir; 182 inet_link_t *ilink; 188 183 int rc; 184 185 if (dgram->iplink != 0) { 186 log_msg(LOG_DEFAULT, LVL_DEBUG, "dgram directly to iplink %zu", 187 dgram->iplink); 188 /* Send packet directly to the specified IP link */ 189 ilink = inet_link_get_by_id(dgram->iplink); 190 if (ilink == 0) 191 return ENOENT; 192 193 if (dgram->src.family != AF_INET || 194 dgram->dest.family != AF_INET) 195 return EINVAL; 196 197 return inet_link_send_dgram(ilink, dgram->src.addr, 198 dgram->dest.addr, dgram, proto, ttl, df); 199 } 200 201 log_msg(LOG_DEFAULT, LVL_DEBUG, "dgram to be routed"); 202 203 /* Route packet using source/destination addresses */ 189 204 190 205 rc = inet_find_dir(&dgram->src, &dgram->dest, dgram->tos, &dir); … … 214 229 215 230 /* Take source address from the address object */ 231 if (remote->family == AF_INET && remote->addr == 0xffffffff) { 232 local->family = AF_INET; 233 local->addr = 0; 234 return EOK; 235 } 216 236 inet_naddr_addr(&dir.aobj->naddr, local); 217 237 return EOK; … … 282 302 inet_dgram_t dgram; 283 303 284 dgram.tos = IPC_GET_ARG1(*icall); 285 286 uint8_t ttl = IPC_GET_ARG2(*icall); 304 dgram.iplink = IPC_GET_ARG1(*icall); 305 dgram.tos = IPC_GET_ARG2(*icall); 306 307 uint8_t ttl = IPC_GET_ARG3(*icall); 287 308 int df = IPC_GET_ARG3(*icall); 288 309 … … 524 545 if ((addr != NULL) || 525 546 (inet_naddr_compare_mask(&solicited_node_mask, &packet->dest)) || 526 (inet_addr_compare(&multicast_all_nodes, &packet->dest))) { 547 (inet_addr_compare(&multicast_all_nodes, &packet->dest)) || 548 (inet_addr_compare(&broadcast4_all_hosts, &packet->dest))) { 527 549 /* Destined for one of the local addresses */ 528 550 -
uspace/srv/net/inetsrv/inetsrv.h
r7de1988c rddd0499d 127 127 128 128 typedef struct { 129 service_id_t iplink; 129 130 inet_addr_t src; 130 131 inet_addr_t dest; -
uspace/srv/net/slip/slip.c
r7de1988c rddd0499d 333 333 "Failed to connect to service %s (ID=%d)", 334 334 svcstr, (int) svcid); 335 return rc;335 return ENOENT; 336 336 } 337 337 slip_iplink.arg = sess_out; … … 342 342 "Failed to connect to service %s (ID=%d)", 343 343 svcstr, (int) svcid); 344 rc = ENOENT; 344 345 goto fail; 345 346 } … … 365 366 log_msg(LOG_DEFAULT, LVL_ERROR, 366 367 "Failed to create receive fibril."); 368 rc = ENOENT; 367 369 goto fail; 368 370 } -
uspace/srv/net/tcp/tcp.c
r7de1988c rddd0499d 141 141 pdu->text_size); 142 142 143 dgram.iplink = 0; 143 144 dgram.src = pdu->src; 144 145 dgram.dest = pdu->dest; -
uspace/srv/net/udp/assoc.c
r7de1988c rddd0499d 184 184 fibril_mutex_unlock(&assoc_list_lock); 185 185 udp_assoc_delref(assoc); 186 } 187 188 /** Set IP link in association. 189 * 190 * @param assoc Association 191 * @param iplink IP link 192 */ 193 void udp_assoc_set_iplink(udp_assoc_t *assoc, service_id_t iplink) 194 { 195 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_iplink(%p, %zu)", 196 assoc, iplink); 197 fibril_mutex_lock(&assoc->lock); 198 assoc->ident.iplink = iplink; 199 fibril_mutex_unlock(&assoc->lock); 186 200 } 187 201 -
uspace/srv/net/udp/assoc.h
r7de1988c rddd0499d 36 36 #define ASSOC_H 37 37 38 #include <ipc/loc.h> 38 39 #include <sys/types.h> 39 40 #include "udp_type.h" … … 45 46 extern void udp_assoc_addref(udp_assoc_t *); 46 47 extern void udp_assoc_delref(udp_assoc_t *); 48 extern void udp_assoc_set_iplink(udp_assoc_t *, service_id_t); 47 49 extern void udp_assoc_set_foreign(udp_assoc_t *, udp_sock_t *); 48 50 extern void udp_assoc_set_local(udp_assoc_t *, udp_sock_t *); -
uspace/srv/net/udp/pdu.c
r7de1988c rddd0499d 215 215 return ENOMEM; 216 216 217 npdu->iplink = sp->iplink; 217 218 npdu->src = sp->local.addr; 218 219 npdu->dest = sp->foreign.addr; -
uspace/srv/net/udp/sock.c
r7de1988c rddd0499d 1 1 /* 2 2 * Copyright (c) 2008 Lukas Mejdrech 3 * Copyright (c) 201 2Jiri Svoboda3 * Copyright (c) 2013 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 349 349 fibril_mutex_lock(&socket->lock); 350 350 351 if (inet_addr_is_any(&socket->assoc->ident.local.addr)) { 351 if (inet_addr_is_any(&socket->assoc->ident.local.addr) && 352 socket->assoc->ident.iplink == 0) { 352 353 /* Determine local IP address */ 353 354 inet_addr_t loc_addr; … … 665 666 static void udp_sock_setsockopt(udp_client_t *client, ipc_callid_t callid, ipc_call_t call) 666 667 { 667 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_setsockopt()"); 668 async_answer_0(callid, ENOTSUP); 669 } 668 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_setsockopt)"); 669 log_msg(LOG_DEFAULT, LVL_DEBUG, " - async_data_write_accept"); 670 671 void *data = NULL; 672 size_t data_len; 673 int rc = async_data_write_accept(&data, false, 0, 0, 0, &data_len); 674 if (rc != EOK) { 675 log_msg(LOG_DEFAULT, LVL_DEBUG, " - failed accepting data"); 676 async_answer_0(callid, rc); 677 return; 678 } 679 680 sysarg_t opt_level = SOL_SOCKET; 681 sysarg_t opt_name = SOCKET_GET_OPT_NAME(call); 682 683 if (opt_level != SOL_SOCKET || opt_name != SO_IPLINK || 684 data_len != sizeof(service_id_t)) { 685 log_msg(LOG_DEFAULT, LVL_DEBUG, " - failed opt_level/name/len"); 686 log_msg(LOG_DEFAULT, LVL_DEBUG, " - failed opt_level=%d, " 687 "opt_name=%d, data_len=%zu", (int)opt_level, (int)opt_name, 688 data_len); 689 async_answer_0(callid, EINVAL); 690 return; 691 } 692 693 log_msg(LOG_DEFAULT, LVL_DEBUG, " - call socket_cores_find"); 694 695 socket_core_t *sock_core = socket_cores_find(&client->sockets, 696 SOCKET_GET_SOCKET_ID(call)); 697 if (sock_core == NULL) { 698 log_msg(LOG_DEFAULT, LVL_DEBUG, " - failed getting sock_core"); 699 async_answer_0(callid, ENOENT); 700 return; 701 } 702 703 udp_sockdata_t *socket = 704 (udp_sockdata_t *) sock_core->specific_data; 705 706 service_id_t iplink = *(service_id_t *)data; 707 udp_uc_set_iplink(socket->assoc, iplink); 708 709 log_msg(LOG_DEFAULT, LVL_DEBUG, " - success"); 710 async_answer_0(callid, EOK); 711 } 712 670 713 671 714 static int udp_sock_recv_fibril(void *arg) … … 714 757 715 758 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_recv_fibril() exited loop"); 716 fibril_mutex_unlock(&sock->recv_buffer_lock);717 759 udp_uc_destroy(sock->assoc); 718 760 … … 730 772 /* Accept the connection */ 731 773 async_answer_0(iid, EOK); 774 775 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_connection: begin"); 732 776 733 777 client.sess = async_callback_receive(EXCHANGE_SERIALIZE); -
uspace/srv/net/udp/ucall.c
r7de1988c rddd0499d 55 55 *assoc = nassoc; 56 56 return UDP_EOK; 57 } 58 59 void udp_uc_set_iplink(udp_assoc_t *assoc, service_id_t iplink) 60 { 61 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_iplink(%p, %zu)", 62 assoc, iplink); 63 64 udp_assoc_set_iplink(assoc, iplink); 57 65 } 58 66 -
uspace/srv/net/udp/ucall.h
r7de1988c rddd0499d 36 36 #define UCALL_H 37 37 38 #include <ipc/loc.h> 38 39 #include <sys/types.h> 39 40 #include "udp_type.h" 40 41 41 42 extern udp_error_t udp_uc_create(udp_assoc_t **); 43 extern void udp_uc_set_iplink(udp_assoc_t *, service_id_t); 42 44 extern udp_error_t udp_uc_set_foreign(udp_assoc_t *, udp_sock_t *); 43 45 extern udp_error_t udp_uc_set_local(udp_assoc_t *, udp_sock_t *); -
uspace/srv/net/udp/udp_inet.c
r7de1988c rddd0499d 84 84 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_transmit_pdu()"); 85 85 86 dgram.iplink = pdu->iplink; 86 87 dgram.src = pdu->src; 87 88 dgram.dest = pdu->dest; -
uspace/srv/net/udp/udp_type.h
r7de1988c rddd0499d 38 38 #include <fibril.h> 39 39 #include <fibril_synch.h> 40 #include <ipc/loc.h> 40 41 #include <socket_core.h> 41 42 #include <sys/types.h> … … 71 72 72 73 typedef struct { 74 service_id_t iplink; 73 75 udp_sock_t local; 74 76 udp_sock_t foreign; … … 85 87 /** Encoded PDU */ 86 88 typedef struct { 89 /** IP link (optional) */ 90 service_id_t iplink; 87 91 /** Source address */ 88 92 inet_addr_t src; 89 93 /** Destination address */ 90 94 inet_addr_t dest; 91 92 95 /** Encoded PDU data including header */ 93 96 void *data; … … 143 146 /** Connection */ 144 147 udp_assoc_t *assoc; 148 /** User-configured IP link */ 149 service_id_t iplink; 145 150 /** Receiving fibril */ 146 151 fid_t recv_fibril;
Note:
See TracChangeset
for help on using the changeset viewer.