ops-pmcmsp.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  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. static 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 irqreturn_t 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 IRQ_HANDLED;
  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 targeted 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 targeted 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. int ret;
  352. #if defined(CONFIG_PMC_MSP7120_GW) || defined(CONFIG_PMC_MSP7120_EVAL)
  353. unsigned int vpe_status;
  354. #endif
  355. #if defined(CONFIG_PROC_FS) && defined(PCI_COUNTERS)
  356. if (proc_init == 0) {
  357. pci_proc_init();
  358. proc_init = ~0;
  359. }
  360. #endif /* CONFIG_PROC_FS && PCI_COUNTERS */
  361. /*
  362. * Just the first time this function invokes, allocate
  363. * an interrupt line for PCI host status interrupts. The
  364. * allocation assigns an interrupt handler to the interrupt.
  365. */
  366. if (pciirqflag == 0) {
  367. ret = request_irq(MSP_INT_PCI,/* Hardcoded internal MSP7120 wiring */
  368. bpci_interrupt,
  369. IRQF_SHARED,
  370. "PMC MSP PCI Host",
  371. preg);
  372. if (ret != 0)
  373. return ret;
  374. pciirqflag = ~0;
  375. }
  376. #if defined(CONFIG_PMC_MSP7120_GW) || defined(CONFIG_PMC_MSP7120_EVAL)
  377. local_irq_save(flags);
  378. vpe_status = dvpe();
  379. #else
  380. spin_lock_irqsave(&bpci_lock, flags);
  381. #endif
  382. /*
  383. * Clear PCI cause register bits.
  384. *
  385. * In Polo, the PCI Host had a dedicated DMA called the
  386. * Block Copy (not to be confused with the general purpose Block
  387. * Copy Engine block). There appear to have been special interrupts
  388. * for this Block Copy, called Block Copy 0 Fault (BC0F) and
  389. * Block Copy 1 Fault (BC1F). MSP4200 and MSP7120 don't have this
  390. * dedicated Block Copy block, so these two interrupts are now
  391. * marked reserved. In case the Block Copy is resurrected in a
  392. * future design, maintain the code that treats these two interrupts
  393. * specially.
  394. *
  395. * Write to clear all interrupts in the PCI status register, aside
  396. * from BC0F and BC1F.
  397. */
  398. preg->if_status = ~(BPCI_IFSTATUS_BC0F | BPCI_IFSTATUS_BC1F);
  399. /* Setup address that is to appear on PCI bus */
  400. preg->config_addr = BPCI_CFGADDR_ENABLE |
  401. (bus_num << BPCI_CFGADDR_BUSNUM_SHF) |
  402. (dev_fn << BPCI_CFGADDR_FUNCTNUM_SHF) |
  403. (where & 0xFC);
  404. /* IF access is a PCI configuration write */
  405. if (access_type == PCI_ACCESS_WRITE) {
  406. value = cpu_to_le32(*data);
  407. *PCI_CONFIG_SPACE_REG = value;
  408. } else {
  409. /* ELSE access is a PCI configuration read */
  410. value = le32_to_cpu(*PCI_CONFIG_SPACE_REG);
  411. *data = value;
  412. }
  413. /*
  414. * Check if the PCI configuration cycle (rd or wr) succeeded, by
  415. * checking the status bits for errors like master or target abort.
  416. */
  417. intr = preg->if_status;
  418. /* Clear config access */
  419. preg->config_addr = 0;
  420. /* IF error occurred */
  421. if (intr & ~(BPCI_IFSTATUS_BC0F | BPCI_IFSTATUS_BC1F)) {
  422. /* Clear status bits */
  423. preg->if_status = ~(BPCI_IFSTATUS_BC0F | BPCI_IFSTATUS_BC1F);
  424. #if defined(CONFIG_PMC_MSP7120_GW) || defined(CONFIG_PMC_MSP7120_EVAL)
  425. evpe(vpe_status);
  426. local_irq_restore(flags);
  427. #else
  428. spin_unlock_irqrestore(&bpci_lock, flags);
  429. #endif
  430. return -1;
  431. }
  432. #if defined(CONFIG_PMC_MSP7120_GW) || defined(CONFIG_PMC_MSP7120_EVAL)
  433. evpe(vpe_status);
  434. local_irq_restore(flags);
  435. #else
  436. spin_unlock_irqrestore(&bpci_lock, flags);
  437. #endif
  438. return PCIBIOS_SUCCESSFUL;
  439. }
  440. /*****************************************************************************
  441. *
  442. * FUNCTION: msp_pcibios_read_config_byte
  443. * _________________________________________________________________________
  444. *
  445. * DESCRIPTION: Read a byte from PCI configuration address spac
  446. * Since the hardware can't address 8 bit chunks
  447. * directly, read a 32-bit chunk, then mask off extraneous
  448. * bits.
  449. *
  450. * INPUTS bus - structure containing attributes for the PCI bus
  451. * that the read is destined for.
  452. * devfn - device/function combination that the read is
  453. * destined for.
  454. * where - register within the Configuration Header space
  455. * to access.
  456. *
  457. * OUTPUTS val - read data
  458. *
  459. * RETURNS: PCIBIOS_SUCCESSFUL - success
  460. * -1 - read access failure
  461. *
  462. ****************************************************************************/
  463. static int
  464. msp_pcibios_read_config_byte(struct pci_bus *bus,
  465. unsigned int devfn,
  466. int where,
  467. u32 *val)
  468. {
  469. u32 data = 0;
  470. /*
  471. * If the config access did not complete normally (e.g., underwent
  472. * master abort) do the PCI compliant thing, which is to supply an
  473. * all ones value.
  474. */
  475. if (msp_pcibios_config_access(PCI_ACCESS_READ, bus, devfn,
  476. where, &data)) {
  477. *val = 0xFFFFFFFF;
  478. return -1;
  479. }
  480. *val = (data >> ((where & 3) << 3)) & 0x0ff;
  481. return PCIBIOS_SUCCESSFUL;
  482. }
  483. /*****************************************************************************
  484. *
  485. * FUNCTION: msp_pcibios_read_config_word
  486. * _________________________________________________________________________
  487. *
  488. * DESCRIPTION: Read a word (16 bits) from PCI configuration address space.
  489. * Since the hardware can't address 16 bit chunks
  490. * directly, read a 32-bit chunk, then mask off extraneous
  491. * bits.
  492. *
  493. * INPUTS bus - structure containing attributes for the PCI bus
  494. * that the read is destined for.
  495. * devfn - device/function combination that the read is
  496. * destined for.
  497. * where - register within the Configuration Header space
  498. * to access.
  499. *
  500. * OUTPUTS val - read data
  501. *
  502. * RETURNS: PCIBIOS_SUCCESSFUL - success
  503. * PCIBIOS_BAD_REGISTER_NUMBER - bad register address
  504. * -1 - read access failure
  505. *
  506. ****************************************************************************/
  507. static int
  508. msp_pcibios_read_config_word(struct pci_bus *bus,
  509. unsigned int devfn,
  510. int where,
  511. u32 *val)
  512. {
  513. u32 data = 0;
  514. /* if (where & 1) */ /* Commented out non-compliant code.
  515. * Should allow word access to configuration
  516. * registers, with only exception being when
  517. * the word access would wrap around into
  518. * the next dword.
  519. */
  520. if ((where & 3) == 3) {
  521. *val = 0xFFFFFFFF;
  522. return PCIBIOS_BAD_REGISTER_NUMBER;
  523. }
  524. /*
  525. * If the config access did not complete normally (e.g., underwent
  526. * master abort) do the PCI compliant thing, which is to supply an
  527. * all ones value.
  528. */
  529. if (msp_pcibios_config_access(PCI_ACCESS_READ, bus, devfn,
  530. where, &data)) {
  531. *val = 0xFFFFFFFF;
  532. return -1;
  533. }
  534. *val = (data >> ((where & 3) << 3)) & 0x0ffff;
  535. return PCIBIOS_SUCCESSFUL;
  536. }
  537. /*****************************************************************************
  538. *
  539. * FUNCTION: msp_pcibios_read_config_dword
  540. * _________________________________________________________________________
  541. *
  542. * DESCRIPTION: Read a double word (32 bits) from PCI configuration
  543. * address space.
  544. *
  545. * INPUTS bus - structure containing attributes for the PCI bus
  546. * that the read is destined for.
  547. * devfn - device/function combination that the read is
  548. * destined for.
  549. * where - register within the Configuration Header space
  550. * to access.
  551. *
  552. * OUTPUTS val - read data
  553. *
  554. * RETURNS: PCIBIOS_SUCCESSFUL - success
  555. * PCIBIOS_BAD_REGISTER_NUMBER - bad register address
  556. * -1 - read access failure
  557. *
  558. ****************************************************************************/
  559. static int
  560. msp_pcibios_read_config_dword(struct pci_bus *bus,
  561. unsigned int devfn,
  562. int where,
  563. u32 *val)
  564. {
  565. u32 data = 0;
  566. /* Address must be dword aligned. */
  567. if (where & 3) {
  568. *val = 0xFFFFFFFF;
  569. return PCIBIOS_BAD_REGISTER_NUMBER;
  570. }
  571. /*
  572. * If the config access did not complete normally (e.g., underwent
  573. * master abort) do the PCI compliant thing, which is to supply an
  574. * all ones value.
  575. */
  576. if (msp_pcibios_config_access(PCI_ACCESS_READ, bus, devfn,
  577. where, &data)) {
  578. *val = 0xFFFFFFFF;
  579. return -1;
  580. }
  581. *val = data;
  582. return PCIBIOS_SUCCESSFUL;
  583. }
  584. /*****************************************************************************
  585. *
  586. * FUNCTION: msp_pcibios_write_config_byte
  587. * _________________________________________________________________________
  588. *
  589. * DESCRIPTION: Write a byte to PCI configuration address space.
  590. * Since the hardware can't address 8 bit chunks
  591. * directly, a read-modify-write is performed.
  592. *
  593. * INPUTS bus - structure containing attributes for the PCI bus
  594. * that the write is destined for.
  595. * devfn - device/function combination that the write is
  596. * destined for.
  597. * where - register within the Configuration Header space
  598. * to access.
  599. * val - value to write
  600. *
  601. * OUTPUTS none
  602. *
  603. * RETURNS: PCIBIOS_SUCCESSFUL - success
  604. * -1 - write access failure
  605. *
  606. ****************************************************************************/
  607. static int
  608. msp_pcibios_write_config_byte(struct pci_bus *bus,
  609. unsigned int devfn,
  610. int where,
  611. u8 val)
  612. {
  613. u32 data = 0;
  614. /* read config space */
  615. if (msp_pcibios_config_access(PCI_ACCESS_READ, bus, devfn,
  616. where, &data))
  617. return -1;
  618. /* modify the byte within the dword */
  619. data = (data & ~(0xff << ((where & 3) << 3))) |
  620. (val << ((where & 3) << 3));
  621. /* write back the full dword */
  622. if (msp_pcibios_config_access(PCI_ACCESS_WRITE, bus, devfn,
  623. where, &data))
  624. return -1;
  625. return PCIBIOS_SUCCESSFUL;
  626. }
  627. /*****************************************************************************
  628. *
  629. * FUNCTION: msp_pcibios_write_config_word
  630. * _________________________________________________________________________
  631. *
  632. * DESCRIPTION: Write a word (16-bits) to PCI configuration address space.
  633. * Since the hardware can't address 16 bit chunks
  634. * directly, a read-modify-write is performed.
  635. *
  636. * INPUTS bus - structure containing attributes for the PCI bus
  637. * that the write is destined for.
  638. * devfn - device/function combination that the write is
  639. * destined for.
  640. * where - register within the Configuration Header space
  641. * to access.
  642. * val - value to write
  643. *
  644. * OUTPUTS none
  645. *
  646. * RETURNS: PCIBIOS_SUCCESSFUL - success
  647. * PCIBIOS_BAD_REGISTER_NUMBER - bad register address
  648. * -1 - write access failure
  649. *
  650. ****************************************************************************/
  651. static int
  652. msp_pcibios_write_config_word(struct pci_bus *bus,
  653. unsigned int devfn,
  654. int where,
  655. u16 val)
  656. {
  657. u32 data = 0;
  658. /* Fixed non-compliance: if (where & 1) */
  659. if ((where & 3) == 3)
  660. return PCIBIOS_BAD_REGISTER_NUMBER;
  661. /* read config space */
  662. if (msp_pcibios_config_access(PCI_ACCESS_READ, bus, devfn,
  663. where, &data))
  664. return -1;
  665. /* modify the word within the dword */
  666. data = (data & ~(0xffff << ((where & 3) << 3))) |
  667. (val << ((where & 3) << 3));
  668. /* write back the full dword */
  669. if (msp_pcibios_config_access(PCI_ACCESS_WRITE, bus, devfn,
  670. where, &data))
  671. return -1;
  672. return PCIBIOS_SUCCESSFUL;
  673. }
  674. /*****************************************************************************
  675. *
  676. * FUNCTION: msp_pcibios_write_config_dword
  677. * _________________________________________________________________________
  678. *
  679. * DESCRIPTION: Write a double word (32-bits) to PCI configuration address
  680. * space.
  681. *
  682. * INPUTS bus - structure containing attributes for the PCI bus
  683. * that the write is destined for.
  684. * devfn - device/function combination that the write is
  685. * destined for.
  686. * where - register within the Configuration Header space
  687. * to access.
  688. * val - value to write
  689. *
  690. * OUTPUTS none
  691. *
  692. * RETURNS: PCIBIOS_SUCCESSFUL - success
  693. * PCIBIOS_BAD_REGISTER_NUMBER - bad register address
  694. * -1 - write access failure
  695. *
  696. ****************************************************************************/
  697. static int
  698. msp_pcibios_write_config_dword(struct pci_bus *bus,
  699. unsigned int devfn,
  700. int where,
  701. u32 val)
  702. {
  703. /* check that address is dword aligned */
  704. if (where & 3)
  705. return PCIBIOS_BAD_REGISTER_NUMBER;
  706. /* perform write */
  707. if (msp_pcibios_config_access(PCI_ACCESS_WRITE, bus, devfn,
  708. where, &val))
  709. return -1;
  710. return PCIBIOS_SUCCESSFUL;
  711. }
  712. /*****************************************************************************
  713. *
  714. * FUNCTION: msp_pcibios_read_config
  715. * _________________________________________________________________________
  716. *
  717. * DESCRIPTION: Interface the PCI configuration read request with
  718. * the appropriate function, based on how many bytes
  719. * the read request is.
  720. *
  721. * INPUTS bus - structure containing attributes for the PCI bus
  722. * that the write is destined for.
  723. * devfn - device/function combination that the write is
  724. * destined for.
  725. * where - register within the Configuration Header space
  726. * to access.
  727. * size - in units of bytes, should be 1, 2, or 4.
  728. *
  729. * OUTPUTS val - value read, with any extraneous bytes masked
  730. * to zero.
  731. *
  732. * RETURNS: PCIBIOS_SUCCESSFUL - success
  733. * -1 - failure
  734. *
  735. ****************************************************************************/
  736. int
  737. msp_pcibios_read_config(struct pci_bus *bus,
  738. unsigned int devfn,
  739. int where,
  740. int size,
  741. u32 *val)
  742. {
  743. if (size == 1) {
  744. if (msp_pcibios_read_config_byte(bus, devfn, where, val)) {
  745. return -1;
  746. }
  747. } else if (size == 2) {
  748. if (msp_pcibios_read_config_word(bus, devfn, where, val)) {
  749. return -1;
  750. }
  751. } else if (size == 4) {
  752. if (msp_pcibios_read_config_dword(bus, devfn, where, val)) {
  753. return -1;
  754. }
  755. } else {
  756. *val = 0xFFFFFFFF;
  757. return -1;
  758. }
  759. return PCIBIOS_SUCCESSFUL;
  760. }
  761. /*****************************************************************************
  762. *
  763. * FUNCTION: msp_pcibios_write_config
  764. * _________________________________________________________________________
  765. *
  766. * DESCRIPTION: Interface the PCI configuration write request with
  767. * the appropriate function, based on how many bytes
  768. * the read request is.
  769. *
  770. * INPUTS bus - structure containing attributes for the PCI bus
  771. * that the write is destined for.
  772. * devfn - device/function combination that the write is
  773. * destined for.
  774. * where - register within the Configuration Header space
  775. * to access.
  776. * size - in units of bytes, should be 1, 2, or 4.
  777. * val - value to write
  778. *
  779. * OUTPUTS: none
  780. *
  781. * RETURNS: PCIBIOS_SUCCESSFUL - success
  782. * -1 - failure
  783. *
  784. ****************************************************************************/
  785. int
  786. msp_pcibios_write_config(struct pci_bus *bus,
  787. unsigned int devfn,
  788. int where,
  789. int size,
  790. u32 val)
  791. {
  792. if (size == 1) {
  793. if (msp_pcibios_write_config_byte(bus, devfn,
  794. where, (u8)(0xFF & val))) {
  795. return -1;
  796. }
  797. } else if (size == 2) {
  798. if (msp_pcibios_write_config_word(bus, devfn,
  799. where, (u16)(0xFFFF & val))) {
  800. return -1;
  801. }
  802. } else if (size == 4) {
  803. if (msp_pcibios_write_config_dword(bus, devfn, where, val)) {
  804. return -1;
  805. }
  806. } else {
  807. return -1;
  808. }
  809. return PCIBIOS_SUCCESSFUL;
  810. }
  811. /*****************************************************************************
  812. *
  813. * STRUCTURE: msp_pci_ops
  814. * _________________________________________________________________________
  815. *
  816. * DESCRIPTION: structure to abstract the hardware specific PCI
  817. * configuration accesses.
  818. *
  819. * ELEMENTS:
  820. * read - function for Linux to generate PCI Configuration reads.
  821. * write - function for Linux to generate PCI Configuration writes.
  822. *
  823. ****************************************************************************/
  824. struct pci_ops msp_pci_ops = {
  825. .read = msp_pcibios_read_config,
  826. .write = msp_pcibios_write_config
  827. };
  828. /*****************************************************************************
  829. *
  830. * STRUCTURE: msp_pci_controller
  831. * _________________________________________________________________________
  832. *
  833. * Describes the attributes of the MSP7120 PCI Host Controller
  834. *
  835. * ELEMENTS:
  836. * pci_ops - abstracts the hardware specific PCI configuration
  837. * accesses.
  838. *
  839. * mem_resource - address range pciauto() uses to assign to PCI device
  840. * memory BARs.
  841. *
  842. * mem_offset - offset between how MSP7120 outbound PCI memory
  843. * transaction addresses appear on the PCI bus and how Linux
  844. * wants to configure memory BARs of the PCI devices.
  845. * MSP7120 does nothing funky, so just set to zero.
  846. *
  847. * io_resource - address range pciauto() uses to assign to PCI device
  848. * I/O BARs.
  849. *
  850. * io_offset - offset between how MSP7120 outbound PCI I/O
  851. * transaction addresses appear on the PCI bus and how
  852. * Linux defaults to configure I/O BARs of the PCI devices.
  853. * MSP7120 maps outbound I/O accesses into the bottom
  854. * bottom 4K of PCI address space (and ignores OATRAN).
  855. * Since the Linux default is to configure I/O BARs to the
  856. * bottom 4K, no special offset is needed. Just set to zero.
  857. *
  858. ****************************************************************************/
  859. static struct pci_controller msp_pci_controller = {
  860. .pci_ops = &msp_pci_ops,
  861. .mem_resource = &pci_mem_resource,
  862. .mem_offset = 0,
  863. .io_map_base = MSP_PCI_IOSPACE_BASE,
  864. .io_resource = &pci_io_resource,
  865. .io_offset = 0
  866. };
  867. /*****************************************************************************
  868. *
  869. * FUNCTION: msp_pci_init
  870. * _________________________________________________________________________
  871. *
  872. * DESCRIPTION: Initialize the PCI Host Controller and register it with
  873. * Linux so Linux can seize control of the PCI bus.
  874. *
  875. ****************************************************************************/
  876. void __init msp_pci_init(void)
  877. {
  878. struct msp_pci_regs *preg = (void *)PCI_BASE_REG;
  879. u32 id;
  880. /* Extract Device ID */
  881. id = read_reg32(PCI_JTAG_DEVID_REG, 0xFFFF) >> 12;
  882. /* Check if JTAG ID identifies MSP7120 */
  883. if (!MSP_HAS_PCI(id)) {
  884. printk(KERN_WARNING "PCI: No PCI; id reads as %x\n", id);
  885. goto no_pci;
  886. }
  887. /*
  888. * Enable flushing of the PCI-SDRAM queue upon a read
  889. * of the SDRAM's Memory Configuration Register.
  890. */
  891. *(unsigned long *)QFLUSH_REG_1 = 3;
  892. /* Configure PCI Host Controller. */
  893. preg->if_status = ~0; /* Clear cause register bits */
  894. preg->config_addr = 0; /* Clear config access */
  895. preg->oatran = MSP_PCI_OATRAN; /* PCI outbound addr translation */
  896. preg->if_mask = 0xF8BF87C0; /* Enable all PCI status interrupts */
  897. /* configure so inb(), outb(), and family are functional */
  898. set_io_port_base(MSP_PCI_IOSPACE_BASE);
  899. /* Tell Linux the details of the MSP7120 PCI Host Controller */
  900. register_pci_controller(&msp_pci_controller);
  901. return;
  902. no_pci:
  903. /* Disable PCI channel */
  904. printk(KERN_WARNING "PCI: no host PCI bus detected\n");
  905. }