ac97: extract moving to next buffer into function

Create a function move_to_next_buffer which handles incrementing civ and
piv properly.

Set the PICB register when that function is called, not when we read a
guest buffer.

BUG=chromium:968724
TEST=playback on-device

Change-Id: Ib384efceeac4be0e056c20591d93fe32b7305db6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954207
Reviewed-by: Fletcher Woodruff <fletcherw@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
Tested-by: Fletcher Woodruff <fletcherw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Fletcher Woodruff 2019-12-04 11:46:00 -07:00 committed by Commit Bot
parent bf433ea9f6
commit 65588b2535
2 changed files with 11 additions and 4 deletions

View file

@ -621,7 +621,8 @@ fn play_buffer(
Ok(()) Ok(())
} }
// Moves to the next buffer for the given function and registers. // Marks the current buffer completed and moves to the next buffer for the given
// function and registers.
fn buffer_completed( fn buffer_completed(
regs: &mut Ac97BusMasterRegs, regs: &mut Ac97BusMasterRegs,
mem: &GuestMemory, mem: &GuestMemory,
@ -645,13 +646,12 @@ fn buffer_completed(
if civ == lvi { if civ == lvi {
new_sr |= SR_DCH | SR_CELV | SR_LVBCI; new_sr |= SR_DCH | SR_CELV | SR_LVBCI;
} else { } else {
let func_regs = regs.func_regs_mut(func); regs.func_regs_mut(func).move_to_next_buffer();
func_regs.civ = func_regs.piv;
func_regs.piv = (func_regs.piv + 1) % 32; // move piv to the next buffer.
} }
update_sr(regs, func, new_sr); update_sr(regs, func, new_sr);
regs.func_regs_mut(func).picb = current_buffer_size(regs.func_regs(func), &mem)? as u16;
if func == Ac97Function::Output { if func == Ac97Function::Output {
regs.po_pointer_update_time = Instant::now(); regs.po_pointer_update_time = Instant::now();
} }

View file

@ -243,4 +243,11 @@ impl Ac97FunctionRegs {
} }
int_mask int_mask
} }
/// Sets the current buffer to the next buffer by updating CIV to PIV, and
/// updates related fields.
pub fn move_to_next_buffer(&mut self) {
self.civ = self.piv;
self.piv = (self.piv + 1) % 32; // move piv to the next buffer.
}
} }