pci.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology
  4. * Author: Fuxin Zhang, [email protected]
  5. */
  6. #include <linux/pci.h>
  7. #include <pci.h>
  8. #include <loongson.h>
  9. static struct resource loongson_pci_mem_resource = {
  10. .name = "pci memory space",
  11. .start = LOONGSON_PCI_MEM_START,
  12. .end = LOONGSON_PCI_MEM_END,
  13. .flags = IORESOURCE_MEM,
  14. };
  15. static struct resource loongson_pci_io_resource = {
  16. .name = "pci io space",
  17. .start = LOONGSON_PCI_IO_START,
  18. .end = IO_SPACE_LIMIT,
  19. .flags = IORESOURCE_IO,
  20. };
  21. static struct pci_controller loongson_pci_controller = {
  22. .pci_ops = &loongson_pci_ops,
  23. .io_resource = &loongson_pci_io_resource,
  24. .mem_resource = &loongson_pci_mem_resource,
  25. .mem_offset = 0x00000000UL,
  26. .io_offset = 0x00000000UL,
  27. };
  28. static void __init setup_pcimap(void)
  29. {
  30. /*
  31. * local to PCI mapping for CPU accessing PCI space
  32. * CPU address space [256M,448M] is window for accessing pci space
  33. * we set pcimap_lo[0,1,2] to map it to pci space[0M,64M], [320M,448M]
  34. *
  35. * pcimap: PCI_MAP2 PCI_Mem_Lo2 PCI_Mem_Lo1 PCI_Mem_Lo0
  36. * [<2G] [384M,448M] [320M,384M] [0M,64M]
  37. */
  38. LOONGSON_PCIMAP = LOONGSON_PCIMAP_PCIMAP_2 |
  39. LOONGSON_PCIMAP_WIN(2, LOONGSON_PCILO2_BASE) |
  40. LOONGSON_PCIMAP_WIN(1, LOONGSON_PCILO1_BASE) |
  41. LOONGSON_PCIMAP_WIN(0, 0);
  42. /*
  43. * PCI-DMA to local mapping: [2G,2G+256M] -> [0M,256M]
  44. */
  45. LOONGSON_PCIBASE0 = 0x80000000ul; /* base: 2G -> mmap: 0M */
  46. /* size: 256M, burst transmission, pre-fetch enable, 64bit */
  47. LOONGSON_PCI_HIT0_SEL_L = 0xc000000cul;
  48. LOONGSON_PCI_HIT0_SEL_H = 0xfffffffful;
  49. LOONGSON_PCI_HIT1_SEL_L = 0x00000006ul; /* set this BAR as invalid */
  50. LOONGSON_PCI_HIT1_SEL_H = 0x00000000ul;
  51. LOONGSON_PCI_HIT2_SEL_L = 0x00000006ul; /* set this BAR as invalid */
  52. LOONGSON_PCI_HIT2_SEL_H = 0x00000000ul;
  53. /* avoid deadlock of PCI reading/writing lock operation */
  54. LOONGSON_PCI_ISR4C = 0xd2000001ul;
  55. /* can not change gnt to break pci transfer when device's gnt not
  56. deassert for some broken device */
  57. LOONGSON_PXARB_CFG = 0x00fe0105ul;
  58. #ifdef CONFIG_CPU_SUPPORTS_ADDRWINCFG
  59. /*
  60. * set cpu addr window2 to map CPU address space to PCI address space
  61. */
  62. LOONGSON_ADDRWIN_CPUTOPCI(ADDRWIN_WIN2, LOONGSON_CPU_MEM_SRC,
  63. LOONGSON_PCI_MEM_DST, MMAP_CPUTOPCI_SIZE);
  64. #endif
  65. }
  66. static int __init pcibios_init(void)
  67. {
  68. setup_pcimap();
  69. loongson_pci_controller.io_map_base = mips_io_port_base;
  70. register_pci_controller(&loongson_pci_controller);
  71. return 0;
  72. }
  73. arch_initcall(pcibios_init);