iommu.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * iommu.h
  3. * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen, IBM Corporation
  4. * Rewrite, cleanup:
  5. * Copyright (C) 2004 Olof Johansson <olof@austin.ibm.com>, IBM Corporation
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifndef _ASM_IOMMU_H
  22. #define _ASM_IOMMU_H
  23. #include <asm/types.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/device.h>
  26. #include <linux/dma-mapping.h>
  27. /*
  28. * IOMAP_MAX_ORDER defines the largest contiguous block
  29. * of dma (tce) space we can get. IOMAP_MAX_ORDER = 13
  30. * allows up to 2**12 pages (4096 * 4096) = 16 MB
  31. */
  32. #define IOMAP_MAX_ORDER 13
  33. /*
  34. * Tces come in two formats, one for the virtual bus and a different
  35. * format for PCI
  36. */
  37. #define TCE_VB 0
  38. #define TCE_PCI 1
  39. /* tce_entry
  40. * Used by pSeries (SMP) and iSeries/pSeries LPAR, but there it's
  41. * abstracted so layout is irrelevant.
  42. */
  43. union tce_entry {
  44. unsigned long te_word;
  45. struct {
  46. unsigned int tb_cacheBits :6; /* Cache hash bits - not used */
  47. unsigned int tb_rsvd :6;
  48. unsigned long tb_rpn :40; /* Real page number */
  49. unsigned int tb_valid :1; /* Tce is valid (vb only) */
  50. unsigned int tb_allio :1; /* Tce is valid for all lps (vb only) */
  51. unsigned int tb_lpindex :8; /* LpIndex for user of TCE (vb only) */
  52. unsigned int tb_pciwr :1; /* Write allowed (pci only) */
  53. unsigned int tb_rdwr :1; /* Read allowed (pci), Write allowed (vb) */
  54. } te_bits;
  55. #define te_cacheBits te_bits.tb_cacheBits
  56. #define te_rpn te_bits.tb_rpn
  57. #define te_valid te_bits.tb_valid
  58. #define te_allio te_bits.tb_allio
  59. #define te_lpindex te_bits.tb_lpindex
  60. #define te_pciwr te_bits.tb_pciwr
  61. #define te_rdwr te_bits.tb_rdwr
  62. };
  63. struct iommu_table {
  64. unsigned long it_busno; /* Bus number this table belongs to */
  65. unsigned long it_size; /* Size of iommu table in entries */
  66. unsigned long it_offset; /* Offset into global table */
  67. unsigned long it_base; /* mapped address of tce table */
  68. unsigned long it_index; /* which iommu table this is */
  69. unsigned long it_type; /* type: PCI or Virtual Bus */
  70. unsigned long it_blocksize; /* Entries in each block (cacheline) */
  71. unsigned long it_hint; /* Hint for next alloc */
  72. unsigned long it_largehint; /* Hint for large allocs */
  73. unsigned long it_halfpoint; /* Breaking point for small/large allocs */
  74. spinlock_t it_lock; /* Protects it_map */
  75. unsigned long *it_map; /* A simple allocation bitmap for now */
  76. };
  77. struct scatterlist;
  78. #ifdef CONFIG_PPC_MULTIPLATFORM
  79. /* Walks all buses and creates iommu tables */
  80. extern void iommu_setup_pSeries(void);
  81. extern void iommu_setup_u3(void);
  82. /* Frees table for an individual device node */
  83. extern void iommu_free_table(struct device_node *dn);
  84. #endif /* CONFIG_PPC_MULTIPLATFORM */
  85. #ifdef CONFIG_PPC_PSERIES
  86. /* Creates table for an individual device node */
  87. extern void iommu_devnode_init_pSeries(struct device_node *dn);
  88. #endif /* CONFIG_PPC_PSERIES */
  89. #ifdef CONFIG_PPC_ISERIES
  90. struct iSeries_Device_Node;
  91. /* Creates table for an individual device node */
  92. extern void iommu_devnode_init_iSeries(struct iSeries_Device_Node *dn);
  93. #endif /* CONFIG_PPC_ISERIES */
  94. /* Initializes an iommu_table based in values set in the passed-in
  95. * structure
  96. */
  97. extern struct iommu_table *iommu_init_table(struct iommu_table * tbl);
  98. extern int iommu_map_sg(struct device *dev, struct iommu_table *tbl,
  99. struct scatterlist *sglist, int nelems,
  100. enum dma_data_direction direction);
  101. extern void iommu_unmap_sg(struct iommu_table *tbl, struct scatterlist *sglist,
  102. int nelems, enum dma_data_direction direction);
  103. extern void *iommu_alloc_coherent(struct iommu_table *tbl, size_t size,
  104. dma_addr_t *dma_handle, unsigned int __nocast flag);
  105. extern void iommu_free_coherent(struct iommu_table *tbl, size_t size,
  106. void *vaddr, dma_addr_t dma_handle);
  107. extern dma_addr_t iommu_map_single(struct iommu_table *tbl, void *vaddr,
  108. size_t size, enum dma_data_direction direction);
  109. extern void iommu_unmap_single(struct iommu_table *tbl, dma_addr_t dma_handle,
  110. size_t size, enum dma_data_direction direction);
  111. extern void iommu_init_early_pSeries(void);
  112. extern void iommu_init_early_iSeries(void);
  113. extern void iommu_init_early_u3(void);
  114. #ifdef CONFIG_PCI
  115. extern void pci_iommu_init(void);
  116. extern void pci_direct_iommu_init(void);
  117. #else
  118. static inline void pci_iommu_init(void) { }
  119. #endif
  120. extern void alloc_u3_dart_table(void);
  121. #endif /* _ASM_IOMMU_H */