merge with master
[platform/upstream/libwsbm.git] / packaging / libwsbm.patch
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
4 @@ -610,6 +610,139 @@
5      return retval;
6  }
7  
8 +int
9 +wsbmBODataUB(struct _WsbmBufferObject *buf,
10 +          unsigned size, const void *data,
11 +          struct _WsbmBufferPool *newPool, uint32_t placement, const unsigned long *user_ptr)
12 +{
13 +    void *virtual = NULL;
14 +    int newBuffer;
15 +    int retval = 0;
16 +    struct _WsbmBufStorage *storage;
17 +    int synced = 0;
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);
23 +
24 +    if (buf->bufferType == WSBM_BUFFER_SIMPLE)
25 +       return -EINVAL;
26 +
27 +    storage = buf->storage;
28 +
29 +    if (newPool == NULL)
30 +       newPool = buf->pool;
31 +
32 +    if (newPool == NULL)
33 +       return -EINVAL;
34 +
35 +    newBuffer = (!storage || storage->pool != newPool ||
36 +                storage->pool->size(storage) < size ||
37 +                storage->pool->size(storage) >
38 +                size + WSBM_BODATA_SIZE_ACCEPT);
39 +
40 +    if (!placement)
41 +       placement = buf->placement;
42 +
43 +    if (newBuffer) {
44 +       if (buf->bufferType == WSBM_BUFFER_REF)
45 +           return -EINVAL;
46 +
47 +       wsbmBufStorageUnref(&buf->storage);
48 +
49 +       if (size == 0) {
50 +           buf->pool = newPool;
51 +           buf->placement = placement;
52 +           retval = 0;
53 +           goto out;
54 +       }
55 +
56 +       buf->storage =
57 +           //newPool->create(newPool, size, placement, buf->alignment);
58 +        ttm_pool_ub_create(newPool, size, placement, buf->alignment, user_ptr);
59 +       if (!buf->storage) {
60 +           retval = -ENOMEM;
61 +           goto out;
62 +       }
63 +
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)) {
69 +       /*
70 +        * Buffer is busy. need to create a new one.
71 +        */
72 +
73 +       struct _WsbmBufStorage *tmp_storage;
74 +
75 +       curPool = storage->pool;
76 +
77 +       tmp_storage =
78 +           curPool->create(curPool, size, placement, buf->alignment);
79 +
80 +       if (tmp_storage) {
81 +           wsbmBufStorageUnref(&buf->storage);
82 +           buf->storage = tmp_storage;
83 +           buf->placement = placement;
84 +       } else {
85 +           retval = curPool->syncforcpu(storage, WSBM_SYNCCPU_WRITE);
86 +           if (retval)
87 +               goto out;
88 +           synced = 1;
89 +       }
90 +    } else
91 +       synced = 1;
92 +
93 +    placement_diff = placement ^ buf->placement;
94 +
95 +    /*
96 +     * We might need to change buffer placement.
97 +     */
98 +
99 +    storage = buf->storage;
100 +    curPool = storage->pool;
101 +
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);
108 +       if (retval)
109 +           goto out;
110 +
111 +       buf->placement = placement;
112 +
113 +    }
114 +
115 +    if (!synced) {
116 +       retval = curPool->syncforcpu(buf->storage, WSBM_SYNCCPU_WRITE);
117 +
118 +       if (retval)
119 +           goto out;
120 +       synced = 1;
121 +    }
122 +
123 +    storage = buf->storage;
124 +    curPool = storage->pool;
125 +
126 +    if (data) {
127 +       retval = curPool->map(storage, WSBM_ACCESS_WRITE, &virtual);
128 +       if (retval)
129 +           goto out;
130 +       memcpy(virtual, data, size);
131 +       curPool->unmap(storage);
132 +    }
133 +
134 +  out:
135 +
136 +    if (synced)
137 +       curPool->releasefromcpu(storage, WSBM_SYNCCPU_WRITE);
138 +
139 +    return retval;
140 +}
141  static struct _WsbmBufStorage *
142  wsbmStorageClone(struct _WsbmBufferObject *buf)
143  {
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
147 @@ -507,3 +507,60 @@
148      pool->setStatus = &pool_setStatus;
149      return pool;
150  }
151 +
152 +
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)
156 +{
157 +    struct _TTMBuffer *dBuf = (struct _TTMBuffer *)
158 +       calloc(1, sizeof(*dBuf));
159 +    struct _TTMPool *ttmPool = containerOf(pool, struct _TTMPool, pool);
160 +    int ret;
161 +    unsigned pageSize = ttmPool->pageSize;
162 +    union ttm_pl_create_ub_arg arg;
163 +
164 +    if (!dBuf)
165 +       return NULL;
166 +
167 +    if ((alignment > pageSize) && (alignment % pageSize))
168 +       goto out_err0;
169 +
170 +    ret = wsbmBufStorageInit(&dBuf->buf, pool);
171 +    if (ret)
172 +       goto out_err0;
173 +
174 +    ret = WSBM_COND_INIT(&dBuf->event);
175 +    if (ret)
176 +       goto out_err1;
177 +
178 +    arg.req.size = size;
179 +    arg.req.placement = placement;
180 +    arg.req.page_alignment = alignment / pageSize;
181 +    arg.req.user_address = user_ptr;
182 +
183 +    DRMRESTARTCOMMANDWRITEREAD(pool->fd, ttmPool->devOffset + TTM_PL_CREATE_UB,
184 +                              arg, ret);
185 +
186 +    if (ret)
187 +       goto out_err2;
188 +
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;
195 +
196 +    return &dBuf->buf;
197 +
198 +  out_err2:
199 +    WSBM_COND_FREE(&dBuf->event);
200 +  out_err1:
201 +    wsbmBufStorageTakedown(&dBuf->buf);
202 +  out_err0:
203 +    free(dBuf);
204 +    return NULL;
205 +}
206 +
207 +