cs5536_pci.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * read/write operation to the PCI config space of CS5536
  3. *
  4. * Copyright (C) 2007 Lemote, Inc.
  5. * Author : jlliu, liujl@lemote.com
  6. *
  7. * Copyright (C) 2009 Lemote, Inc.
  8. * Author: Wu Zhangjin, wuzhangjin@gmail.com
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. * the Virtual Support Module(VSM) for virtulizing the PCI
  16. * configure space are defined in cs5536_modulename.c respectively,
  17. *
  18. * after this virtulizing, user can access the PCI configure space
  19. * directly as a normal multi-function PCI device which follows
  20. * the PCI-2.2 spec.
  21. */
  22. #include <linux/types.h>
  23. #include <cs5536/cs5536_pci.h>
  24. #include <cs5536/cs5536_vsm.h>
  25. enum {
  26. CS5536_FUNC_START = -1,
  27. CS5536_ISA_FUNC,
  28. reserved_func,
  29. CS5536_IDE_FUNC,
  30. CS5536_ACC_FUNC,
  31. CS5536_OHCI_FUNC,
  32. CS5536_EHCI_FUNC,
  33. CS5536_FUNC_END,
  34. };
  35. static const cs5536_pci_vsm_write vsm_conf_write[] = {
  36. [CS5536_ISA_FUNC] = pci_isa_write_reg,
  37. [reserved_func] = NULL,
  38. [CS5536_IDE_FUNC] = pci_ide_write_reg,
  39. [CS5536_ACC_FUNC] = pci_acc_write_reg,
  40. [CS5536_OHCI_FUNC] = pci_ohci_write_reg,
  41. [CS5536_EHCI_FUNC] = pci_ehci_write_reg,
  42. };
  43. static const cs5536_pci_vsm_read vsm_conf_read[] = {
  44. [CS5536_ISA_FUNC] = pci_isa_read_reg,
  45. [reserved_func] = NULL,
  46. [CS5536_IDE_FUNC] = pci_ide_read_reg,
  47. [CS5536_ACC_FUNC] = pci_acc_read_reg,
  48. [CS5536_OHCI_FUNC] = pci_ohci_read_reg,
  49. [CS5536_EHCI_FUNC] = pci_ehci_read_reg,
  50. };
  51. /*
  52. * write to PCI config space and transfer it to MSR write.
  53. */
  54. void cs5536_pci_conf_write4(int function, int reg, u32 value)
  55. {
  56. if ((function <= CS5536_FUNC_START) || (function >= CS5536_FUNC_END))
  57. return;
  58. if ((reg < 0) || (reg > 0x100) || ((reg & 0x03) != 0))
  59. return;
  60. if (vsm_conf_write[function] != NULL)
  61. vsm_conf_write[function](reg, value);
  62. }
  63. /*
  64. * read PCI config space and transfer it to MSR access.
  65. */
  66. u32 cs5536_pci_conf_read4(int function, int reg)
  67. {
  68. u32 data = 0;
  69. if ((function <= CS5536_FUNC_START) || (function >= CS5536_FUNC_END))
  70. return 0;
  71. if ((reg < 0) || ((reg & 0x03) != 0))
  72. return 0;
  73. if (reg > 0x100)
  74. return 0xffffffff;
  75. if (vsm_conf_read[function] != NULL)
  76. data = vsm_conf_read[function](reg);
  77. return data;
  78. }