source: mainline/uspace/srv/hw/irc/i8259/i8259.c@ 659ebd86

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 659ebd86 was 1558d85, checked in by Jakub Jermar <jakub@…>, 9 years ago

Remove duplicate includes

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * Copyright (c) 2011 Martin Decky
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
29/** @addtogroup i8259
30 * @{
31 */
32
33/**
34 * @file i8259.c
35 * @brief i8259 driver.
36 */
37
38#include <ipc/services.h>
39#include <ipc/irc.h>
40#include <ns.h>
41#include <sysinfo.h>
42#include <as.h>
43#include <ddi.h>
44#include <align.h>
45#include <stdbool.h>
46#include <errno.h>
47#include <async.h>
48#include <stdio.h>
49#include <ipc/loc.h>
50
51#define NAME "i8259"
52
53#define IO_RANGE0_START ((ioport8_t *) 0x0020U)
54#define IO_RANGE0_SIZE 2
55
56#define IO_RANGE1_START ((ioport8_t *) 0x00a0U)
57#define IO_RANGE1_SIZE 2
58
59static ioport8_t *io_range0;
60static ioport8_t *io_range1;
61
62#define PIC_PIC0PORT1 0
63#define PIC_PIC0PORT2 1
64
65#define PIC_PIC1PORT1 0
66#define PIC_PIC1PORT2 1
67
68#define PIC_MAX_IRQ 15
69
70static int pic_enable_irq(sysarg_t irq)
71{
72 if (irq > PIC_MAX_IRQ)
73 return ENOENT;
74
75 uint16_t irqmask = 1 << irq;
76 uint8_t val;
77
78 if (irqmask & 0xff) {
79 val = pio_read_8(io_range0 + PIC_PIC0PORT2);
80 pio_write_8(io_range0 + PIC_PIC0PORT2,
81 (uint8_t) (val & (~(irqmask & 0xff))));
82 }
83
84 if (irqmask >> 8) {
85 val = pio_read_8(io_range1 + PIC_PIC1PORT2);
86 pio_write_8(io_range1 + PIC_PIC1PORT2,
87 (uint8_t) (val & (~(irqmask >> 8))));
88 }
89
90 return EOK;
91}
92
93/** Handle one connection to i8259.
94 *
95 * @param iid Hash of the request that opened the connection.
96 * @param icall Call data of the request that opened the connection.
97 * @param arg Local argument.
98 */
99static void i8259_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
100{
101 ipc_callid_t callid;
102 ipc_call_t call;
103
104 /*
105 * Answer the first IPC_M_CONNECT_ME_TO call.
106 */
107 async_answer_0(iid, EOK);
108
109 while (true) {
110 callid = async_get_call(&call);
111
112 if (!IPC_GET_IMETHOD(call)) {
113 /* The other side has hung up. */
114 async_answer_0(callid, EOK);
115 return;
116 }
117
118 switch (IPC_GET_IMETHOD(call)) {
119 case IRC_ENABLE_INTERRUPT:
120 async_answer_0(callid, pic_enable_irq(IPC_GET_ARG1(call)));
121 break;
122 case IRC_CLEAR_INTERRUPT:
123 /* Noop */
124 async_answer_0(callid, EOK);
125 break;
126 default:
127 async_answer_0(callid, EINVAL);
128 break;
129 }
130 }
131}
132
133/** Initialize the i8259 driver.
134 *
135 */
136static bool i8259_init(void)
137{
138 sysarg_t i8259;
139
140 if ((sysinfo_get_value("i8259", &i8259) != EOK) || (!i8259)) {
141 printf("%s: No i8259 found\n", NAME);
142 return false;
143 }
144
145 if ((pio_enable((void *) IO_RANGE0_START, IO_RANGE0_SIZE,
146 (void **) &io_range0) != EOK) ||
147 (pio_enable((void *) IO_RANGE1_START, IO_RANGE1_SIZE,
148 (void **) &io_range1) != EOK)) {
149 printf("%s: i8259 not accessible\n", NAME);
150 return false;
151 }
152
153 async_set_fallback_port_handler(i8259_connection, NULL);
154 service_register(SERVICE_IRC);
155
156 return true;
157}
158
159int main(int argc, char **argv)
160{
161 printf("%s: HelenOS i8259 driver\n", NAME);
162
163 if (!i8259_init())
164 return -1;
165
166 printf("%s: Accepting connections\n", NAME);
167 task_retval(0);
168 async_manager();
169
170 /* Never reached */
171 return 0;
172}
173
174/**
175 * @}
176 */
Note: See TracBrowser for help on using the repository browser.