blob: 1b12c4b90f20b3154d010b90376d2358636748c2 [file] [log] [blame]
// Copyright 2018 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.
#pragma once
#include <zircon/types.h>
__BEGIN_CDECLS;
typedef struct {
// |vaddr| points to the content starting at |offset| in |vmo|.
void* vaddr;
zx_off_t offset;
size_t size;
zx_handle_t vmo;
} mmio_buffer_t;
typedef struct {
const mmio_buffer_t* mmio;
zx_handle_t pmt;
// |paddr| points to the content starting at |mmio->offset| in |mmio->vmo|.
zx_paddr_t paddr;
} mmio_pinned_buffer_t;
// Takes raw mmio resources, and maps it into address space. |offset| is the
// offset from the begining of |vmo| where the mmio region begins. |size|
// specifies the size of the mmio region. |offset| + |size| must be less than
// or equal to the size of |vmo|.
// Always consumes |vmo|, including in error cases.
zx_status_t mmio_buffer_init(mmio_buffer_t* buffer, zx_off_t offset, size_t size,
zx_handle_t vmo, uint32_t cache_policy);
// Unmaps the mmio region.
void mmio_buffer_release(mmio_buffer_t* buffer);
// Returns a pinned buffer if successful. |buffer| must outlive |out|.
//
// Example usage: A device needs access to another device's MMIO space.
zx_status_t mmio_buffer_pin(mmio_buffer_t* buffer, zx_handle_t bti, mmio_pinned_buffer_t* out);
// Unpins the buffer.
void mmio_buffer_unpin(mmio_pinned_buffer_t* buffer);
__END_CDECLS;