1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
2 | // File : tty_driver.c |
---|
3 | // Date : 23/05/2013 |
---|
4 | // Author : alain greiner |
---|
5 | // Copyright (c) UPMC-LIP6 |
---|
6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
7 | |
---|
8 | #include <giet_config.h> |
---|
9 | #include <hard_config.h> |
---|
10 | #include <tty_driver.h> |
---|
11 | #include <xcu_driver.h> |
---|
12 | #include <ctx_handler.h> |
---|
13 | #include <utils.h> |
---|
14 | #include <tty0.h> |
---|
15 | |
---|
16 | #if !defined(SEG_TTY_BASE) |
---|
17 | # error: You must define SEG_TTY_BASE in the hard_config.h file |
---|
18 | #endif |
---|
19 | |
---|
20 | #if !defined(NB_TTY_CHANNELS) |
---|
21 | # error: You must define NB_TTY_CHANNELS in the hard_config.h file |
---|
22 | #endif |
---|
23 | |
---|
24 | #if (NB_TTY_CHANNELS == 0) |
---|
25 | # error: The NB_TTY_CHANNELS in the hard_config.h file cannot be 0 |
---|
26 | #endif |
---|
27 | |
---|
28 | //////////////////////////////////////////////////////////////////////////////////// |
---|
29 | // global variables |
---|
30 | //////////////////////////////////////////////////////////////////////////////////// |
---|
31 | |
---|
32 | simple_lock_t _tty_tx_lock[NB_TTY_CHANNELS] __attribute__((aligned(64))); |
---|
33 | |
---|
34 | unsigned int _tty_rx_buf[NB_TTY_CHANNELS]; |
---|
35 | unsigned int _tty_rx_full[NB_TTY_CHANNELS]; |
---|
36 | |
---|
37 | //////////////////////////////////////////////////////////////////////////////////// |
---|
38 | // access functions |
---|
39 | //////////////////////////////////////////////////////////////////////////////////// |
---|
40 | |
---|
41 | ///////////////////////////////////////////////////// |
---|
42 | unsigned int _tty_get_register( unsigned int channel, |
---|
43 | unsigned int index ) |
---|
44 | { |
---|
45 | unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index; |
---|
46 | return _io_extended_read( vaddr ); |
---|
47 | } |
---|
48 | |
---|
49 | ///////////////////////////////////////////// |
---|
50 | void _tty_set_register( unsigned int channel, |
---|
51 | unsigned int index, |
---|
52 | unsigned int value ) |
---|
53 | { |
---|
54 | unsigned int* vaddr = (unsigned int*)SEG_TTY_BASE + channel*TTY_SPAN + index; |
---|
55 | _io_extended_write( vaddr, value ); |
---|
56 | } |
---|
57 | |
---|
58 | ////////////////////////////////////// |
---|
59 | void _tty_init( unsigned int channel ) |
---|
60 | { |
---|
61 | _tty_rx_full[channel] = 0; |
---|
62 | } |
---|
63 | |
---|
64 | //////////////////////////////////////// |
---|
65 | void _tty_rx_isr( unsigned int irq_type, // HWI / WTI |
---|
66 | unsigned int irq_id, // index returned by XCU |
---|
67 | unsigned int channel ) // TTY channel |
---|
68 | { |
---|
69 | unsigned int gpid = _get_procid(); |
---|
70 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
71 | |
---|
72 | // get TTY status |
---|
73 | unsigned int status = _tty_get_register( channel, TTY_STATUS ); |
---|
74 | |
---|
75 | // check both TTY status and kernel buffer status: |
---|
76 | // does nothing if kernel buffer full or tty_buffer empty |
---|
77 | if ( ((status & 0x1) == 0) || |
---|
78 | (_tty_rx_full[channel] != 0) ) return; |
---|
79 | |
---|
80 | // reset WTI in XCU if WTI type |
---|
81 | if ( irq_type == IRQ_TYPE_WTI ) |
---|
82 | { |
---|
83 | unsigned int value; |
---|
84 | _xcu_get_wti_value( cluster_xy, irq_id, &value ); |
---|
85 | } |
---|
86 | |
---|
87 | // transfer character to kernel buffer and acknowledge TTY IRQ |
---|
88 | _tty_rx_buf[channel] = _tty_get_register( channel, TTY_READ ); |
---|
89 | |
---|
90 | // set kernel buffer status |
---|
91 | asm volatile( "sync" ); |
---|
92 | _tty_rx_full[channel] = 1; |
---|
93 | |
---|
94 | #if GIET_DEBUG_IRQS // we don't take the TTY lock to avoid deadlock |
---|
95 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
96 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
97 | unsigned int lpid = gpid & ((1<<P_WIDTH)-1); |
---|
98 | _puts("\n[IRQS DEBUG] Processor["); |
---|
99 | _putd(x ); |
---|
100 | _puts(","); |
---|
101 | _putd(y ); |
---|
102 | _puts(","); |
---|
103 | _putd(lpid ); |
---|
104 | _puts("] enters _tty_rx_isr() at cycle "); |
---|
105 | _putd(_get_proctime() ); |
---|
106 | _puts("\n read byte = "); |
---|
107 | _putx(_tty_rx_buf[channel] ); |
---|
108 | _puts("\n"); |
---|
109 | #endif |
---|
110 | |
---|
111 | } |
---|
112 | |
---|
113 | ///////////////////////////////////////// |
---|
114 | void _tty_tx_isr( unsigned int irq_type, // HWI / WTI |
---|
115 | unsigned int irq_id, // index returned by XCU |
---|
116 | unsigned int channel ) // TTY channel |
---|
117 | { |
---|
118 | _puts("\n[GIET ERROR] the _tty_tx_isr() is not implemented\n"); |
---|
119 | _exit(); |
---|
120 | } |
---|
121 | |
---|
122 | // Local Variables: |
---|
123 | // tab-width: 4 |
---|
124 | // c-basic-offset: 4 |
---|
125 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
126 | // indent-tabs-mode: nil |
---|
127 | // End: |
---|
128 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
129 | |
---|