/* * console_unregister * @console: Console data. * This function will unregister a console. */ void console_unregister(CONSOLE *console) { /* This could be a file descriptor chain, so destroy it. */ fs_destroy_chain((FD)&console->fs); #ifndef CONFIG_SEMAPHORE /* Lock the scheduler. */ scheduler_lock(); #else /* Obtain the global data lock. */ OS_ASSERT(semaphore_obtain(&console_data.lock, MAX_WAIT) != SUCCESS); /* Obtain the lock for the console needed to be unregistered. */ if (semaphore_obtain(&console->lock, MAX_WAIT) == SUCCESS) { #endif /* Resume all tasks waiting on this file descriptor. */ fd_handle_criteria((FD)console, NULL, FS_NODE_DELETED); #ifdef CONFIG_SEMAPHORE /* Delete the console lock. */ semaphore_destroy(&console->lock); #endif /* Just remove this console from console list. */ OS_ASSERT(sll_remove(&console_data.list, console, OFFSETOF(CONSOLE, fs.next)) != console); #ifdef CONFIG_SEMAPHORE } /* Release the global data lock. */ semaphore_release(&console_data.lock); #else /* Enable scheduling. */ scheduler_unlock(); #endif } /* console_unregister */
/* * console_lock * @fd: File descriptor for the console. * This function will get the lock for a given console. */ static int32_t console_lock(void *fd) { #ifdef CONFIG_SEMAPHORE /* Obtain data lock for this console. */ return semaphore_obtain(&((CONSOLE *)fd)->lock, MAX_WAIT); #else /* Remove some compiler warnings. */ UNUSED_PARAM(fd); /* Lock scheduler. */ scheduler_lock(); /* Return success. */ return (SUCCESS); #endif } /* console_lock */
/* * net_buffer_lock * @fd: Networking buffer file descriptor. * This function will get the lock for net buffer file descriptor. */ static int32_t net_buffer_lock(void *fd) { #ifdef CONFIG_SEMAPHORE /* Obtain data lock for networking buffers. */ return semaphore_obtain(&((NET_BUFFER_FS *)fd)->lock, MAX_WAIT); #else /* Remove some compiler warnings. */ UNUSED_PARAM(fd); /* Lock scheduler. */ scheduler_lock(); /* Return success. */ return (SUCCESS); #endif } /* net_buffer_lock */
/* * console_open * @name: Console name. * @flags: Open flags. * This function will open a console node. */ static void *console_open(char *name, uint32_t flags) { NODE_PARAM param; void *fd = NULL; #ifdef CONFIG_SEMAPHORE /* Obtain the global data lock. */ OS_ASSERT(semaphore_obtain(&console_data.lock, MAX_WAIT) != SUCCESS); #endif /* Initialize a search parameter. */ param.name = name; param.priv = (void *)fd; /* First find a file system to which this call can be forwarded. */ sll_search(&console_data.list, NULL, &fs_sreach_node, ¶m, OFFSETOF(CONSOLE, fs.next)); /* If a node was found. */ if (param.priv) { /* Use this FD, we will update it if required. */ fd = param.priv; } #ifdef CONFIG_SEMAPHORE /* Release the global data lock. */ semaphore_release(&console_data.lock); #endif if (fd != NULL) { /* Check if we need to call the underlying function to get a new file * descriptor. */ if (((CONSOLE *)fd)->fs.open != NULL) { /* Call the underlying API to get the file descriptor. */ fd = ((CONSOLE *)fd)->fs.open(name, flags); } } /* Return the file descriptor. */ return (fd); } /* console_open */
/* * console_register * @console: Console data. * This function will register a console. */ void console_register(CONSOLE *console) { #ifndef CONFIG_SEMAPHORE /* Lock the scheduler. */ scheduler_lock(); #else /* Obtain the global data lock. */ OS_ASSERT(semaphore_obtain(&console_data.lock, MAX_WAIT) != SUCCESS); /* Create a semaphore to protect this console device. */ memset(&console->lock, 0, sizeof(SEMAPHORE)); semaphore_create(&console->lock, 1, 1, SEMAPHORE_PRIORITY); #endif /* This utility is called by drivers for registering consoles for the * applicable devices, so no need to check for name conflicts. */ /* Just push this file system in the list. */ sll_push(&console_data.list, console, OFFSETOF(CONSOLE, fs.next)); /* Initialize console FS data. */ console->fs.get_lock = console_lock; console->fs.release_lock = console_unlock; console->fs.timeout = MAX_WAIT; /* Initialize file system condition. */ fs_condition_init(&console->fs); #ifdef CONFIG_SEMAPHORE /* Release the global data lock. */ semaphore_release(&console_data.lock); #else /* Enable scheduling. */ scheduler_unlock(); #endif } /* console_register */
/* * mem_dynamic_print_usage * @mem_dynamic: The memory region. * @level: Flags to specify level of required information. * This function will print the information about a given dynamic region. */ void mem_dynamic_print_usage(MEM_DYNAMIC *mem_dynamic, uint32_t level) { uint32_t start, end, i, free, total_free = 0; MEM_FREE *free_mem; #ifdef CONFIG_SEMAPHORE /* Obtain the memory lock. */ OS_ASSERT(semaphore_obtain(&mem_dynamic->lock, MAX_WAIT) != SUCCESS); #else /* Lock the scheduler. */ scheduler_lock(); #endif /* CONFIG_SEMAPHORE */ /* Memory general information. */ if (level & STAT_MEM_GENERAL) { start = (uint32_t)mem_dynamic->pages[0].base_start; end = (uint32_t)mem_dynamic->pages[mem_dynamic->num_pages - 1].base_end; /* Print general information about this memory region. */ printf("Memory Region Information:\r\n"); printf("Start\t\t: 0x%X\r\n", start); printf("End\t\t: 0x%X\r\n", end); printf("Total Size\t: %d\r\n", (end - start)); } /* Page information. */ if ((level & STAT_MEM_PAGE_INFO) || (level & STAT_MEM_GENERAL)) { /* If we are only printing page information. */ if (!(level & STAT_MEM_GENERAL)) { printf("Memory Page(s) Information:\r\n"); } /* If we need to print page information. */ if (level & STAT_MEM_PAGE_INFO) { printf("P[n]\tStart\t\tEnd\t\tFree\r\n"); } /* Go through all the pages in this memory region. */ for (i = 0; i < mem_dynamic->num_pages; i++) { /* Calculate free memory on this page. */ free = 0; free_mem = mem_dynamic->pages[i].free_list.head; /* Go through free memory list. */ while (free_mem) { free += free_mem->descriptor.size; free_mem = free_mem->next; } /* Add it to total free. */ total_free += free; /* If we need to print per page information. */ if (level & STAT_MEM_PAGE_INFO) { printf("[%d]\t0x%X\t0x%X\t%d\r\n", i, mem_dynamic->pages[i].base_start, mem_dynamic->pages[i].base_end, free); } } /* Print total number of bytes free in this memory region. */ printf("Total Free\t: %d\r\n", total_free); } #ifdef CONFIG_SEMAPHORE /* Release the memory lock. */ semaphore_release(&mem_dynamic->lock); #else /* Enable scheduling. */ scheduler_unlock(); #endif /* CONFIG_SEMAPHORE */ } /* mem_dynamic_print_usage */