Subversion Repositories f9daq

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
86 f9daq 1
//****************************************************************************
2
// Copyright (C) 2000-2006  ARW Elektronik Germany
3
//
4
//
5
// This program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 2 of the License, or
8
// (at your option) any later version.
9
//
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
//
19
// This product is not authorized for use as critical component in 
20
// life support systems without the express written approval of 
21
// ARW Elektronik Germany.
22
//  
23
// Please announce changes and hints to ARW Elektronik
24
//
25
// Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de)
26
//
27
//****************************************************************************
28
 
29
//****************************************************************************
30
//
31
// askpci.c - a hardware independent tool to get 
32
//           information about searched pci-hardware
33
//
34
// $Log: askpci.c,v $
35
// Revision 1.11  2006/06/04 12:26:07  klaus
36
// release_20060604; Version 6.9; pci_{en|dis}able_device() added; remap_page_range reorganized
37
//
38
// Revision 1.10  2005/10/07 16:57:10  klaus
39
// fixed a bug with request_irq with IRQs greater than 127
40
//
41
// Revision 1.9  2004/08/12 19:59:19  klaus
42
// conversion to kernel-version 2.6, released version 6.0
43
//
44
// Revision 1.8  2003/06/19 08:23:38  klaus
45
// re-compiled with RH-7.2 (kernel 2.4.10)
46
//
47
// Revision 1.7  2003/05/11 11:12:03  klaus
48
// matched to kernel 2.4 PCI handling, debug messages improved
49
//
50
// Revision 1.5  2003/05/05 18:15:55  klaus
51
// added some debug code and reject if no CONFIG_PCI found, Version 4.7
52
//
53
// Revision 1.4  2001/11/20 20:12:50  klaus
54
// included new header and CVS log
55
//
56
//
57
// derived from code originated from Dirk Muehlenberg               AR   18.02.2000
58
// MODVERSIONS included                                             AR   24.04.2000
59
//
60
//****************************************************************************
61
 
62
 
63
/*
64
 
65
   (c) 2000 ARW Elektronik
66
 
67
   this source code is published under GPL (Open Source). You can use, redistribute and
68
   modify it unless this header   is not modified or deleted. No warranty is given that
69
   this software will work like expected.
70
 
71
*/
72
 
73
#include "common.h"  /* must be the first include */
74
 
75
#include <linux/pci.h>
76
#include <asm/types.h>
77
#include "list.h"
78
#include "askpci.h"
79
 
80
 
81
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
82
#define pci_enable_device(x) 0
83
#endif
84
 
85
 
86
/* fills the configration header */
87
 
88
// init the first time, anchor for next device search
89
static struct pci_dev *from = NULL;
90
 
91
PCIConfigHeader *GetPCIConfigHeader ( __u16 vendor_id, __u16 device_id, short index)
92
{
93
  PCIConfigHeader *pci_ch = (PCIConfigHeader *)NULL;
94
 
95
#ifdef CONFIG_PCI
96
 
97
  int i;
98
 
99
  DPRINTK(KERN_DEBUG "pcicc32 : GetPCIConfigHeader (%d)\n", index);
100
 
101
  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
102
        if (!CONFIG_PCI)
103
        #else
104
  if (!pci_present())
105
        #endif
106
  {
107
    printk(KERN_ERR "pcicc32 : GetPCIConfigHeader(): no pcibios present!\n");
108
    return (PCIConfigHeader *)NULL;
109
  }
110
 
111
  pci_ch = (PCIConfigHeader *)kmalloc(sizeof(PCIConfigHeader), GFP_ATOMIC);
112
  if (!pci_ch) return (PCIConfigHeader *)NULL;
113
 
114
  pci_ch->vendor_id = vendor_id;
115
  pci_ch->device_id = device_id;
116
  pci_ch->index     = index;
117
 
118
  pci_ch->PCI_dev = pci_get_device(pci_ch->vendor_id, pci_ch->device_id, from);
119
        if ((pci_ch->PCI_dev == NULL) || (pci_enable_device(pci_ch->PCI_dev)))
120
        {
121
                kfree_s(pci_ch, sizeof(*pci_ch)); // FREE(pci_ch);
122
                from = NULL;
123
                return (PCIConfigHeader *)NULL;
124
        }
125
 
126
  for (i=0;i<6;i++)
127
  {
128
                pci_ch->desc[i].base_address = pci_ch->PCI_dev->resource[i].start;
129
                pci_ch->desc[i].size         = pci_ch->PCI_dev->resource[i].end - pci_ch->PCI_dev->resource[i].start;
130
                if (pci_ch->desc[i].size)
131
                        pci_ch->desc[i].size += 1;
132
 
133
    if (pci_ch->PCI_dev->resource[i].flags & IORESOURCE_IO) /* io space */
134
    {
135
                        pci_ch->desc[i].type         = PCI_BASE_ADDRESS_SPACE_IO;
136
                        pci_ch->desc[i].prefetchable = 0;
137
    }
138
    else
139
    {
140
                        pci_ch->desc[i].type         = 0;      
141
                        pci_ch->desc[i].prefetchable = (pci_ch->PCI_dev->resource[i].flags & IORESOURCE_PREFETCH) ? 1 : 0;
142
    }  
143
 
144
                DPRINTK(KERN_DEBUG "pcicc32 : address=0x%08x, size=0x%08x, type=%s, prefetch=%s\n",
145
                           pci_ch->desc[i].base_address, pci_ch->desc[i].size,
146
                              (pci_ch->desc[i].type) ? "io " : "mem",
147
                                  (pci_ch->desc[i].prefetchable) ? "yes" : "no ");                       
148
 }
149
 
150
  /* --- now complete PCIConfigHeader for compatibility --- */
151
        pci_ch->subsystem_id         = pci_ch->PCI_dev->subsystem_device;
152
        pci_ch->subsystem_vendor_id  = pci_ch->PCI_dev->subsystem_vendor;
153
        DPRINTK(KERN_DEBUG "pcicc32 : irq=%d, sub-dev-ID=0x%04x, sub-ven-ID=0x%04x\n", pci_ch->PCI_dev->irq, pci_ch->subsystem_id, pci_ch->subsystem_vendor_id);
154
 
155
        /* --- next starting point ---*/
156
        from = pci_ch->PCI_dev;
157
 
158
#else
159
#error "No PCI support, please investigate CONFIG_PCI"
160
#endif  
161
 
162
  return pci_ch;
163
}
164
 
165
/* ------------------------------------------------------------------------- */
166
/* ------------------------------------------------------------------------- */
167