Changes in / [ddd0499d:7de1988c] in mainline
- Files:
-
- 7 deleted
- 52 edited
Legend:
- Unmodified
- Added
- Removed
-
.bzrignore
rddd0499d r7de1988c 265 265 uspace/app/corecfg/corecfg 266 266 uspace/dist/app/corecfg 267 uspace/dist/srv/rfb268 uspace/srv/hid/rfb/rfb269 uspace/dist/srv/dhcp270 uspace/srv/net/dhcp/dhcp -
boot/Makefile.common
rddd0499d r7de1988c 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 \116 114 $(USPACE_PATH)/srv/net/dnsrsrv/dnsrsrv \ 117 115 $(USPACE_PATH)/srv/net/ethip/ethip \ -
kernel/arch/abs32le/include/arch/mm/frame.h
rddd0499d r7de1988c 39 39 #define FRAME_SIZE (1 << FRAME_WIDTH) 40 40 41 #define FRAME_LOWPRIO 042 43 41 #include <typedefs.h> 44 42 -
kernel/arch/amd64/include/arch/mm/frame.h
rddd0499d r7de1988c 39 39 #define FRAME_SIZE (1 << FRAME_WIDTH) 40 40 41 #define FRAME_LOWPRIO 0x100042 43 41 #ifndef __ASM__ 44 42 -
kernel/arch/amd64/src/ddi/ddi.c
rddd0499d r7de1988c 68 68 */ 69 69 70 void *store = malloc(bitmap_size(elements ), FRAME_ATOMIC);70 void *store = malloc(bitmap_size(elements, 0), 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, 75 bitmap_initialize(&oldiomap, task->arch.iomap.elements, 0, 76 76 task->arch.iomap.bits); 77 77 78 bitmap_initialize(&task->arch.iomap, elements, store);78 bitmap_initialize(&task->arch.iomap, elements, 0, store); 79 79 80 80 /* … … 129 129 130 130 bitmap_t iomap; 131 bitmap_initialize(&iomap, TSS_IOMAP_SIZE * 8, 131 bitmap_initialize(&iomap, TSS_IOMAP_SIZE * 8, 0, 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 );159 size_t size = bitmap_size(elements, 0); 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
rddd0499d r7de1988c 46 46 { 47 47 task->arch.iomapver = 0; 48 bitmap_initialize(&task->arch.iomap, 0, NULL);48 bitmap_initialize(&task->arch.iomap, 0, 0, NULL); 49 49 } 50 50 -
kernel/arch/arm32/include/arch/mm/frame.h
rddd0499d r7de1988c 39 39 #define FRAME_WIDTH 12 /* 4KB frames */ 40 40 #define FRAME_SIZE (1 << FRAME_WIDTH) 41 42 #define FRAME_LOWPRIO 043 41 44 42 #ifndef __ASM__ -
kernel/arch/ia32/include/arch/mm/frame.h
rddd0499d r7de1988c 39 39 #define FRAME_SIZE (1 << FRAME_WIDTH) 40 40 41 #define FRAME_LOWPRIO 0x100042 43 41 #ifndef __ASM__ 44 42 -
kernel/arch/ia32/src/ddi/ddi.c
rddd0499d r7de1988c 68 68 */ 69 69 70 void *store = malloc(bitmap_size(elements ), FRAME_ATOMIC);70 void *store = malloc(bitmap_size(elements, 0), 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, 75 bitmap_initialize(&oldiomap, task->arch.iomap.elements, 0, 76 76 task->arch.iomap.bits); 77 77 78 bitmap_initialize(&task->arch.iomap, elements, store);78 bitmap_initialize(&task->arch.iomap, elements, 0, store); 79 79 80 80 /* … … 129 129 130 130 bitmap_t iomap; 131 bitmap_initialize(&iomap, TSS_IOMAP_SIZE * 8, 131 bitmap_initialize(&iomap, TSS_IOMAP_SIZE * 8, 0, 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 );159 size_t size = bitmap_size(elements, 0); 160 160 gdt_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + size); 161 161 gdtr_load(&cpugdtr); -
kernel/arch/ia32/src/proc/task.c
rddd0499d r7de1988c 46 46 { 47 47 task->arch.iomapver = 0; 48 bitmap_initialize(&task->arch.iomap, 0, NULL);48 bitmap_initialize(&task->arch.iomap, 0, 0, NULL); 49 49 } 50 50 -
kernel/arch/ia64/include/arch/mm/frame.h
rddd0499d r7de1988c 39 39 #define FRAME_SIZE (1 << FRAME_WIDTH) 40 40 41 #define FRAME_LOWPRIO 042 43 41 #ifndef __ASM__ 44 42 -
kernel/arch/ia64/src/ddi/ddi.c
rddd0499d r7de1988c 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);62 void *store = malloc(bitmap_size(IO_MEMMAP_PAGES, 0), 0); 63 63 if (store == NULL) 64 64 return ENOMEM; 65 65 66 bitmap_initialize(task->arch.iomap, IO_MEMMAP_PAGES, store);66 bitmap_initialize(task->arch.iomap, IO_MEMMAP_PAGES, 0, store); 67 67 bitmap_clear_range(task->arch.iomap, 0, IO_MEMMAP_PAGES); 68 68 } -
kernel/arch/mips32/include/arch/mm/frame.h
rddd0499d r7de1988c 39 39 #define FRAME_SIZE (1 << FRAME_WIDTH) 40 40 41 #define FRAME_LOWPRIO 042 43 41 #ifndef __ASM__ 44 42 -
kernel/arch/mips64/include/arch/mm/frame.h
rddd0499d r7de1988c 39 39 #define FRAME_SIZE (1 << FRAME_WIDTH) 40 40 41 #define FRAME_LOWPRIO 042 43 41 #ifndef __ASM__ 44 42 -
kernel/arch/ppc32/include/arch/mm/frame.h
rddd0499d r7de1988c 39 39 #define FRAME_SIZE (1 << FRAME_WIDTH) 40 40 41 #define FRAME_LOWPRIO 042 43 41 #ifndef __ASM__ 44 42 -
kernel/arch/sparc64/include/arch/mm/sun4u/frame.h
rddd0499d r7de1988c 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) 53 54 #define FRAME_LOWPRIO 0 51 #define FRAME_WIDTH 14 /* 16K */ 52 #define FRAME_SIZE (1 << FRAME_WIDTH) 55 53 56 54 #ifndef __ASM__ -
kernel/arch/sparc64/include/arch/mm/sun4v/frame.h
rddd0499d r7de1988c 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) 43 44 #define FRAME_LOWPRIO 0 41 #define FRAME_WIDTH 13 42 #define FRAME_SIZE (1 << FRAME_WIDTH) 45 43 46 44 #endif -
kernel/generic/include/adt/bitmap.h
rddd0499d r7de1988c 44 44 size_t elements; 45 45 uint8_t *bits; 46 size_t next_fit; 46 47 size_t block_size; 48 uint8_t *blocks; 47 49 } bitmap_t; 48 50 … … 50 52 unsigned int value) 51 53 { 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; 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 } 63 74 } 64 75 } … … 69 80 return 0; 70 81 71 size_t byte = element / BITMAP_ELEMENT; 72 uint8_t mask = 1 << (element & BITMAP_REMAINER); 73 74 return !!((bitmap->bits)[byte] & mask); 82 return !!((bitmap->bits)[element / BITMAP_ELEMENT] & 83 (1 << (element & BITMAP_REMAINER))); 75 84 } 76 85 77 extern size_t bitmap_size(size_t );78 extern void bitmap_initialize(bitmap_t *, size_t, void *);86 extern size_t bitmap_size(size_t, size_t); 87 extern void bitmap_initialize(bitmap_t *, size_t, size_t, void *); 79 88 80 89 extern void bitmap_set_range(bitmap_t *, size_t, size_t); 81 90 extern void bitmap_clear_range(bitmap_t *, size_t, size_t); 82 91 83 extern int bitmap_allocate_range(bitmap_t *, size_t, size_t, size_t, size_t ,84 size_t *);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); 85 94 extern void bitmap_copy(bitmap_t *, bitmap_t *, size_t); 86 95 -
kernel/generic/include/mm/frame.h
rddd0499d r7de1988c 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, 134 size_t *); 133 extern uintptr_t frame_alloc_generic(size_t, frame_flags_t, uintptr_t, size_t *); 135 134 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
rddd0499d r7de1988c 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 hierarchy 41 * for faster range searches. The second level bitmap (of blocks) 42 * is not precise, but conservative. This means that if the block 43 * 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 the 45 * bits in the block. 46 * 39 47 */ 40 48 … … 48 56 #define ALL_ZEROES 0x00 49 57 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 68 58 /** Get bitmap size 69 59 * … … 71 61 * 72 62 * @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. 73 65 * 74 66 * @return Size (in bytes) required for the bitmap. 75 67 * 76 68 */ 77 size_t bitmap_size(size_t elements )69 size_t bitmap_size(size_t elements, size_t block_size) 78 70 { 79 71 size_t size = elements / BITMAP_ELEMENT; … … 82 74 size++; 83 75 76 if (block_size > 0) { 77 size += elements / block_size; 78 79 if ((elements % block_size) != 0) 80 size++; 81 } 82 84 83 return size; 85 84 } … … 91 90 * @param bitmap Bitmap structure. 92 91 * @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. 93 94 * @param data Address of the memory used to hold the map. 94 95 * The optional 2nd level bitmap follows the 1st … … 96 97 * 97 98 */ 98 void bitmap_initialize(bitmap_t *bitmap, size_t elements, void *data) 99 void bitmap_initialize(bitmap_t *bitmap, size_t elements, size_t block_size, 100 void *data) 99 101 { 100 102 bitmap->elements = elements; 101 103 bitmap->bits = (uint8_t *) data; 102 bitmap->next_fit = 0; 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 } 103 155 } 104 156 … … 114 166 ASSERT(start + count <= bitmap->elements); 115 167 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 { 116 189 if (count == 0) 117 190 return; 118 191 119 size_t start_byte = start / BITMAP_ELEMENT;120 192 size_t aligned_start = ALIGN_UP(start, BITMAP_ELEMENT); 121 193 … … 130 202 131 203 if (start + count < aligned_start) { 132 /* Set bits in the middle of byte .*/133 bit map->bits[start_byte] |=134 ((1 << lub) - 1) << (start & BITMAP_REMAINER);204 /* Set bits in the middle of byte */ 205 bits[start / BITMAP_ELEMENT] &= 206 ~(((1 << lub) - 1) << (start & BITMAP_REMAINER)); 135 207 return; 136 208 } 137 209 138 210 if (lub) { 139 /* Make sure to setany leading unaligned bits. */140 bit map->bits[start_byte] |=141 ~((1 << (BITMAP_ELEMENT - lub)) - 1);211 /* Make sure to clear any leading unaligned bits. */ 212 bits[start / BITMAP_ELEMENT] &= 213 (1 << (BITMAP_ELEMENT - lub)) - 1; 142 214 } 143 215 … … 145 217 146 218 for (i = 0; i < amb / BITMAP_ELEMENT; i++) { 147 /* The middle bits can be set byte by byte. */ 148 bitmap->bits[aligned_start / BITMAP_ELEMENT + i] = 149 ALL_ONES; 219 /* The middle bits can be cleared byte by byte. */ 220 bits[aligned_start / BITMAP_ELEMENT + i] = ALL_ZEROES; 150 221 } 151 222 152 223 if (tab) { 153 /* Make sure to set any trailing aligned bits. */ 154 bitmap->bits[aligned_start / BITMAP_ELEMENT + i] |= 155 (1 << tab) - 1; 224 /* Make sure to clear any trailing aligned bits. */ 225 bits[aligned_start / BITMAP_ELEMENT + i] &= ~((1 << tab) - 1); 156 226 } 157 227 } … … 168 238 ASSERT(start + count <= bitmap->elements); 169 239 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; 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 } 213 255 } 214 256 … … 258 300 * @param count Number of continuous zero bits to find. 259 301 * @param base Address of the first bit in the bitmap. 260 * @param prefered Prefered address to start searching from.261 302 * @param constraint Constraint for the address of the first zero bit. 262 303 * @param index Place to store the index of the first zero … … 270 311 */ 271 312 int bitmap_allocate_range(bitmap_t *bitmap, size_t count, size_t base, 272 size_t prefered, size_tconstraint, size_t *index)313 size_t constraint, size_t *index) 273 314 { 274 315 if (count == 0) 275 316 return false; 276 317 277 size_t size = bitmap_size(bitmap->elements);278 size_t next_fit = bitmap->next_fit;279 280 318 /* 281 * Adjust the next-fit value according to the address282 * the caller prefers to start the search at.319 * This is a trivial implementation that should be 320 * optimized further. 283 321 */ 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) 322 323 for (size_t i = 0; i < bitmap->elements; i++) { 324 if (!constraint_satisfy(i, base, constraint)) 296 325 continue; 297 326 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; 327 if (!bitmap_get(bitmap, i)) { 328 bool continuous = true; 302 329 303 if (i >= bitmap->elements) 304 break; 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 } 305 337 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; 338 if (continuous) { 339 if (index != NULL) { 340 bitmap_set_range(bitmap, i, count); 341 *index = i; 318 342 } 319 343 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; 344 return true; 330 345 } 331 346 } 347 332 348 } 333 349 … … 335 351 } 336 352 353 /** Clear range of set bits. 354 * 355 * This is essentially bitmap_clear_range(), but it also 356 * 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 be 367 * 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 337 378 /** @} 338 379 */ -
kernel/generic/src/ddi/ddi.c
rddd0499d r7de1988c 329 329 330 330 size_t frames = SIZE2FRAMES(size); 331 *phys = frame_alloc (frames, FRAME_NO_RESERVE, constraint);331 *phys = frame_alloc_noreserve(frames, 0, constraint); 332 332 if (*phys == 0) 333 333 return ENOMEM; -
kernel/generic/src/mm/frame.c
rddd0499d r7de1988c 60 60 #include <config.h> 61 61 #include <str.h> 62 63 #define BITMAP_BLOCK_SIZE 1024 62 64 63 65 zones_t zones; … … 234 236 * the bitmap if the last argument is NULL. 235 237 */ 236 237 238 return ((zone->flags & ZONE_AVAILABLE) && 238 239 bitmap_allocate_range(&zone->bitmap, count, zone->base, 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; 240 constraint, NULL)); 323 241 } 324 242 … … 332 250 * @param constraint Indication of bits that cannot be set in the 333 251 * physical frame number of the first allocated frame. 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. 252 * @param hind Preferred zone. 338 253 * 339 254 */ … … 344 259 hint = 0; 345 260 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); 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; 357 281 } 358 282 … … 390 314 size_t index; 391 315 int avail = bitmap_allocate_range(&zone->bitmap, count, zone->base, 392 FRAME_LOWPRIO,constraint, &index);316 constraint, &index); 393 317 394 318 ASSERT(avail); … … 428 352 429 353 if (!--frame->refcount) { 430 bitmap_ set(&zone->bitmap, index, 0);354 bitmap_free_range(&zone->bitmap, index, 1); 431 355 432 356 /* Update zone information. */ … … 486 410 487 411 bitmap_initialize(&zones.info[z1].bitmap, zones.info[z1].count, 488 confdata + (sizeof(frame_t) * zones.info[z1].count)); 412 BITMAP_BLOCK_SIZE, confdata + 413 (sizeof(frame_t) * zones.info[z1].count)); 489 414 bitmap_clear_range(&zones.info[z1].bitmap, 0, zones.info[z1].count); 490 415 … … 653 578 */ 654 579 655 bitmap_initialize(&zone->bitmap, count, confdata +656 (sizeof(frame_t) * count));580 bitmap_initialize(&zone->bitmap, count, BITMAP_BLOCK_SIZE, 581 confdata + (sizeof(frame_t) * count)); 657 582 bitmap_clear_range(&zone->bitmap, 0, count); 658 583 … … 666 591 frame_initialize(&zone->frames[i]); 667 592 } else { 668 bitmap_initialize(&zone->bitmap, 0, NULL);593 bitmap_initialize(&zone->bitmap, 0, 0, NULL); 669 594 zone->frames = NULL; 670 595 } … … 680 605 size_t zone_conf_size(size_t count) 681 606 { 682 return (count * sizeof(frame_t) + bitmap_size(count)); 607 return (count * sizeof(frame_t) + 608 bitmap_size(count, BITMAP_BLOCK_SIZE)); 683 609 } 684 610 … … 961 887 } 962 888 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 963 896 /** Free frames of physical memory. 964 897 * … … 1208 1141 /* 1209 1142 * Because printing may require allocation of memory, we may not hold 1210 * the frame allocator locks when printing zone statistics. Therefore,1143 * the frame allocator locks when printing zone statistics. Therefore, 1211 1144 * we simply gather the statistics under the protection of the locks and 1212 1145 * print the statistics when the locks have been released. … … 1217 1150 */ 1218 1151 1219 size_t free_lowmem = 0;1220 size_t free_highmem = 0;1221 size_t free_highprio = 0;1222 1223 1152 for (size_t i = 0;; i++) { 1224 1153 irq_spinlock_lock(&zones.lock, true); … … 1229 1158 } 1230 1159 1231 pfn_t fbase = zones.info[i].base; 1232 uintptr_t base = PFN2ADDR(fbase); 1160 uintptr_t base = PFN2ADDR(zones.info[i].base); 1233 1161 size_t count = zones.info[i].count; 1234 1162 zone_flags_t flags = zones.info[i].flags; … … 1236 1164 size_t busy_count = zones.info[i].busy_count; 1237 1165 1166 irq_spinlock_unlock(&zones.lock, true); 1167 1238 1168 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 examine1255 * all high priority memory to get accurate1256 * 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 } else1264 break;1265 }1266 }1267 }1268 1269 irq_spinlock_unlock(&zones.lock, true);1270 1169 1271 1170 printf("%-4zu", i); … … 1292 1191 printf("\n"); 1293 1192 } 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);1314 1193 } 1315 1194 … … 1337 1216 } 1338 1217 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); 1218 uintptr_t base = PFN2ADDR(zones.info[znum].base); 1345 1219 zone_flags_t flags = zones.info[znum].flags; 1346 1220 size_t count = zones.info[znum].count; … … 1348 1222 size_t busy_count = zones.info[znum].busy_count; 1349 1223 1224 irq_spinlock_unlock(&zones.lock, true); 1225 1350 1226 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 examine1367 * all high priority memory to get accurate1368 * 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 } else1376 break;1377 }1378 }1379 }1380 1381 irq_spinlock_unlock(&zones.lock, true);1382 1227 1383 1228 uint64_t size; 1384 1229 const char *size_suffix; 1385 1386 1230 bin_order_suffix(FRAMES2SIZE(count), &size, &size_suffix, false); 1387 1231 1388 printf("Zone number: 1389 printf("Zone base address: 1390 printf("Zone size: 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, 1391 1235 size, size_suffix); 1392 printf("Zone flags: 1236 printf("Zone flags: %c%c%c%c%c\n", 1393 1237 available ? 'A' : '-', 1394 1238 (flags & ZONE_RESERVED) ? 'R' : '-', … … 1400 1244 bin_order_suffix(FRAMES2SIZE(busy_count), &size, &size_suffix, 1401 1245 false); 1402 printf("Allocated space: 1246 printf("Allocated space: %zu frames (%" PRIu64 " %s)\n", 1403 1247 busy_count, size, size_suffix); 1404 1405 1248 bin_order_suffix(FRAMES2SIZE(free_count), &size, &size_suffix, 1406 1249 false); 1407 printf("Available space: 1250 printf("Available space: %zu frames (%" PRIu64 " %s)\n", 1408 1251 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);1424 1252 } 1425 1253 } -
uspace/Makefile
rddd0499d r7de1988c 90 90 srv/devman \ 91 91 srv/loader \ 92 srv/net/dhcp \93 92 srv/net/dnsrsrv \ 94 93 srv/net/ethip \ … … 122 121 srv/hid/remcons \ 123 122 srv/hw/char/s3c24xx_uart \ 124 srv/hid/rfb \125 123 drv/audio/sb16 \ 126 124 drv/infrastructure/root \ -
uspace/app/sportdmp/sportdmp.c
rddd0499d r7de1988c 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); 91 if (rc != EOK) { 89 90 rc = loc_category_get_svcs(serial_cat_id, &svc_ids, &svc_count); if (rc != EOK) { 92 91 fprintf(stderr, "Failed getting list of services\n"); 93 92 return 1; 94 93 } 95 94 96 95 if (svc_count == 0) { 97 96 fprintf(stderr, "No service in category 'serial'\n"); … … 99 98 return 1; 100 99 } 101 100 102 101 svc_id = svc_ids[0]; 103 102 free(svc_ids); 104 103 } 105 104 106 105 if (argc > arg) { 107 106 fprintf(stderr, "Too many arguments\n"); … … 109 108 return 1; 110 109 } 111 112 110 111 113 112 async_sess_t *sess = loc_service_connect(EXCHANGE_SERIALIZE, svc_id, 114 113 IPC_FLAG_BLOCKING); … … 116 115 fprintf(stderr, "Failed connecting to service\n"); 117 116 } 118 117 119 118 async_exch_t *exch = async_exchange_begin(sess); 120 119 rc = async_req_4_0(exch, SERIAL_SET_COM_PROPS, baud, 121 120 SERIAL_NO_PARITY, 8, 1); 122 121 async_exchange_end(exch); 123 122 124 123 if (rc != EOK) { 125 124 fprintf(stderr, "Failed setting serial properties\n"); 126 125 return 2; 127 126 } 128 127 129 128 uint8_t *buf = (uint8_t *) malloc(BUF_SIZE); 130 129 if (buf == NULL) { … … 132 131 return 3; 133 132 } 134 133 135 134 while (true) { 136 135 ssize_t read = char_dev_read(sess, buf, BUF_SIZE); … … 145 144 fflush(stdout); 146 145 } 147 146 148 147 free(buf); 149 148 return 0; 150 149 } 151 -
uspace/drv/audio/sb16/dsp.c
rddd0499d r7de1988c 180 180 void *buffer = NULL; 181 181 182 int ret = dmamem_map_anonymous(size, DMAMEM_16MiB | 0x0000ffff,182 int ret = dmamem_map_anonymous(size, DMAMEM_16MiB, 183 183 AS_AREA_WRITE | AS_AREA_READ, 0, &pa, &buffer); 184 184 if (ret != EOK) { -
uspace/lib/c/generic/inet.c
rddd0499d r7de1988c 111 111 112 112 ipc_call_t answer; 113 aid_t req = async_send_ 4(exch, INET_SEND, dgram->iplink, dgram->tos,114 ttl, df,&answer);113 aid_t req = async_send_3(exch, INET_SEND, dgram->tos, ttl, df, 114 &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
rddd0499d r7de1988c 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;51 49 52 50 const addr48_t addr48_broadcast = { -
uspace/lib/c/generic/net/socket_client.c
rddd0499d r7de1988c 923 923 * message. 924 924 */ 925 int send(int socket_id, constvoid *data, size_t datalength, int flags)925 int send(int socket_id, void *data, size_t datalength, int flags) 926 926 { 927 927 /* Without the address */ -
uspace/lib/c/include/inet/addr.h
rddd0499d r7de1988c 68 68 } inet_naddr_t; 69 69 70 extern const addr32_t addr32_broadcast_all_hosts;71 70 extern const addr48_t addr48_broadcast; 72 71 -
uspace/lib/c/include/inet/inet.h
rddd0499d r7de1988c 37 37 38 38 #include <inet/addr.h> 39 #include <ipc/loc.h>40 39 #include <sys/types.h> 41 40 … … 43 42 44 43 typedef struct { 45 /** Local IP link service ID (optional) */46 service_id_t iplink;47 44 inet_addr_t src; 48 45 inet_addr_t dest; -
uspace/lib/c/include/ipc/socket.h
rddd0499d r7de1988c 198 198 #define SOCKET_GET_OPT_NAME(call) \ 199 199 ({ \ 200 int opt_name = (int) IPC_GET_ARG 2(call); \200 int opt_name = (int) IPC_GET_ARG4(call); \ 201 201 opt_name; \ 202 202 }) -
uspace/lib/c/include/net/socket.h
rddd0499d r7de1988c 57 57 extern int connect(int, const struct sockaddr *, socklen_t); 58 58 extern int closesocket(int); 59 extern int send(int, constvoid *, size_t, int);59 extern int send(int, 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
rddd0499d r7de1988c 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_IPLINK84 };85 86 77 #endif 87 78 -
uspace/srv/fs/mfs/mfs_rw.c
rddd0499d r7de1988c 104 104 bool write_mode, uint32_t w_block) 105 105 { 106 int nr_direct;106 int r, nr_direct; 107 107 int ptrs_per_block; 108 uint32_t *ind_zone = NULL, *ind2_zone = NULL; 109 int r = EOK; 108 uint32_t *ind_zone, *ind2_zone; 110 109 111 110 struct mfs_ino_info *ino_i = mnode->ino_i; … … 131 130 ino_i->dirty = true; 132 131 } 133 goto out;132 return EOK; 134 133 } 135 134 … … 143 142 r = alloc_zone_and_clear(inst, &zone); 144 143 if (r != EOK) 145 goto out;144 return r; 146 145 147 146 ino_i->i_izone[0] = zone; … … 150 149 /* Sparse block */ 151 150 *b = 0; 152 goto out;151 return EOK; 153 152 } 154 153 } … … 156 155 r = read_ind_zone(inst, ino_i->i_izone[0], &ind_zone); 157 156 if (r != EOK) 158 goto out;157 return r; 159 158 160 159 *b = ind_zone[rblock]; … … 164 163 } 165 164 166 goto out ;165 goto out_free_ind1; 167 166 } 168 167 … … 177 176 r = alloc_zone_and_clear(inst, &zone); 178 177 if (r != EOK) 179 goto out;178 return r; 180 179 181 180 ino_i->i_izone[1] = zone; … … 184 183 /* Sparse block */ 185 184 *b = 0; 186 goto out;185 return EOK; 187 186 } 188 187 } … … 190 189 r = read_ind_zone(inst, ino_i->i_izone[1], &ind_zone); 191 190 if (r != EOK) 192 goto out;191 return r; 193 192 194 193 /* … … 204 203 r = alloc_zone_and_clear(inst, &zone); 205 204 if (r != EOK) 206 goto out ;205 goto out_free_ind1; 207 206 208 207 ind_zone[ind2_off] = zone; … … 210 209 } else { 211 210 /* Sparse block */ 211 r = EOK; 212 212 *b = 0; 213 goto out ;213 goto out_free_ind1; 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 ;219 goto out_free_ind1; 220 220 221 221 *b = ind2_zone[rblock - (ind2_off * ptrs_per_block)]; … … 225 225 } 226 226 227 out: 227 r = EOK; 228 228 229 free(ind2_zone); 230 out_free_ind1: 229 231 free(ind_zone); 230 232 return r; -
uspace/srv/hid/compositor/compositor.c
rddd0499d r7de1988c 143 143 static LIST_INITIALIZE(viewport_list); 144 144 145 static FIBRIL_MUTEX_INITIALIZE(discovery_mtx);146 147 145 /** Input server proxy */ 148 146 static input_t *input; … … 2116 2114 } 2117 2115 2118 static int discover_viewports(void) 2119 { 2116 static int compositor_srv_init(char *input_svc, char *name) 2117 { 2118 /* Coordinates of the central pixel. */ 2119 coord_origin = UINT32_MAX / 4; 2120 2121 /* Color of the viewport background. Must be opaque. */ 2122 bg_color = PIXEL(255, 75, 70, 75); 2123 2124 /* Register compositor server. */ 2125 async_set_client_connection(client_connection); 2126 int rc = loc_server_register(NAME); 2127 if (rc != EOK) { 2128 printf("%s: Unable to register server (%s)\n", NAME, str_error(rc)); 2129 return -1; 2130 } 2131 2132 /* Register interrupt handler to switch back from kconsole. */ 2133 async_set_interrupt_received(interrupt_received); 2134 rc = event_subscribe(EVENT_KCONSOLE, 0); 2135 if (rc != EOK) { 2136 printf("%s: Failed to register kconsole notifications (%s)\n", 2137 NAME, str_error(rc)); 2138 } 2139 2140 server_name = name; 2141 2142 char svc[LOC_NAME_MAXLEN + 1]; 2143 snprintf(svc, LOC_NAME_MAXLEN, "%s/%s", NAMESPACE, server_name); 2144 2145 service_id_t service_id; 2146 rc = loc_service_register(svc, &service_id); 2147 if (rc != EOK) { 2148 printf("%s: Unable to register service %s\n", NAME, svc); 2149 return rc; 2150 } 2151 2152 /* Prepare window registrator (entrypoint for clients). */ 2153 char winreg[LOC_NAME_MAXLEN + 1]; 2154 snprintf(winreg, LOC_NAME_MAXLEN, "%s%s/winreg", NAMESPACE, server_name); 2155 if (loc_service_register(winreg, &winreg_id) != EOK) { 2156 printf("%s: Unable to register service %s\n", NAME, winreg); 2157 return -1; 2158 } 2159 2160 /* Establish input bidirectional connection. */ 2161 rc = input_connect(input_svc); 2162 if (rc != EOK) { 2163 printf("%s: Failed to connect to input service.\n", NAME); 2164 return rc; 2165 } 2166 2120 2167 /* Create viewports and connect them to visualizers. */ 2121 2168 category_id_t cat_id; 2122 intrc = loc_category_get_id("visualizer", &cat_id, IPC_FLAG_BLOCKING);2169 rc = loc_category_get_id("visualizer", &cat_id, IPC_FLAG_BLOCKING); 2123 2170 if (rc != EOK) { 2124 2171 printf("%s: Failed to get visualizer category.\n", NAME); 2172 input_disconnect(); 2125 2173 return -1; 2126 2174 } … … 2131 2179 if (rc != EOK || svcs_cnt == 0) { 2132 2180 printf("%s: Failed to get visualizer category services.\n", NAME); 2181 input_disconnect(); 2133 2182 return -1; 2134 2183 } 2135 2136 fibril_mutex_lock(&viewport_list_mtx); 2184 2137 2185 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 2186 char *svc_name; 2150 2187 rc = loc_service_get_name(svcs[i], &svc_name); … … 2156 2193 } 2157 2194 } 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 2172 static int compositor_srv_init(char *input_svc, char *name)2173 {2174 /* Coordinates of the central pixel. */2175 coord_origin = UINT32_MAX / 4;2176 2177 /* Color of the viewport background. Must be opaque. */2178 bg_color = PIXEL(255, 75, 70, 75);2179 2180 /* Register compositor server. */2181 async_set_client_connection(client_connection);2182 int rc = loc_server_register(NAME);2183 if (rc != EOK) {2184 printf("%s: Unable to register server (%s)\n", NAME, str_error(rc));2185 return -1;2186 }2187 2188 /* Register interrupt handler to switch back from kconsole. */2189 async_set_interrupt_received(interrupt_received);2190 rc = event_subscribe(EVENT_KCONSOLE, 0);2191 if (rc != EOK) {2192 printf("%s: Failed to register kconsole notifications (%s)\n",2193 NAME, str_error(rc));2194 }2195 2196 server_name = name;2197 2198 char svc[LOC_NAME_MAXLEN + 1];2199 snprintf(svc, LOC_NAME_MAXLEN, "%s/%s", NAMESPACE, server_name);2200 2201 service_id_t service_id;2202 rc = loc_service_register(svc, &service_id);2203 if (rc != EOK) {2204 printf("%s: Unable to register service %s\n", NAME, svc);2205 return rc;2206 }2207 2208 /* Prepare window registrator (entrypoint for clients). */2209 char winreg[LOC_NAME_MAXLEN + 1];2210 snprintf(winreg, LOC_NAME_MAXLEN, "%s%s/winreg", NAMESPACE, server_name);2211 if (loc_service_register(winreg, &winreg_id) != EOK) {2212 printf("%s: Unable to register service %s\n", NAME, winreg);2213 return -1;2214 }2215 2216 /* Establish input bidirectional connection. */2217 rc = input_connect(input_svc);2218 if (rc != EOK) {2219 printf("%s: Failed to connect to input service.\n", NAME);2220 return rc;2221 }2222 2223 rc = loc_register_cat_change_cb(category_change_cb);2224 if (rc != EOK) {2225 printf("%s: Failed to register category change callback\n", NAME);2226 input_disconnect();2227 return rc;2228 }2229 2230 rc = discover_viewports();2231 if (rc != EOK) {2232 input_disconnect();2233 return rc;2234 }2235 2195 2236 2196 if (list_empty(&viewport_list)) { … … 2243 2203 comp_damage(0, 0, UINT32_MAX, UINT32_MAX); 2244 2204 2245 2246 2205 return EOK; 2247 2206 } -
uspace/srv/net/dnsrsrv/dnsrsrv.c
rddd0499d r7de1988c 60 60 rc = transport_init(); 61 61 if (rc != EOK) { 62 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing t ransport.");62 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed initializing tarnsport."); 63 63 return EIO; 64 64 } -
uspace/srv/net/ethip/arp.c
rddd0499d r7de1988c 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 106 100 int rc = atrans_lookup(ip_addr, mac_addr); 107 101 if (rc == EOK) -
uspace/srv/net/ethip/ethip_nic.c
rddd0499d r7de1988c 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 211 204 log_msg(LOG_DEFAULT, LVL_DEBUG, "Initialized IP link service,"); 212 205 -
uspace/srv/net/inetsrv/icmp.c
rddd0499d r7de1988c 105 105 reply->checksum = host2uint16_t_be(checksum); 106 106 107 rdgram.iplink = 0;108 107 rdgram.src = dgram->dest; 109 108 rdgram.dest = dgram->src; … … 172 171 inet_addr_set(sdu->dest, &dgram.dest); 173 172 174 dgram.iplink = 0;175 173 dgram.tos = ICMP_TOS; 176 174 dgram.data = rdata; -
uspace/srv/net/inetsrv/inet_link.c
rddd0499d r7de1988c 235 235 inet_addrobj_t *addr = NULL; 236 236 237 /* XXX FIXME Cannot rely on loopback being the first IP link service!! */238 237 if (first_link) { 239 238 addr = inet_addrobj_new(); … … 241 240 inet_naddr(&addr->naddr, 127, 0, 0, 1, 24); 242 241 first_link = false; 242 } else { 243 /* 244 * FIXME 245 * Setting static IPv4 address for testing purposes: 246 * 10.0.2.15/24 247 */ 248 addr = inet_addrobj_new(); 249 250 inet_naddr(&addr->naddr, 10, 0, 2, 15, 24); 243 251 } 244 252 -
uspace/srv/net/inetsrv/inetsrv.c
rddd0499d r7de1988c 68 68 }; 69 69 70 static inet_addr_t broadcast4_all_hosts = {71 .family = AF_INET,72 .addr = 0xffffffff73 };74 75 70 static inet_addr_t multicast_all_nodes = { 76 71 .family = AF_INET6, … … 124 119 } 125 120 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 126 132 rc = inet_link_discovery_start(); 127 133 if (rc != EOK) … … 180 186 { 181 187 inet_dir_t dir; 182 inet_link_t *ilink;183 188 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 */204 189 205 190 rc = inet_find_dir(&dgram->src, &dgram->dest, dgram->tos, &dir); … … 229 214 230 215 /* 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 }236 216 inet_naddr_addr(&dir.aobj->naddr, local); 237 217 return EOK; … … 302 282 inet_dgram_t dgram; 303 283 304 dgram.iplink = IPC_GET_ARG1(*icall); 305 dgram.tos = IPC_GET_ARG2(*icall); 306 307 uint8_t ttl = IPC_GET_ARG3(*icall); 284 dgram.tos = IPC_GET_ARG1(*icall); 285 286 uint8_t ttl = IPC_GET_ARG2(*icall); 308 287 int df = IPC_GET_ARG3(*icall); 309 288 … … 545 524 if ((addr != NULL) || 546 525 (inet_naddr_compare_mask(&solicited_node_mask, &packet->dest)) || 547 (inet_addr_compare(&multicast_all_nodes, &packet->dest)) || 548 (inet_addr_compare(&broadcast4_all_hosts, &packet->dest))) { 526 (inet_addr_compare(&multicast_all_nodes, &packet->dest))) { 549 527 /* Destined for one of the local addresses */ 550 528 -
uspace/srv/net/inetsrv/inetsrv.h
rddd0499d r7de1988c 127 127 128 128 typedef struct { 129 service_id_t iplink;130 129 inet_addr_t src; 131 130 inet_addr_t dest; -
uspace/srv/net/slip/slip.c
rddd0499d r7de1988c 333 333 "Failed to connect to service %s (ID=%d)", 334 334 svcstr, (int) svcid); 335 return ENOENT;335 return rc; 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;345 344 goto fail; 346 345 } … … 366 365 log_msg(LOG_DEFAULT, LVL_ERROR, 367 366 "Failed to create receive fibril."); 368 rc = ENOENT;369 367 goto fail; 370 368 } -
uspace/srv/net/tcp/tcp.c
rddd0499d r7de1988c 141 141 pdu->text_size); 142 142 143 dgram.iplink = 0;144 143 dgram.src = pdu->src; 145 144 dgram.dest = pdu->dest; -
uspace/srv/net/udp/assoc.c
rddd0499d r7de1988c 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 Association191 * @param iplink IP link192 */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);200 186 } 201 187 -
uspace/srv/net/udp/assoc.h
rddd0499d r7de1988c 36 36 #define ASSOC_H 37 37 38 #include <ipc/loc.h>39 38 #include <sys/types.h> 40 39 #include "udp_type.h" … … 46 45 extern void udp_assoc_addref(udp_assoc_t *); 47 46 extern void udp_assoc_delref(udp_assoc_t *); 48 extern void udp_assoc_set_iplink(udp_assoc_t *, service_id_t);49 47 extern void udp_assoc_set_foreign(udp_assoc_t *, udp_sock_t *); 50 48 extern void udp_assoc_set_local(udp_assoc_t *, udp_sock_t *); -
uspace/srv/net/udp/pdu.c
rddd0499d r7de1988c 215 215 return ENOMEM; 216 216 217 npdu->iplink = sp->iplink;218 217 npdu->src = sp->local.addr; 219 218 npdu->dest = sp->foreign.addr; -
uspace/srv/net/udp/sock.c
rddd0499d r7de1988c 1 1 /* 2 2 * Copyright (c) 2008 Lukas Mejdrech 3 * Copyright (c) 201 3Jiri Svoboda3 * Copyright (c) 2012 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) && 352 socket->assoc->ident.iplink == 0) { 351 if (inet_addr_is_any(&socket->assoc->ident.local.addr)) { 353 352 /* Determine local IP address */ 354 353 inet_addr_t loc_addr; … … 666 665 static void udp_sock_setsockopt(udp_client_t *client, ipc_callid_t callid, ipc_call_t call) 667 666 { 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 667 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_setsockopt()"); 668 async_answer_0(callid, ENOTSUP); 669 } 713 670 714 671 static int udp_sock_recv_fibril(void *arg) … … 757 714 758 715 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_recv_fibril() exited loop"); 716 fibril_mutex_unlock(&sock->recv_buffer_lock); 759 717 udp_uc_destroy(sock->assoc); 760 718 … … 772 730 /* Accept the connection */ 773 731 async_answer_0(iid, EOK); 774 775 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_connection: begin");776 732 777 733 client.sess = async_callback_receive(EXCHANGE_SERIALIZE); -
uspace/srv/net/udp/ucall.c
rddd0499d r7de1988c 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);65 57 } 66 58 -
uspace/srv/net/udp/ucall.h
rddd0499d r7de1988c 36 36 #define UCALL_H 37 37 38 #include <ipc/loc.h>39 38 #include <sys/types.h> 40 39 #include "udp_type.h" 41 40 42 41 extern udp_error_t udp_uc_create(udp_assoc_t **); 43 extern void udp_uc_set_iplink(udp_assoc_t *, service_id_t);44 42 extern udp_error_t udp_uc_set_foreign(udp_assoc_t *, udp_sock_t *); 45 43 extern udp_error_t udp_uc_set_local(udp_assoc_t *, udp_sock_t *); -
uspace/srv/net/udp/udp_inet.c
rddd0499d r7de1988c 84 84 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_transmit_pdu()"); 85 85 86 dgram.iplink = pdu->iplink;87 86 dgram.src = pdu->src; 88 87 dgram.dest = pdu->dest; -
uspace/srv/net/udp/udp_type.h
rddd0499d r7de1988c 38 38 #include <fibril.h> 39 39 #include <fibril_synch.h> 40 #include <ipc/loc.h>41 40 #include <socket_core.h> 42 41 #include <sys/types.h> … … 72 71 73 72 typedef struct { 74 service_id_t iplink;75 73 udp_sock_t local; 76 74 udp_sock_t foreign; … … 87 85 /** Encoded PDU */ 88 86 typedef struct { 89 /** IP link (optional) */90 service_id_t iplink;91 87 /** Source address */ 92 88 inet_addr_t src; 93 89 /** Destination address */ 94 90 inet_addr_t dest; 91 95 92 /** Encoded PDU data including header */ 96 93 void *data; … … 146 143 /** Connection */ 147 144 udp_assoc_t *assoc; 148 /** User-configured IP link */149 service_id_t iplink;150 145 /** Receiving fibril */ 151 146 fid_t recv_fibril;
Note:
See TracChangeset
for help on using the changeset viewer.