ht.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /*
  2. * Copyright 2003 PMC-Sierra
  3. * Author: Manish Lachwani (lachwani@pmc-sierra.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. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  11. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  13. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  14. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  15. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  16. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  17. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  18. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  19. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. *
  21. * You should have received a copy of the GNU General Public License along
  22. * with this program; if not, write to the Free Software Foundation, Inc.,
  23. * 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. #include <linux/config.h>
  26. #include <linux/types.h>
  27. #include <linux/pci.h>
  28. #include <linux/kernel.h>
  29. #include <linux/slab.h>
  30. #include <linux/version.h>
  31. #include <asm/pci.h>
  32. #include <asm/io.h>
  33. #include <linux/init.h>
  34. #include <asm/titan_dep.h>
  35. #ifdef CONFIG_HYPERTRANSPORT
  36. /*
  37. * This function check if the Hypertransport Link Initialization completed. If
  38. * it did, then proceed further with scanning bus #2
  39. */
  40. static __inline__ int check_titan_htlink(void)
  41. {
  42. u32 val;
  43. val = *(volatile uint32_t *)(RM9000x2_HTLINK_REG);
  44. if (val & 0x00000020)
  45. /* HT Link Initialization completed */
  46. return 1;
  47. else
  48. return 0;
  49. }
  50. static int titan_ht_config_read_dword(struct pci_dev *device,
  51. int offset, u32* val)
  52. {
  53. int dev, bus, func;
  54. uint32_t address_reg, data_reg;
  55. uint32_t address;
  56. bus = device->bus->number;
  57. dev = PCI_SLOT(device->devfn);
  58. func = PCI_FUNC(device->devfn);
  59. /* XXX Need to change the Bus # */
  60. if (bus > 2)
  61. address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
  62. 0x80000000 | 0x1;
  63. else
  64. address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
  65. address_reg = RM9000x2_OCD_HTCFGA;
  66. data_reg = RM9000x2_OCD_HTCFGD;
  67. RM9K_WRITE(address_reg, address);
  68. RM9K_READ(data_reg, val);
  69. return PCIBIOS_SUCCESSFUL;
  70. }
  71. static int titan_ht_config_read_word(struct pci_dev *device,
  72. int offset, u16* val)
  73. {
  74. int dev, bus, func;
  75. uint32_t address_reg, data_reg;
  76. uint32_t address;
  77. bus = device->bus->number;
  78. dev = PCI_SLOT(device->devfn);
  79. func = PCI_FUNC(device->devfn);
  80. /* XXX Need to change the Bus # */
  81. if (bus > 2)
  82. address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
  83. 0x80000000 | 0x1;
  84. else
  85. address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
  86. address_reg = RM9000x2_OCD_HTCFGA;
  87. data_reg = RM9000x2_OCD_HTCFGD;
  88. if ((offset & 0x3) == 0)
  89. offset = 0x2;
  90. else
  91. offset = 0x0;
  92. RM9K_WRITE(address_reg, address);
  93. RM9K_READ_16(data_reg + offset, val);
  94. return PCIBIOS_SUCCESSFUL;
  95. }
  96. u32 longswap(unsigned long l)
  97. {
  98. unsigned char b1,b2,b3,b4;
  99. b1 = l&255;
  100. b2 = (l>>8)&255;
  101. b3 = (l>>16)&255;
  102. b4 = (l>>24)&255;
  103. return ((b1<<24) + (b2<<16) + (b3<<8) + b4);
  104. }
  105. static int titan_ht_config_read_byte(struct pci_dev *device,
  106. int offset, u8* val)
  107. {
  108. int dev, bus, func;
  109. uint32_t address_reg, data_reg;
  110. uint32_t address;
  111. int offset1;
  112. bus = device->bus->number;
  113. dev = PCI_SLOT(device->devfn);
  114. func = PCI_FUNC(device->devfn);
  115. /* XXX Need to change the Bus # */
  116. if (bus > 2)
  117. address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
  118. 0x80000000 | 0x1;
  119. else
  120. address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
  121. address_reg = RM9000x2_OCD_HTCFGA;
  122. data_reg = RM9000x2_OCD_HTCFGD;
  123. RM9K_WRITE(address_reg, address);
  124. if ((offset & 0x3) == 0) {
  125. offset1 = 0x3;
  126. }
  127. if ((offset & 0x3) == 1) {
  128. offset1 = 0x2;
  129. }
  130. if ((offset & 0x3) == 2) {
  131. offset1 = 0x1;
  132. }
  133. if ((offset & 0x3) == 3) {
  134. offset1 = 0x0;
  135. }
  136. RM9K_READ_8(data_reg + offset1, val);
  137. return PCIBIOS_SUCCESSFUL;
  138. }
  139. static int titan_ht_config_write_dword(struct pci_dev *device,
  140. int offset, u8 val)
  141. {
  142. int dev, bus, func;
  143. uint32_t address_reg, data_reg;
  144. uint32_t address;
  145. bus = device->bus->number;
  146. dev = PCI_SLOT(device->devfn);
  147. func = PCI_FUNC(device->devfn);
  148. /* XXX Need to change the Bus # */
  149. if (bus > 2)
  150. address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
  151. 0x80000000 | 0x1;
  152. else
  153. address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
  154. address_reg = RM9000x2_OCD_HTCFGA;
  155. data_reg = RM9000x2_OCD_HTCFGD;
  156. RM9K_WRITE(address_reg, address);
  157. RM9K_WRITE(data_reg, val);
  158. return PCIBIOS_SUCCESSFUL;
  159. }
  160. static int titan_ht_config_write_word(struct pci_dev *device,
  161. int offset, u8 val)
  162. {
  163. int dev, bus, func;
  164. uint32_t address_reg, data_reg;
  165. uint32_t address;
  166. bus = device->bus->number;
  167. dev = PCI_SLOT(device->devfn);
  168. func = PCI_FUNC(device->devfn);
  169. /* XXX Need to change the Bus # */
  170. if (bus > 2)
  171. address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
  172. 0x80000000 | 0x1;
  173. else
  174. address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
  175. address_reg = RM9000x2_OCD_HTCFGA;
  176. data_reg = RM9000x2_OCD_HTCFGD;
  177. if ((offset & 0x3) == 0)
  178. offset = 0x2;
  179. else
  180. offset = 0x0;
  181. RM9K_WRITE(address_reg, address);
  182. RM9K_WRITE_16(data_reg + offset, val);
  183. return PCIBIOS_SUCCESSFUL;
  184. }
  185. static int titan_ht_config_write_byte(struct pci_dev *device,
  186. int offset, u8 val)
  187. {
  188. int dev, bus, func;
  189. uint32_t address_reg, data_reg;
  190. uint32_t address;
  191. int offset1;
  192. bus = device->bus->number;
  193. dev = PCI_SLOT(device->devfn);
  194. func = PCI_FUNC(device->devfn);
  195. /* XXX Need to change the Bus # */
  196. if (bus > 2)
  197. address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
  198. 0x80000000 | 0x1;
  199. else
  200. address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
  201. address_reg = RM9000x2_OCD_HTCFGA;
  202. data_reg = RM9000x2_OCD_HTCFGD;
  203. RM9K_WRITE(address_reg, address);
  204. if ((offset & 0x3) == 0) {
  205. offset1 = 0x3;
  206. }
  207. if ((offset & 0x3) == 1) {
  208. offset1 = 0x2;
  209. }
  210. if ((offset & 0x3) == 2) {
  211. offset1 = 0x1;
  212. }
  213. if ((offset & 0x3) == 3) {
  214. offset1 = 0x0;
  215. }
  216. RM9K_WRITE_8(data_reg + offset1, val);
  217. return PCIBIOS_SUCCESSFUL;
  218. }
  219. static void titan_pcibios_set_master(struct pci_dev *dev)
  220. {
  221. u16 cmd;
  222. int bus = dev->bus->number;
  223. if (check_titan_htlink())
  224. titan_ht_config_read_word(dev, PCI_COMMAND, &cmd);
  225. cmd |= PCI_COMMAND_MASTER;
  226. if (check_titan_htlink())
  227. titan_ht_config_write_word(dev, PCI_COMMAND, cmd);
  228. }
  229. int pcibios_enable_resources(struct pci_dev *dev)
  230. {
  231. u16 cmd, old_cmd;
  232. u8 tmp1;
  233. int idx;
  234. struct resource *r;
  235. int bus = dev->bus->number;
  236. if (check_titan_htlink())
  237. titan_ht_config_read_word(dev, PCI_COMMAND, &cmd);
  238. old_cmd = cmd;
  239. for (idx = 0; idx < 6; idx++) {
  240. r = &dev->resource[idx];
  241. if (!r->start && r->end) {
  242. printk(KERN_ERR
  243. "PCI: Device %s not available because of "
  244. "resource collisions\n", pci_name(dev));
  245. return -EINVAL;
  246. }
  247. if (r->flags & IORESOURCE_IO)
  248. cmd |= PCI_COMMAND_IO;
  249. if (r->flags & IORESOURCE_MEM)
  250. cmd |= PCI_COMMAND_MEMORY;
  251. }
  252. if (cmd != old_cmd) {
  253. if (check_titan_htlink())
  254. titan_ht_config_write_word(dev, PCI_COMMAND, cmd);
  255. }
  256. if (check_titan_htlink())
  257. titan_ht_config_read_byte(dev, PCI_CACHE_LINE_SIZE, &tmp1);
  258. if (tmp1 != 8) {
  259. printk(KERN_WARNING "PCI setting cache line size to 8 from "
  260. "%d\n", tmp1);
  261. }
  262. if (check_titan_htlink())
  263. titan_ht_config_write_byte(dev, PCI_CACHE_LINE_SIZE, 8);
  264. if (check_titan_htlink())
  265. titan_ht_config_read_byte(dev, PCI_LATENCY_TIMER, &tmp1);
  266. if (tmp1 < 32 || tmp1 == 0xff) {
  267. printk(KERN_WARNING "PCI setting latency timer to 32 from %d\n",
  268. tmp1);
  269. }
  270. if (check_titan_htlink())
  271. titan_ht_config_write_byte(dev, PCI_LATENCY_TIMER, 32);
  272. return 0;
  273. }
  274. int pcibios_enable_device(struct pci_dev *dev, int mask)
  275. {
  276. return pcibios_enable_resources(dev);
  277. }
  278. void pcibios_update_resource(struct pci_dev *dev, struct resource *root,
  279. struct resource *res, int resource)
  280. {
  281. u32 new, check;
  282. int reg;
  283. return;
  284. new = res->start | (res->flags & PCI_REGION_FLAG_MASK);
  285. if (resource < 6) {
  286. reg = PCI_BASE_ADDRESS_0 + 4 * resource;
  287. } else if (resource == PCI_ROM_RESOURCE) {
  288. res->flags |= IORESOURCE_ROM_ENABLE;
  289. reg = dev->rom_base_reg;
  290. } else {
  291. /*
  292. * Somebody might have asked allocation of a non-standard
  293. * resource
  294. */
  295. return;
  296. }
  297. pci_write_config_dword(dev, reg, new);
  298. pci_read_config_dword(dev, reg, &check);
  299. if ((new ^ check) &
  300. ((new & PCI_BASE_ADDRESS_SPACE_IO) ? PCI_BASE_ADDRESS_IO_MASK :
  301. PCI_BASE_ADDRESS_MEM_MASK)) {
  302. printk(KERN_ERR "PCI: Error while updating region "
  303. "%s/%d (%08x != %08x)\n", pci_name(dev), resource,
  304. new, check);
  305. }
  306. }
  307. void pcibios_align_resource(void *data, struct resource *res,
  308. unsigned long size, unsigned long align)
  309. {
  310. struct pci_dev *dev = data;
  311. if (res->flags & IORESOURCE_IO) {
  312. unsigned long start = res->start;
  313. /* We need to avoid collisions with `mirrored' VGA ports
  314. and other strange ISA hardware, so we always want the
  315. addresses kilobyte aligned. */
  316. if (size > 0x100) {
  317. printk(KERN_ERR "PCI: I/O Region %s/%d too large"
  318. " (%ld bytes)\n", pci_name(dev),
  319. dev->resource - res, size);
  320. }
  321. start = (start + 1024 - 1) & ~(1024 - 1);
  322. res->start = start;
  323. }
  324. }
  325. struct pci_ops titan_pci_ops = {
  326. titan_ht_config_read_byte,
  327. titan_ht_config_read_word,
  328. titan_ht_config_read_dword,
  329. titan_ht_config_write_byte,
  330. titan_ht_config_write_word,
  331. titan_ht_config_write_dword
  332. };
  333. void __init pcibios_fixup_bus(struct pci_bus *c)
  334. {
  335. titan_ht_pcibios_fixup_bus(c);
  336. }
  337. void __init pcibios_init(void)
  338. {
  339. /* Reset PCI I/O and PCI MEM values */
  340. /* XXX Need to add the proper values here */
  341. ioport_resource.start = 0xe0000000;
  342. ioport_resource.end = 0xe0000000 + 0x20000000 - 1;
  343. iomem_resource.start = 0xc0000000;
  344. iomem_resource.end = 0xc0000000 + 0x20000000 - 1;
  345. /* XXX Need to add bus values */
  346. pci_scan_bus(2, &titan_pci_ops, NULL);
  347. pci_scan_bus(3, &titan_pci_ops, NULL);
  348. }
  349. /*
  350. * for parsing "pci=" kernel boot arguments.
  351. */
  352. char *pcibios_setup(char *str)
  353. {
  354. printk(KERN_INFO "rr: pcibios_setup\n");
  355. /* Nothing to do for now. */
  356. return str;
  357. }
  358. unsigned __init int pcibios_assign_all_busses(void)
  359. {
  360. /* We want to use the PCI bus detection done by PMON */
  361. return 0;
  362. }
  363. #endif /* CONFIG_HYPERTRANSPORT */