1 /*
2 * Copyright (c) 2010, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * */
33 #ifndef _PROTO_H_INCLUDED
34 #define _PROTO_H_INCLUDED
36 struct _iofunc_attr;
37 #define RESMGR_HANDLE_T struct _iofunc_attr
38 struct tiler_ocb;
39 #define IOFUNC_OCB_T struct tiler_ocb
40 #define RESMGR_OCB_T struct tiler_ocb
41 #define THREAD_POOL_PARAM_T dispatch_context_t
43 #include <errno.h>
44 #include <stdio.h>
45 #include <stddef.h>
46 #include <stdlib.h>
47 #include <unistd.h>
48 #include <string.h>
49 #include <atomic.h>
50 #include <stdbool.h>
51 #include <devctl.h>
52 #include <fcntl.h>
53 #include <stdint.h>
54 #include <hw/inout.h>
55 #include <sys/iofunc.h>
56 #include <sys/dispatch.h>
57 #include <sys/procmgr.h>
58 #include <sys/mman.h>
59 #include <sys/neutrino.h>
60 #include <sys/siginfo.h>
62 #include "tiler/tiler_devctl.h"
63 #include "List.h"
65 void *
66 mmap64_peer(pid_t pid, void *addr, size_t len, int prot, int flags, int fd, off64_t off);
67 void *
68 mmap_peer(pid_t pid, void *addr, size_t len, int prot, int flags, int fd, off_t off);
69 int
70 munmap_peer(pid_t pid, void *addr, size_t len);
71 int
72 mem_offset64_peer(pid_t pid, const uintptr_t addr, size_t len,
73 off64_t *offset, size_t *contig_len);
75 typedef struct tiler_ocb {
76 iofunc_ocb_t hdr;
77 void *pi;
78 } tiler_ocb_t;
80 typedef struct tiler_dev {
81 iofunc_attr_t hdr;
82 dispatch_t *dpp;
83 dispatch_context_t *ctp;
84 int id;
85 iofunc_notify_t notify[3];
86 void *hdl;
87 //struct blocking_notifier_head notifier;
88 } tiler_dev_t;
90 s32 tiler_init(u32 size);
91 void tiler_exit(void);
92 int tiler_islowmem(void);
93 void tiler_purge(void);
94 tiler_ocb_t * ocb_calloc (resmgr_context_t * ctp, IOFUNC_ATTR_T * device);
95 void ocb_free (tiler_ocb_t * ocb);
97 /* Over-ride alloc/free implementation */
98 #define kmalloc(a,b) malloc(a)
99 #define kzalloc(a,b) calloc(1,a)
100 #define kfree(a) free(a)
102 /* Over-ride mutex implementation */
103 #define mutex_init(x) pthread_mutex_init(x, NULL)
104 #define mutex_lock pthread_mutex_lock
105 #define mutex_unlock pthread_mutex_unlock
106 #define mutex_destroy pthread_mutex_destroy
108 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
109 #define ALIGN(x, a) (((x) + ((typeof(x))(a) - 1)) & ~((typeof(x))(a) - 1))
110 #define PAGE_ALIGN(a) (((a)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1)))
112 /* Over-ride list implementation */
113 struct list_head {
114 struct list_head *prev;
115 struct list_head *next;
116 };
117 #define list_add_tail(x, head) List_enqueue((List_Handle)head, (List_Elem *)x)
118 #define list_add(x, head) List_enqueueHead((List_Handle)head, (List_Elem *)x)
119 #define list_for_each_safe(a,b,c) List_traverse_safe(a,b,c)
120 #define list_for_each_entry_safe(a,b,c,d) List_traverse_elem(a,b,c,d)
121 #define list_entry(x,y,z) List_elem(x,y,z)
122 #define list_del(x) List_remove(NULL,(List_Elem *)x)
123 #define list_is_singular(x) List_is_singular((List_Handle)x)
124 #define INIT_LIST_HEAD(x) List_elemClear((List_Elem *)x)
125 #define LIST_HEAD(x) struct list_head x = { &(x), &(x) }
126 #define list_empty(x) List_empty((List_Handle)x)
127 #define list_empty_careful(x) List_empty((List_Handle)x)
128 #define list_first_entry(ptr, type, member) List_elem((ptr)->next, type, member)
129 #define list_move(x,y) List_move((List_Handle)y,(List_Elem *)x)
131 /* Over-ride register read/write implementation */
132 #define __raw_readl(x) *((volatile u32 *) (x))
133 #define __raw_writel(x, y) *((volatile u32 *)(y))=x
135 /* Over-ride mem barrier implementation */
136 #define wmb __cpu_membarrier
138 #endif