1 diff -uBr libwsbm-old/src/wsbm_manager.c libwsbm/src/wsbm_manager.c
2 --- libwsbm-old/src/wsbm_manager.c 2009-08-20 12:09:37.000000000 -0700
3 +++ libwsbm/src/wsbm_manager.c 2010-06-25 19:03:58.305282722 -0700
9 +wsbmBODataUB(struct _WsbmBufferObject *buf,
10 + unsigned size, const void *data,
11 + struct _WsbmBufferPool *newPool, uint32_t placement, const unsigned long *user_ptr)
13 + void *virtual = NULL;
16 + struct _WsbmBufStorage *storage;
18 + uint32_t placement_diff;
19 + struct _WsbmBufferPool *curPool;
20 + extern struct _WsbmBufStorage *
21 +ttm_pool_ub_create(struct _WsbmBufferPool *pool,
22 + unsigned long size, uint32_t placement, unsigned alignment, const unsigned long *user_ptr);
24 + if (buf->bufferType == WSBM_BUFFER_SIMPLE)
27 + storage = buf->storage;
29 + if (newPool == NULL)
30 + newPool = buf->pool;
32 + if (newPool == NULL)
35 + newBuffer = (!storage || storage->pool != newPool ||
36 + storage->pool->size(storage) < size ||
37 + storage->pool->size(storage) >
38 + size + WSBM_BODATA_SIZE_ACCEPT);
41 + placement = buf->placement;
44 + if (buf->bufferType == WSBM_BUFFER_REF)
47 + wsbmBufStorageUnref(&buf->storage);
50 + buf->pool = newPool;
51 + buf->placement = placement;
57 + //newPool->create(newPool, size, placement, buf->alignment);
58 + ttm_pool_ub_create(newPool, size, placement, buf->alignment, user_ptr);
59 + if (!buf->storage) {
64 + buf->placement = placement;
65 + buf->pool = newPool;
66 + } else if (wsbmAtomicRead(&storage->onList) ||
67 + 0 != storage->pool->syncforcpu(storage, WSBM_SYNCCPU_WRITE |
68 + WSBM_SYNCCPU_DONT_BLOCK)) {
70 + * Buffer is busy. need to create a new one.
73 + struct _WsbmBufStorage *tmp_storage;
75 + curPool = storage->pool;
78 + curPool->create(curPool, size, placement, buf->alignment);
81 + wsbmBufStorageUnref(&buf->storage);
82 + buf->storage = tmp_storage;
83 + buf->placement = placement;
85 + retval = curPool->syncforcpu(storage, WSBM_SYNCCPU_WRITE);
93 + placement_diff = placement ^ buf->placement;
96 + * We might need to change buffer placement.
99 + storage = buf->storage;
100 + curPool = storage->pool;
102 + if (placement_diff) {
103 + assert(curPool->setStatus != NULL);
104 + curPool->releasefromcpu(storage, WSBM_SYNCCPU_WRITE);
105 + retval = curPool->setStatus(storage,
106 + placement_diff & placement,
107 + placement_diff & ~placement);
111 + buf->placement = placement;
116 + retval = curPool->syncforcpu(buf->storage, WSBM_SYNCCPU_WRITE);
123 + storage = buf->storage;
124 + curPool = storage->pool;
127 + retval = curPool->map(storage, WSBM_ACCESS_WRITE, &virtual);
130 + memcpy(virtual, data, size);
131 + curPool->unmap(storage);
137 + curPool->releasefromcpu(storage, WSBM_SYNCCPU_WRITE);
141 static struct _WsbmBufStorage *
142 wsbmStorageClone(struct _WsbmBufferObject *buf)
144 diff -uBr libwsbm-old/src/wsbm_ttmpool.c libwsbm/src/wsbm_ttmpool.c
145 --- libwsbm-old/src/wsbm_ttmpool.c 2009-08-20 12:09:37.000000000 -0700
146 +++ libwsbm/src/wsbm_ttmpool.c 2010-06-25 19:03:58.304282858 -0700
148 pool->setStatus = &pool_setStatus;
153 +struct _WsbmBufStorage *
154 +ttm_pool_ub_create(struct _WsbmBufferPool *pool,
155 + unsigned long size, uint32_t placement, unsigned alignment, const unsigned long *user_ptr)
157 + struct _TTMBuffer *dBuf = (struct _TTMBuffer *)
158 + calloc(1, sizeof(*dBuf));
159 + struct _TTMPool *ttmPool = containerOf(pool, struct _TTMPool, pool);
161 + unsigned pageSize = ttmPool->pageSize;
162 + union ttm_pl_create_ub_arg arg;
167 + if ((alignment > pageSize) && (alignment % pageSize))
170 + ret = wsbmBufStorageInit(&dBuf->buf, pool);
174 + ret = WSBM_COND_INIT(&dBuf->event);
178 + arg.req.size = size;
179 + arg.req.placement = placement;
180 + arg.req.page_alignment = alignment / pageSize;
181 + arg.req.user_address = user_ptr;
183 + DRMRESTARTCOMMANDWRITEREAD(pool->fd, ttmPool->devOffset + TTM_PL_CREATE_UB,
189 + dBuf->requestedSize = size;
190 + dBuf->kBuf.gpuOffset = arg.rep.gpu_offset;
191 + dBuf->mapHandle = arg.rep.map_handle;
192 + dBuf->realSize = arg.rep.bo_size;
193 + dBuf->kBuf.placement = arg.rep.placement;
194 + dBuf->kBuf.handle = arg.rep.handle;
199 + WSBM_COND_FREE(&dBuf->event);
201 + wsbmBufStorageTakedown(&dBuf->buf);