Merge tag 'tags/sound-sdw-kconfig-fixes' into for-linus
[linux-2.6-microblaze.git] / include / drm / ttm / ttm_bo_api.h
1 /**************************************************************************
2  *
3  * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24  * USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 /*
28  * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
29  */
30
31 #ifndef _TTM_BO_API_H_
32 #define _TTM_BO_API_H_
33
34 #include <drm/drm_gem.h>
35 #include <drm/drm_hashtab.h>
36 #include <drm/drm_vma_manager.h>
37 #include <linux/kref.h>
38 #include <linux/list.h>
39 #include <linux/wait.h>
40 #include <linux/mutex.h>
41 #include <linux/mm.h>
42 #include <linux/bitmap.h>
43 #include <linux/dma-resv.h>
44
45 #include "ttm_resource.h"
46
47 struct ttm_bo_global;
48
49 struct ttm_bo_device;
50
51 struct dma_buf_map;
52
53 struct drm_mm_node;
54
55 struct ttm_placement;
56
57 struct ttm_place;
58
59 struct ttm_lru_bulk_move;
60
61 /**
62  * enum ttm_bo_type
63  *
64  * @ttm_bo_type_device: These are 'normal' buffers that can
65  * be mmapped by user space. Each of these bos occupy a slot in the
66  * device address space, that can be used for normal vm operations.
67  *
68  * @ttm_bo_type_kernel: These buffers are like ttm_bo_type_device buffers,
69  * but they cannot be accessed from user-space. For kernel-only use.
70  *
71  * @ttm_bo_type_sg: Buffer made from dmabuf sg table shared with another
72  * driver.
73  */
74
75 enum ttm_bo_type {
76         ttm_bo_type_device,
77         ttm_bo_type_kernel,
78         ttm_bo_type_sg
79 };
80
81 struct ttm_tt;
82
83 /**
84  * struct ttm_buffer_object
85  *
86  * @base: drm_gem_object superclass data.
87  * @bdev: Pointer to the buffer object device structure.
88  * @type: The bo type.
89  * @destroy: Destruction function. If NULL, kfree is used.
90  * @num_pages: Actual number of pages.
91  * @acc_size: Accounted size for this object.
92  * @kref: Reference count of this buffer object. When this refcount reaches
93  * zero, the object is destroyed or put on the delayed delete list.
94  * @mem: structure describing current placement.
95  * @ttm: TTM structure holding system pages.
96  * @evicted: Whether the object was evicted without user-space knowing.
97  * @deleted: True if the object is only a zombie and already deleted.
98  * @lru: List head for the lru list.
99  * @ddestroy: List head for the delayed destroy list.
100  * @swap: List head for swap LRU list.
101  * @moving: Fence set when BO is moving
102  * @offset: The current GPU offset, which can have different meanings
103  * depending on the memory type. For SYSTEM type memory, it should be 0.
104  * @cur_placement: Hint of current placement.
105  *
106  * Base class for TTM buffer object, that deals with data placement and CPU
107  * mappings. GPU mappings are really up to the driver, but for simpler GPUs
108  * the driver can usually use the placement offset @offset directly as the
109  * GPU virtual address. For drivers implementing multiple
110  * GPU memory manager contexts, the driver should manage the address space
111  * in these contexts separately and use these objects to get the correct
112  * placement and caching for these GPU maps. This makes it possible to use
113  * these objects for even quite elaborate memory management schemes.
114  * The destroy member, the API visibility of this object makes it possible
115  * to derive driver specific types.
116  */
117
118 struct ttm_buffer_object {
119         struct drm_gem_object base;
120
121         /**
122          * Members constant at init.
123          */
124
125         struct ttm_bo_device *bdev;
126         enum ttm_bo_type type;
127         void (*destroy) (struct ttm_buffer_object *);
128         size_t acc_size;
129
130         /**
131         * Members not needing protection.
132         */
133         struct kref kref;
134
135         /**
136          * Members protected by the bo::resv::reserved lock.
137          */
138
139         struct ttm_resource mem;
140         struct ttm_tt *ttm;
141         bool deleted;
142
143         /**
144          * Members protected by the bdev::lru_lock.
145          */
146
147         struct list_head lru;
148         struct list_head ddestroy;
149         struct list_head swap;
150
151         /**
152          * Members protected by a bo reservation.
153          */
154
155         struct dma_fence *moving;
156         unsigned priority;
157         unsigned pin_count;
158
159         /**
160          * Special members that are protected by the reserve lock
161          * and the bo::lock when written to. Can be read with
162          * either of these locks held.
163          */
164
165         struct sg_table *sg;
166 };
167
168 /**
169  * struct ttm_bo_kmap_obj
170  *
171  * @virtual: The current kernel virtual address.
172  * @page: The page when kmap'ing a single page.
173  * @bo_kmap_type: Type of bo_kmap.
174  *
175  * Object describing a kernel mapping. Since a TTM bo may be located
176  * in various memory types with various caching policies, the
177  * mapping can either be an ioremap, a vmap, a kmap or part of a
178  * premapped region.
179  */
180
181 #define TTM_BO_MAP_IOMEM_MASK 0x80
182 struct ttm_bo_kmap_obj {
183         void *virtual;
184         struct page *page;
185         enum {
186                 ttm_bo_map_iomap        = 1 | TTM_BO_MAP_IOMEM_MASK,
187                 ttm_bo_map_vmap         = 2,
188                 ttm_bo_map_kmap         = 3,
189                 ttm_bo_map_premapped    = 4 | TTM_BO_MAP_IOMEM_MASK,
190         } bo_kmap_type;
191         struct ttm_buffer_object *bo;
192 };
193
194 /**
195  * struct ttm_operation_ctx
196  *
197  * @interruptible: Sleep interruptible if sleeping.
198  * @no_wait_gpu: Return immediately if the GPU is busy.
199  * @gfp_retry_mayfail: Set the __GFP_RETRY_MAYFAIL when allocation pages.
200  * @allow_res_evict: Allow eviction of reserved BOs. Can be used when multiple
201  * BOs share the same reservation object.
202  * @force_alloc: Don't check the memory account during suspend or CPU page
203  * faults. Should only be used by TTM internally.
204  * @resv: Reservation object to allow reserved evictions with.
205  *
206  * Context for TTM operations like changing buffer placement or general memory
207  * allocation.
208  */
209 struct ttm_operation_ctx {
210         bool interruptible;
211         bool no_wait_gpu;
212         bool gfp_retry_mayfail;
213         bool allow_res_evict;
214         bool force_alloc;
215         struct dma_resv *resv;
216         uint64_t bytes_moved;
217 };
218
219 /**
220  * ttm_bo_get - reference a struct ttm_buffer_object
221  *
222  * @bo: The buffer object.
223  */
224 static inline void ttm_bo_get(struct ttm_buffer_object *bo)
225 {
226         kref_get(&bo->kref);
227 }
228
229 /**
230  * ttm_bo_get_unless_zero - reference a struct ttm_buffer_object unless
231  * its refcount has already reached zero.
232  * @bo: The buffer object.
233  *
234  * Used to reference a TTM buffer object in lookups where the object is removed
235  * from the lookup structure during the destructor and for RCU lookups.
236  *
237  * Returns: @bo if the referencing was successful, NULL otherwise.
238  */
239 static inline __must_check struct ttm_buffer_object *
240 ttm_bo_get_unless_zero(struct ttm_buffer_object *bo)
241 {
242         if (!kref_get_unless_zero(&bo->kref))
243                 return NULL;
244         return bo;
245 }
246
247 /**
248  * ttm_bo_wait - wait for buffer idle.
249  *
250  * @bo:  The buffer object.
251  * @interruptible:  Use interruptible wait.
252  * @no_wait:  Return immediately if buffer is busy.
253  *
254  * This function must be called with the bo::mutex held, and makes
255  * sure any previous rendering to the buffer is completed.
256  * Note: It might be necessary to block validations before the
257  * wait by reserving the buffer.
258  * Returns -EBUSY if no_wait is true and the buffer is busy.
259  * Returns -ERESTARTSYS if interrupted by a signal.
260  */
261 int ttm_bo_wait(struct ttm_buffer_object *bo, bool interruptible, bool no_wait);
262
263 static inline int ttm_bo_wait_ctx(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx)
264 {
265         return ttm_bo_wait(bo, ctx->interruptible, ctx->no_wait_gpu);
266 }
267
268 /**
269  * ttm_bo_mem_compat - Check if proposed placement is compatible with a bo
270  *
271  * @placement:  Return immediately if buffer is busy.
272  * @mem:  The struct ttm_resource indicating the region where the bo resides
273  * @new_flags: Describes compatible placement found
274  *
275  * Returns true if the placement is compatible
276  */
277 bool ttm_bo_mem_compat(struct ttm_placement *placement, struct ttm_resource *mem,
278                        uint32_t *new_flags);
279
280 /**
281  * ttm_bo_validate
282  *
283  * @bo: The buffer object.
284  * @placement: Proposed placement for the buffer object.
285  * @ctx: validation parameters.
286  *
287  * Changes placement and caching policy of the buffer object
288  * according proposed placement.
289  * Returns
290  * -EINVAL on invalid proposed placement.
291  * -ENOMEM on out-of-memory condition.
292  * -EBUSY if no_wait is true and buffer busy.
293  * -ERESTARTSYS if interrupted by a signal.
294  */
295 int ttm_bo_validate(struct ttm_buffer_object *bo,
296                     struct ttm_placement *placement,
297                     struct ttm_operation_ctx *ctx);
298
299 /**
300  * ttm_bo_put
301  *
302  * @bo: The buffer object.
303  *
304  * Unreference a buffer object.
305  */
306 void ttm_bo_put(struct ttm_buffer_object *bo);
307
308 /**
309  * ttm_bo_move_to_lru_tail
310  *
311  * @bo: The buffer object.
312  * @mem: Resource object.
313  * @bulk: optional bulk move structure to remember BO positions
314  *
315  * Move this BO to the tail of all lru lists used to lookup and reserve an
316  * object. This function must be called with struct ttm_bo_global::lru_lock
317  * held, and is used to make a BO less likely to be considered for eviction.
318  */
319 void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo,
320                              struct ttm_resource *mem,
321                              struct ttm_lru_bulk_move *bulk);
322
323 /**
324  * ttm_bo_bulk_move_lru_tail
325  *
326  * @bulk: bulk move structure
327  *
328  * Bulk move BOs to the LRU tail, only valid to use when driver makes sure that
329  * BO order never changes. Should be called with ttm_bo_global::lru_lock held.
330  */
331 void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk);
332
333 /**
334  * ttm_bo_lock_delayed_workqueue
335  *
336  * Prevent the delayed workqueue from running.
337  * Returns
338  * True if the workqueue was queued at the time
339  */
340 int ttm_bo_lock_delayed_workqueue(struct ttm_bo_device *bdev);
341
342 /**
343  * ttm_bo_unlock_delayed_workqueue
344  *
345  * Allows the delayed workqueue to run.
346  */
347 void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev, int resched);
348
349 /**
350  * ttm_bo_eviction_valuable
351  *
352  * @bo: The buffer object to evict
353  * @place: the placement we need to make room for
354  *
355  * Check if it is valuable to evict the BO to make room for the given placement.
356  */
357 bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
358                               const struct ttm_place *place);
359
360 size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev,
361                            unsigned long bo_size,
362                            unsigned struct_size);
363
364 /**
365  * ttm_bo_init_reserved
366  *
367  * @bdev: Pointer to a ttm_bo_device struct.
368  * @bo: Pointer to a ttm_buffer_object to be initialized.
369  * @size: Requested size of buffer object.
370  * @type: Requested type of buffer object.
371  * @flags: Initial placement flags.
372  * @page_alignment: Data alignment in pages.
373  * @ctx: TTM operation context for memory allocation.
374  * @acc_size: Accounted size for this object.
375  * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
376  * @destroy: Destroy function. Use NULL for kfree().
377  *
378  * This function initializes a pre-allocated struct ttm_buffer_object.
379  * As this object may be part of a larger structure, this function,
380  * together with the @destroy function,
381  * enables driver-specific objects derived from a ttm_buffer_object.
382  *
383  * On successful return, the caller owns an object kref to @bo. The kref and
384  * list_kref are usually set to 1, but note that in some situations, other
385  * tasks may already be holding references to @bo as well.
386  * Furthermore, if resv == NULL, the buffer's reservation lock will be held,
387  * and it is the caller's responsibility to call ttm_bo_unreserve.
388  *
389  * If a failure occurs, the function will call the @destroy function, or
390  * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is
391  * illegal and will likely cause memory corruption.
392  *
393  * Returns
394  * -ENOMEM: Out of memory.
395  * -EINVAL: Invalid placement flags.
396  * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
397  */
398
399 int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
400                          struct ttm_buffer_object *bo,
401                          size_t size, enum ttm_bo_type type,
402                          struct ttm_placement *placement,
403                          uint32_t page_alignment,
404                          struct ttm_operation_ctx *ctx,
405                          size_t acc_size, struct sg_table *sg,
406                          struct dma_resv *resv,
407                          void (*destroy) (struct ttm_buffer_object *));
408
409 /**
410  * ttm_bo_init
411  *
412  * @bdev: Pointer to a ttm_bo_device struct.
413  * @bo: Pointer to a ttm_buffer_object to be initialized.
414  * @size: Requested size of buffer object.
415  * @type: Requested type of buffer object.
416  * @flags: Initial placement flags.
417  * @page_alignment: Data alignment in pages.
418  * @interruptible: If needing to sleep to wait for GPU resources,
419  * sleep interruptible.
420  * pinned in physical memory. If this behaviour is not desired, this member
421  * holds a pointer to a persistent shmem object. Typically, this would
422  * point to the shmem object backing a GEM object if TTM is used to back a
423  * GEM user interface.
424  * @acc_size: Accounted size for this object.
425  * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
426  * @destroy: Destroy function. Use NULL for kfree().
427  *
428  * This function initializes a pre-allocated struct ttm_buffer_object.
429  * As this object may be part of a larger structure, this function,
430  * together with the @destroy function,
431  * enables driver-specific objects derived from a ttm_buffer_object.
432  *
433  * On successful return, the caller owns an object kref to @bo. The kref and
434  * list_kref are usually set to 1, but note that in some situations, other
435  * tasks may already be holding references to @bo as well.
436  *
437  * If a failure occurs, the function will call the @destroy function, or
438  * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is
439  * illegal and will likely cause memory corruption.
440  *
441  * Returns
442  * -ENOMEM: Out of memory.
443  * -EINVAL: Invalid placement flags.
444  * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
445  */
446 int ttm_bo_init(struct ttm_bo_device *bdev, struct ttm_buffer_object *bo,
447                 size_t size, enum ttm_bo_type type,
448                 struct ttm_placement *placement,
449                 uint32_t page_alignment, bool interrubtible, size_t acc_size,
450                 struct sg_table *sg, struct dma_resv *resv,
451                 void (*destroy) (struct ttm_buffer_object *));
452
453 /**
454  * ttm_kmap_obj_virtual
455  *
456  * @map: A struct ttm_bo_kmap_obj returned from ttm_bo_kmap.
457  * @is_iomem: Pointer to an integer that on return indicates 1 if the
458  * virtual map is io memory, 0 if normal memory.
459  *
460  * Returns the virtual address of a buffer object area mapped by ttm_bo_kmap.
461  * If *is_iomem is 1 on return, the virtual address points to an io memory area,
462  * that should strictly be accessed by the iowriteXX() and similar functions.
463  */
464 static inline void *ttm_kmap_obj_virtual(struct ttm_bo_kmap_obj *map,
465                                          bool *is_iomem)
466 {
467         *is_iomem = !!(map->bo_kmap_type & TTM_BO_MAP_IOMEM_MASK);
468         return map->virtual;
469 }
470
471 /**
472  * ttm_bo_kmap
473  *
474  * @bo: The buffer object.
475  * @start_page: The first page to map.
476  * @num_pages: Number of pages to map.
477  * @map: pointer to a struct ttm_bo_kmap_obj representing the map.
478  *
479  * Sets up a kernel virtual mapping, using ioremap, vmap or kmap to the
480  * data in the buffer object. The ttm_kmap_obj_virtual function can then be
481  * used to obtain a virtual address to the data.
482  *
483  * Returns
484  * -ENOMEM: Out of memory.
485  * -EINVAL: Invalid range.
486  */
487 int ttm_bo_kmap(struct ttm_buffer_object *bo, unsigned long start_page,
488                 unsigned long num_pages, struct ttm_bo_kmap_obj *map);
489
490 /**
491  * ttm_bo_kunmap
492  *
493  * @map: Object describing the map to unmap.
494  *
495  * Unmaps a kernel map set up by ttm_bo_kmap.
496  */
497 void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map);
498
499 /**
500  * ttm_bo_vmap
501  *
502  * @bo: The buffer object.
503  * @map: pointer to a struct dma_buf_map representing the map.
504  *
505  * Sets up a kernel virtual mapping, using ioremap or vmap to the
506  * data in the buffer object. The parameter @map returns the virtual
507  * address as struct dma_buf_map. Unmap the buffer with ttm_bo_vunmap().
508  *
509  * Returns
510  * -ENOMEM: Out of memory.
511  * -EINVAL: Invalid range.
512  */
513 int ttm_bo_vmap(struct ttm_buffer_object *bo, struct dma_buf_map *map);
514
515 /**
516  * ttm_bo_vunmap
517  *
518  * @bo: The buffer object.
519  * @map: Object describing the map to unmap.
520  *
521  * Unmaps a kernel map set up by ttm_bo_vmap().
522  */
523 void ttm_bo_vunmap(struct ttm_buffer_object *bo, struct dma_buf_map *map);
524
525 /**
526  * ttm_bo_mmap_obj - mmap memory backed by a ttm buffer object.
527  *
528  * @vma:       vma as input from the fbdev mmap method.
529  * @bo:        The bo backing the address space.
530  *
531  * Maps a buffer object.
532  */
533 int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo);
534
535 /**
536  * ttm_bo_mmap - mmap out of the ttm device address space.
537  *
538  * @filp:      filp as input from the mmap method.
539  * @vma:       vma as input from the mmap method.
540  * @bdev:      Pointer to the ttm_bo_device with the address space manager.
541  *
542  * This function is intended to be called by the device mmap method.
543  * if the device address space is to be backed by the bo manager.
544  */
545 int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma,
546                 struct ttm_bo_device *bdev);
547
548 /**
549  * ttm_bo_io
550  *
551  * @bdev:      Pointer to the struct ttm_bo_device.
552  * @filp:      Pointer to the struct file attempting to read / write.
553  * @wbuf:      User-space pointer to address of buffer to write. NULL on read.
554  * @rbuf:      User-space pointer to address of buffer to read into.
555  * Null on write.
556  * @count:     Number of bytes to read / write.
557  * @f_pos:     Pointer to current file position.
558  * @write:     1 for read, 0 for write.
559  *
560  * This function implements read / write into ttm buffer objects, and is
561  * intended to
562  * be called from the fops::read and fops::write method.
563  * Returns:
564  * See man (2) write, man(2) read. In particular,
565  * the function may return -ERESTARTSYS if
566  * interrupted by a signal.
567  */
568 ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
569                   const char __user *wbuf, char __user *rbuf,
570                   size_t count, loff_t *f_pos, bool write);
571
572 int ttm_bo_swapout(struct ttm_operation_ctx *ctx);
573
574 /**
575  * ttm_bo_uses_embedded_gem_object - check if the given bo uses the
576  * embedded drm_gem_object.
577  *
578  * Most ttm drivers are using gem too, so the embedded
579  * ttm_buffer_object.base will be initialized by the driver (before
580  * calling ttm_bo_init).  It is also possible to use ttm without gem
581  * though (vmwgfx does that).
582  *
583  * This helper will figure whenever a given ttm bo is a gem object too
584  * or not.
585  *
586  * @bo: The bo to check.
587  */
588 static inline bool ttm_bo_uses_embedded_gem_object(struct ttm_buffer_object *bo)
589 {
590         return bo->base.dev != NULL;
591 }
592
593 /**
594  * ttm_bo_pin - Pin the buffer object.
595  * @bo: The buffer object to pin
596  *
597  * Make sure the buffer is not evicted any more during memory pressure.
598  */
599 static inline void ttm_bo_pin(struct ttm_buffer_object *bo)
600 {
601         dma_resv_assert_held(bo->base.resv);
602         WARN_ON_ONCE(!kref_read(&bo->kref));
603         ++bo->pin_count;
604 }
605
606 /**
607  * ttm_bo_unpin - Unpin the buffer object.
608  * @bo: The buffer object to unpin
609  *
610  * Allows the buffer object to be evicted again during memory pressure.
611  */
612 static inline void ttm_bo_unpin(struct ttm_buffer_object *bo)
613 {
614         dma_resv_assert_held(bo->base.resv);
615         WARN_ON_ONCE(!bo->pin_count);
616         WARN_ON_ONCE(!kref_read(&bo->kref));
617         --bo->pin_count;
618 }
619
620 int ttm_mem_evict_first(struct ttm_bo_device *bdev,
621                         struct ttm_resource_manager *man,
622                         const struct ttm_place *place,
623                         struct ttm_operation_ctx *ctx,
624                         struct ww_acquire_ctx *ticket);
625
626 /* Default number of pre-faulted pages in the TTM fault handler */
627 #define TTM_BO_VM_NUM_PREFAULT 16
628
629 vm_fault_t ttm_bo_vm_reserve(struct ttm_buffer_object *bo,
630                              struct vm_fault *vmf);
631
632 vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,
633                                     pgprot_t prot,
634                                     pgoff_t num_prefault,
635                                     pgoff_t fault_page_size);
636
637 vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf);
638
639 void ttm_bo_vm_open(struct vm_area_struct *vma);
640
641 void ttm_bo_vm_close(struct vm_area_struct *vma);
642
643 int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr,
644                      void *buf, int len, int write);
645
646 #endif