sgiioc4.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. /*
  2. * Copyright (c) 2003 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. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  17. * Mountain View, CA 94043, or:
  18. *
  19. * http://www.sgi.com
  20. *
  21. * For further information regarding this notice, see:
  22. *
  23. * http://oss.sgi.com/projects/GenInfo/NoticeExplan
  24. */
  25. #include <linux/module.h>
  26. #include <linux/types.h>
  27. #include <linux/pci.h>
  28. #include <linux/delay.h>
  29. #include <linux/hdreg.h>
  30. #include <linux/init.h>
  31. #include <linux/kernel.h>
  32. #include <linux/timer.h>
  33. #include <linux/mm.h>
  34. #include <linux/ioport.h>
  35. #include <linux/blkdev.h>
  36. #include <linux/ioc4.h>
  37. #include <asm/io.h>
  38. #include <linux/ide.h>
  39. /* IOC4 Specific Definitions */
  40. #define IOC4_CMD_OFFSET 0x100
  41. #define IOC4_CTRL_OFFSET 0x120
  42. #define IOC4_DMA_OFFSET 0x140
  43. #define IOC4_INTR_OFFSET 0x0
  44. #define IOC4_TIMING 0x00
  45. #define IOC4_DMA_PTR_L 0x01
  46. #define IOC4_DMA_PTR_H 0x02
  47. #define IOC4_DMA_ADDR_L 0x03
  48. #define IOC4_DMA_ADDR_H 0x04
  49. #define IOC4_BC_DEV 0x05
  50. #define IOC4_BC_MEM 0x06
  51. #define IOC4_DMA_CTRL 0x07
  52. #define IOC4_DMA_END_ADDR 0x08
  53. /* Bits in the IOC4 Control/Status Register */
  54. #define IOC4_S_DMA_START 0x01
  55. #define IOC4_S_DMA_STOP 0x02
  56. #define IOC4_S_DMA_DIR 0x04
  57. #define IOC4_S_DMA_ACTIVE 0x08
  58. #define IOC4_S_DMA_ERROR 0x10
  59. #define IOC4_ATA_MEMERR 0x02
  60. /* Read/Write Directions */
  61. #define IOC4_DMA_WRITE 0x04
  62. #define IOC4_DMA_READ 0x00
  63. /* Interrupt Register Offsets */
  64. #define IOC4_INTR_REG 0x03
  65. #define IOC4_INTR_SET 0x05
  66. #define IOC4_INTR_CLEAR 0x07
  67. #define IOC4_IDE_CACHELINE_SIZE 128
  68. #define IOC4_CMD_CTL_BLK_SIZE 0x20
  69. #define IOC4_SUPPORTED_FIRMWARE_REV 46
  70. typedef struct {
  71. u32 timing_reg0;
  72. u32 timing_reg1;
  73. u32 low_mem_ptr;
  74. u32 high_mem_ptr;
  75. u32 low_mem_addr;
  76. u32 high_mem_addr;
  77. u32 dev_byte_count;
  78. u32 mem_byte_count;
  79. u32 status;
  80. } ioc4_dma_regs_t;
  81. /* Each Physical Region Descriptor Entry size is 16 bytes (2 * 64 bits) */
  82. /* IOC4 has only 1 IDE channel */
  83. #define IOC4_PRD_BYTES 16
  84. #define IOC4_PRD_ENTRIES (PAGE_SIZE /(4*IOC4_PRD_BYTES))
  85. static void
  86. sgiioc4_init_hwif_ports(hw_regs_t * hw, unsigned long data_port,
  87. unsigned long ctrl_port, unsigned long irq_port)
  88. {
  89. unsigned long reg = data_port;
  90. int i;
  91. /* Registers are word (32 bit) aligned */
  92. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
  93. hw->io_ports[i] = reg + i * 4;
  94. if (ctrl_port)
  95. hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;
  96. if (irq_port)
  97. hw->io_ports[IDE_IRQ_OFFSET] = irq_port;
  98. }
  99. static void
  100. sgiioc4_maskproc(ide_drive_t * drive, int mask)
  101. {
  102. ide_hwif_t *hwif = HWIF(drive);
  103. hwif->OUTB(mask ? (drive->ctl | 2) : (drive->ctl & ~2),
  104. IDE_CONTROL_REG);
  105. }
  106. static int
  107. sgiioc4_checkirq(ide_hwif_t * hwif)
  108. {
  109. u8 intr_reg =
  110. hwif->INL(hwif->io_ports[IDE_IRQ_OFFSET] + IOC4_INTR_REG * 4);
  111. if (intr_reg & 0x03)
  112. return 1;
  113. return 0;
  114. }
  115. static int
  116. sgiioc4_clearirq(ide_drive_t * drive)
  117. {
  118. u32 intr_reg;
  119. ide_hwif_t *hwif = HWIF(drive);
  120. unsigned long other_ir =
  121. hwif->io_ports[IDE_IRQ_OFFSET] + (IOC4_INTR_REG << 2);
  122. /* Code to check for PCI error conditions */
  123. intr_reg = hwif->INL(other_ir);
  124. if (intr_reg & 0x03) { /* Valid IOC4-IDE interrupt */
  125. /*
  126. * Using hwif->INB to read the IDE_STATUS_REG has a side effect
  127. * of clearing the interrupt. The first read should clear it
  128. * if it is set. The second read should return a "clear" status
  129. * if it got cleared. If not, then spin for a bit trying to
  130. * clear it.
  131. */
  132. u8 stat = hwif->INB(IDE_STATUS_REG);
  133. int count = 0;
  134. stat = hwif->INB(IDE_STATUS_REG);
  135. while ((stat & 0x80) && (count++ < 100)) {
  136. udelay(1);
  137. stat = hwif->INB(IDE_STATUS_REG);
  138. }
  139. if (intr_reg & 0x02) {
  140. /* Error when transferring DMA data on PCI bus */
  141. u32 pci_err_addr_low, pci_err_addr_high,
  142. pci_stat_cmd_reg;
  143. pci_err_addr_low =
  144. hwif->INL(hwif->io_ports[IDE_IRQ_OFFSET]);
  145. pci_err_addr_high =
  146. hwif->INL(hwif->io_ports[IDE_IRQ_OFFSET] + 4);
  147. pci_read_config_dword(hwif->pci_dev, PCI_COMMAND,
  148. &pci_stat_cmd_reg);
  149. printk(KERN_ERR
  150. "%s(%s) : PCI Bus Error when doing DMA:"
  151. " status-cmd reg is 0x%x\n",
  152. __FUNCTION__, drive->name, pci_stat_cmd_reg);
  153. printk(KERN_ERR
  154. "%s(%s) : PCI Error Address is 0x%x%x\n",
  155. __FUNCTION__, drive->name,
  156. pci_err_addr_high, pci_err_addr_low);
  157. /* Clear the PCI Error indicator */
  158. pci_write_config_dword(hwif->pci_dev, PCI_COMMAND,
  159. 0x00000146);
  160. }
  161. /* Clear the Interrupt, Error bits on the IOC4 */
  162. hwif->OUTL(0x03, other_ir);
  163. intr_reg = hwif->INL(other_ir);
  164. }
  165. return intr_reg & 3;
  166. }
  167. static void sgiioc4_ide_dma_start(ide_drive_t * drive)
  168. {
  169. ide_hwif_t *hwif = HWIF(drive);
  170. unsigned int reg = hwif->INL(hwif->dma_base + IOC4_DMA_CTRL * 4);
  171. unsigned int temp_reg = reg | IOC4_S_DMA_START;
  172. hwif->OUTL(temp_reg, hwif->dma_base + IOC4_DMA_CTRL * 4);
  173. }
  174. static u32
  175. sgiioc4_ide_dma_stop(ide_hwif_t *hwif, u64 dma_base)
  176. {
  177. u32 ioc4_dma;
  178. int count;
  179. count = 0;
  180. ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4);
  181. while ((ioc4_dma & IOC4_S_DMA_STOP) && (count++ < 200)) {
  182. udelay(1);
  183. ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4);
  184. }
  185. return ioc4_dma;
  186. }
  187. /* Stops the IOC4 DMA Engine */
  188. static int
  189. sgiioc4_ide_dma_end(ide_drive_t * drive)
  190. {
  191. u32 ioc4_dma, bc_dev, bc_mem, num, valid = 0, cnt = 0;
  192. ide_hwif_t *hwif = HWIF(drive);
  193. u64 dma_base = hwif->dma_base;
  194. int dma_stat = 0;
  195. unsigned long *ending_dma = (unsigned long *) hwif->dma_base2;
  196. hwif->OUTL(IOC4_S_DMA_STOP, dma_base + IOC4_DMA_CTRL * 4);
  197. ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
  198. if (ioc4_dma & IOC4_S_DMA_STOP) {
  199. printk(KERN_ERR
  200. "%s(%s): IOC4 DMA STOP bit is still 1 :"
  201. "ioc4_dma_reg 0x%x\n",
  202. __FUNCTION__, drive->name, ioc4_dma);
  203. dma_stat = 1;
  204. }
  205. /*
  206. * The IOC4 will DMA 1's to the ending dma area to indicate that
  207. * previous data DMA is complete. This is necessary because of relaxed
  208. * ordering between register reads and DMA writes on the Altix.
  209. */
  210. while ((cnt++ < 200) && (!valid)) {
  211. for (num = 0; num < 16; num++) {
  212. if (ending_dma[num]) {
  213. valid = 1;
  214. break;
  215. }
  216. }
  217. udelay(1);
  218. }
  219. if (!valid) {
  220. printk(KERN_ERR "%s(%s) : DMA incomplete\n", __FUNCTION__,
  221. drive->name);
  222. dma_stat = 1;
  223. }
  224. bc_dev = hwif->INL(dma_base + IOC4_BC_DEV * 4);
  225. bc_mem = hwif->INL(dma_base + IOC4_BC_MEM * 4);
  226. if ((bc_dev & 0x01FF) || (bc_mem & 0x1FF)) {
  227. if (bc_dev > bc_mem + 8) {
  228. printk(KERN_ERR
  229. "%s(%s): WARNING!! byte_count_dev %d "
  230. "!= byte_count_mem %d\n",
  231. __FUNCTION__, drive->name, bc_dev, bc_mem);
  232. }
  233. }
  234. drive->waiting_for_dma = 0;
  235. ide_destroy_dmatable(drive);
  236. return dma_stat;
  237. }
  238. static int
  239. sgiioc4_ide_dma_check(ide_drive_t * drive)
  240. {
  241. if (ide_config_drive_speed(drive, XFER_MW_DMA_2) != 0) {
  242. printk(KERN_INFO
  243. "Couldnot set %s in Multimode-2 DMA mode | "
  244. "Drive %s using PIO instead\n",
  245. drive->name, drive->name);
  246. drive->using_dma = 0;
  247. } else
  248. drive->using_dma = 1;
  249. return 0;
  250. }
  251. static int
  252. sgiioc4_ide_dma_on(ide_drive_t * drive)
  253. {
  254. drive->using_dma = 1;
  255. return HWIF(drive)->ide_dma_host_on(drive);
  256. }
  257. static int
  258. sgiioc4_ide_dma_off_quietly(ide_drive_t * drive)
  259. {
  260. drive->using_dma = 0;
  261. return HWIF(drive)->ide_dma_host_off(drive);
  262. }
  263. /* returns 1 if dma irq issued, 0 otherwise */
  264. static int
  265. sgiioc4_ide_dma_test_irq(ide_drive_t * drive)
  266. {
  267. return sgiioc4_checkirq(HWIF(drive));
  268. }
  269. static int
  270. sgiioc4_ide_dma_host_on(ide_drive_t * drive)
  271. {
  272. if (drive->using_dma)
  273. return 0;
  274. return 1;
  275. }
  276. static int
  277. sgiioc4_ide_dma_host_off(ide_drive_t * drive)
  278. {
  279. sgiioc4_clearirq(drive);
  280. return 0;
  281. }
  282. static int
  283. sgiioc4_ide_dma_lostirq(ide_drive_t * drive)
  284. {
  285. HWIF(drive)->resetproc(drive);
  286. return __ide_dma_lostirq(drive);
  287. }
  288. static void
  289. sgiioc4_resetproc(ide_drive_t * drive)
  290. {
  291. sgiioc4_ide_dma_end(drive);
  292. sgiioc4_clearirq(drive);
  293. }
  294. static u8
  295. sgiioc4_INB(unsigned long port)
  296. {
  297. u8 reg = (u8) inb(port);
  298. if ((port & 0xFFF) == 0x11C) { /* Status register of IOC4 */
  299. if (reg & 0x51) { /* Not busy...check for interrupt */
  300. unsigned long other_ir = port - 0x110;
  301. unsigned int intr_reg = (u32) inl(other_ir);
  302. /* Clear the Interrupt, Error bits on the IOC4 */
  303. if (intr_reg & 0x03) {
  304. outl(0x03, other_ir);
  305. intr_reg = (u32) inl(other_ir);
  306. }
  307. }
  308. }
  309. return reg;
  310. }
  311. /* Creates a dma map for the scatter-gather list entries */
  312. static void __devinit
  313. ide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base)
  314. {
  315. int num_ports = sizeof (ioc4_dma_regs_t);
  316. printk(KERN_INFO "%s: BM-DMA at 0x%04lx-0x%04lx\n", hwif->name,
  317. dma_base, dma_base + num_ports - 1);
  318. if (!request_region(dma_base, num_ports, hwif->name)) {
  319. printk(KERN_ERR
  320. "%s(%s) -- ERROR, Addresses 0x%p to 0x%p "
  321. "ALREADY in use\n",
  322. __FUNCTION__, hwif->name, (void *) dma_base,
  323. (void *) dma_base + num_ports - 1);
  324. goto dma_alloc_failure;
  325. }
  326. hwif->dma_base = dma_base;
  327. hwif->dmatable_cpu = pci_alloc_consistent(hwif->pci_dev,
  328. IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
  329. &hwif->dmatable_dma);
  330. if (!hwif->dmatable_cpu)
  331. goto dma_alloc_failure;
  332. hwif->sg_max_nents = IOC4_PRD_ENTRIES;
  333. hwif->dma_base2 = (unsigned long)
  334. pci_alloc_consistent(hwif->pci_dev,
  335. IOC4_IDE_CACHELINE_SIZE,
  336. (dma_addr_t *) &(hwif->dma_status));
  337. if (!hwif->dma_base2)
  338. goto dma_base2alloc_failure;
  339. return;
  340. dma_base2alloc_failure:
  341. pci_free_consistent(hwif->pci_dev,
  342. IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
  343. hwif->dmatable_cpu, hwif->dmatable_dma);
  344. printk(KERN_INFO
  345. "%s() -- Error! Unable to allocate DMA Maps for drive %s\n",
  346. __FUNCTION__, hwif->name);
  347. printk(KERN_INFO
  348. "Changing from DMA to PIO mode for Drive %s\n", hwif->name);
  349. dma_alloc_failure:
  350. /* Disable DMA because we couldnot allocate any DMA maps */
  351. hwif->autodma = 0;
  352. hwif->atapi_dma = 0;
  353. }
  354. /* Initializes the IOC4 DMA Engine */
  355. static void
  356. sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
  357. {
  358. u32 ioc4_dma;
  359. ide_hwif_t *hwif = HWIF(drive);
  360. u64 dma_base = hwif->dma_base;
  361. u32 dma_addr, ending_dma_addr;
  362. ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4);
  363. if (ioc4_dma & IOC4_S_DMA_ACTIVE) {
  364. printk(KERN_WARNING
  365. "%s(%s):Warning!! DMA from previous transfer was still active\n",
  366. __FUNCTION__, drive->name);
  367. hwif->OUTL(IOC4_S_DMA_STOP, dma_base + IOC4_DMA_CTRL * 4);
  368. ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
  369. if (ioc4_dma & IOC4_S_DMA_STOP)
  370. printk(KERN_ERR
  371. "%s(%s) : IOC4 Dma STOP bit is still 1\n",
  372. __FUNCTION__, drive->name);
  373. }
  374. ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4);
  375. if (ioc4_dma & IOC4_S_DMA_ERROR) {
  376. printk(KERN_WARNING
  377. "%s(%s) : Warning!! - DMA Error during Previous"
  378. " transfer | status 0x%x\n",
  379. __FUNCTION__, drive->name, ioc4_dma);
  380. hwif->OUTL(IOC4_S_DMA_STOP, dma_base + IOC4_DMA_CTRL * 4);
  381. ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
  382. if (ioc4_dma & IOC4_S_DMA_STOP)
  383. printk(KERN_ERR
  384. "%s(%s) : IOC4 DMA STOP bit is still 1\n",
  385. __FUNCTION__, drive->name);
  386. }
  387. /* Address of the Scatter Gather List */
  388. dma_addr = cpu_to_le32(hwif->dmatable_dma);
  389. hwif->OUTL(dma_addr, dma_base + IOC4_DMA_PTR_L * 4);
  390. /* Address of the Ending DMA */
  391. memset((unsigned int *) hwif->dma_base2, 0, IOC4_IDE_CACHELINE_SIZE);
  392. ending_dma_addr = cpu_to_le32(hwif->dma_status);
  393. hwif->OUTL(ending_dma_addr, dma_base + IOC4_DMA_END_ADDR * 4);
  394. hwif->OUTL(dma_direction, dma_base + IOC4_DMA_CTRL * 4);
  395. drive->waiting_for_dma = 1;
  396. }
  397. /* IOC4 Scatter Gather list Format */
  398. /* 128 Bit entries to support 64 bit addresses in the future */
  399. /* The Scatter Gather list Entry should be in the BIG-ENDIAN Format */
  400. /* --------------------------------------------------------------------- */
  401. /* | Upper 32 bits - Zero | Lower 32 bits- address | */
  402. /* --------------------------------------------------------------------- */
  403. /* | Upper 32 bits - Zero |EOL| 15 unused | 16 Bit Length| */
  404. /* --------------------------------------------------------------------- */
  405. /* Creates the scatter gather list, DMA Table */
  406. static unsigned int
  407. sgiioc4_build_dma_table(ide_drive_t * drive, struct request *rq, int ddir)
  408. {
  409. ide_hwif_t *hwif = HWIF(drive);
  410. unsigned int *table = hwif->dmatable_cpu;
  411. unsigned int count = 0, i = 1;
  412. struct scatterlist *sg;
  413. hwif->sg_nents = i = ide_build_sglist(drive, rq);
  414. if (!i)
  415. return 0; /* sglist of length Zero */
  416. sg = hwif->sg_table;
  417. while (i && sg_dma_len(sg)) {
  418. dma_addr_t cur_addr;
  419. int cur_len;
  420. cur_addr = sg_dma_address(sg);
  421. cur_len = sg_dma_len(sg);
  422. while (cur_len) {
  423. if (count++ >= IOC4_PRD_ENTRIES) {
  424. printk(KERN_WARNING
  425. "%s: DMA table too small\n",
  426. drive->name);
  427. goto use_pio_instead;
  428. } else {
  429. u32 xcount, bcount =
  430. 0x10000 - (cur_addr & 0xffff);
  431. if (bcount > cur_len)
  432. bcount = cur_len;
  433. /* put the addr, length in
  434. * the IOC4 dma-table format */
  435. *table = 0x0;
  436. table++;
  437. *table = cpu_to_be32(cur_addr);
  438. table++;
  439. *table = 0x0;
  440. table++;
  441. xcount = bcount & 0xffff;
  442. *table = cpu_to_be32(xcount);
  443. table++;
  444. cur_addr += bcount;
  445. cur_len -= bcount;
  446. }
  447. }
  448. sg++;
  449. i--;
  450. }
  451. if (count) {
  452. table--;
  453. *table |= cpu_to_be32(0x80000000);
  454. return count;
  455. }
  456. use_pio_instead:
  457. pci_unmap_sg(hwif->pci_dev, hwif->sg_table, hwif->sg_nents,
  458. hwif->sg_dma_direction);
  459. return 0; /* revert to PIO for this request */
  460. }
  461. static int sgiioc4_ide_dma_setup(ide_drive_t *drive)
  462. {
  463. struct request *rq = HWGROUP(drive)->rq;
  464. unsigned int count = 0;
  465. int ddir;
  466. if (rq_data_dir(rq))
  467. ddir = PCI_DMA_TODEVICE;
  468. else
  469. ddir = PCI_DMA_FROMDEVICE;
  470. if (!(count = sgiioc4_build_dma_table(drive, rq, ddir))) {
  471. /* try PIO instead of DMA */
  472. ide_map_sg(drive, rq);
  473. return 1;
  474. }
  475. if (rq_data_dir(rq))
  476. /* Writes TO the IOC4 FROM Main Memory */
  477. ddir = IOC4_DMA_READ;
  478. else
  479. /* Writes FROM the IOC4 TO Main Memory */
  480. ddir = IOC4_DMA_WRITE;
  481. sgiioc4_configure_for_dma(ddir, drive);
  482. return 0;
  483. }
  484. static void __devinit
  485. ide_init_sgiioc4(ide_hwif_t * hwif)
  486. {
  487. hwif->mmio = 2;
  488. hwif->autodma = 1;
  489. hwif->atapi_dma = 1;
  490. hwif->ultra_mask = 0x0; /* Disable Ultra DMA */
  491. hwif->mwdma_mask = 0x2; /* Multimode-2 DMA */
  492. hwif->swdma_mask = 0x2;
  493. hwif->tuneproc = NULL; /* Sets timing for PIO mode */
  494. hwif->speedproc = NULL; /* Sets timing for DMA &/or PIO modes */
  495. hwif->selectproc = NULL;/* Use the default routine to select drive */
  496. hwif->reset_poll = NULL;/* No HBA specific reset_poll needed */
  497. hwif->pre_reset = NULL; /* No HBA specific pre_set needed */
  498. hwif->resetproc = &sgiioc4_resetproc;/* Reset DMA engine,
  499. clear interrupts */
  500. hwif->intrproc = NULL; /* Enable or Disable interrupt from drive */
  501. hwif->maskproc = &sgiioc4_maskproc; /* Mask on/off NIEN register */
  502. hwif->quirkproc = NULL;
  503. hwif->busproc = NULL;
  504. hwif->dma_setup = &sgiioc4_ide_dma_setup;
  505. hwif->dma_start = &sgiioc4_ide_dma_start;
  506. hwif->ide_dma_end = &sgiioc4_ide_dma_end;
  507. hwif->ide_dma_check = &sgiioc4_ide_dma_check;
  508. hwif->ide_dma_on = &sgiioc4_ide_dma_on;
  509. hwif->ide_dma_off_quietly = &sgiioc4_ide_dma_off_quietly;
  510. hwif->ide_dma_test_irq = &sgiioc4_ide_dma_test_irq;
  511. hwif->ide_dma_host_on = &sgiioc4_ide_dma_host_on;
  512. hwif->ide_dma_host_off = &sgiioc4_ide_dma_host_off;
  513. hwif->ide_dma_lostirq = &sgiioc4_ide_dma_lostirq;
  514. hwif->ide_dma_timeout = &__ide_dma_timeout;
  515. hwif->INB = &sgiioc4_INB;
  516. }
  517. static int __devinit
  518. sgiioc4_ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t * d)
  519. {
  520. unsigned long base, ctl, dma_base, irqport;
  521. ide_hwif_t *hwif;
  522. int h;
  523. for (h = 0; h < MAX_HWIFS; ++h) {
  524. hwif = &ide_hwifs[h];
  525. /* Find an empty HWIF */
  526. if (hwif->chipset == ide_unknown)
  527. break;
  528. }
  529. /* Get the CmdBlk and CtrlBlk Base Registers */
  530. base = pci_resource_start(dev, 0) + IOC4_CMD_OFFSET;
  531. ctl = pci_resource_start(dev, 0) + IOC4_CTRL_OFFSET;
  532. irqport = pci_resource_start(dev, 0) + IOC4_INTR_OFFSET;
  533. dma_base = pci_resource_start(dev, 0) + IOC4_DMA_OFFSET;
  534. if (!request_region(base, IOC4_CMD_CTL_BLK_SIZE, hwif->name)) {
  535. printk(KERN_ERR
  536. "%s : %s -- ERROR, Port Addresses "
  537. "0x%p to 0x%p ALREADY in use\n",
  538. __FUNCTION__, hwif->name, (void *) base,
  539. (void *) base + IOC4_CMD_CTL_BLK_SIZE);
  540. return -ENOMEM;
  541. }
  542. if (hwif->io_ports[IDE_DATA_OFFSET] != base) {
  543. /* Initialize the IO registers */
  544. sgiioc4_init_hwif_ports(&hwif->hw, base, ctl, irqport);
  545. memcpy(hwif->io_ports, hwif->hw.io_ports,
  546. sizeof (hwif->io_ports));
  547. hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
  548. }
  549. hwif->irq = dev->irq;
  550. hwif->chipset = ide_pci;
  551. hwif->pci_dev = dev;
  552. hwif->channel = 0; /* Single Channel chip */
  553. hwif->cds = (struct ide_pci_device_s *) d;
  554. hwif->gendev.parent = &dev->dev;/* setup proper ancestral information */
  555. /* Initializing chipset IRQ Registers */
  556. hwif->OUTL(0x03, irqport + IOC4_INTR_SET * 4);
  557. ide_init_sgiioc4(hwif);
  558. if (dma_base)
  559. ide_dma_sgiioc4(hwif, dma_base);
  560. else
  561. printk(KERN_INFO "%s: %s Bus-Master DMA disabled\n",
  562. hwif->name, d->name);
  563. if (probe_hwif_init(hwif))
  564. return -EIO;
  565. /* Create /proc/ide entries */
  566. create_proc_ide_interfaces();
  567. return 0;
  568. }
  569. static unsigned int __devinit
  570. pci_init_sgiioc4(struct pci_dev *dev, ide_pci_device_t * d)
  571. {
  572. unsigned int class_rev;
  573. int ret;
  574. pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
  575. class_rev &= 0xff;
  576. printk(KERN_INFO "%s: IDE controller at PCI slot %s, revision %d\n",
  577. d->name, pci_name(dev), class_rev);
  578. if (class_rev < IOC4_SUPPORTED_FIRMWARE_REV) {
  579. printk(KERN_ERR "Skipping %s IDE controller in slot %s: "
  580. "firmware is obsolete - please upgrade to revision"
  581. "46 or higher\n", d->name, pci_name(dev));
  582. ret = -EAGAIN;
  583. goto out;
  584. }
  585. ret = sgiioc4_ide_setup_pci_device(dev, d);
  586. out:
  587. return ret;
  588. }
  589. static ide_pci_device_t sgiioc4_chipsets[] __devinitdata = {
  590. {
  591. /* Channel 0 */
  592. .name = "SGIIOC4",
  593. .init_hwif = ide_init_sgiioc4,
  594. .init_dma = ide_dma_sgiioc4,
  595. .channels = 1,
  596. .autodma = AUTODMA,
  597. /* SGI IOC4 doesn't have enablebits. */
  598. .bootable = ON_BOARD,
  599. }
  600. };
  601. int
  602. ioc4_ide_attach_one(struct ioc4_driver_data *idd)
  603. {
  604. return pci_init_sgiioc4(idd->idd_pdev,
  605. &sgiioc4_chipsets[idd->idd_pci_id->driver_data]);
  606. }
  607. static struct ioc4_submodule ioc4_ide_submodule = {
  608. .is_name = "IOC4_ide",
  609. .is_owner = THIS_MODULE,
  610. .is_probe = ioc4_ide_attach_one,
  611. /* .is_remove = ioc4_ide_remove_one, */
  612. };
  613. static int __devinit
  614. ioc4_ide_init(void)
  615. {
  616. return ioc4_register_submodule(&ioc4_ide_submodule);
  617. }
  618. static void __devexit
  619. ioc4_ide_exit(void)
  620. {
  621. ioc4_unregister_submodule(&ioc4_ide_submodule);
  622. }
  623. module_init(ioc4_ide_init);
  624. module_exit(ioc4_ide_exit);
  625. MODULE_AUTHOR("Aniket Malatpure - Silicon Graphics Inc. (SGI)");
  626. MODULE_DESCRIPTION("IDE PCI driver module for SGI IOC4 Base-IO Card");
  627. MODULE_LICENSE("GPL");