ht.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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/types.h>
  26. #include <linux/pci.h>
  27. #include <linux/kernel.h>
  28. #include <asm/pci.h>
  29. #include <asm/io.h>
  30. #include <linux/init.h>
  31. #include <asm/titan_dep.h>
  32. #ifdef CONFIG_HYPERTRANSPORT
  33. /*
  34. * This function check if the Hypertransport Link Initialization completed. If
  35. * it did, then proceed further with scanning bus #2
  36. */
  37. static __inline__ int check_titan_htlink(void)
  38. {
  39. u32 val;
  40. val = *(volatile uint32_t *)(RM9000x2_HTLINK_REG);
  41. if (val & 0x00000020)
  42. /* HT Link Initialization completed */
  43. return 1;
  44. else
  45. return 0;
  46. }
  47. static int titan_ht_config_read_dword(struct pci_dev *device,
  48. int offset, u32* val)
  49. {
  50. int dev, bus, func;
  51. uint32_t address_reg, data_reg;
  52. uint32_t address;
  53. bus = device->bus->number;
  54. dev = PCI_SLOT(device->devfn);
  55. func = PCI_FUNC(device->devfn);
  56. /* XXX Need to change the Bus # */
  57. if (bus > 2)
  58. address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
  59. 0x80000000 | 0x1;
  60. else
  61. address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
  62. address_reg = RM9000x2_OCD_HTCFGA;
  63. data_reg = RM9000x2_OCD_HTCFGD;
  64. RM9K_WRITE(address_reg, address);
  65. RM9K_READ(data_reg, val);
  66. return PCIBIOS_SUCCESSFUL;
  67. }
  68. static int titan_ht_config_read_word(struct pci_dev *device,
  69. int offset, u16* val)
  70. {
  71. int dev, bus, func;
  72. uint32_t address_reg, data_reg;
  73. uint32_t address;
  74. bus = device->bus->number;
  75. dev = PCI_SLOT(device->devfn);
  76. func = PCI_FUNC(device->devfn);
  77. /* XXX Need to change the Bus # */
  78. if (bus > 2)
  79. address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
  80. 0x80000000 | 0x1;
  81. else
  82. address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
  83. address_reg = RM9000x2_OCD_HTCFGA;
  84. data_reg = RM9000x2_OCD_HTCFGD;
  85. if ((offset & 0x3) == 0)
  86. offset = 0x2;
  87. else
  88. offset = 0x0;
  89. RM9K_WRITE(address_reg, address);
  90. RM9K_READ_16(data_reg + offset, val);
  91. return PCIBIOS_SUCCESSFUL;
  92. }
  93. u32 longswap(unsigned long l)
  94. {
  95. unsigned char b1, b2, b3, b4;
  96. b1 = l&255;
  97. b2 = (l>>8)&255;
  98. b3 = (l>>16)&255;
  99. b4 = (l>>24)&255;
  100. return ((b1<<24) + (b2<<16) + (b3<<8) + b4);
  101. }
  102. static int titan_ht_config_read_byte(struct pci_dev *device,
  103. int offset, u8* val)
  104. {
  105. int dev, bus, func;
  106. uint32_t address_reg, data_reg;
  107. uint32_t address;
  108. int offset1;
  109. bus = device->bus->number;
  110. dev = PCI_SLOT(device->devfn);
  111. func = PCI_FUNC(device->devfn);
  112. /* XXX Need to change the Bus # */
  113. if (bus > 2)
  114. address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
  115. 0x80000000 | 0x1;
  116. else
  117. address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
  118. address_reg = RM9000x2_OCD_HTCFGA;
  119. data_reg = RM9000x2_OCD_HTCFGD;
  120. RM9K_WRITE(address_reg, address);
  121. if ((offset & 0x3) == 0) {
  122. offset1 = 0x3;
  123. }
  124. if ((offset & 0x3) == 1) {
  125. offset1 = 0x2;
  126. }
  127. if ((offset & 0x3) == 2) {
  128. offset1 = 0x1;
  129. }
  130. if ((offset & 0x3) == 3) {
  131. offset1 = 0x0;
  132. }
  133. RM9K_READ_8(data_reg + offset1, val);
  134. return PCIBIOS_SUCCESSFUL;
  135. }
  136. static int titan_ht_config_write_dword(struct pci_dev *device,
  137. int offset, u8 val)
  138. {
  139. int dev, bus, func;
  140. uint32_t address_reg, data_reg;
  141. uint32_t address;
  142. bus = device->bus->number;
  143. dev = PCI_SLOT(device->devfn);
  144. func = PCI_FUNC(device->devfn);
  145. /* XXX Need to change the Bus # */
  146. if (bus > 2)
  147. address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
  148. 0x80000000 | 0x1;
  149. else
  150. address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
  151. address_reg = RM9000x2_OCD_HTCFGA;
  152. data_reg = RM9000x2_OCD_HTCFGD;
  153. RM9K_WRITE(address_reg, address);
  154. RM9K_WRITE(data_reg, val);
  155. return PCIBIOS_SUCCESSFUL;
  156. }
  157. static int titan_ht_config_write_word(struct pci_dev *device,
  158. int offset, u8 val)
  159. {
  160. int dev, bus, func;
  161. uint32_t address_reg, data_reg;
  162. uint32_t address;
  163. bus = device->bus->number;
  164. dev = PCI_SLOT(device->devfn);
  165. func = PCI_FUNC(device->devfn);
  166. /* XXX Need to change the Bus # */
  167. if (bus > 2)
  168. address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
  169. 0x80000000 | 0x1;
  170. else
  171. address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
  172. address_reg = RM9000x2_OCD_HTCFGA;
  173. data_reg = RM9000x2_OCD_HTCFGD;
  174. if ((offset & 0x3) == 0)
  175. offset = 0x2;
  176. else
  177. offset = 0x0;
  178. RM9K_WRITE(address_reg, address);
  179. RM9K_WRITE_16(data_reg + offset, val);
  180. return PCIBIOS_SUCCESSFUL;
  181. }
  182. static int titan_ht_config_write_byte(struct pci_dev *device,
  183. int offset, u8 val)
  184. {
  185. int dev, bus, func;
  186. uint32_t address_reg, data_reg;
  187. uint32_t address;
  188. int offset1;
  189. bus = device->bus->number;
  190. dev = PCI_SLOT(device->devfn);
  191. func = PCI_FUNC(device->devfn);
  192. /* XXX Need to change the Bus # */
  193. if (bus > 2)
  194. address = (bus << 16) | (dev << 11) | (func << 8) | (offset & 0xfc) |
  195. 0x80000000 | 0x1;
  196. else
  197. address = (dev << 11) | (func << 8) | (offset & 0xfc) | 0x80000000;
  198. address_reg = RM9000x2_OCD_HTCFGA;
  199. data_reg = RM9000x2_OCD_HTCFGD;
  200. RM9K_WRITE(address_reg, address);
  201. if ((offset & 0x3) == 0) {
  202. offset1 = 0x3;
  203. }
  204. if ((offset & 0x3) == 1) {
  205. offset1 = 0x2;
  206. }
  207. if ((offset & 0x3) == 2) {
  208. offset1 = 0x1;
  209. }
  210. if ((offset & 0x3) == 3) {
  211. offset1 = 0x0;
  212. }
  213. RM9K_WRITE_8(data_reg + offset1, val);
  214. return PCIBIOS_SUCCESSFUL;
  215. }
  216. static void titan_pcibios_set_master(struct pci_dev *dev)
  217. {
  218. u16 cmd;
  219. int bus = dev->bus->number;
  220. if (check_titan_htlink())
  221. titan_ht_config_read_word(dev, PCI_COMMAND, &cmd);
  222. cmd |= PCI_COMMAND_MASTER;
  223. if (check_titan_htlink())
  224. titan_ht_config_write_word(dev, PCI_COMMAND, cmd);
  225. }
  226. int pcibios_enable_resources(struct pci_dev *dev)
  227. {
  228. u16 cmd, old_cmd;
  229. u8 tmp1;
  230. int idx;
  231. struct resource *r;
  232. int bus = dev->bus->number;
  233. if (check_titan_htlink())
  234. titan_ht_config_read_word(dev, PCI_COMMAND, &cmd);
  235. old_cmd = cmd;
  236. for (idx = 0; idx < 6; idx++) {
  237. r = &dev->resource[idx];
  238. if (!r->start && r->end) {
  239. printk(KERN_ERR
  240. "PCI: Device %s not available because of "
  241. "resource collisions\n", pci_name(dev));
  242. return -EINVAL;
  243. }
  244. if (r->flags & IORESOURCE_IO)
  245. cmd |= PCI_COMMAND_IO;
  246. if (r->flags & IORESOURCE_MEM)
  247. cmd |= PCI_COMMAND_MEMORY;
  248. }
  249. if (cmd != old_cmd) {
  250. if (check_titan_htlink())
  251. titan_ht_config_write_word(dev, PCI_COMMAND, cmd);
  252. }
  253. if (check_titan_htlink())
  254. titan_ht_config_read_byte(dev, PCI_CACHE_LINE_SIZE, &tmp1);
  255. if (tmp1 != 8) {
  256. printk(KERN_WARNING "PCI setting cache line size to 8 from "
  257. "%d\n", tmp1);
  258. }
  259. if (check_titan_htlink())
  260. titan_ht_config_write_byte(dev, PCI_CACHE_LINE_SIZE, 8);
  261. if (check_titan_htlink())
  262. titan_ht_config_read_byte(dev, PCI_LATENCY_TIMER, &tmp1);
  263. if (tmp1 < 32 || tmp1 == 0xff) {
  264. printk(KERN_WARNING "PCI setting latency timer to 32 from %d\n",
  265. tmp1);
  266. }
  267. if (check_titan_htlink())
  268. titan_ht_config_write_byte(dev, PCI_LATENCY_TIMER, 32);
  269. return 0;
  270. }
  271. int pcibios_enable_device(struct pci_dev *dev, int mask)
  272. {
  273. return pcibios_enable_resources(dev);
  274. }
  275. resource_size_t pcibios_align_resource(void *data, const struct resource *res,
  276. resource_size_t size, resource_size_t align)
  277. {
  278. struct pci_dev *dev = data;
  279. resource_size_t start = res->start;
  280. if (res->flags & IORESOURCE_IO) {
  281. /* We need to avoid collisions with `mirrored' VGA ports
  282. and other strange ISA hardware, so we always want the
  283. addresses kilobyte aligned. */
  284. if (size > 0x100) {
  285. printk(KERN_ERR "PCI: I/O Region %s/%d too large"
  286. " (%ld bytes)\n", pci_name(dev),
  287. dev->resource - res, size);
  288. }
  289. start = (start + 1024 - 1) & ~(1024 - 1);
  290. }
  291. return start;
  292. }
  293. struct pci_ops titan_pci_ops = {
  294. titan_ht_config_read_byte,
  295. titan_ht_config_read_word,
  296. titan_ht_config_read_dword,
  297. titan_ht_config_write_byte,
  298. titan_ht_config_write_word,
  299. titan_ht_config_write_dword
  300. };
  301. void __init pcibios_fixup_bus(struct pci_bus *c)
  302. {
  303. titan_ht_pcibios_fixup_bus(c);
  304. }
  305. void __init pcibios_init(void)
  306. {
  307. /* Reset PCI I/O and PCI MEM values */
  308. /* XXX Need to add the proper values here */
  309. ioport_resource.start = 0xe0000000;
  310. ioport_resource.end = 0xe0000000 + 0x20000000 - 1;
  311. iomem_resource.start = 0xc0000000;
  312. iomem_resource.end = 0xc0000000 + 0x20000000 - 1;
  313. /* XXX Need to add bus values */
  314. pci_scan_bus(2, &titan_pci_ops, NULL);
  315. pci_scan_bus(3, &titan_pci_ops, NULL);
  316. }
  317. /*
  318. * for parsing "pci=" kernel boot arguments.
  319. */
  320. char *pcibios_setup(char *str)
  321. {
  322. printk(KERN_INFO "rr: pcibios_setup\n");
  323. /* Nothing to do for now. */
  324. return str;
  325. }
  326. unsigned __init int pcibios_assign_all_busses(void)
  327. {
  328. /* We want to use the PCI bus detection done by PMON */
  329. return 0;
  330. }
  331. #endif /* CONFIG_HYPERTRANSPORT */