~n-muench/ubuntu/oneiric/open-vm-tools/open-vm-tools.fix-836277

« back to all changes in this revision

Viewing changes to modules/linux/vmxnet3/compat_pci.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-10-23 15:32:00 UTC
  • mfrom: (1.1.2 upstream) (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20081023153200-gc1bfx89hj35c799
Tags: 2008.10.10-123053-2
* Correcting typo in dh_installinit call.
* Downgrading depends on module-assistant to recommends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 1999 VMware, Inc. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License as published by the
 
6
 * Free Software Foundation version 2 and no later version.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
10
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
11
 * for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
15
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
16
 *
 
17
 *********************************************************/
 
18
 
 
19
/*
 
20
 * compat_pci.h: PCI compatibility wrappers.
 
21
 */
 
22
 
 
23
#ifndef __COMPAT_PCI_H__
 
24
#define __COMPAT_PCI_H__
 
25
 
 
26
#include "compat_ioport.h"
 
27
#include <linux/pci.h>
 
28
#ifndef KERNEL_2_1
 
29
#   include <linux/bios32.h>
 
30
#endif
 
31
 
 
32
 
 
33
/* 2.0.x has useless struct pci_dev; remap it to our own */
 
34
#ifndef KERNEL_2_1
 
35
#define pci_dev    vmw_pci_driver_instance
 
36
#endif
 
37
 
 
38
 
 
39
/* 2.0/2.2 does not have pci driver API */
 
40
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
 
41
struct vmw_pci_driver_instance {
 
42
   struct vmw_pci_driver_instance *next;
 
43
   void                   *driver_data;
 
44
   struct pci_driver      *pcidrv;
 
45
#ifdef KERNEL_2_1
 
46
   struct pci_dev         *pcidev;
 
47
#else
 
48
   unsigned char           bus;
 
49
   unsigned char           devfn;
 
50
   unsigned int            irq;
 
51
#endif
 
52
};
 
53
#endif
 
54
 
 
55
 
 
56
/* 2.0 has pcibios_* calls only...  We have to provide pci_* compatible wrappers. */
 
57
#ifndef KERNEL_2_1
 
58
static inline int
 
59
pci_read_config_byte(struct pci_dev *pdev,  // IN: PCI slot
 
60
                     unsigned char   where, // IN: Byte to read
 
61
                     u8             *value) // OUT: Value read
 
62
{
 
63
   return pcibios_read_config_byte(pdev->bus, pdev->devfn, where, value);
 
64
}
 
65
 
 
66
static inline int
 
67
pci_read_config_dword(struct pci_dev *pdev,  // IN: PCI slot
 
68
                      unsigned char   where, // IN: Dword to read
 
69
                      u32            *value) // OUT: Value read
 
70
{
 
71
   return pcibios_read_config_dword(pdev->bus, pdev->devfn, where, value);
 
72
}
 
73
 
 
74
static inline int
 
75
pci_write_config_dword(struct pci_dev *pdev,  // IN: PCI slot
 
76
                       unsigned char   where, // IN: Dword to write
 
77
                       u32             value) // IN: Value to write
 
78
{
 
79
   return pcibios_write_config_dword(pdev->bus, pdev->devfn, where, value);
 
80
}
 
81
#endif
 
82
 
 
83
 
 
84
/*
 
85
 *-----------------------------------------------------------------------------
 
86
 *
 
87
 * compat_pci_name --
 
88
 *
 
89
 *      Return human readable PCI slot name.  Note that some implementations
 
90
 *      return a pointer to the static storage, so returned value may be
 
91
 *      overwritten by subsequent calls to this function.
 
92
 *
 
93
 * Results:
 
94
 *      Returns pointer to the string with slot name.
 
95
 *
 
96
 * Side effects:
 
97
 *      None.
 
98
 *
 
99
 *-----------------------------------------------------------------------------
 
100
 */
 
101
 
 
102
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 22)
 
103
#define compat_pci_name(pdev) pci_name(pdev)
 
104
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0)
 
