pci-noop.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * linux/arch/alpha/kernel/pci-noop.c
  3. *
  4. * Stub PCI interfaces for Jensen-specific kernels.
  5. */
  6. #include <linux/pci.h>
  7. #include <linux/init.h>
  8. #include <linux/bootmem.h>
  9. #include <linux/gfp.h>
  10. #include <linux/capability.h>
  11. #include <linux/mm.h>
  12. #include <linux/errno.h>
  13. #include <linux/sched.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/scatterlist.h>
  16. #include "proto.h"
  17. /*
  18. * The PCI controller list.
  19. */
  20. struct pci_controller *hose_head, **hose_tail = &hose_head;
  21. struct pci_controller *pci_isa_hose;
  22. struct pci_controller * __init
  23. alloc_pci_controller(void)
  24. {
  25. struct pci_controller *hose;
  26. hose = alloc_bootmem(sizeof(*hose));
  27. *hose_tail = hose;
  28. hose_tail = &hose->next;
  29. return hose;
  30. }
  31. struct resource * __init
  32. alloc_resource(void)
  33. {
  34. struct resource *res;
  35. res = alloc_bootmem(sizeof(*res));
  36. return res;
  37. }
  38. asmlinkage long
  39. sys_pciconfig_iobase(long which, unsigned long bus, unsigned long dfn)
  40. {
  41. struct pci_controller *hose;
  42. /* from hose or from bus.devfn */
  43. if (which & IOBASE_FROM_HOSE) {
  44. for (hose = hose_head; hose; hose = hose->next)
  45. if (hose->index == bus)
  46. break;
  47. if (!hose)
  48. return -ENODEV;
  49. } else {
  50. /* Special hook for ISA access. */
  51. if (bus == 0 && dfn == 0)
  52. hose = pci_isa_hose;
  53. else
  54. return -ENODEV;
  55. }
  56. switch (which & ~IOBASE_FROM_HOSE) {
  57. case IOBASE_HOSE:
  58. return hose->index;
  59. case IOBASE_SPARSE_MEM:
  60. return hose->sparse_mem_base;
  61. case IOBASE_DENSE_MEM:
  62. return hose->dense_mem_base;
  63. case IOBASE_SPARSE_IO:
  64. return hose->sparse_io_base;
  65. case IOBASE_DENSE_IO:
  66. return hose->dense_io_base;
  67. case IOBASE_ROOT_BUS:
  68. return hose->bus->number;
  69. }
  70. return -EOPNOTSUPP;
  71. }
  72. asmlinkage long
  73. sys_pciconfig_read(unsigned long bus, unsigned long dfn,
  74. unsigned long off, unsigned long len, void *buf)
  75. {
  76. if (!capable(CAP_SYS_ADMIN))
  77. return -EPERM;
  78. else
  79. return -ENODEV;
  80. }
  81. asmlinkage long
  82. sys_pciconfig_write(unsigned long bus, unsigned long dfn,
  83. unsigned long off, unsigned long len, void *buf)
  84. {
  85. if (!capable(CAP_SYS_ADMIN))
  86. return -EPERM;
  87. else
  88. return -ENODEV;
  89. }
  90. static void *alpha_noop_alloc_coherent(struct device *dev, size_t size,
  91. dma_addr_t *dma_handle, gfp_t gfp)
  92. {
  93. void *ret;
  94. if (!dev || *dev->dma_mask >= 0xffffffffUL)
  95. gfp &= ~GFP_DMA;
  96. ret = (void *)__get_free_pages(gfp, get_order(size));
  97. if (ret) {
  98. memset(ret, 0, size);
  99. *dma_handle = virt_to_phys(ret);
  100. }
  101. return ret;
  102. }
  103. static void alpha_noop_free_coherent(struct device *dev, size_t size,
  104. void *cpu_addr, dma_addr_t dma_addr)
  105. {
  106. free_pages((unsigned long)cpu_addr, get_order(size));
  107. }
  108. static dma_addr_t alpha_noop_map_page(struct device *dev, struct page *page,
  109. unsigned long offset, size_t size,
  110. enum dma_data_direction dir,
  111. struct dma_attrs *attrs)
  112. {
  113. return page_to_pa(page) + offset;
  114. }
  115. static int alpha_noop_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
  116. enum dma_data_direction dir, struct dma_attrs *attrs)
  117. {
  118. int i;
  119. struct scatterlist *sg;
  120. for_each_sg(sgl, sg, nents, i) {
  121. void *va;
  122. BUG_ON(!sg_page(sg));
  123. va = sg_virt(sg);
  124. sg_dma_address(sg) = (dma_addr_t)virt_to_phys(va);
  125. sg_dma_len(sg) = sg->length;
  126. }
  127. return nents;
  128. }
  129. static int alpha_noop_mapping_error(struct device *dev, dma_addr_t dma_addr)
  130. {
  131. return 0;
  132. }
  133. static int alpha_noop_supported(struct device *dev, u64 mask)
  134. {
  135. return mask < 0x00ffffffUL ? 0 : 1;
  136. }
  137. static int alpha_noop_set_mask(struct device *dev, u64 mask)
  138. {
  139. if (!dev->dma_mask || !dma_supported(dev, mask))
  140. return -EIO;
  141. *dev->dma_mask = mask;
  142. return 0;
  143. }
  144. struct dma_map_ops alpha_noop_ops = {
  145. .alloc_coherent = alpha_noop_alloc_coherent,
  146. .free_coherent = alpha_noop_free_coherent,
  147. .map_page = alpha_noop_map_page,
  148. .map_sg = alpha_noop_map_sg,
  149. .mapping_error = alpha_noop_mapping_error,
  150. .dma_supported = alpha_noop_supported,
  151. .set_dma_mask = alpha_noop_set_mask,
  152. };
  153. struct dma_map_ops *dma_ops = &alpha_noop_ops;
  154. EXPORT_SYMBOL(dma_ops);
  155. void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
  156. {
  157. return NULL;
  158. }
  159. void pci_iounmap(struct pci_dev *dev, void __iomem * addr)
  160. {
  161. }
  162. EXPORT_SYMBOL(pci_iomap);
  163. EXPORT_SYMBOL(pci_iounmap);