source: mainline/uspace/srv/hw/irc/obio/obio.c@ 8d2dd7f2

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

OBIO uspace driver no longer depends on information provided by kernel

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[42742c5a]1/*
2 * Copyright (c) 2009 Jakub Jermar
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
[ffa2c8ef]29/** @addtogroup obio
[42742c5a]30 * @{
[ffa2c8ef]31 */
[42742c5a]32
33/**
[ffa2c8ef]34 * @file obio.c
35 * @brief OBIO driver.
[42742c5a]36 *
37 * OBIO is a short for on-board I/O. On UltraSPARC IIi and systems with U2P,
38 * there is a piece of the root PCI bus controller address space, which
39 * contains interrupt mapping and clear registers for all on-board devices.
40 * Although UltraSPARC IIi and U2P are different in general, these registers can
41 * be found at the same addresses.
42 */
43
44#include <ipc/services.h>
[acc7ce4]45#include <ipc/irc.h>
[79ae36dd]46#include <ns.h>
[42742c5a]47#include <as.h>
48#include <ddi.h>
49#include <align.h>
[3e6a98c5]50#include <stdbool.h>
[42742c5a]51#include <errno.h>
52#include <async.h>
53#include <align.h>
54#include <async.h>
55#include <stdio.h>
[15f3c3f]56#include <ipc/loc.h>
[42742c5a]57
58#define NAME "obio"
59
60#define OBIO_SIZE 0x1898
61
62#define OBIO_IMR_BASE 0x200
63#define OBIO_IMR(ino) (OBIO_IMR_BASE + ((ino) & INO_MASK))
64
65#define OBIO_CIR_BASE 0x300
66#define OBIO_CIR(ino) (OBIO_CIR_BASE + ((ino) & INO_MASK))
67
68#define INO_MASK 0x1f
69
[8442d10]70static uintptr_t base_phys;
[bf9cb2f]71static volatile uint64_t *base_virt = (volatile uint64_t *) AS_AREA_ANY;
[42742c5a]72
73/** Handle one connection to obio.
74 *
75 * @param iid Hash of the request that opened the connection.
76 * @param icall Call data of the request that opened the connection.
[9934f7d]77 * @param arg Local argument.
[42742c5a]78 */
[9934f7d]79static void obio_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
[42742c5a]80{
81 ipc_callid_t callid;
82 ipc_call_t call;
83
84 /*
85 * Answer the first IPC_M_CONNECT_ME_TO call.
86 */
[ffa2c8ef]87 async_answer_0(iid, EOK);
[42742c5a]88
89 while (1) {
90 int inr;
91
92 callid = async_get_call(&call);
[228e490]93 switch (IPC_GET_IMETHOD(call)) {
[acc7ce4]94 case IRC_ENABLE_INTERRUPT:
[6da5a6b]95 inr = IPC_GET_ARG1(call);
96 base_virt[OBIO_IMR(inr & INO_MASK)] |= (1UL << 31);
[ffa2c8ef]97 async_answer_0(callid, EOK);
[acc7ce4]98 break;
99 case IRC_CLEAR_INTERRUPT:
[42742c5a]100 inr = IPC_GET_ARG1(call);
[f3f7009]101 base_virt[OBIO_CIR(inr & INO_MASK)] = 0;
[ffa2c8ef]102 async_answer_0(callid, EOK);
[42742c5a]103 break;
104 default:
[ffa2c8ef]105 async_answer_0(callid, EINVAL);
[42742c5a]106 break;
107 }
108 }
109}
110
111/** Initialize the OBIO driver.
112 *
[df01d303]113 * In the future, the OBIO driver should be integrated with the sun4u platform driver.
[42742c5a]114 */
115static bool obio_init(void)
116{
[6da5a6b]117 base_phys = (uintptr_t) 0x1fe00000000ULL;
[42742c5a]118
119 int flags = AS_AREA_READ | AS_AREA_WRITE;
[fbcdeb8]120 int retval = physmem_map(base_phys,
[58f6229]121 ALIGN_UP(OBIO_SIZE, PAGE_SIZE) >> PAGE_WIDTH, flags,
122 (void *) &base_virt);
[42742c5a]123
124 if (retval < 0) {
[79ae36dd]125 printf("%s: Error mapping OBIO registers\n", NAME);
[42742c5a]126 return false;
127 }
128
[6da5a6b]129 printf("%s: OBIO registers with base at %lx\n", NAME, base_phys);
[d9fae235]130
[b688fd8]131 async_set_fallback_port_handler(obio_connection, NULL);
[57d129e]132 service_register(SERVICE_IRC);
[42742c5a]133
134 return true;
135}
136
137int main(int argc, char **argv)
138{
[79ae36dd]139 printf("%s: HelenOS OBIO driver\n", NAME);
[42742c5a]140
141 if (!obio_init())
142 return -1;
143
[79ae36dd]144 printf("%s: Accepting connections\n", NAME);
145 task_retval(0);
[42742c5a]146 async_manager();
[79ae36dd]147
[42742c5a]148 /* Never reached */
149 return 0;
150}
151
152/**
153 * @}
[79ae36dd]154 */
Note: See TracBrowser for help on using the repository browser.