105
#define compat_pci_name(pdev) (pdev)->slot_name
 
106
#elif defined(KERNEL_2_1)
 
107
static inline const char*
 
108
compat_pci_name(struct pci_dev* pdev)
 
109
{
 
110
   static char slot_name[12];
 
111
   sprintf(slot_name, "%02X:%02X.%X", pdev->bus->number,
 
112
           PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
 
113
   return slot_name;
 
114
}
 
115
#else
 
116
static inline const char*
 
117
compat_pci_name(struct pci_dev* pdev)
 
118
{
 
119
   static char slot_name[12];
 
120
   sprintf(slot_name, "%02X:%02X.%X", pdev->bus,
 
121
           PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
 
122
   return slot_name;
 
123
}
 
124
#endif
 
125
 
 
126
 
 
127
/* pci_resource_start comes in 4 flavors - 2.0, 2.2, early 2.3, 2.4+ */
 
128
#ifndef KERNEL_2_1
 
129
static inline unsigned long
 
130
compat_pci_resource_start(struct pci_dev *pdev,
 
131
                          unsigned int    index)
 
132
{
 
133
   u32 addr;
 
134
 
 
135
   if (pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0 + index * 4, &addr)) {
 
136
      printk(KERN_ERR "Unable to read base address %u from PCI slot %s!\n",
 
137
             index, compat_pci_name(pdev));
 
138
      return ~0UL;
 
139
   }
 
140
   if (addr & PCI_BASE_ADDRESS_SPACE) {
 
141
      return addr & PCI_BASE_ADDRESS_IO_MASK;
 
142
   } else {
 
143
      return addr & PCI_BASE_ADDRESS_MEM_MASK;
 
144
   }
 
145
}
 
146
#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 1)
 
147
#   define compat_pci_resource_start(dev, index) \
 
148
       (((dev)->base_address[index] & PCI_BASE_ADDRESS_SPACE) \
 
149
          ? ((dev)->base_address[index] & PCI_BASE_ADDRESS_IO_MASK) \
 
150
          : ((dev)->base_address[index] & PCI_BASE_ADDRESS_MEM_MASK))
 
151
#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 43)
 
152
#   define compat_pci_resource_start(dev, index) \
 
153
       ((dev)->resource[index].start)
 
154
#else
 
155
#   define compat_pci_resource_start(dev, index) \
 
156
       pci_resource_start(dev, index)
 
157
#endif
 
158
 
 
159
/* since 2.3.15, a new set of s/w res flags IORESOURCE_ is introduced,
 
160
 * we fake them by returning either IORESOURCE_{IO, MEM} prior to 2.3.15 since
 
161
 * this is what compat_pci_request_region uses
 
162
 */
 
163
#ifndef KERNEL_2_1
 
164
static inline unsigned long
 
165
compat_pci_resource_flags(struct pci_dev *pdev,
 
166
                          unsigned int    index)
 
167
{
 
168
   u32 addr;
 
169
 
 
170
   if (pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0 + index * 4, &addr)) {
 
171
      printk(KERN_ERR "Unable to read base address %u from PCI slot %s!\n",
 
172
             index, compat_pci_name(pdev));
 
173
      return ~0UL;
 
174
   }
 
175
   if (addr & PCI_BASE_ADDRESS_SPACE) {
 
176
      return IORESOURCE_IO;
 
177
   } else {
 
178
      return IORESOURCE_MEM;
 
179
   }
 
180
}
 
181
#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 1)
 
182
#   define compat_pci_resource_flags(dev, index) \
 
183
       (((dev)->base_address[index] & PCI_BASE_ADDRESS_SPACE) \
 
184
          ? IORESOURCE_IO: IORESOURCE_MEM)
 
185
#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 15)
 
186
    /* IORESOURCE_xxx appeared in 2.3.15 and is set in resource[].flags */
 
187
#   define compat_pci_resource_flags(dev, index) ((dev)->resource[index].flags)
 
188
#else
 
189
#   define compat_pci_resource_flags(dev, index) pci_resource_flags(dev, index)
 
