Rev 2071 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2071 | Rev 2141 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup genericklog |
29 | /** @addtogroup genericklog |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <mm/frame.h> |
35 | #include <mm/frame.h> |
36 | #include <sysinfo/sysinfo.h> |
36 | #include <sysinfo/sysinfo.h> |
37 | #include <console/klog.h> |
37 | #include <console/klog.h> |
38 | #include <print.h> |
38 | #include <print.h> |
39 | #include <ddi/device.h> |
39 | #include <ddi/device.h> |
40 | #include <ddi/irq.h> |
40 | #include <ddi/irq.h> |
41 | #include <ddi/ddi.h> |
41 | #include <ddi/ddi.h> |
42 | #include <ipc/irq.h> |
42 | #include <ipc/irq.h> |
43 | 43 | ||
44 | /** Physical memory area used for klog. */ |
44 | /** Physical memory area used for klog. */ |
45 | static parea_t klog_parea; |
45 | static parea_t klog_parea; |
46 | 46 | ||
47 | /* |
47 | /* |
48 | * For now, we use 0 as INR. |
48 | * For now, we use 0 as INR. |
49 | * However, on some architectures 0 is the clock interrupt (e.g. amd64 and |
49 | * However, on some architectures 0 is the clock interrupt (e.g. amd64 and |
50 | * ia32). It is therefore desirable to have architecture specific definition of |
50 | * ia32). It is therefore desirable to have architecture specific definition of |
51 | * KLOG_VIRT_INR in the future. |
51 | * KLOG_VIRT_INR in the future. |
52 | */ |
52 | */ |
53 | #define KLOG_VIRT_INR 0 |
53 | #define KLOG_VIRT_INR 0 |
54 | 54 | ||
55 | /* Order of frame to be allocated for klog communication */ |
55 | /* Order of frame to be allocated for klog communication */ |
56 | #define KLOG_ORDER 0 |
56 | #define KLOG_ORDER 0 |
57 | 57 | ||
58 | static char *klog; |
58 | static char *klog; |
59 | static int klogsize; |
59 | static int klogsize; |
60 | static int klogpos; |
60 | static int klogpos; |
61 | 61 | ||
62 | SPINLOCK_INITIALIZE(klog_lock); |
62 | SPINLOCK_INITIALIZE(klog_lock); |
63 | 63 | ||
64 | static irq_t klog_irq; |
64 | static irq_t klog_irq; |
65 | 65 | ||
66 | static irq_ownership_t klog_claim(void); |
66 | static irq_ownership_t klog_claim(void); |
67 | 67 | ||
68 | /** Initialize kernel logging facility |
68 | /** Initialize kernel logging facility |
69 | * |
69 | * |
70 | * Allocate pages that are to be shared with uspace for console data. |
70 | * Allocate pages that are to be shared with uspace for console data. |
71 | * The shared area is a circular buffer. Userspace application may |
71 | * The shared area is a circular buffer. Userspace application may |
72 | * be notified on new data with indication of position and size |
72 | * be notified on new data with indication of position and size |
73 | * of the data within the circular buffer. |
73 | * of the data within the circular buffer. |
74 | */ |
74 | */ |
75 | void klog_init(void) |
75 | void klog_init(void) |
76 | { |
76 | { |
77 | void *faddr; |
77 | void *faddr; |
78 | 78 | ||
79 | faddr = frame_alloc(KLOG_ORDER, FRAME_ATOMIC); |
79 | faddr = frame_alloc(KLOG_ORDER, FRAME_ATOMIC); |
80 | if (!faddr) |
80 | if (!faddr) |
81 | panic("Cannot allocate page for klog"); |
81 | panic("Cannot allocate page for klog"); |
82 | klog = (char *) PA2KA(faddr); |
82 | klog = (char *) PA2KA(faddr); |
83 | 83 | ||
84 | devno_t devno = device_assign_devno(); |
84 | devno_t devno = device_assign_devno(); |
85 | 85 | ||
86 | klog_parea.pbase = (uintptr_t) faddr; |
86 | klog_parea.pbase = (uintptr_t) faddr; |
87 | klog_parea.vbase = (uintptr_t) klog; |
87 | klog_parea.vbase = (uintptr_t) klog; |
88 | klog_parea.frames = 1 << KLOG_ORDER; |
88 | klog_parea.frames = 1 << KLOG_ORDER; |
89 | klog_parea.cacheable = true; |
89 | klog_parea.cacheable = true; |
90 | ddi_parea_register(&klog_parea); |
90 | ddi_parea_register(&klog_parea); |
91 | 91 | ||
92 | sysinfo_set_item_val("klog.faddr", NULL, (unative_t) faddr); |
92 | sysinfo_set_item_val("klog.faddr", NULL, (unative_t) faddr); |
93 | sysinfo_set_item_val("klog.fcolor", NULL, (unative_t) |
- | |
94 | PAGE_COLOR((uintptr_t) klog)); |
- | |
95 | sysinfo_set_item_val("klog.pages", NULL, 1 << KLOG_ORDER); |
93 | sysinfo_set_item_val("klog.pages", NULL, 1 << KLOG_ORDER); |
96 | sysinfo_set_item_val("klog.devno", NULL, devno); |
94 | sysinfo_set_item_val("klog.devno", NULL, devno); |
97 | sysinfo_set_item_val("klog.inr", NULL, KLOG_VIRT_INR); |
95 | sysinfo_set_item_val("klog.inr", NULL, KLOG_VIRT_INR); |
98 | 96 | ||
99 | irq_initialize(&klog_irq); |
97 | irq_initialize(&klog_irq); |
100 | klog_irq.devno = devno; |
98 | klog_irq.devno = devno; |
101 | klog_irq.inr = KLOG_VIRT_INR; |
99 | klog_irq.inr = KLOG_VIRT_INR; |
102 | klog_irq.claim = klog_claim; |
100 | klog_irq.claim = klog_claim; |
103 | irq_register(&klog_irq); |
101 | irq_register(&klog_irq); |
104 | 102 | ||
105 | klogsize = PAGE_SIZE << KLOG_ORDER; |
103 | klogsize = PAGE_SIZE << KLOG_ORDER; |
106 | klogpos = 0; |
104 | klogpos = 0; |
107 | } |
105 | } |
108 | 106 | ||
109 | /** Allways refuse IRQ ownership. |
107 | /** Allways refuse IRQ ownership. |
110 | * |
108 | * |
111 | * This is not a real IRQ, so we always decline. |
109 | * This is not a real IRQ, so we always decline. |
112 | * |
110 | * |
113 | * @return Always returns IRQ_DECLINE. |
111 | * @return Always returns IRQ_DECLINE. |
114 | */ |
112 | */ |
115 | irq_ownership_t klog_claim(void) |
113 | irq_ownership_t klog_claim(void) |
116 | { |
114 | { |
117 | return IRQ_DECLINE; |
115 | return IRQ_DECLINE; |
118 | } |
116 | } |
119 | 117 | ||
120 | static void klog_vprintf(const char *fmt, va_list args) |
118 | static void klog_vprintf(const char *fmt, va_list args) |
121 | { |
119 | { |
122 | int ret; |
120 | int ret; |
123 | va_list atst; |
121 | va_list atst; |
124 | 122 | ||
125 | va_copy(atst, args); |
123 | va_copy(atst, args); |
126 | spinlock_lock(&klog_lock); |
124 | spinlock_lock(&klog_lock); |
127 | 125 | ||
128 | ret = vsnprintf(klog+klogpos, klogsize-klogpos, fmt, atst); |
126 | ret = vsnprintf(klog+klogpos, klogsize-klogpos, fmt, atst); |
129 | if (ret >= klogsize-klogpos) { |
127 | if (ret >= klogsize-klogpos) { |
130 | klogpos = 0; |
128 | klogpos = 0; |
131 | if (ret >= klogsize) |
129 | if (ret >= klogsize) |
132 | goto out; |
130 | goto out; |
133 | } |
131 | } |
134 | ipc_irq_send_msg(&klog_irq, klogpos, ret, 0); |
132 | ipc_irq_send_msg(&klog_irq, klogpos, ret, 0); |
135 | klogpos += ret; |
133 | klogpos += ret; |
136 | if (klogpos >= klogsize) |
134 | if (klogpos >= klogsize) |
137 | klogpos = 0; |
135 | klogpos = 0; |
138 | out: |
136 | out: |
139 | spinlock_unlock(&klog_lock); |
137 | spinlock_unlock(&klog_lock); |
140 | va_end(atst); |
138 | va_end(atst); |
141 | } |
139 | } |
142 | 140 | ||
143 | /** Printf a message to kernel-uspace log */ |
141 | /** Printf a message to kernel-uspace log */ |
144 | void klog_printf(const char *fmt, ...) |
142 | void klog_printf(const char *fmt, ...) |
145 | { |
143 | { |
146 | va_list args; |
144 | va_list args; |
147 | 145 | ||
148 | va_start(args, fmt); |
146 | va_start(args, fmt); |
149 | 147 | ||
150 | klog_vprintf(fmt, args); |
148 | klog_vprintf(fmt, args); |
151 | 149 | ||
152 | va_end(args); |
150 | va_end(args); |
153 | } |
151 | } |
154 | 152 | ||
155 | /** @} |
153 | /** @} |
156 | */ |
154 | */ |
157 | 155 |