pci.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. static struct resource loongson_pci_mem_resource = {
  14. .name = "pci memory space",
  15. .start = LOONGSON_PCI_MEM_START,
  16. .end = LOONGSON_PCI_MEM_END,
  17. .flags = IORESOURCE_MEM,
  18. };
  19. static struct resource loongson_pci_io_resource = {
  20. .name = "pci io space",
  21. .start = LOONGSON_PCI_IO_START,
  22. .end = IO_SPACE_LIMIT,
  23. .flags = IORESOURCE_IO,
  24. };
  25. static struct pci_controller loongson_pci_controller = {
  26. .pci_ops = &bonito64_pci_ops,
  27. .io_resource = &loongson_pci_io_resource,
  28. .mem_resource = &loongson_pci_mem_resource,
  29. .mem_offset = 0x00000000UL,
  30. .io_offset = 0x00000000UL,
  31. };
  32. static void __init setup_pcimap(void)
  33. {
  34. /*
  35. * local to PCI mapping for CPU accessing PCI space
  36. * CPU address space [256M,448M] is window for accessing pci space
  37. * we set pcimap_lo[0,1,2] to map it to pci space[0M,64M], [320M,448M]
  38. *
  39. * pcimap: PCI_MAP2 PCI_Mem_Lo2 PCI_Mem_Lo1 PCI_Mem_Lo0
  40. * [<2G] [384M,448M] [320M,384M] [0M,64M]
  41. */
  42. BONITO_PCIMAP = BONITO_PCIMAP_PCIMAP_2 |
  43. BONITO_PCIMAP_WIN(2, BONITO_PCILO2_BASE) |
  44. BONITO_PCIMAP_WIN(1, BONITO_PCILO1_BASE) |
  45. BONITO_PCIMAP_WIN(0, 0);
  46. /*
  47. * PCI-DMA to local mapping: [2G,2G+256M] -> [0M,256M]
  48. */
  49. BONITO_PCIBASE0 = 0x80000000ul; /* base: 2G -> mmap: 0M */
  50. /* size: 256M, burst transmission, pre-fetch enable, 64bit */
  51. LOONGSON_PCI_HIT0_SEL_L = 0xc000000cul;
  52. LOONGSON_PCI_HIT0_SEL_H = 0xfffffffful;
  53. LOONGSON_PCI_HIT1_SEL_L = 0x00000006ul; /* set this BAR as invalid */
  54. LOONGSON_PCI_HIT1_SEL_H = 0x00000000ul;
  55. LOONGSON_PCI_HIT2_SEL_L = 0x00000006ul; /* set this BAR as invalid */
  56. LOONGSON_PCI_HIT2_SEL_H = 0x00000000ul;
  57. /* avoid deadlock of PCI reading/writing lock operation */
  58. LOONGSON_PCI_ISR4C = 0xd2000001ul;
  59. /* can not change gnt to break pci transfer when device's gnt not
  60. deassert for some broken device */
  61. LOONGSON_PXARB_CFG = 0x00fe0105ul;
  62. }
  63. static int __init pcibios_init(void)
  64. {
  65. setup_pcimap();
  66. loongson_pci_controller.io_map_base = mips_io_port_base;
  67. register_pci_controller(&loongson_pci_controller);
  68. return 0;
  69. }
  70. arch_initcall(pcibios_init);