88
99#include <linux/device.h>
1010#include <linux/dma-direction.h>
11+ #include <linux/spinlock.h>
1112#include <linux/types.h>
1213
1314enum host1x_class {
@@ -24,6 +25,28 @@ struct iommu_group;
2425
2526u64 host1x_get_dma_mask (struct host1x * host1x );
2627
28+ /**
29+ * struct host1x_bo_cache - host1x buffer object cache
30+ * @mappings: list of mappings
31+ * @lock: synchronizes accesses to the list of mappings
32+ */
33+ struct host1x_bo_cache {
34+ struct list_head mappings ;
35+ struct mutex lock ;
36+ };
37+
38+ static inline void host1x_bo_cache_init (struct host1x_bo_cache * cache )
39+ {
40+ INIT_LIST_HEAD (& cache -> mappings );
41+ mutex_init (& cache -> lock );
42+ }
43+
44+ static inline void host1x_bo_cache_destroy (struct host1x_bo_cache * cache )
45+ {
46+ /* XXX warn if not empty? */
47+ mutex_destroy (& cache -> lock );
48+ }
49+
2750/**
2851 * struct host1x_client_ops - host1x client operations
2952 * @early_init: host1x client early initialization code
@@ -74,6 +97,8 @@ struct host1x_client {
7497 struct host1x_client * parent ;
7598 unsigned int usecount ;
7699 struct mutex lock ;
100+
101+ struct host1x_bo_cache cache ;
77102};
78103
79104/*
@@ -84,16 +109,26 @@ struct host1x_bo;
84109struct sg_table ;
85110
86111struct host1x_bo_mapping {
112+ struct kref ref ;
87113 struct dma_buf_attachment * attach ;
88114 enum dma_data_direction direction ;
115+ struct list_head list ;
89116 struct host1x_bo * bo ;
90117 struct sg_table * sgt ;
91118 unsigned int chunks ;
92119 struct device * dev ;
93120 dma_addr_t phys ;
94121 size_t size ;
122+
123+ struct host1x_bo_cache * cache ;
124+ struct list_head entry ;
95125};
96126
127+ static inline struct host1x_bo_mapping * to_host1x_bo_mapping (struct kref * ref )
128+ {
129+ return container_of (ref , struct host1x_bo_mapping , ref );
130+ }
131+
97132struct host1x_bo_ops {
98133 struct host1x_bo * (* get )(struct host1x_bo * bo );
99134 void (* put )(struct host1x_bo * bo );
@@ -106,11 +141,15 @@ struct host1x_bo_ops {
106141
107142struct host1x_bo {
108143 const struct host1x_bo_ops * ops ;
144+ struct list_head mappings ;
145+ spinlock_t lock ;
109146};
110147
111148static inline void host1x_bo_init (struct host1x_bo * bo ,
112149 const struct host1x_bo_ops * ops )
113150{
151+ INIT_LIST_HEAD (& bo -> mappings );
152+ spin_lock_init (& bo -> lock );
114153 bo -> ops = ops ;
115154}
116155
@@ -124,16 +163,10 @@ static inline void host1x_bo_put(struct host1x_bo *bo)
124163 bo -> ops -> put (bo );
125164}
126165
127- static inline struct host1x_bo_mapping * host1x_bo_pin (struct device * dev , struct host1x_bo * bo ,
128- enum dma_data_direction dir )
129- {
130- return bo -> ops -> pin (dev , bo , dir );
131- }
132-
133- static inline void host1x_bo_unpin (struct host1x_bo_mapping * map )
134- {
135- map -> bo -> ops -> unpin (map );
136- }
166+ struct host1x_bo_mapping * host1x_bo_pin (struct device * dev , struct host1x_bo * bo ,
167+ enum dma_data_direction dir ,
168+ struct host1x_bo_cache * cache );
169+ void host1x_bo_unpin (struct host1x_bo_mapping * map );
137170
138171static inline void * host1x_bo_mmap (struct host1x_bo * bo )
139172{
0 commit comments