ht.c 13 KB

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