source: mainline/uspace/srv/drivers/pciintel/pci.c@ 8c06905

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8c06905 was 8c06905, checked in by Lenka Trochtova <trochtova.lenka@…>, 15 years ago

parts of pci driver

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Copyright (c) 2010 Lenka Trochtova
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/**
30 * @defgroup pciintel pci bus driver for intel method 1.
31 * @brief HelenOS root pci bus driver for intel method 1.
32 * @{
33 */
34
35/** @file
36 */
37
38#include <assert.h>
39#include <stdio.h>
40#include <errno.h>
41#include <bool.h>
42#include <fibril_synch.h>
43#include <stdlib.h>
44#include <string.h>
45#include <ctype.h>
46#include <macros.h>
47
48#include <driver.h>
49#include <devman.h>
50#include <ipc/devman.h>
51#include <ipc/dev_iface.h>
52#include <resource.h>
53#include <device/hw_res.h>
54#include <ddi.h>
55
56#define NAME "pciintel"
57
58static bool pci_add_device(device_t *dev);
59
60/** The pci bus driver's standard operations.
61 */
62static driver_ops_t pci_ops = {
63 .add_device = &pci_add_device
64};
65
66/** The pci bus driver structure.
67 */
68static driver_t pci_driver = {
69 .name = NAME,
70 .driver_ops = &pci_ops
71};
72
73typedef struct pciintel_bus_data {
74 void *conf_io_addr;
75 void *conf_data_port;
76 void *conf_addr_port;
77} pci_bus_data_t;
78
79
80static bool pci_add_device(device_t *dev)
81{
82 printf(NAME ": pci_add_device\n");
83
84 pci_bus_data_t *bus_data = (pci_bus_data_t *)malloc(sizeof(pci_bus_data_t));
85 if (NULL == bus_data) {
86 printf(NAME ": pci_add_device allocation failed.\n");
87 return false;
88 }
89
90 dev->parent_phone = devman_parent_device_connect(dev->handle, IPC_FLAG_BLOCKING);
91 if (dev->parent_phone <= 0) {
92 printf(NAME ": pci_add_device failed to connect to the parent's driver.\n");
93 free(bus_data);
94 return false;
95 }
96
97 hw_resource_list_t hw_resources;
98
99 if (!get_hw_resources(dev->parent_phone, &hw_resources)) {
100 printf(NAME ": pci_add_device failed to get hw resources for the device.\n");
101 free(bus_data);
102 ipc_hangup(dev->parent_phone);
103 return false;
104 }
105
106
107 printf(NAME ": conf_addr = %x.\n", hw_resources.resources[0].res.reg.address);
108
109 assert(hw_resources.count > 0);
110 assert(hw_resources.resources[0].type == REGISTER);
111 assert(hw_resources.resources[0].res.reg.size == 8);
112
113 bus_data->conf_io_addr = hw_resources.resources[0].res.reg.address;
114
115 if (pio_enable(bus_data->conf_io_addr, 8, &bus_data->conf_addr_port)) {
116 printf(NAME ": failed to enable configuration ports.\n");
117 free(bus_data);
118 ipc_hangup(dev->parent_phone);
119 clean_hw_resource_list(&hw_resources);
120 return false;
121 }
122 bus_data->conf_data_port = (char *)bus_data->conf_addr_port + 4;
123
124 dev->driver_data = bus_data;
125
126 // TODO scan the bus
127
128 clean_hw_resource_list(&hw_resources);
129
130 return true;
131}
132
133int main(int argc, char *argv[])
134{
135 printf(NAME ": HelenOS pci bus driver (intel method 1).\n");
136 return driver_main(&pci_driver);
137}
138
139/**
140 * @}
141 */
Note: See TracBrowser for help on using the repository browser.