summaryrefslogtreecommitdiffstats
path: root/qemu/roms/SLOF/board-js2x/rtas/rtas_pci.c
blob: 55dbf53364ead0a03abb98b0f3a6ea41772a1200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/******************************************************************************
 * Copyright (c) 2004, 2008 IBM Corporation
 * All rights reserved.
 * This program and the accompanying materials
 * are made available under the terms of the BSD License
 * which accompanies this distribution, and is available at
 * http://www.opensource.org/licenses/bsd-license.php
 *
 * Contributors:
 *     IBM Corporation - initial implementation
 *****************************************************************************/
#include <stdint.h>
#include <rtas.h>
#include <hw.h>
#include "rtas_board.h"

void
rtas_ibm_read_pci_config (rtas_args_t *rtas_args)
{
	int retVal = 0;
	uint64_t addr = ((uint64_t) rtas_args->args[1]) << 32;  // high 32 bits of PHB UID
	addr |= (rtas_args->args[2] & 0xFFFFFFFF); // low 32 bits of PHB UID
	addr |= (rtas_args->args[0] & 0x00FFFFFF); // bus, devfn, offset
	unsigned int size = rtas_args->args[3];

	/* Check for bus != 0  on PCI/PCI-X (PHB UID = 0xf2000000) */
	if (((addr & 0xf2000000) == 0xf2000000) && (addr & 0xff0000))
		addr += 0x1000000;

	if (size == 1)
		rtas_args->args[5] = load8_ci(addr);
	else if (size == 2)
		rtas_args->args[5] = bswap16_load(addr);
	else if (size == 4)
		rtas_args->args[5] = bswap32_load(addr);
	else
		retVal = -3;  /* Bad arguments */

	rtas_args->args[4] = retVal;
}

void
rtas_ibm_write_pci_config (rtas_args_t *rtas_args)
{
	int retVal = 0;
	uint64_t addr = ((uint64_t) rtas_args->args[1]) << 32;  // high 32 bits of PHB UID
	addr |= (rtas_args->args[2] & 0xFFFFFFFF); // low 32 bits of PHB UID
	addr |= (rtas_args->args[0] & 0x00FFFFFF); // bus, devfn, offset
	unsigned int size = rtas_args->args[3];

	addr |= 0xf2000000;

	/* Check for bus != 0  on PCI/PCI-X (PHB UID = 0xf2000000) */
	if (((addr & 0xf2000000) == 0xf2000000) && (addr & 0xff0000))
		addr += 0x1000000;

	if (size == 1)
		store8_ci(addr, rtas_args->args[4]);
	else if (size == 2)
		bswap16_store(addr, rtas_args->args[4]);
	else if (size == 4)
		bswap32_store(addr, rtas_args->args[4]);
	else
		retVal = -3;  /* Bad arguments */

	rtas_args->args[5] = retVal;
}

void
rtas_read_pci_config (rtas_args_t *rtas_args)
{
	int retVal = 0;
	unsigned long addr = rtas_args->args[0];
	unsigned int size = rtas_args->args[1];
	addr |= 0xf2000000;

	/* Check for bus != 0 */
	if (addr & 0xff0000)
		addr += 0x1000000;

	if (size == 1)
		rtas_args->args[3] = load8_ci(addr);
	else if (size == 2)
		rtas_args->args[3] = bswap16_load(addr);
	else if (size == 4)
		rtas_args->args[3] = bswap32_load(addr);
	else
		retVal = -3;  /* Bad arguments */

	rtas_args->args[2] = retVal;
}

void
rtas_write_pci_config (rtas_args_t *rtas_args)
{
	int retVal = 0;
	unsigned long addr = rtas_args->args[0];
	unsigned int size = rtas_args->args[1];

	addr |= 0xf2000000;

	/* Check for bus != 0 */
	if (addr & 0xff0000)
		addr += 0x1000000;

	if (size == 1)
		store8_ci(addr, rtas_args->args[2]);
	else if (size == 2)
		bswap16_store(addr, rtas_args->args[2]);
	else if (size == 4)
		bswap32_store(addr, rtas_args->args[2]);
	else
		retVal = -3;  /* Bad arguments */

	rtas_args->args[3] = retVal;
}