| // Copyright 2017 The Fuchsia Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| #include <zircon/assert.h> | |
| #include <fbl/auto_lock.h> | |
| #include <string.h> | |
| #include <intel-hda/utils/intel-hda-registers.h> | |
| #include "codec-cmd-job.h" | |
| #include "debug-logging.h" | |
| #include "intel-hda-controller.h" | |
| #include "thread-annotations.h" | |
| namespace audio { | |
| namespace intel_hda { | |
| namespace { | |
| fbl::Mutex snapshot_regs_buffer_lock; | |
| ihda_controller_snapshot_regs_resp_t snapshot_regs_buffer TA_GUARDED(snapshot_regs_buffer_lock); | |
| } // anon namespace | |
| zx_status_t IntelHDAController::SnapshotRegs(dispatcher::Channel* channel, | |
| const ihda_controller_snapshot_regs_req_t& req) { | |
| ZX_DEBUG_ASSERT(channel != nullptr); | |
| // TODO(johngro) : What an enormous PITA. Every register needs to be | |
| // accessed with the proper sized transaction on the PCI bus, so we cannot | |
| // just use memcpy to do this. Life will be better when we have VMOs in | |
| // place. Then, we can implement the IOCTL by simply cloning the reigster | |
| // VMO (reducing its rights to read-only in the process) and sending it back | |
| // to the calling process. The diagnostic util can then put their own | |
| // cycles on the PCI bus. | |
| fbl::AutoLock lock(&snapshot_regs_buffer_lock); | |
| auto regs_ptr = reinterpret_cast<hda_registers_t*>(snapshot_regs_buffer.snapshot); | |
| auto& regs = *regs_ptr; | |
| static_assert(sizeof(snapshot_regs_buffer.snapshot) == sizeof(hda_registers_t), | |
| "Register snapshot buffer size does not match register file size!"); | |
| snapshot_regs_buffer.hdr = req.hdr; | |
| memset(®s, 0, sizeof(regs)); | |
| regs.gcap = REG_RD(®s_->gcap); | |
| regs.vmin = REG_RD(®s_->vmin); | |
| regs.vmaj = REG_RD(®s_->vmaj); | |
| regs.outpay = REG_RD(®s_->outpay); | |
| regs.inpay = REG_RD(®s_->inpay); | |
| regs.gctl = REG_RD(®s_->gctl); | |
| regs.wakeen = REG_RD(®s_->wakeen); | |
| regs.statests = REG_RD(®s_->statests); | |
| regs.gsts = REG_RD(®s_->gsts); | |
| regs.outstrmpay = REG_RD(®s_->outstrmpay); | |
| regs.instrmpay = REG_RD(®s_->instrmpay); | |
| regs.intctl = REG_RD(®s_->intctl); | |
| regs.intsts = REG_RD(®s_->intsts); | |
| regs.walclk = REG_RD(®s_->walclk); | |
| regs.ssync = REG_RD(®s_->ssync); | |
| regs.corblbase = REG_RD(®s_->corblbase); | |
| regs.corbubase = REG_RD(®s_->corbubase); | |
| regs.corbwp = REG_RD(®s_->corbwp); | |
| regs.corbrp = REG_RD(®s_->corbrp); | |
| regs.corbctl = REG_RD(®s_->corbctl); | |
| regs.corbsts = REG_RD(®s_->corbsts); | |
| regs.corbsize = REG_RD(®s_->corbsize); | |
| regs.rirblbase = REG_RD(®s_->rirblbase); | |
| regs.rirbubase = REG_RD(®s_->rirbubase); | |
| regs.rirbwp = REG_RD(®s_->rirbwp); | |
| regs.rintcnt = REG_RD(®s_->rintcnt); | |
| regs.rirbctl = REG_RD(®s_->rirbctl); | |
| regs.rirbsts = REG_RD(®s_->rirbsts); | |
| regs.rirbsize = REG_RD(®s_->rirbsize); | |
| regs.icoi = REG_RD(®s_->icoi); | |
| regs.icii = REG_RD(®s_->icii); | |
| regs.icis = REG_RD(®s_->icis); | |
| regs.dpiblbase = REG_RD(®s_->dpiblbase); | |
| regs.dpibubase = REG_RD(®s_->dpibubase); | |
| uint16_t gcap = REG_RD(®s_->gcap); | |
| unsigned int stream_cnt = HDA_REG_GCAP_ISS(gcap) | |
| + HDA_REG_GCAP_OSS(gcap) | |
| + HDA_REG_GCAP_BSS(gcap); | |
| for (unsigned int i = 0; i < stream_cnt; ++i) { | |
| auto& sin = regs_->stream_desc[i]; | |
| auto& sout = regs.stream_desc[i]; | |
| sout.ctl_sts.w = REG_RD(&sin.ctl_sts.w); | |
| sout.lpib = REG_RD(&sin.lpib); | |
| sout.cbl = REG_RD(&sin.cbl); | |
| sout.lvi = REG_RD(&sin.lvi); | |
| sout.fifod = REG_RD(&sin.fifod); | |
| sout.fmt = REG_RD(&sin.fmt); | |
| sout.bdpl = REG_RD(&sin.bdpl); | |
| sout.bdpu = REG_RD(&sin.bdpu); | |
| } | |
| return channel->Write(&snapshot_regs_buffer, sizeof(snapshot_regs_buffer)); | |
| } | |
| } // namespace intel_hda | |
| } // namespace audio |