pci_etherboot.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:9k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * This program is free software; you can redistribute it and/or
  3.  * modify it under the terms of the GNU General Public License as
  4.  * published by the Free Software Foundation; either version 2, or (at
  5.  * your option) any later version.
  6.  */
  7. #include <linux/config.h>
  8. #include <asm/galileo-boards/evb64120A/pci.h>
  9. #include <asm/byteorder.h>
  10. #include "etherboot.h"
  11. #include "pci_etherboot.h"
  12. #include "galileo_port.h"
  13. #define MAX_PCI_DEVS 10
  14. PCI_DEVICE pci0_devices[MAX_PCI_DEVS];
  15. PCI_DEVICE pci1_devices[MAX_PCI_DEVS];
  16. static int pci_range_ck(unsigned char bus, unsigned char dev)
  17. {
  18. if ((bus == 0) && (dev >= 0) && (dev < 30))
  19. return 0; // Bus/Device Number OK
  20. return -1; // Bus/Device Number not OK
  21. }
  22. /********************************************************************
  23.  * pcibios_(read/write)_config_(byte/word/dword)
  24.  *
  25.  *Inputs :
  26.  *bus - bus number
  27.  *dev - device number
  28.  *offset - register offset in the configuration space
  29.  *val - value to be written / read
  30.  *
  31.  *Outputs :
  32.  *Sucees/Failure
  33.  *********************************************************************/
  34. #define PCI_CFG_DATA    ((volatile unsigned long *)0xb4000cfc)
  35. #define PCI_CFG_CTRL    ((volatile unsigned long *)0xb4000cf8)
  36. #define PCI_CFG_SET(dev,fun,off) 
  37.         ((*PCI_CFG_CTRL) = cpu_to_le32((0x80000000 | ((dev)<<11) | ((fun)<<8) | (off))))
  38. int pcibios_read_config_dword(unsigned char bus, unsigned char dev,
  39.       unsigned char offset, unsigned int *val)
  40. {
  41. if (offset & 0x3) {
  42. return PCIBIOS_BAD_REGISTER_NUMBER;
  43. }
  44. if (pci_range_ck(bus, dev)) {
  45. *val = 0xFFFFFFFF;
  46. return PCIBIOS_DEVICE_NOT_FOUND;
  47. }
  48. PCI_CFG_SET(dev, 0, offset);
  49. if (dev != 0) {
  50. *val = *PCI_CFG_DATA;
  51. } else {
  52. *val = cpu_to_le32(*PCI_CFG_DATA);
  53. }
  54. return PCIBIOS_SUCCESSFUL;
  55. }
  56. int pcibios_read_config_word(unsigned char bus, unsigned char dev,
  57.      unsigned char offset, unsigned short *val)
  58. {
  59. if (offset & 0x1)
  60. return PCIBIOS_BAD_REGISTER_NUMBER;
  61. if (pci_range_ck(bus, dev)) {
  62. *val = 0xffff;
  63. return PCIBIOS_DEVICE_NOT_FOUND;
  64. }
  65. PCI_CFG_SET(dev, 0, (offset & ~0x3));
  66. if (dev != 0) {
  67. *val = *PCI_CFG_DATA >> ((offset & 3) * 8);
  68. } else {
  69. *val = cpu_to_le32(*PCI_CFG_DATA) >> ((offset & 3) * 8);
  70. }
  71. return PCIBIOS_SUCCESSFUL;
  72. }
  73. int pcibios_read_config_byte(unsigned char bus, unsigned char dev,
  74.      unsigned char offset, unsigned char *val)
  75. {
  76. if (pci_range_ck(bus, dev)) {
  77. *val = 0xff;
  78. return PCIBIOS_DEVICE_NOT_FOUND;
  79. }
  80. PCI_CFG_SET(dev, 0, (offset & ~0x3));
  81. if (dev != 0) {
  82. *val = *PCI_CFG_DATA >> ((offset & 3) * 8);
  83. } else {
  84. *val = cpu_to_le32(*PCI_CFG_DATA >> ((offset & 3) * 8));
  85. }
  86. return PCIBIOS_SUCCESSFUL;
  87. }
  88. int pcibios_write_config_dword(unsigned char bus, unsigned char dev,
  89.        unsigned char offset, unsigned int val)
  90. {
  91. if (offset & 0x3)
  92. return PCIBIOS_BAD_REGISTER_NUMBER;
  93. if (pci_range_ck(bus, dev))
  94. return PCIBIOS_DEVICE_NOT_FOUND;
  95. PCI_CFG_SET(dev, 0, offset);
  96. if (dev != 0) {
  97. *PCI_CFG_DATA = val;
  98. } else {
  99. *PCI_CFG_DATA = cpu_to_le32(val);
  100. }
  101. return PCIBIOS_SUCCESSFUL;
  102. }
  103. int pcibios_write_config_word(unsigned char bus, unsigned char dev,
  104.       unsigned char offset, unsigned short val)
  105. {
  106. unsigned long tmp;
  107. if (offset & 0x1)
  108. return PCIBIOS_BAD_REGISTER_NUMBER;
  109. if (pci_range_ck(bus, dev))
  110. return PCIBIOS_DEVICE_NOT_FOUND;
  111. PCI_CFG_SET(dev, 0, (offset & ~0x3));
  112. if (dev != 0) {
  113. tmp = *PCI_CFG_DATA;
  114. } else {
  115. tmp = cpu_to_le32(*PCI_CFG_DATA);
  116. }
  117. tmp &= ~(0xffff << ((offset & 0x3) * 8));
  118. tmp |= (val << ((offset & 0x3) * 8));
  119. if (dev != 0) {
  120. *PCI_CFG_DATA = tmp;
  121. } else {
  122. *PCI_CFG_DATA = cpu_to_le32(tmp);
  123. }
  124. return PCIBIOS_SUCCESSFUL;
  125. }
  126. int pcibios_write_config_byte(unsigned char bus, unsigned char dev,
  127.       unsigned char offset, unsigned char val)
  128. {
  129. unsigned long tmp;
  130. if (pci_range_ck(bus, dev))
  131. return PCIBIOS_DEVICE_NOT_FOUND;
  132. PCI_CFG_SET(dev, 0, (offset & ~0x3));
  133. if (dev != 0) {
  134. tmp = *PCI_CFG_DATA;
  135. } else {
  136. tmp = cpu_to_le32(*PCI_CFG_DATA);
  137. }
  138. tmp &= ~(0xff << ((offset & 0x3) * 8));
  139. tmp |= (val << ((offset & 0x3) * 8));
  140. *PCI_CFG_DATA = cpu_to_le32(tmp);
  141. return PCIBIOS_SUCCESSFUL;
  142. }
  143. /********************************************************************
  144.  * eth_pci_init - Fill pci_devi
  145.  *
  146.  *Inputs :
  147.  *bus - bus number
  148.  *dev - device number
  149.  *offset - register offset in the configuration space
  150.  *val - value to be written / read
  151.  *
  152.  *Outputs :
  153.  *Sucees/Failure
  154.  *********************************************************************/
  155. void eth_pci_init(struct pci_device *pcidev)
  156. {
  157. int i, count;
  158. pcibios_write_config_word(0, 0, 4, 0x7);
  159. pcibios_write_config_dword(0, 8, BAR0, 0x12000000);
  160. pcibios_write_config_dword(0, 8, BAR1, 0x10000001);
  161. pcibios_write_config_dword(0, 8, BAR2, 0x12100000);
  162. strcpy(pci0_devices[0].type, "Network Controller");
  163. pci0_devices[0].deviceNum = 8;
  164. pci0_devices[0].venID = 0x8086;
  165. pci0_devices[0].deviceID = 0x1229;
  166. pci0_devices[0].bar0Base = 0x12000000;
  167. pci0_devices[0].bar0Size = 0x00001000;
  168. pci0_devices[0].bar0Type = 0;
  169. pci0_devices[0].bar1Base = 0x10000000;
  170. pci0_devices[0].bar1Size = 0x40;
  171. pci0_devices[0].bar1Type = 1;
  172. pci0_devices[0].bar2Base = 0x12100000;
  173. pci0_devices[0].bar2Size = 0x00100000;
  174. pci0_devices[0].bar2Type = 0;
  175. for (i = 0; pcidev[i].vendor != 0; i++) {
  176. /* Look for device in PCI0 first */
  177. for (count = 0; count < MAX_PCI_DEVS; count++) {
  178. if ((pci0_devices[count].type[0] != 0)
  179.     && ((unsigned short) pci0_devices[count].
  180. venID == (unsigned short) pcidev[i].vendor)
  181.     && ((unsigned short) pci0_devices[count].
  182. deviceID ==
  183. (unsigned short) pcidev[i].dev_id)) {
  184. if ((pci0_devices[count].bar0Type == 1)
  185.     && (pci0_devices[count].bar0Size != 0))
  186. pcidev[i].ioaddr =
  187.     pci0_devices[count].bar0Base;
  188. if ((pci0_devices[count].bar1Type == 1)
  189.     && (pci0_devices[count].bar1Size != 0))
  190. pcidev[i].ioaddr =
  191.     pci0_devices[count].bar1Base;
  192. if ((pci0_devices[count].bar2Type == 1)
  193.     && (pci0_devices[count].bar2Size != 0))
  194. pcidev[i].ioaddr =
  195.     pci0_devices[count].bar2Base;
  196. if ((pci0_devices[count].bar3Type == 1)
  197.     && (pci0_devices[count].bar3Size != 0))
  198. pcidev[i].ioaddr =
  199.     pci0_devices[count].bar3Base;
  200. if ((pci0_devices[count].bar4Type == 1)
  201.     && (pci0_devices[count].bar4Size != 0))
  202. pcidev[i].ioaddr =
  203.     pci0_devices[count].bar4Base;
  204. if ((pci0_devices[count].bar5Type == 1)
  205.     && (pci0_devices[count].bar5Size != 0))
  206. pcidev[i].ioaddr =
  207.     pci0_devices[count].bar5Base;
  208. if ((pci0_devices[count].bar0Type == 0)
  209.     && (pci0_devices[count].bar0Size != 0))
  210. pcidev[i].membase =
  211.     pci0_devices[count].bar0Base;
  212. if ((pci0_devices[count].bar1Type == 0)
  213.     && (pci0_devices[count].bar1Size != 0))
  214. pcidev[i].membase =
  215.     pci0_devices[count].bar1Base;
  216. if ((pci0_devices[count].bar2Type == 0)
  217.     && (pci0_devices[count].bar2Size != 0))
  218. pcidev[i].membase =
  219.     pci0_devices[count].bar2Base;
  220. if ((pci0_devices[count].bar3Type == 0)
  221.     && (pci0_devices[count].bar3Size != 0))
  222. pcidev[i].membase =
  223.     pci0_devices[count].bar3Base;
  224. if ((pci0_devices[count].bar4Type == 0)
  225.     && (pci0_devices[count].bar4Size != 0))
  226. pcidev[i].membase =
  227.     pci0_devices[count].bar4Base;
  228. if ((pci0_devices[count].bar5Type == 0)
  229.     && (pci0_devices[count].bar5Size != 0))
  230. pcidev[i].membase =
  231.     pci0_devices[count].bar5Base;
  232. pcidev[i].bus = 0;
  233. pcidev[i].devfn =
  234.     pci0_devices[count].deviceNum;
  235. }
  236. #ifdef CONFIG_EVB_PCI1
  237. if ((pci1_devices[count].type[0] != 0)
  238.     && (pci1_devices[count].venID ==
  239. pcidev[i].vendor)
  240.     && (pci1_devices[count].deviceID ==
  241. pcidev[i].dev_id)) {
  242. if ((pci1_devices[count].bar0Type == 1)
  243.     && (pci1_devices[count].bar0Size != 0))
  244. pcidev[i].ioaddr =
  245.     pci1_devices[count].bar0Base;
  246. if ((pci1_devices[count].bar1Type == 1)
  247.     && (pci1_devices[count].bar1Size != 0))
  248. pcidev[i].ioaddr =
  249.     pci1_devices[count].bar1Base;
  250. if ((pci1_devices[count].bar2Type == 1)
  251.     && (pci1_devices[count].bar2Size != 0))
  252. pcidev[i].ioaddr =
  253.     pci1_devices[count].bar2Base;
  254. if ((pci1_devices[count].bar3Type == 1)
  255.     && (pci1_devices[count].bar3Size != 0))
  256. pcidev[i].ioaddr =
  257.     pci1_devices[count].bar3Base;
  258. if ((pci1_devices[count].bar4Type == 1)
  259.     && (pci1_devices[count].bar4Size != 0))
  260. pcidev[i].ioaddr =
  261.     pci1_devices[count].bar4Base;
  262. if ((pci1_devices[count].bar5Type == 1)
  263.     && (pci1_devices[count].bar5Size != 0))
  264. pcidev[i].ioaddr =
  265.     pci1_devices[count].bar5Base;
  266. if ((pci1_devices[count].bar0Type == 0)
  267.     && (pci1_devices[count].bar0Size != 0))
  268. pcidev[i].membase =
  269.     pci1_devices[count].bar0Base;
  270. if ((pci1_devices[count].bar1Type == 0)
  271.     && (pci1_devices[count].bar1Size != 0))
  272. pcidev[i].membase =
  273.     pci1_devices[count].bar1Base;
  274. if ((pci1_devices[count].bar2Type == 0)
  275.     && (pci1_devices[count].bar2Size != 0))
  276. pcidev[i].membase =
  277.     pci1_devices[count].bar2Base;
  278. if ((pci1_devices[count].bar3Type == 0)
  279.     && (pci1_devices[count].bar3Size != 0))
  280. pcidev[i].membase =
  281.     pci1_devices[count].bar3Base;
  282. if ((pci1_devices[count].bar4Type == 0)
  283.     && (pci1_devices[count].bar4Size != 0))
  284. pcidev[i].membase =
  285.     pci1_devices[count].bar4Base;
  286. if ((pci1_devices[count].bar5Type == 0)
  287.     && (pci1_devices[count].bar5Size != 0))
  288. pcidev[i].membase =
  289.     pci1_devices[count].bar5Base;
  290. pcidev[i].bus = 1;
  291. pcidev[i].devfn =
  292.     pci1_devices[count].deviceNum;
  293. }
  294. #endif
  295. }
  296. }
  297. }