|
|
1.1 root 1: /******************************************************************************
2: * Copyright (c) 2004, 2008 IBM Corporation
3: * All rights reserved.
4: * This program and the accompanying materials
5: * are made available under the terms of the BSD License
6: * which accompanies this distribution, and is available at
7: * http://www.opensource.org/licenses/bsd-license.php
8: *
9: * Contributors:
10: * IBM Corporation - initial implementation
11: *****************************************************************************/
12:
1.1.1.2 ! root 13: #include <stdint.h>
1.1 root 14: #include <rtas.h>
15: #include <of.h>
16: #include <pci.h>
17: #include <string.h>
18: #include <kernel.h>
19: #include <cpu.h>
20: #include <cache.h>
21:
22: int
23: pci_calc_bar_size(long long puid, int bus, int devfn, int bar)
24: {
25: int size;
26: int old;
27: bar = bar * 4 + 0x10;
28: old = rtas_pci_config_read(puid, 4, bus, devfn, bar);
29: rtas_pci_config_write(puid, 4, bus, devfn, bar, 0xffffffff);
30: size = (rtas_pci_config_read(puid, 4, bus, devfn, bar) & (-4)) * -1;
31: rtas_pci_config_write(puid, 4, bus, devfn, bar, old);
32: return size;
33: }
34:
35: int
36: pci_get_bar_start(long long puid, int bus, int devfn, int bar)
37: {
38: return rtas_pci_config_read(puid, 4, bus, devfn, bar * 4 + 0x10);
39: }
40:
41: void
42: pci_set_bar_start(long long puid, int bus, int devfn, int bar, int value)
43: {
44: rtas_pci_config_write(puid, 4, bus, devfn, bar * 4 + 0x10, value);
45: }
46:
47: unsigned int
48: read_io(void *addr, size_t sz)
49: {
50: unsigned int ret;
51:
52: switch (sz) {
53: case 1:
54: ret = ci_read_8(addr);
55: break;
56: case 2:
57: ret = ci_read_16(addr);
58: break;
59: case 4:
60: ret = ci_read_32(addr);
61: break;
62: default:
63: ret = 0;
64: }
65:
66: return ret;
67: }
68:
69: int
70: write_io(void *addr, unsigned int value, size_t sz)
71: {
72: switch (sz) {
73: case 1:
74: ci_write_8(addr, value);
75: break;
76: case 2:
77: ci_write_16(addr, value);
78: break;
79: case 4:
80: ci_write_32(addr, value);
81: break;
82: default:
83: return -1;
84: }
85:
86: return 0;
87: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.