sgiioc4.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. /*
  2. * Copyright (c) 2003-2006 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * You should have received a copy of the GNU General Public
  13. * License along with this program; if not, write the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  15. *
  16. * For further information regarding this notice, see:
  17. *
  18. * http://oss.sgi.com/projects/GenInfo/NoticeExplan
  19. */
  20. #include <linux/module.h>
  21. #include <linux/types.h>
  22. #include <linux/pci.h>
  23. #include <linux/delay.h>
  24. #include <linux/hdreg.h>
  25. #include <linux/init.h>
  26. #include <linux/kernel.h>
  27. #include <linux/ioport.h>
  28. #include <linux/blkdev.h>
  29. #include <linux/scatterlist.h>
  30. #include <linux/ioc4.h>
  31. #include <asm/io.h>
  32. #include <linux/ide.h>
  33. #define DRV_NAME "SGIIOC4"
  34. /* IOC4 Specific Definitions */
  35. #define IOC4_CMD_OFFSET 0x100
  36. #define IOC4_CTRL_OFFSET 0x120
  37. #define IOC4_DMA_OFFSET 0x140
  38. #define IOC4_INTR_OFFSET 0x0
  39. #define IOC4_TIMING 0x00
  40. #define IOC4_DMA_PTR_L 0x01
  41. #define IOC4_DMA_PTR_H 0x02
  42. #define IOC4_DMA_ADDR_L 0x03
  43. #define IOC4_DMA_ADDR_H 0x04
  44. #define IOC4_BC_DEV 0x05
  45. #define IOC4_BC_MEM 0x06
  46. #define IOC4_DMA_CTRL 0x07
  47. #define IOC4_DMA_END_ADDR 0x08
  48. /* Bits in the IOC4 Control/Status Register */
  49. #define IOC4_S_DMA_START 0x01
  50. #define IOC4_S_DMA_STOP 0x02
  51. #define IOC4_S_DMA_DIR 0x04
  52. #define IOC4_S_DMA_ACTIVE 0x08
  53. #define IOC4_S_DMA_ERROR 0x10
  54. #define IOC4_ATA_MEMERR 0x02
  55. /* Read/Write Directions */
  56. #define IOC4_DMA_WRITE 0x04
  57. #define IOC4_DMA_READ 0x00
  58. /* Interrupt Register Offsets */
  59. #define IOC4_INTR_REG 0x03
  60. #define IOC4_INTR_SET 0x05
  61. #define IOC4_INTR_CLEAR 0x07
  62. #define IOC4_IDE_CACHELINE_SIZE 128
  63. #define IOC4_CMD_CTL_BLK_SIZE 0x20
  64. #define IOC4_SUPPORTED_FIRMWARE_REV 46
  65. typedef struct {
  66. u32 timing_reg0;
  67. u32 timing_reg1;
  68. u32 low_mem_ptr;
  69. u32 high_mem_ptr;
  70. u32 low_mem_addr;
  71. u32 high_mem_addr;
  72. u32 dev_byte_count;
  73. u32 mem_byte_count;
  74. u32 status;
  75. } ioc4_dma_regs_t;
  76. /* Each Physical Region Descriptor Entry size is 16 bytes (2 * 64 bits) */
  77. /* IOC4 has only 1 IDE channel */
  78. #define IOC4_PRD_BYTES 16
  79. #define IOC4_PRD_ENTRIES (PAGE_SIZE /(4*IOC4_PRD_BYTES))
  80. static void
  81. sgiioc4_init_hwif_ports(hw_regs_t * hw, unsigned long data_port,
  82. unsigned long ctrl_port, unsigned long irq_port)
  83. {
  84. unsigned long reg = data_port;
  85. int i;
  86. /* Registers are word (32 bit) aligned */
  87. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
  88. hw->io_ports[i] = reg + i * 4;
  89. if (ctrl_port)
  90. hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;
  91. if (irq_port)
  92. hw->io_ports[IDE_IRQ_OFFSET] = irq_port;
  93. }
  94. static void
  95. sgiioc4_maskproc(ide_drive_t * drive, int mask)
  96. {
  97. writeb(mask ? (drive->ctl | 2) : (drive->ctl & ~2),
  98. (void __iomem *)drive->hwif->io_ports[IDE_CONTROL_OFFSET]);
  99. }
  100. static int
  101. sgiioc4_checkirq(ide_hwif_t * hwif)
  102. {
  103. unsigned long intr_addr =
  104. hwif->io_ports[IDE_IRQ_OFFSET] + IOC4_INTR_REG * 4;
  105. if ((u8)readl((void __iomem *)intr_addr) & 0x03)
  106. return 1;
  107. return 0;
  108. }
  109. static u8 sgiioc4_INB(unsigned long);
  110. static int
  111. sgiioc4_clearirq(ide_drive_t * drive)
  112. {
  113. u32 intr_reg;
  114. ide_hwif_t *hwif = HWIF(drive);
  115. unsigned long other_ir =
  116. hwif->io_ports[IDE_IRQ_OFFSET] + (IOC4_INTR_REG << 2);
  117. /* Code to check for PCI error conditions */
  118. intr_reg = readl((void __iomem *)other_ir);
  119. if (intr_reg & 0x03) { /* Valid IOC4-IDE interrupt */
  120. /*
  121. * Using sgiioc4_INB to read the Status register has a side
  122. * effect of clearing the interrupt. The first read should
  123. * clear it if it is set. The second read should return
  124. * a "clear" status if it got cleared. If not, then spin
  125. * for a bit trying to clear it.
  126. */
  127. u8 stat = sgiioc4_INB(hwif->io_ports[IDE_STATUS_OFFSET]);
  128. int count = 0;
  129. stat = sgiioc4_INB(hwif->io_ports[IDE_STATUS_OFFSET]);
  130. while ((stat & 0x80) && (count++ < 100)) {
  131. udelay(1);
  132. stat = sgiioc4_INB(hwif->io_ports[IDE_STATUS_OFFSET]);
  133. }
  134. if (intr_reg & 0x02) {
  135. struct pci_dev *dev = to_pci_dev(hwif->dev);
  136. /* Error when transferring DMA data on PCI bus */
  137. u32 pci_err_addr_low, pci_err_addr_high,
  138. pci_stat_cmd_reg;
  139. pci_err_addr_low =
  140. readl((void __iomem *)hwif->io_ports[IDE_IRQ_OFFSET]);
  141. pci_err_addr_high =
  142. readl((void __iomem *)(hwif->io_ports[IDE_IRQ_OFFSET] + 4));
  143. pci_read_config_dword(dev, PCI_COMMAND,
  144. &pci_stat_cmd_reg);
  145. printk(KERN_ERR
  146. "%s(%s) : PCI Bus Error when doing DMA:"
  147. " status-cmd reg is 0x%x\n",
  148. __FUNCTION__, drive->name, pci_stat_cmd_reg);
  149. printk(KERN_ERR
  150. "%s(%s) : PCI Error Address is 0x%x%x\n",
  151. __FUNCTION__, drive->name,
  152. pci_err_addr_high, pci_err_addr_low);
  153. /* Clear the PCI Error indicator */
  154. pci_write_config_dword(dev, PCI_COMMAND, 0x00000146);
  155. }
  156. /* Clear the Interrupt, Error bits on the IOC4 */
  157. writel(0x03, (void __iomem *)other_ir);
  158. intr_reg = readl((void __iomem *)other_ir);
  159. }
  160. return intr_reg & 3;
  161. }
  162. static void sgiioc4_ide_dma_start(ide_drive_t * drive)
  163. {
  164. ide_hwif_t *hwif = HWIF(drive);
  165. unsigned long ioc4_dma_addr = hwif->dma_base + IOC4_DMA_CTRL * 4;
  166. unsigned int reg = readl((void __iomem *)ioc4_dma_addr);
  167. unsigned int temp_reg = reg | IOC4_S_DMA_START;
  168. writel(temp_reg, (void __iomem *)ioc4_dma_addr);
  169. }
  170. static u32
  171. sgiioc4_ide_dma_stop(ide_hwif_t *hwif, u64 dma_base)
  172. {
  173. unsigned long ioc4_dma_addr = dma_base + IOC4_DMA_CTRL * 4;
  174. u32 ioc4_dma;
  175. int count;
  176. count = 0;
  177. ioc4_dma = readl((void __iomem *)ioc4_dma_addr);
  178. while ((ioc4_dma & IOC4_S_DMA_STOP) && (count++ < 200)) {
  179. udelay(1);
  180. ioc4_dma = readl((void __iomem *)ioc4_dma_addr);
  181. }
  182. return ioc4_dma;
  183. }
  184. /* Stops the IOC4 DMA Engine */
  185. static int
  186. sgiioc4_ide_dma_end(ide_drive_t * drive)
  187. {
  188. u32 ioc4_dma, bc_dev, bc_mem, num, valid = 0, cnt = 0;
  189. ide_hwif_t *hwif = HWIF(drive);
  190. unsigned long dma_base = hwif->dma_base;
  191. int dma_stat = 0;
  192. unsigned long *ending_dma = ide_get_hwifdata(hwif);
  193. writel(IOC4_S_DMA_STOP, (void __iomem *)(dma_base + IOC4_DMA_CTRL * 4));
  194. ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
  195. if (ioc4_dma & IOC4_S_DMA_STOP) {
  196. printk(KERN_ERR
  197. "%s(%s): IOC4 DMA STOP bit is still 1 :"
  198. "ioc4_dma_reg 0x%x\n",
  199. __FUNCTION__, drive->name, ioc4_dma);
  200. dma_stat = 1;
  201. }
  202. /*
  203. * The IOC4 will DMA 1's to the ending dma area to indicate that
  204. * previous data DMA is complete. This is necessary because of relaxed
  205. * ordering between register reads and DMA writes on the Altix.
  206. */
  207. while ((cnt++ < 200) && (!valid)) {
  208. for (num = 0; num < 16; num++) {
  209. if (ending_dma[num]) {
  210. valid = 1;
  211. break;
  212. }
  213. }
  214. udelay(1);
  215. }
  216. if (!valid) {
  217. printk(KERN_ERR "%s(%s) : DMA incomplete\n", __FUNCTION__,
  218. drive->name);
  219. dma_stat = 1;
  220. }
  221. bc_dev = readl((void __iomem *)(dma_base + IOC4_BC_DEV * 4));
  222. bc_mem = readl((void __iomem *)(dma_base + IOC4_BC_MEM * 4));
  223. if ((bc_dev & 0x01FF) || (bc_mem & 0x1FF)) {
  224. if (bc_dev > bc_mem + 8) {
  225. printk(KERN_ERR
  226. "%s(%s): WARNING!! byte_count_dev %d "
  227. "!= byte_count_mem %d\n",
  228. __FUNCTION__, drive->name, bc_dev, bc_mem);
  229. }
  230. }
  231. drive->waiting_for_dma = 0;
  232. ide_destroy_dmatable(drive);
  233. return dma_stat;
  234. }
  235. static void sgiioc4_set_dma_mode(ide_drive_t *drive, const u8 speed)
  236. {
  237. }
  238. /* returns 1 if dma irq issued, 0 otherwise */
  239. static int
  240. sgiioc4_ide_dma_test_irq(ide_drive_t * drive)
  241. {
  242. return sgiioc4_checkirq(HWIF(drive));
  243. }
  244. static void sgiioc4_dma_host_set(ide_drive_t *drive, int on)
  245. {
  246. if (!on)
  247. sgiioc4_clearirq(drive);
  248. }
  249. static void
  250. sgiioc4_resetproc(ide_drive_t * drive)
  251. {
  252. sgiioc4_ide_dma_end(drive);
  253. sgiioc4_clearirq(drive);
  254. }
  255. static void
  256. sgiioc4_dma_lost_irq(ide_drive_t * drive)
  257. {
  258. sgiioc4_resetproc(drive);
  259. ide_dma_lost_irq(drive);
  260. }
  261. static u8
  262. sgiioc4_INB(unsigned long port)
  263. {
  264. u8 reg = (u8) readb((void __iomem *) port);
  265. if ((port & 0xFFF) == 0x11C) { /* Status register of IOC4 */
  266. if (reg & 0x51) { /* Not busy...check for interrupt */
  267. unsigned long other_ir = port - 0x110;
  268. unsigned int intr_reg = (u32) readl((void __iomem *) other_ir);
  269. /* Clear the Interrupt, Error bits on the IOC4 */
  270. if (intr_reg & 0x03) {
  271. writel(0x03, (void __iomem *) other_ir);
  272. intr_reg = (u32) readl((void __iomem *) other_ir);
  273. }
  274. }
  275. }
  276. return reg;
  277. }
  278. /* Creates a dma map for the scatter-gather list entries */
  279. static int __devinit
  280. ide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base)
  281. {
  282. struct pci_dev *dev = to_pci_dev(hwif->dev);
  283. void __iomem *virt_dma_base;
  284. int num_ports = sizeof (ioc4_dma_regs_t);
  285. void *pad;
  286. printk(KERN_INFO "%s: BM-DMA at 0x%04lx-0x%04lx\n", hwif->name,
  287. dma_base, dma_base + num_ports - 1);
  288. if (!request_mem_region(dma_base, num_ports, hwif->name)) {
  289. printk(KERN_ERR
  290. "%s(%s) -- ERROR, Addresses 0x%p to 0x%p "
  291. "ALREADY in use\n",
  292. __FUNCTION__, hwif->name, (void *) dma_base,
  293. (void *) dma_base + num_ports - 1);
  294. return -1;
  295. }
  296. virt_dma_base = ioremap(dma_base, num_ports);
  297. if (virt_dma_base == NULL) {
  298. printk(KERN_ERR
  299. "%s(%s) -- ERROR, Unable to map addresses 0x%lx to 0x%lx\n",
  300. __FUNCTION__, hwif->name, dma_base, dma_base + num_ports - 1);
  301. goto dma_remap_failure;
  302. }
  303. hwif->dma_base = (unsigned long) virt_dma_base;
  304. hwif->dmatable_cpu = pci_alloc_consistent(dev,
  305. IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
  306. &hwif->dmatable_dma);
  307. if (!hwif->dmatable_cpu)
  308. goto dma_pci_alloc_failure;
  309. hwif->sg_max_nents = IOC4_PRD_ENTRIES;
  310. pad = pci_alloc_consistent(dev, IOC4_IDE_CACHELINE_SIZE,
  311. (dma_addr_t *) &(hwif->dma_status));
  312. if (pad) {
  313. ide_set_hwifdata(hwif, pad);
  314. return 0;
  315. }
  316. pci_free_consistent(dev, IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
  317. hwif->dmatable_cpu, hwif->dmatable_dma);
  318. printk(KERN_INFO
  319. "%s() -- Error! Unable to allocate DMA Maps for drive %s\n",
  320. __FUNCTION__, hwif->name);
  321. printk(KERN_INFO
  322. "Changing from DMA to PIO mode for Drive %s\n", hwif->name);
  323. dma_pci_alloc_failure:
  324. iounmap(virt_dma_base);
  325. dma_remap_failure:
  326. release_mem_region(dma_base, num_ports);
  327. return -1;
  328. }
  329. /* Initializes the IOC4 DMA Engine */
  330. static void
  331. sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
  332. {
  333. u32 ioc4_dma;
  334. ide_hwif_t *hwif = HWIF(drive);
  335. unsigned long dma_base = hwif->dma_base;
  336. unsigned long ioc4_dma_addr = dma_base + IOC4_DMA_CTRL * 4;
  337. u32 dma_addr, ending_dma_addr;
  338. ioc4_dma = readl((void __iomem *)ioc4_dma_addr);
  339. if (ioc4_dma & IOC4_S_DMA_ACTIVE) {
  340. printk(KERN_WARNING
  341. "%s(%s):Warning!! DMA from previous transfer was still active\n",
  342. __FUNCTION__, drive->name);
  343. writel(IOC4_S_DMA_STOP, (void __iomem *)ioc4_dma_addr);
  344. ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
  345. if (ioc4_dma & IOC4_S_DMA_STOP)
  346. printk(KERN_ERR
  347. "%s(%s) : IOC4 Dma STOP bit is still 1\n",
  348. __FUNCTION__, drive->name);
  349. }
  350. ioc4_dma = readl((void __iomem *)ioc4_dma_addr);
  351. if (ioc4_dma & IOC4_S_DMA_ERROR) {
  352. printk(KERN_WARNING
  353. "%s(%s) : Warning!! - DMA Error during Previous"
  354. " transfer | status 0x%x\n",
  355. __FUNCTION__, drive->name, ioc4_dma);
  356. writel(IOC4_S_DMA_STOP, (void __iomem *)ioc4_dma_addr);
  357. ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
  358. if (ioc4_dma & IOC4_S_DMA_STOP)
  359. printk(KERN_ERR
  360. "%s(%s) : IOC4 DMA STOP bit is still 1\n",
  361. __FUNCTION__, drive->name);
  362. }
  363. /* Address of the Scatter Gather List */
  364. dma_addr = cpu_to_le32(hwif->dmatable_dma);
  365. writel(dma_addr, (void __iomem *)(dma_base + IOC4_DMA_PTR_L * 4));
  366. /* Address of the Ending DMA */
  367. memset(ide_get_hwifdata(hwif), 0, IOC4_IDE_CACHELINE_SIZE);
  368. ending_dma_addr = cpu_to_le32(hwif->dma_status);
  369. writel(ending_dma_addr, (void __iomem *)(dma_base + IOC4_DMA_END_ADDR * 4));
  370. writel(dma_direction, (void __iomem *)ioc4_dma_addr);
  371. drive->waiting_for_dma = 1;
  372. }
  373. /* IOC4 Scatter Gather list Format */
  374. /* 128 Bit entries to support 64 bit addresses in the future */
  375. /* The Scatter Gather list Entry should be in the BIG-ENDIAN Format */
  376. /* --------------------------------------------------------------------- */
  377. /* | Upper 32 bits - Zero | Lower 32 bits- address | */
  378. /* --------------------------------------------------------------------- */
  379. /* | Upper 32 bits - Zero |EOL| 15 unused | 16 Bit Length| */
  380. /* --------------------------------------------------------------------- */
  381. /* Creates the scatter gather list, DMA Table */
  382. static unsigned int
  383. sgiioc4_build_dma_table(ide_drive_t * drive, struct request *rq, int ddir)
  384. {
  385. ide_hwif_t *hwif = HWIF(drive);
  386. unsigned int *table = hwif->dmatable_cpu;
  387. unsigned int count = 0, i = 1;
  388. struct scatterlist *sg;
  389. hwif->sg_nents = i = ide_build_sglist(drive, rq);
  390. if (!i)
  391. return 0; /* sglist of length Zero */
  392. sg = hwif->sg_table;
  393. while (i && sg_dma_len(sg)) {
  394. dma_addr_t cur_addr;
  395. int cur_len;
  396. cur_addr = sg_dma_address(sg);
  397. cur_len = sg_dma_len(sg);
  398. while (cur_len) {
  399. if (count++ >= IOC4_PRD_ENTRIES) {
  400. printk(KERN_WARNING
  401. "%s: DMA table too small\n",
  402. drive->name);
  403. goto use_pio_instead;
  404. } else {
  405. u32 bcount =
  406. 0x10000 - (cur_addr & 0xffff);
  407. if (bcount > cur_len)
  408. bcount = cur_len;
  409. /* put the addr, length in
  410. * the IOC4 dma-table format */
  411. *table = 0x0;
  412. table++;
  413. *table = cpu_to_be32(cur_addr);
  414. table++;
  415. *table = 0x0;
  416. table++;
  417. *table = cpu_to_be32(bcount);
  418. table++;
  419. cur_addr += bcount;
  420. cur_len -= bcount;
  421. }
  422. }
  423. sg = sg_next(sg);
  424. i--;
  425. }
  426. if (count) {
  427. table--;
  428. *table |= cpu_to_be32(0x80000000);
  429. return count;
  430. }
  431. use_pio_instead:
  432. ide_destroy_dmatable(drive);
  433. return 0; /* revert to PIO for this request */
  434. }
  435. static int sgiioc4_ide_dma_setup(ide_drive_t *drive)
  436. {
  437. struct request *rq = HWGROUP(drive)->rq;
  438. unsigned int count = 0;
  439. int ddir;
  440. if (rq_data_dir(rq))
  441. ddir = PCI_DMA_TODEVICE;
  442. else
  443. ddir = PCI_DMA_FROMDEVICE;
  444. if (!(count = sgiioc4_build_dma_table(drive, rq, ddir))) {
  445. /* try PIO instead of DMA */
  446. ide_map_sg(drive, rq);
  447. return 1;
  448. }
  449. if (rq_data_dir(rq))
  450. /* Writes TO the IOC4 FROM Main Memory */
  451. ddir = IOC4_DMA_READ;
  452. else
  453. /* Writes FROM the IOC4 TO Main Memory */
  454. ddir = IOC4_DMA_WRITE;
  455. sgiioc4_configure_for_dma(ddir, drive);
  456. return 0;
  457. }
  458. static void __devinit
  459. ide_init_sgiioc4(ide_hwif_t * hwif)
  460. {
  461. hwif->mmio = 1;
  462. hwif->set_pio_mode = NULL; /* Sets timing for PIO mode */
  463. hwif->set_dma_mode = &sgiioc4_set_dma_mode;
  464. hwif->selectproc = NULL;/* Use the default routine to select drive */
  465. hwif->reset_poll = NULL;/* No HBA specific reset_poll needed */
  466. hwif->pre_reset = NULL; /* No HBA specific pre_set needed */
  467. hwif->resetproc = &sgiioc4_resetproc;/* Reset DMA engine,
  468. clear interrupts */
  469. hwif->maskproc = &sgiioc4_maskproc; /* Mask on/off NIEN register */
  470. hwif->quirkproc = NULL;
  471. hwif->INB = &sgiioc4_INB;
  472. if (hwif->dma_base == 0)
  473. return;
  474. hwif->dma_host_set = &sgiioc4_dma_host_set;
  475. hwif->dma_setup = &sgiioc4_ide_dma_setup;
  476. hwif->dma_start = &sgiioc4_ide_dma_start;
  477. hwif->ide_dma_end = &sgiioc4_ide_dma_end;
  478. hwif->ide_dma_test_irq = &sgiioc4_ide_dma_test_irq;
  479. hwif->dma_lost_irq = &sgiioc4_dma_lost_irq;
  480. hwif->dma_timeout = &ide_dma_timeout;
  481. }
  482. static const struct ide_port_info sgiioc4_port_info __devinitdata = {
  483. .chipset = ide_pci,
  484. .host_flags = IDE_HFLAG_NO_DMA | /* no SFF-style DMA */
  485. IDE_HFLAG_NO_AUTOTUNE,
  486. .mwdma_mask = ATA_MWDMA2_ONLY,
  487. };
  488. static int __devinit
  489. sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
  490. {
  491. unsigned long cmd_base, dma_base, irqport;
  492. unsigned long bar0, cmd_phys_base, ctl;
  493. void __iomem *virt_base;
  494. ide_hwif_t *hwif;
  495. u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
  496. hw_regs_t hw;
  497. struct ide_port_info d = sgiioc4_port_info;
  498. hwif = ide_find_port();
  499. if (hwif == NULL) {
  500. printk(KERN_ERR "%s: too many IDE interfaces, no room in table\n",
  501. DRV_NAME);
  502. return -ENOMEM;
  503. }
  504. /* Get the CmdBlk and CtrlBlk Base Registers */
  505. bar0 = pci_resource_start(dev, 0);
  506. virt_base = ioremap(bar0, pci_resource_len(dev, 0));
  507. if (virt_base == NULL) {
  508. printk(KERN_ERR "%s: Unable to remap BAR 0 address: 0x%lx\n",
  509. DRV_NAME, bar0);
  510. return -ENOMEM;
  511. }
  512. cmd_base = (unsigned long) virt_base + IOC4_CMD_OFFSET;
  513. ctl = (unsigned long) virt_base + IOC4_CTRL_OFFSET;
  514. irqport = (unsigned long) virt_base + IOC4_INTR_OFFSET;
  515. dma_base = pci_resource_start(dev, 0) + IOC4_DMA_OFFSET;
  516. cmd_phys_base = bar0 + IOC4_CMD_OFFSET;
  517. if (!request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE,
  518. hwif->name)) {
  519. printk(KERN_ERR
  520. "%s : %s -- ERROR, Addresses "
  521. "0x%p to 0x%p ALREADY in use\n",
  522. __FUNCTION__, hwif->name, (void *) cmd_phys_base,
  523. (void *) cmd_phys_base + IOC4_CMD_CTL_BLK_SIZE);
  524. return -ENOMEM;
  525. }
  526. /* Initialize the IO registers */
  527. memset(&hw, 0, sizeof(hw));
  528. sgiioc4_init_hwif_ports(&hw, cmd_base, ctl, irqport);
  529. hw.irq = dev->irq;
  530. hw.chipset = ide_pci;
  531. hw.dev = &dev->dev;
  532. ide_init_port_hw(hwif, &hw);
  533. hwif->dev = &dev->dev;
  534. /* The IOC4 uses MMIO rather than Port IO. */
  535. default_hwif_mmiops(hwif);
  536. /* Initializing chipset IRQ Registers */
  537. writel(0x03, (void __iomem *)(irqport + IOC4_INTR_SET * 4));
  538. if (dma_base == 0 || ide_dma_sgiioc4(hwif, dma_base)) {
  539. printk(KERN_INFO "%s: %s Bus-Master DMA disabled\n",
  540. hwif->name, DRV_NAME);
  541. d.mwdma_mask = 0;
  542. }
  543. ide_init_sgiioc4(hwif);
  544. idx[0] = hwif->index;
  545. if (ide_device_add(idx, &d))
  546. return -EIO;
  547. return 0;
  548. }
  549. static unsigned int __devinit
  550. pci_init_sgiioc4(struct pci_dev *dev)
  551. {
  552. int ret;
  553. printk(KERN_INFO "%s: IDE controller at PCI slot %s, revision %d\n",
  554. DRV_NAME, pci_name(dev), dev->revision);
  555. if (dev->revision < IOC4_SUPPORTED_FIRMWARE_REV) {
  556. printk(KERN_ERR "Skipping %s IDE controller in slot %s: "
  557. "firmware is obsolete - please upgrade to "
  558. "revision46 or higher\n",
  559. DRV_NAME, pci_name(dev));
  560. ret = -EAGAIN;
  561. goto out;
  562. }
  563. ret = sgiioc4_ide_setup_pci_device(dev);
  564. out:
  565. return ret;
  566. }
  567. int
  568. ioc4_ide_attach_one(struct ioc4_driver_data *idd)
  569. {
  570. /* PCI-RT does not bring out IDE connection.
  571. * Do not attach to this particular IOC4.
  572. */
  573. if (idd->idd_variant == IOC4_VARIANT_PCI_RT)
  574. return 0;
  575. return pci_init_sgiioc4(idd->idd_pdev);
  576. }
  577. static struct ioc4_submodule ioc4_ide_submodule = {
  578. .is_name = "IOC4_ide",
  579. .is_owner = THIS_MODULE,
  580. .is_probe = ioc4_ide_attach_one,
  581. /* .is_remove = ioc4_ide_remove_one, */
  582. };
  583. static int __init ioc4_ide_init(void)
  584. {
  585. return ioc4_register_submodule(&ioc4_ide_submodule);
  586. }
  587. late_initcall(ioc4_ide_init); /* Call only after IDE init is done */
  588. MODULE_AUTHOR("Aniket Malatpure/Jeremy Higdon");
  589. MODULE_DESCRIPTION("IDE PCI driver module for SGI IOC4 Base-IO Card");
  590. MODULE_LICENSE("GPL");