1// Copyright 2017 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <ddk/io-buffer.h>
6#include <ddk/protocol/platform-device.h>
7#include <zircon/types.h>
8#include <lib/zx/vmo.h>
9
10namespace audio {
11namespace gauss {
12
13class VmoHelperBase {
14public:
15    zx_status_t AllocateVmo(zx_handle_t bti, size_t buffer_size);
16    zx_status_t GetVmoRange(zx_paddr_t* start_address);
17    zx_status_t Duplicate(uint32_t rights, zx::vmo* handle);
18    void DestroyVmo();
19
20protected:
21    io_buffer_t buffer_;
22    bool valid_ = false;
23};
24
25template <bool DEBUG>
26class VmoHelper : public VmoHelperBase {
27public:
28    zx_status_t AllocateVmo(zx_handle_t bti, size_t buffer_size);
29    void printoffsetinvmo(uint32_t offset);
30    void DestroyVmo();
31};
32
33template <>
34class VmoHelper<true> : public VmoHelperBase {
35public:
36    zx_status_t AllocateVmo(zx_handle_t bti, size_t buffer_size);
37    void printoffsetinvmo(uint32_t offset);
38    void DestroyVmo();
39
40private:
41    uintptr_t ring_buffer_virt_;
42};
43}
44}
45