mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-25 23:10:32 +00:00
Refactor entire HDAudio driver to use new register functions, instead of direct pointer manipulation.
This commit is contained in:
parent
d58bc8c410
commit
f8729688b9
1 changed files with 45 additions and 78 deletions
|
@ -285,8 +285,10 @@ U8 HDAudioRegReadU8(U16 hd_reg)
|
||||||
return *dest;
|
return *dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
*wp = hda.corb_wp;
|
U0 HDSyncCORB()
|
||||||
while (*rp & 255 != hda.corb_wp)
|
{
|
||||||
|
HDAudioRegWriteU16(HD_CORBWP, hda.corb_wp);
|
||||||
|
while (HDAudioRegReadU16(HD_CORBRP) & 0xFF != hda.corb_wp)
|
||||||
Yield;
|
Yield;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,8 +300,7 @@ U0 HDWriteCORB(I64 cad, I64 nid, U32 val)
|
||||||
|
|
||||||
I64 HDSyncRIRB()
|
I64 HDSyncRIRB()
|
||||||
{
|
{
|
||||||
U16 *_w = hda.bar + HD_RIRBWP;
|
I64 wp = HDAudioRegReadU16(HD_RIRBWP), res = 0;
|
||||||
I64 wp = *_w, res = 0;
|
|
||||||
|
|
||||||
while (hda.rirb_rp != wp)
|
while (hda.rirb_rp != wp)
|
||||||
res = hda.rirb[++hda.rirb_rp];
|
res = hda.rirb[++hda.rirb_rp];
|
||||||
|
@ -309,13 +310,12 @@ I64 HDSyncRIRB()
|
||||||
|
|
||||||
I64 HDReadRIRB()
|
I64 HDReadRIRB()
|
||||||
{
|
{
|
||||||
U16 *_w = hda.bar + HD_RIRBWP;
|
|
||||||
I64 wp, res = 0;
|
I64 wp, res = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Yield;
|
Yield;
|
||||||
wp = *_w;
|
wp = HDAudioRegReadU16(HD_RIRBWP);
|
||||||
} while (wp == hda.rirb_rp);
|
} while (wp == hda.rirb_rp);
|
||||||
res = hda.rirb[++hda.rirb_rp];
|
res = hda.rirb[++hda.rirb_rp];
|
||||||
|
|
||||||
|
@ -334,7 +334,6 @@ I64 HDWriteCORBSync(I64 cad, I64 nid, U32 val)
|
||||||
Bool HDTestCORBSync(I64 cad, I64 nid, U32 val)
|
Bool HDTestCORBSync(I64 cad, I64 nid, U32 val)
|
||||||
{
|
{
|
||||||
//Checks for a response
|
//Checks for a response
|
||||||
U16 *_w;
|
|
||||||
I64 wp;
|
I64 wp;
|
||||||
|
|
||||||
HDSyncCORB;
|
HDSyncCORB;
|
||||||
|
@ -343,8 +342,7 @@ Bool HDTestCORBSync(I64 cad, I64 nid, U32 val)
|
||||||
HDSyncCORB;
|
HDSyncCORB;
|
||||||
|
|
||||||
Sleep(1);
|
Sleep(1);
|
||||||
_w = hda.bar + HD_RIRBWP;
|
wp = HDAudioRegReadU16(HD_RIRBWP);
|
||||||
wp = *_w;
|
|
||||||
if (wp == hda.rirb_rp)
|
if (wp == hda.rirb_rp)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
HDReadRIRB;
|
HDReadRIRB;
|
||||||
|
@ -404,20 +402,17 @@ U0 HDTraverse(I64 cad, I64 nid)
|
||||||
|
|
||||||
U0 HDRun(Bool in, Bool out)
|
U0 HDRun(Bool in, Bool out)
|
||||||
{
|
{
|
||||||
U32 *_d;
|
|
||||||
if (hda.bar)
|
if (hda.bar)
|
||||||
{
|
{
|
||||||
if (out)
|
if (out)
|
||||||
{
|
{
|
||||||
_d = hda.bar + OSTR0 + STRCTL;
|
HDAudioRegWriteU32(OSTR0 + STRCTL, 0x100002); // ??
|
||||||
*_d = 0x100002;
|
|
||||||
hda.out_running = TRUE;
|
hda.out_running = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in)
|
if (in)
|
||||||
{
|
{
|
||||||
_d = hda.bar + ISTR0 + STRCTL;
|
HDAudioRegWriteU32(ISTR0 + STRCTL, 0x200002); // ??
|
||||||
*_d = 0x200002;
|
|
||||||
hda.in_running = TRUE;
|
hda.in_running = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -425,20 +420,17 @@ U0 HDRun(Bool in, Bool out)
|
||||||
|
|
||||||
U0 HDStop(Bool in, Bool out)
|
U0 HDStop(Bool in, Bool out)
|
||||||
{
|
{
|
||||||
U32 *_d;
|
|
||||||
if (hda.bar)
|
if (hda.bar)
|
||||||
{
|
{
|
||||||
if (out)
|
if (out)
|
||||||
{
|
{
|
||||||
_d = hda.bar + OSTR0 + STRCTL;
|
HDAudioRegWriteU32(OSTR0 + STRCTL, 0); // ??
|
||||||
*_d = 0;
|
|
||||||
hda.out_running = FALSE;
|
hda.out_running = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in)
|
if (in)
|
||||||
{
|
{
|
||||||
_d = hda.bar + ISTR0 + STRCTL;
|
HDAudioRegWriteU32(ISTR0 + STRCTL, 0); // ??
|
||||||
*_d = 0;
|
|
||||||
hda.in_running = FALSE;
|
hda.in_running = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -556,22 +548,22 @@ U0 HDAudioTask(I64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
U0 HDRst()
|
U0 HDReset()
|
||||||
{
|
{
|
||||||
U32 d, *_d = hda.bar + HD_GCTL;
|
U32 d;
|
||||||
|
|
||||||
HDStop(TRUE, TRUE);
|
HDStop(TRUE, TRUE);
|
||||||
*_d = 0; //rst
|
HDAudioRegWriteU32(HD_GCTL, 0); //rst // ??
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Sleep(1);
|
Sleep(1);
|
||||||
d = *_d;
|
d = HDAudioRegReadU32(HD_GCTL);
|
||||||
} while (d & 1);
|
} while (d & 1);
|
||||||
*_d = 1;
|
HDAudioRegWriteU32(HD_GCTL, 1); //??
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Sleep(1);
|
Sleep(1);
|
||||||
d = *_d;
|
d = HDAudioRegReadU32(HD_GCTL);
|
||||||
} while (!(d & 1));
|
} while (!(d & 1));
|
||||||
Sleep(1);
|
Sleep(1);
|
||||||
}
|
}
|
||||||
|
@ -609,9 +601,7 @@ U0 HDAudioUncachedInit()
|
||||||
public Bool HDAudioInit(I64 hd_bus, I64 hd_dev, I64 hd_fun)
|
public Bool HDAudioInit(I64 hd_bus, I64 hd_dev, I64 hd_fun)
|
||||||
{
|
{
|
||||||
I64 i;
|
I64 i;
|
||||||
U32 *_d;
|
U16 w, val;
|
||||||
U16 w, *_w, val;
|
|
||||||
U8 *_b;
|
|
||||||
|
|
||||||
if (hda.bar)
|
if (hda.bar)
|
||||||
HDAudioEnd;
|
HDAudioEnd;
|
||||||
|
@ -628,52 +618,40 @@ public Bool HDAudioInit(I64 hd_bus, I64 hd_dev, I64 hd_fun)
|
||||||
val |= PCI_CMDF_IOEN | PCI_CMDF_BMEN | PCI_CMDF_INTD | PCI_CMDF_MSEN;
|
val |= PCI_CMDF_IOEN | PCI_CMDF_BMEN | PCI_CMDF_INTD | PCI_CMDF_MSEN;
|
||||||
PCIWriteU16(hd_bus, hd_dev, hd_fun, PCIR_COMMAND, val);
|
PCIWriteU16(hd_bus, hd_dev, hd_fun, PCIR_COMMAND, val);
|
||||||
|
|
||||||
HDRst;
|
HDReset;
|
||||||
|
|
||||||
hda.corb = CAllocAligned(HD_CORB_ENTRIES * sizeof(U32), 128, hda.hc);
|
hda.corb = CAllocAligned(HD_CORB_ENTRIES * sizeof(U32), 128, hda.hc);
|
||||||
_d = hda.bar + HD_CORBLBASE;
|
HDAudioRegWriteU32(HD_CORBLBASE, hda.corb(I64).u32[0]);
|
||||||
*_d = hda.corb(I64).u32[0];
|
HDAudioRegWriteU32(HD_CORBUBASE, hda.corb(I64).u32[1]);
|
||||||
_d = hda.bar + HD_CORBUBASE;
|
|
||||||
*_d = hda.corb(I64).u32[1];
|
|
||||||
|
|
||||||
hda.rirb = CAllocAligned(HD_RIRB_ENTRIES * sizeof(I64), 128, hda.hc);
|
hda.rirb = CAllocAligned(HD_RIRB_ENTRIES * sizeof(I64), 128, hda.hc);
|
||||||
_d = hda.bar + HD_RIRBLBASE;
|
HDAudioRegWriteU32(HD_RIRBLBASE, hda.rirb(I64).u32[0]);
|
||||||
*_d = hda.rirb(I64).u32[0];
|
HDAudioRegWriteU32(HD_RIRBUBASE, hda.rirb(I64).u32[1]);
|
||||||
_d = hda.bar + HD_RIRBUBASE;
|
|
||||||
*_d = hda.rirb(I64).u32[1];
|
|
||||||
|
|
||||||
_w = hda.bar + HD_CORBRP;
|
HDAudioRegWriteU16(HD_CORBRP, 0x8000); //Rst read ptr // ??
|
||||||
*_w = 0x8000; //Rst read ptr
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Yield;
|
Yield;
|
||||||
w = *_w;
|
w = HDAudioRegReadU16(HD_CORBRP);
|
||||||
} while (!(w & 0x8000));
|
} while (!(w & 0x8000));
|
||||||
*_w = 0x0000; //Rst read ptr
|
HDAudioRegWriteU16(HD_CORBRP, 0x0000); //Rst read ptr // ??
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Yield;
|
Yield;
|
||||||
w = *_w;
|
w = HDAudioRegReadU16(HD_CORBRP);
|
||||||
} while (w & 0x8000);
|
} while (w & 0x8000);
|
||||||
|
|
||||||
_w = hda.bar + HD_RIRBWP;
|
HDAudioRegWriteU16(HD_RIRBWP, 0x8000); //Rst write ptr // ??
|
||||||
*_w = 0x8000; //Rst write ptr
|
|
||||||
|
|
||||||
_b = hda.bar + HD_CORBCTL;
|
HDAudioRegWriteU8(HD_CORBCTL, 0x02); //Run // ??
|
||||||
*_b = 0x02; //Run
|
HDAudioRegWriteU8(HD_RIRBCTL, 0x02); //Run // ??
|
||||||
_b = hda.bar + HD_RIRBCTL;
|
|
||||||
*_b = 0x02; //Run
|
|
||||||
|
|
||||||
_w = hda.bar + HD_CORBWP;
|
hda.corb_wp = HDAudioRegReadU16(HD_CORBWP);
|
||||||
hda.corb_wp = *_w;
|
hda.rirb_rp = HDAudioRegReadU16(HD_RIRBWP);
|
||||||
_w = hda.bar + HD_RIRBWP;
|
|
||||||
hda.rirb_rp = *_w;
|
|
||||||
|
|
||||||
hda.ostr0_bdl = CAllocAligned(HD_BDL_ENTRIES * sizeof(CHDBufDesc), 128, hda.hc);
|
hda.ostr0_bdl = CAllocAligned(HD_BDL_ENTRIES * sizeof(CHDBufDesc), 128, hda.hc);
|
||||||
_d = hda.bar + OSTR0 + STRBDPL;
|
HDAudioRegWriteU32(OSTR0 + STRBDPL, hda.ostr0_bdl(I64).u32[0]);
|
||||||
*_d = hda.ostr0_bdl(I64).u32[0];
|
HDAudioRegWriteU32(OSTR0 + STRBDPU, hda.ostr0_bdl(I64).u32[1]);
|
||||||
_d = hda.bar + OSTR0 + STRBDPU;
|
|
||||||
*_d = hda.ostr0_bdl(I64).u32[1];
|
|
||||||
for (i = 0; i < 2; i++)
|
for (i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
hda.ostr0_bdl[i].buf = hda.ostr0_buf[i] = CAllocAligned(SND_BUF_LEN * sizeof(SND_OUT_CONTAINER), 128, hda.hc);
|
hda.ostr0_bdl[i].buf = hda.ostr0_buf[i] = CAllocAligned(SND_BUF_LEN * sizeof(SND_OUT_CONTAINER), 128, hda.hc);
|
||||||
|
@ -682,10 +660,8 @@ public Bool HDAudioInit(I64 hd_bus, I64 hd_dev, I64 hd_fun)
|
||||||
}
|
}
|
||||||
|
|
||||||
hda.istr0_bdl = CAllocAligned(HD_BDL_ENTRIES * sizeof(CHDBufDesc), 128, hda.hc);
|
hda.istr0_bdl = CAllocAligned(HD_BDL_ENTRIES * sizeof(CHDBufDesc), 128, hda.hc);
|
||||||
_d = hda.bar + ISTR0 + STRBDPL;
|
HDAudioRegWriteU32(ISTR0 + STRBDPL, hda.istr0_bdl(I64).u32[0]);
|
||||||
*_d = hda.istr0_bdl(I64).u32[0];
|
HDAudioRegWriteU32(ISTR0 + STRBDPU, hda.istr0_bdl(I64).u32[1]);
|
||||||
_d = hda.bar + ISTR0 + STRBDPU;
|
|
||||||
*_d = hda.istr0_bdl(I64).u32[1];
|
|
||||||
for (i = 0; i < 2; i++)
|
for (i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
hda.istr0_bdl[i].buf = hda.istr0_buf[i] = CAllocAligned(SND_BUF_LEN * sizeof(SND_IN_CONTAINER), 128, hda.hc);
|
hda.istr0_bdl[i].buf = hda.istr0_buf[i] = CAllocAligned(SND_BUF_LEN * sizeof(SND_IN_CONTAINER), 128, hda.hc);
|
||||||
|
@ -693,8 +669,7 @@ public Bool HDAudioInit(I64 hd_bus, I64 hd_dev, I64 hd_fun)
|
||||||
hda.istr0_bdl[i].ctrl = 1;
|
hda.istr0_bdl[i].ctrl = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_w = hda.bar + HD_STATESTS;
|
w = HDAudioRegReadU16(HD_STATESTS);
|
||||||
w = *_w;
|
|
||||||
while (w)
|
while (w)
|
||||||
{
|
{
|
||||||
hda.cad = Bsf(w);
|
hda.cad = Bsf(w);
|
||||||
|
@ -702,23 +677,15 @@ public Bool HDAudioInit(I64 hd_bus, I64 hd_dev, I64 hd_fun)
|
||||||
{
|
{
|
||||||
HDTraverse(hda.cad, 0);
|
HDTraverse(hda.cad, 0);
|
||||||
|
|
||||||
_d = hda.bar + OSTR0 + STRLPIB;
|
HDAudioRegWriteU32(OSTR0 + STRLPIB, 0);
|
||||||
*_d = 0;
|
HDAudioRegWriteU32(OSTR0 + STRCBL, HD_POS_BUF_MULTIPLES * SND_BUF_LEN * sizeof(SND_OUT_CONTAINER));
|
||||||
_d = hda.bar + OSTR0 + STRCBL;
|
HDAudioRegWriteU16(OSTR0 + STRLVI, 1); //last valid idx // ??
|
||||||
*_d = HD_POS_BUF_MULTIPLES * SND_BUF_LEN * sizeof(SND_OUT_CONTAINER);
|
HDAudioRegWriteU16(OSTR0 + STRFMT, HD_DFT_OUT_FMT);
|
||||||
_w = hda.bar + OSTR0 + STRLVI;
|
|
||||||
*_w = 1; //last valid idx
|
|
||||||
_w = hda.bar + OSTR0 + STRFMT;
|
|
||||||
*_w = HD_DFT_OUT_FMT;
|
|
||||||
|
|
||||||
_d = hda.bar + ISTR0 + STRLPIB;
|
HDAudioRegWriteU32(ISTR0 + STRLPIB, 0);
|
||||||
*_d = 0;
|
HDAudioRegWriteU32(ISTR0 + STRCBL, HD_POS_BUF_MULTIPLES * SND_BUF_LEN * sizeof(SND_IN_CONTAINER));
|
||||||
_d = hda.bar + ISTR0 + STRCBL;
|
HDAudioRegWriteU16(ISTR0 + STRLVI, 1); //last valid idx // ??
|
||||||
*_d = HD_POS_BUF_MULTIPLES * SND_BUF_LEN * sizeof(SND_IN_CONTAINER);
|
HDAudioRegWriteU16(ISTR0 + STRFMT, HD_DFT_IN_FMT);
|
||||||
_w = hda.bar + ISTR0 + STRLVI;
|
|
||||||
*_w = 1; //last valid idx
|
|
||||||
_w = hda.bar + ISTR0 + STRFMT;
|
|
||||||
*_w = HD_DFT_IN_FMT;
|
|
||||||
|
|
||||||
LBts(&sys_semas[SEMA_SOUND], 0); //turn off until cfg completed
|
LBts(&sys_semas[SEMA_SOUND], 0); //turn off until cfg completed
|
||||||
LBtr(&snd_flags, Sf_FILLING_OUT);
|
LBtr(&snd_flags, Sf_FILLING_OUT);
|
||||||
|
|
Loading…
Reference in a new issue