190
#endif
 
191
 
 
192
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 18)
 
193
static inline unsigned long
 
194
compat_pci_resource_len(struct pci_dev *pdev,  // IN
 
195
                        unsigned int    index) // IN
 
196
{
 
197
   u32 addr, mask;
 
198
   unsigned char reg = PCI_BASE_ADDRESS_0 + index * 4;
 
199
 
 
200
   if (pci_read_config_dword(pdev, reg, &addr) || addr == 0xFFFFFFFF) {
 
201
      return 0;
 
202
   }
 
203
 
 
204
   pci_write_config_dword(pdev, reg, 0xFFFFFFFF);
 
205
   pci_read_config_dword(pdev, reg, &mask);
 
206
   pci_write_config_dword(pdev, reg, addr);
 
207
 
 
208
   if (mask == 0 || mask == 0xFFFFFFFF) {
 
209
      return 0;
 
210
   }
 
211
   if (addr & PCI_BASE_ADDRESS_SPACE) {
 
212
      return 65536 - (mask & PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
 
213
   } else {
 
214
      return -(mask & PCI_BASE_ADDRESS_MEM_MASK);
 
215
   }
 
216
}
 
217
#else
 
218
#define compat_pci_resource_len(dev, index) pci_resource_len(dev, index)
 
219
#endif
 
220
 
 
221
/* pci_request_region appears in 2.4.20 */
 
222
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 20)
 
223
static inline int
 
224
compat_pci_request_region(struct pci_dev *pdev, int bar, char *name)
 
225
{
 
226
   if (compat_pci_resource_len(pdev, bar) == 0) {
 
227
      return 0;
 
228
   }
 
229
 
 
230
   if (compat_pci_resource_flags(pdev, bar) & IORESOURCE_IO) {
 
231
      if (!compat_request_region(compat_pci_resource_start(pdev, bar),
 
232
                                 compat_pci_resource_len(pdev, bar),
 
233
                                 name)) {
 
234
         return -EBUSY;
 
235
      }
 
236
   } else if (compat_pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
 
237
      if (!compat_request_mem_region(compat_pci_resource_start(pdev, bar),
 
238
                                     compat_pci_resource_len(pdev, bar),
 
239
                                     name)) {
 
240
         return -EBUSY;
 
241
      }
 
242
   }
 
243
 
 
244
   return 0;
 
245
}
 
246
 
 
247
static inline void
 
248
compat_pci_release_region(struct pci_dev *pdev, int bar)
 
249
{
 
250
   if (compat_pci_resource_len(pdev, bar) != 0) {
 
251
      if (compat_pci_resource_flags(pdev, bar) & IORESOURCE_IO) {
 
252
         release_region(compat_pci_resource_start(pdev, bar),
 
253
                        compat_pci_resource_len(pdev, bar));
 
254
      } else if (compat_pci_resource_flags(pdev, bar) & IORESOURCE_MEM) {
 
255
         compat_release_mem_region(compat_pci_resource_start(pdev, bar),
 
256
                                   compat_pci_resource_len(pdev, bar));
 
257
      }
 
258
   }
 
259
}
 
260
#else
 
261
#define compat_pci_request_region(pdev, bar, name)  pci_request_region(pdev, bar, name)
 
262
#define compat_pci_release_region(pdev, bar)        pci_release_region(pdev, bar)
 
263
#endif
 
264
 
 
265
/* pci_request_regions appeears in 2.4.3 */
 
266
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 3)
 
267
static inline int
 
268
compat_pci_request_regions(struct pci_dev *pdev, char *name)
 
269
{
 
270
   int i;
 
271
   
 
272
   for (i = 0; i < 6; i++) {
 
273
      if (compat_pci_request_region(pdev, i, name)) {
 
274
         goto release;
 
275
      }
 
276
   }
 
277
   return 0;
 
278
 
 
279
release:
 
280
   while (--i >= 0) {
 
281
      compat_pci_release_region(pdev, i);
 
282
   }
 
283
   return -EBUSY;
 
284
}
 
285
static inline void
 
