summaryrefslogtreecommitdiffstats
path: root/arch/ppc/kernel/indirect_pci.c
blob: 641d77a5253d71257c08934d26d91dd85f1efde6 (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
117
118
119
120
121
/*
 * Support for indirect PCI bridges.
 *
 * Copyright (C) 1998 Gabriel Paubert.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */

#include <linux/pci.h>
#include <asm/io.h>
#include <asm/system.h>

unsigned int * pci_config_address;
unsigned char * pci_config_data;

int indirect_pcibios_read_config_byte(unsigned char bus, unsigned char dev_fn,
			     unsigned char offset, unsigned char *val)
{
	unsigned flags;

	save_flags(flags); cli();
	
	out_be32(pci_config_address, 
		 ((offset&0xfc)<<24) | (dev_fn<<16) | (bus<<8) | 0x80);

	*val= in_8(pci_config_data + (offset&3));

	restore_flags(flags);
	return PCIBIOS_SUCCESSFUL;
}

int indirect_pcibios_read_config_word(unsigned char bus, unsigned char dev_fn,
			     unsigned char offset, unsigned short *val)
{
	unsigned flags;
	
	if (offset&1) return PCIBIOS_BAD_REGISTER_NUMBER;

	save_flags(flags); cli();
	
	out_be32(pci_config_address, 
		 ((offset&0xfc)<<24) | (dev_fn<<16) | (bus<<8) | 0x80);

	*val= in_le16((unsigned short *)(pci_config_data + (offset&3)));

	restore_flags(flags);
	return PCIBIOS_SUCCESSFUL;
}

int indirect_pcibios_read_config_dword(unsigned char bus, unsigned char dev_fn,
			     unsigned char offset, unsigned int *val)
{
	unsigned flags;
	
	if (offset&3) return PCIBIOS_BAD_REGISTER_NUMBER;

	save_flags(flags); cli();
	
	out_be32(pci_config_address, 
		 ((offset&0xfc)<<24) | (dev_fn<<16) | (bus<<8) | 0x80);

	*val= in_le32((unsigned *)pci_config_data);

	restore_flags(flags);
	return PCIBIOS_SUCCESSFUL;
}

int indirect_pcibios_write_config_byte(unsigned char bus, unsigned char dev_fn,
			     unsigned char offset, unsigned char val)
{
	unsigned flags;

	save_flags(flags); cli();
	
	out_be32(pci_config_address, 
		 ((offset&0xfc)<<24) | (dev_fn<<16) | (bus<<8) | 0x80);

	out_8(pci_config_data + (offset&3), val);

	restore_flags(flags);
	return PCIBIOS_SUCCESSFUL;
}

int indirect_pcibios_write_config_word(unsigned char bus, unsigned char dev_fn,
			     unsigned char offset, unsigned short val)
{
	unsigned flags;

	if (offset&1) return PCIBIOS_BAD_REGISTER_NUMBER;

	save_flags(flags); cli();
	
	out_be32(pci_config_address, 
		 ((offset&0xfc)<<24) | (dev_fn<<16) | (bus<<8) | 0x80);

	out_le16((unsigned short *)(pci_config_data + (offset&3)), val);

	restore_flags(flags);
	return PCIBIOS_SUCCESSFUL;
}

int indirect_pcibios_write_config_dword(unsigned char bus, unsigned char dev_fn,
			     unsigned char offset, unsigned int val)
{
	unsigned flags;

	if (offset&3) return PCIBIOS_BAD_REGISTER_NUMBER;

	save_flags(flags); cli();
	
	out_be32(pci_config_address, 
		 ((offset&0xfc)<<24) | (dev_fn<<16) | (bus<<8) | 0x80);

	out_le32((unsigned *)pci_config_data, val);

	restore_flags(flags);
	return PCIBIOS_SUCCESSFUL;
}