source: mainline/uspace/drv/intctl/obio/obio.c@ f834dd81

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f834dd81 was 2b11c3c, checked in by Jiri Svoboda <jiri@…>, 8 years ago

OBIO should not store base address in a global variable.

  • Property mode set to 100644
File size: 4.5 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
[be1b1e68]44#include <align.h>
[42742c5a]45#include <as.h>
[be1b1e68]46#include <async.h>
47#include <ddf/driver.h>
48#include <ddf/log.h>
[42742c5a]49#include <ddi.h>
[be1b1e68]50#include <errno.h>
[4c363fa2]51#include <inttypes.h>
[be1b1e68]52#include <ipc/irc.h>
[3e6a98c5]53#include <stdbool.h>
[42742c5a]54#include <stdio.h>
55
[be1b1e68]56#include "obio.h"
57
[42742c5a]58#define NAME "obio"
59
[9a2eb14]60#define OBIO_SIZE 0x1898
[42742c5a]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
70/** Handle one connection to obio.
71 *
72 * @param iid Hash of the request that opened the connection.
73 * @param icall Call data of the request that opened the connection.
[9934f7d]74 * @param arg Local argument.
[42742c5a]75 */
[9934f7d]76static void obio_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
[42742c5a]77{
78 ipc_callid_t callid;
79 ipc_call_t call;
[2b11c3c]80 obio_t *obio;
[42742c5a]81
82 /*
83 * Answer the first IPC_M_CONNECT_ME_TO call.
84 */
[ffa2c8ef]85 async_answer_0(iid, EOK);
[42742c5a]86
[2b11c3c]87 obio = (obio_t *)ddf_dev_data_get(ddf_fun_get_dev((ddf_fun_t *)arg));
88
[42742c5a]89 while (1) {
90 int inr;
[be1b1e68]91
[42742c5a]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);
[2b11c3c]96 ((volatile uint64_t *)(obio->regs))[OBIO_IMR(inr & INO_MASK)] |= (1UL << 31);
[ffa2c8ef]97 async_answer_0(callid, EOK);
[acc7ce4]98 break;
[07cb0108]99 case IRC_DISABLE_INTERRUPT:
100 /* XXX TODO */
101 async_answer_0(callid, EOK);
102 break;
[acc7ce4]103 case IRC_CLEAR_INTERRUPT:
[42742c5a]104 inr = IPC_GET_ARG1(call);
[2b11c3c]105 ((volatile uint64_t *)(obio->regs))[OBIO_CIR(inr & INO_MASK)] = 0;
[ffa2c8ef]106 async_answer_0(callid, EOK);
[42742c5a]107 break;
108 default:
[ffa2c8ef]109 async_answer_0(callid, EINVAL);
[42742c5a]110 break;
111 }
112 }
113}
114
[be1b1e68]115/** Add OBIO device. */
116int obio_add(obio_t *obio, obio_res_t *res)
[42742c5a]117{
[be1b1e68]118 ddf_fun_t *fun_a = NULL;
[2b11c3c]119 int flags;
120 int retval;
[9a2eb14]121 int rc;
[be1b1e68]122
[2b11c3c]123 flags = AS_AREA_READ | AS_AREA_WRITE;
124 obio->regs = (volatile uint64_t *)AS_AREA_ANY;
125 retval = physmem_map(res->base,
[58f6229]126 ALIGN_UP(OBIO_SIZE, PAGE_SIZE) >> PAGE_WIDTH, flags,
[2b11c3c]127 (void *) &obio->regs);
[be1b1e68]128
[42742c5a]129 if (retval < 0) {
[be1b1e68]130 ddf_msg(LVL_ERROR, "Error mapping OBIO registers");
131 rc = EIO;
132 goto error;
[9a2eb14]133 }
[be1b1e68]134
[2b11c3c]135 ddf_msg(LVL_NOTE, "OBIO registers with base at 0x%" PRIun, res->base);
[be1b1e68]136
137 fun_a = ddf_fun_create(obio->dev, fun_exposed, "a");
138 if (fun_a == NULL) {
139 ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
140 rc = ENOMEM;
141 goto error;
[9a2eb14]142 }
[be1b1e68]143
144 ddf_fun_set_conn_handler(fun_a, obio_connection);
145
146 rc = ddf_fun_bind(fun_a);
[9a2eb14]147 if (rc != EOK) {
[be1b1e68]148 ddf_msg(LVL_ERROR, "Failed binding function 'a'. (%d)", rc);
149 goto error;
[9a2eb14]150 }
[be1b1e68]151
152 rc = ddf_fun_add_to_category(fun_a, "irc");
153 if (rc != EOK)
154 goto error;
155
156 return EOK;
157error:
158 if (fun_a != NULL)
159 ddf_fun_destroy(fun_a);
160 return rc;
[42742c5a]161}
162
[be1b1e68]163/** Remove OBIO device */
164int obio_remove(obio_t *obio)
[42742c5a]165{
[be1b1e68]166 return ENOTSUP;
[42742c5a]167}
168
[be1b1e68]169/** OBIO device gone */
170int obio_gone(obio_t *obio)
171{
172 return ENOTSUP;
173}
174
175
[42742c5a]176/**
177 * @}
[79ae36dd]178 */
Note: See TracBrowser for help on using the repository browser.