Changeset 6119f24 in mainline
- Timestamp:
- 2011-01-29T18:58:24Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 10477601, 6aef742
- Parents:
- d7533c7
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/klog/klog.c
rd7533c7 r6119f24 36 36 37 37 #include <stdio.h> 38 #include <ipc/ns.h>39 38 #include <async.h> 40 #include <ipc/services.h>41 39 #include <as.h> 42 #include < sysinfo.h>40 #include <ddi.h> 43 41 #include <event.h> 44 42 #include <errno.h> 45 43 #include <str_error.h> 46 44 #include <io/klog.h> 45 #include <sysinfo.h> 47 46 48 47 #define NAME "klog" … … 79 78 int main(int argc, char *argv[]) 80 79 { 81 klog = service_klog_share_in(&klog_length); 82 if (klog == NULL) { 83 printf("%s: Error accessing to klog\n", NAME); 84 return -1; 80 size_t pages; 81 int rc = sysinfo_get_value("klog.pages", &pages); 82 if (rc != EOK) { 83 fprintf(stderr, "%s: Unable to get number of klog pages\n", 84 NAME); 85 return rc; 85 86 } 86 87 87 if (event_subscribe(EVENT_KLOG, 0) != EOK) { 88 printf("%s: Error registering klog notifications\n", NAME); 89 return -1; 88 uintptr_t faddr; 89 rc = sysinfo_get_value("klog.faddr", &faddr); 90 if (rc != EOK) { 91 fprintf(stderr, "%s: Unable to get klog physical address\n", 92 NAME); 93 return rc; 94 } 95 96 size_t size = pages * PAGE_SIZE; 97 klog_length = size / sizeof(wchar_t); 98 99 klog = (wchar_t *) as_get_mappable_page(size); 100 if (klog == NULL) { 101 fprintf(stderr, "%s: Unable to allocate virtual memory area\n", 102 NAME); 103 return ENOMEM; 104 } 105 106 rc = physmem_map((void *) faddr, (void *) klog, pages, 107 AS_AREA_READ | AS_AREA_CACHEABLE); 108 if (rc != EOK) { 109 fprintf(stderr, "%s: Unable to map klog\n", NAME); 110 return rc; 111 } 112 113 rc = event_subscribe(EVENT_KLOG, 0); 114 if (rc != EOK) { 115 fprintf(stderr, "%s: Unable to register klog notifications\n", 116 NAME); 117 return rc; 90 118 } 91 119 -
uspace/lib/c/generic/ipc/ns.c
rd7533c7 r6119f24 34 34 35 35 #include <async.h> 36 #include <ipc/services.h>37 36 #include <ipc/ns.h> 38 #include <sysinfo.h>39 #include <errno.h>40 #include <as.h>41 #include <macros.h>42 37 43 38 int service_register(sysarg_t service) … … 56 51 } 57 52 58 wchar_t *service_klog_share_in(size_t *length)59 {60 size_t pages;61 if (sysinfo_get_value("klog.pages", &pages) != EOK)62 return NULL;63 64 size_t size = pages * PAGE_SIZE;65 *length = size / sizeof(wchar_t);66 67 wchar_t *klog = (wchar_t *) as_get_mappable_page(size);68 if (klog == NULL)69 return NULL;70 71 int res = async_share_in_start_1_0(PHONE_NS, (void *) klog, size,72 SERVICE_MEM_KLOG);73 if (res != EOK) {74 as_area_destroy((void *) klog);75 return NULL;76 }77 78 return klog;79 }80 81 void *service_realtime_share_in(void)82 {83 void *rtime = as_get_mappable_page(PAGE_SIZE);84 if (rtime == NULL)85 return NULL;86 87 int res = async_share_in_start_1_0(PHONE_NS, rtime, PAGE_SIZE,88 SERVICE_MEM_REALTIME);89 if (res != EOK) {90 as_area_destroy((void *) rtime);91 return NULL;92 }93 94 return rtime;95 }96 97 53 /** @} 98 54 */ -
uspace/lib/c/generic/time.c
rd7533c7 r6119f24 34 34 35 35 #include <sys/time.h> 36 #include < unistd.h>36 #include <time.h> 37 37 #include <bool.h> 38 #include <ipc/ns.h>39 38 #include <arch/barrier.h> 40 39 #include <macros.h> 40 #include <errno.h> 41 #include <sysinfo.h> 42 #include <as.h> 43 #include <ddi.h> 41 44 #include <libc.h> 42 #include <time.h>43 45 44 46 /** Pointer to kernel shared variables with time */ … … 137 139 int gettimeofday(struct timeval *tv, struct timezone *tz) 138 140 { 139 if (!ktime) { 140 ktime = service_realtime_share_in(); 141 if (!ktime) 141 if (ktime == NULL) { 142 uintptr_t faddr; 143 int rc = sysinfo_get_value("clock.faddr", &faddr); 144 if (rc != EOK) { 145 errno = rc; 142 146 return -1; 147 } 148 149 void *addr = as_get_mappable_page(PAGE_SIZE); 150 if (addr == NULL) { 151 errno = ENOMEM; 152 return -1; 153 } 154 155 rc = physmem_map((void *) faddr, addr, 1, 156 AS_AREA_READ | AS_AREA_CACHEABLE); 157 if (rc != EOK) { 158 as_area_destroy(addr); 159 errno = rc; 160 return -1; 161 } 162 163 ktime = addr; 143 164 } 144 165 -
uspace/lib/c/include/ipc/ns.h
rd7533c7 r6119f24 50 50 extern int service_connect_blocking(sysarg_t, sysarg_t, sysarg_t); 51 51 52 extern wchar_t *service_klog_share_in(size_t *);53 extern void *service_realtime_share_in(void);54 55 52 #endif 56 53 -
uspace/lib/c/include/ipc/services.h
rd7533c7 r6119f24 66 66 } services_t; 67 67 68 /* Memory areas to be received from NS */69 typedef enum {70 SERVICE_MEM_REALTIME = 1,71 SERVICE_MEM_KLOG = 272 } mem_services_t;73 74 68 #endif 75 69 -
uspace/srv/ns/ns.c
rd7533c7 r6119f24 37 37 38 38 #include <ipc/ipc.h> 39 #include <ipc/services.h>40 39 #include <ipc/ns.h> 41 #include <unistd.h>42 40 #include <stdio.h> 43 41 #include <errno.h> 44 #include <as.h>45 #include <ddi.h>46 #include <event.h>47 42 #include <macros.h> 48 #include <sysinfo.h>49 43 #include "ns.h" 50 44 #include "service.h" 51 45 #include "clonable.h" 52 46 #include "task.h" 53 54 static void *clockaddr = NULL;55 static void *klogaddr = NULL;56 57 static void get_as_area(ipc_callid_t callid, ipc_call_t *call, void *faddr,58 size_t pages, void **addr)59 {60 if ((faddr == NULL) || (pages == 0)) {61 ipc_answer_0(callid, ENOENT);62 return;63 }64 65 if (*addr == NULL) {66 *addr = as_get_mappable_page(pages * PAGE_SIZE);67 68 if (*addr == NULL) {69 ipc_answer_0(callid, ENOENT);70 return;71 }72 73 if (physmem_map(faddr, *addr, pages,74 AS_AREA_READ | AS_AREA_CACHEABLE) != 0) {75 ipc_answer_0(callid, ENOENT);76 return;77 }78 }79 80 ipc_answer_2(callid, EOK, (sysarg_t) *addr, AS_AREA_READ);81 }82 83 static void setup_clock_area(ipc_callid_t callid, ipc_call_t *call, void **addr)84 {85 uintptr_t faddr;86 int err = sysinfo_get_value("clock.faddr", &faddr);87 88 if (err != EOK)89 ipc_answer_0(callid, err);90 91 get_as_area(callid, call, (void *) faddr, 1, addr);92 }93 94 static void setup_klog_area(ipc_callid_t callid, ipc_call_t *call, void **addr)95 {96 uintptr_t faddr;97 int err = sysinfo_get_value("klog.faddr", &faddr);98 99 if (err != EOK)100 ipc_answer_0(callid, err);101 102 size_t pages;103 err = sysinfo_get_value("klog.pages", &pages);104 105 if (err != EOK)106 ipc_answer_0(callid, err);107 108 get_as_area(callid, call, (void *) faddr, pages, addr);109 }110 47 111 48 int main(int argc, char **argv) … … 138 75 139 76 switch (IPC_GET_IMETHOD(call)) { 140 case IPC_M_SHARE_IN:141 switch (IPC_GET_ARG3(call)) {142 case SERVICE_MEM_REALTIME:143 setup_clock_area(callid, &call, &clockaddr);144 break;145 case SERVICE_MEM_KLOG:146 setup_klog_area(callid, &call, &klogaddr);147 break;148 default:149 ipc_answer_0(callid, ENOENT);150 }151 continue;152 77 case IPC_M_PHONE_HUNGUP: 153 78 retval = ns_task_disconnect(&call); -
uspace/srv/ns/task.h
rd7533c7 r6119f24 35 35 36 36 #include <ipc/common.h> 37 #include <task.h> 37 38 38 39 extern int task_init(void);
Note:
See TracChangeset
for help on using the changeset viewer.