1 // Copyright 2016 The Fuchsia Authors 2 // 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file or at 5 // https://opensource.org/licenses/MIT 6 7 #pragma once 8 9 #include <assert.h> 10 #include <fbl/array.h> 11 #include <fbl/canary.h> 12 #include <fbl/intrusive_double_list.h> 13 #include <fbl/macros.h> 14 #include <fbl/ref_counted.h> 15 #include <fbl/ref_ptr.h> 16 #include <kernel/mutex.h> 17 #include <lib/user_copy/user_ptr.h> 18 #include <list.h> 19 #include <stdint.h> 20 #include <vm/vm.h> 21 #include <vm/vm_object.h> 22 #include <zircon/thread_annotations.h> 23 #include <zircon/types.h> 24 25 // VMO representing a physical range of memory 26 class VmObjectPhysical final : public VmObject { 27 public: 28 static zx_status_t Create(paddr_t base, uint64_t size, fbl::RefPtr<VmObject>* vmo); 29 is_contiguous()30 bool is_contiguous() const override { return true; } 31 size()32 uint64_t size() const override { return size_; } 33 34 zx_status_t Lookup(uint64_t offset, uint64_t len, 35 vmo_lookup_fn_t lookup_fn, void* context) override; 36 37 void Dump(uint depth, bool verbose) override; 38 39 zx_status_t GetPageLocked(uint64_t offset, uint pf_flags, list_node* free_list, 40 vm_page_t**, paddr_t* pa) override TA_REQ(lock_); 41 42 uint32_t GetMappingCachePolicy() const override; 43 zx_status_t SetMappingCachePolicy(const uint32_t cache_policy) override; 44 45 private: 46 // private constructor (use Create()) 47 VmObjectPhysical(paddr_t base, uint64_t size); 48 49 // private destructor, only called from refptr 50 ~VmObjectPhysical() override; 51 friend fbl::RefPtr<VmObjectPhysical>; 52 53 DISALLOW_COPY_ASSIGN_AND_MOVE(VmObjectPhysical); 54 55 // members 56 const uint64_t size_ = 0; 57 const paddr_t base_ = 0; 58 uint32_t mapping_cache_flags_ TA_GUARDED(lock_) = 0; 59 }; 60