ht.c 13 KB

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