pci-noop.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. struct dma_attrs *attrs)
  93. {
  94. void *ret;
  95. if (!dev || *dev->dma_mask >= 0xffffffffUL)
  96. gfp &= ~GFP_DMA;
  97. ret = (void *)__get_free_pages(gfp, get_order(size));
  98. if (ret) {
  99. memset(ret, 0, size);
  100. *dma_handle = virt_to_phys(ret);
  101. }
  102. return ret;
  103. }
  104. static void alpha_noop_free_coherent(struct device *dev, size_t size,
  105. void *cpu_addr, dma_addr_t dma_addr,
  106. struct dma_attrs *attrs)
  107. {
  108. free_pages((unsigned long)cpu_addr, get_order(size));
  109. }
  110. static dma_addr_t alpha_noop_map_page(struct device *dev, struct page *page,
  111. unsigned long offset, size_t size,
  112. enum dma_data_direction dir,
  113. struct dma_attrs *attrs)
  114. {
  115. return page_to_pa(page) + offset;
  116. }
  117. static int alpha_noop_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
  118. enum dma_data_direction dir, struct dma_attrs *attrs)
  119. {
  120. int i;
  121. struct scatterlist *sg;
  122. for_each_sg(sgl, sg, nents, i) {
  123. void *va;
  124. BUG_ON(!sg_page(sg));
  125. va = sg_virt(sg);
  126. sg_dma_address(sg) = (dma_addr_t)virt_to_phys(va);
  127. sg_dma_len(sg) = sg->length;
  128. }
  129. return nents;
  130. }
  131. static int alpha_noop_mapping_error(struct device *dev, dma_addr_t dma_addr)
  132. {
  133. return 0;
  134. }
  135. static int alpha_noop_supported(struct device *dev, u64 mask)
  136. {
  137. return mask < 0x00ffffffUL ? 0 : 1;
  138. }
  139. struct dma_map_ops alpha_noop_ops = {
  140. .alloc = alpha_noop_alloc_coherent,
  141. .free = alpha_noop_free_coherent,
  142. .map_page = alpha_noop_map_page,
  143. .map_sg = alpha_noop_map_sg,
  144. .mapping_error = alpha_noop_mapping_error,
  145. .dma_supported = alpha_noop_supported,
  146. };
  147. struct dma_map_ops *dma_ops = &alpha_noop_ops;
  148. EXPORT_SYMBOL(dma_ops);