pci.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * (C) Copyright 2003
  3. * AMIRIX Systems Inc.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <ppc4xx.h>
  25. #include <asm/processor.h>
  26. #include <pci.h>
  27. #define PCI_MEM_82559ER_CSR_BASE 0x30200000
  28. #define PCI_IO_82559ER_CSR_BASE 0x40000200
  29. /** AP1100 specific values */
  30. #define PSII_BASE 0x30000000 /**< PowerSpan II dual bridge local bus register address */
  31. #define PSII_CONFIG_ADDR 0x30000290 /**< PowerSpan II Configuration Cycle Address configuration register */
  32. #define PSII_CONFIG_DATA 0x30000294 /**< PowerSpan II Configuration Cycle Data register. */
  33. #define PSII_CONFIG_DEST_PCI2 0x01000000 /**< PowerSpan II configuration cycle destination selection, set for PCI2 bus */
  34. #define PSII_PCI_MEM_BASE 0x30200000 /**< Local Bus address for start of PCI memory space on PCI2 bus. */
  35. #define PSII_PCI_MEM_SIZE 0x1BE00000 /**< PCI Memory space about 510 Meg. */
  36. #define AP1000_SYS_MEM_START 0x00000000 /**< System memory starts at 0. */
  37. #define AP1000_SYS_MEM_SIZE 0x08000000 /**< System memory is 128 Meg. */
  38. /* static int G_verbosity_level = 1; */
  39. #define G_verbosity_level 1
  40. void write1 (unsigned long addr, unsigned char val)
  41. {
  42. volatile unsigned char *p = (volatile unsigned char *) addr;
  43. if (G_verbosity_level > 1)
  44. printf ("write1: addr=%08x val=%02x\n", (unsigned int) addr,
  45. val);
  46. *p = val;
  47. asm ("eieio");
  48. }
  49. unsigned char read1 (unsigned long addr)
  50. {
  51. unsigned char val;
  52. volatile unsigned char *p = (volatile unsigned char *) addr;
  53. if (G_verbosity_level > 1)
  54. printf ("read1: addr=%08x ", (unsigned int) addr);
  55. val = *p;
  56. asm ("eieio");
  57. if (G_verbosity_level > 1)
  58. printf ("val=%08x\n", val);
  59. return val;
  60. }
  61. void write2 (unsigned long addr, unsigned short val)
  62. {
  63. volatile unsigned short *p = (volatile unsigned short *) addr;
  64. if (G_verbosity_level > 1)
  65. printf ("write2: addr=%08x val=%04x -> *p=%04x\n",
  66. (unsigned int) addr, val,
  67. ((val & 0xFF00) >> 8) | ((val & 0x00FF) << 8));
  68. *p = ((val & 0xFF00) >> 8) | ((val & 0x00FF) << 8);
  69. asm ("eieio");
  70. }
  71. unsigned short read2 (unsigned long addr)
  72. {
  73. unsigned short val;
  74. volatile unsigned short *p = (volatile unsigned short *) addr;
  75. if (G_verbosity_level > 1)
  76. printf ("read2: addr=%08x ", (unsigned int) addr);
  77. val = *p;
  78. val = ((val & 0xFF00) >> 8) | ((val & 0x00FF) << 8);
  79. asm ("eieio");
  80. if (G_verbosity_level > 1)
  81. printf ("*p=%04x -> val=%04x\n",
  82. ((val & 0xFF00) >> 8) | ((val & 0x00FF) << 8), val);
  83. return val;
  84. }
  85. void write4 (unsigned long addr, unsigned long val)
  86. {
  87. volatile unsigned long *p = (volatile unsigned long *) addr;
  88. if (G_verbosity_level > 1)
  89. printf ("write4: addr=%08x val=%08x -> *p=%08x\n",
  90. (unsigned int) addr, (unsigned int) val,
  91. (unsigned int) (((val & 0xFF000000) >> 24) |
  92. ((val & 0x000000FF) << 24) |
  93. ((val & 0x00FF0000) >> 8) |
  94. ((val & 0x0000FF00) << 8)));
  95. *p = ((val & 0xFF000000) >> 24) | ((val & 0x000000FF) << 24) |
  96. ((val & 0x00FF0000) >> 8) | ((val & 0x0000FF00) << 8);
  97. asm ("eieio");
  98. }
  99. unsigned long read4 (unsigned long addr)
  100. {
  101. unsigned long val;
  102. volatile unsigned long *p = (volatile unsigned long *) addr;
  103. if (G_verbosity_level > 1)
  104. printf ("read4: addr=%08x", (unsigned int) addr);
  105. val = *p;
  106. val = ((val & 0xFF000000) >> 24) | ((val & 0x000000FF) << 24) |
  107. ((val & 0x00FF0000) >> 8) | ((val & 0x0000FF00) << 8);
  108. asm ("eieio");
  109. if (G_verbosity_level > 1)
  110. printf ("*p=%04x -> val=%04x\n",
  111. (unsigned int) (((val & 0xFF000000) >> 24) |
  112. ((val & 0x000000FF) << 24) |
  113. ((val & 0x00FF0000) >> 8) |
  114. ((val & 0x0000FF00) << 8)),
  115. (unsigned int) val);
  116. return val;
  117. }
  118. void write4be (unsigned long addr, unsigned long val)
  119. {
  120. volatile unsigned long *p = (volatile unsigned long *) addr;
  121. if (G_verbosity_level > 1)
  122. printf ("write4: addr=%08x val=%08x\n", (unsigned int) addr,
  123. (unsigned int) val);
  124. *p = val;
  125. asm ("eieio");
  126. }
  127. /** One byte configuration write on PSII.
  128. * Currently fixes destination PCI bus to PCI2, onboard
  129. * pci.
  130. * @param hose PCI Host controller information. Ignored.
  131. * @param dev Encoded PCI device/Bus and Function value.
  132. * @param reg PCI Configuration register number.
  133. * @param val Address of location for received byte.
  134. * @return Always Zero.
  135. */
  136. static int psII_read_config_byte (struct pci_controller *hose,
  137. pci_dev_t dev, int reg, u8 * val)
  138. {
  139. write4be (PSII_CONFIG_ADDR, PSII_CONFIG_DEST_PCI2 | /* Operate on PCI2 bus interface . */
  140. (PCI_BUS (dev) << 16) | (PCI_DEV (dev) << 11) | (PCI_FUNC (dev) << 8) | ((reg & 0xFF) & ~3)); /* Configuation cycle type 0 */
  141. *val = read1 (PSII_CONFIG_DATA + (reg & 0x03));
  142. return (0);
  143. }
  144. /** One byte configuration write on PSII.
  145. * Currently fixes destination bus to PCI2, onboard
  146. * pci.
  147. * @param hose PCI Host controller information. Ignored.
  148. * @param dev Encoded PCI device/Bus and Function value.
  149. * @param reg PCI Configuration register number.
  150. * @param val Output byte.
  151. * @return Always Zero.
  152. */
  153. static int psII_write_config_byte (struct pci_controller *hose,
  154. pci_dev_t dev, int reg, u8 val)
  155. {
  156. write4be (PSII_CONFIG_ADDR, PSII_CONFIG_DEST_PCI2 | /* Operate on PCI2 bus interface . */
  157. (PCI_BUS (dev) << 16) | (PCI_DEV (dev) << 11) | (PCI_FUNC (dev) << 8) | ((reg & 0xFF) & ~3)); /* Configuation cycle type 0 */
  158. write1 (PSII_CONFIG_DATA + (reg & 0x03), (unsigned char) val);
  159. return (0);
  160. }
  161. /** One word (16 bit) configuration read on PSII.
  162. * Currently fixes destination PCI bus to PCI2, onboard
  163. * pci.
  164. * @param hose PCI Host controller information. Ignored.
  165. * @param dev Encoded PCI device/Bus and Function value.
  166. * @param reg PCI Configuration register number.
  167. * @param val Address of location for received word.
  168. * @return Always Zero.
  169. */
  170. static int psII_read_config_word (struct pci_controller *hose,
  171. pci_dev_t dev, int reg, u16 * val)
  172. {
  173. write4be (PSII_CONFIG_ADDR, PSII_CONFIG_DEST_PCI2 | /* Operate on PCI2 bus interface . */
  174. (PCI_BUS (dev) << 16) | (PCI_DEV (dev) << 11) | (PCI_FUNC (dev) << 8) | ((reg & 0xFF) & ~3)); /* Configuation cycle type 0 */
  175. *val = read2 (PSII_CONFIG_DATA + (reg & 0x03));
  176. return (0);
  177. }
  178. /** One word (16 bit) configuration write on PSII.
  179. * Currently fixes destination bus to PCI2, onboard
  180. * pci.
  181. * @param hose PCI Host controller information. Ignored.
  182. * @param dev Encoded PCI device/Bus and Function value.
  183. * @param reg PCI Configuration register number.
  184. * @param val Output word.
  185. * @return Always Zero.
  186. */
  187. static int psII_write_config_word (struct pci_controller *hose,
  188. pci_dev_t dev, int reg, u16 val)
  189. {
  190. write4be (PSII_CONFIG_ADDR, PSII_CONFIG_DEST_PCI2 | /* Operate on PCI2 bus interface . */
  191. (PCI_BUS (dev) << 16) | (PCI_DEV (dev) << 11) | (PCI_FUNC (dev) << 8) | ((reg & 0xFF) & ~3)); /* Configuation cycle type 0 */
  192. write2 (PSII_CONFIG_DATA + (reg & 0x03), (unsigned short) val);
  193. return (0);
  194. }
  195. /** One DWord (32 bit) configuration read on PSII.
  196. * Currently fixes destination PCI bus to PCI2, onboard
  197. * pci.
  198. * @param hose PCI Host controller information. Ignored.
  199. * @param dev Encoded PCI device/Bus and Function value.
  200. * @param reg PCI Configuration register number.
  201. * @param val Address of location for received byte.
  202. * @return Always Zero.
  203. */
  204. static int psII_read_config_dword (struct pci_controller *hose,
  205. pci_dev_t dev, int reg, u32 * val)
  206. {
  207. write4be (PSII_CONFIG_ADDR, PSII_CONFIG_DEST_PCI2 | /* Operate on PCI2 bus interface . */
  208. (PCI_BUS (dev) << 16) | (PCI_DEV (dev) << 11) | (PCI_FUNC (dev) << 8) | ((reg & 0xFF) & ~3)); /* Configuation cycle type 0 */
  209. *val = read4 (PSII_CONFIG_DATA);
  210. return (0);
  211. }
  212. /** One DWord (32 bit) configuration write on PSII.
  213. * Currently fixes destination bus to PCI2, onboard
  214. * pci.
  215. * @param hose PCI Host controller information. Ignored.
  216. * @param dev Encoded PCI device/Bus and Function value.
  217. * @param reg PCI Configuration register number.
  218. * @param val Output Dword.
  219. * @return Always Zero.
  220. */
  221. static int psII_write_config_dword (struct pci_controller *hose,
  222. pci_dev_t dev, int reg, u32 val)
  223. {
  224. write4be (PSII_CONFIG_ADDR, PSII_CONFIG_DEST_PCI2 | /* Operate on PCI2 bus interface . */
  225. (PCI_BUS (dev) << 16) | (PCI_DEV (dev) << 11) | (PCI_FUNC (dev) << 8) | ((reg & 0xFF) & ~3)); /* Configuation cycle type 0 */
  226. write4 (PSII_CONFIG_DATA, (unsigned long) val);
  227. return (0);
  228. }
  229. static struct pci_config_table ap1000_config_table[] = {
  230. #ifdef CONFIG_AP1000
  231. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  232. PCI_BUS (CFG_ETH_DEV_FN), PCI_DEV (CFG_ETH_DEV_FN),
  233. PCI_FUNC (CFG_ETH_DEV_FN),
  234. pci_cfgfunc_config_device,
  235. {CFG_ETH_IOBASE, CFG_ETH_MEMBASE,
  236. PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER}},
  237. #endif
  238. {}
  239. };
  240. static struct pci_controller psII_hose = {
  241. config_table:ap1000_config_table,
  242. };
  243. void pci_init_board (void)
  244. {
  245. struct pci_controller *hose = &psII_hose;
  246. /*
  247. * Register the hose
  248. */
  249. hose->first_busno = 0;
  250. hose->last_busno = 0xff;
  251. /* System memory space */
  252. pci_set_region (hose->regions + 0,
  253. AP1000_SYS_MEM_START, AP1000_SYS_MEM_START,
  254. AP1000_SYS_MEM_SIZE,
  255. PCI_REGION_MEM | PCI_REGION_MEMORY);
  256. /* PCI Memory space */
  257. pci_set_region (hose->regions + 1,
  258. PSII_PCI_MEM_BASE, PSII_PCI_MEM_BASE,
  259. PSII_PCI_MEM_SIZE, PCI_REGION_MEM);
  260. /* No IO Memory space - for now */
  261. pci_set_ops (hose,
  262. psII_read_config_byte,
  263. psII_read_config_word,
  264. psII_read_config_dword,
  265. psII_write_config_byte,
  266. psII_write_config_word, psII_write_config_dword);
  267. hose->region_count = 2;
  268. pci_register_hose (hose);
  269. hose->last_busno = pci_hose_scan (hose);
  270. }