Subversion Repositories Kolibri OS

Rev

Rev 6946 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. format PE DLL native 0.05
  9. section '.flat' code readable writable executable
  10.  
  11. DEBUG           equ 1
  12. FDEBUG          equ 0
  13. DEBUG_IRQ       equ 0
  14.  
  15. USE_SINGLE_MODE equ  0   ; 1 = Single mode; 0 = Normal mode.
  16. USE_UNSOL_EV    equ  1   ; 1 = Use unsolicited events; 0 = Do not use unsolicited events.
  17.  
  18. TEST_VERSION_NUMBER  equ '019a'
  19.  
  20. ;Asper+ [
  21. SDO_TAG  equ 1        ;Output stream tag id (any number except 0)
  22. SDO_IDX  equ 4        ;Output stream index
  23. ;According to "Intel® I/O Controller Hub 6 (ICH6) High Definition Audio / AC ’97 Programmer’s Reference Manual (PRM) May 2005 Document"
  24. ;and "Intel® I/O Controller Hub 6 (ICH6) Family Datasheet" SDO0=4,
  25. ;but according to "High Definition Audio Specification Revision 1.0a June 17, 2010" SDO0 depends on the number of SDIs.
  26.  
  27. SDO_INT         equ 1 shl SDO_IDX       ;Output stream interrupt (must be power of 2)
  28. SDO_OFS         equ 0x80+(SDO_IDX*0x20) ;Output stream offset
  29. ;Asper+ ]
  30.  
  31. CURRENT_API     equ   0x0100      ;1.00
  32. COMPATIBLE_API  equ   0x0101      ;1.01
  33. API_VERSION     equ   (COMPATIBLE_API shl 16) or CURRENT_API
  34.  
  35. IRQ_REMAP       equ 0
  36. IRQ_LINE        equ 0
  37.  
  38. CPU_FREQ        equ  2600d
  39.  
  40. ; Vendors
  41. VID_INTEL         equ 0x8086
  42. VID_NVIDIA        equ 0x10DE
  43. VID_ATI           equ 0x1002
  44. VID_AMD           equ 0x1022
  45. VID_VIA           equ 0x1106
  46. VID_SIS           equ 0x1039
  47. VID_ULI           equ 0x10B9
  48. VID_CREATIVE      equ 0x1102
  49. VID_TERA          equ 0x6549
  50. VID_RDC           equ 0x17F3
  51. VID_VMWARE        equ 0x15AD
  52.  
  53. ; Devices
  54. ; Intel
  55. CTRL_INTEL_SCH2       equ  0x080a
  56. CTRL_INTEL_HPT        equ  0x0c0c
  57. CTRL_INTEL_0F04       equ  0x0F04
  58. CTRL_INTEL_CPT        equ  0x1c20
  59. CTRL_INTEL_PGB        equ  0x1d20
  60. CTRL_INTEL_PPT1       equ  0x1e20
  61. CTRL_INTEL_2284       equ  0x2284
  62. CTRL_INTEL_ICH6       equ  0x2668
  63. CTRL_INTEL_63XXESB    equ  0x269a
  64. CTRL_INTEL_ICH7       equ  0x27d8
  65. CTRL_INTEL_ICH8       equ  0x284b
  66. CTRL_INTEL_82801_UNK1 equ  0x2911
  67. CTRL_INTEL_ICH9       equ  0x293e
  68. CTRL_INTEL_ICH9_2     equ  0x293f
  69. CTRL_INTEL_ICH10      equ  0x3a3e
  70. CTRL_INTEL_ICH10_2    equ  0x3a6e
  71. CTRL_INTEL_PCH        equ  0x3b56
  72. CTRL_INTEL_PCH2       equ  0x3b57
  73. CTRL_INTEL_SCH        equ  0x811b
  74. CTRL_INTEL_LPT        equ  0x8c20
  75. CTRL_INTEL_8ca0       equ  0x8cA0
  76. CTRL_INTEL_8d20       equ  0x8d20
  77. CTRL_INTEL_8d21       equ  0x8d21
  78. CTRL_INTEL_A1F0       equ  0xA1F0
  79. CTRL_INTEL_A270       equ  0xA270
  80. CTRL_INTEL_9C20       equ  0x9c20
  81. CTRL_INTEL_9C21       equ  0x9c21
  82. CTRL_INTEL_9CA0       equ  0x9cA0
  83. CTRL_INTEL_A170       equ  0xA170
  84. CTRL_INTEL_9D70       equ  0x9D70
  85. CTRL_INTEL_5A98       equ  0x5A98
  86. ; Nvidia
  87. CTRL_NVIDIA_MCP51        equ  0x026c
  88. CTRL_NVIDIA_MCP55        equ  0x0371
  89. CTRL_NVIDIA_MCP61_1      equ  0x03e4
  90. CTRL_NVIDIA_MCP61_2      equ  0x03f0
  91. CTRL_NVIDIA_MCP65_1      equ  0x044a
  92. CTRL_NVIDIA_MCP65_2      equ  0x044b
  93. CTRL_NVIDIA_MCP67_1      equ  0x055c
  94. CTRL_NVIDIA_MCP67_2      equ  0x055d
  95. CTRL_NVIDIA_MCP78_1      equ  0x0774
  96. CTRL_NVIDIA_MCP78_2      equ  0x0775
  97. CTRL_NVIDIA_MCP78_3      equ  0x0776
  98. CTRL_NVIDIA_MCP78_4      equ  0x0777
  99. CTRL_NVIDIA_MCP73_1      equ  0x07fc
  100. CTRL_NVIDIA_MCP73_2      equ  0x07fd
  101. CTRL_NVIDIA_MCP79_1      equ  0x0ac0
  102. CTRL_NVIDIA_MCP79_2      equ  0x0ac1
  103. CTRL_NVIDIA_MCP79_3      equ  0x0ac2
  104. CTRL_NVIDIA_MCP79_4      equ  0x0ac3
  105. CTRL_NVIDIA_0BE2         equ  0x0be2
  106. CTRL_NVIDIA_0BE3         equ  0x0be3
  107. CTRL_NVIDIA_0BE4         equ  0x0be4
  108. CTRL_NVIDIA_GT100        equ  0x0be5
  109. CTRL_NVIDIA_GT106        equ  0x0be9
  110. CTRL_NVIDIA_GT108        equ  0x0bea
  111. CTRL_NVIDIA_GT104        equ  0x0beb
  112. CTRL_NVIDIA_GT116        equ  0x0bee
  113. CTRL_NVIDIA_MCP89_1      equ  0x0d94
  114. CTRL_NVIDIA_MCP89_2      equ  0x0d95
  115. CTRL_NVIDIA_MCP89_3      equ  0x0d96
  116. CTRL_NVIDIA_MCP89_4      equ  0x0d97
  117. CTRL_NVIDIA_GF119        equ  0x0e08
  118. CTRL_NVIDIA_GF110_1      equ  0x0e09
  119. CTRL_NVIDIA_GF110_2      equ  0x0e0c
  120. ; ATI
  121. CTRL_ATI_SB450           equ  0x437b
  122. CTRL_ATI_SB600           equ  0x4383
  123. ; ATI HDMI
  124. CTRL_ATI_RS600           equ  0x793b
  125. CTRL_ATI_RS690           equ  0x7919
  126. CTRL_ATI_RS780           equ  0x960f
  127. CTRL_ATI_RS_UNK1         equ  0x970f
  128. CTRL_ATI_R600            equ  0xaa00
  129. CTRL_ATI_RV630           equ  0xaa08
  130. CTRL_ATI_RV610           equ  0xaa10
  131. CTRL_ATI_RV670           equ  0xaa18
  132. CTRL_ATI_RV635           equ  0xaa20
  133. CTRL_ATI_RV620           equ  0xaa28
  134. CTRL_ATI_RV770           equ  0xaa30
  135. CTRL_ATI_RV730           equ  0xaa38
  136. CTRL_ATI_RV710           equ  0xaa40
  137. CTRL_ATI_RV740           equ  0xaa48
  138. ; AMD
  139. CTRL_AMD_HUDSON          equ  0x780d
  140. CTRL_AMD_RAVEN_RIDGE     equ  0x15e3
  141. ; VIA
  142. CTRL_VIA_VT82XX          equ  0x3288
  143. CTRL_VIA_VT61XX          equ  0x9140
  144. CTRL_VIA_VT71XX          equ  0x9170
  145. ; SiS
  146. CTRL_SIS_966             equ  0x7502
  147. ; ULI
  148. CTRL_ULI_M5461           equ  0x5461
  149. ; Creative
  150. CTRL_CREATIVE_CA0110_IBG     equ  0x0009
  151. CTRL_CREATIVE_SOUND_CORE3D_1 equ  0x0010
  152. CTRL_CREATIVE_SOUND_CORE3D_2 equ  0x0012
  153. ; Teradici
  154. CTRL_TERA_UNK1           equ  0x1200
  155. ; RDC Semiconductor
  156. CTRL_RDC_R3010           equ  0x3010
  157. ;VMware
  158. CTRL_VMWARE_UNK1         equ  0x1977
  159.  
  160.  
  161. ; driver types
  162. AZX_DRIVER_ICH           equ  0
  163. AZX_DRIVER_PCH           equ  1
  164. AZX_DRIVER_SCH           equ  2
  165. AZX_DRIVER_ATI           equ  3
  166. AZX_DRIVER_ATIHDMI       equ  4
  167. AZX_DRIVER_VIA           equ  5
  168. AZX_DRIVER_SIS           equ  6
  169. AZX_DRIVER_ULI           equ  7
  170. AZX_DRIVER_NVIDIA        equ  8
  171. AZX_DRIVER_TERA          equ  9
  172. AZX_DRIVER_CTX           equ  10
  173. AZX_DRIVER_GENERIC       equ  11
  174. AZX_NUM_DRIVERS          equ  12
  175.  
  176.  
  177. ; registers
  178.  
  179. ICH6_REG_GCAP            equ  0x00
  180. ICH6_REG_VMIN            equ  0x02
  181. ICH6_REG_VMAJ            equ  0x03
  182. ICH6_REG_OUTPAY          equ  0x04
  183. ICH6_REG_INPAY           equ  0x06
  184. ICH6_REG_GCTL            equ  0x08
  185.   ICH6_GCTL_RESET          equ  (1 shl 0)  ; controller reset
  186.   ICH6_GCTL_FCNTRL         equ  (1 shl 1)  ; flush control
  187.   ICH6_GCTL_UNSOL          equ  (1 shl 8)  ; accept unsol. response enable
  188. ICH6_REG_WAKEEN          equ  0x0c
  189. ICH6_REG_STATESTS        equ  0x0e
  190. ICH6_REG_GSTS            equ  0x10
  191.   ICH6_GSTS_FSTS           equ  (1 shl 1)  ; flush status
  192. ICH6_REG_INTCTL          equ  0x20
  193. ICH6_REG_INTSTS          equ  0x24
  194. ICH6_REG_WALLCLK         equ  0x30  ; 24Mhz source
  195. ICH6_REG_OLD_SSYNC       equ  0x34  ; SSYNC for old ICH
  196. ICH6_REG_SSYNC           equ  0x38
  197. ICH6_REG_CORBLBASE       equ  0x40
  198. ICH6_REG_CORBUBASE       equ  0x44
  199. ICH6_REG_CORBWP          equ  0x48
  200. ICH6_REG_CORBRP          equ  0x4A
  201.   ICH6_CORBRP_RST          equ  (1 shl 15)  ; read pointer reset
  202. ICH6_REG_CORBCTL         equ  0x4c
  203.   ICH6_CORBCTL_RUN         equ  (1 shl 1)   ; enable DMA
  204.   ICH6_CORBCTL_CMEIE       equ  (1 shl 0)   ; enable memory error irq
  205. ICH6_REG_CORBSTS         equ  0x4d
  206.   ICH6_CORBSTS_CMEI        equ  (1 shl 0)   ; memory error indication
  207. ICH6_REG_CORBSIZE        equ  0x4e
  208.  
  209. ICH6_REG_RIRBLBASE       equ  0x50
  210. ICH6_REG_RIRBUBASE       equ  0x54
  211. ICH6_REG_RIRBWP          equ  0x58
  212.   ICH6_RIRBWP_RST          equ  (1 shl 15)  ; write pointer reset
  213. ICH6_REG_RINTCNT         equ  0x5a
  214. ICH6_REG_RIRBCTL         equ  0x5c
  215.   ICH6_RBCTL_IRQ_EN        equ  (1 shl 0)   ; enable IRQ
  216.   ICH6_RBCTL_DMA_EN        equ  (1 shl 1)   ; enable DMA
  217.   ICH6_RBCTL_OVERRUN_EN    equ  (1 shl 2)   ; enable overrun irq
  218. ICH6_REG_RIRBSTS         equ  0x5d
  219.   ICH6_RBSTS_IRQ           equ  (1 shl 0)   ; response irq
  220.   ICH6_RBSTS_OVERRUN       equ  (1 shl 2)   ; overrun irq
  221. ICH6_REG_RIRBSIZE        equ  0x5e
  222.  
  223. ICH6_REG_IC              equ  0x60
  224. ICH6_REG_IR              equ  0x64
  225. ICH6_REG_IRS             equ  0x68
  226.   ICH6_IRS_VALID           equ  2
  227.   ICH6_IRS_BUSY            equ  1
  228.  
  229. ICH6_REG_DPLBASE         equ  0x70
  230. ICH6_REG_DPUBASE         equ  0x74
  231.   ICH6_DPLBASE_ENABLE      equ  1     ; Enable position buffer
  232.  
  233. ; SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
  234. SDI0_SD_OFFSET    equ  0x80
  235. SDI1_SD_OFFSET    equ  0xA0
  236. SDI2_SD_OFFSET    equ  0xC0
  237. SDI3_SD_OFFSET    equ  0xE0
  238. SDO0_SD_OFFSET    equ  0x100
  239. SDO1_SD_OFFSET    equ  0x120
  240. SDO2_SD_OFFSET    equ  0X140
  241. SDO3_SD_OFFSET    equ  0x160
  242.  
  243. ; stream register offsets from stream base
  244. ICH6_REG_SD_CTL          equ  0x00
  245. ICH6_REG_SD_STS          equ  0x03
  246. ICH6_REG_SD_LPIB         equ  0x04
  247. ICH6_REG_SD_CBL          equ  0x08
  248. ICH6_REG_SD_LVI          equ  0x0c
  249. ICH6_REG_SD_FIFOW        equ  0x0e
  250. ICH6_REG_SD_FIFOSIZE     equ  0x10
  251. ICH6_REG_SD_FORMAT       equ  0x12
  252. ICH6_REG_SD_BDLPL        equ  0x18
  253. ICH6_REG_SD_BDLPU        equ  0x1c
  254.  
  255. ; PCI space
  256. ICH6_PCIREG_TCSEL        equ  0x44
  257.  
  258. ; other constants
  259. ICH6_RIRB_EX_UNSOL_EV    equ   (1 shl 4)
  260.  
  261. ; max number of SDs
  262. MAX_ICH6_DEV             equ  8
  263. ; max number of fragments - we may use more if allocating more pages for BDL
  264. AZX_MAX_FRAG             equ  (4096 / (MAX_ICH6_DEV * 16))
  265. ; max buffer size - no h/w limit, you can increase as you like
  266. AZX_MAX_BUF_SIZE         equ  (1024*1024*1024)
  267. ; max number of PCM devices per card
  268. AZX_MAX_PCMS             equ  8
  269.  
  270. ; RIRB int mask: overrun[2], response[0]
  271. RIRB_INT_RESPONSE        equ  0x01
  272. RIRB_INT_OVERRUN         equ  0x04
  273. RIRB_INT_MASK            equ  0x05
  274.  
  275. ; STATESTS int mask: SD2,SD1,SD0
  276. STATESTS_INT_MASK        equ  0x07
  277. AZX_MAX_CODECS           equ  4
  278.  
  279. ; SD_CTL bits
  280. SD_CTL_STREAM_RESET      equ  0x01    ; stream reset bit
  281. SD_CTL_DMA_START         equ  0x02    ; stream DMA start bit
  282. SD_CTL_STREAM_TAG_MASK   equ  (0xf shl 20)
  283. SD_CTL_STREAM_TAG_SHIFT  equ  20
  284.  
  285. ; SD_CTL and SD_STS
  286. SD_INT_DESC_ERR          equ  0x10    ; descriptor error interrupt
  287. SD_INT_FIFO_ERR          equ  0x08    ; FIFO error interrupt
  288. SD_INT_COMPLETE          equ  0x04    ; completion interrupt
  289. SD_INT_MASK              equ  (SD_INT_DESC_ERR or SD_INT_FIFO_ERR or SD_INT_COMPLETE)
  290.  
  291. ; SD_STS
  292. SD_STS_FIFO_READY        equ  0x20    ; FIFO ready
  293.  
  294. ; INTCTL and INTSTS
  295. ICH6_INT_ALL_STREAM      equ  0xff            ; all stream interrupts
  296. ICH6_INT_CTRL_EN         equ  0x40000000      ; controller interrupt enable bit
  297. ICH6_INT_GLOBAL_EN       equ  0x80000000      ; global interrupt enable bit
  298.  
  299. ; GCTL reset bit
  300. ICH6_GCTL_RESET          equ  1
  301.  
  302. ; CORB/RIRB control, read/write pointer
  303. ICH6_RBCTL_DMA_EN        equ  0x02    ; enable DMA
  304. ICH6_RBCTL_IRQ_EN        equ  0x01    ; enable IRQ
  305. ICH6_RBRWP_CLR           equ  0x8000  ; read/write pointer clear
  306. ; below are so far hardcoded - should read registers in future
  307. ICH6_MAX_CORB_ENTRIES    equ  256
  308. ICH6_MAX_RIRB_ENTRIES    equ  256
  309.  
  310. ; position fix mode
  311. POS_FIX_AUTO             equ  0
  312. POS_FIX_LPIB             equ  1
  313. POS_FIX_POSBUF           equ  2
  314. POS_FIX_VIACOMBO         equ  4
  315. POS_FIX_COMBO            equ  8
  316.  
  317. ; Defines for ATI HD Audio support in SB450 south bridge
  318. ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR   equ  0x42
  319. ATI_SB450_HDAUDIO_ENABLE_SNOOP      equ  0x02
  320.  
  321. ; Defines for Nvidia HDA support
  322. NVIDIA_HDA_TRANSREG_ADDR            equ  0x4e
  323. NVIDIA_HDA_ENABLE_COHBITS           equ  0x0f
  324. NVIDIA_HDA_ISTRM_COH                equ  0x4d
  325. NVIDIA_HDA_OSTRM_COH                equ  0x4c
  326. NVIDIA_HDA_ENABLE_COHBIT            equ  0x01
  327.  
  328. ; Defines for Intel SCH HDA snoop control
  329. INTEL_SCH_HDA_DEVC                  equ  0x78
  330. INTEL_SCH_HDA_DEVC_NOSNOOP          equ  (0x1 shl 11)
  331.  
  332. ; Define IN stream 0 FIFO size offset in VIA controller
  333. VIA_IN_STREAM0_FIFO_SIZE_OFFSET     equ  0x90
  334. ; Define VIA HD Audio Device ID
  335. VIA_HDAC_DEVICE_ID                  equ  0x3288
  336.  
  337. ; HD Audio class code
  338. PCI_CLASS_MULTIMEDIA_HD_AUDIO       equ  0x0403
  339.  
  340.  
  341. SRV_GETVERSION           equ  0
  342. DEV_PLAY                 equ  1
  343. DEV_STOP                 equ  2
  344. DEV_CALLBACK             equ  3
  345. DEV_SET_BUFF             equ  4
  346. DEV_NOTIFY               equ  5
  347. DEV_SET_MASTERVOL        equ  6
  348. DEV_GET_MASTERVOL        equ  7
  349. DEV_GET_INFO             equ  8
  350. DEV_GET_POS              equ  9
  351. DEV_SET_CHANNEL_VOLUME   equ  10
  352. DEV_GET_CHANNEL_VOLUME   equ  11
  353. ;Asper: Non standard system service. For the tests only! [
  354. DEV_EXEC_CODEC_CMD       equ  100
  355. ;Asper: Non standard system service. For the tests only! ]
  356.  
  357. struc AC_CNTRL              ;AC controller base class
  358. {
  359.         .bus                dd ?
  360.         .devfn              dd ?
  361.  
  362.         .vendor             dw ?
  363.         .dev_id             dw ?
  364.         .pci_cmd            dd ?
  365.         .pci_stat           dd ?
  366.  
  367.         .ctrl_io_base       dd ?
  368.         .ctrl_mem_base      dd ?
  369.         .cfg_reg            dd ?
  370.         .int_line           dd ?
  371.  
  372.         .vendor_ids         dd ?    ;vendor id string
  373.         .ctrl_ids           dd ?    ;hub id string
  374.  
  375.         .buffer             dd ?
  376.  
  377.         .notify_pos         dd ?
  378.         .notify_task        dd ?
  379.  
  380.         .lvi_reg            dd ?
  381.         .civ_val            dd 1
  382.         .user_callback      dd ?
  383.  
  384.         .ctrl_read8         dd ?
  385.         .ctrl_read16        dd ?
  386.         .ctrl_read32        dd ?
  387.  
  388.         .ctrl_write8        dd ?
  389.         .ctrl_write16       dd ?
  390.         .ctrl_write32       dd ?
  391.  
  392.         .codec_mask         dd ?
  393.         .rb                 dd ?
  394.         .rirb_rp            dw 0
  395.         .rirb_wp            dw 0
  396.         .corb_rp            dw 0
  397.         .corb_wp            dw 0
  398.         .rirb_cmd           dd 0
  399.         .rirb_res           dd 0
  400.         .rirb_error         dd 0
  401.         .response_reset     dd 0
  402.         .polling_mode       db 0
  403.         .poll_count         db 0
  404.         .posbuf             dd ?
  405.         .start_wallclk      dd ? ; start + minimum wallclk
  406.         .period_wallclk     dd ? ; wallclk for period
  407.         .position_fix       db ?
  408. }
  409.  
  410. struc CODEC                ;Audio Chip base class
  411. {
  412.         .addr               dd ?    ; codec slot index (codec address)
  413.         .afg                dd ?    ; AFG node id
  414.         .mfg                dd ?    ; MFG node id
  415.  
  416.         .function_id        dd ?
  417.         .subsystem_id       dd ?
  418.         .revision_id        dd ?
  419.         .chip_id            dw ?
  420.         .vendor_id          dw ?
  421.  
  422.         ; widget capabilities cache
  423.         .num_nodes          dw ?
  424.         .start_nid          dw ?
  425.         .wcaps              dd ?
  426.  
  427.         .init_pins          dd ?    ; initial (BIOS) pin configurations
  428.         .num_pins           dd ?    ;Asper +  : word is enough, but for align...
  429.         .beeper_nid         dw ?
  430.                       .pad  dw ?
  431.  
  432.         .ac_vendor_ids      dd ?    ;ac vendor id string
  433.         .chip_ids           dd ?    ;chip model string
  434. }
  435.  
  436. struc CTRL_INFO
  437. {
  438.         .pci_cmd            dd ?
  439.         .irq                dd ?
  440.         .glob_cntrl         dd ?
  441.         .glob_sta           dd ?
  442.         .codec_io_base      dd ?
  443.         .ctrl_io_base       dd ?
  444.         .codec_mem_base     dd ?
  445.         .ctrl_mem_base      dd ?
  446.         .codec_id           dd ?
  447. }
  448.  
  449. struc IOCTL
  450. {
  451.         .handle             dd ?
  452.         .io_code            dd ?
  453.         .input              dd ?
  454.         .inp_size           dd ?
  455.         .output             dd ?
  456.         .out_size           dd ?
  457. }
  458.  
  459. EVENT_NOTIFY    equ 0x00000200
  460.  
  461. ; Macroses by CleverMouse
  462. ; The following macro assume that we are on uniprocessor machine.
  463. ; Serious work is needed for multiprocessor machines.
  464. macro spin_lock_irqsave spinlock
  465. {
  466.         pushf
  467.         cli
  468. }
  469. macro spin_unlock_irqrestore spinlock
  470. {
  471.         popf
  472. }
  473. macro spin_lock_irq spinlock
  474. {
  475.         cli
  476. }
  477. macro spin_unlock_irq spinlock
  478. {
  479.         sti
  480. }
  481.  
  482. SPINLOCK_BUSY = 1
  483. SPINLOCK_FREE = 0
  484.  
  485. macro spin_lock
  486. {
  487.         push    eax ebx
  488.         mov     eax, aspinlock
  489.         mov     ebx, SPINLOCK_BUSY
  490. @@:
  491.         lock    xchg [eax], ebx
  492.         cmp     ebx, SPINLOCK_FREE
  493.         jnz     @b
  494.         pop     ebx eax
  495. }
  496.  
  497. macro spin_unlock
  498. {
  499.         push    eax ebx
  500.         mov     eax, aspinlock
  501.         mov     eax, aspinlock
  502.         mov     ebx, SPINLOCK_FREE
  503.         lock    xchg    [eax], ebx
  504.         pop     ebx eax
  505. }
  506.  
  507. data fixups
  508. end data
  509.  
  510. include '../../struct.inc'
  511. include '../../macros.inc'
  512. include '../../proc32.inc'
  513. include '../../peimport.inc'
  514. include 'CODEC_H.INC'
  515.  
  516. entry START
  517.  
  518. ;proc START c, reason:dword, cmdline:dword
  519. proc START
  520.         push    ebx esi ; save used registers to be stdcall
  521. virtual at esp
  522.                 rd      2 ; saved registers
  523.                 dd      ? ; return address
  524. .reason         dd      ? ; DRV_ENTRY or DRV_EXIT
  525. .cmdline        dd      ? ; normally NULL
  526. end virtual
  527. ; 1. Check the reason for the call, do nothing unless initializing.
  528.         cmp     [.reason], DRV_ENTRY
  529.         jne     .stop
  530.  
  531. if DEBUG
  532.         mov     esi, msgTV
  533.         invoke  SysMsgBoardStr
  534.  
  535.         mov     esi, msgInit
  536.         invoke  SysMsgBoardStr
  537. end if
  538.  
  539.         call    detect_controller
  540.         test    eax, eax
  541.         jz      .fail
  542.  
  543.         mov     esi,[ctrl.vendor_ids]
  544.         invoke  SysMsgBoardStr
  545.         mov     esi, [ctrl.ctrl_ids]
  546.         invoke  SysMsgBoardStr
  547.  
  548.         call    init_controller
  549.         test    eax, eax
  550.         jz      .fail
  551.  
  552. ;Asper This part is from "azx_create" proc. [
  553.         mov     [ctrl.position_fix], POS_FIX_LPIB
  554.         cmp     [driver_type], AZX_DRIVER_VIA
  555.         je      .set_via_patch
  556.         cmp     [driver_type], AZX_DRIVER_ATI
  557.         jne     .no_via_patch
  558. .set_via_patch:
  559.         or      [ctrl.position_fix], POS_FIX_VIACOMBO
  560. .no_via_patch:
  561.         ; codec detection
  562.         mov     eax, [ctrl.codec_mask]
  563.         test    eax, eax
  564.         jnz     @f
  565. if DEBUG
  566.         mov     esi, msgNoCodecsFound
  567.         jmp     .fail_msg
  568. else
  569.         jmp     .fail
  570. end if
  571. @@:
  572. ;Asper ]
  573.  
  574.         mov     esi, msgPrimBuff
  575.         invoke  SysMsgBoardStr
  576.         call    create_primary_buff
  577.         mov     esi, msgDone
  578.         invoke  SysMsgBoardStr
  579.  
  580. if IRQ_REMAP
  581.         pushf
  582.         cli
  583.  
  584.         mov     ebx, [ctrl.int_line]
  585.         in      al, 0xA1
  586.         mov     ah, al
  587.         in      al, 0x21
  588.         test    ebx, ebx
  589.         jz      .skip
  590.         bts     ax, bx                  ;mask old line
  591. .skip
  592.         bts     ax, IRQ_LINE            ;mask new line
  593.         out     0x21, al
  594.         mov     al, ah
  595.         out     0xA1, al
  596.                                            ;remap IRQ
  597.         invoke  PciWrite8, 0, 0xF8, 0x61, IRQ_LINE
  598.  
  599.         mov     dx, 0x4d0               ;8259 ELCR1
  600.         in      al, dx
  601.         bts     ax, IRQ_LINE
  602.         out     dx, al                  ;set level-triggered mode
  603.         mov     [ctrl.int_line], IRQ_LINE
  604.         popf
  605.         mov     esi, msgRemap
  606.         invoke  SysMsgBoardStr
  607. end if
  608.  
  609.         mov     ebx, [ctrl.int_line]
  610.         invoke  AttachIntHandler, ebx, hda_irq, dword 0
  611.  
  612. ;Asper This part is from "azx_probe" proc. [
  613.         call    azx_codec_create
  614.         cmp     eax, 0
  615.         jl      .fail
  616.  
  617.         call    azx_codec_configure
  618.         cmp     eax, 0
  619.         jl      .fail
  620. ;] Asper
  621.  
  622.         ; create PCM streams
  623. ;Asper+ [
  624.         mov     eax, [spec.dac_node]
  625. if DEBUG ;-
  626.         push    eax esi
  627.         mov     esi, msgVal
  628.         invoke  SysMsgBoardStr
  629.         stdcall  fdword2str, 3
  630.         invoke  SysMsgBoardStr
  631.         pop     esi eax
  632. end if
  633.  
  634.         test    eax, eax
  635.         jz      .fail
  636.         mov     ebx, [spec.dac_node+4]
  637. if DEBUG ;-
  638.         push    eax esi
  639.         mov     esi, msgVal
  640.         invoke  SysMsgBoardStr
  641.         mov     eax, [spec.dac_node+4]
  642.         stdcall fdword2str, 3
  643.         invoke  SysMsgBoardStr
  644.         pop     esi eax
  645. end if
  646.  
  647.         test    ebx, ebx
  648.         jz      @f
  649.         cmp     eax, ebx
  650.         je      @f
  651.         stdcall hda_codec_setup_stream, ebx, SDO_TAG, 0, 0x11   ; Left & Right channels (Front panel)
  652. @@:
  653.         stdcall hda_codec_setup_stream, eax, SDO_TAG, 0, 0x11   ; Left & Right channels (Back panel)
  654. ;Asper+ ]
  655.  
  656.         invoke  TimerHS, 1, 0, snd_hda_automute, 0
  657. if USE_SINGLE_MODE
  658.         mov     esi, msgSingleMode
  659.         invoke  SysMsgBoardStr
  660. else
  661.         mov     esi, msgNormalMode
  662.         invoke  SysMsgBoardStr
  663. end if
  664.  
  665. .reg:
  666.         invoke  RegService, sz_sound_srv, service_proc
  667.         pop     esi ebx
  668.         ret
  669. .fail:
  670.         mov     esi, msgFail
  671. .fail_msg:
  672.         invoke  SysMsgBoardStr
  673.         pop     esi ebx
  674.         xor     eax, eax
  675.         ret
  676. .stop:
  677.         call    stop
  678.         pop     esi ebx
  679.         xor     eax, eax
  680.         ret
  681. endp
  682.  
  683. handle     equ  IOCTL.handle
  684. io_code    equ  IOCTL.io_code
  685. input      equ  IOCTL.input
  686. inp_size   equ  IOCTL.inp_size
  687. output     equ  IOCTL.output
  688. out_size   equ  IOCTL.out_size
  689.  
  690. align 4
  691. proc service_proc stdcall, ioctl:dword
  692.         mov     edi, [ioctl]
  693.         mov     eax, [edi+io_code]
  694.  
  695.         cmp     eax, SRV_GETVERSION
  696.         jne     @F
  697.  
  698.         mov     eax, [edi+output]
  699.         cmp     [edi+out_size], 4
  700.         jne     .fail
  701.  
  702.         mov     [eax], dword API_VERSION
  703.         xor     eax, eax
  704.         ret
  705. @@:
  706.         cmp     eax, DEV_PLAY
  707.         jne     @F
  708. if DEBUG
  709.         mov     esi, msgPlay
  710.         invoke  SysMsgBoardStr
  711. end if
  712.         call    play
  713.         xor     eax, eax
  714.         ret
  715. @@:
  716.         cmp     eax, DEV_STOP
  717.         jne     @F
  718. if DEBUG
  719.         mov     esi, msgStop
  720.         invoke  SysMsgBoardStr
  721. end if
  722.         call    stop
  723.         xor     eax, eax
  724.         ret
  725. @@:
  726.         cmp     eax, DEV_CALLBACK
  727.         jne     @f
  728.         mov     ebx, [edi+input]
  729.         stdcall set_callback, [ebx]
  730.         xor     eax, eax
  731.         ret
  732. @@:
  733.         cmp     eax, DEV_SET_MASTERVOL
  734.         jne     @f
  735.         mov     eax, [edi+input]
  736.         mov     eax, [eax]
  737.         call    set_master_vol
  738.         xor     eax, eax
  739.         ret
  740. @@:
  741.         cmp     eax, DEV_GET_MASTERVOL
  742.         jne     @f
  743.         mov     ebx, [edi+output]
  744.         stdcall get_master_vol, ebx
  745.         xor     eax, eax
  746.         ret
  747. ;@@:
  748. ;        cmp     eax, DEV_GET_INFO
  749. ;        jne     @f
  750. ;        mov     ebx, [edi+output]
  751. ;        stdcall get_dev_info, ebx
  752. ;        xor     eax, eax
  753. ;        ret
  754. @@:
  755.         cmp     eax, DEV_GET_POS
  756.         jne     @f
  757.         stdcall azx_get_position
  758.         shr     eax, 2
  759.         mov     ebx, [edi+output]
  760.         mov     [ebx], eax
  761.         xor     eax, eax
  762.         ret
  763. @@:
  764. ;        cmp     eax, DEV_SET_CHANNEL_VOLUME
  765. ;        jne     @f
  766. ;if DEBUG
  767. ;        mov     esi, msgSetChannelVolume
  768. ;        invoke  SysMsgBoardStr
  769. ;end if
  770. ;        mov      ebx, [edi+input]
  771. ;        mov      cl,  byte [ebx]      ; cl=channel
  772. ;        mov      eax, dword [ebx+1]   ; eax=volume in Db
  773. ;if DEBUG
  774. ;        push    eax esi
  775. ;        mov     esi, msgYAHOO1
  776. ;        invoke  SysMsgBoardStr
  777. ;        stdcall fdword2str, 1
  778. ;        invoke  SysMsgBoardStr
  779. ;        mov     esi, strSemicolon
  780. ;        invoke  SysMsgBoardStr
  781. ;        movzx   eax, cl
  782. ;        stdcall fdword2str, 3
  783. ;        invoke  SysMsgBoardStr
  784. ;        pop     esi eax
  785. ;end if
  786. ;    ;        call    set_channel_volume
  787. ;        xor     eax, eax
  788. ;        ret
  789. ;@@:
  790. ;        cmp     eax, DEV_GET_CHANNEL_VOLUME
  791. ;        jne     @f
  792. ;        mov     cl,  byte [edi+input]  ; cl=channel
  793. ;        call    get_channel_volume
  794. ;        mov     ebx, [edi+output]
  795. ;        mov     [ebx], eax
  796. ;        xor     eax, eax
  797. ;        ret
  798. ;@@:
  799.  
  800. ;Asper: Non standard system service. For the tests only! [
  801. @@:
  802.         cmp      eax, DEV_EXEC_CODEC_CMD
  803.         jne      @f
  804.  
  805.         mov      eax, [edi+input]
  806.         mov      eax, [eax]
  807.         stdcall  codec_exec_verb, eax
  808.         xor      eax, eax
  809.         ret
  810. @@:
  811. ;Asper: Non standard system service. For the tests only! ]
  812.  
  813. .fail:
  814.         or       eax, -1
  815.         ret
  816. endp
  817.  
  818. restore handle
  819. restore io_code
  820. restore input
  821. restore inp_size
  822. restore output
  823. restore out_size
  824.  
  825.  
  826. align 4
  827. proc hda_irq   ;+
  828.         spin_lock
  829. if DEBUG_IRQ
  830.         push    eax esi
  831.         ;mov     esi, msgIRQ
  832.         ;invoke  SysMsgBoardStr
  833.         invoke  GetTimerTicks
  834.         stdcall fdword2str, 2
  835.         invoke  SysMsgBoardStr
  836.         pop     esi eax
  837. end if
  838.         mov     edx, ICH6_REG_INTSTS
  839.         call    azx_readl
  840.         test    eax, eax
  841.         jnz     @f
  842.         spin_unlock
  843.         ret
  844. @@:
  845.         mov     ebx, eax ; status
  846.         mov     eax, SDO_INT
  847.         test    ebx, eax
  848.         jz      @f
  849.  
  850.         mov     edx, ICH6_REG_SD_STS + SDO_OFS
  851.         call    azx_readb
  852.         mov     bl, al
  853.  
  854.         mov     al, SD_INT_MASK
  855.         mov     edx, ICH6_REG_SD_STS + SDO_OFS
  856.         call    azx_writeb
  857.  
  858.         test    bl, SD_INT_COMPLETE
  859.         jz      @f
  860.  
  861.         mov     eax, [ctrl.civ_val]
  862.         inc     eax
  863.         and     eax, 4-1 ;2-1
  864.         mov     [ctrl.civ_val], eax
  865.  
  866.         mov     ebx, dword [buff_list+eax*4]
  867.         cmp     [ctrl.user_callback], 0
  868.         je      @f
  869.         stdcall [ctrl.user_callback], ebx
  870. @@:
  871.         ; clear rirb int
  872.         mov     edx, ICH6_REG_RIRBSTS
  873.         call    azx_readb
  874.  
  875.         test    al, RIRB_INT_MASK
  876.         jz      .l1
  877.         test    al, RIRB_INT_RESPONSE
  878.         jz      .l2
  879.  
  880.         cmp     byte [driver_type], AZX_DRIVER_CTX
  881.         jne     @f
  882.         mov     eax, 80    ; wait 80 us
  883.         call    StallExec
  884. @@:
  885.         call    azx_update_rirb
  886. .l2:
  887.         mov     al, RIRB_INT_MASK
  888.         mov     edx, ICH6_REG_RIRBSTS
  889.         call    azx_writeb
  890. .l1:
  891.  
  892. ;if 0
  893.         ; clear state status int
  894.         mov     edx, ICH6_REG_STATESTS
  895.         call    azx_readb
  896.         test    al, 0x04
  897.         jz      @f
  898.  
  899.         mov     al, 0x04
  900.         mov     edx, ICH6_REG_STATESTS
  901.         call    azx_writeb
  902. @@:
  903. ;end if
  904.         or      eax, 1
  905.         spin_unlock
  906.         ret
  907. endp
  908.  
  909.  
  910. align 4
  911. proc create_primary_buff
  912.  
  913.         invoke  KernelAlloc, 4096
  914.         mov     [ctrl.posbuf], eax
  915.  
  916.         invoke  KernelAlloc, 0x10000 ;0x8000
  917.         mov     [ctrl.buffer], eax
  918.  
  919.         mov     edi, eax
  920.         mov     ecx, 0x10000/4 ;0x8000/4
  921.         xor     eax, eax
  922.         cld
  923.         rep     stosd
  924.  
  925.         invoke  KernelAlloc, 4096
  926.         mov     [pcmout_bdl], eax
  927.  
  928.         mov     edi, eax
  929.         mov     ecx, 4096/4
  930.         xor     eax, eax
  931.         cld
  932.         rep     stosd
  933.  
  934.         ; reset BDL address
  935.         xor     eax, eax
  936.         mov     edx, ICH6_REG_SD_BDLPL + SDO_OFS
  937.         call    azx_writel
  938.         xor     eax, eax
  939.         mov     edx, ICH6_REG_SD_BDLPU + SDO_OFS
  940.         call    azx_writel
  941.  
  942.         ; program the initial BDL entries
  943.         mov     eax, [ctrl.buffer]
  944.         mov     ebx, eax
  945.         invoke  GetPgAddr
  946.         and     ebx, 0xFFF
  947.         add     eax, ebx
  948.  
  949.         mov     ebx, 0x4000 ;buffer size
  950.         mov     ecx, 8      ;number of periods
  951.         mov     edi, [pcmout_bdl] ;pcmout_bdl
  952. .next_period:
  953.         push    eax ecx
  954.         mov     ecx, 4 ;2  ;number of bdl in a period
  955. .next_bdl:
  956.         ; program the address field of the BDL entry
  957.         mov     dword [edi], eax
  958.         mov     dword [edi+4], 0
  959.         ; program the size field of the BDL entry
  960.         mov     dword [edi+8],  ebx
  961.         ; program the IOC to enable interrupt when buffer completes
  962.         mov     dword [edi+12], 0x01
  963.  
  964.         add     eax, ebx
  965.         add     edi, 16
  966.         dec     ecx
  967.         jnz     .next_bdl
  968.  
  969.         pop     ecx eax
  970.         dec     ecx
  971.         jnz     .next_period
  972.  
  973.         mov     edi, buff_list
  974.         mov     eax, [ctrl.buffer]
  975.         mov     ecx, 4 ;2
  976. @@:
  977.         mov     [edi], eax
  978.         mov     [edi+8], eax
  979.         mov     [edi+16], eax
  980.         mov     [edi+24], eax
  981.         mov     [edi+32], eax
  982.         mov     [edi+40], eax
  983.         mov     [edi+48], eax
  984.         mov     [edi+56], eax
  985.  
  986.         add     eax, ebx
  987.         add     edi, 4
  988.         loop    @B
  989.  
  990.         ; wallclk has 24Mhz clock source
  991.         mov     [ctrl.period_wallclk], ((0x4000 * 24000) / 48000) * 1000
  992.  
  993.         call    azx_stream_reset
  994.         call    azx_setup_controller
  995.         ret
  996. endp
  997.  
  998. align 4
  999. proc detect_controller
  1000. locals
  1001.         last_bus dd ?
  1002.         bus      dd ?
  1003.         devfn    dd ?
  1004. endl
  1005.         xor     eax, eax
  1006.         mov     [bus], eax
  1007.         inc     eax
  1008.         invoke  PciApi
  1009.         cmp     eax, -1
  1010.         je      .err
  1011.  
  1012.         mov     [last_bus], eax
  1013.  
  1014. .next_bus:
  1015.         and     [devfn], 0
  1016. .next_dev:
  1017.         invoke  PciRead32, [bus], [devfn], dword 0
  1018.         test    eax, eax
  1019.         jz      .next
  1020.         cmp     eax, -1
  1021.         je      .next
  1022.  
  1023.         mov     edi, devices
  1024. @@:
  1025.         mov     ebx, [edi]
  1026.         test    ebx, ebx
  1027.         jz      .next
  1028.  
  1029.         cmp     eax, ebx
  1030.         je      .found
  1031.         add     edi, 12
  1032.         jmp     @b
  1033. .next:
  1034.         inc     [devfn]
  1035.         cmp     [devfn], 256
  1036.         jb      .next_dev
  1037.         mov     eax, [bus]
  1038.         inc     eax
  1039.         mov     [bus], eax
  1040.         cmp     eax, [last_bus]
  1041.         jna     .next_bus
  1042.         xor     eax, eax
  1043.         ret
  1044. .found:
  1045.         mov     ebx, [bus]
  1046.         mov     [ctrl.bus], ebx
  1047.  
  1048.         mov     ecx, [devfn]
  1049.         mov     [ctrl.devfn], ecx
  1050.  
  1051.         mov     edx, eax
  1052.         and     edx, 0xFFFF
  1053.         mov     [ctrl.vendor], dx
  1054.         shr     eax, 16
  1055.         mov     [ctrl.dev_id], ax
  1056.  
  1057.         mov     ebx, [edi+4]
  1058.         mov     [ctrl.ctrl_ids], ebx
  1059.  
  1060.         cmp     edx, VID_INTEL
  1061.         jne     @f
  1062.         mov     [ctrl.vendor_ids], msg_Intel
  1063.         jmp     .ok
  1064. @@:
  1065.         cmp     edx, VID_NVIDIA
  1066.         jne     @f
  1067.         mov     [ctrl.vendor_ids], msg_NVidia
  1068.         jmp     .ok
  1069. @@:
  1070.         cmp     edx, VID_ATI
  1071.         jne     @f
  1072.         cmp     eax, 0x4383
  1073.         jg      .ati_hdmi
  1074.         mov     [ctrl.vendor_ids], msg_ATI
  1075.         jmp     .ok
  1076. .ati_hdmi:
  1077.         mov     [ctrl.vendor_ids], msg_ATI_HDMI
  1078.         jmp     .ok
  1079. @@:
  1080.         cmp     edx, VID_AMD
  1081.         jne     @f
  1082.         mov     [ctrl.vendor_ids], msg_AMD
  1083.         jmp     .ok
  1084. @@:
  1085.         cmp     edx, VID_VIA
  1086.         jne     @f
  1087.         mov     [ctrl.vendor_ids], msg_VIA
  1088.         jmp     .ok
  1089. @@:
  1090.         cmp     edx, VID_SIS
  1091.         jne     @f
  1092.         mov     [ctrl.vendor_ids], msg_SIS
  1093.         jmp     .ok
  1094. @@:
  1095.         cmp     edx, VID_ULI
  1096.         jne     @f
  1097.         mov     [ctrl.vendor_ids], msg_ULI
  1098.         jmp     .ok
  1099. @@:
  1100.         cmp     edx, VID_TERA
  1101.         jne     @f
  1102.         mov     [ctrl.vendor_ids], msg_TERA
  1103.         jmp     .ok
  1104. @@:
  1105.         cmp     edx, VID_CREATIVE
  1106.         jne     @f
  1107.         mov     [ctrl.vendor_ids], msg_CREATIVE
  1108.         jmp     .ok
  1109. @@:
  1110.         cmp     edx, VID_RDC
  1111.         jne     @f
  1112.         mov     [ctrl.vendor_ids], msg_RDC
  1113.         jmp     .ok
  1114. @@:
  1115.         cmp     edx, VID_VMWARE
  1116.         jne     @f
  1117.         mov     [ctrl.vendor_ids], msg_VMWARE
  1118.         jmp     .ok
  1119. @@:
  1120. .err:
  1121.         xor     eax, eax
  1122.         mov     [ctrl.vendor_ids], eax     ;something  wrong ?
  1123.         mov     [driver_type], -1
  1124.         ret
  1125. .ok:
  1126.         mov     ebx, [edi+8]
  1127.         mov     [driver_type], ebx
  1128.         ret
  1129. endp
  1130.  
  1131. align 4
  1132. proc init_controller
  1133.  
  1134.         invoke  PciRead32, [ctrl.bus], [ctrl.devfn], dword 4
  1135.         movi    ebx, 0x6
  1136.         and     ebx, eax
  1137.         cmp     ebx, 0x6 ; Test Master and Memory bits
  1138.         jz      @f
  1139.         or      eax, 0x6 ; Set Master and Memory bits
  1140.         invoke  PciWrite32, [ctrl.bus], [ctrl.devfn], dword 4, eax
  1141.         invoke  PciRead32, [ctrl.bus], [ctrl.devfn], dword 4
  1142. @@:
  1143.         mov     ebx, eax
  1144.         and     eax, 0xFFFF
  1145.         mov     [ctrl.pci_cmd], eax
  1146.         shr     ebx, 16
  1147.         mov     [ctrl.pci_stat], ebx
  1148.  
  1149.         mov     esi, msgPciCmd
  1150.         invoke  SysMsgBoardStr
  1151.         stdcall fdword2str, 2
  1152.         invoke  SysMsgBoardStr
  1153.  
  1154.         mov     esi, msgPciStat
  1155.         invoke  SysMsgBoardStr
  1156.         mov     eax, [ctrl.pci_stat]
  1157.         stdcall fdword2str, 2
  1158.         invoke  SysMsgBoardStr
  1159.  
  1160.         mov     esi, msgHDALowMMIo
  1161.         invoke  SysMsgBoardStr
  1162.         invoke  PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x10
  1163.         stdcall fdword2str, 2
  1164.         invoke  SysMsgBoardStr
  1165.  
  1166.         and     eax, 0xFFFFC000
  1167.         mov     [ctrl.ctrl_mem_base], eax
  1168.  
  1169.         mov     esi, msgHDAUpMMIo
  1170.         invoke  SysMsgBoardStr
  1171.         invoke  PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x14
  1172.         ;-mov     [ctrl.hda_upper_mem_base], eax
  1173.         stdcall fdword2str, 2
  1174.         invoke  SysMsgBoardStr
  1175.  
  1176. .default:
  1177.         invoke  PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x3C
  1178.         and     eax, 0xFF
  1179. @@:
  1180.         mov     [ctrl.int_line], eax
  1181.         mov     [ctrl.user_callback], 0
  1182.  
  1183.         call    set_HDA
  1184. ;Asper This is from "azx_create" proc. [
  1185.         xor     eax, eax
  1186.         mov     edx, ICH6_REG_GCAP
  1187.         call    azx_readw
  1188. if DEBUG
  1189.         mov     esi, msgGCap
  1190.         invoke  SysMsgBoardStr
  1191.         stdcall fdword2str, 2
  1192.         invoke  SysMsgBoardStr
  1193. end if
  1194.         ; allocate CORB/RIRB
  1195.         call    azx_alloc_cmd_io
  1196.  
  1197.         ; initialize chip
  1198.         call    azx_init_pci
  1199.  
  1200.         xor     eax, eax
  1201.         call    azx_init_chip
  1202. ;] Asper
  1203.  
  1204.         xor     eax, eax
  1205.         inc     eax
  1206.         ret
  1207. endp
  1208.  
  1209.  
  1210.  
  1211. PG_SW           equ 0x003
  1212. PG_NOCACHE      equ 0x018
  1213.  
  1214. align 4
  1215. proc set_HDA
  1216.         invoke  MapIoMem,[ctrl.ctrl_mem_base],0x1000,PG_SW+PG_NOCACHE
  1217.         mov     [ctrl.ctrl_mem_base], eax
  1218.         ret
  1219. endp
  1220.  
  1221.  
  1222. ; in:  eax - fullreset_flag
  1223. ;
  1224. ; reset codec link
  1225. align 4
  1226. proc reset_controller
  1227. locals
  1228.         counter dd ?
  1229. endl
  1230.  
  1231.         test    eax, eax
  1232.         jz      .skip
  1233.  
  1234.         ; clear STATESTS
  1235.         mov     eax, STATESTS_INT_MASK
  1236.         mov     edx, ICH6_REG_STATESTS
  1237.         call    azx_writeb
  1238.  
  1239.         ; reset controller
  1240.         mov     edx, ICH6_REG_GCTL
  1241.         call    azx_readl
  1242.         mov     ebx, ICH6_GCTL_RESET
  1243.         xor     ebx, -1
  1244.         and     eax, ebx
  1245.         mov     edx, ICH6_REG_GCTL
  1246.         call    azx_writel
  1247.  
  1248.         mov     [counter], 50    ; total 50*100 us = 0.5s
  1249. .wait0:
  1250.  
  1251.         mov     edx, ICH6_REG_GCTL
  1252.         call    azx_readb
  1253.         test    eax, eax
  1254.         jz      @f
  1255.  
  1256.         mov     eax, 100    ; wait 100 us
  1257.         call    StallExec
  1258.  
  1259.         dec     [counter]
  1260.         jnz     .wait0
  1261. @@:
  1262.         ; delay for >= 100us for codec PLL to settle per spec
  1263.         ; Rev 0.9 section 5.5.1
  1264.         mov     eax, 100    ; wait 100 us
  1265.         call    StallExec
  1266.  
  1267.         ; Bring controller out of reset
  1268.         mov     edx, ICH6_REG_GCTL
  1269.         call    azx_readb
  1270.         or      eax, ICH6_GCTL_RESET
  1271.         mov     edx, ICH6_REG_GCTL
  1272.         call    azx_writeb
  1273.  
  1274.         mov     [counter], 50    ; total 50*100 us = 0.5s
  1275. .wait1:
  1276.  
  1277.         mov     edx, ICH6_REG_GCTL
  1278.         call    azx_readb
  1279.         test    eax, eax
  1280.         jnz     @f
  1281.  
  1282.         mov     eax, 100    ; wait 100 us
  1283.         call    StallExec
  1284.  
  1285.         dec     [counter]
  1286.         jnz     .wait1
  1287. @@:
  1288.  
  1289.         ; Brent Chartrand said to wait >= 540us for codecs to intialize
  1290.         mov     eax, 540    ; wait 540 us
  1291.         call    StallExec
  1292.  
  1293. .skip:
  1294.         ; check to see if controller is ready
  1295.         mov     edx, ICH6_REG_GCTL
  1296.         call    azx_readb
  1297.         test    eax, eax
  1298.         jz      .fail
  1299.  
  1300.         ; Accept unsolicited responses
  1301. if USE_SINGLE_MODE
  1302. else if USE_UNSOL_EV
  1303. ;UNSUPPORTED YET! [
  1304.         mov     edx, ICH6_REG_GCTL
  1305.         call    azx_readl
  1306.         or      eax, ICH6_GCTL_UNSOL
  1307.         mov     edx, ICH6_REG_GCTL
  1308.         call    azx_writel
  1309. ;UNSUPPORTED YET! ]
  1310. end if
  1311.  
  1312.         ; detect codecs
  1313.         mov     eax, [ctrl.codec_mask]
  1314.         test    ax, ax
  1315.         jnz     @f
  1316.  
  1317.         mov     edx, ICH6_REG_STATESTS
  1318.         call    azx_readw
  1319.         mov     [ctrl.codec_mask], eax
  1320.  
  1321. if DEBUG
  1322.         mov     esi, msgCodecMask
  1323.         invoke  SysMsgBoardStr
  1324.         stdcall fdword2str, 2
  1325.         invoke  SysMsgBoardStr
  1326. end if
  1327.  
  1328. @@:
  1329.  
  1330. .ok:
  1331.         clc
  1332.         ret
  1333. .fail:
  1334. if DEBUG
  1335.         mov     esi, msgHDARFail
  1336.         invoke  SysMsgBoardStr
  1337. end if
  1338.         stc
  1339.         ret
  1340. endp
  1341.  
  1342.  
  1343. align 4
  1344. play:
  1345.         spin_lock_irq
  1346.         mov     edx, ICH6_REG_WALLCLK
  1347.         call    azx_readl
  1348.         mov     [ctrl.start_wallclk], eax
  1349.  
  1350.         call    azx_stream_start
  1351.         xor     eax, eax
  1352.         spin_unlock_irq
  1353.         ret
  1354.  
  1355. align 4
  1356. stop:
  1357.         spin_lock_irq
  1358. ;*        call    azx_stream_stop        ;Asper: Hangs system
  1359. ;R        push    ebx ecx edx
  1360. ;R        ; stop DMA
  1361. ;R        mov     edx, ICH6_REG_SD_CTL
  1362. ;R        call    azx_sd_readb
  1363. ;R        mov     bl, SD_CTL_DMA_START or SD_INT_MASK
  1364. ;R        xor     bl, -1
  1365. ;R        and     al, bl
  1366. ;R        mov     edx, ICH6_REG_SD_CTL
  1367. ;R        call    azx_sd_writeb
  1368. ;R        mov     edx, ICH6_REG_SD_STS
  1369. ;R        mov     al, SD_INT_MASK
  1370. ;R        call    azx_sd_writeb  ; to be sure
  1371.           ; disable SIE
  1372. ;N        mov     edx, ICH6_REG_INTCTL
  1373. ;N        call    azx_readb
  1374. ;N        mov     bl, SDO_INT ;shl azx_dev->index
  1375. ;N        xor     bl, -1
  1376. ;N        and     al, bl
  1377. ;N        mov     edx, ICH6_REG_INTCTL
  1378. ;N        call    azx_writeb
  1379.  
  1380.         ;     int timeout = 5000;
  1381.         ;     while (azx_sd_readb(azx_dev, SD_CTL) & SD_CTL_DMA_START && --timeout) ;
  1382. ;Asper: Hangs system   [
  1383. ;*        mov     ecx, 5000
  1384. ;*.l1:
  1385. ;*        mov     edx, ICH6_REG_SD_CTL
  1386. ;*        call    azx_sd_readb
  1387. ;*        test    al, SD_CTL_DMA_START
  1388. ;*        jz      @f
  1389. ;*        dec     ecx
  1390. ;*        jnz     .l1
  1391. ;*@@:
  1392. ;*
  1393. ;*        pop     edx ecx ebx
  1394. ;Asper ]
  1395.  
  1396.         xor     eax, eax
  1397.         spin_unlock_irq
  1398.         ret
  1399.  
  1400. ;align 4
  1401. ;proc get_dev_info stdcall, p_info:dword ;deprecated
  1402. ;virtual at esi
  1403. ;        CTRL_INFO CTRL_INFO
  1404. ;end virtual
  1405. ;
  1406. ;        mov     esi, [p_info]
  1407. ;        mov     eax, [ctrl.int_line]
  1408. ;        mov     bx,  [ctrl.dev_id]
  1409. ;        shl     ebx, 16
  1410. ;        and     bx,  [ctrl.vendor]
  1411. ;        mov     ecx, [ctrl.pci_cmd]
  1412. ;        mov     edx, [ctrl.codec_mem_base] ;[ctrl.hda_lower_mem_base]
  1413. ;        mov     edi, [ctrl.ctrl_mem_base] ;[ctrl.hda_upper_mem_base]
  1414. ;
  1415. ;        mov     [CTRL_INFO.irq], eax
  1416. ;        mov     [CTRL_INFO.codec_id], ebx
  1417. ;        mov     [CTRL_INFO.pci_cmd], ecx
  1418. ;        mov     [CTRL_INFO.codec_mem_base], edx
  1419. ;        mov     [CTRL_INFO.ctrl_mem_base], edi
  1420. ;
  1421. ;        xor     eax, eax
  1422. ;        mov     [CTRL_INFO.codec_io_base], eax
  1423. ;        mov     [CTRL_INFO.ctrl_io_base], eax
  1424. ;        mov     [CTRL_INFO.glob_cntrl], eax
  1425. ;        mov     [CTRL_INFO.glob_sta], eax
  1426. ;        ret
  1427. ;endp
  1428.  
  1429. align 4
  1430. proc set_callback stdcall, handler:dword
  1431.         mov     eax, [handler]
  1432.         mov     [ctrl.user_callback], eax
  1433.         ret
  1434. endp
  1435.  
  1436.  
  1437.  
  1438. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1439. ;; Interface for HD codec ;;
  1440. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1441.  
  1442. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1443. ;; CORB / RIRB interface ;;
  1444. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1445.  
  1446. proc azx_alloc_cmd_io
  1447.         push    eax ecx edx
  1448.         ; single page (at least 4096 bytes) must suffice for both ringbuffers
  1449.         invoke  KernelAlloc, 4096
  1450.         mov     [ctrl.rb], eax
  1451.  
  1452.         mov     edi, eax
  1453.         mov     ecx, 4096/4
  1454.         xor     eax, eax
  1455.         cld
  1456.         rep     stosd
  1457.  
  1458.         pop     edx ecx eax
  1459.         ret
  1460. endp
  1461.  
  1462. proc azx_init_cmd_io
  1463.         spin_lock_irq
  1464.         pusha
  1465.         ; CORB set up
  1466.         mov     eax, [ctrl.rb]
  1467.         mov     ebx, eax
  1468.         invoke  GetPgAddr
  1469.         and     ebx, 0xFFF
  1470.         add     eax, ebx
  1471.         push    eax  ; save corb address
  1472.         mov     edx, ICH6_REG_CORBLBASE
  1473.         call    azx_writel
  1474.         xor     eax, eax
  1475.         mov     edx, ICH6_REG_CORBUBASE
  1476.         call    azx_writel
  1477.  
  1478.         ; set the corb size to 256 entries (ULI requires explicitly)
  1479.         mov     al, 0x02
  1480.         mov     edx, ICH6_REG_CORBSIZE
  1481.         call    azx_writeb
  1482.         ; set the corb write pointer to 0
  1483.         xor     ax, ax
  1484.         mov     edx, ICH6_REG_CORBWP
  1485.         call    azx_writew
  1486.         ; reset the corb hw read pointer
  1487.         mov     ax, ICH6_CORBRP_RST
  1488.         mov     edx, ICH6_REG_CORBRP
  1489.         call    azx_writew
  1490.         ; enable corb dma
  1491.         mov     al, ICH6_CORBCTL_RUN
  1492.         mov     edx, ICH6_REG_CORBCTL
  1493.         call    azx_writeb
  1494.  
  1495.         ; RIRB set up
  1496.         mov     [ctrl.rirb_rp], 0
  1497.         mov     [ctrl.rirb_wp], 0
  1498.         mov     [ctrl.rirb_cmd], 0
  1499.  
  1500.         pop     eax  ; restore corb address
  1501.         add     eax, 2048
  1502.         mov     edx, ICH6_REG_RIRBLBASE
  1503.         call    azx_writel
  1504.         xor     eax, eax
  1505.         mov     edx, ICH6_REG_RIRBUBASE
  1506.         call    azx_writel
  1507.  
  1508.         ; set the rirb size to 256 entries (ULI requires explicitly)
  1509.         mov     al, 0x02
  1510.         mov     edx, ICH6_REG_RIRBSIZE
  1511.         call    azx_writeb
  1512.         ; reset the rirb hw write pointer
  1513.         mov     ax, ICH6_RIRBWP_RST
  1514.         mov     edx, ICH6_REG_RIRBWP
  1515.         call    azx_writew
  1516.         ; set N=1, get RIRB response interrupt for new entry
  1517.         xor     ax, ax
  1518.         cmp     byte [driver_type], AZX_DRIVER_CTX
  1519.         jne     @f
  1520.         mov     ax, 0xC0-1
  1521.   @@:
  1522.         inc     ax
  1523.         mov     edx, ICH6_REG_RINTCNT
  1524.         call    azx_writew
  1525.         ; enable rirb dma and response irq
  1526.         mov     al, ICH6_RBCTL_DMA_EN or ICH6_RBCTL_IRQ_EN
  1527.         mov     edx, ICH6_REG_RIRBCTL
  1528.         call    azx_writeb
  1529.  
  1530.         popa
  1531.         spin_unlock_irq
  1532.         ret
  1533. endp
  1534.  
  1535. proc azx_free_cmd_io
  1536.         spin_lock_irq
  1537.         push    eax edx
  1538.         ; disable ringbuffer DMAs
  1539.         xor     al, al
  1540.         mov     edx, ICH6_REG_RIRBCTL
  1541.         call    azx_writeb
  1542.         mov     edx, ICH6_REG_CORBCTL
  1543.         call    azx_writeb
  1544.         pop     edx eax
  1545.         spin_unlock_irq
  1546.         ret
  1547. endp
  1548.  
  1549.  
  1550. ; send a command
  1551. proc azx_corb_send_cmd  stdcall, val:dword
  1552.         spin_lock_irq
  1553.         push    edx edi
  1554.         xor     eax, eax
  1555.         ; add command to corb
  1556.         mov     edx, ICH6_REG_CORBWP
  1557.         call    azx_readb
  1558.         inc     al
  1559.         inc     dword [ctrl.rirb_cmd]
  1560.         mov     edi, dword [ctrl.rb]
  1561.  
  1562.         push    eax
  1563.         shl     eax, 2 ;wp=wp*sizeof(corb entry)=wp*4
  1564.         add     edi, eax
  1565.         mov     eax, dword [val]
  1566.         stosd
  1567.         pop     eax
  1568.         mov     edx, ICH6_REG_CORBWP
  1569.         call    azx_writel
  1570.  
  1571.         pop     edi edx
  1572.         xor     eax, eax ;Asper+
  1573.         spin_unlock_irq
  1574.         ret
  1575. endp
  1576.  
  1577.  
  1578. ; retrieve RIRB entry - called from interrupt handler
  1579. proc azx_update_rirb
  1580.         pusha
  1581.         xor     eax, eax
  1582.         mov     edx, ICH6_REG_RIRBWP
  1583.         call    azx_readb ;call  azx_readw
  1584.  
  1585.         cmp     ax, [ctrl.rirb_wp]
  1586.         je      .done
  1587.         mov     [ctrl.rirb_wp], ax
  1588.         mov     bx, [ctrl.rirb_rp]
  1589.  
  1590. .l1:
  1591.         cmp     bx, [ctrl.rirb_wp]
  1592.         je      .l3
  1593.  
  1594.         inc     bl
  1595. .l2:
  1596.         cmp     bx, ICH6_MAX_RIRB_ENTRIES
  1597.         jl      @f
  1598.         sub     bx, ICH6_MAX_RIRB_ENTRIES
  1599.         jmp     .l2
  1600. @@:
  1601.  
  1602.         movzx   edx, bx
  1603.         shl     edx, 1 + 2 ; an RIRB entry is 8-bytes
  1604.         mov     esi, dword [ctrl.rb]
  1605.         add     esi, 2048
  1606.         add     esi, edx
  1607.         lodsd   ; res
  1608.         mov     edx, eax
  1609.         lodsd   ; res_ex
  1610.  
  1611.         test    eax, ICH6_RIRB_EX_UNSOL_EV
  1612.         jz      @f
  1613.         stdcall snd_hda_queue_unsol_event, edx, eax
  1614.         jmp     .l1
  1615. @@:
  1616.         mov     ecx, [ctrl.rirb_cmd]
  1617.         test    ecx, ecx
  1618.         jz      @f
  1619.         mov     [ctrl.rirb_res], edx
  1620.         dec     dword [ctrl.rirb_cmd]
  1621.         jmp     .l1
  1622. @@:
  1623. if DEBUG
  1624.         push    esi
  1625.         mov     esi, msgSpuriousResponce
  1626.         invoke  SysMsgBoardStr
  1627.         pop     esi
  1628. end if
  1629.         jmp     .l1
  1630. .l3:
  1631.         mov     [ctrl.rirb_rp], bx
  1632. .done:
  1633.         popa
  1634.         ret
  1635. endp
  1636.  
  1637. ; receive a response
  1638. proc azx_rirb_get_response
  1639. locals
  1640.         do_poll db 0
  1641. endl
  1642.  
  1643.         push    ebx ecx edx
  1644. .again:
  1645.         mov     ecx, 1000;+1000
  1646. .next_try:
  1647.         mov     al, [ctrl.polling_mode]
  1648.         test    al, al
  1649.         jnz     .poll
  1650.         mov     ah, [do_poll]
  1651.         test    ah, ah
  1652.         jz      @f
  1653. .poll:
  1654.         spin_lock_irq
  1655.         call    azx_update_rirb
  1656.         spin_unlock_irq
  1657. @@:
  1658.         mov     eax, [ctrl.rirb_cmd]
  1659.         test    eax, eax
  1660.         jnz     .l1
  1661.         mov     [ctrl.rirb_error], 0
  1662.         mov     al, [do_poll]
  1663.         test    al, al
  1664.         jnz     @f
  1665.         mov     [ctrl.poll_count], 0
  1666. @@:
  1667.         mov     eax, [ctrl.rirb_res] ; the last value
  1668.         jmp     .out
  1669. .l1:
  1670.         push    eax
  1671.         mov     eax, 2000  ; temporary workaround
  1672.         call    StallExec
  1673.         pop     eax
  1674.         dec     ecx
  1675.         jnz     .next_try
  1676. .no_next_try:
  1677.         mov     al, [ctrl.polling_mode]
  1678.         test    al, al
  1679.         jnz     .no_poll
  1680.  
  1681.         mov     al, [ctrl.poll_count]
  1682.         cmp     al, 2
  1683.         jge     .poll_count_overflow
  1684. if DEBUG
  1685.         push    eax esi
  1686.         mov     esi, msgGetResponceTimeout
  1687.         invoke  SysMsgBoardStr
  1688.         mov     esi, msgPollingCodecOnce
  1689.         invoke  SysMsgBoardStr
  1690.         pop     esi eax
  1691. end if
  1692.         mov     [do_poll], 1
  1693.         inc     [ctrl.poll_count]
  1694.         jmp     .again
  1695.  
  1696. .poll_count_overflow:
  1697. if DEBUG
  1698.         push    eax esi
  1699.         mov     esi, msgGetResponceTimeout
  1700.         invoke  SysMsgBoardStr
  1701.         mov     esi, msgSwitchToPollMode
  1702.         invoke  SysMsgBoardStr
  1703.         pop     esi eax
  1704. end if
  1705.         mov     [ctrl.polling_mode], 1
  1706.         jmp     .again
  1707.  
  1708. .no_poll:
  1709.  
  1710.         mov     al, [ctrl.polling_mode]
  1711.         test    al, al
  1712.         jz      @f
  1713.         mov     eax, -1
  1714.         jmp     .out
  1715. @@:
  1716.  
  1717.         ; a fatal communication error; need either to reset or to fallback
  1718.         ; to the single_cmd mode
  1719.         mov     [ctrl.rirb_error], 1
  1720.         ;Asper~ -?  [
  1721.         mov     [ctrl.response_reset], 1
  1722.         mov     eax, -1  ; give a chance to retry
  1723.         jmp     .out
  1724.         ;Asper~ -?  ]
  1725.  
  1726.         ;-? mov     [ctrl.single_cmd], 1
  1727.         mov     [ctrl.response_reset], 0
  1728.  
  1729.         ; release CORB/RIRB
  1730.         call    azx_free_cmd_io
  1731.         ; disable unsolicited responses
  1732.         mov     edx, ICH6_REG_GCTL
  1733.         call    azx_readl
  1734.         mov     ebx, ICH6_GCTL_UNSOL
  1735.         xor     ebx, -1
  1736.         and     eax, ebx
  1737.         mov     edx, ICH6_REG_GCTL
  1738.         call    azx_writel
  1739.         mov     eax, -1
  1740. .out:
  1741.         pop     edx ecx ebx
  1742.         ret
  1743. endp
  1744.  
  1745. ;
  1746. ; Use the single immediate command instead of CORB/RIRB for simplicity
  1747. ;
  1748. ; Note: according to Intel, this is not preferred use.  The command was
  1749. ;       intended for the BIOS only, and may get confused with unsolicited
  1750. ;       responses.  So, we shouldn't use it for normal operation from the
  1751. ;       driver.
  1752. ;       I left the codes, however, for debugging/testing purposes.
  1753. ;
  1754.  
  1755. ; receive a response
  1756. proc azx_single_wait_for_response
  1757.         push    ecx edx esi
  1758.  
  1759.         mov     ecx, 50
  1760. .l1:
  1761.         test    ecx, ecx
  1762.         jz      .timeout
  1763.  
  1764.         ; check IRV busy bit
  1765.         mov     edx, ICH6_REG_IRS
  1766.         call    azx_readw
  1767.         test    ax, ICH6_IRS_VALID
  1768.         jz      @f
  1769.         ; reuse rirb.res as the response return value
  1770.         mov     edx, ICH6_REG_IR
  1771.         call    azx_readl
  1772.         mov     [ctrl.rirb_res], eax
  1773.  
  1774.         pop     esi edx ecx
  1775.         xor     eax, eax
  1776.         ret
  1777. @@:
  1778.         xor     eax, eax
  1779.         inc     eax
  1780.         call    StallExec
  1781.  
  1782.         dec     ecx
  1783.         jmp     .l1
  1784. .timeout:
  1785. if DEBUG
  1786.         xor     eax, eax
  1787.         mov     edx, ICH6_REG_IRS
  1788.         call    azx_readw
  1789.         mov     esi, msgGetResponceTimeout
  1790.         invoke  SysMsgBoardStr
  1791.         mov     esi, msgIRS
  1792.         invoke  SysMsgBoardStr
  1793.         stdcall fdword2str, 2
  1794.         invoke  SysMsgBoardStr
  1795. end if
  1796.  
  1797.         pop     esi edx ecx
  1798.         mov     eax, -1
  1799.         mov     [ctrl.rirb_res], eax
  1800.         ret
  1801. endp
  1802.  
  1803. ; send a command
  1804. proc azx_single_send_cmd  stdcall, val:dword
  1805.         push    ecx edx esi
  1806.  
  1807.         mov     ecx, 50
  1808. .l1:
  1809.         test    ecx, ecx
  1810.         jz      .timeout
  1811.  
  1812.         ; check ICB busy bit
  1813.         mov     edx, ICH6_REG_IRS
  1814.         call    azx_readw
  1815.         test    ax, ICH6_IRS_BUSY
  1816.         jnz     @f
  1817.         ; Clear IRV valid bit
  1818.         mov     edx, ICH6_REG_IRS
  1819.         call    azx_readw
  1820.         or      ax, ICH6_IRS_VALID
  1821.         mov     edx, ICH6_REG_IRS
  1822.         call    azx_writew
  1823.  
  1824.         mov     eax, dword [val]
  1825.         mov     edx, ICH6_REG_IC
  1826.         call    azx_writel
  1827.  
  1828.         mov     edx, ICH6_REG_IRS
  1829.         call    azx_readw
  1830.         or      ax, ICH6_IRS_BUSY
  1831.         mov     edx, ICH6_REG_IRS
  1832.         call    azx_writew
  1833.  
  1834.         stdcall azx_single_wait_for_response
  1835.         pop     esi edx ecx
  1836.         ret
  1837. @@:
  1838.         dec     ecx
  1839.         jmp     .l1
  1840. .timeout:
  1841. if DEBUG
  1842.         xor     eax, eax
  1843.         mov     edx, ICH6_REG_IRS
  1844.         call    azx_readw
  1845.         mov     esi, msgSendCmdTimeout
  1846.         invoke  SysMsgBoardStr
  1847.         stdcall fdword2str, 2
  1848.         invoke  SysMsgBoardStr
  1849.         mov     esi, msgVal
  1850.         invoke  SysMsgBoardStr
  1851.         mov     eax, dword [val]
  1852.         stdcall fdword2str, 2
  1853.         invoke  SysMsgBoardStr
  1854. end if
  1855.  
  1856.         pop     esi edx ecx
  1857.         mov     eax, -1
  1858.         ret
  1859. endp
  1860.  
  1861. ; receive a response
  1862. proc azx_single_get_response
  1863.         mov     eax, [ctrl.rirb_res]
  1864.         ret
  1865. endp
  1866.  
  1867. ;
  1868. ; The below are the main callbacks from hda_codec.
  1869. ;
  1870. ; They are just the skeleton to call sub-callbacks according to the
  1871. ; current setting of chip->single_cmd.
  1872. ;
  1873.  
  1874. ; send a command
  1875. proc azx_send_cmd  stdcall, val:dword
  1876. if USE_SINGLE_MODE
  1877.         stdcall azx_single_send_cmd, [val]
  1878. else
  1879.         stdcall azx_corb_send_cmd, [val]
  1880. end if
  1881.         ret
  1882. endp
  1883.  
  1884. ; get a response
  1885. proc azx_get_response
  1886. if USE_SINGLE_MODE
  1887.         call    azx_single_get_response
  1888. else
  1889.         call    azx_rirb_get_response
  1890. end if
  1891.         ret
  1892. endp
  1893.  
  1894.  
  1895. ;;;;;;;;;;;;;;;;;;;;;;;;
  1896. ;; Lowlevel interface ;;
  1897. ;;;;;;;;;;;;;;;;;;;;;;;;
  1898.  
  1899. ; enable interrupts
  1900. proc azx_int_enable
  1901.         push     eax edx
  1902.         ; enable controller CIE and GIE
  1903.         mov     edx, ICH6_REG_INTCTL
  1904.         call    azx_readl
  1905.         or      eax, ICH6_INT_CTRL_EN or ICH6_INT_GLOBAL_EN
  1906.         mov     edx, ICH6_REG_INTCTL
  1907.         call    azx_writel
  1908.         pop     edx eax
  1909.         ret
  1910. endp
  1911.  
  1912. ; disable interrupts
  1913. proc azx_int_disable
  1914.         push    eax ebx edx
  1915.  
  1916.         ; disable interrupts in stream descriptor
  1917.         mov     edx, ICH6_REG_SD_CTL + SDO_OFS
  1918.         call    azx_readb
  1919.         mov     bl, SD_INT_MASK
  1920.         xor     bl, -1
  1921.         and     al, bl
  1922.         mov     edx, ICH6_REG_SD_CTL + SDO_OFS
  1923.         call    azx_writeb
  1924.  
  1925.         ; disable SIE for all streams
  1926.         xor     al, al
  1927.         mov     edx, ICH6_REG_INTCTL
  1928.         call    azx_writeb
  1929.  
  1930.         ; disable controller CIE and GIE
  1931.         mov     edx, ICH6_REG_INTCTL
  1932.         call    azx_readl
  1933.         mov     ebx, ICH6_INT_CTRL_EN or ICH6_INT_GLOBAL_EN
  1934.         xor     ebx, -1
  1935.         and     eax, ebx
  1936.         call    azx_writel
  1937.         pop     edx ebx eax
  1938.         ret
  1939. endp
  1940.  
  1941. ; clear interrupts
  1942. proc azx_int_clear
  1943.         push    eax edx
  1944.  
  1945.         ; clear stream status
  1946.         mov     al, SD_INT_MASK
  1947.         mov     edx, ICH6_REG_SD_STS + SDO_OFS
  1948.         call    azx_writeb
  1949.  
  1950.         ; clear STATESTS
  1951.         mov     al, STATESTS_INT_MASK
  1952.         mov     edx, ICH6_REG_STATESTS
  1953.         call    azx_writeb
  1954.  
  1955.         ; clear rirb status
  1956.         mov     al, RIRB_INT_MASK
  1957.         mov     edx, ICH6_REG_RIRBSTS
  1958.         call    azx_writeb
  1959.  
  1960.         ; clear int status
  1961.         mov     eax, ICH6_INT_CTRL_EN or ICH6_INT_ALL_STREAM
  1962.         mov     edx, ICH6_REG_INTSTS
  1963.         call    azx_writel
  1964.         pop     edx eax
  1965.         ret
  1966. endp
  1967.  
  1968.  
  1969. ; start a stream
  1970. proc azx_stream_start
  1971.         push    eax edx
  1972.  
  1973.         ; enable SIE
  1974.         mov     edx, ICH6_REG_INTCTL
  1975.         call    azx_readl
  1976.  
  1977.         or      eax, 0xC0000000 ;Asper+
  1978.         or      eax, SDO_INT  ; Asper: output stream interrupt index
  1979.         mov     edx, ICH6_REG_INTCTL
  1980.         call    azx_writel
  1981.         ; set DMA start and interrupt mask
  1982.         mov     edx, ICH6_REG_SD_CTL + SDO_OFS
  1983.         call    azx_readb
  1984.  
  1985.         or      al, SD_CTL_DMA_START or SD_INT_MASK
  1986.  
  1987.         mov     edx, ICH6_REG_SD_CTL + SDO_OFS
  1988.         call    azx_writeb
  1989.  
  1990.         pop     edx eax
  1991.         ret
  1992. endp
  1993.  
  1994. ; stop DMA
  1995. proc azx_stream_clear
  1996.         push    eax ebx edx
  1997.         mov     edx, ICH6_REG_SD_CTL + SDO_OFS
  1998.         call    azx_readb
  1999.         mov     bl, SD_CTL_DMA_START or SD_INT_MASK
  2000.         xor     bl, -1
  2001.         and     al, bl
  2002.         mov     edx, ICH6_REG_SD_CTL + SDO_OFS
  2003.         call    azx_writeb
  2004.         mov     al, SD_INT_MASK
  2005.         mov     edx, ICH6_REG_SD_STS + SDO_OFS
  2006.         call    azx_writeb
  2007.         pop     edx ebx eax
  2008.         ret
  2009. endp
  2010.  
  2011. ; stop a stream
  2012. proc azx_stream_stop
  2013.         push    eax ebx edx
  2014.         call    azx_stream_clear
  2015.         ; disable SIE
  2016.         mov     edx, ICH6_REG_INTCTL
  2017.         call    azx_readl
  2018.         mov     ebx, (SDO_INT)
  2019.         xor     ebx, -1
  2020.         and     eax, ebx
  2021.         mov     edx, ICH6_REG_INTCTL
  2022.         call    azx_writel
  2023.         pop     edx ebx eax
  2024.         ret
  2025. endp
  2026.  
  2027. ;
  2028. ;in: eax = full_reset
  2029. ;
  2030. ; initialize the chip
  2031. proc azx_init_chip
  2032.         push    eax
  2033.  
  2034.         ; reset controller
  2035.         mov     eax, 1 ;full reset
  2036.         call    reset_controller
  2037.  
  2038.         ; initialize interrupts
  2039.         call    azx_int_clear
  2040.         call    azx_int_enable
  2041.  
  2042.         ; initialize the codec command I/O
  2043. if USE_SINGLE_MODE
  2044. else
  2045.         call    azx_init_cmd_io
  2046. end if
  2047.  
  2048.         ; program the position buffer
  2049.         mov     eax, dword [ctrl.posbuf]
  2050.         mov     ebx, eax
  2051.         invoke  GetPgAddr
  2052.         and     ebx, 0xFFF
  2053.         add     eax, ebx
  2054.         mov     edx, ICH6_REG_DPLBASE
  2055.         call    azx_writel
  2056.         xor     eax, eax
  2057.         mov     edx, ICH6_REG_DPUBASE
  2058.         call    azx_writel
  2059.  
  2060.         pop     eax
  2061.         ret
  2062. endp
  2063.  
  2064.  
  2065. ; initialize the PCI registers
  2066.  
  2067. ; update bits in a PCI register byte
  2068. proc update_pci_byte  stdcall, reg:dword, mask:dword, val:dword
  2069.         push    ax bx
  2070.         invoke  PciRead8, [ctrl.bus], [ctrl.devfn], [reg]
  2071.         mov     bl, byte [mask]
  2072.         mov     bh, bl
  2073.         xor     bl, -1
  2074.         and     al, bl
  2075.         shr     bx, 8
  2076.         and     bl, byte [val]
  2077.         or      al, bl
  2078.         invoke  PciWrite8, [ctrl.bus], [ctrl.devfn], [reg], eax
  2079.         pop     bx ax
  2080.         ret
  2081. endp
  2082.  
  2083.  
  2084. proc azx_init_pci
  2085.         ; Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
  2086.         ; TCSEL == Traffic Class Select Register, which sets PCI express QOS
  2087.         ; Ensuring these bits are 0 clears playback static on some HD Audio
  2088.         ; codecs
  2089.         push    eax
  2090.         stdcall update_pci_byte, ICH6_PCIREG_TCSEL, 0x07, 0
  2091.  
  2092.         mov     eax, [driver_type]
  2093.         cmp     eax, AZX_DRIVER_ATI
  2094.         jne     @f
  2095.         ; For ATI SB450 azalia HD audio, we need to enable snoop
  2096.         stdcall update_pci_byte, ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 0x07, ATI_SB450_HDAUDIO_ENABLE_SNOOP
  2097.         jmp     .done
  2098. @@:
  2099.         cmp     eax, AZX_DRIVER_NVIDIA
  2100.         jne     @f
  2101.         ; For NVIDIA HDA, enable snoop
  2102.         stdcall update_pci_byte, NVIDIA_HDA_TRANSREG_ADDR, 0x0f, NVIDIA_HDA_ENABLE_COHBITS
  2103.         stdcall update_pci_byte, NVIDIA_HDA_ISTRM_COH, 0x01, NVIDIA_HDA_ENABLE_COHBIT
  2104.         stdcall update_pci_byte, NVIDIA_HDA_OSTRM_COH, 0x01, NVIDIA_HDA_ENABLE_COHBIT
  2105.         jmp     .done
  2106. @@:
  2107.         cmp     eax, AZX_DRIVER_SCH
  2108.         je      .l1
  2109.         cmp     eax, AZX_DRIVER_PCH
  2110.         jne     @f
  2111. .l1:
  2112.         invoke  PciRead16,  [ctrl.bus], [ctrl.devfn], dword INTEL_SCH_HDA_DEVC
  2113.         test    ax, INTEL_SCH_HDA_DEVC_NOSNOOP
  2114.         jz      @f
  2115.         push    ebx
  2116.         mov     ebx, INTEL_SCH_HDA_DEVC_NOSNOOP
  2117.         xor     ebx, -1
  2118.         and     eax, ebx
  2119.         pop     ebx
  2120.         invoke  PciWrite16,  [ctrl.bus], [ctrl.devfn], dword INTEL_SCH_HDA_DEVC, eax
  2121.         invoke  PciRead16,  [ctrl.bus], [ctrl.devfn], dword INTEL_SCH_HDA_DEVC
  2122.  
  2123. if DEBUG
  2124.         push    esi
  2125.         mov     esi, msgHDASnoopDisabled
  2126.         invoke  SysMsgBoardStr
  2127.         mov     esi, msg_OK
  2128.         test    ax, INTEL_SCH_HDA_DEVC_NOSNOOP
  2129.         jz      .snoop_ok
  2130.         mov     esi, msg_Fail
  2131. .snoop_ok:
  2132.         invoke  SysMsgBoardStr
  2133.         pop     esi
  2134. end if
  2135. @@:
  2136. .done:
  2137.         pop     eax
  2138.         ret
  2139. endp
  2140.  
  2141.  
  2142. ; reset stream
  2143. proc azx_stream_reset
  2144.         push    eax ebx ecx edx
  2145.  
  2146.         call    azx_stream_clear
  2147.  
  2148.         mov     edx, ICH6_REG_SD_CTL + SDO_OFS
  2149.         call    azx_readb
  2150.         or      al, SD_CTL_STREAM_RESET
  2151.         mov     edx, ICH6_REG_SD_CTL + SDO_OFS
  2152.         call    azx_writeb
  2153.  
  2154.         mov     eax, 3
  2155.         call    StallExec
  2156.  
  2157.         mov     ecx, 300
  2158. .l1:
  2159.         mov     edx, ICH6_REG_SD_CTL + SDO_OFS
  2160.         call    azx_readb
  2161.         test    al, SD_CTL_STREAM_RESET
  2162.         jnz     @f
  2163.         dec     ecx
  2164.         jnz     .l1
  2165. @@:
  2166.         mov     bl, SD_CTL_STREAM_RESET
  2167.         xor     bl, -1
  2168.         and     al, bl
  2169.         mov     edx, ICH6_REG_SD_CTL + SDO_OFS
  2170.         call    azx_writeb
  2171.  
  2172.         mov     eax, 3
  2173.         call    StallExec
  2174.  
  2175.         mov     ecx, 300
  2176.         ; waiting for hardware to report that the stream is out of reset
  2177. .l2:
  2178.         mov     edx, ICH6_REG_SD_CTL + SDO_OFS
  2179.         call    azx_readb
  2180.         test    al, SD_CTL_STREAM_RESET
  2181.         jnz     @f
  2182.         dec     ecx
  2183.         jnz     .l2
  2184. @@:
  2185.         ; reset first position - may not be synced with hw at this time
  2186.         mov     edx, [ctrl.posbuf]
  2187.         mov     dword [edx], 0
  2188.         pop     edx ecx ebx eax
  2189.         ret
  2190. endp
  2191.  
  2192.  
  2193. ; set up the SD for streaming
  2194. proc azx_setup_controller
  2195.         push    eax ebx ecx edx
  2196.         ; make sure the run bit is zero for SD
  2197.         call    azx_stream_clear
  2198.  
  2199.         ; program the stream_tag
  2200.         mov     edx, ICH6_REG_SD_CTL + SDO_OFS
  2201.         call    azx_readl
  2202.         mov     ecx, SD_CTL_STREAM_TAG_MASK
  2203.         xor     ecx, -1
  2204.         and     eax, ecx
  2205.         mov     ecx, SDO_TAG
  2206.         shl     ecx, SD_CTL_STREAM_TAG_SHIFT
  2207.         or      eax, ecx
  2208.         ; Asper stream_tag = SDO_TAG
  2209.         mov     edx, ICH6_REG_SD_CTL + SDO_OFS
  2210.         call    azx_writel
  2211.  
  2212.         ; program the length of samples in cyclic buffer
  2213.         mov     eax, 0x4000*32
  2214.         mov     edx, ICH6_REG_SD_CBL + SDO_OFS
  2215.         call    azx_writel
  2216.  
  2217.         ; program the stream format
  2218.         ; this value needs to be the same as the one programmed
  2219.         mov     ax, 0x11
  2220.         mov     edx, ICH6_REG_SD_FORMAT + SDO_OFS
  2221.         call    azx_writew
  2222.  
  2223.         ; program the stream LVI (last valid index) of the BDL
  2224.         mov     eax, 32-1 ;4-1 ;2-1
  2225.         mov     [ctrl.lvi_reg], eax
  2226.         mov     edx, ICH6_REG_SD_LVI + SDO_OFS
  2227.         call    azx_writew
  2228.  
  2229.         ; program the BDL address
  2230.         ; lower BDL address
  2231.         mov     eax, [pcmout_bdl]
  2232.         mov     ebx, eax
  2233.         invoke  GetPgAddr
  2234.         and     ebx, 0xFFF
  2235.         add     eax, ebx
  2236.         mov     edx, ICH6_REG_SD_BDLPL + SDO_OFS
  2237.         call    azx_writel
  2238.         ; upper BDL address
  2239.         xor     eax, eax       ;upper_32bit(azx_dev->bdl_addr)
  2240.         mov     edx, ICH6_REG_SD_BDLPU + SDO_OFS
  2241.         call    azx_writel
  2242.  
  2243.         ; enable the position buffer
  2244.         cmp     [ctrl.position_fix], POS_FIX_LPIB
  2245.         jz      @f
  2246.         mov     edx, ICH6_REG_DPLBASE
  2247.         call    azx_readl
  2248.         and     eax, ICH6_DPLBASE_ENABLE
  2249.         jnz     @f
  2250.         mov     eax, dword [ctrl.posbuf]
  2251.         mov     ebx, eax
  2252.         invoke  GetPgAddr
  2253.         and     ebx, 0xFFF
  2254.         add     eax, ebx
  2255.         or      eax, ICH6_DPLBASE_ENABLE
  2256.         mov     edx, ICH6_REG_DPLBASE
  2257.         call    azx_writel
  2258. @@:
  2259.         ; set the interrupt enable bits in the descriptor control register
  2260.         mov     edx, ICH6_REG_SD_CTL + SDO_OFS
  2261.         call    azx_readl
  2262.         or      eax, SD_INT_MASK
  2263.         mov     edx, ICH6_REG_SD_CTL + SDO_OFS
  2264.         call    azx_writel
  2265.  
  2266.         pop     edx ecx ebx eax
  2267.         ret
  2268. endp
  2269.  
  2270.  
  2271. ;(...)
  2272.  
  2273. ; Probe the given codec address
  2274. proc probe_codec, addr:dword
  2275.         push    edx
  2276.         mov     eax, [addr]
  2277.         shl     eax, 28
  2278.         mov     edx, (AC_NODE_ROOT shl 20) or (AC_VERB_PARAMETERS shl 8) or AC_PAR_VENDOR_ID
  2279.         or      eax, edx
  2280.         stdcall azx_send_cmd, eax
  2281.         stdcall azx_get_response
  2282.  
  2283.         cmp     eax, -1
  2284.         je      .out
  2285.         mov     eax, [addr]
  2286.         mov     [codec.addr], eax ;Asper+
  2287. if DEBUG
  2288.         push    esi
  2289.         mov     esi, msgCodecOK
  2290.         invoke  SysMsgBoardStr
  2291.         mov     esi, msgCAd
  2292.         invoke  SysMsgBoardStr
  2293.         stdcall fdword2str, 3
  2294.         invoke  SysMsgBoardStr
  2295.         pop     esi
  2296. end if
  2297.         xor     eax, eax
  2298. .out:
  2299.         pop     edx
  2300.         ret
  2301. endp
  2302.  
  2303.  
  2304. proc  azx_bus_reset
  2305.         call    azx_stop_chip
  2306.         call    azx_init_chip
  2307.         ret
  2308. endp
  2309.  
  2310.  
  2311. ; Codec initialization
  2312. proc azx_codec_create
  2313.         push    ebx  ecx  edx
  2314.         ;(...)
  2315.         ; First try to probe all given codec slots
  2316.         ; Asper: We asume for now that max slots for codecs = 4
  2317.         xor     ecx, ecx
  2318.         xor     edx, edx
  2319.         inc     edx
  2320. .next_slot:
  2321.         test    edx, [ctrl.codec_mask]
  2322.         jz      @f
  2323.         stdcall probe_codec, ecx
  2324.         test    eax, eax
  2325.         jz      .init ;@f
  2326.         ; Some BIOSen give you wrong codec addresses that don't exist
  2327. if DEBUG
  2328.         mov     esi, msgCodecError
  2329.         invoke  SysMsgBoardStr
  2330. end if
  2331.         mov     ebx, edx
  2332.         xor     ebx, -1
  2333.         and     [ctrl.codec_mask], ebx
  2334.  
  2335.         ; More badly, accessing to a non-existing
  2336.         ; codec often screws up the controller chip,
  2337.         ; and disturbs the further communications.
  2338.         ; Thus if an error occurs during probing,
  2339.         ; better to reset the controller chip to
  2340.         ; get back to the sanity state.
  2341.         ;call    azx_bus_reset
  2342. @@:
  2343.         shl     edx, 1
  2344.         inc     ecx
  2345. ;if USE_FIRST_CODEC
  2346. ;        cmp     ecx, 1
  2347. ;else
  2348.         cmp     ecx, 4
  2349. ;end if
  2350.         jl      .next_slot
  2351.         mov     eax, -1
  2352.         jmp     .out
  2353. .init:
  2354.         push    ecx edx
  2355.         stdcall snd_hda_codec_init
  2356.         pop     edx ecx
  2357.         test    eax, eax
  2358.         jnz     @b
  2359. .out:
  2360.         pop     edx  ecx  ebx
  2361.         ret
  2362. endp
  2363.  
  2364.  
  2365. proc azx_codec_configure
  2366.         ;(...)
  2367.         call    snd_hda_codec_configure
  2368.         ret
  2369. endp
  2370.  
  2371.  
  2372. proc azx_get_position
  2373.         test    [ctrl.position_fix], POS_FIX_LPIB
  2374.         jz      @f
  2375.         ; read LPIB
  2376.         mov     edx, ICH6_REG_SD_LPIB + SDO_OFS
  2377.         call    azx_readl
  2378.         jmp     .out
  2379. @@:
  2380.         test    [ctrl.position_fix], POS_FIX_VIACOMBO
  2381.         jz      @f
  2382. ;        call    azx_get_via_position
  2383. ;        jmp     .out
  2384. @@:
  2385.         ; use the position buffer
  2386.         push    edx
  2387.         mov     edx, dword [ctrl.posbuf]
  2388.         mov     eax, dword [edx]
  2389.         pop     edx
  2390. .out:
  2391.         cmp     eax, 0x4000 ; bufsize
  2392.         jl      @f
  2393.         xor     eax, eax
  2394. @@:
  2395.         ret
  2396. endp
  2397.  
  2398.  
  2399. proc azx_stop_chip
  2400.         push    eax edx
  2401.  
  2402.         ; disable interrupts
  2403.         call    azx_int_disable
  2404.         call    azx_int_clear
  2405.  
  2406.         ; disable CORB/RIRB
  2407.         call    azx_free_cmd_io
  2408.  
  2409.         ; disable position buffer
  2410.         xor     eax, eax
  2411.         mov     edx, ICH6_REG_DPLBASE
  2412.         call    azx_writel
  2413.         mov     edx, ICH6_REG_DPUBASE
  2414.         call    azx_writel
  2415.         pop     edx eax
  2416.         ret
  2417. endp
  2418.  
  2419.  
  2420. ; in:  eax = volume (-10000 - 0)
  2421. align 4
  2422. set_master_vol:
  2423.         mov     ecx, 3
  2424.         call    set_channel_volume
  2425.         ret
  2426.  
  2427.  
  2428. ; out:  [pvol] = volume (-10000 - 0)
  2429. align 4
  2430. proc  get_master_vol stdcall, pvol:dword
  2431.         xor     ecx, ecx
  2432.         call    get_channel_volume
  2433.         mov     ebx, [pvol]
  2434.         mov     [ebx], eax
  2435.         xor     eax, eax
  2436.         ret
  2437. endp
  2438.  
  2439.  
  2440. ; in:   ecx = channel mask (1 - Left; 2 - Right; 3-Both)
  2441. ;       eax = volume (-10000 - 0)
  2442. align 4
  2443. set_channel_volume:
  2444.         push    eax ebx ecx edx
  2445.         mov     ebx, [volume.maxDb]
  2446.         neg     eax
  2447. if DEBUG ;-
  2448.         push    eax esi
  2449.         mov     esi, msgNewVolume
  2450.         invoke  SysMsgBoardStr
  2451.         stdcall fdword2str, 2
  2452.         invoke  SysMsgBoardStr
  2453.  
  2454.         mov     esi, msgMinVolume
  2455.         invoke  SysMsgBoardStr
  2456.         mov     eax, ebx
  2457.         stdcall fdword2str, 2
  2458.         invoke  SysMsgBoardStr
  2459.         pop     esi eax
  2460. end if
  2461.         test    ebx, ebx
  2462.         jz      .err_out
  2463.  
  2464.         cmp     eax, 0
  2465.         jg      @f
  2466.         xor     eax, eax
  2467.         jmp     .set
  2468. @@:
  2469.         cmp     eax, ebx
  2470.         jng     .set
  2471.         mov     eax, ebx
  2472. .set:
  2473.         sub     ebx, eax
  2474.         mov     eax, ebx
  2475.         ;cdq
  2476.         xor     edx, edx
  2477.         push    eax
  2478.         movzx   eax, [volume.step_size]
  2479.         imul    eax, (100/4)
  2480.         mov     ebx, eax
  2481.         pop     eax
  2482.         xor     edx, edx
  2483.         idiv    ebx
  2484.  
  2485.         mov     edx, [volume.out_amp_node]
  2486.         test    edx, edx
  2487.         jz      .out
  2488.         movzx   ebx, [edx+HDA_GNODE.nid]
  2489.  
  2490.         test    ecx, 1   ; Left channel ?
  2491.         jz      @f
  2492.         stdcall put_volume_mute, ebx, 0, HDA_OUTPUT, 0, eax
  2493. @@:
  2494.         test    ecx, 2   ; Right channel ?
  2495.         jz      .out
  2496.         stdcall put_volume_mute, ebx, 1, HDA_OUTPUT, 0, eax
  2497. .out:
  2498.         pop     edx ecx ebx eax
  2499.         ret
  2500. .err_out:
  2501. if DEBUG  ;-
  2502.         push    esi
  2503.         mov     esi, emsgNoVolCtrl
  2504.         invoke  SysMsgBoardStr
  2505.         pop     esi
  2506. end if
  2507.         jmp     .out
  2508.  
  2509. ; in:   ecx = channel (1 - Left; 2 - Right)
  2510. ; out:  eax = volume (-10000 - 0)
  2511. align 4
  2512. get_channel_volume:
  2513.         push    ebx ecx edx
  2514.         cmp     ecx, 2
  2515.         jg      .out
  2516.         dec     cl
  2517.         xor     eax, eax
  2518.         mov     edx, [volume.out_amp_node]
  2519.         test    edx, edx
  2520.         jz      .out
  2521.         movzx   ebx, [edx+HDA_GNODE.nid]
  2522.         stdcall get_volume_mute, ebx, ecx, HDA_OUTPUT, 0
  2523.         and     eax, 0x7F ;get gain
  2524.         mov     cl, [volume.step_size]
  2525.         mul     cl
  2526.         imul    eax, (-100/4)
  2527. .out:
  2528.         pop     edx ecx ebx
  2529.         ret
  2530.  
  2531.  
  2532. ; in:  ecx = delay
  2533. udelay:
  2534.         push    eax ecx edx
  2535.         test    ecx, ecx
  2536.         jnz     @f
  2537.         inc     ecx
  2538. @@:
  2539.         mov     eax, ecx
  2540.         mov     cx, 500
  2541.         mul     cl
  2542.         mov     ecx, edx
  2543.         shl     ecx, 16
  2544.         or      ecx, eax
  2545. @@:
  2546.         xor     eax, eax
  2547.         cpuid
  2548.         dec     ecx
  2549.         jz      @b
  2550.         pop     edx ecx eax
  2551.         ret
  2552.  
  2553. align 4
  2554. proc StallExec
  2555.         push    ecx edx ebx eax
  2556.  
  2557.         mov     ecx, CPU_FREQ
  2558.         mul     ecx
  2559.         mov     ebx, eax       ;low
  2560.         mov     ecx, edx       ;high
  2561.         rdtsc
  2562.         add     ebx, eax
  2563.         adc     ecx,edx
  2564. @@:
  2565.         rdtsc
  2566.         sub     eax, ebx
  2567.         sbb     edx, ecx
  2568.         js      @B
  2569.  
  2570.         pop     eax ebx edx ecx
  2571.         ret
  2572. endp
  2573.  
  2574. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2575. ;         MEMORY MAPPED IO    (os depended) ;
  2576. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2577.  
  2578. align 4
  2579. proc azx_readb
  2580.         add     edx, [ctrl.ctrl_mem_base]
  2581.         mov     al, [edx]
  2582.         ret
  2583. endp
  2584.  
  2585. align 4
  2586. proc azx_readw
  2587.         add     edx, [ctrl.ctrl_mem_base]
  2588.         mov     ax, [edx]
  2589.         ret
  2590. endp
  2591.  
  2592. align 4
  2593. proc azx_readl
  2594.         add     edx, [ctrl.ctrl_mem_base]
  2595.         mov     eax, [edx]
  2596.         ret
  2597. endp
  2598.  
  2599. align 4
  2600. proc azx_writeb
  2601.         add     edx, [ctrl.ctrl_mem_base]
  2602.         mov     [edx], al
  2603.         ret
  2604. endp
  2605.  
  2606. align 4
  2607. proc azx_writew
  2608.         add     edx, [ctrl.ctrl_mem_base]
  2609.         mov     [edx], ax
  2610.         ret
  2611. endp
  2612.  
  2613. align 4
  2614. proc azx_writel
  2615.         add     edx, [ctrl.ctrl_mem_base]
  2616.         mov     [edx], eax
  2617.         ret
  2618. endp
  2619.  
  2620. ;_______
  2621.  
  2622. proc  snd_hda_automute stdcall, data:dword
  2623.         push    eax ebx ecx edx esi
  2624.         mov     esi, [spec.out_pin_node+4]
  2625.         mov     ecx, [spec.out_pin_node]
  2626.         test    esi, esi
  2627.         jnz     @f
  2628.         xchg    ecx, esi
  2629.         test    esi, esi
  2630.         jz      .out
  2631. @@:
  2632.         movzx   edx, word [esi + HDA_GNODE.nid]
  2633.         stdcall is_jack_detectable, edx
  2634.         test    eax, eax
  2635.         jz      .out
  2636.  
  2637.         stdcall snd_hda_read_pin_sense, edx, 1
  2638.         test    eax, AC_PINSENSE_PRESENCE
  2639.         jnz     @f
  2640.         xchg    ecx, esi
  2641. @@:
  2642.         ; set PIN-Out enable
  2643.         test    esi, esi
  2644.         jz      .out
  2645.         xor     edx, edx
  2646.         test    [esi + HDA_GNODE.pin_caps], AC_PINCAP_HP_DRV
  2647.         jz      @f
  2648.         mov     edx, AC_PINCTL_HP_EN
  2649. @@:
  2650.         or      edx, AC_PINCTL_OUT_EN
  2651.         movzx   eax, [esi + HDA_GNODE.nid]
  2652.         stdcall snd_hda_codec_write, eax, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, edx
  2653.  
  2654.         ; set PIN-Out disable
  2655.         test    ecx, ecx
  2656.         jz      .out
  2657.         xor     edx, edx
  2658.         movzx   eax, [ecx + HDA_GNODE.nid]
  2659.         stdcall snd_hda_codec_write, eax, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, edx
  2660. .out:
  2661.         pop     esi edx ecx ebx eax
  2662.         ret
  2663. endp
  2664.  
  2665.  
  2666. ;Asper remember to add this functions:
  2667. proc  snd_hda_queue_unsol_event stdcall, par1:dword, par2:dword
  2668. ;if DEBUG
  2669. ;        push    esi
  2670. ;        mov     esi, msgUnsolEvent
  2671. ;        invoke  SysMsgBoardStr
  2672. ;        pop     esi
  2673. ;end if
  2674. if USE_UNSOL_EV = 1
  2675.         ;Test. Do not make queue, process immediately!
  2676.         ;stdcall here snd_hda_read_pin_sense stdcall, nid:dword, trigger_sense:dword
  2677.         ;and then mute/unmute pin based on the results
  2678.         invoke  TimerHS, 1, 0, snd_hda_automute, 0
  2679. end if
  2680.         ret
  2681. endp
  2682. ;...
  2683.  
  2684.  
  2685. align 4
  2686. proc  fdword2str stdcall, flags:dword   ; bit 0 - skipLeadZeroes; bit 1 - newLine; other bits undefined
  2687.         push    eax ebx ecx
  2688.         mov     esi, hex_buff
  2689.         mov     ecx, -8
  2690.         push    eax
  2691. @@:
  2692.         rol     eax, 4
  2693.         mov     ebx, eax
  2694.         and     ebx, 0x0F
  2695.         mov     bl, [ebx+hexletters]
  2696.         mov     [8+esi+ecx], bl
  2697.         inc     ecx
  2698.         jnz     @b
  2699.         pop     eax
  2700.  
  2701.         mov     dword [esi+8], 0
  2702.         test    [flags], 0x2 ; new line ?
  2703.         jz      .no_newline
  2704.         mov     dword [esi+8], 0x00000A0D
  2705. .no_newline:
  2706.  
  2707.         push    eax
  2708.         test    [flags], 0x1 ; skip zero bits ?
  2709.         jz      .no_skipz
  2710.         mov     ecx, 8
  2711. @@:
  2712.         test    eax, 0xF0000000
  2713.         jnz     .skipz_done
  2714.         rol     eax, 4
  2715.         inc     esi
  2716.         dec     ecx
  2717.         jnz     @b
  2718.         dec     esi
  2719. .skipz_done:
  2720. .no_skipz:
  2721.         pop     eax
  2722.  
  2723.         pop     ecx ebx eax
  2724.         ret
  2725. endp
  2726.  
  2727. hexletters   db '0123456789ABCDEF'
  2728. hex_buff     db 8 dup(0),13,10,0,0
  2729.  
  2730.  
  2731. include "CODEC.INC"
  2732. include "hda_generic.inc"
  2733.  
  2734. align 4
  2735. devices:
  2736. ; Intel
  2737.         dd (CTRL_INTEL_SCH2    shl 16)+VID_INTEL,msg_INTEL_SCH2,           AZX_DRIVER_SCH
  2738.         dd (CTRL_INTEL_HPT     shl 16)+VID_INTEL,msg_INTEL_HPT,            AZX_DRIVER_SCH
  2739.         dd (CTRL_INTEL_CPT     shl 16)+VID_INTEL,msg_INTEL_CPT,            AZX_DRIVER_PCH
  2740.         dd (CTRL_INTEL_PGB     shl 16)+VID_INTEL,msg_INTEL_PGB,            AZX_DRIVER_PCH
  2741.         dd (CTRL_INTEL_PPT1    shl 16)+VID_INTEL,msg_INTEL_PPT1,           AZX_DRIVER_PCH
  2742.     dd (CTRL_INTEL_ICH6    shl 16)+VID_INTEL,msg_INTEL_ICH6,       AZX_DRIVER_ICH
  2743.         dd (CTRL_INTEL_63XXESB shl 16)+VID_INTEL,msg_INTEL_63XXESB,        AZX_DRIVER_ICH
  2744.     dd (CTRL_INTEL_ICH7    shl 16)+VID_INTEL,msg_INTEL_ICH7,       AZX_DRIVER_ICH
  2745.     dd (CTRL_INTEL_ICH8    shl 16)+VID_INTEL,msg_INTEL_ICH8,       AZX_DRIVER_ICH
  2746.         dd (CTRL_INTEL_82801_UNK1  shl 16)+VID_INTEL,msg_INTEL_82801_UNK1, AZX_DRIVER_ICH
  2747.     dd (CTRL_INTEL_ICH9    shl 16)+VID_INTEL,msg_INTEL_ICH9,       AZX_DRIVER_ICH
  2748.     dd (CTRL_INTEL_ICH9_2  shl 16)+VID_INTEL,msg_INTEL_ICH9,       AZX_DRIVER_ICH
  2749.     dd (CTRL_INTEL_ICH10   shl 16)+VID_INTEL,msg_INTEL_ICH10,      AZX_DRIVER_ICH
  2750.     dd (CTRL_INTEL_ICH10_2 shl 16)+VID_INTEL,msg_INTEL_ICH10,      AZX_DRIVER_ICH
  2751.         dd (CTRL_INTEL_PCH     shl 16)+VID_INTEL,msg_INTEL_PCH,            AZX_DRIVER_PCH
  2752.         dd (CTRL_INTEL_PCH2    shl 16)+VID_INTEL,msg_INTEL_PCH2,           AZX_DRIVER_PCH
  2753.         dd (CTRL_INTEL_SCH     shl 16)+VID_INTEL,msg_INTEL_SCH,            AZX_DRIVER_SCH
  2754.         dd (CTRL_INTEL_LPT     shl 16)+VID_INTEL,msg_INTEL_LPT,            AZX_DRIVER_PCH
  2755.     dd (CTRL_INTEL_0F04    shl 16)+VID_INTEL,msg_INTEL_BAYTRAIL,   AZX_DRIVER_PCH
  2756.     dd (CTRL_INTEL_2284    shl 16)+VID_INTEL,msg_INTEL_BRASWELL,   AZX_DRIVER_PCH
  2757.     dd (CTRL_INTEL_8ca0    shl 16)+VID_INTEL,msg_INTEL_9SERIES,    AZX_DRIVER_PCH
  2758.     dd (CTRL_INTEL_8d20    shl 16)+VID_INTEL,msg_INTEL_WELLSBURG,  AZX_DRIVER_PCH
  2759.     dd (CTRL_INTEL_8d21    shl 16)+VID_INTEL,msg_INTEL_WELLSBURG,  AZX_DRIVER_PCH
  2760.     dd (CTRL_INTEL_A1F0    shl 16)+VID_INTEL,msg_INTEL_LEWISBURG,  AZX_DRIVER_PCH
  2761.     dd (CTRL_INTEL_A270    shl 16)+VID_INTEL,msg_INTEL_LEWISBURG,  AZX_DRIVER_PCH
  2762.     dd (CTRL_INTEL_9C20    shl 16)+VID_INTEL,msg_INTEL_LYNX_LP,    AZX_DRIVER_PCH
  2763.     dd (CTRL_INTEL_9C21    shl 16)+VID_INTEL,msg_INTEL_LYNX_LP,    AZX_DRIVER_PCH
  2764.     dd (CTRL_INTEL_9CA0    shl 16)+VID_INTEL,msg_INTEL_WILD_LP,    AZX_DRIVER_PCH
  2765.     dd (CTRL_INTEL_A170    shl 16)+VID_INTEL,msg_INTEL_SUNRISE,    AZX_DRIVER_PCH
  2766.     dd (CTRL_INTEL_9D70    shl 16)+VID_INTEL,msg_INTEL_SUN_LP,     AZX_DRIVER_PCH
  2767.     dd (CTRL_INTEL_5A98    shl 16)+VID_INTEL,msg_INTEL_BROXTON,    AZX_DRIVER_PCH
  2768.  
  2769. ; Nvidia
  2770.         dd (CTRL_NVIDIA_MCP51    shl 16)+VID_NVIDIA,msg_NVIDIA_MCP51,      AZX_DRIVER_NVIDIA
  2771.         dd (CTRL_NVIDIA_MCP55    shl 16)+VID_NVIDIA,msg_NVIDIA_MCP55,      AZX_DRIVER_NVIDIA
  2772.         dd (CTRL_NVIDIA_MCP61_1  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP61,      AZX_DRIVER_NVIDIA
  2773.         dd (CTRL_NVIDIA_MCP61_2  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP61,      AZX_DRIVER_NVIDIA
  2774.         dd (CTRL_NVIDIA_MCP65_1  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP65,      AZX_DRIVER_NVIDIA
  2775.         dd (CTRL_NVIDIA_MCP65_2  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP65,      AZX_DRIVER_NVIDIA
  2776.         dd (CTRL_NVIDIA_MCP67_1  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP67,      AZX_DRIVER_NVIDIA
  2777.         dd (CTRL_NVIDIA_MCP67_2  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP67,      AZX_DRIVER_NVIDIA
  2778.         dd (CTRL_NVIDIA_MCP73_1  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP73,      AZX_DRIVER_NVIDIA
  2779.         dd (CTRL_NVIDIA_MCP73_2  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP73,      AZX_DRIVER_NVIDIA
  2780.         dd (CTRL_NVIDIA_MCP78_1  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP78,      AZX_DRIVER_NVIDIA
  2781.         dd (CTRL_NVIDIA_MCP78_2  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP78,      AZX_DRIVER_NVIDIA
  2782.         dd (CTRL_NVIDIA_MCP78_3  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP78,      AZX_DRIVER_NVIDIA
  2783.         dd (CTRL_NVIDIA_MCP78_4  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP78,      AZX_DRIVER_NVIDIA
  2784.         dd (CTRL_NVIDIA_MCP79_1  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP79,      AZX_DRIVER_NVIDIA
  2785.         dd (CTRL_NVIDIA_MCP79_2  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP79,      AZX_DRIVER_NVIDIA
  2786.         dd (CTRL_NVIDIA_MCP79_3  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP79,      AZX_DRIVER_NVIDIA
  2787.         dd (CTRL_NVIDIA_MCP79_4  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP79,      AZX_DRIVER_NVIDIA
  2788.         dd (CTRL_NVIDIA_0BE2     shl 16)+VID_NVIDIA,msg_NVIDIA_0BE2,       AZX_DRIVER_NVIDIA
  2789.         dd (CTRL_NVIDIA_0BE3     shl 16)+VID_NVIDIA,msg_NVIDIA_0BE3,       AZX_DRIVER_NVIDIA
  2790.         dd (CTRL_NVIDIA_0BE4     shl 16)+VID_NVIDIA,msg_NVIDIA_0BE4,       AZX_DRIVER_NVIDIA
  2791.         dd (CTRL_NVIDIA_GT100    shl 16)+VID_NVIDIA,msg_NVIDIA_GT100,      AZX_DRIVER_NVIDIA
  2792.         dd (CTRL_NVIDIA_GT106    shl 16)+VID_NVIDIA,msg_NVIDIA_GT106,      AZX_DRIVER_NVIDIA
  2793.         dd (CTRL_NVIDIA_GT108    shl 16)+VID_NVIDIA,msg_NVIDIA_GT108,      AZX_DRIVER_NVIDIA
  2794.         dd (CTRL_NVIDIA_GT104    shl 16)+VID_NVIDIA,msg_NVIDIA_GT104,      AZX_DRIVER_NVIDIA
  2795.         dd (CTRL_NVIDIA_GT116    shl 16)+VID_NVIDIA,msg_NVIDIA_GT116,      AZX_DRIVER_NVIDIA
  2796.         dd (CTRL_NVIDIA_MCP89_1  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP89,      AZX_DRIVER_NVIDIA
  2797.         dd (CTRL_NVIDIA_MCP89_2  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP89,      AZX_DRIVER_NVIDIA
  2798.         dd (CTRL_NVIDIA_MCP89_3  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP89,      AZX_DRIVER_NVIDIA
  2799.         dd (CTRL_NVIDIA_MCP89_4  shl 16)+VID_NVIDIA,msg_NVIDIA_MCP89,      AZX_DRIVER_NVIDIA
  2800.         dd (CTRL_NVIDIA_GF119    shl 16)+VID_NVIDIA,msg_NVIDIA_GF119,      AZX_DRIVER_NVIDIA
  2801.         dd (CTRL_NVIDIA_GF110_1  shl 16)+VID_NVIDIA,msg_NVIDIA_GF110,      AZX_DRIVER_NVIDIA
  2802.         dd (CTRL_NVIDIA_GF110_2  shl 16)+VID_NVIDIA,msg_NVIDIA_GF110,      AZX_DRIVER_NVIDIA
  2803. ; ATI
  2804.         dd (CTRL_ATI_SB450  shl 16)+VID_ATI,msg_ATI_SB450,                 AZX_DRIVER_ATI
  2805.         dd (CTRL_ATI_SB600  shl 16)+VID_ATI,msg_ATI_SB600,                 AZX_DRIVER_ATI
  2806.         dd (CTRL_ATI_RS600  shl 16)+VID_ATI,msg_ATI_RS600,                 AZX_DRIVER_ATIHDMI
  2807.         dd (CTRL_ATI_RS690  shl 16)+VID_ATI,msg_ATI_RS690,                 AZX_DRIVER_ATIHDMI
  2808.         dd (CTRL_ATI_RS780  shl 16)+VID_ATI,msg_ATI_RS780,                 AZX_DRIVER_ATIHDMI
  2809.         dd (CTRL_ATI_RS_UNK1  shl 16)+VID_ATI,msg_ATI_RS_UNK1,             AZX_DRIVER_ATIHDMI
  2810.         dd (CTRL_ATI_R600   shl 16)+VID_ATI,msg_ATI_R600,                  AZX_DRIVER_ATIHDMI
  2811.         dd (CTRL_ATI_RV610  shl 16)+VID_ATI,msg_ATI_RV610,                 AZX_DRIVER_ATIHDMI
  2812.         dd (CTRL_ATI_RV620  shl 16)+VID_ATI,msg_ATI_RV620,                 AZX_DRIVER_ATIHDMI
  2813.         dd (CTRL_ATI_RV630  shl 16)+VID_ATI,msg_ATI_RV630,                 AZX_DRIVER_ATIHDMI
  2814.         dd (CTRL_ATI_RV635  shl 16)+VID_ATI,msg_ATI_RV635,                 AZX_DRIVER_ATIHDMI
  2815.         dd (CTRL_ATI_RV670  shl 16)+VID_ATI,msg_ATI_RV670,                 AZX_DRIVER_ATIHDMI
  2816.         dd (CTRL_ATI_RV710  shl 16)+VID_ATI,msg_ATI_RV710,                 AZX_DRIVER_ATIHDMI
  2817.         dd (CTRL_ATI_RV730  shl 16)+VID_ATI,msg_ATI_RV730,                 AZX_DRIVER_ATIHDMI
  2818.         dd (CTRL_ATI_RV740  shl 16)+VID_ATI,msg_ATI_RV740,                 AZX_DRIVER_ATIHDMI
  2819.         dd (CTRL_ATI_RV770  shl 16)+VID_ATI,msg_ATI_RV770,                 AZX_DRIVER_ATIHDMI
  2820. ; AMD
  2821.         dd (CTRL_AMD_HUDSON shl 16)+VID_AMD,msg_AMD_HUDSON,                AZX_DRIVER_GENERIC
  2822.         dd (CTRL_AMD_RAVEN_RIDGE shl 16)+VID_AMD,msg_AMD_RAVEN_RIDGE,      AZX_DRIVER_GENERIC
  2823. ; VIA
  2824.         dd (CTRL_VIA_VT82XX shl 16)+VID_VIA,msg_VIA_VT82XX,                AZX_DRIVER_VIA
  2825.         dd (CTRL_VIA_VT61XX shl 16)+VID_VIA,msg_VIA_VT61XX,                AZX_DRIVER_GENERIC
  2826.         dd (CTRL_VIA_VT71XX shl 16)+VID_VIA,msg_VIA_VT71XX,                AZX_DRIVER_GENERIC
  2827. ; SiS
  2828.         dd (CTRL_SIS_966    shl 16)+VID_SIS,msg_SIS_966,                   AZX_DRIVER_SIS
  2829. ; ULI
  2830.         dd (CTRL_ULI_M5461  shl 16)+VID_ULI,msg_ULI_M5461,                 AZX_DRIVER_ULI
  2831. ; Teradici
  2832.         dd (CTRL_TERA_UNK1  shl 16)+VID_ULI,msg_TERA_UNK1,                 AZX_DRIVER_TERA
  2833. ; Creative
  2834.         dd (CTRL_CREATIVE_CA0110_IBG     shl 16)+VID_CREATIVE,msg_CREATIVE_CA0110_IBG,   AZX_DRIVER_CTX
  2835.         dd (CTRL_CREATIVE_SOUND_CORE3D_1 shl 16)+VID_CREATIVE,msg_CREATIVE_SOUND_CORE3D, AZX_DRIVER_GENERIC
  2836.         dd (CTRL_CREATIVE_SOUND_CORE3D_2 shl 16)+VID_CREATIVE,msg_CREATIVE_SOUND_CORE3D, AZX_DRIVER_GENERIC
  2837. ; RDC Semiconductor
  2838.         dd (CTRL_RDC_R3010  shl 16)+VID_RDC,msg_RDC_R3010,                 AZX_DRIVER_GENERIC
  2839. ; VMware
  2840.         dd (CTRL_VMWARE_UNK1  shl 16)+VID_VMWARE,msg_VMWARE_UNK1,          AZX_DRIVER_GENERIC
  2841.  
  2842.         dd 0    ;terminator
  2843.  
  2844.  
  2845. version      dd (5 shl 16) or (API_VERSION and 0xFFFF)
  2846.  
  2847. msg_Intel               db 'Intel ',0
  2848. msg_INTEL_CPT           db 'Cougar Point',13,10,0
  2849. msg_INTEL_PGB           db 'Patsburg',13,10,0
  2850. msg_INTEL_PPT1          db 'Panther Point',13,10,0
  2851. msg_INTEL_LPT           db 'Lynx Point',13,10,0
  2852. msg_INTEL_HPT           db 'Haswell',13,10,0
  2853. msg_INTEL_ICH6      db 'ICH6',13,10,0
  2854. msg_INTEL_63XXESB       db '631x/632xESB',13,10,0
  2855. msg_INTEL_ICH7      db 'ICH7', 13,10,0
  2856. msg_INTEL_ICH8      db 'ICH8', 13,10,0
  2857. msg_INTEL_ICH9      db 'ICH9', 13,10,0
  2858. msg_INTEL_ICH10     db 'ICH10',13,10,0
  2859. msg_INTEL_PCH           db 'PCH',13,10,0
  2860. msg_INTEL_PCH2          db 'PCH2',13,10,0
  2861. msg_INTEL_SCH           db 'Poulsbo',13,10,0
  2862. msg_INTEL_SCH2          db 'Oaktrail',13,10,0
  2863. msg_INTEL_BAYTRAIL  db 'BayTrail',  13,10,0
  2864. msg_INTEL_BRASWELL  db 'Braswell',  13,10,0
  2865. msg_INTEL_9SERIES   db '9 Series',  13,10,0
  2866. msg_INTEL_WELLSBURG db 'Wellsburg',  13,10,0
  2867. msg_INTEL_LEWISBURG db 'Lewisburg',  13,10,0
  2868. msg_INTEL_LYNX_LP   db 'Lynx Point-LP',13,10,0
  2869. msg_INTEL_WILD_LP   db 'Wildcat Point-LP',13,10,0
  2870. msg_INTEL_SUNRISE   db 'Sunrise Point',13,10,0
  2871. msg_INTEL_SUN_LP    db 'Sunrise Point-LP',13,10,0
  2872. msg_INTEL_BROXTON   db 'Broxton-P',13,10,0
  2873.  
  2874. msg_INTEL_82801_UNK1    db '82801_UNK1',  13,10,0
  2875.  
  2876. msg_NVidia              db 'NVidia ',0
  2877. msg_NVIDIA_MCP51        db 'MCP51',      13,10,0
  2878. msg_NVIDIA_MCP55        db 'MCP55',      13,10,0
  2879. msg_NVIDIA_MCP61        db 'MCP61',      13,10,0
  2880. msg_NVIDIA_MCP65        db 'MCP65',      13,10,0
  2881. msg_NVIDIA_MCP67        db 'MCP67',      13,10,0
  2882. msg_NVIDIA_MCP73        db 'MCP73',      13,10,0
  2883. msg_NVIDIA_MCP78        db 'MCP78',      13,10,0
  2884. msg_NVIDIA_MCP79        db 'MCP79',      13,10,0
  2885. msg_NVIDIA_MCP89        db 'MCP89',      13,10,0
  2886. msg_NVIDIA_0BE2         db '(0x0be2)',   13,10,0
  2887. msg_NVIDIA_0BE3         db '(0x0be3)',   13,10,0
  2888. msg_NVIDIA_0BE4         db '(0x0be4)',   13,10,0
  2889. msg_NVIDIA_GT100        db 'GT100',      13,10,0
  2890. msg_NVIDIA_GT104        db 'GT104',      13,10,0
  2891. msg_NVIDIA_GT106        db 'GT106',      13,10,0
  2892. msg_NVIDIA_GT108        db 'GT108',      13,10,0
  2893. msg_NVIDIA_GT116        db 'GT116',      13,10,0
  2894. msg_NVIDIA_GF119        db 'GF119',      13,10,0
  2895. msg_NVIDIA_GF110        db 'GF110',      13,10,0
  2896.  
  2897. msg_ATI              db 'ATI ',0
  2898. msg_ATI_SB450        db 'SB450',      13,10,0
  2899. msg_ATI_SB600        db 'SB600',      13,10,0
  2900.  
  2901. msg_ATI_HDMI         db 'ATI HDMI ',0
  2902. msg_ATI_RS600        db 'RS600',      13,10,0
  2903. msg_ATI_RS690        db 'RS690',      13,10,0
  2904. msg_ATI_RS780        db 'RS780',      13,10,0
  2905. msg_ATI_RS_UNK1      db 'RS_UNK1',    13,10,0
  2906. msg_ATI_R600         db 'R600',       13,10,0
  2907. msg_ATI_RV610        db 'RV610',      13,10,0
  2908. msg_ATI_RV620        db 'RV620',      13,10,0
  2909. msg_ATI_RV630        db 'RV630',      13,10,0
  2910. msg_ATI_RV635        db 'RV635',      13,10,0
  2911. msg_ATI_RV670        db 'RV670',      13,10,0
  2912. msg_ATI_RV710        db 'RV710',      13,10,0
  2913. msg_ATI_RV730        db 'RV730',      13,10,0
  2914. msg_ATI_RV740        db 'RV740',      13,10,0
  2915. msg_ATI_RV770        db 'RV770',      13,10,0
  2916.  
  2917. msg_AMD              db 'AMD ',0
  2918. msg_AMD_HUDSON       db 'Hudson',     13,10,0
  2919. msg_AMD_RAVEN_RIDGE  db 'RavenRidge', 13,10,0
  2920.  
  2921. msg_VIA              db 'VIA ',0
  2922. msg_VIA_VT82XX       db 'VT8251/8237A',     13,10,0
  2923. msg_VIA_VT61XX       db 'GFX VT6122/VX11',  13,10,0
  2924. msg_VIA_VT71XX       db 'GFX VT7122/VX900', 13,10,0
  2925.  
  2926. msg_SIS              db 'SIS ',0
  2927. msg_SIS_966          db '966',      13,10,0
  2928.  
  2929. msg_ULI              db 'ULI ',0
  2930. msg_ULI_M5461        db 'M5461',      13,10,0
  2931.  
  2932. msg_TERA             db 'Teradici ',0
  2933. msg_TERA_UNK1        db 'UNK1',      13,10,0
  2934.  
  2935. msg_CREATIVE                  db 'Creative ',0
  2936. msg_CREATIVE_CA0110_IBG       db 'CA0110-IBG',13,10,0 ;SB X-Fi Xtreme Audio
  2937. msg_CREATIVE_SOUND_CORE3D     db 'Sound Core3D'
  2938.  
  2939. msg_RDC              db 'RDC ',0
  2940. msg_RDC_R3010        db 'R3010', 13,10,0
  2941.  
  2942. msg_VMWARE           db 'VMware ',0
  2943. msg_VMWARE_UNK1      db 'UNK1', 13,10,0
  2944.  
  2945. szKernel             db 'KERNEL',0
  2946. sz_sound_srv         db 'SOUND',0
  2947.  
  2948. msgInit      db 'detect hardware...',13,10,0
  2949. msgFail      db 'device not found',13,10,0
  2950. msgAttchIRQ  db 'IRQ line not supported', 13,10,0
  2951. msgInvIRQ    db 'IRQ line not assigned or invalid', 13,10,0
  2952. msgPlay      db 'start play', 13,10,0
  2953. msgStop      db 'stop play',  13,10,0
  2954. msgSetChannelVolume  db 'Set Channel Volume', 13,10,0
  2955. msgIRQ       db 'HDA IRQ', 13,10,0
  2956. msgInitCtrl  db 'init controller',13,10,0
  2957. msgPrimBuff  db 'create primary buffer ...',0
  2958. msgDone      db 'done',13,10,0
  2959. msgRemap     db 'Remap IRQ',13,10,0
  2960. msgOk        db 'service installed',13,10,0
  2961. msgCold      db 'cold reset',13,10,0
  2962.     msgHDARFail    db 'controller not ready',13,10,0
  2963. msgCFail     db 'codec not ready',13,10,0
  2964. msgResetOk   db 'reset complete',13,10,0
  2965. msgPciCmd    db 'PCI command     ',0
  2966. msgPciStat   db 'PCI status      ',0
  2967.     msgHDALowMMIo db 'lower mmio base ',0
  2968.     msgHDAUpMMIo  db 'upper mmio base ',0
  2969. msgIrqMap    db 'HDA irq map as      ',0
  2970. ;msgUnsolEvent db 'Unsolicited event!',13,10,0
  2971.  
  2972. ;Asper [
  2973. if DEBUG
  2974.     msgCodecMask             db 'codec_mask = ',0
  2975.     msgNoCodecsFound         db 'no codecs found!',13,10,0
  2976.     msgHDASnoopDisabled      db 'HDA snoop disabled, enabling ... ',0
  2977.     msg_OK                   db 'OK',13,10,0
  2978.     msg_Fail                 db 'Failed',13,10,0
  2979.     msgSpuriousResponce      db 'spurious responce ',0
  2980.     emsgInvalidAFGSubtree    db 'Invalid AFG subtree',13,10,0
  2981.     emsgConnListNotAvailable db 'connection list not available for ',0
  2982.     msgUnmuteOut             db 'UNMUTE OUT: NID=',0
  2983.     msgUnmuteIn              db 'UNMUTE IN: NID=',0
  2984.     msgGetResponceTimeout    db 'get_response timeout: ',0
  2985.     msgVal                   db ' val=',0
  2986.     emsgBusResetFatalComm    db 'resetting BUS due to fatal communication error',13,10,0
  2987.     msgCodecOK               db 'codec probed OK',13,10,0
  2988.     msgCodecError            db 'codec probe error disabling it...',13,10,0
  2989.     emsgNoAFGorMFGFound      db 'no AFG or MFG node found',13,10,0
  2990.     msgNoAFGFound            db 'no AFG node found, trying another codec',13,10,0
  2991.     emsgNoMem                db 'hda_codec: cannot malloc',13,10,0
  2992.     msgConnect               db 'CONNECT: NID=',0
  2993.     msgIdx                   db ' IDX=',0
  2994.     msgSkipDigitalOutNode    db 'Skip Digital OUT node ',0
  2995.     msgAudOutFound           db 'AUD_OUT found ',0
  2996.     emsgNoParserAvailable    db 'No codec parser is available',13,10,0
  2997.     emsgNoProperOutputPathFound  db 'hda_generic: no proper output path found',13,10,0
  2998.     emsgInvConnList          db 'hda_codec: invalid CONNECT_LIST verb ',0
  2999.     emsgInvDepRangeVal       db 'hda_codec: invalid dep_range_val ',0
  3000.     emsgTooManyConns         db 'Too many connections',13,10,0
  3001.         emsgNoVolCtrl        db 'No volume control',13,10,0
  3002.     msgHDACodecSetupStream   db 'hda_codec_setup_stream: NID=',0
  3003.     msgStream                db 'stream=',0
  3004.     msgChannel               db 'channel=',0
  3005.     msgFormat                db 'format=',0
  3006.  
  3007.     msgPollingCodecOnce      db 'polling the codec once',13,10,0 ;Asper~
  3008.     msgSwitchToPollMode      db 'switching to polling mode',13,10,0 ;Asper~
  3009.  
  3010.     strSemicolon             db ':',0
  3011.     msgSETUP_FG_NODES        db 'Setup FG nodes = start_nid:total_nodes = ',0
  3012.     msgFG_TYPE               db 'FG type = ',0
  3013.     msgPinCfgs               db 'Pin configurations:',13,10,0
  3014.     msgWCaps                 db 'Widget capabilities:',13,10,0
  3015.     msgCAd                   db 'CAd = ',0
  3016.     msgTCSEL                 db 'PCI TCSEL     ',0
  3017.     msgTV                    db 'HDA test version ',TEST_VERSION_NUMBER,13,10,0
  3018.     msgGCap                  db 'GCAP = ',0
  3019. end if
  3020.  
  3021. if USE_SINGLE_MODE
  3022.     msgSingleMode            db 'Single mode !',13,10,0
  3023.     msgIRS                   db 'IRS=',0
  3024.     msgSendCmdTimeout        db 'send_cmd timeout: IRS=',0
  3025. else
  3026.     msgNormalMode            db 'Normal mode !',13,10,0
  3027. end if
  3028.  
  3029. if DEBUG
  3030.     msgYAHOO2                db 'YAHOO2: ',0
  3031.     msgMinVolume             db 'MinVolume: ',0
  3032.     msgNewVolume             db 'NewVolume: ',0
  3033.  
  3034.     msgVerbQuery             db 'Q: ',0
  3035.     msgVerbAnswer            db 'A: ',0
  3036.     msgPin_Nid               db 'Pin Nid = ',0
  3037.     msgPin_Ctl               db 'Pin Control = ',0
  3038.     msgPin_Caps              db 'Pin Capabilities = ',0
  3039.     msgDef_Cfg               db 'Pin def_cfg = ',0
  3040.     msgAmp_Out_Caps          db 'Pin Amp Out caps = ',0
  3041.     msgAmpVal                db 'Amp val = ',0
  3042.     msgEnableEAPD            db 'Enable EAPD: NID=',0
  3043.     msgBeeperNid             db 'Beeper found: NID=',0
  3044.     msgBeeperValue           db 'Beeper initial value: ',0
  3045.     msgBeepNow               db 'Beep!',13,10,0
  3046.  
  3047.     msgNodeSeq               db 'Sequence of codec nodes:',13,10,0
  3048.     msgNID                   db 'NID: 0x',0
  3049. end if
  3050.  
  3051. ;] Asper
  3052.  
  3053. aspinlock        dd SPINLOCK_FREE
  3054.  
  3055. codec CODEC
  3056. ctrl AC_CNTRL
  3057.  
  3058. ;Asper: BDL must be aligned to 128 according to HDA specification.
  3059. pcmout_bdl       rd 1
  3060. buff_list        rd 32
  3061.  
  3062. driver_type      rd 1
  3063.