pci.c 2.9 KB

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