Subversion Repositories HelenOS

Rev

Rev 1888 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1888 Rev 1923
Line 34... Line 34...
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>
-
 
40
#include <ddi/irq.h>
39
#include <ipc/irq.h>
41
#include <ipc/irq.h>
40
 
42
 
41
/* Order of frame to be allocated for klog communication */
43
/* Order of frame to be allocated for klog communication */
42
#define KLOG_ORDER 0
44
#define KLOG_ORDER  0
43
 
45
 
44
static char *klog;
46
static char *klog;
45
static int klogsize;
47
static int klogsize;
46
static int klogpos;
48
static int klogpos;
47
 
49
 
48
SPINLOCK_INITIALIZE(klog_lock);
50
SPINLOCK_INITIALIZE(klog_lock);
49
 
51
 
-
 
52
static irq_t klog_irq;
-
 
53
 
-
 
54
static irq_ownership_t klog_claim(void);
-
 
55
 
50
/** Initialize kernel logging facility
56
/** Initialize kernel logging facility
51
 *
57
 *
52
 * Allocate pages that are to be shared with uspace for console data.
58
 * Allocate pages that are to be shared with uspace for console data.
53
 * The shared area is a circular buffer. Userspace application may
59
 * The shared area is a circular buffer. Userspace application may
54
 * be notified on new data with indication of position and size
60
 * be notified on new data with indication of position and size
Line 61... Line 67...
61
    faddr = frame_alloc(KLOG_ORDER, FRAME_ATOMIC);
67
    faddr = frame_alloc(KLOG_ORDER, FRAME_ATOMIC);
62
    if (!faddr)
68
    if (!faddr)
63
        panic("Cannot allocate page for klog");
69
        panic("Cannot allocate page for klog");
64
    klog = (char *)PA2KA(faddr);
70
    klog = (char *)PA2KA(faddr);
65
   
71
   
-
 
72
    devno_t devno = device_assign_devno();
-
 
73
   
66
    sysinfo_set_item_val("klog.faddr", NULL, (unative_t)faddr);
74
    sysinfo_set_item_val("klog.faddr", NULL, (unative_t)faddr);
67
    sysinfo_set_item_val("klog.pages", NULL, 1 << KLOG_ORDER);
75
    sysinfo_set_item_val("klog.pages", NULL, 1 << KLOG_ORDER);
-
 
76
    sysinfo_set_item_val("klog.devno", NULL, devno);
-
 
77
    sysinfo_set_item_val("klog.inr", NULL, VIRT_INR_KLOG);
-
 
78
 
-
 
79
    irq_initialize(&klog_irq);
-
 
80
    klog_irq.devno = devno;
-
 
81
    klog_irq.inr = VIRT_INR_KLOG;
-
 
82
    klog_irq.claim = klog_claim;
-
 
83
    irq_register(&klog_irq);
68
 
84
 
69
    klogsize = PAGE_SIZE << KLOG_ORDER;
85
    klogsize = PAGE_SIZE << KLOG_ORDER;
70
    klogpos = 0;
86
    klogpos = 0;
71
}
87
}
72
 
88
 
-
 
89
/** Allways refuse IRQ ownership.
-
 
90
 *
-
 
91
 * This is not a real IRQ, so we always decline.
-
 
92
 *
-
 
93
 * @return Always returns IRQ_DECLINE.
-
 
94
 */
-
 
95
irq_ownership_t klog_claim(void)
-
 
96
{
-
 
97
    return IRQ_DECLINE;
-
 
98
}
-
 
99
 
73
static void klog_vprintf(const char *fmt, va_list args)
100
static void klog_vprintf(const char *fmt, va_list args)
74
{
101
{
75
    int ret;
102
    int ret;
76
    va_list atst;
103
    va_list atst;
77
 
104
 
Line 82... Line 109...
82
    if (ret >= klogsize-klogpos) {
109
    if (ret >= klogsize-klogpos) {
83
        klogpos = 0;
110
        klogpos = 0;
84
        if (ret >= klogsize)
111
        if (ret >= klogsize)
85
            goto out;
112
            goto out;
86
    }
113
    }
87
    ipc_irq_send_msg(IPC_IRQ_KLOG, klogpos, ret, 0);
114
    ipc_irq_send_msg(&klog_irq, klogpos, ret, 0);
88
    klogpos += ret;
115
    klogpos += ret;
89
    if (klogpos >= klogsize)
116
    if (klogpos >= klogsize)
90
        klogpos = 0;
117
        klogpos = 0;
91
out:
118
out:
92
    spinlock_unlock(&klog_lock);
119
    spinlock_unlock(&klog_lock);