source: mainline/uspace/drv/ohci/pci.c@ e7bc999

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e7bc999 was e7bc999, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

Add interrupt support

Fix register structure
Interrupts disabled as there is no way to access mm registers in the handler

  • Property mode set to 100644
File size: 4.7 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 drvusbohci
30 * @{
31 */
32/**
33 * @file
34 * PCI related functions needed by the OHCI driver.
35 */
36#include <errno.h>
37#include <assert.h>
38#include <as.h>
39#include <devman.h>
40#include <ddi.h>
41#include <libarch/ddi.h>
42#include <device/hw_res.h>
43
44#include <usb/debug.h>
45#include <pci_dev_iface.h>
46
47#include "pci.h"
48
49#define PAGE_SIZE_MASK 0xfffff000
50
51#define HCC_PARAMS_OFFSET 0x8
52#define HCC_PARAMS_EECP_MASK 0xff
53#define HCC_PARAMS_EECP_OFFSET 8
54
55#define CMD_OFFSET 0x0
56#define CONFIGFLAG_OFFSET 0x40
57
58#define USBCMD_RUN 1
59
60#define USBLEGSUP_OFFSET 0
61#define USBLEGSUP_BIOS_CONTROL (1 << 16)
62#define USBLEGSUP_OS_CONTROL (1 << 24)
63#define USBLEGCTLSTS_OFFSET 4
64
65#define DEFAULT_WAIT 10000
66#define WAIT_STEP 10
67
68/** Get address of registers and IRQ for given device.
69 *
70 * @param[in] dev Device asking for the addresses.
71 * @param[out] mem_reg_address Base address of the memory range.
72 * @param[out] mem_reg_size Size of the memory range.
73 * @param[out] irq_no IRQ assigned to the device.
74 * @return Error code.
75 */
76int pci_get_my_registers(ddf_dev_t *dev,
77 uintptr_t *mem_reg_address, size_t *mem_reg_size, int *irq_no)
78{
79 assert(dev != NULL);
80
81 int parent_phone = devman_parent_device_connect(dev->handle,
82 IPC_FLAG_BLOCKING);
83 if (parent_phone < 0) {
84 return parent_phone;
85 }
86
87 int rc;
88
89 hw_resource_list_t hw_resources;
90 rc = hw_res_get_resource_list(parent_phone, &hw_resources);
91 if (rc != EOK) {
92 async_hangup(parent_phone);
93 return rc;
94 }
95
96 uintptr_t mem_address = 0;
97 size_t mem_size = 0;
98 bool mem_found = false;
99
100 int irq = 0;
101 bool irq_found = false;
102
103 size_t i;
104 for (i = 0; i < hw_resources.count; i++) {
105 hw_resource_t *res = &hw_resources.resources[i];
106 switch (res->type)
107 {
108 case INTERRUPT:
109 irq = res->res.interrupt.irq;
110 irq_found = true;
111 usb_log_debug2("Found interrupt: %d.\n", irq);
112 break;
113
114 case MEM_RANGE:
115 if (res->res.mem_range.address != 0
116 && res->res.mem_range.size != 0 ) {
117 mem_address = res->res.mem_range.address;
118 mem_size = res->res.mem_range.size;
119 usb_log_debug2("Found mem: %llx %zu.\n",
120 mem_address, mem_size);
121 mem_found = true;
122 }
123 default:
124 break;
125 }
126 }
127
128 if (mem_found && irq_found) {
129 *mem_reg_address = mem_address;
130 *mem_reg_size = mem_size;
131 *irq_no = irq;
132 rc = EOK;
133 } else {
134 rc = ENOENT;
135 }
136
137 async_hangup(parent_phone);
138 return rc;
139}
140/*----------------------------------------------------------------------------*/
141/** Calls the PCI driver with a request to enable interrupts
142 *
143 * @param[in] device Device asking for interrupts
144 * @return Error code.
145 */
146int pci_enable_interrupts(ddf_dev_t *device)
147{
148 return ENOTSUP;
149 int parent_phone =
150 devman_parent_device_connect(device->handle, IPC_FLAG_BLOCKING);
151 if (parent_phone < 0) {
152 return parent_phone;
153 }
154 bool enabled = hw_res_enable_interrupt(parent_phone);
155 async_hangup(parent_phone);
156 return enabled ? EOK : EIO;
157}
158/*----------------------------------------------------------------------------*/
159/** Implements BIOS handoff routine as decribed in OHCI spec
160 *
161 * @param[in] device Device asking for interrupts
162 * @return Error code.
163 */
164int pci_disable_legacy(ddf_dev_t *device)
165{
166 /* TODO: implement */
167 return EOK;
168}
169/*----------------------------------------------------------------------------*/
170/**
171 * @}
172 */
173
174/**
175 * @}
176 */
Note: See TracBrowser for help on using the repository browser.