ide-pci.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:43k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *  linux/drivers/ide/ide-pci.c Version 1.05 June 9, 2000
  3.  *
  4.  *  Copyright (c) 1998-2000  Andre Hedrick <andre@linux-ide.org>
  5.  *
  6.  *  Copyright (c) 1995-1998  Mark Lord
  7.  *  May be copied or modified under the terms of the GNU General Public License
  8.  */
  9. /*
  10.  *  This module provides support for automatic detection and
  11.  *  configuration of all PCI IDE interfaces present in a system.  
  12.  */
  13. #include <linux/config.h>
  14. #include <linux/types.h>
  15. #include <linux/kernel.h>
  16. #include <linux/timer.h>
  17. #include <linux/mm.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/pci.h>
  20. #include <linux/init.h>
  21. #include <linux/ide.h>
  22. #include <asm/io.h>
  23. #include <asm/irq.h>
  24. #define DEVID_PIIXa ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82371FB_0})
  25. #define DEVID_PIIXb ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82371FB_1})
  26. #define DEVID_MPIIX ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82371MX})
  27. #define DEVID_PIIX3 ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82371SB_1})
  28. #define DEVID_PIIX4 ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82371AB})
  29. #define DEVID_ICH0 ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82801AB_1})
  30. #define DEVID_PIIX4E2 ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82443MX_1})
  31. #define DEVID_ICH ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82801AA_1})
  32. #define DEVID_PIIX4U2 ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82372FB_1})
  33. #define DEVID_PIIX4NX ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82451NX})
  34. #define DEVID_ICH2 ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82801BA_9})
  35. #define DEVID_ICH2M ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82801BA_8})
  36. #define DEVID_ICH3M ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82801CA_10})
  37. #define DEVID_ICH3 ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82801CA_11})
  38. #define DEVID_ICH4 ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82801DB_11})
  39. #define DEVID_CICH ((ide_pci_devid_t){PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82801E_11})
  40. #define DEVID_VIA_IDE ((ide_pci_devid_t){PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C561})
  41. #define DEVID_MR_IDE ((ide_pci_devid_t){PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C576_1})
  42. #define DEVID_VP_IDE ((ide_pci_devid_t){PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C586_1})
  43. #define DEVID_PDC20246 ((ide_pci_devid_t){PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20246})
  44. #define DEVID_PDC20262 ((ide_pci_devid_t){PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20262})
  45. #define DEVID_PDC20265 ((ide_pci_devid_t){PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20265})
  46. #define DEVID_PDC20267 ((ide_pci_devid_t){PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20267})
  47. #define DEVID_PDC20268  ((ide_pci_devid_t){PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20268})
  48. #define DEVID_PDC20270  ((ide_pci_devid_t){PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20270})
  49. #define DEVID_PDC20269 ((ide_pci_devid_t){PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20269})
  50. #define DEVID_PDC20275 ((ide_pci_devid_t){PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20275})
  51. #define DEVID_PDC20276 ((ide_pci_devid_t){PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20276})
  52. #define DEVID_RZ1000 ((ide_pci_devid_t){PCI_VENDOR_ID_PCTECH,  PCI_DEVICE_ID_PCTECH_RZ1000})
  53. #define DEVID_RZ1001 ((ide_pci_devid_t){PCI_VENDOR_ID_PCTECH,  PCI_DEVICE_ID_PCTECH_RZ1001})
  54. #define DEVID_SAMURAI ((ide_pci_devid_t){PCI_VENDOR_ID_PCTECH,  PCI_DEVICE_ID_PCTECH_SAMURAI_IDE})
  55. #define DEVID_CMD640 ((ide_pci_devid_t){PCI_VENDOR_ID_CMD,     PCI_DEVICE_ID_CMD_640})
  56. #define DEVID_CMD643 ((ide_pci_devid_t){PCI_VENDOR_ID_CMD,     PCI_DEVICE_ID_CMD_643})
  57. #define DEVID_CMD646 ((ide_pci_devid_t){PCI_VENDOR_ID_CMD,     PCI_DEVICE_ID_CMD_646})
  58. #define DEVID_CMD648 ((ide_pci_devid_t){PCI_VENDOR_ID_CMD,     PCI_DEVICE_ID_CMD_648})
  59. #define DEVID_CMD649 ((ide_pci_devid_t){PCI_VENDOR_ID_CMD,     PCI_DEVICE_ID_CMD_649})
  60. #define DEVID_CMD680 ((ide_pci_devid_t){PCI_VENDOR_ID_CMD,     PCI_DEVICE_ID_CMD_680})
  61. #define DEVID_SIS5513 ((ide_pci_devid_t){PCI_VENDOR_ID_SI,      PCI_DEVICE_ID_SI_5513})
  62. #define DEVID_OPTI621 ((ide_pci_devid_t){PCI_VENDOR_ID_OPTI,    PCI_DEVICE_ID_OPTI_82C621})
  63. #define DEVID_OPTI621V ((ide_pci_devid_t){PCI_VENDOR_ID_OPTI,    PCI_DEVICE_ID_OPTI_82C558})
  64. #define DEVID_OPTI621X ((ide_pci_devid_t){PCI_VENDOR_ID_OPTI,    PCI_DEVICE_ID_OPTI_82C825})
  65. #define DEVID_TRM290 ((ide_pci_devid_t){PCI_VENDOR_ID_TEKRAM,  PCI_DEVICE_ID_TEKRAM_DC290})
  66. #define DEVID_NS87410 ((ide_pci_devid_t){PCI_VENDOR_ID_NS,      PCI_DEVICE_ID_NS_87410})
  67. #define DEVID_NS87415 ((ide_pci_devid_t){PCI_VENDOR_ID_NS,      PCI_DEVICE_ID_NS_87415})
  68. #define DEVID_HT6565 ((ide_pci_devid_t){PCI_VENDOR_ID_HOLTEK,  PCI_DEVICE_ID_HOLTEK_6565})
  69. #define DEVID_AEC6210 ((ide_pci_devid_t){PCI_VENDOR_ID_ARTOP,   PCI_DEVICE_ID_ARTOP_ATP850UF})
  70. #define DEVID_AEC6260 ((ide_pci_devid_t){PCI_VENDOR_ID_ARTOP,   PCI_DEVICE_ID_ARTOP_ATP860})
  71. #define DEVID_AEC6260R ((ide_pci_devid_t){PCI_VENDOR_ID_ARTOP,   PCI_DEVICE_ID_ARTOP_ATP860R})
  72. #define DEVID_W82C105 ((ide_pci_devid_t){PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_82C105})
  73. #define DEVID_UM8673F ((ide_pci_devid_t){PCI_VENDOR_ID_UMC,     PCI_DEVICE_ID_UMC_UM8673F})
  74. #define DEVID_UM8886A ((ide_pci_devid_t){PCI_VENDOR_ID_UMC,     PCI_DEVICE_ID_UMC_UM8886A})
  75. #define DEVID_UM8886BF ((ide_pci_devid_t){PCI_VENDOR_ID_UMC,     PCI_DEVICE_ID_UMC_UM8886BF})
  76. #define DEVID_HPT34X ((ide_pci_devid_t){PCI_VENDOR_ID_TTI,     PCI_DEVICE_ID_TTI_HPT343})
  77. #define DEVID_HPT366 ((ide_pci_devid_t){PCI_VENDOR_ID_TTI,     PCI_DEVICE_ID_TTI_HPT366})
  78. #define DEVID_ALI15X3 ((ide_pci_devid_t){PCI_VENDOR_ID_AL,      PCI_DEVICE_ID_AL_M5229})
  79. #define DEVID_CY82C693 ((ide_pci_devid_t){PCI_VENDOR_ID_CONTAQ,  PCI_DEVICE_ID_CONTAQ_82C693})
  80. #define DEVID_HINT ((ide_pci_devid_t){0x3388,                0x8013})
  81. #define DEVID_CS5530 ((ide_pci_devid_t){PCI_VENDOR_ID_CYRIX,   PCI_DEVICE_ID_CYRIX_5530_IDE})
  82. #define DEVID_AMD7401 ((ide_pci_devid_t){PCI_VENDOR_ID_AMD,     PCI_DEVICE_ID_AMD_COBRA_7401})
  83. #define DEVID_AMD7409 ((ide_pci_devid_t){PCI_VENDOR_ID_AMD,     PCI_DEVICE_ID_AMD_VIPER_7409})
  84. #define DEVID_AMD7411 ((ide_pci_devid_t){PCI_VENDOR_ID_AMD,     PCI_DEVICE_ID_AMD_VIPER_7411})
  85. #define DEVID_AMD7441 ((ide_pci_devid_t){PCI_VENDOR_ID_AMD,     PCI_DEVICE_ID_AMD_VIPER_7441})
  86. #define DEVID_PDCADMA ((ide_pci_devid_t){PCI_VENDOR_ID_PDC,     PCI_DEVICE_ID_PDC_1841})
  87. #define DEVID_SLC90E66 ((ide_pci_devid_t){PCI_VENDOR_ID_EFAR,    PCI_DEVICE_ID_EFAR_SLC90E66_1})
  88. #define DEVID_OSB4 ((ide_pci_devid_t){PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE})
  89. #define DEVID_CSB5 ((ide_pci_devid_t){PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE})
  90. #define DEVID_ITE8172G ((ide_pci_devid_t){PCI_VENDOR_ID_ITE,     PCI_DEVICE_ID_ITE_IT8172G})
  91. #define IDE_IGNORE ((void *)-1)
  92. #define IDE_NO_DRIVER ((void *)-2)
  93. #ifdef CONFIG_BLK_DEV_AEC62XX
  94. extern unsigned int pci_init_aec62xx(struct pci_dev *, const char *);
  95. extern unsigned int ata66_aec62xx(ide_hwif_t *);
  96. extern void ide_init_aec62xx(ide_hwif_t *);
  97. extern void ide_dmacapable_aec62xx(ide_hwif_t *, unsigned long);
  98. #define PCI_AEC62XX &pci_init_aec62xx
  99. #define ATA66_AEC62XX &ata66_aec62xx
  100. #define INIT_AEC62XX &ide_init_aec62xx
  101. #define DMA_AEC62XX &ide_dmacapable_aec62xx
  102. #else
  103. #define PCI_AEC62XX NULL
  104. #define ATA66_AEC62XX NULL
  105. #define INIT_AEC62XX IDE_NO_DRIVER
  106. #define DMA_AEC62XX NULL
  107. #endif
  108. #ifdef CONFIG_BLK_DEV_ALI15X3
  109. extern unsigned int pci_init_ali15x3(struct pci_dev *, const char *);
  110. extern unsigned int ata66_ali15x3(ide_hwif_t *);
  111. extern void ide_init_ali15x3(ide_hwif_t *);
  112. extern void ide_dmacapable_ali15x3(ide_hwif_t *, unsigned long);
  113. #define PCI_ALI15X3 &pci_init_ali15x3
  114. #define ATA66_ALI15X3 &ata66_ali15x3
  115. #define INIT_ALI15X3 &ide_init_ali15x3
  116. #define DMA_ALI15X3 &ide_dmacapable_ali15x3
  117. #else
  118. #define PCI_ALI15X3 NULL
  119. #define ATA66_ALI15X3 NULL
  120. #define INIT_ALI15X3 IDE_NO_DRIVER
  121. #define DMA_ALI15X3 NULL
  122. #endif
  123. #ifdef CONFIG_BLK_DEV_AMD74XX
  124. extern unsigned int pci_init_amd74xx(struct pci_dev *, const char *);
  125. extern unsigned int ata66_amd74xx(ide_hwif_t *);
  126. extern void ide_init_amd74xx(ide_hwif_t *);
  127. extern void ide_dmacapable_amd74xx(ide_hwif_t *, unsigned long);
  128. #define PCI_AMD74XX &pci_init_amd74xx
  129. #define ATA66_AMD74XX &ata66_amd74xx
  130. #define INIT_AMD74XX &ide_init_amd74xx
  131. #define DMA_AMD74XX &ide_dmacapable_amd74xx
  132. #else
  133. #define PCI_AMD74XX NULL
  134. #define ATA66_AMD74XX NULL
  135. #define INIT_AMD74XX IDE_NO_DRIVER
  136. #define DMA_AMD74XX NULL
  137. #endif
  138. #ifdef CONFIG_BLK_DEV_CMD64X
  139. extern unsigned int pci_init_cmd64x(struct pci_dev *, const char *);
  140. extern unsigned int ata66_cmd64x(ide_hwif_t *);
  141. extern void ide_init_cmd64x(ide_hwif_t *);
  142. extern void ide_dmacapable_cmd64x(ide_hwif_t *, unsigned long);
  143. #define PCI_CMD64X &pci_init_cmd64x
  144. #define ATA66_CMD64X &ata66_cmd64x
  145. #define INIT_CMD64X &ide_init_cmd64x
  146. #else
  147. #define PCI_CMD64X NULL
  148. #define ATA66_CMD64X NULL
  149. #ifdef __sparc_v9__
  150. #define INIT_CMD64X IDE_IGNORE
  151. #else
  152. #define INIT_CMD64X IDE_NO_DRIVER
  153. #endif
  154. #endif
  155. #ifdef CONFIG_BLK_DEV_CY82C693
  156. extern unsigned int pci_init_cy82c693(struct pci_dev *, const char *);
  157. extern void ide_init_cy82c693(ide_hwif_t *);
  158. #define PCI_CY82C693 &pci_init_cy82c693
  159. #define INIT_CY82C693 &ide_init_cy82c693
  160. #else
  161. #define PCI_CY82C693 NULL
  162. #define INIT_CY82C693 IDE_NO_DRIVER
  163. #endif
  164. #ifdef CONFIG_BLK_DEV_CS5530
  165. extern unsigned int pci_init_cs5530(struct pci_dev *, const char *);
  166. extern void ide_init_cs5530(ide_hwif_t *);
  167. #define PCI_CS5530 &pci_init_cs5530
  168. #define INIT_CS5530 &ide_init_cs5530
  169. #else
  170. #define PCI_CS5530 NULL
  171. #define INIT_CS5530 IDE_NO_DRIVER
  172. #endif
  173. #ifdef CONFIG_BLK_DEV_HPT34X
  174. extern unsigned int pci_init_hpt34x(struct pci_dev *, const char *);
  175. extern void ide_init_hpt34x(ide_hwif_t *);
  176. #define PCI_HPT34X &pci_init_hpt34x
  177. #define INIT_HPT34X &ide_init_hpt34x
  178. #else
  179. #define PCI_HPT34X NULL
  180. #define INIT_HPT34X IDE_IGNORE
  181. #endif
  182. #ifdef CONFIG_BLK_DEV_HPT366
  183. extern byte hpt363_shared_irq;
  184. extern byte hpt363_shared_pin;
  185. extern unsigned int pci_init_hpt366(struct pci_dev *, const char *);
  186. extern unsigned int ata66_hpt366(ide_hwif_t *);
  187. extern void ide_init_hpt366(ide_hwif_t *);
  188. extern void ide_dmacapable_hpt366(ide_hwif_t *, unsigned long);
  189. #define PCI_HPT366 &pci_init_hpt366
  190. #define ATA66_HPT366 &ata66_hpt366
  191. #define INIT_HPT366 &ide_init_hpt366
  192. #define DMA_HPT366 &ide_dmacapable_hpt366
  193. #else
  194. static byte hpt363_shared_irq;
  195. static byte hpt363_shared_pin;
  196. #define PCI_HPT366 NULL
  197. #define ATA66_HPT366 NULL
  198. #define INIT_HPT366 IDE_NO_DRIVER
  199. #define DMA_HPT366 NULL
  200. #endif
  201. #ifdef CONFIG_BLK_DEV_NS87415
  202. extern void ide_init_ns87415(ide_hwif_t *);
  203. #define INIT_NS87415 &ide_init_ns87415
  204. #else
  205. #define INIT_NS87415 IDE_IGNORE
  206. #endif
  207. #ifdef CONFIG_BLK_DEV_OPTI621
  208. extern void ide_init_opti621(ide_hwif_t *);
  209. #define INIT_OPTI621 &ide_init_opti621
  210. #else
  211. #define INIT_OPTI621 IDE_NO_DRIVER
  212. #endif
  213. #ifdef CONFIG_BLK_DEV_PDC_ADMA
  214. extern unsigned int pci_init_pdcadma(struct pci_dev *, const char *);
  215. extern unsigned int ata66_pdcadma(ide_hwif_t *);
  216. extern void ide_init_pdcadma(ide_hwif_t *);
  217. extern void ide_dmacapable_pdcadma(ide_hwif_t *, unsigned long);
  218. #define PCI_PDCADMA &pci_init_pdcadma
  219. #define ATA66_PDCADMA &ata66_pdcadma
  220. #define INIT_PDCADMA &ide_init_pdcadma
  221. #define DMA_PDCADMA &ide_dmacapable_pdcadma
  222. #else
  223. #define PCI_PDCADMA IDE_IGNORE
  224. #define ATA66_PDCADMA IDE_IGNORE
  225. #define INIT_PDCADMA IDE_IGNORE
  226. #define DMA_PDCADMA IDE_IGNORE
  227. #endif
  228. #ifdef CONFIG_BLK_DEV_PDC202XX
  229. extern unsigned int pci_init_pdc202xx(struct pci_dev *, const char *);
  230. extern unsigned int ata66_pdc202xx(ide_hwif_t *);
  231. extern void ide_init_pdc202xx(ide_hwif_t *);
  232. #define PCI_PDC202XX &pci_init_pdc202xx
  233. #define ATA66_PDC202XX &ata66_pdc202xx
  234. #define INIT_PDC202XX &ide_init_pdc202xx
  235. #else
  236. #define PCI_PDC202XX NULL
  237. #define ATA66_PDC202XX NULL
  238. #define INIT_PDC202XX NULL
  239. #endif
  240. #ifdef CONFIG_BLK_DEV_PIIX
  241. extern unsigned int pci_init_piix(struct pci_dev *, const char *);
  242. extern unsigned int ata66_piix(ide_hwif_t *);
  243. extern void ide_init_piix(ide_hwif_t *);
  244. #define PCI_PIIX &pci_init_piix
  245. #define ATA66_PIIX &ata66_piix
  246. #define INIT_PIIX &ide_init_piix
  247. #else
  248. #define PCI_PIIX NULL
  249. #define ATA66_PIIX NULL
  250. #define INIT_PIIX IDE_NO_DRIVER
  251. #endif
  252. #ifdef CONFIG_BLK_DEV_IT8172
  253. extern unsigned int pci_init_it8172(struct pci_dev *, const char *);
  254. extern unsigned int ata66_it8172(ide_hwif_t *);
  255. extern void ide_init_it8172(ide_hwif_t *);
  256. #define PCI_IT8172 &pci_init_it8172
  257. #define INIT_IT8172 &ide_init_it8172
  258. #else
  259. #define PCI_IT8172 NULL
  260. #define ATA66_IT8172 NULL
  261. #define INIT_IT8172 NULL
  262. #endif
  263. #ifdef CONFIG_BLK_DEV_RZ1000
  264. extern void ide_init_rz1000(ide_hwif_t *);
  265. #define INIT_RZ1000 &ide_init_rz1000
  266. #else
  267. #define INIT_RZ1000 IDE_IGNORE
  268. #endif
  269. #define INIT_SAMURAI NULL
  270. #ifdef CONFIG_BLK_DEV_SVWKS
  271. extern unsigned int pci_init_svwks(struct pci_dev *, const char *);
  272. extern unsigned int ata66_svwks(ide_hwif_t *);
  273. extern void ide_init_svwks(ide_hwif_t *);
  274. #define PCI_SVWKS &pci_init_svwks
  275. #define ATA66_SVWKS &ata66_svwks
  276. #define INIT_SVWKS &ide_init_svwks
  277. #else
  278. #define PCI_SVWKS NULL
  279. #define ATA66_SVWKS NULL
  280. #define INIT_SVWKS IDE_NO_DRIVER
  281. #endif
  282. #ifdef CONFIG_BLK_DEV_SIS5513
  283. extern unsigned int pci_init_sis5513(struct pci_dev *, const char *);
  284. extern unsigned int ata66_sis5513(ide_hwif_t *);
  285. extern void ide_init_sis5513(ide_hwif_t *);
  286. #define PCI_SIS5513 &pci_init_sis5513
  287. #define ATA66_SIS5513 &ata66_sis5513
  288. #define INIT_SIS5513 &ide_init_sis5513
  289. #else
  290. #define PCI_SIS5513 NULL
  291. #define ATA66_SIS5513 NULL
  292. #define INIT_SIS5513 IDE_NO_DRIVER
  293. #endif
  294. #ifdef CONFIG_BLK_DEV_SLC90E66
  295. extern unsigned int pci_init_slc90e66(struct pci_dev *, const char *);
  296. extern unsigned int ata66_slc90e66(ide_hwif_t *);
  297. extern void ide_init_slc90e66(ide_hwif_t *);
  298. #define PCI_SLC90E66 &pci_init_slc90e66
  299. #define ATA66_SLC90E66 &ata66_slc90e66
  300. #define INIT_SLC90E66 &ide_init_slc90e66
  301. #else
  302. #define PCI_SLC90E66 NULL
  303. #define ATA66_SLC90E66 NULL
  304. #define INIT_SLC90E66 IDE_NO_DRIVER
  305. #endif
  306. #ifdef CONFIG_BLK_DEV_SL82C105
  307. extern unsigned int pci_init_sl82c105(struct pci_dev *, const char *);
  308. extern void dma_init_sl82c105(ide_hwif_t *, unsigned long);
  309. extern void ide_init_sl82c105(ide_hwif_t *);
  310. #define PCI_W82C105 &pci_init_sl82c105
  311. #define DMA_W82C105 &dma_init_sl82c105
  312. #define INIT_W82C105 &ide_init_sl82c105
  313. #else
  314. #define PCI_W82C105 NULL
  315. #define DMA_W82C105 NULL
  316. #define INIT_W82C105 IDE_IGNORE
  317. #endif
  318. #ifdef CONFIG_BLK_DEV_TRM290
  319. extern void ide_init_trm290(ide_hwif_t *);
  320. #define INIT_TRM290 &ide_init_trm290
  321. #else
  322. #define INIT_TRM290 IDE_IGNORE
  323. #endif
  324. #ifdef CONFIG_BLK_DEV_VIA82CXXX
  325. extern unsigned int pci_init_via82cxxx(struct pci_dev *, const char *);
  326. extern unsigned int ata66_via82cxxx(ide_hwif_t *);
  327. extern void ide_init_via82cxxx(ide_hwif_t *);
  328. extern void ide_dmacapable_via82cxxx(ide_hwif_t *, unsigned long);
  329. #define PCI_VIA82CXXX &pci_init_via82cxxx
  330. #define ATA66_VIA82CXXX &ata66_via82cxxx
  331. #define INIT_VIA82CXXX &ide_init_via82cxxx
  332. #define DMA_VIA82CXXX &ide_dmacapable_via82cxxx
  333. #else
  334. #define PCI_VIA82CXXX NULL
  335. #define ATA66_VIA82CXXX NULL
  336. #define INIT_VIA82CXXX IDE_NO_DRIVER
  337. #define DMA_VIA82CXXX NULL
  338. #endif
  339. typedef struct ide_pci_enablebit_s {
  340. byte reg; /* byte pci reg holding the enable-bit */
  341. byte mask; /* mask to isolate the enable-bit */
  342. byte val; /* value of masked reg when "enabled" */
  343. } ide_pci_enablebit_t;
  344. typedef struct ide_pci_device_s {
  345. ide_pci_devid_t devid;
  346. char *name;
  347. unsigned int (*init_chipset)(struct pci_dev *dev, const char *name);
  348. unsigned int (*ata66_check)(ide_hwif_t *hwif);
  349. void  (*init_hwif)(ide_hwif_t *hwif);
  350. void (*dma_init)(ide_hwif_t *hwif, unsigned long dmabase);
  351. ide_pci_enablebit_t enablebits[2];
  352. byte bootable;
  353. unsigned int extra;
  354. } ide_pci_device_t;
  355. static ide_pci_device_t ide_pci_chipsets[] __initdata = {
  356. {DEVID_PIIXa, "PIIX", NULL, NULL, INIT_PIIX, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}},  ON_BOARD, 0 },
  357. {DEVID_PIIXb, "PIIX", NULL, NULL, INIT_PIIX, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}},  ON_BOARD, 0 },
  358. {DEVID_MPIIX, "MPIIX", NULL, NULL, INIT_PIIX, NULL, {{0x6D,0x80,0x80}, {0x6F,0x80,0x80}}, ON_BOARD, 0 },
  359. {DEVID_PIIX3, "PIIX3", PCI_PIIX, NULL, INIT_PIIX, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}},  ON_BOARD, 0 },
  360. {DEVID_PIIX4, "PIIX4", PCI_PIIX, NULL, INIT_PIIX, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}},  ON_BOARD, 0 },
  361. {DEVID_ICH0, "ICH0",  PCI_PIIX, NULL, INIT_PIIX, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, ON_BOARD, 0 },
  362. {DEVID_PIIX4E2, "PIIX4", PCI_PIIX, NULL, INIT_PIIX, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, ON_BOARD, 0 },
  363. {DEVID_ICH, "ICH",   PCI_PIIX, ATA66_PIIX, INIT_PIIX, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, ON_BOARD, 0 },
  364. {DEVID_PIIX4U2, "PIIX4", PCI_PIIX, ATA66_PIIX, INIT_PIIX, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, ON_BOARD, 0 },
  365. {DEVID_PIIX4NX, "PIIX4", PCI_PIIX, NULL, INIT_PIIX, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, ON_BOARD, 0 },
  366. {DEVID_ICH2, "ICH2",  PCI_PIIX, ATA66_PIIX, INIT_PIIX, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, ON_BOARD, 0 },
  367. {DEVID_ICH2M, "ICH2M", PCI_PIIX, ATA66_PIIX, INIT_PIIX, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, ON_BOARD, 0 },
  368. {DEVID_ICH3M, "ICH3M", PCI_PIIX, ATA66_PIIX, INIT_PIIX, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, ON_BOARD, 0 },
  369. {DEVID_ICH3, "ICH3",  PCI_PIIX, ATA66_PIIX, INIT_PIIX, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, ON_BOARD, 0 },
  370. {DEVID_ICH4, "ICH4",  PCI_PIIX, ATA66_PIIX, INIT_PIIX, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, ON_BOARD, 0 },
  371. {DEVID_CICH, "C-ICH", PCI_PIIX, ATA66_PIIX, INIT_PIIX, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, ON_BOARD, 0 },
  372. {DEVID_VIA_IDE, "VIA_IDE", NULL, NULL, NULL, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, ON_BOARD, 0 },
  373. {DEVID_MR_IDE, "VP_IDE", PCI_VIA82CXXX, ATA66_VIA82CXXX,INIT_VIA82CXXX, DMA_VIA82CXXX, {{0x40,0x02,0x02}, {0x40,0x01,0x01}},  ON_BOARD, 0 },
  374. {DEVID_VP_IDE, "VP_IDE", PCI_VIA82CXXX, ATA66_VIA82CXXX,INIT_VIA82CXXX, DMA_VIA82CXXX, {{0x40,0x02,0x02}, {0x40,0x01,0x01}},  ON_BOARD, 0 },
  375. #ifndef CONFIG_PDC202XX_FORCE
  376.         {DEVID_PDC20246,"PDC20246", PCI_PDC202XX, NULL, INIT_PDC202XX, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, OFF_BOARD, 16 },
  377.         {DEVID_PDC20262,"PDC20262", PCI_PDC202XX, ATA66_PDC202XX, INIT_PDC202XX, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, OFF_BOARD, 48 },
  378.         {DEVID_PDC20265,"PDC20265", PCI_PDC202XX, ATA66_PDC202XX, INIT_PDC202XX, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, OFF_BOARD, 48 },
  379.         {DEVID_PDC20267,"PDC20267", PCI_PDC202XX, ATA66_PDC202XX, INIT_PDC202XX, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, OFF_BOARD, 48 },
  380. #else /* !CONFIG_PDC202XX_FORCE */
  381. {DEVID_PDC20246,"PDC20246", PCI_PDC202XX, NULL, INIT_PDC202XX, NULL, {{0x50,0x02,0x02}, {0x50,0x04,0x04}},  OFF_BOARD, 16 },
  382. {DEVID_PDC20262,"PDC20262", PCI_PDC202XX, ATA66_PDC202XX, INIT_PDC202XX, NULL, {{0x50,0x02,0x02}, {0x50,0x04,0x04}}, OFF_BOARD, 48 },
  383. {DEVID_PDC20265,"PDC20265", PCI_PDC202XX, ATA66_PDC202XX, INIT_PDC202XX, NULL, {{0x50,0x02,0x02}, {0x50,0x04,0x04}}, OFF_BOARD, 48 },
  384. {DEVID_PDC20267,"PDC20267", PCI_PDC202XX, ATA66_PDC202XX, INIT_PDC202XX, NULL, {{0x50,0x02,0x02}, {0x50,0x04,0x04}}, OFF_BOARD, 48 },
  385. #endif
  386. {DEVID_PDC20268,"PDC20268", PCI_PDC202XX, ATA66_PDC202XX, INIT_PDC202XX, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, OFF_BOARD, 0 },
  387. /* Promise used a different PCI ident for the raid card apparently to try and
  388.    prevent Linux detecting it and using our own raid code. We want to detect
  389.    it for the ataraid drivers, so we have to list both here.. */
  390. {DEVID_PDC20270,"PDC20270", PCI_PDC202XX, ATA66_PDC202XX, INIT_PDC202XX, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, OFF_BOARD, 0 },
  391. {DEVID_PDC20269,"PDC20269", PCI_PDC202XX, ATA66_PDC202XX,  INIT_PDC202XX, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, OFF_BOARD, 0 },
  392. {DEVID_PDC20275,"PDC20275", PCI_PDC202XX, ATA66_PDC202XX, INIT_PDC202XX, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, OFF_BOARD, 0 },
  393. {DEVID_PDC20276,"PDC20276", PCI_PDC202XX, ATA66_PDC202XX, INIT_PDC202XX, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, OFF_BOARD, 0 },
  394. {DEVID_RZ1000, "RZ1000", NULL, NULL, INIT_RZ1000, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}},  ON_BOARD, 0 },
  395. {DEVID_RZ1001, "RZ1001", NULL, NULL, INIT_RZ1000, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}},  ON_BOARD, 0 },
  396. {DEVID_SAMURAI, "SAMURAI", NULL, NULL, INIT_SAMURAI, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, ON_BOARD, 0 },
  397. {DEVID_CMD640, "CMD640", NULL, NULL, IDE_IGNORE, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}},  ON_BOARD, 0 },
  398. {DEVID_NS87410, "NS87410", NULL, NULL, NULL, NULL, {{0x43,0x08,0x08}, {0x47,0x08,0x08}},  ON_BOARD, 0 },
  399. {DEVID_SIS5513, "SIS5513", PCI_SIS5513, ATA66_SIS5513, INIT_SIS5513, NULL, {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},  ON_BOARD, 0 },
  400. {DEVID_CMD643, "CMD643", PCI_CMD64X, NULL, INIT_CMD64X, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, ON_BOARD, 0 },
  401. {DEVID_CMD646, "CMD646", PCI_CMD64X, NULL, INIT_CMD64X, NULL, {{0x00,0x00,0x00}, {0x51,0x80,0x80}},  ON_BOARD, 0 },
  402. {DEVID_CMD648, "CMD648", PCI_CMD64X, ATA66_CMD64X, INIT_CMD64X, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, ON_BOARD, 0 },
  403. {DEVID_CMD649, "CMD649", PCI_CMD64X, ATA66_CMD64X, INIT_CMD64X, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, ON_BOARD, 0 },
  404. #ifndef CONFIG_BLK_DEV_CMD680
  405. {DEVID_CMD680, "CMD680", NULL, NULL, NULL, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, ON_BOARD, 0 },
  406. #else /* CONFIG_BLK_DEV_CMD680 */
  407. {DEVID_CMD680, "CMD680", PCI_CMD64X, ATA66_CMD64X, INIT_CMD64X, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, ON_BOARD, 0 },
  408. #endif /* !CONFIG_BLK_DEV_CMD680 */
  409. {DEVID_HT6565, "HT6565", NULL, NULL, NULL, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}},  ON_BOARD, 0 },
  410. {DEVID_OPTI621, "OPTI621", NULL, NULL, INIT_OPTI621, NULL, {{0x45,0x80,0x00}, {0x40,0x08,0x00}},  ON_BOARD, 0 },
  411. {DEVID_OPTI621X,"OPTI621X", NULL, NULL, INIT_OPTI621, NULL, {{0x45,0x80,0x00}, {0x40,0x08,0x00}},  ON_BOARD, 0 },
  412. {DEVID_TRM290, "TRM290", NULL, NULL, INIT_TRM290, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}},  ON_BOARD, 0 },
  413. {DEVID_NS87415, "NS87415", NULL, NULL, INIT_NS87415, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}},  ON_BOARD, 0 },
  414. {DEVID_AEC6210, "AEC6210", PCI_AEC62XX, NULL, INIT_AEC62XX, DMA_AEC62XX, {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},  OFF_BOARD, 0 },
  415. {DEVID_AEC6260, "AEC6260", PCI_AEC62XX, ATA66_AEC62XX, INIT_AEC62XX, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, NEVER_BOARD, 0 },
  416. {DEVID_AEC6260R,"AEC6260R", PCI_AEC62XX, ATA66_AEC62XX, INIT_AEC62XX, NULL, {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, OFF_BOARD, 0 },
  417. {DEVID_W82C105, "W82C105", PCI_W82C105, NULL, INIT_W82C105, DMA_W82C105, {{0x40,0x01,0x01}, {0x40,0x10,0x10}},  ON_BOARD, 0 },
  418. {DEVID_UM8673F, "UM8673F", NULL, NULL, NULL, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, ON_BOARD, 0 },
  419. {DEVID_UM8886A, "UM8886A", NULL, NULL, NULL, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, ON_BOARD, 0 },
  420. {DEVID_UM8886BF,"UM8886BF", NULL, NULL, NULL, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}},  ON_BOARD, 0 },
  421. {DEVID_HPT34X, "HPT34X", PCI_HPT34X, NULL, INIT_HPT34X, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, NEVER_BOARD, 16 },
  422. {DEVID_HPT366, "HPT366", PCI_HPT366, ATA66_HPT366, INIT_HPT366, DMA_HPT366, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, OFF_BOARD, 240 },
  423. {DEVID_ALI15X3, "ALI15X3", PCI_ALI15X3, ATA66_ALI15X3, INIT_ALI15X3, DMA_ALI15X3, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, ON_BOARD, 0 },
  424. {DEVID_CY82C693,"CY82C693", PCI_CY82C693, NULL, INIT_CY82C693, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, ON_BOARD, 0 },
  425. {DEVID_HINT, "HINT_IDE", NULL, NULL, NULL, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, ON_BOARD, 0 },
  426. {DEVID_CS5530, "CS5530", PCI_CS5530, NULL, INIT_CS5530, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, ON_BOARD, 0 },
  427. {DEVID_AMD7401, "AMD7401", NULL, NULL, NULL, DMA_AMD74XX, {{0x40,0x01,0x01}, {0x40,0x02,0x02}}, ON_BOARD, 0 },
  428. {DEVID_AMD7409, "AMD7409", PCI_AMD74XX, ATA66_AMD74XX, INIT_AMD74XX, DMA_AMD74XX, {{0x40,0x01,0x01}, {0x40,0x02,0x02}}, ON_BOARD, 0 },
  429. {DEVID_AMD7411, "AMD7411", PCI_AMD74XX, ATA66_AMD74XX, INIT_AMD74XX, DMA_AMD74XX, {{0x40,0x01,0x01}, {0x40,0x02,0x02}}, ON_BOARD, 0 },
  430. {DEVID_AMD7441, "AMD7441", PCI_AMD74XX, ATA66_AMD74XX, INIT_AMD74XX, DMA_AMD74XX, {{0x40,0x01,0x01}, {0x40,0x02,0x02}}, ON_BOARD, 0 },
  431. {DEVID_PDCADMA, "PDCADMA", PCI_PDCADMA, ATA66_PDCADMA, INIT_PDCADMA, DMA_PDCADMA, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, OFF_BOARD, 0 },
  432. {DEVID_SLC90E66,"SLC90E66", PCI_SLC90E66, ATA66_SLC90E66, INIT_SLC90E66, NULL, {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, ON_BOARD, 0 },
  433.         {DEVID_OSB4,    "ServerWorks OSB4", PCI_SVWKS, ATA66_SVWKS, INIT_SVWKS, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, ON_BOARD, 0 },
  434. {DEVID_CSB5, "ServerWorks CSB5", PCI_SVWKS, ATA66_SVWKS, INIT_SVWKS, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, ON_BOARD, 0 },
  435. {DEVID_ITE8172G,"IT8172G", PCI_IT8172, NULL, INIT_IT8172, NULL, {{0x00,0x00,0x00}, {0x40,0x00,0x01}}, ON_BOARD, 0 },
  436. {IDE_PCI_DEVID_NULL, "PCI_IDE", NULL, NULL, NULL, NULL, {{0x00,0x00,0x00}, {0x00,0x00,0x00}},  ON_BOARD, 0 }};
  437. /*
  438.  * This allows offboard ide-pci cards the enable a BIOS, verify interrupt
  439.  * settings of split-mirror pci-config space, place chipset into init-mode,
  440.  * and/or preserve an interrupt if the card is not native ide support.
  441.  */
  442. static unsigned int __init ide_special_settings (struct pci_dev *dev, const char *name)
  443. {
  444. switch(dev->device) {
  445. case PCI_DEVICE_ID_TTI_HPT366:
  446. case PCI_DEVICE_ID_PROMISE_20246:
  447. case PCI_DEVICE_ID_PROMISE_20262:
  448. case PCI_DEVICE_ID_PROMISE_20265:
  449. case PCI_DEVICE_ID_PROMISE_20267:
  450. case PCI_DEVICE_ID_PROMISE_20268:
  451. case PCI_DEVICE_ID_PROMISE_20270:
  452. case PCI_DEVICE_ID_PROMISE_20269:
  453. case PCI_DEVICE_ID_PROMISE_20275:
  454. case PCI_DEVICE_ID_PROMISE_20276:
  455. case PCI_DEVICE_ID_ARTOP_ATP850UF:
  456. case PCI_DEVICE_ID_ARTOP_ATP860:
  457. case PCI_DEVICE_ID_ARTOP_ATP860R:
  458. return dev->irq;
  459. default:
  460. break;
  461. }
  462. return 0;
  463. }
  464. /*
  465.  * Match a PCI IDE port against an entry in ide_hwifs[],
  466.  * based on io_base port if possible.
  467.  */
  468. static ide_hwif_t __init *ide_match_hwif (unsigned long io_base, byte bootable, const char *name)
  469. {
  470. int h;
  471. ide_hwif_t *hwif;
  472. /*
  473.  * Look for a hwif with matching io_base specified using
  474.  * parameters to ide_setup().
  475.  */
  476. for (h = 0; h < MAX_HWIFS; ++h) {
  477. hwif = &ide_hwifs[h];
  478. if (hwif->io_ports[IDE_DATA_OFFSET] == io_base) {
  479. if (hwif->chipset == ide_generic)
  480. return hwif; /* a perfect match */
  481. }
  482. }
  483. /*
  484.  * Look for a hwif with matching io_base default value.
  485.  * If chipset is "ide_unknown", then claim that hwif slot.
  486.  * Otherwise, some other chipset has already claimed it..  :(
  487.  */
  488. for (h = 0; h < MAX_HWIFS; ++h) {
  489. hwif = &ide_hwifs[h];
  490. if (hwif->io_ports[IDE_DATA_OFFSET] == io_base) {
  491. if (hwif->chipset == ide_unknown)
  492. return hwif; /* match */
  493. printk("%s: port 0x%04lx already claimed by %sn", name, io_base, hwif->name);
  494. return NULL; /* already claimed */
  495. }
  496. }
  497. /*
  498.  * Okay, there is no hwif matching our io_base,
  499.  * so we'll just claim an unassigned slot.
  500.  * Give preference to claiming other slots before claiming ide0/ide1,
  501.  * just in case there's another interface yet-to-be-scanned
  502.  * which uses ports 1f0/170 (the ide0/ide1 defaults).
  503.  *
  504.  * Unless there is a bootable card that does not use the standard
  505.  * ports 1f0/170 (the ide0/ide1 defaults). The (bootable) flag.
  506.  */
  507. if (bootable) {
  508. for (h = 0; h < MAX_HWIFS; ++h) {
  509. hwif = &ide_hwifs[h];
  510. if (hwif->chipset == ide_unknown)
  511. return hwif; /* pick an unused entry */
  512. }
  513. } else {
  514. for (h = 2; h < MAX_HWIFS; ++h) {
  515. hwif = ide_hwifs + h;
  516. if (hwif->chipset == ide_unknown)
  517. return hwif; /* pick an unused entry */
  518. }
  519. }
  520. for (h = 0; h < 2; ++h) {
  521. hwif = ide_hwifs + h;
  522. if (hwif->chipset == ide_unknown)
  523. return hwif; /* pick an unused entry */
  524. }
  525. printk("%s: too many IDE interfaces, no room in tablen", name);
  526. return NULL;
  527. }
  528. static int __init ide_setup_pci_baseregs (struct pci_dev *dev, const char *name)
  529. {
  530. byte reg, progif = 0;
  531. /*
  532.  * Place both IDE interfaces into PCI "native" mode:
  533.  */
  534. if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) || (progif & 5) != 5) {
  535. if ((progif & 0xa) != 0xa) {
  536. printk("%s: device not capable of full native PCI moden", name);
  537. return 1;
  538. }
  539. printk("%s: placing both ports into native PCI moden", name);
  540. (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5);
  541. if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) || (progif & 5) != 5) {
  542. printk("%s: rewrite of PROGIF failed, wanted 0x%04x, got 0x%04xn", name, progif|5, progif);
  543. return 1;
  544. }
  545. }
  546. /*
  547.  * Setup base registers for IDE command/control spaces for each interface:
  548.  */
  549. for (reg = 0; reg < 4; reg++) {
  550. struct resource *res = dev->resource + reg;
  551. if ((res->flags & IORESOURCE_IO) == 0)
  552. continue;
  553. if (!res->start) {
  554. printk("%s: Missing I/O address #%dn", name, reg);
  555. return 1;
  556. }
  557. }
  558. return 0;
  559. }
  560. /*
  561.  * ide_setup_pci_device() looks at the primary/secondary interfaces
  562.  * on a PCI IDE device and, if they are enabled, prepares the IDE driver
  563.  * for use with them.  This generic code works for most PCI chipsets.
  564.  *
  565.  * One thing that is not standardized is the location of the
  566.  * primary/secondary interface "enable/disable" bits.  For chipsets that
  567.  * we "know" about, this information is in the ide_pci_device_t struct;
  568.  * for all other chipsets, we just assume both interfaces are enabled.
  569.  */
  570. static void __init ide_setup_pci_device (struct pci_dev *dev, ide_pci_device_t *d)
  571. {
  572. unsigned int port, at_least_one_hwif_enabled = 0, autodma = 0, pciirq = 0;
  573. unsigned short pcicmd = 0, tried_config = 0;
  574. byte tmp = 0;
  575. ide_hwif_t *hwif, *mate = NULL;
  576. unsigned int class_rev;
  577. static int secondpdc = 0;
  578. #ifdef CONFIG_IDEDMA_AUTO
  579. if (!noautodma)
  580. autodma = 1;
  581. #endif
  582. if (d->init_hwif == IDE_NO_DRIVER) {
  583. printk(KERN_WARNING "%s: detected chipset, but driver not compiled in!n", d->name);
  584. d->init_hwif = NULL;
  585. }
  586. if (pci_enable_device(dev)) {
  587. if(pci_enable_device_bars(dev, 1<<4))
  588. {
  589. printk(KERN_WARNING "%s: (ide_setup_pci_device:) Could not enable device.n", d->name);
  590. return;
  591. }
  592. printk(KERN_INFO "%s: BIOS setup was incomplete.n", d->name);
  593. }
  594. check_if_enabled:
  595. if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd)) {
  596. printk("%s: error accessing PCI regsn", d->name);
  597. return;
  598. }
  599. if (!(pcicmd & PCI_COMMAND_IO)) { /* is device disabled? */
  600. /*
  601.  * PnP BIOS was *supposed* to have set this device up for us,
  602.  * but we can do it ourselves, so long as the BIOS has assigned an IRQ
  603.  *  (or possibly the device is using a "legacy header" for IRQs).
  604.  * Maybe the user deliberately *disabled* the device,
  605.  * but we'll eventually ignore it again if no drives respond.
  606.  */
  607. if (tried_config++
  608.  || ide_setup_pci_baseregs(dev, d->name)
  609.  || pci_write_config_word(dev, PCI_COMMAND, pcicmd | PCI_COMMAND_IO)) {
  610. printk("%s: device disabled (BIOS)n", d->name);
  611. return;
  612. }
  613. autodma = 0; /* default DMA off if we had to configure it here */
  614. goto check_if_enabled;
  615. }
  616. if (tried_config)
  617. printk("%s: device enabled (Linux)n", d->name);
  618. pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
  619. class_rev &= 0xff;
  620. if (IDE_PCI_DEVID_EQ(d->devid, DEVID_HPT34X)) {
  621. /* see comments in hpt34x.c on why..... */
  622. char *chipset_names[] = {"HPT343", "HPT345"};
  623. strcpy(d->name, chipset_names[(pcicmd & PCI_COMMAND_MEMORY) ? 1 : 0]);
  624. d->bootable = (pcicmd & PCI_COMMAND_MEMORY) ? OFF_BOARD : NEVER_BOARD;
  625. }
  626. printk("%s: chipset revision %dn", d->name, class_rev);
  627. /*
  628.  * Can we trust the reported IRQ?
  629.  */
  630. pciirq = dev->irq;
  631. if (dev->class >> 8 == PCI_CLASS_STORAGE_RAID)
  632. {
  633.     /*  By rights we want to ignore these, but the Promise Fastrak
  634.  * people have some strange ideas about proprietary so we have
  635.  * to act otherwise on those. The supertrak however we need
  636.  * to skip 
  637.  */
  638. if (IDE_PCI_DEVID_EQ(d->devid, DEVID_PDC20265))
  639. {
  640. printk(KERN_INFO "ide: Found promise 20265 in RAID mode.n");
  641. if(dev->bus->self && dev->bus->self->vendor == PCI_VENDOR_ID_INTEL &&
  642.    dev->bus->self->device == PCI_DEVICE_ID_INTEL_I960)
  643. {
  644. printk(KERN_INFO "ide: Skipping Promise PDC20265 attached to I2O RAID controller.n");
  645. return;
  646. }
  647. }
  648. /* Its attached to something else, just a random bridge.
  649.    Suspect a fastrak and fall through */
  650. }
  651. if ((dev->class & ~(0xfa)) != ((PCI_CLASS_STORAGE_IDE << 8) | 5)) {
  652. printk("%s: not 100%% native mode: will probe irqs latern", d->name);
  653. /*
  654.  * This allows offboard ide-pci cards the enable a BIOS,
  655.  * verify interrupt settings of split-mirror pci-config
  656.  * space, place chipset into init-mode, and/or preserve
  657.  * an interrupt if the card is not native ide support.
  658.  */
  659. pciirq = (d->init_chipset) ? d->init_chipset(dev, d->name) : ide_special_settings(dev, d->name);
  660. } else if (tried_config) {
  661. printk("%s: will probe irqs latern", d->name);
  662. pciirq = 0;
  663. } else if (!pciirq) {
  664. printk("%s: bad irq (%d): will probe latern", d->name, pciirq);
  665. pciirq = 0;
  666. } else {
  667. if (d->init_chipset)
  668. (void) d->init_chipset(dev, d->name);
  669. #ifdef __sparc__
  670. printk("%s: 100%% native mode on irq %sn",
  671.        d->name, __irq_itoa(pciirq));
  672. #else
  673. printk("%s: 100%% native mode on irq %dn", d->name, pciirq);
  674. #endif
  675. }
  676. /*
  677.  * Set up the IDE ports
  678.  */
  679. for (port = 0; port <= 1; ++port) {
  680. unsigned long base = 0, ctl = 0;
  681. ide_pci_enablebit_t *e = &(d->enablebits[port]);
  682. /* 
  683.  * If this is a Promise FakeRaid controller, the 2nd controller will be marked as 
  684.  * disabled while it is actually there and enabled by the bios for raid purposes. 
  685.  * Skip the normal "is it enabled" test for those.
  686.  */
  687. if ((IDE_PCI_DEVID_EQ(d->devid, DEVID_PDC20265)) && (secondpdc++==1) && (port==1)  ) 
  688. goto controller_ok;
  689. if ((IDE_PCI_DEVID_EQ(d->devid, DEVID_PDC20262)) && (secondpdc++==1) && (port==1)  ) 
  690. goto controller_ok;
  691. if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) || (tmp & e->mask) != e->val))
  692. continue; /* port not enabled */
  693. controller_ok:
  694. if (IDE_PCI_DEVID_EQ(d->devid, DEVID_HPT366) && (port) && (class_rev < 0x03))
  695. return;
  696. if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE || (dev->class & (port ? 4 : 1)) != 0) {
  697. ctl  = dev->resource[(2*port)+1].start;
  698. base = dev->resource[2*port].start;
  699. if (!(ctl & PCI_BASE_ADDRESS_IO_MASK) ||
  700.     !(base & PCI_BASE_ADDRESS_IO_MASK)) {
  701. printk("%s: IO baseregs (BIOS) are reported as MEM, report to <andre@linux-ide.org>.n", d->name);
  702. #if 0
  703. /* FIXME! This really should check that it really gets the IO/MEM part right! */
  704. continue;
  705. #endif
  706. }
  707. }
  708. if ((ctl && !base) || (base && !ctl)) {
  709. printk("%s: inconsistent baseregs (BIOS) for port %d, skippingn", d->name, port);
  710. continue;
  711. }
  712. if (!ctl)
  713. ctl = port ? 0x374 : 0x3f4; /* use default value */
  714. if (!base)
  715. base = port ? 0x170 : 0x1f0; /* use default value */
  716. if ((hwif = ide_match_hwif(base, d->bootable, d->name)) == NULL)
  717. continue; /* no room in ide_hwifs[] */
  718. if (hwif->io_ports[IDE_DATA_OFFSET] != base) {
  719. ide_init_hwif_ports(&hwif->hw, base, (ctl | 2), NULL);
  720. memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports));
  721. hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
  722. }
  723. hwif->chipset = ide_pci;
  724. hwif->pci_dev = dev;
  725. hwif->pci_devid = d->devid;
  726. hwif->channel = port;
  727. if (!hwif->irq)
  728. hwif->irq = pciirq;
  729. if (mate) {
  730. hwif->mate = mate;
  731. mate->mate = hwif;
  732. if (IDE_PCI_DEVID_EQ(d->devid, DEVID_AEC6210)) {
  733. hwif->serialized = 1;
  734. mate->serialized = 1;
  735. }
  736. }
  737. if (IDE_PCI_DEVID_EQ(d->devid, DEVID_UM8886A) ||
  738.     IDE_PCI_DEVID_EQ(d->devid, DEVID_UM8886BF) ||
  739.     IDE_PCI_DEVID_EQ(d->devid, DEVID_UM8673F)) {
  740. hwif->irq = hwif->channel ? 15 : 14;
  741. goto bypass_umc_dma;
  742. }
  743. if (IDE_PCI_DEVID_EQ(d->devid, DEVID_MPIIX))
  744. goto bypass_piix_dma;
  745. if (IDE_PCI_DEVID_EQ(d->devid, DEVID_PDCADMA))
  746. goto bypass_legacy_dma;
  747. if (hwif->udma_four) {
  748. printk("%s: ATA-66/100 forced bit set (WARNING)!!n", d->name);
  749. } else {
  750. hwif->udma_four = (d->ata66_check) ? d->ata66_check(hwif) : 0;
  751. }
  752. #ifdef CONFIG_BLK_DEV_IDEDMA
  753. if (IDE_PCI_DEVID_EQ(d->devid, DEVID_SIS5513) ||
  754.     IDE_PCI_DEVID_EQ(d->devid, DEVID_AEC6260) ||
  755.     IDE_PCI_DEVID_EQ(d->devid, DEVID_PIIX4NX) ||
  756.     IDE_PCI_DEVID_EQ(d->devid, DEVID_HPT34X)  ||
  757.     IDE_PCI_DEVID_EQ(d->devid, DEVID_VIA_IDE) ||
  758.     IDE_PCI_DEVID_EQ(d->devid, DEVID_MR_IDE)  ||
  759.     IDE_PCI_DEVID_EQ(d->devid, DEVID_VP_IDE))
  760. autodma = 0;
  761. if (autodma)
  762. hwif->autodma = 1;
  763. if (IDE_PCI_DEVID_EQ(d->devid, DEVID_PDC20246) ||
  764.     IDE_PCI_DEVID_EQ(d->devid, DEVID_PDC20262) ||
  765.     IDE_PCI_DEVID_EQ(d->devid, DEVID_PDC20265) ||
  766.     IDE_PCI_DEVID_EQ(d->devid, DEVID_PDC20267) ||
  767.     IDE_PCI_DEVID_EQ(d->devid, DEVID_PDC20268) ||
  768.     IDE_PCI_DEVID_EQ(d->devid, DEVID_PDC20270) ||
  769.     IDE_PCI_DEVID_EQ(d->devid, DEVID_PDC20269) ||
  770.     IDE_PCI_DEVID_EQ(d->devid, DEVID_PDC20275) ||
  771.     IDE_PCI_DEVID_EQ(d->devid, DEVID_PDC20276) ||
  772.     IDE_PCI_DEVID_EQ(d->devid, DEVID_AEC6210) ||
  773.     IDE_PCI_DEVID_EQ(d->devid, DEVID_AEC6260) ||
  774.     IDE_PCI_DEVID_EQ(d->devid, DEVID_AEC6260R) ||
  775.     IDE_PCI_DEVID_EQ(d->devid, DEVID_HPT34X) ||
  776.     IDE_PCI_DEVID_EQ(d->devid, DEVID_HPT366) ||
  777.     IDE_PCI_DEVID_EQ(d->devid, DEVID_CS5530) ||
  778.     IDE_PCI_DEVID_EQ(d->devid, DEVID_CY82C693) ||
  779.     IDE_PCI_DEVID_EQ(d->devid, DEVID_CMD646) ||
  780.     IDE_PCI_DEVID_EQ(d->devid, DEVID_CMD648) ||
  781.     IDE_PCI_DEVID_EQ(d->devid, DEVID_CMD649) ||
  782.     IDE_PCI_DEVID_EQ(d->devid, DEVID_CMD680) ||
  783.     IDE_PCI_DEVID_EQ(d->devid, DEVID_OSB4) ||
  784.     ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && (dev->class & 0x80))) {
  785. unsigned long dma_base = ide_get_or_set_dma_base(hwif, (!mate && d->extra) ? d->extra : 0, d->name);
  786. if (dma_base && !(pcicmd & PCI_COMMAND_MASTER)) {
  787. /*
  788.      * Set up BM-DMA capability (PnP BIOS should have done this)
  789.      */
  790.      if (!IDE_PCI_DEVID_EQ(d->devid, DEVID_CS5530))
  791. hwif->autodma = 0; /* default DMA off if we had to configure it here */
  792. (void) pci_write_config_word(dev, PCI_COMMAND, pcicmd | PCI_COMMAND_MASTER);
  793. if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) || !(pcicmd & PCI_COMMAND_MASTER)) {
  794. printk("%s: %s error updating PCICMDn", hwif->name, d->name);
  795. dma_base = 0;
  796. }
  797. }
  798. if (dma_base) {
  799. if (d->dma_init) {
  800. d->dma_init(hwif, dma_base);
  801. } else {
  802. ide_setup_dma(hwif, dma_base, 8);
  803. }
  804. } else {
  805. printk("%s: %s Bus-Master DMA disabled (BIOS)n", hwif->name, d->name);
  806. }
  807. }
  808. #endif /* CONFIG_BLK_DEV_IDEDMA */
  809. bypass_legacy_dma:
  810. bypass_piix_dma:
  811. bypass_umc_dma:
  812. if (d->init_hwif)  /* Call chipset-specific routine for each enabled hwif */
  813. d->init_hwif(hwif);
  814. mate = hwif;
  815. at_least_one_hwif_enabled = 1;
  816. }
  817. if (!at_least_one_hwif_enabled)
  818. printk("%s: neither IDE port enabled (BIOS)n", d->name);
  819. }
  820. static void __init pdc20270_device_order_fixup (struct pci_dev *dev, ide_pci_device_t *d)
  821. {
  822. struct pci_dev *dev2 = NULL, *findev;
  823. ide_pci_device_t *d2;
  824. if ((dev->bus->self &&
  825.      dev->bus->self->vendor == PCI_VENDOR_ID_DEC) &&
  826.     (dev->bus->self->device == PCI_DEVICE_ID_DEC_21150)) {
  827. if (PCI_SLOT(dev->devfn) & 2) {
  828. return;
  829. }
  830. d->extra = 0;
  831. pci_for_each_dev(findev) {
  832. if ((findev->vendor == dev->vendor) &&
  833.     (findev->device == dev->device) &&
  834.     (PCI_SLOT(findev->devfn) & 2)) {
  835. byte irq = 0, irq2 = 0;
  836. dev2 = findev;
  837. pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
  838. pci_read_config_byte(dev2, PCI_INTERRUPT_LINE, &irq2);
  839.                                 if (irq != irq2) {
  840. dev2->irq = dev->irq;
  841.                                         pci_write_config_byte(dev2, PCI_INTERRUPT_LINE, irq);
  842.                                 }
  843. }
  844. }
  845. }
  846. printk("%s: IDE controller on PCI bus %02x dev %02xn", d->name, dev->bus->number, dev->devfn);
  847. ide_setup_pci_device(dev, d);
  848. if (!dev2)
  849. return;
  850. d2 = d;
  851. printk("%s: IDE controller on PCI bus %02x dev %02xn", d2->name, dev2->bus->number, dev2->devfn);
  852. ide_setup_pci_device(dev2, d2);
  853. }
  854. static void __init hpt366_device_order_fixup (struct pci_dev *dev, ide_pci_device_t *d)
  855. {
  856. struct pci_dev *dev2 = NULL, *findev;
  857. ide_pci_device_t *d2;
  858. unsigned char pin1 = 0, pin2 = 0;
  859. unsigned int class_rev;
  860. char *chipset_names[] = {"HPT366", "HPT366", "HPT368", "HPT370", "HPT370A", "HPT372"};
  861. if (PCI_FUNC(dev->devfn) & 1)
  862. return;
  863. pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
  864. class_rev &= 0xff;
  865. if (class_rev > 5)
  866. class_rev = 5;
  867. strcpy(d->name, chipset_names[class_rev]);
  868. switch(class_rev) {
  869. case 4:
  870. case 3: printk("%s: IDE controller on PCI bus %02x dev %02xn", d->name, dev->bus->number, dev->devfn);
  871. ide_setup_pci_device(dev, d);
  872. return;
  873. default: break;
  874. }
  875. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin1);
  876. pci_for_each_dev(findev) {
  877. if ((findev->vendor == dev->vendor) &&
  878.     (findev->device == dev->device) &&
  879.     ((findev->devfn - dev->devfn) == 1) &&
  880.     (PCI_FUNC(findev->devfn) & 1)) {
  881. dev2 = findev;
  882. pci_read_config_byte(dev2, PCI_INTERRUPT_PIN, &pin2);
  883. hpt363_shared_pin = (pin1 != pin2) ? 1 : 0;
  884. hpt363_shared_irq = (dev->irq == dev2->irq) ? 1 : 0;
  885. if (hpt363_shared_pin && hpt363_shared_irq) {
  886. d->bootable = ON_BOARD;
  887. printk("%s: onboard version of chipset, pin1=%d pin2=%dn", d->name, pin1, pin2);
  888. #if 0
  889. /* I forgot why I did this once, but it fixed something. */
  890. pci_write_config_byte(dev2, PCI_INTERRUPT_PIN, dev->irq);
  891. printk("PCI: %s: Fixing interrupt %d pin %d to ZERO n", d->name, dev2->irq, pin2);
  892. pci_write_config_byte(dev2, PCI_INTERRUPT_LINE, 0);
  893. #endif
  894. }
  895. break;
  896. }
  897. }
  898. printk("%s: IDE controller on PCI bus %02x dev %02xn", d->name, dev->bus->number, dev->devfn);
  899. ide_setup_pci_device(dev, d);
  900. if (!dev2)
  901. return;
  902. d2 = d;
  903. printk("%s: IDE controller on PCI bus %02x dev %02xn", d2->name, dev2->bus->number, dev2->devfn);
  904. ide_setup_pci_device(dev2, d2);
  905. }
  906. /*
  907.  * ide_scan_pcibus() gets invoked at boot time from ide.c.
  908.  * It finds all PCI IDE controllers and calls ide_setup_pci_device for them.
  909.  */
  910. void __init ide_scan_pcidev (struct pci_dev *dev)
  911. {
  912. ide_pci_devid_t devid;
  913. ide_pci_device_t *d;
  914. devid.vid = dev->vendor;
  915. devid.did = dev->device;
  916. for (d = ide_pci_chipsets; d->devid.vid && !IDE_PCI_DEVID_EQ(d->devid, devid); ++d);
  917. if (d->init_hwif == IDE_IGNORE)
  918. printk("%s: ignored by ide_scan_pci_device() (uses own driver)n", d->name);
  919. else if (IDE_PCI_DEVID_EQ(d->devid, DEVID_OPTI621V) && !(PCI_FUNC(dev->devfn) & 1))
  920. return;
  921. else if (IDE_PCI_DEVID_EQ(d->devid, DEVID_CY82C693) && (!(PCI_FUNC(dev->devfn) & 1) || !((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)))
  922. return; /* CY82C693 is more than only a IDE controller */
  923. else if (IDE_PCI_DEVID_EQ(d->devid, DEVID_ITE8172G) && (!(PCI_FUNC(dev->devfn) & 1) || !((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)))
  924. return; /* IT8172G is also more than only an IDE controller */
  925. else if (IDE_PCI_DEVID_EQ(d->devid, DEVID_UM8886A) && !(PCI_FUNC(dev->devfn) & 1))
  926. return; /* UM8886A/BF pair */
  927. else if (IDE_PCI_DEVID_EQ(d->devid, DEVID_HPT366))
  928. hpt366_device_order_fixup(dev, d);
  929. else if (IDE_PCI_DEVID_EQ(d->devid, DEVID_PDC20270))
  930. pdc20270_device_order_fixup(dev, d);
  931. else if (!IDE_PCI_DEVID_EQ(d->devid, IDE_PCI_DEVID_NULL) || (dev->class >> 8) == PCI_CLASS_STORAGE_IDE) {
  932. if (IDE_PCI_DEVID_EQ(d->devid, IDE_PCI_DEVID_NULL))
  933. printk("%s: unknown IDE controller on PCI bus %02x device %02x, VID=%04x, DID=%04xn",
  934.        d->name, dev->bus->number, dev->devfn, devid.vid, devid.did);
  935. else
  936. printk("%s: IDE controller on PCI bus %02x dev %02xn", d->name, dev->bus->number, dev->devfn);
  937. ide_setup_pci_device(dev, d);
  938. }
  939. }
  940. void __init ide_scan_pcibus (int scan_direction)
  941. {
  942. struct pci_dev *dev;
  943. if (!scan_direction) {
  944. pci_for_each_dev(dev) {
  945. ide_scan_pcidev(dev);
  946. }
  947. } else {
  948. pci_for_each_dev_reverse(dev) {
  949. ide_scan_pcidev(dev);
  950. }
  951. }
  952. }