summaryrefslogtreecommitdiff
path: root/pci-arbiter/pcifs.h
blob: 72cf2910e251a46c2f115c264cf9a05ab45cee73 (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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
   Copyright (C) 2017 Free Software Foundation, Inc.
   Written by Miles Bader <miles@gnu.org>

   This file is part of the GNU Hurd.

   The GNU Hurd is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2, or (at
   your option) any later version.

   The GNU Hurd is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with the GNU Hurd.  If not, see <http://www.gnu.org/licenses/>.
*/

/* PCI Filesystem header */

#ifndef PCIFS_H
#define PCIFS_H

#include <hurd/netfs.h>
#include <pthread.h>
#include <maptime.h>

#include <pciaccess.h>
// FIXME: Hardcoded PCI config size
#define PCI_CONFIG_SIZE 256

#include <netfs_impl.h>

/* Size of a directory entry name */
#ifndef NAME_SIZE
#define NAME_SIZE 16
#endif

/* Node cache defaults size */
#define NODE_CACHE_MAX 16

/*
 * Directory entry. Contains all per-node data our problem requires.
 *
 * All directory entries are created on startup and used to generate the
 * fs tree and create or retrieve libnetfs node objects.
 *
 * From libnetfs' point of view, these are the light nodes.
 */
struct pcifs_dirent
{
  /*
   * Complete bus identification, including domain, of the device.  On
   * platforms that do not support PCI domains (e.g., 32-bit x86 hardware),
   * the domain will always be zero.
   *
   * Negative value means no value.
   */
  int32_t domain;
  int16_t bus;
  int16_t dev;
  int8_t func;

  /*
   * Device's class, subclass, and programming interface packed into a
   * single 32-bit value.  The class is at bits [23:16], subclass is at
   * bits [15:8], and programming interface is at [7:0].
   *
   * Negative value means no value.
   */
  int32_t device_class;

  char name[NAME_SIZE];
  struct pcifs_dirent *parent;
  io_statbuf_t stat;

  /*
   * We only need two kind of nodes: files and directories.
   * When `dir' is null, this is a file; when not null, it's a directory.
   */
  struct pcifs_dir *dir;

  /* Active node on this entry */
  struct node *node;

  /*
   * Underlying virtual device if any.
   *
   * Only for entries having a full B/D/F address.
   */
  struct pci_device *device;
};

/*
 * A directory, it only contains a list of directory entries
 */
struct pcifs_dir
{
  /* Number of directory entries */
  uint16_t num_entries;

  /* Array of directory entries */
  struct pcifs_dirent **entries;
};

/*
 * Set of permissions.
 *
 * For each Class[,subclass] and/or Domain[,bus[,dev[,func]]], one UID and/or GID.
 */
struct pcifs_perm
{
  /*
   * D/b/d/f scope of permissions.
   *
   * Negative value means no value.
   */
  int32_t domain;
  int16_t bus;
  int16_t dev;
  int8_t func;

  /*
   * Class and subclass scope of permissions
   *
   * Negative value means no value.
   */
  int16_t d_class;
  int16_t d_subclass;

  /* User and group ids */
  int32_t uid;
  int32_t gid;
};

/* Various parameters that can be used to change the behavior of an ftpfs.  */
struct pcifs_params
{
  /* The size of the node cache.  */
  size_t node_cache_max;

  /* FS permissions.  */
  struct pcifs_perm *perms;
  size_t num_perms;
};

/* A particular filesystem.  */
struct pcifs
{
  /* Root of filesystem.  */
  struct node *root;

  /* FS configuration */
  struct pcifs_params params;

  /* A cache that holds a reference to recently used nodes.  */
  struct node *node_cache_mru, *node_cache_lru;
  size_t node_cache_len;	/* Number of entries in it.  */
  pthread_mutex_t node_cache_lock;

  /* Lock for pci_conf operations */
  pthread_mutex_t pci_conf_lock;

  struct pcifs_dirent *entries;
  size_t num_entries;
};

/* Main FS pointer */
extern struct pcifs *fs;

/* Global mapped time */
extern volatile struct mapped_time_value *pcifs_maptime;

/* Update entry and node times */
#define UPDATE_TIMES(e, what) (\
  {\
    fshelp_touch (&e->stat, what, pcifs_maptime);\
    if(e->node)\
      fshelp_touch (&e->node->nn_stat, what, pcifs_maptime);\
  }\
)

/* Update entry and node owner */
#define UPDATE_OWNER(e, uid) (\
  {\
    e->stat.st_uid = uid;\
    if(e->node)\
      e->node->nn_stat.st_uid = uid;\
  }\
)

/* Update entry and node group */
#define UPDATE_GROUP(e, gid) (\
  {\
    e->stat.st_gid = gid;\
    if(e->node)\
      e->node->nn_stat.st_gid = gid;\
  }\
)

/* FS manipulation functions */
error_t alloc_file_system (struct pcifs **fs);
error_t init_file_system (file_t underlying_node, struct pcifs *fs);
error_t create_fs_tree (struct pcifs *fs);
error_t fs_set_permissions (struct pcifs *fs);
error_t entry_check_perms (struct iouser *user, struct pcifs_dirent *e,
                          int flags);

#endif /* PCIFS_H */