home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lxapi32.zip / Include / asm / pci.h < prev    next >
C/C++ Source or Header  |  2002-04-26  |  7KB  |  245 lines

  1. /* $Id: pci.h,v 1.2 2002/04/26 23:09:20 smilcke Exp $ */
  2.  
  3. #ifndef __i386_PCI_H
  4. #define __i386_PCI_H
  5.  
  6. #include <linux/config.h>
  7.  
  8. #ifdef __KERNEL__
  9.  
  10. #ifdef TARGET_OS2
  11. static __inline__ void BUG(){}
  12. #endif
  13.  
  14. /* Can be used to override the logic in pci_scan_bus for skipping
  15.    already-configured bus numbers - to be used for buggy BIOSes
  16.    or architectures with incomplete PCI setup by the loader */
  17.  
  18. #ifdef CONFIG_PCI
  19. extern unsigned int pcibios_assign_all_busses(void);
  20. #else
  21. #define pcibios_assign_all_busses()    0
  22. #endif
  23.  
  24. extern unsigned long pci_mem_start;
  25. #define PCIBIOS_MIN_IO        0x1000
  26. #define PCIBIOS_MIN_MEM        (pci_mem_start)
  27.  
  28. void pcibios_set_master(struct pci_dev *dev);
  29. void pcibios_penalize_isa_irq(int irq);
  30.  
  31. /* Dynamic DMA mapping stuff.
  32.  * i386 has everything mapped statically.
  33.  */
  34.  
  35. #include <linux/types.h>
  36. #include <linux/slab.h>
  37. #ifdef TARGET_OS2
  38. #include <asm/scatterl.h>
  39. #else
  40. #include <asm/scatterlist.h>
  41. #endif
  42. #include <linux/string.h>
  43. #include <asm/io.h>
  44.  
  45. struct pci_dev;
  46.  
  47. /* Allocate and map kernel buffer using consistent mode DMA for a device.
  48.  * hwdev should be valid struct pci_dev pointer for PCI devices,
  49.  * NULL for PCI-like buses (ISA, EISA).
  50.  * Returns non-NULL cpu-view pointer to the buffer if successful and
  51.  * sets *dma_addrp to the pci side dma address as well, else *dma_addrp
  52.  * is undefined.
  53.  */
  54. extern void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
  55.                   dma_addr_t *dma_handle);
  56.  
  57. /* Free and unmap a consistent DMA buffer.
  58.  * cpu_addr is what was returned from pci_alloc_consistent,
  59.  * size must be the same as what as passed into pci_alloc_consistent,
  60.  * and likewise dma_addr must be the same as what *dma_addrp was set to.
  61.  *
  62.  * References to the memory and mappings associated with cpu_addr/dma_addr
  63.  * past this call are illegal.
  64.  */
  65. extern void pci_free_consistent(struct pci_dev *hwdev, size_t size,
  66.                 void *vaddr, dma_addr_t dma_handle);
  67.  
  68. /* Map a single buffer of the indicated size for DMA in streaming mode.
  69.  * The 32-bit bus address to use is returned.
  70.  *
  71.  * Once the device is given the dma address, the device owns this memory
  72.  * until either pci_unmap_single or pci_dma_sync_single is performed.
  73.  */
  74. #ifdef TARGET_OS2
  75. static __inline__
  76. #else
  77. static inline
  78. #endif
  79. dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr,
  80.                     size_t size, int direction)
  81. {
  82.     if (direction == PCI_DMA_NONE)
  83.         BUG();
  84.     return virt_to_bus(ptr);
  85. }
  86.  
  87. /* Unmap a single streaming mode DMA translation.  The dma_addr and size
  88.  * must match what was provided for in a previous pci_map_single call.  All
  89.  * other usages are undefined.
  90.  *
  91.  * After this call, reads by the cpu to the buffer are guarenteed to see
  92.  * whatever the device wrote there.
  93.  */
  94. #ifdef TARGET_OS2
  95. static __inline__
  96. #else
  97. static inline
  98. #endif
  99. void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
  100.                     size_t size, int direction)
  101. {
  102.     if (direction == PCI_DMA_NONE)
  103.         BUG();
  104.     /* Nothing to do */
  105. }
  106.  
  107. /* Map a set of buffers described by scatterlist in streaming
  108.  * mode for DMA.  This is the scather-gather version of the
  109.  * above pci_map_single interface.  Here the scatter gather list
  110.  * elements are each tagged with the appropriate dma address
  111.  * and length.  They are obtained via sg_dma_{address,length}(SG).
  112.  *
  113.  * NOTE: An implementation may be able to use a smaller number of
  114.  *       DMA address/length pairs than there are SG table elements.
  115.  *       (for example via virtual mapping capabilities)
  116.  *       The routine returns the number of addr/length pairs actually
  117.  *       used, at most nents.
  118.  *
  119.  * Device ownership issues as mentioned above for pci_map_single are
  120.  * the same here.
  121.  */
  122. #ifdef TARGET_OS2
  123. static __inline__
  124. #else
  125. static inline
  126. #endif
  127. int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
  128.                  int nents, int direction)
  129. {
  130.     if (direction == PCI_DMA_NONE)
  131.         BUG();
  132.     return nents;
  133. }
  134.  
  135. /* Unmap a set of streaming mode DMA translations.
  136.  * Again, cpu read rules concerning calls here are the same as for
  137.  * pci_unmap_single() above.
  138.  */
  139. #ifdef TARGET_OS2
  140. static __inline__
  141. #else
  142. static inline
  143. #endif
  144. void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
  145.                 int nents, int direction)
  146. {
  147.     if (direction == PCI_DMA_NONE)
  148.         BUG();
  149.     /* Nothing to do */
  150. }
  151.  
  152. /* Make physical memory consistent for a single
  153.  * streaming mode DMA translation after a transfer.
  154.  *
  155.  * If you perform a pci_map_single() but wish to interrogate the
  156.  * buffer using the cpu, yet do not wish to teardown the PCI dma
  157.  * mapping, you must call this function before doing so.  At the
  158.  * next point you give the PCI dma address back to the card, the
  159.  * device again owns the buffer.
  160.  */
  161. #ifdef TARGET_OS2
  162. static __inline__
  163. #else
  164. static inline
  165. #endif
  166. void pci_dma_sync_single(struct pci_dev *hwdev,
  167.                        dma_addr_t dma_handle,
  168.                        size_t size, int direction)
  169. {
  170.     if (direction == PCI_DMA_NONE)
  171.         BUG();
  172.     /* Nothing to do */
  173. }
  174.  
  175. /* Make physical memory consistent for a set of streaming
  176.  * mode DMA translations after a transfer.
  177.  *
  178.  * The same as pci_dma_sync_single but for a scatter-gather list,
  179.  * same rules and usage.
  180.  */
  181. #ifdef TARGET_OS2
  182. static __inline__
  183. #else
  184. static inline
  185. #endif
  186. void pci_dma_sync_sg(struct pci_dev *hwdev,
  187.                    struct scatterlist *sg,
  188.                    int nelems, int direction)
  189. {
  190.     if (direction == PCI_DMA_NONE)
  191.         BUG();
  192.     /* Nothing to do */
  193. }
  194.  
  195. /* Return whether the given PCI device DMA address mask can
  196.  * be supported properly.  For example, if your device can
  197.  * only drive the low 24-bits during PCI bus mastering, then
  198.  * you would pass 0x00ffffff as the mask to this function.
  199.  */
  200. #ifdef TARGET_OS2
  201. static __inline__
  202. #else
  203. static inline
  204. #endif
  205. int pci_dma_supported(struct pci_dev *hwdev, dma_addr_t mask)
  206. {
  207.         /*
  208.          * we fall back to GFP_DMA when the mask isn't all 1s,
  209.          * so we can't guarantee allocations that must be
  210.          * within a tighter range than GFP_DMA..
  211.          */
  212.         if(mask < 0x00ffffff)
  213.                 return 0;
  214.  
  215.     return 1;
  216. }
  217.  
  218. /* These macros should be used after a pci_map_sg call has been done
  219.  * to get bus addresses of each of the SG entries and their lengths.
  220.  * You should only work with the number of sg entries pci_map_sg
  221.  * returns, or alternatively stop on the first sg_dma_len(sg) which
  222.  * is 0.
  223.  */
  224. #define sg_dma_address(sg)    (virt_to_bus((sg)->address))
  225. #define sg_dma_len(sg)        ((sg)->length)
  226.  
  227. /* Return the index of the PCI controller for device. */
  228. #ifdef TARGET_OS2
  229. static __inline__
  230. #else
  231. static inline
  232. #endif
  233. int pci_controller_num(struct pci_dev *dev)
  234. {
  235.     return 0;
  236. }
  237.  
  238. #define HAVE_PCI_MMAP
  239. extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
  240.                    enum pci_mmap_state mmap_state, int write_combine);
  241.  
  242. #endif /* __KERNEL__ */
  243.  
  244. #endif /* __i386_PCI_H */
  245.