Subversion Repositories shark

Rev

Rev 592 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
587 giacomo 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Mauro Marinoni <mauro.marinoni@unipv.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/*
20
 * This program is free software; you can redistribute it and/or modify
21
 * it under the terms of the GNU General Public License as published by
22
 * the Free Software Foundation; either version 2 of the License, or
23
 * (at your option) any later version.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU General Public License
31
 * along with this program; if not, write to the Free Software
32
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33
 */
34
 
35
#include <linuxcomp.h>
36
#include <linux/pci.h>
37
 
38
//#define __DEBUG_20TO26__
39
 
40
void linuxpci_init(void)
41
{
42
                        // PCI26_init MUST be called first ( TODO - Check )
43
}
44
 
45
int pci20to26_find_class(unsigned int class_code, int index, BYTE *bus, BYTE *dev)
46
{
47
        struct pci_dev *ptmp = NULL;
48
        int curr = 0;
49
 
50
        ptmp = pci_find_class(class_code, ptmp);
51
        while (ptmp) {
52
#ifdef __DEBUG_20TO26__
53
                printk(KERN_DEBUG "pci20to26_find_class %x: found at bus %d, dev %d.\n", ptmp->class, ptmp->bus->number, ptmp->devfn);
54
#endif
55
 
56
                if (curr == index) {
57
                        *bus = ptmp->bus->number;
58
                        *dev = ptmp->devfn;
59
 
60
#ifdef __DEBUG_20TO26__
61
                        printk(KERN_DEBUG "pci20to26_find_class: found at bus %d, dev %d\n", *bus, *dev);
62
#endif
63
 
64
                        return PCIBIOS_SUCCESSFUL;
65
                }
66
                ++curr;
67
                ptmp = pci_find_class(class_code, ptmp);
68
        }
69
 
70
        return PCIBIOS_DEVICE_NOT_FOUND;
71
}
72
 
73
int pcibios_present(void)
74
{
75
        return 1;       // PCI26 initialized? ( TODO - Check )
76
}
77
 
78
int pci20to26_read_config_byte(unsigned int bus, unsigned int dev, int where, u8 *val)
79
{
80
        struct pci_dev tmp;
81
        struct pci_dev *ptmp = &tmp;
82
 
83
        ptmp = pci_find_slot(bus, dev);
592 mauro 84
        if (!ptmp)
85
                return 0;
587 giacomo 86
        pci_read_config_byte(ptmp, where, val);
87
 
88
#ifdef __DEBUG_20TO26__
89
        printk(KERN_DEBUG "pci20to26_read_config_byte: (bus %d, dev %d) -> %d\n", bus, dev, *val);
90
#endif
91
 
92
        return 1;
93
}
94
 
95
int pci20to26_read_config_word(unsigned int bus, unsigned int dev, int where, u16  *val)
96
{
97
        struct pci_dev tmp;
98
        struct pci_dev *ptmp = &tmp;
99
 
100
        ptmp = pci_find_slot(bus, dev);
592 mauro 101
        if (!ptmp)
102
                return 0;
587 giacomo 103
        pci_read_config_word(ptmp, where, val);
104
 
105
#ifdef __DEBUG_20TO26__
106
        printk(KERN_DEBUG "pci20to26_read_config_word: (bus %d, dev %d) -> %d\n", bus, dev, *val);
107
#endif
108
 
109
        return 1;
110
}
111
 
112
int pci20to26_read_config_dword(unsigned int bus, unsigned int dev, int where, u32 *val)
113
{
114
        struct pci_dev tmp;
115
        struct pci_dev *ptmp = &tmp;
116
 
117
        ptmp = pci_find_slot(bus, dev);
592 mauro 118
        if (!ptmp)
119
                return 0;
587 giacomo 120
        pci_read_config_dword(ptmp, where, val);
121
 
122
#ifdef __DEBUG_20TO26__
123
        printk(KERN_DEBUG "pci20to26_read_config_dword: (bus %d, dev %d) -> %uld\n", bus, dev, *val);
124
#endif
125
 
126
        return 1;
127
}
128
 
129
int pci20to26_write_config_byte(unsigned int bus, unsigned int dev, int where, u8 val)
130
{
131
        struct pci_dev tmp;
132
        struct pci_dev *ptmp = &tmp;
133
 
134
        ptmp = pci_find_slot(bus, dev);
592 mauro 135
        if (!ptmp)
136
                return 0;
587 giacomo 137
        pci_write_config_byte(ptmp, where, val);
138
 
139
        return 1;
140
}
141
 
142
int pci20to26_write_config_word(unsigned int bus, unsigned int dev, int where, u16 val)
143
{
144
        struct pci_dev tmp;
145
        struct pci_dev *ptmp = &tmp;
146
 
147
        ptmp = pci_find_slot(bus, dev);
592 mauro 148
        if (!ptmp)
149
                return 0;
587 giacomo 150
        pci_write_config_word(ptmp, where, val);
151
 
152
        return 1;
153
}
154
 
155
int pci20to26_write_config_dword(unsigned int bus, unsigned int dev, int where, u32 val)
156
{
157
        struct pci_dev tmp;
158
        struct pci_dev *ptmp = &tmp;
159
 
160
        ptmp = pci_find_slot(bus, dev);
592 mauro 161
        if (!ptmp)
162
                return 0;
587 giacomo 163
        pci_write_config_dword(ptmp, where, val);
164
 
165
        return 1;
166
}