source: mainline/uspace/drv/intctl/obio/obio.c@ 7c0e1f5

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

Use proper PRI* macro to print OBIO base in hex

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