Rev 1923 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1923 | Rev 1924 | ||
---|---|---|---|
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 <ipc/irq.h> |
41 | #include <ipc/irq.h> |
42 | 42 | ||
- | 43 | /* |
|
- | 44 | * For now, we use 0 as INR. |
|
- | 45 | * However, on some architectures 0 is the clock interrupt (e.g. amd64 and ia32). |
|
- | 46 | * It is therefore desirable to have architecture specific definition of KLOG_VIRT_INR |
|
- | 47 | * in the future. |
|
- | 48 | */ |
|
- | 49 | #define KLOG_VIRT_INR 0 |
|
- | 50 | ||
43 | /* Order of frame to be allocated for klog communication */ |
51 | /* Order of frame to be allocated for klog communication */ |
44 | #define KLOG_ORDER 0 |
52 | #define KLOG_ORDER 0 |
45 | 53 | ||
46 | static char *klog; |
54 | static char *klog; |
47 | static int klogsize; |
55 | static int klogsize; |
48 | static int klogpos; |
56 | static int klogpos; |
49 | 57 | ||
50 | SPINLOCK_INITIALIZE(klog_lock); |
58 | SPINLOCK_INITIALIZE(klog_lock); |
51 | 59 | ||
52 | static irq_t klog_irq; |
60 | static irq_t klog_irq; |
53 | 61 | ||
54 | static irq_ownership_t klog_claim(void); |
62 | static irq_ownership_t klog_claim(void); |
55 | 63 | ||
56 | /** Initialize kernel logging facility |
64 | /** Initialize kernel logging facility |
57 | * |
65 | * |
58 | * Allocate pages that are to be shared with uspace for console data. |
66 | * Allocate pages that are to be shared with uspace for console data. |
59 | * The shared area is a circular buffer. Userspace application may |
67 | * The shared area is a circular buffer. Userspace application may |
60 | * be notified on new data with indication of position and size |
68 | * be notified on new data with indication of position and size |
61 | * of the data within the circular buffer. |
69 | * of the data within the circular buffer. |
62 | */ |
70 | */ |
63 | void klog_init(void) |
71 | void klog_init(void) |
64 | { |
72 | { |
65 | void *faddr; |
73 | void *faddr; |
66 | 74 | ||
67 | faddr = frame_alloc(KLOG_ORDER, FRAME_ATOMIC); |
75 | faddr = frame_alloc(KLOG_ORDER, FRAME_ATOMIC); |
68 | if (!faddr) |
76 | if (!faddr) |
69 | panic("Cannot allocate page for klog"); |
77 | panic("Cannot allocate page for klog"); |
70 | klog = (char *)PA2KA(faddr); |
78 | klog = (char *)PA2KA(faddr); |
71 | 79 | ||
72 | devno_t devno = device_assign_devno(); |
80 | devno_t devno = device_assign_devno(); |
73 | 81 | ||
74 | sysinfo_set_item_val("klog.faddr", NULL, (unative_t)faddr); |
82 | sysinfo_set_item_val("klog.faddr", NULL, (unative_t)faddr); |
75 | sysinfo_set_item_val("klog.pages", NULL, 1 << KLOG_ORDER); |
83 | sysinfo_set_item_val("klog.pages", NULL, 1 << KLOG_ORDER); |
76 | sysinfo_set_item_val("klog.devno", NULL, devno); |
84 | sysinfo_set_item_val("klog.devno", NULL, devno); |
77 | sysinfo_set_item_val("klog.inr", NULL, VIRT_INR_KLOG); |
85 | sysinfo_set_item_val("klog.inr", NULL, KLOG_VIRT_INR); |
78 | 86 | ||
79 | irq_initialize(&klog_irq); |
87 | irq_initialize(&klog_irq); |
80 | klog_irq.devno = devno; |
88 | klog_irq.devno = devno; |
81 | klog_irq.inr = VIRT_INR_KLOG; |
89 | klog_irq.inr = KLOG_VIRT_INR; |
82 | klog_irq.claim = klog_claim; |
90 | klog_irq.claim = klog_claim; |
83 | irq_register(&klog_irq); |
91 | irq_register(&klog_irq); |
84 | 92 | ||
85 | klogsize = PAGE_SIZE << KLOG_ORDER; |
93 | klogsize = PAGE_SIZE << KLOG_ORDER; |
86 | klogpos = 0; |
94 | klogpos = 0; |
87 | } |
95 | } |
88 | 96 | ||
89 | /** Allways refuse IRQ ownership. |
97 | /** Allways refuse IRQ ownership. |
90 | * |
98 | * |
91 | * This is not a real IRQ, so we always decline. |
99 | * This is not a real IRQ, so we always decline. |
92 | * |
100 | * |
93 | * @return Always returns IRQ_DECLINE. |
101 | * @return Always returns IRQ_DECLINE. |
94 | */ |
102 | */ |
95 | irq_ownership_t klog_claim(void) |
103 | irq_ownership_t klog_claim(void) |
96 | { |
104 | { |
97 | return IRQ_DECLINE; |
105 | return IRQ_DECLINE; |
98 | } |
106 | } |
99 | 107 | ||
100 | static void klog_vprintf(const char *fmt, va_list args) |
108 | static void klog_vprintf(const char *fmt, va_list args) |
101 | { |
109 | { |
102 | int ret; |
110 | int ret; |
103 | va_list atst; |
111 | va_list atst; |
104 | 112 | ||
105 | va_copy(atst, args); |
113 | va_copy(atst, args); |
106 | spinlock_lock(&klog_lock); |
114 | spinlock_lock(&klog_lock); |
107 | 115 | ||
108 | ret = vsnprintf(klog+klogpos, klogsize-klogpos, fmt, atst); |
116 | ret = vsnprintf(klog+klogpos, klogsize-klogpos, fmt, atst); |
109 | if (ret >= klogsize-klogpos) { |
117 | if (ret >= klogsize-klogpos) { |
110 | klogpos = 0; |
118 | klogpos = 0; |
111 | if (ret >= klogsize) |
119 | if (ret >= klogsize) |
112 | goto out; |
120 | goto out; |
113 | } |
121 | } |
114 | ipc_irq_send_msg(&klog_irq, klogpos, ret, 0); |
122 | ipc_irq_send_msg(&klog_irq, klogpos, ret, 0); |
115 | klogpos += ret; |
123 | klogpos += ret; |
116 | if (klogpos >= klogsize) |
124 | if (klogpos >= klogsize) |
117 | klogpos = 0; |
125 | klogpos = 0; |
118 | out: |
126 | out: |
119 | spinlock_unlock(&klog_lock); |
127 | spinlock_unlock(&klog_lock); |
120 | va_end(atst); |
128 | va_end(atst); |
121 | } |
129 | } |
122 | 130 | ||
123 | /** Printf a message to kernel-uspace log */ |
131 | /** Printf a message to kernel-uspace log */ |
124 | void klog_printf(const char *fmt, ...) |
132 | void klog_printf(const char *fmt, ...) |
125 | { |
133 | { |
126 | va_list args; |
134 | va_list args; |
127 | 135 | ||
128 | va_start(args, fmt); |
136 | va_start(args, fmt); |
129 | 137 | ||
130 | klog_vprintf(fmt, args); |
138 | klog_vprintf(fmt, args); |
131 | 139 | ||
132 | va_end(args); |
140 | va_end(args); |
133 | } |
141 | } |
134 | 142 | ||
135 | /** @} |
143 | /** @} |
136 | */ |
144 | */ |
137 | 145 |