286
compat_pci_release_regions(struct pci_dev *pdev)
 
287
{
 
288
   int i;
 
289
   
 
290
   for (i = 0; i < 6; i++) {
 
291
      compat_pci_release_region(pdev, i);
 
292
   }
 
293
}
 
294
#else
 
295
#define compat_pci_request_regions(pdev, name) pci_request_regions(pdev, name)
 
296
#define compat_pci_release_regions(pdev)       pci_release_regions(pdev)
 
297
#endif
 
298
 
 
299
/* pci_enable_device is available since 2.4.0 */
 
300
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
 
301
#define compat_pci_enable_device(pdev) (0)
 
302
#else
 
303
#define compat_pci_enable_device(pdev) pci_enable_device(pdev)
 
304
#endif
 
305
 
 
306
 
 
307
/* pci_set_master is available since 2.2.0 */
 
308
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 0)
 
309
#define compat_pci_set_master(pdev) (0)
 
310
#else
 
311
#define compat_pci_set_master(pdev) pci_set_master(pdev)
 
312
#endif
 
313
 
 
314
 
 
315
/* pci_disable_device is available since 2.4.4 */
 
316
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 4)
 
317
#define compat_pci_disable_device(pdev) do {} while (0)
 
318
#else
 
319
#define compat_pci_disable_device(pdev) pci_disable_device(pdev)
 
320
#endif
 
321
 
 
322
 
 
323
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
 
324
/*
 
325
 * Devices supported by particular pci driver.  While 2.4+ kernels
 
326
 * can do match on subsystem and class too, we support match on
 
327
 * vendor/device IDs only.
 
328
 */
 
329
struct pci_device_id {
 
330
   unsigned int vendor, device;
 
331
   unsigned long driver_data;
 
332
};
 
333
#define PCI_DEVICE(vend, dev)   .vendor = (vend), .device = (dev)
 
334
 
 
335
/* PCI driver */
 
336
struct pci_driver {
 
337
   const char *name;
 
338
   const struct pci_device_id *id_table;
 
339
   int   (*probe)(struct pci_dev* dev, const struct pci_device_id* id);
 
340
   void  (*remove)(struct pci_dev* dev);
 
341
};
 
342
 
 
343
 
 
344
/*
 
345
 * Note that this is static variable.  Maybe everything below should be in
 
346
 * separate compat_pci.c file, but currently only user of this file is vmxnet,
 
347
 * and vmxnet has only one file, so it is fine.  Also with vmxnet all
 
348
 * functions below are called just once, so difference between 'inline' and
 
349
 * separate compat_pci.c should be very small.
 
350
 */
 
351
 
 
352
static struct vmw_pci_driver_instance *pci_driver_instances = NULL;
 
353
 
 
354
#ifdef KERNEL_2_1
 
355
#define vmw_pci_device(instance) (instance)->pcidev
 
356
#else
 
357
#define vmw_pci_device(instance) (instance)
 
358
#endif
 
359
 
 
360
 
 
361
/*
 
362
 *-----------------------------------------------------------------------------
 
363
 *
 
364
 * pci_register_driver --
 
365
 *
 
366
 *      Create driver instances for all matching PCI devices in the box.
 
367
 *
 
368
 * Results:
 
369
 *      Returns 0 for success, negative error value for failure.
 
370
 *
 
371
 * Side effects:
 
372
 *      None.
 
373
 *
 
374
 *-----------------------------------------------------------------------------
 
375
 */
 
376
 
 
377
static inline int
 
378
pci_register_driver(struct pci_driver *drv)
 
