~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201207201942

« back to all changes in this revision

Viewing changes to modules/linux/vmxnet/compat_pci_mapping.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-03-20 10:19:00 UTC
  • mfrom: (1.1.4 upstream) (2.4.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090320101900-1o604camiubq2de8
Tags: 2009.03.18-154848-2
Correcting patch system depends (Closes: #520493).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 2008 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
#ifndef __COMPAT_PCI_MAPPING_H__
 
20
#define __COMPAT_PCI_MAPPING_H__
 
21
 
 
22
#include <asm/types.h>
 
23
#include <asm/io.h>
 
24
#include <linux/pci.h>
 
25
 
 
26
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,41)
 
27
typedef u32 dma_addr_t;
 
28
 
 
29
static __inline__ int 
 
30
get_order(unsigned long size)
 
31
{
 
32
   int order;
 
33
 
 
34
   size = (size - 1) >> (PAGE_SHIFT - 1);
 
35
   order = -1;
 
36
   do {
 
37
      size >>= 1;
 
38
      order++;
 
39
   } while (size);
 
40
   return order;
 
41
}
 
42
 
 
43
static inline void *
 
44
compat_pci_alloc_consistent(struct pci_dev *hwdev, size_t size, dma_addr_t *dma_handle)
 
45
{
 
46
   void *ptr = (void *)__get_free_pages(GFP_ATOMIC, get_order(size));
 
47
   if (ptr) {
 
48
      memset(ptr, 0, size);
 
49
      *dma_handle = virt_to_phys(ptr);
 
50
   }
 
51
   return ptr;
 
52
}
 
53
 
 
54
static inline void
 
55
compat_pci_free_consistent(struct pci_dev *hwdev, size_t size, void *vaddr, 
 
56
                           dma_addr_t dma_handle)
 
57
{
 
58
   free_pages((unsigned long)vaddr, get_order(size));
 
59
}
 
60
 
 
61
static inline dma_addr_t
 
62
compat_pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, int direction)
 
63
{
 
64
   return virt_to_phys(ptr);
 
65
}
 
66
 
 
67
static inline void
 
68
compat_pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
 
69
                        size_t size, int direction)
 
70
{
 
71
}
 
72
 
 
73
#else
 
74
#define compat_pci_alloc_consistent(hwdev, size, dma_handle) \
 
75
   pci_alloc_consistent(hwdev, size, dma_handle)
 
76
#define compat_pci_free_consistent(hwdev, size, vaddr, dma_handle) \
 
77
   pci_free_consistent(hwdev, size, vaddr, dma_handle)
 
78
#define compat_pci_map_single(hwdev, ptr, size, direction) \
 
79
   pci_map_single(hwdev, ptr, size, direction)
 
80
#define compat_pci_unmap_single(hwdev, dma_addr, size, direction) \
 
81
   pci_unmap_single(hwdev, dma_addr, size, direction)
 
82
#endif
 
83
 
 
84
#endif