summaryrefslogtreecommitdiff
path: root/rnn/dedma.h
blob: b2eaa8477b02103d4d9d627853c55d0dd735f57d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * Copyright (C) 2010 Francisco Jerez.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef __DEDMA_H__
#define __DEDMA_H__

#define _GNU_SOURCE
#include <errno.h>
#include <assert.h>
#include <stdlib.h>
#include <libgen.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>

#include "rnn.h"
#include "rnndec.h"

#define MAX_DELTA 16384 /* size of the reordering window */
#define MAX_OUT_OF_BAND 8 /* maximum consecutive out of band data entries */
#define MAX_CACHE 4096 /* dump cache size */
#define MAX_OBJECTS 256 /* object cache size */
#define MAX_SUBCHAN 8

struct ent {
	uint32_t addr;
	uint32_t val;
	bool out_of_band;
};

struct obj {
	uint32_t handle;
	uint32_t class;
	char *name;
	struct rnndeccontext *ctx;
};

struct filter {
	int map;
	uint32_t addr0, addr1; /* address range we care about */
};

struct cache {
	int i0, i1; /* cached index range */
	int k; /* offset the cache starts in */
	struct ent ent[MAX_CACHE];
};

struct dma {
	int incr;
	int subchan;
	int addr;
	int size;
	int skip;
	int nops;
};

struct state {
	struct {
		bool (*parse)(struct state *);
		void (*flush)(struct state *, struct ent *);
		int (*print)(const char *, ...);
	} op;

	FILE *f;
	uint32_t chipset;
	uint32_t pci_id;

	struct rnndb *db;
	struct rnndomain *dom;
	const struct envy_colors *colors;

	struct filter filter;
	struct cache cache;

	struct {
		char *buf;
		size_t n;
		uint32_t addr;
	} parse;

	struct obj objects[MAX_OBJECTS];
	struct obj *subchan[MAX_SUBCHAN];
	struct dma dma;
};

/* dedma.c */
void
add_object(struct state *s, uint32_t handle, uint32_t class);

struct obj *
get_object(struct state *s, uint32_t handle);

int
dedma(struct state *s, FILE *f, bool dry_run);

/* dedma_cache.c */
struct ent *
get_ent(struct state *s, int i);

void
rotate_ent(struct state *s, int i, int j);

void
add_ent(struct state *s, struct ent *e);

void
drop_ent(struct state *s, int i);

void
flush_cache(struct state *s);

/* dedma_back.c */
void
parse_renouveau_chipset(struct state *s, char *path);

void
parse_renouveau_objects(struct state *s, char *path);

void
parse_renouveau_startup(struct state *s, char *path);

bool
parse_renouveau(struct state *s);

bool
parse_valgrind(struct state *s);

#endif