379
{
 
380
   const struct pci_device_id *chipID;
 
381
 
 
382
   for (chipID = drv->id_table; chipID->vendor; chipID++) {
 
383
#ifdef KERNEL_2_1
 
384
      struct pci_dev *pdev;
 
385
 
 
386
      for (pdev = NULL;
 
387
           (pdev = pci_find_device(chipID->vendor, chipID->device, pdev)) != NULL; ) {
 
388
#else
 
389
      int adapter;
 
390
      unsigned char bus, devfn, irq;
 
391
 
 
392
      for (adapter = 0;
 
393
           pcibios_find_device(chipID->vendor, chipID->device, adapter,
 
394
                               &bus, &devfn) == 0;
 
395
           adapter++) {
 
396
#endif
 
397
         struct vmw_pci_driver_instance *pdi;
 
398
         int err;
 
399
 
 
400
         pdi = kmalloc(sizeof *pdi, GFP_KERNEL);
 
401
         if (!pdi) {
 
402
            printk(KERN_ERR "Not enough memory.\n");
 
403
            break;
 
404
         }
 
405
         pdi->pcidrv = drv;
 
406
#ifdef KERNEL_2_1
 
407
         pdi->pcidev = pdev;
 
408
#else
 
409
         pdi->bus = bus;
 
410
         pdi->devfn = devfn;
 
411
         if (pci_read_config_byte(pdi, PCI_INTERRUPT_LINE, &irq)) {
 
412
            pdi->irq = -1;
 
413
         } else {
 
414
            pdi->irq = irq;
 
415
         }
 
416
#endif
 
417
         pdi->driver_data = NULL;
 
418
         pdi->next = pci_driver_instances;
 
419
         pci_driver_instances = pdi;
 
420
         err = drv->probe(vmw_pci_device(pdi), chipID);
 
421
         if (err) {
 
422
            pci_driver_instances = pdi->next;
 
423
            kfree(pdi);
 
424
         }
 
425
      }
 
426
   }
 
427
   return 0;
 
428
}
 
429
 
 
430
 
 
431
/*
 
432
 *-----------------------------------------------------------------------------
 
433
 *
 
434
 * compat_pci_unregister_driver --
 
435
 *
 
436
 *      Shut down PCI driver - unbind all device instances from driver.
 
437
 *
 
438
 * Results:
 
439
 *      None.
 
440
 *
 
441
 * Side effects:
 
442
 *      None.
 
443
 *
 
444
 *-----------------------------------------------------------------------------
 
445
 */
 
446
 
 
447
static inline void
 
448
pci_unregister_driver(struct pci_driver *drv)
 
449
{
 
450
   struct vmw_pci_driver_instance **ppdi;
 
451
 
 
452
   ppdi = &pci_driver_instances;
 
453
   while (1) {
 
454
      struct vmw_pci_driver_instance *pdi = *ppdi;
 
455
 
 
456
      if (!pdi) {
 
457
         break;
 
458
      }
 
459
      if (pdi->pcidrv == drv) {
 
460
         drv->remove(vmw_pci_device(pdi));
 
461
         *ppdi = pdi->next;
 
462
         kfree(pdi);
 
463
      } else {
 
464
         ppdi = &pdi->next;
 
465
      }
 
466
   }
 
467
}
 
468
#else
 
469
/* provide PCI_DEVICE for early 2.4.x kernels */
 
470
#ifndef PCI_DEVICE
 
471
#define PCI_DEVICE(vend, dev)   .vendor = (vend), .device = (dev), \
 
472
                                .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
 
473
#endif
 
474
#endif
 
475
 
 
476
 
 
477
/* provide dummy MODULE_DEVICE_TABLE for 2.0/2.2 */
 
478
#ifndef MODULE_DEVICE_TABLE
 
479
#define MODULE_DEVICE_TABLE(bus, devices)
 
480
#endif
 
481
 
 
482
 
 
483
/*
 
484
 *-----------------------------------------------------------------------------
 
485
 *
 
486
 * pci_set_drvdata --
 
487
 *
 
488
 *      Set per-device driver's private data.
 
489
 *
 
490
 * Results:
 
491
 *      None.
 
492
 *
 
493
 * Side effects:
 
494
 *      None.
 
495
 *
 
496
 *-----------------------------------------------------------------------------
 
497
 */
 
498
 
 
499
/*
 
500
 *-----------------------------------------------------------------------------
 
501
 *
 
502
 * pci_get_drvdata --
 
503
 *
 
504
 *      Retrieve per-device driver's private data.
 
505
 *
 
506
 * Results:
 
507
 *      per-device driver's data previously set by pci_set_drvdata,
 
508
 *      or NULL on failure.
 
509
 *
 
510
 * Side effects:
 
511
 *      None.
 
512
 *
 
513
 *-----------------------------------------------------------------------------
 
514
 */
 
515
 
 
516
#ifndef KERNEL_2_1
 
517
/* 2.0.x is simple, we have driver_data directly in pci_dev */
 
518
#define pci_set_drvdata(pdev, data) do { (pdev)->driver_data = (data); } while (0)
 
519
#define pci_get_drvdata(pdev)       (pdev)->driver_data
 
520
#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
 
521
/* 2.2.x is trickier, we have to find driver instance first */
 
522
static inline void
 
523
pci_set_drvdata(struct pci_dev *pdev, void* data)
 
524
{
 
525
   struct vmw_pci_driver_instance *pdi;
 
526
 
 
527
   for (pdi = pci_driver_instances; pdi; pdi = pdi->next) {
 
528
      if (pdi->pcidev == pdev) {
 
529
         pdi->driver_data = data;
 
530
         return;
 
531
      }
 
532
   }
 
533
   printk(KERN_ERR "pci_set_drvdata issued for unknown device %p\n", pdev);
 
534
}
 
535
 
 
536
static inline void *
 
537
pci_get_drvdata(struct pci_dev *pdev)
 
538
{
 
539
   struct vmw_pci_driver_instance *pdi;
 
540
 
 
541
   for (pdi = pci_driver_instances; pdi; pdi = pdi->next) {
 
542
      if (pdi->pcidev == pdev) {
 
543
         return pdi->driver_data;
 
544
      }
 
545
   }
 
546
   printk(KERN_ERR "pci_get_drvdata issued for unknown device %p\n", pdev);
 
547
   return NULL;
 
548
}
 
549
#endif
 
550
 
 
551
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,48)
 
