L4Re - L4 Runtime Environment
__l4_fpage.h
1 
6 /*
7  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
8  * Alexander Warg <warg@os.inf.tu-dresden.de>,
9  * Björn Döbel <doebel@os.inf.tu-dresden.de>,
10  * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
11  * economic rights: Technische Universität Dresden (Germany)
12  *
13  * This file is part of TUD:OS and distributed under the terms of the
14  * GNU General Public License 2.
15  * Please see the COPYING-GPL-2 file for details.
16  *
17  * As a special exception, you may use this file as part of a free software
18  * library without restriction. Specifically, if other files instantiate
19  * templates or use macros or inline functions from this file, or you compile
20  * this file and link it with other files to produce an executable, this
21  * file does not by itself cause the resulting executable to be covered by
22  * the GNU General Public License. This exception does not however
23  * invalidate any other reasons why the executable file might be covered by
24  * the GNU General Public License.
25  */
26 #pragma once
27 
56 {
61 
66 
70  L4_FPAGE_TYPE_MASK = ((1UL << L4_FPAGE_TYPE_BITS) - 1)
72  L4_FPAGE_SIZE_MASK = ((1UL << L4_FPAGE_SIZE_BITS) - 1)
74  L4_FPAGE_ADDR_MASK = ~0UL << L4_FPAGE_ADDR_SHIFT,
75 };
76 
81 typedef union {
84 } l4_fpage_t;
85 
89 enum
90 {
92 };
93 
98 typedef struct {
102 
103 
108 {
115 };
116 
135 {
209 };
210 
215 {
216  L4_FPAGE_SPECIAL = 0,
217  L4_FPAGE_MEMORY = 1,
218  L4_FPAGE_IO = 2,
219  L4_FPAGE_OBJ = 3,
220 };
221 
226 {
227  L4_FPAGE_CONTROL_OFFSET_SHIFT = 10,
228  L4_FPAGE_CONTROL_MASK = ~0UL << L4_FPAGE_CONTROL_OFFSET_SHIFT,
229 };
230 
241 {
244 
249 
256 };
257 
258 
263 {
266 
269 
272 
275 };
276 
277 
281 enum
282 {
285 
288 };
289 
290 
291 
303 L4_INLINE l4_fpage_t
304 l4_fpage(l4_addr_t address, unsigned int size, unsigned char rights) L4_NOTHROW;
305 
312 L4_INLINE l4_fpage_t
314 
321 L4_INLINE l4_fpage_t
323 
324 
335 L4_INLINE l4_fpage_t
336 l4_iofpage(unsigned long port, unsigned int size) L4_NOTHROW;
337 
338 
351 L4_INLINE l4_fpage_t
352 l4_obj_fpage(l4_cap_idx_t obj, unsigned int order, unsigned char rights) L4_NOTHROW;
353 
363 L4_INLINE int
365 
366 
400 L4_INLINE l4_umword_t
401 l4_map_control(l4_umword_t spot, unsigned char cache, unsigned grant) L4_NOTHROW;
402 
414 L4_INLINE l4_umword_t
415 l4_map_obj_control(l4_umword_t spot, unsigned grant) L4_NOTHROW;
416 
425 L4_INLINE unsigned
427 
436 L4_INLINE unsigned
438 
449 L4_INLINE unsigned
451 
462 L4_INLINE unsigned long
464 
478 L4_INLINE l4_addr_t
480 
494 L4_INLINE l4_cap_idx_t
496 
510 L4_INLINE unsigned long
512 
522 L4_INLINE l4_fpage_t
523 l4_fpage_set_rights(l4_fpage_t src, unsigned char new_rights) L4_NOTHROW;
524 
536 L4_INLINE int
537 l4_fpage_contains(l4_fpage_t fpage, l4_addr_t addr, unsigned size) L4_NOTHROW;
538 
555 L4_INLINE unsigned char
556 l4_fpage_max_order(unsigned char order, l4_addr_t addr,
557  l4_addr_t min_addr, l4_addr_t max_addr,
558  l4_addr_t hotspot L4_DEFAULT_PARAM(0));
559 
560 /*************************************************************************
561  * Implementations
562  *************************************************************************/
563 
564 L4_INLINE unsigned
566 {
567  return (f.raw & L4_FPAGE_RIGHTS_MASK) >> L4_FPAGE_RIGHTS_SHIFT;
568 }
569 
570 L4_INLINE unsigned
572 {
573  return (f.raw & L4_FPAGE_TYPE_MASK) >> L4_FPAGE_TYPE_SHIFT;
574 }
575 
576 L4_INLINE unsigned
578 {
579  return (f.raw & L4_FPAGE_SIZE_MASK) >> L4_FPAGE_SIZE_SHIFT;
580 }
581 
582 L4_INLINE unsigned long
584 {
585  return (f.raw & L4_FPAGE_ADDR_MASK) >> L4_FPAGE_ADDR_SHIFT;
586 }
587 
588 L4_INLINE unsigned long
590 {
591  return (f.raw & L4_FPAGE_ADDR_MASK) >> L4_FPAGE_ADDR_SHIFT;
592 }
593 
594 L4_INLINE l4_addr_t
596 {
597  return f.raw & L4_FPAGE_ADDR_MASK;
598 }
599 
600 L4_INLINE l4_cap_idx_t
602 {
603  return f.raw & L4_FPAGE_ADDR_MASK;
604 }
605 
607 L4_INLINE l4_fpage_t
608 __l4_fpage_generic(unsigned long address, unsigned int type,
609  unsigned int size, unsigned char rights) L4_NOTHROW;
610 
611 L4_INLINE l4_fpage_t
612 __l4_fpage_generic(unsigned long address, unsigned int type,
613  unsigned int size, unsigned char rights) L4_NOTHROW
614 {
615  l4_fpage_t t;
617  | ((type << L4_FPAGE_TYPE_SHIFT) & L4_FPAGE_TYPE_MASK)
618  | ((size << L4_FPAGE_SIZE_SHIFT) & L4_FPAGE_SIZE_MASK)
619  | ((address ) & L4_FPAGE_ADDR_MASK);
620  return t;
621 }
622 
623 L4_INLINE l4_fpage_t
624 l4_fpage_set_rights(l4_fpage_t src, unsigned char new_rights) L4_NOTHROW
625 {
626  l4_fpage_t f;
627  f.raw = ((L4_FPAGE_TYPE_MASK | L4_FPAGE_SIZE_MASK | L4_FPAGE_ADDR_MASK) & src.raw)
628  | ((new_rights << L4_FPAGE_RIGHTS_SHIFT) & L4_FPAGE_RIGHTS_MASK);
629  return f;
630 }
631 
632 L4_INLINE l4_fpage_t
633 l4_fpage(l4_addr_t address, unsigned int size, unsigned char rights) L4_NOTHROW
634 {
635  return __l4_fpage_generic(address, L4_FPAGE_MEMORY, size, rights);
636 }
637 
638 L4_INLINE l4_fpage_t
639 l4_iofpage(unsigned long port, unsigned int size) L4_NOTHROW
640 {
641  return __l4_fpage_generic(port << L4_FPAGE_ADDR_SHIFT, L4_FPAGE_IO, size, L4_FPAGE_RW);
642 }
643 
644 L4_INLINE l4_fpage_t
645 l4_obj_fpage(l4_cap_idx_t obj, unsigned int order, unsigned char rights) L4_NOTHROW
646 {
647  static_assert((unsigned long)L4_CAP_SHIFT >= L4_FPAGE_ADDR_SHIFT,
648  "Capability index does not fit into fpage.");
649  return __l4_fpage_generic(obj, L4_FPAGE_OBJ, order, rights);
650 }
651 
652 L4_INLINE l4_fpage_t
653 l4_fpage_all(void) L4_NOTHROW
654 {
655  return __l4_fpage_generic(0, 0, L4_WHOLE_ADDRESS_SPACE, 0);
656 }
657 
658 L4_INLINE l4_fpage_t
659 l4_fpage_invalid(void) L4_NOTHROW
660 {
661  return __l4_fpage_generic(0, 0, 0, 0);
662 }
663 
664 
665 L4_INLINE int
667 {
668  return l4_fpage_rights(fp) & L4_FPAGE_W;
669 }
670 
671 L4_INLINE l4_umword_t
672 l4_map_control(l4_umword_t snd_base, unsigned char cache, unsigned grant) L4_NOTHROW
673 {
674  return (snd_base & L4_FPAGE_CONTROL_MASK)
675  | ((l4_umword_t)cache << 4) | L4_ITEM_MAP | grant;
676 }
677 
678 L4_INLINE l4_umword_t
679 l4_map_obj_control(l4_umword_t snd_base, unsigned grant) L4_NOTHROW
680 {
681  return l4_map_control(snd_base, 0, grant);
682 }
683 
684 L4_INLINE int
685 l4_fpage_contains(l4_fpage_t fpage, l4_addr_t addr, unsigned log2size) L4_NOTHROW
686 {
687  l4_addr_t fa = l4_fpage_memaddr(fpage);
688  return (fa <= addr)
689  && (fa + (1UL << l4_fpage_size(fpage)) >= addr + (1UL << log2size));
690 }
691 
692 L4_INLINE unsigned char
693 l4_fpage_max_order(unsigned char order, l4_addr_t addr,
694  l4_addr_t min_addr, l4_addr_t max_addr,
695  l4_addr_t hotspot)
696 {
697  while (order < 30 /* limit to 1GB flexpages */)
698  {
699  l4_addr_t mask;
700  l4_addr_t base = l4_trunc_size(addr, order + 1);
701  if (base < min_addr)
702  return order;
703 
704  if (base + (1UL << (order + 1)) - 1 > max_addr - 1)
705  return order;
706 
707  mask = ~(~0UL << (order + 1));
708  if (hotspot == ~0UL || ((addr ^ hotspot) & mask))
709  break;
710 
711  ++order;
712  }
713 
714  return order;
715 }
Identify a message item as map item.
Definition: consts.h:189
Object-type specific right.
Definition: __l4_fpage.h:246
l4_fpage_t l4_iofpage(unsigned long port, unsigned int size) L4_NOTHROW
Create an IO-port flex page.
Definition: __l4_fpage.h:639
Read and interface specific &#39;W&#39; right for capability flex-pages.
Definition: __l4_fpage.h:176
Interface specific &#39;S&#39; right for capability flex-pages.
Definition: __l4_fpage.h:153
Object-type specific right.
Definition: __l4_fpage.h:247
l4_umword_t fpage
Raw value.
Definition: __l4_fpage.h:82
l4_fpage_consts
L4 flexpage structure.
Definition: __l4_fpage.h:55
Interface specific &#39;W&#39; right for capability flex-pages.
Definition: __l4_fpage.h:143
Read-write-execute flex page.
Definition: __l4_fpage.h:114
unsigned long l4_fpage_page(l4_fpage_t f) L4_NOTHROW
Return the page part from a flex page.
Definition: __l4_fpage.h:583
unsigned long l4_fpage_ioport(l4_fpage_t f) L4_NOTHROW
Return the IO port number from the IO flex page.
Definition: __l4_fpage.h:589
Read and interface specific &#39;S&#39; right for capability flex-pages.
Definition: __l4_fpage.h:183
Mapping is reference-counted (default).
Definition: __l4_fpage.h:242
L4_obj_fpage_ctl
Flex-page map control for capabilities (snd_base)
Definition: __l4_fpage.h:240
Send-flex-page types.
Definition: __l4_fpage.h:98
Flexpage type size (memory, IO port, obj...)
Definition: __l4_fpage.h:63
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
The receiver may invoke IPC-gate-specific functions on the capability, e.g.
Definition: __l4_fpage.h:255
Object-type specific right.
Definition: __l4_fpage.h:245
l4_fpage_t fpage
Source flex-page descriptor.
Definition: __l4_fpage.h:100
Cacheability option to enable caches for the mapping.
Definition: __l4_fpage.h:268
L4_cap_fpage_rights
Cap-flex-page rights.
Definition: __l4_fpage.h:134
int l4_fpage_contains(l4_fpage_t fpage, l4_addr_t addr, unsigned size) L4_NOTHROW
Test whether a given range is completely within an fpage.
Definition: __l4_fpage.h:685
Delete right for capability flex-pages.
Definition: __l4_fpage.h:169
Don&#39;t increase the reference counter.
Definition: __l4_fpage.h:243
l4_addr_t l4_trunc_size(l4_addr_t address, unsigned char bits) L4_NOTHROW
Round an address down to the next lower flex page with size bits.
Definition: consts.h:375
l4_fpage_t l4_fpage_invalid(void) L4_NOTHROW
Get an invalid flex page.
Definition: __l4_fpage.h:659
Read right for capability flex-pages.
Definition: __l4_fpage.h:160
Whole I/O address space size.
Definition: __l4_fpage.h:284
Read, &#39;S&#39;, and delete right for capability flex-pages.
Definition: __l4_fpage.h:208
unsigned l4_fpage_rights(l4_fpage_t f) L4_NOTHROW
Return rights from a flex page.
Definition: __l4_fpage.h:565
Whole address space size.
Definition: __l4_fpage.h:91
Maximum I/O port address.
Definition: __l4_fpage.h:287
l4_fpage_t l4_fpage(l4_addr_t address, unsigned int size, unsigned char rights) L4_NOTHROW
Create a memory flex page.
Definition: __l4_fpage.h:633
Read-execute flex page.
Definition: __l4_fpage.h:113
Flexpage type shift (memory, IO port, obj...)
Definition: __l4_fpage.h:58
Page address shift.
Definition: __l4_fpage.h:60
Capability index shift.
Definition: consts.h:131
unsigned l4_fpage_type(l4_fpage_t f) L4_NOTHROW
Return type from a flex page.
Definition: __l4_fpage.h:571
Read-write flex page.
Definition: __l4_fpage.h:112
unsigned char l4_fpage_max_order(unsigned char order, l4_addr_t addr, l4_addr_t min_addr, l4_addr_t max_addr, l4_addr_t hotspot=0)
Determine maximum flex page size of a region.
Definition: __l4_fpage.h:693
l4_cap_idx_t l4_fpage_obj(l4_fpage_t f) L4_NOTHROW
Return the capability index from the object flex page.
Definition: __l4_fpage.h:601
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
L4_fpage_rights
Flex-page rights.
Definition: __l4_fpage.h:107
L4_fpage_type
Flex-page type.
Definition: __l4_fpage.h:214
Enable the cacheability option in a send flex page.
Definition: __l4_fpage.h:265
Cacheability option to disable caching for the mapping.
Definition: __l4_fpage.h:274
l4_umword_t raw
Raw value.
Definition: __l4_fpage.h:83
Flexpage size size (log2-based)
Definition: __l4_fpage.h:64
l4_addr_t l4_fpage_memaddr(l4_fpage_t f) L4_NOTHROW
Return the memory address from the memory flex page.
Definition: __l4_fpage.h:595
l4_umword_t l4_map_obj_control(l4_umword_t spot, unsigned grant) L4_NOTHROW
Create the first word for a map item for the object space.
Definition: __l4_fpage.h:679
Read-only flex page.
Definition: __l4_fpage.h:111
All Object-type specific right bits.
Definition: __l4_fpage.h:248
Mask to get the flexpage rights.
Definition: __l4_fpage.h:68
l4_umword_t l4_map_control(l4_umword_t spot, unsigned char cache, unsigned grant) L4_NOTHROW
Create the first word for a map item for the memory space.
Definition: __l4_fpage.h:672
l4_fpage_cacheability_opt_t
Flex-page cacheability option.
Definition: __l4_fpage.h:262
L4 flexpage type.
Definition: __l4_fpage.h:81
L4_fpage_control
Flex-page map control flags.
Definition: __l4_fpage.h:225
Read, write, and delete right for capability flex-pages.
Definition: __l4_fpage.h:202
unsigned l4_fpage_size(l4_fpage_t f) L4_NOTHROW
Return size from a flex page.
Definition: __l4_fpage.h:577
int l4_is_fpage_writable(l4_fpage_t fp) L4_NOTHROW
Test if the flex page is writable.
Definition: __l4_fpage.h:666
Access permissions shift.
Definition: __l4_fpage.h:57
l4_umword_t snd_base
Offset in receive window (send base)
Definition: __l4_fpage.h:99
Access permissions size.
Definition: __l4_fpage.h:62
Read, interface specific &#39;W&#39;, and &#39;S&#39; rights for capability flex-pages.
Definition: __l4_fpage.h:190
l4_fpage_t l4_fpage_set_rights(l4_fpage_t src, unsigned char new_rights) L4_NOTHROW
Set new right in a flex page.
Definition: __l4_fpage.h:624
unsigned long l4_addr_t
Address type.
Definition: l4int.h:45
l4_fpage_t l4_fpage_all(void) L4_NOTHROW
Get a flex page, describing all address spaces at once.
Definition: __l4_fpage.h:653
Full rights for capability flex-pages.
Definition: __l4_fpage.h:196
Executable flex page.
Definition: __l4_fpage.h:109
Read right for capability flex-pages.
Definition: __l4_fpage.h:159
Writable flex page.
Definition: __l4_fpage.h:110
Flexpage size shift (log2-based)
Definition: __l4_fpage.h:59
l4_fpage_t l4_obj_fpage(l4_cap_idx_t obj, unsigned int order, unsigned char rights) L4_NOTHROW
Create a kernel-object flex page.
Definition: __l4_fpage.h:645
Cacheability option to enable buffered writes for the mapping.
Definition: __l4_fpage.h:271
Page address size.
Definition: __l4_fpage.h:65
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:185
#define L4_MWORD_BITS
Size of machine words in bits.
Definition: l4int.h:33