Subversion Repositories HelenOS

Rev

Rev 1888 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1595 palkovsky 1
/*
2
 * Copyright (C) 2006 Ondrej Palkovsky
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
1888 jermar 29
/** @addtogroup genericklog
1702 cejka 30
 * @{
31
 */
32
/** @file
33
 */
34
 
1595 palkovsky 35
#include <mm/frame.h>
36
#include <sysinfo/sysinfo.h>
37
#include <console/klog.h>
38
#include <print.h>
1923 jermar 39
#include <ddi/device.h>
40
#include <ddi/irq.h>
1595 palkovsky 41
#include <ipc/irq.h>
42
 
43
/* Order of frame to be allocated for klog communication */
1923 jermar 44
#define KLOG_ORDER  0
1595 palkovsky 45
 
46
static char *klog;
47
static int klogsize;
48
static int klogpos;
49
 
50
SPINLOCK_INITIALIZE(klog_lock);
51
 
1923 jermar 52
static irq_t klog_irq;
53
 
54
static irq_ownership_t klog_claim(void);
55
 
1643 palkovsky 56
/** Initialize kernel logging facility
1595 palkovsky 57
 *
1643 palkovsky 58
 * Allocate pages that are to be shared with uspace for console data.
59
 * The shared area is a circular buffer. Userspace application may
60
 * be notified on new data with indication of position and size
61
 * of the data within the circular buffer.
1595 palkovsky 62
 */
63
void klog_init(void)
64
{
65
    void *faddr;
66
 
1760 palkovsky 67
    faddr = frame_alloc(KLOG_ORDER, FRAME_ATOMIC);
1595 palkovsky 68
    if (!faddr)
69
        panic("Cannot allocate page for klog");
70
    klog = (char *)PA2KA(faddr);
71
 
1923 jermar 72
    devno_t devno = device_assign_devno();
73
 
1780 jermar 74
    sysinfo_set_item_val("klog.faddr", NULL, (unative_t)faddr);
1595 palkovsky 75
    sysinfo_set_item_val("klog.pages", NULL, 1 << KLOG_ORDER);
1923 jermar 76
    sysinfo_set_item_val("klog.devno", NULL, devno);
77
    sysinfo_set_item_val("klog.inr", NULL, VIRT_INR_KLOG);
1595 palkovsky 78
 
1923 jermar 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);
84
 
1595 palkovsky 85
    klogsize = PAGE_SIZE << KLOG_ORDER;
86
    klogpos = 0;
87
}
88
 
1923 jermar 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
 
1595 palkovsky 100
static void klog_vprintf(const char *fmt, va_list args)
101
{
102
    int ret;
103
    va_list atst;
104
 
105
    va_copy(atst, args);
106
    spinlock_lock(&klog_lock);
107
 
108
    ret = vsnprintf(klog+klogpos, klogsize-klogpos, fmt, atst);
1613 palkovsky 109
    if (ret >= klogsize-klogpos) {
1595 palkovsky 110
        klogpos = 0;
1613 palkovsky 111
        if (ret >= klogsize)
1595 palkovsky 112
            goto out;
113
    }
1923 jermar 114
    ipc_irq_send_msg(&klog_irq, klogpos, ret, 0);
1595 palkovsky 115
    klogpos += ret;
116
    if (klogpos >= klogsize)
117
        klogpos = 0;
118
out:
119
    spinlock_unlock(&klog_lock);
120
    va_end(atst);
121
}
122
 
123
/** Printf a message to kernel-uspace log */
124
void klog_printf(const char *fmt, ...)
125
{
126
    va_list args;
127
 
128
    va_start(args, fmt);
129
 
130
    klog_vprintf(fmt, args);
131
 
132
    va_end(args);
133
}
1702 cejka 134
 
1888 jermar 135
/** @}
1702 cejka 136
 */