552
#   define PCI_DMA_BIDIRECTIONAL        0
 
553
#   define PCI_DMA_TODEVICE             1
 
554
#   define PCI_DMA_FROMDEVICE           2
 
555
#   define PCI_DMA_NONE                 3
 
556
#endif
 
557
 
 
558
/*
 
559
 * Power Management related compat wrappers.
 
560
 */
 
561
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 10)
 
562
#   define compat_pci_save_state(pdev)      pci_save_state((pdev), NULL)
 
563
#   define compat_pci_restore_state(pdev)   pci_restore_state((pdev), NULL)
 
564
#else
 
565
#   define compat_pci_save_state(pdev)      pci_save_state((pdev))
 
566
#   define compat_pci_restore_state(pdev)   pci_restore_state((pdev))
 
567
#endif
 
568
 
 
569
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)
 
570
#   define pm_message_t          u32
 
571
#   define compat_pci_choose_state(pdev, state)  (state)
 
572
#   define PCI_D0               0
 
573
#   define PCI_D3hot            3
 
574
#else
 
575
#   define compat_pci_choose_state(pdev, state)  pci_choose_state((pdev), (state))
 
576
#endif
 
577
 
 
578
/* 2.6.14 changed the PCI shutdown callback */
 
579
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
 
580
#   define COMPAT_PCI_SHUTDOWN(func)               .driver = { .shutdown = (func), }
 
581
#   define COMPAT_PCI_DECLARE_SHUTDOWN(func, var)  (func)(struct device *(var))
 
582
#   define COMPAT_PCI_TO_DEV(dev)                  (to_pci_dev(dev))
 
583
#else
 
584
#   define COMPAT_PCI_SHUTDOWN(func)               .shutdown = (func)
 
585
#   define COMPAT_PCI_DECLARE_SHUTDOWN(func, var)  (func)(struct pci_dev *(var))
 
586
#   define COMPAT_PCI_TO_DEV(dev)                  (dev)
 
587
#endif
 
588
 
 
589
 
 
590
#endif /* __COMPAT_PCI_H__ */