ops-pmcmsp.c 32 KB

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