Subversion Repositories Kolibri OS

Rev

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