source: mainline/uspace/drv/char/i8042/main.c@ 7259317

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

Do not create a new fibril for each IRQ notification

In the absence of fibril serialization, manager fibrils can
theoretically block in async IPC or on fibril synchronization
primitives. Consequently, it is safe to execute the IRQ handler directly
from the manager fibril. The manager fibril can block while processing
the notification, but most of the times it will not block and the
handler will execute atomically.

This changeset modifies the current behaviour so that we no longer spawn
a new notification fibril for each IRQ, but rather execute the handler
directly from the manager fibril and test if the execution blocked. If
it blocked, the manager fibril had assumed the role of a notification
fibril and we destroy it afterwards - merely to avoid fibril population
explosion. Otherwise, which is the usual behavior, we keep it so that
it resumes its job of a manager fibril.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * Copyright (c) 2011 Jan Vesely
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 drvi8042
30 * @{
31 */
32
33/** @file
34 * @brief i8042 driver DDF bits.
35 */
36
37#include <libarch/inttypes.h>
38#include <libarch/config.h>
39#include <ddf/driver.h>
40#include <device/hw_res_parsed.h>
41#include <errno.h>
42#include <str_error.h>
43#include <ddf/log.h>
44#include <stdio.h>
45#include "i8042.h"
46
47/** Get address of I/O registers.
48 *
49 * @param[in] dev Device asking for the addresses.
50 * @param[out] p_io_reg Pointer to register range.
51 * @param[out] kbd_irq Primary port IRQ.
52 * @param[out] mouse_irq Auxiliary port IRQ.
53 *
54 * @return Error code.
55 *
56 */
57static int get_my_registers(ddf_dev_t *dev, addr_range_t *p_io_reg,
58 int *kbd_irq, int *mouse_irq)
59{
60 assert(dev);
61
62 async_sess_t *parent_sess = ddf_dev_parent_sess_create(dev);
63 if (parent_sess == NULL)
64 return ENOMEM;
65
66 hw_res_list_parsed_t hw_resources;
67 hw_res_list_parsed_init(&hw_resources);
68 const int ret = hw_res_get_list_parsed(parent_sess, &hw_resources, 0);
69 if (ret != EOK)
70 return ret;
71
72 if ((hw_resources.irqs.count != 2) ||
73 (hw_resources.io_ranges.count != 1)) {
74 hw_res_list_parsed_clean(&hw_resources);
75 return EINVAL;
76 }
77
78 if (p_io_reg)
79 *p_io_reg = hw_resources.io_ranges.ranges[0];
80
81 if (kbd_irq)
82 *kbd_irq = hw_resources.irqs.irqs[0];
83
84 if (mouse_irq)
85 *mouse_irq = hw_resources.irqs.irqs[1];
86
87 hw_res_list_parsed_clean(&hw_resources);
88 return EOK;
89}
90
91/** Initialize a new ddf driver instance of i8042 driver
92 *
93 * @param[in] device DDF instance of the device to initialize.
94 *
95 * @return Error code.
96 *
97 */
98static int i8042_dev_add(ddf_dev_t *device)
99{
100 addr_range_t io_regs;
101 int kbd = 0;
102 int mouse = 0;
103 int rc;
104
105 if (!device)
106 return EINVAL;
107
108 rc = get_my_registers(device, &io_regs, &kbd, &mouse);
109 if (rc != EOK) {
110 ddf_msg(LVL_ERROR, "Failed to get registers: %s.",
111 str_error(rc));
112 return rc;
113 }
114
115 ddf_msg(LVL_DEBUG,
116 "I/O regs at %p (size %zuB), IRQ kbd %d, IRQ mouse %d.",
117 RNGABSPTR(io_regs), RNGSZ(io_regs), kbd, mouse);
118
119 i8042_t *i8042 = ddf_dev_data_alloc(device, sizeof(i8042_t));
120 if (i8042 == NULL) {
121 ddf_msg(LVL_ERROR, "Out of memory.");
122 return ENOMEM;
123 }
124
125 rc = i8042_init(i8042, &io_regs, kbd, mouse, device);
126 if (rc != EOK) {
127 ddf_msg(LVL_ERROR, "Failed to initialize i8042 driver: %s.",
128 str_error(rc));
129 return rc;
130 }
131
132 ddf_msg(LVL_NOTE, "Controlling '%s' (%" PRIun ").",
133 ddf_dev_get_name(device), ddf_dev_get_handle(device));
134 return EOK;
135}
136
137/** DDF driver operations. */
138static driver_ops_t i8042_driver_ops = {
139 .dev_add = i8042_dev_add,
140};
141
142/** DDF driver. */
143static driver_t i8042_driver = {
144 .name = NAME,
145 .driver_ops = &i8042_driver_ops
146};
147
148int main(int argc, char *argv[])
149{
150 printf("%s: HelenOS PS/2 driver.\n", NAME);
151 ddf_log_init(NAME);
152
153 return ddf_driver_main(&i8042_driver);
154}
155
156/**
157 * @}
158 */
Note: See TracBrowser for help on using the repository browser.