ops-pmcmsp.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  1. /*
  2. * PMC-Sierra MSP board specific pci_ops
  3. *
  4. * Copyright 2001 MontaVista Software Inc.
  5. * Copyright 2005-2007 PMC-Sierra, Inc
  6. *
  7. * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
  8. *
  9. * Much of the code is derived from the original DDB5074 port by
  10. * Geert Uytterhoeven <geert@linux-m68k.org>
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. *
  17. */
  18. #define PCI_COUNTERS 1
  19. #include <linux/types.h>
  20. #include <linux/pci.h>
  21. #include <linux/interrupt.h>
  22. #if defined(CONFIG_PROC_FS) && defined(PCI_COUNTERS)
  23. #include <linux/proc_fs.h>
  24. #include <linux/seq_file.h>
  25. #endif /* CONFIG_PROC_FS && PCI_COUNTERS */
  26. #include <linux/kernel.h>
  27. #include <linux/init.h>
  28. #include <asm/byteorder.h>
  29. #if defined(CONFIG_PMC_MSP7120_GW) || defined(CONFIG_PMC_MSP7120_EVAL)
  30. #include <asm/mipsmtregs.h>
  31. #endif
  32. #include <msp_prom.h>
  33. #include <msp_cic_int.h>
  34. #include <msp_pci.h>
  35. #include <msp_regs.h>
  36. #include <msp_regops.h>
  37. #define PCI_ACCESS_READ 0
  38. #define PCI_ACCESS_WRITE 1
  39. #if defined(CONFIG_PROC_FS) && defined(PCI_COUNTERS)
  40. static char proc_init;
  41. extern struct proc_dir_entry *proc_bus_pci_dir;
  42. unsigned int pci_int_count[32];
  43. static void pci_proc_init(void);
  44. /*****************************************************************************
  45. *
  46. * FUNCTION: show_msp_pci_counts
  47. * _________________________________________________________________________
  48. *
  49. * DESCRIPTION: Prints the count of how many times each PCI
  50. * interrupt has asserted. Can be invoked by the
  51. * /proc filesystem.
  52. *
  53. * INPUTS: m - synthetic file construction data
  54. * v - iterator
  55. *
  56. * RETURNS: 0 or error
  57. *
  58. ****************************************************************************/
  59. static int show_msp_pci_counts(struct seq_file *m, void *v)
  60. {
  61. int i;
  62. unsigned int intcount, total = 0;
  63. for (i = 0; i < 32; ++i) {
  64. intcount = pci_int_count[i];
  65. if (intcount != 0) {
  66. seq_printf(m, "[%d] = %u\n", i, intcount);
  67. total += intcount;
  68. }
  69. }
  70. seq_printf(m, "total = %u\n", total);
  71. return 0;
  72. }
  73. static int msp_pci_rd_cnt_open(struct inode *inode, struct file *file)
  74. {
  75. return single_open(file, show_msp_pci_counts, NULL);
  76. }
  77. static const struct file_operations msp_pci_rd_cnt_fops = {
  78. .open = msp_pci_rd_cnt_open,
  79. .read = seq_read,
  80. .llseek = seq_lseek,
  81. .release = single_release,
  82. };
  83. /*****************************************************************************
  84. *
  85. * FUNCTION: gen_pci_cfg_wr_show
  86. * _________________________________________________________________________
  87. *
  88. * DESCRIPTION: Generates a configuration write cycle for debug purposes.
  89. * The IDSEL line asserted and location and data written are
  90. * immaterial. Just want to be able to prove that a
  91. * configuration write can be correctly generated on the
  92. * PCI bus. Intent is that this function by invocable from
  93. * the /proc filesystem.
  94. *
  95. * INPUTS: m - synthetic file construction data
  96. * v - iterator
  97. *
  98. * RETURNS: 0 or error
  99. *
  100. ****************************************************************************/
  101. static int gen_pci_cfg_wr_show(struct seq_file *m, void *v)
  102. {
  103. unsigned char where = 0; /* Write to static Device/Vendor ID */
  104. unsigned char bus_num = 0; /* Bus 0 */
  105. unsigned char dev_fn = 0xF; /* Arbitrary device number */
  106. u32 wr_data = 0xFF00AA00; /* Arbitrary data */
  107. struct msp_pci_regs *preg = (void *)PCI_BASE_REG;
  108. unsigned long value;
  109. int intr;
  110. seq_puts(m, "PMC MSP PCI: Beginning\n");
  111. if (proc_init == 0) {
  112. pci_proc_init();
  113. proc_init = ~0;
  114. }
  115. seq_puts(m, "PMC MSP PCI: Before Cfg Wr\n");
  116. /*
  117. * Generate PCI Configuration Write Cycle
  118. */
  119. /* Clear cause register bits */
  120. preg->if_status = ~(BPCI_IFSTATUS_BC0F | BPCI_IFSTATUS_BC1F);
  121. /* Setup address that is to appear on PCI bus */
  122. preg->config_addr = BPCI_CFGADDR_ENABLE |
  123. (bus_num << BPCI_CFGADDR_BUSNUM_SHF) |
  124. (dev_fn << BPCI_CFGADDR_FUNCTNUM_SHF) |
  125. (where & 0xFC);
  126. value = cpu_to_le32(wr_data);
  127. /* Launch the PCI configuration write cycle */
  128. *PCI_CONFIG_SPACE_REG = value;
  129. /*
  130. * Check if the PCI configuration cycle (rd or wr) succeeded, by
  131. * checking the status bits for errors like master or target abort.
  132. */
  133. intr = preg->if_status;
  134. seq_puts(m, "PMC MSP PCI: After Cfg Wr\n");
  135. return 0;
  136. }
  137. static int gen_pci_cfg_wr_open(struct inode *inode, struct file *file)
  138. {
  139. return single_open(file, gen_pci_cfg_wr_show, NULL);
  140. }
  141. static const struct file_operations gen_pci_cfg_wr_fops = {
  142. .open = gen_pci_cfg_wr_open,
  143. .read = seq_read,
  144. .llseek = seq_lseek,
  145. .release = single_release,
  146. };
  147. /*****************************************************************************
  148. *
  149. * FUNCTION: pci_proc_init
  150. * _________________________________________________________________________
  151. *
  152. * DESCRIPTION: Create entries in the /proc filesystem for debug access.
  153. *
  154. * INPUTS: none
  155. *
  156. * OUTPUTS: none
  157. *
  158. * RETURNS: none
  159. *
  160. ****************************************************************************/
  161. static void pci_proc_init(void)
  162. {
  163. proc_create("pmc_msp_pci_rd_cnt", 0, NULL, &msp_pci_rd_cnt_fops);
  164. proc_create("pmc_msp_pci_cfg_wr", 0, NULL, &gen_pci_cfg_wr_fops);
  165. }
  166. #endif /* CONFIG_PROC_FS && PCI_COUNTERS */
  167. /*****************************************************************************
  168. *
  169. * STRUCT: pci_io_resource
  170. * _________________________________________________________________________
  171. *
  172. * DESCRIPTION: Defines the address range that pciauto() will use to
  173. * assign to the I/O BARs of PCI devices.
  174. *
  175. * Use the start and end addresses of the MSP7120 PCI Host
  176. * Controller I/O space, in the form that they appear on the
  177. * PCI bus AFTER MSP7120 has performed address translation.
  178. *
  179. * For I/O accesses, MSP7120 ignores OATRAN and maps I/O
  180. * accesses into the bottom 0xFFF region of address space,
  181. * so that is the range to put into the pci_io_resource
  182. * struct.
  183. *
  184. * In MSP4200, the start address was 0x04 instead of the
  185. * expected 0x00. Will just assume there was a good reason
  186. * for this!
  187. *
  188. * NOTES: Linux, by default, will assign I/O space to the lowest
  189. * region of address space. Since MSP7120 and Linux,
  190. * by default, have no offset in between how they map, the
  191. * io_offset element of pci_controller struct should be set
  192. * to zero.
  193. * ELEMENTS:
  194. * name - String used for a meaningful name.
  195. *
  196. * start - Start address of MSP7120's I/O space, as MSP7120 presents
  197. * the address on the PCI bus.
  198. *
  199. * end - End address of MSP7120's I/O space, as MSP7120 presents
  200. * the address on the PCI bus.
  201. *
  202. * flags - Attributes indicating the type of resource. In this case,
  203. * indicate I/O space.
  204. *
  205. ****************************************************************************/
  206. static struct resource pci_io_resource = {
  207. .name = "pci IO space",
  208. .start = 0x04,
  209. .end = 0x0FFF,
  210. .flags = IORESOURCE_IO /* I/O space */
  211. };
  212. /*****************************************************************************
  213. *
  214. * STRUCT: pci_mem_resource
  215. * _________________________________________________________________________
  216. *
  217. * DESCRIPTION: Defines the address range that pciauto() will use to
  218. * assign to the memory BARs of PCI devices.
  219. *
  220. * The .start and .end values are dependent upon how address
  221. * translation is performed by the OATRAN regiser.
  222. *
  223. * The values to use for .start and .end are the values
  224. * in the form they appear on the PCI bus AFTER MSP7120 has
  225. * performed OATRAN address translation.
  226. *
  227. * ELEMENTS:
  228. * name - String used for a meaningful name.
  229. *
  230. * start - Start address of MSP7120's memory space, as MSP7120 presents
  231. * the address on the PCI bus.
  232. *
  233. * end - End address of MSP7120's memory space, as MSP7120 presents
  234. * the address on the PCI bus.
  235. *
  236. * flags - Attributes indicating the type of resource. In this case,
  237. * indicate memory space.
  238. *
  239. ****************************************************************************/
  240. static struct resource pci_mem_resource = {
  241. .name = "pci memory space",
  242. .start = MSP_PCI_SPACE_BASE,
  243. .end = MSP_PCI_SPACE_END,
  244. .flags = IORESOURCE_MEM /* memory space */
  245. };
  246. /*****************************************************************************
  247. *
  248. * FUNCTION: bpci_interrupt
  249. * _________________________________________________________________________
  250. *
  251. * DESCRIPTION: PCI status interrupt handler. Updates the count of how
  252. * many times each status bit has been set, then clears
  253. * the status bits. If the appropriate macros are defined,
  254. * these counts can be viewed via the /proc filesystem.
  255. *
  256. * INPUTS: irq - unused
  257. * dev_id - unused
  258. * pt_regs - unused
  259. *
  260. * OUTPUTS: none
  261. *
  262. * RETURNS: PCIBIOS_SUCCESSFUL - success
  263. *
  264. ****************************************************************************/
  265. static irqreturn_t bpci_interrupt(int irq, void *dev_id)
  266. {
  267. struct msp_pci_regs *preg = (void *)PCI_BASE_REG;
  268. unsigned int stat = preg->if_status;
  269. #if defined(CONFIG_PROC_FS) && defined(PCI_COUNTERS)
  270. int i;
  271. for (i = 0; i < 32; ++i) {
  272. if ((1 << i) & stat)
  273. ++pci_int_count[i];
  274. }
  275. #endif /* PROC_FS && PCI_COUNTERS */
  276. /* printk("PCI ISR: Status=%08X\n", stat); */
  277. /* write to clear all asserted interrupts */
  278. preg->if_status = stat;
  279. return IRQ_HANDLED;
  280. }
  281. /*****************************************************************************
  282. *
  283. * FUNCTION: msp_pcibios_config_access
  284. * _________________________________________________________________________
  285. *
  286. * DESCRIPTION: Performs a PCI configuration access (rd or wr), then
  287. * checks that the access succeeded by querying MSP7120's
  288. * PCI status bits.
  289. *
  290. * INPUTS:
  291. * access_type - kind of PCI configuration cycle to perform
  292. * (read or write). Legal values are
  293. * PCI_ACCESS_WRITE and PCI_ACCESS_READ.
  294. *
  295. * bus - pointer to the bus number of the device to
  296. * be targeted for the configuration cycle.
  297. * The only element of the pci_bus structure
  298. * used is bus->number. This argument determines
  299. * if the configuration access will be Type 0 or
  300. * Type 1. Since MSP7120 assumes itself to be the
  301. * PCI Host, any non-zero bus->number generates
  302. * a Type 1 access.
  303. *
  304. * devfn - this is an 8-bit field. The lower three bits
  305. * specify the function number of the device to
  306. * be targeted for the configuration cycle, with
  307. * all three-bit combinations being legal. The
  308. * upper five bits specify the device number,
  309. * with legal values being 10 to 31.
  310. *
  311. * where - address within the Configuration Header
  312. * space to access.
  313. *
  314. * data - for write accesses, contains the data to
  315. * write.
  316. *
  317. * OUTPUTS:
  318. * data - for read accesses, contains the value read.
  319. *
  320. * RETURNS: PCIBIOS_SUCCESSFUL - success
  321. * -1 - access failure
  322. *
  323. ****************************************************************************/
  324. int msp_pcibios_config_access(unsigned char access_type,
  325. struct pci_bus *bus,
  326. unsigned int devfn,
  327. unsigned char where,
  328. u32 *data)
  329. {
  330. struct msp_pci_regs *preg = (void *)PCI_BASE_REG;
  331. unsigned char bus_num = bus->number;
  332. unsigned char dev_fn = (unsigned char)devfn;
  333. unsigned long intr;
  334. unsigned long value;
  335. static char pciirqflag;
  336. int ret;
  337. #if defined(CONFIG_PMC_MSP7120_GW) || defined(CONFIG_PMC_MSP7120_EVAL)
  338. unsigned int vpe_status;
  339. #endif
  340. #if defined(CONFIG_PROC_FS) && defined(PCI_COUNTERS)
  341. if (proc_init == 0) {
  342. pci_proc_init();
  343. proc_init = ~0;
  344. }
  345. #endif /* CONFIG_PROC_FS && PCI_COUNTERS */
  346. /*
  347. * Just the first time this function invokes, allocate
  348. * an interrupt line for PCI host status interrupts. The
  349. * allocation assigns an interrupt handler to the interrupt.
  350. */
  351. if (pciirqflag == 0) {
  352. ret = request_irq(MSP_INT_PCI,/* Hardcoded internal MSP7120 wiring */
  353. bpci_interrupt,
  354. IRQF_SHARED,
  355. "PMC MSP PCI Host",
  356. preg);
  357. if (ret != 0)
  358. return ret;
  359. pciirqflag = ~0;
  360. }
  361. #if defined(CONFIG_PMC_MSP7120_GW) || defined(CONFIG_PMC_MSP7120_EVAL)
  362. vpe_status = dvpe();
  363. #endif
  364. /*
  365. * Clear PCI cause register bits.
  366. *
  367. * In Polo, the PCI Host had a dedicated DMA called the
  368. * Block Copy (not to be confused with the general purpose Block
  369. * Copy Engine block). There appear to have been special interrupts
  370. * for this Block Copy, called Block Copy 0 Fault (BC0F) and
  371. * Block Copy 1 Fault (BC1F). MSP4200 and MSP7120 don't have this
  372. * dedicated Block Copy block, so these two interrupts are now
  373. * marked reserved. In case the Block Copy is resurrected in a
  374. * future design, maintain the code that treats these two interrupts
  375. * specially.
  376. *
  377. * Write to clear all interrupts in the PCI status register, aside
  378. * from BC0F and BC1F.
  379. */
  380. preg->if_status = ~(BPCI_IFSTATUS_BC0F | BPCI_IFSTATUS_BC1F);
  381. /* Setup address that is to appear on PCI bus */
  382. preg->config_addr = BPCI_CFGADDR_ENABLE |
  383. (bus_num << BPCI_CFGADDR_BUSNUM_SHF) |
  384. (dev_fn << BPCI_CFGADDR_FUNCTNUM_SHF) |
  385. (where & 0xFC);
  386. /* IF access is a PCI configuration write */
  387. if (access_type == PCI_ACCESS_WRITE) {
  388. value = cpu_to_le32(*data);
  389. *PCI_CONFIG_SPACE_REG = value;
  390. } else {
  391. /* ELSE access is a PCI configuration read */
  392. value = le32_to_cpu(*PCI_CONFIG_SPACE_REG);
  393. *data = value;
  394. }
  395. /*
  396. * Check if the PCI configuration cycle (rd or wr) succeeded, by
  397. * checking the status bits for errors like master or target abort.
  398. */
  399. intr = preg->if_status;
  400. /* Clear config access */
  401. preg->config_addr = 0;
  402. /* IF error occurred */
  403. if (intr & ~(BPCI_IFSTATUS_BC0F | BPCI_IFSTATUS_BC1F)) {
  404. /* Clear status bits */
  405. preg->if_status = ~(BPCI_IFSTATUS_BC0F | BPCI_IFSTATUS_BC1F);
  406. #if defined(CONFIG_PMC_MSP7120_GW) || defined(CONFIG_PMC_MSP7120_EVAL)
  407. evpe(vpe_status);
  408. #endif
  409. return -1;
  410. }
  411. #if defined(CONFIG_PMC_MSP7120_GW) || defined(CONFIG_PMC_MSP7120_EVAL)
  412. evpe(vpe_status);
  413. #endif
  414. return PCIBIOS_SUCCESSFUL;
  415. }
  416. /*****************************************************************************
  417. *
  418. * FUNCTION: msp_pcibios_read_config_byte
  419. * _________________________________________________________________________
  420. *
  421. * DESCRIPTION: Read a byte from PCI configuration address spac
  422. * Since the hardware can't address 8 bit chunks
  423. * directly, read a 32-bit chunk, then mask off extraneous
  424. * bits.
  425. *
  426. * INPUTS bus - structure containing attributes for the PCI bus
  427. * that the read is destined for.
  428. * devfn - device/function combination that the read is
  429. * destined for.
  430. * where - register within the Configuration Header space
  431. * to access.
  432. *
  433. * OUTPUTS val - read data
  434. *
  435. * RETURNS: PCIBIOS_SUCCESSFUL - success
  436. * -1 - read access failure
  437. *
  438. ****************************************************************************/
  439. static int
  440. msp_pcibios_read_config_byte(struct pci_bus *bus,
  441. unsigned int devfn,
  442. int where,
  443. u32 *val)
  444. {
  445. u32 data = 0;
  446. /*
  447. * If the config access did not complete normally (e.g., underwent
  448. * master abort) do the PCI compliant thing, which is to supply an
  449. * all ones value.
  450. */
  451. if (msp_pcibios_config_access(PCI_ACCESS_READ, bus, devfn,
  452. where, &data)) {
  453. *val = 0xFFFFFFFF;
  454. return -1;
  455. }
  456. *val = (data >> ((where & 3) << 3)) & 0x0ff;
  457. return PCIBIOS_SUCCESSFUL;
  458. }
  459. /*****************************************************************************
  460. *
  461. * FUNCTION: msp_pcibios_read_config_word
  462. * _________________________________________________________________________
  463. *
  464. * DESCRIPTION: Read a word (16 bits) from PCI configuration address space.
  465. * Since the hardware can't address 16 bit chunks
  466. * directly, read a 32-bit chunk, then mask off extraneous
  467. * bits.
  468. *
  469. * INPUTS bus - structure containing attributes for the PCI bus
  470. * that the read is destined for.
  471. * devfn - device/function combination that the read is
  472. * destined for.
  473. * where - register within the Configuration Header space
  474. * to access.
  475. *
  476. * OUTPUTS val - read data
  477. *
  478. * RETURNS: PCIBIOS_SUCCESSFUL - success
  479. * PCIBIOS_BAD_REGISTER_NUMBER - bad register address
  480. * -1 - read access failure
  481. *
  482. ****************************************************************************/
  483. static int
  484. msp_pcibios_read_config_word(struct pci_bus *bus,
  485. unsigned int devfn,
  486. int where,
  487. u32 *val)
  488. {
  489. u32 data = 0;
  490. /* if (where & 1) */ /* Commented out non-compliant code.
  491. * Should allow word access to configuration
  492. * registers, with only exception being when
  493. * the word access would wrap around into
  494. * the next dword.
  495. */
  496. if ((where & 3) == 3) {
  497. *val = 0xFFFFFFFF;
  498. return PCIBIOS_BAD_REGISTER_NUMBER;
  499. }
  500. /*
  501. * If the config access did not complete normally (e.g., underwent
  502. * master abort) do the PCI compliant thing, which is to supply an
  503. * all ones value.
  504. */
  505. if (msp_pcibios_config_access(PCI_ACCESS_READ, bus, devfn,
  506. where, &data)) {
  507. *val = 0xFFFFFFFF;
  508. return -1;
  509. }
  510. *val = (data >> ((where & 3) << 3)) & 0x0ffff;
  511. return PCIBIOS_SUCCESSFUL;
  512. }
  513. /*****************************************************************************
  514. *
  515. * FUNCTION: msp_pcibios_read_config_dword
  516. * _________________________________________________________________________
  517. *
  518. * DESCRIPTION: Read a double word (32 bits) from PCI configuration
  519. * address space.
  520. *
  521. * INPUTS bus - structure containing attributes for the PCI bus
  522. * that the read is destined for.
  523. * devfn - device/function combination that the read is
  524. * destined for.
  525. * where - register within the Configuration Header space
  526. * to access.
  527. *
  528. * OUTPUTS val - read data
  529. *
  530. * RETURNS: PCIBIOS_SUCCESSFUL - success
  531. * PCIBIOS_BAD_REGISTER_NUMBER - bad register address
  532. * -1 - read access failure
  533. *
  534. ****************************************************************************/
  535. static int
  536. msp_pcibios_read_config_dword(struct pci_bus *bus,
  537. unsigned int devfn,
  538. int where,
  539. u32 *val)
  540. {
  541. u32 data = 0;
  542. /* Address must be dword aligned. */
  543. if (where & 3) {
  544. *val = 0xFFFFFFFF;
  545. return PCIBIOS_BAD_REGISTER_NUMBER;
  546. }
  547. /*
  548. * If the config access did not complete normally (e.g., underwent
  549. * master abort) do the PCI compliant thing, which is to supply an
  550. * all ones value.
  551. */
  552. if (msp_pcibios_config_access(PCI_ACCESS_READ, bus, devfn,
  553. where, &data)) {
  554. *val = 0xFFFFFFFF;
  555. return -1;
  556. }
  557. *val = data;
  558. return PCIBIOS_SUCCESSFUL;
  559. }
  560. /*****************************************************************************
  561. *
  562. * FUNCTION: msp_pcibios_write_config_byte
  563. * _________________________________________________________________________
  564. *
  565. * DESCRIPTION: Write a byte to PCI configuration address space.
  566. * Since the hardware can't address 8 bit chunks
  567. * directly, a read-modify-write is performed.
  568. *
  569. * INPUTS bus - structure containing attributes for the PCI bus
  570. * that the write is destined for.
  571. * devfn - device/function combination that the write is
  572. * destined for.
  573. * where - register within the Configuration Header space
  574. * to access.
  575. * val - value to write
  576. *
  577. * OUTPUTS none
  578. *
  579. * RETURNS: PCIBIOS_SUCCESSFUL - success
  580. * -1 - write access failure
  581. *
  582. ****************************************************************************/
  583. static int
  584. msp_pcibios_write_config_byte(struct pci_bus *bus,
  585. unsigned int devfn,
  586. int where,
  587. u8 val)
  588. {
  589. u32 data = 0;
  590. /* read config space */
  591. if (msp_pcibios_config_access(PCI_ACCESS_READ, bus, devfn,
  592. where, &data))
  593. return -1;
  594. /* modify the byte within the dword */
  595. data = (data & ~(0xff << ((where & 3) << 3))) |
  596. (val << ((where & 3) << 3));
  597. /* write back the full dword */
  598. if (msp_pcibios_config_access(PCI_ACCESS_WRITE, bus, devfn,
  599. where, &data))
  600. return -1;
  601. return PCIBIOS_SUCCESSFUL;
  602. }
  603. /*****************************************************************************
  604. *
  605. * FUNCTION: msp_pcibios_write_config_word
  606. * _________________________________________________________________________
  607. *
  608. * DESCRIPTION: Write a word (16-bits) to PCI configuration address space.
  609. * Since the hardware can't address 16 bit chunks
  610. * directly, a read-modify-write is performed.
  611. *
  612. * INPUTS bus - structure containing attributes for the PCI bus
  613. * that the write is destined for.
  614. * devfn - device/function combination that the write is
  615. * destined for.
  616. * where - register within the Configuration Header space
  617. * to access.
  618. * val - value to write
  619. *
  620. * OUTPUTS none
  621. *
  622. * RETURNS: PCIBIOS_SUCCESSFUL - success
  623. * PCIBIOS_BAD_REGISTER_NUMBER - bad register address
  624. * -1 - write access failure
  625. *
  626. ****************************************************************************/
  627. static int
  628. msp_pcibios_write_config_word(struct pci_bus *bus,
  629. unsigned int devfn,
  630. int where,
  631. u16 val)
  632. {
  633. u32 data = 0;
  634. /* Fixed non-compliance: if (where & 1) */
  635. if ((where & 3) == 3)
  636. return PCIBIOS_BAD_REGISTER_NUMBER;
  637. /* read config space */
  638. if (msp_pcibios_config_access(PCI_ACCESS_READ, bus, devfn,
  639. where, &data))
  640. return -1;
  641. /* modify the word within the dword */
  642. data = (data & ~(0xffff << ((where & 3) << 3))) |
  643. (val << ((where & 3) << 3));
  644. /* write back the full dword */
  645. if (msp_pcibios_config_access(PCI_ACCESS_WRITE, bus, devfn,
  646. where, &data))
  647. return -1;
  648. return PCIBIOS_SUCCESSFUL;
  649. }
  650. /*****************************************************************************
  651. *
  652. * FUNCTION: msp_pcibios_write_config_dword
  653. * _________________________________________________________________________
  654. *
  655. * DESCRIPTION: Write a double word (32-bits) to PCI configuration address
  656. * space.
  657. *
  658. * INPUTS bus - structure containing attributes for the PCI bus
  659. * that the write is destined for.
  660. * devfn - device/function combination that the write is
  661. * destined for.
  662. * where - register within the Configuration Header space
  663. * to access.
  664. * val - value to write
  665. *
  666. * OUTPUTS none
  667. *
  668. * RETURNS: PCIBIOS_SUCCESSFUL - success
  669. * PCIBIOS_BAD_REGISTER_NUMBER - bad register address
  670. * -1 - write access failure
  671. *
  672. ****************************************************************************/
  673. static int
  674. msp_pcibios_write_config_dword(struct pci_bus *bus,
  675. unsigned int devfn,
  676. int where,
  677. u32 val)
  678. {
  679. /* check that address is dword aligned */
  680. if (where & 3)
  681. return PCIBIOS_BAD_REGISTER_NUMBER;
  682. /* perform write */
  683. if (msp_pcibios_config_access(PCI_ACCESS_WRITE, bus, devfn,
  684. where, &val))
  685. return -1;
  686. return PCIBIOS_SUCCESSFUL;
  687. }
  688. /*****************************************************************************
  689. *
  690. * FUNCTION: msp_pcibios_read_config
  691. * _________________________________________________________________________
  692. *
  693. * DESCRIPTION: Interface the PCI configuration read request with
  694. * the appropriate function, based on how many bytes
  695. * the read request is.
  696. *
  697. * INPUTS bus - structure containing attributes for the PCI bus
  698. * that the write is destined for.
  699. * devfn - device/function combination that the write is
  700. * destined for.
  701. * where - register within the Configuration Header space
  702. * to access.
  703. * size - in units of bytes, should be 1, 2, or 4.
  704. *
  705. * OUTPUTS val - value read, with any extraneous bytes masked
  706. * to zero.
  707. *
  708. * RETURNS: PCIBIOS_SUCCESSFUL - success
  709. * -1 - failure
  710. *
  711. ****************************************************************************/
  712. int
  713. msp_pcibios_read_config(struct pci_bus *bus,
  714. unsigned int devfn,
  715. int where,
  716. int size,
  717. u32 *val)
  718. {
  719. if (size == 1) {
  720. if (msp_pcibios_read_config_byte(bus, devfn, where, val)) {
  721. return -1;
  722. }
  723. } else if (size == 2) {
  724. if (msp_pcibios_read_config_word(bus, devfn, where, val)) {
  725. return -1;
  726. }
  727. } else if (size == 4) {
  728. if (msp_pcibios_read_config_dword(bus, devfn, where, val)) {
  729. return -1;
  730. }
  731. } else {
  732. *val = 0xFFFFFFFF;
  733. return -1;
  734. }
  735. return PCIBIOS_SUCCESSFUL;
  736. }
  737. /*****************************************************************************
  738. *
  739. * FUNCTION: msp_pcibios_write_config
  740. * _________________________________________________________________________
  741. *
  742. * DESCRIPTION: Interface the PCI configuration write request with
  743. * the appropriate function, based on how many bytes
  744. * the read request is.
  745. *
  746. * INPUTS bus - structure containing attributes for the PCI bus
  747. * that the write is destined for.
  748. * devfn - device/function combination that the write is
  749. * destined for.
  750. * where - register within the Configuration Header space
  751. * to access.
  752. * size - in units of bytes, should be 1, 2, or 4.
  753. * val - value to write
  754. *
  755. * OUTPUTS: none
  756. *
  757. * RETURNS: PCIBIOS_SUCCESSFUL - success
  758. * -1 - failure
  759. *
  760. ****************************************************************************/
  761. int
  762. msp_pcibios_write_config(struct pci_bus *bus,
  763. unsigned int devfn,
  764. int where,
  765. int size,
  766. u32 val)
  767. {
  768. if (size == 1) {
  769. if (msp_pcibios_write_config_byte(bus, devfn,
  770. where, (u8)(0xFF & val))) {
  771. return -1;
  772. }
  773. } else if (size == 2) {
  774. if (msp_pcibios_write_config_word(bus, devfn,
  775. where, (u16)(0xFFFF & val))) {
  776. return -1;
  777. }
  778. } else if (size == 4) {
  779. if (msp_pcibios_write_config_dword(bus, devfn, where, val)) {
  780. return -1;
  781. }
  782. } else {
  783. return -1;
  784. }
  785. return PCIBIOS_SUCCESSFUL;
  786. }
  787. /*****************************************************************************
  788. *
  789. * STRUCTURE: msp_pci_ops
  790. * _________________________________________________________________________
  791. *
  792. * DESCRIPTION: structure to abstract the hardware specific PCI
  793. * configuration accesses.
  794. *
  795. * ELEMENTS:
  796. * read - function for Linux to generate PCI Configuration reads.
  797. * write - function for Linux to generate PCI Configuration writes.
  798. *
  799. ****************************************************************************/
  800. struct pci_ops msp_pci_ops = {
  801. .read = msp_pcibios_read_config,
  802. .write = msp_pcibios_write_config
  803. };
  804. /*****************************************************************************
  805. *
  806. * STRUCTURE: msp_pci_controller
  807. * _________________________________________________________________________
  808. *
  809. * Describes the attributes of the MSP7120 PCI Host Controller
  810. *
  811. * ELEMENTS:
  812. * pci_ops - abstracts the hardware specific PCI configuration
  813. * accesses.
  814. *
  815. * mem_resource - address range pciauto() uses to assign to PCI device
  816. * memory BARs.
  817. *
  818. * mem_offset - offset between how MSP7120 outbound PCI memory
  819. * transaction addresses appear on the PCI bus and how Linux
  820. * wants to configure memory BARs of the PCI devices.
  821. * MSP7120 does nothing funky, so just set to zero.
  822. *
  823. * io_resource - address range pciauto() uses to assign to PCI device
  824. * I/O BARs.
  825. *
  826. * io_offset - offset between how MSP7120 outbound PCI I/O
  827. * transaction addresses appear on the PCI bus and how
  828. * Linux defaults to configure I/O BARs of the PCI devices.
  829. * MSP7120 maps outbound I/O accesses into the bottom
  830. * bottom 4K of PCI address space (and ignores OATRAN).
  831. * Since the Linux default is to configure I/O BARs to the
  832. * bottom 4K, no special offset is needed. Just set to zero.
  833. *
  834. ****************************************************************************/
  835. static struct pci_controller msp_pci_controller = {
  836. .pci_ops = &msp_pci_ops,
  837. .mem_resource = &pci_mem_resource,
  838. .mem_offset = 0,
  839. .io_map_base = MSP_PCI_IOSPACE_BASE,
  840. .io_resource = &pci_io_resource,
  841. .io_offset = 0
  842. };
  843. /*****************************************************************************
  844. *
  845. * FUNCTION: msp_pci_init
  846. * _________________________________________________________________________
  847. *
  848. * DESCRIPTION: Initialize the PCI Host Controller and register it with
  849. * Linux so Linux can seize control of the PCI bus.
  850. *
  851. ****************************************************************************/
  852. void __init msp_pci_init(void)
  853. {
  854. struct msp_pci_regs *preg = (void *)PCI_BASE_REG;
  855. u32 id;
  856. /* Extract Device ID */
  857. id = read_reg32(PCI_JTAG_DEVID_REG, 0xFFFF) >> 12;
  858. /* Check if JTAG ID identifies MSP7120 */
  859. if (!MSP_HAS_PCI(id)) {
  860. printk(KERN_WARNING "PCI: No PCI; id reads as %x\n", id);
  861. goto no_pci;
  862. }
  863. /*
  864. * Enable flushing of the PCI-SDRAM queue upon a read
  865. * of the SDRAM's Memory Configuration Register.
  866. */
  867. *(unsigned long *)QFLUSH_REG_1 = 3;
  868. /* Configure PCI Host Controller. */
  869. preg->if_status = ~0; /* Clear cause register bits */
  870. preg->config_addr = 0; /* Clear config access */
  871. preg->oatran = MSP_PCI_OATRAN; /* PCI outbound addr translation */
  872. preg->if_mask = 0xF8BF87C0; /* Enable all PCI status interrupts */
  873. /* configure so inb(), outb(), and family are functional */
  874. set_io_port_base(MSP_PCI_IOSPACE_BASE);
  875. /* Tell Linux the details of the MSP7120 PCI Host Controller */
  876. register_pci_controller(&msp_pci_controller);
  877. return;
  878. no_pci:
  879. /* Disable PCI channel */
  880. printk(KERN_WARNING "PCI: no host PCI bus detected\n");
  881. }