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 
28 #include <l4/sys/compiler.h>
29 
58 {
63 
68 
72  L4_FPAGE_TYPE_MASK = ((1UL << L4_FPAGE_TYPE_BITS) - 1)
74  L4_FPAGE_SIZE_MASK = ((1UL << L4_FPAGE_SIZE_BITS) - 1)
76  L4_FPAGE_ADDR_MASK = ~0UL << L4_FPAGE_ADDR_SHIFT,
77 };
78 
83 typedef union {
86 } l4_fpage_t;
87 
91 enum
92 {
94 };
95 
100 typedef struct {
104 
105 
110 {
117 };
118 
137 {
211 };
212 
217 {
218  L4_FPAGE_SPECIAL = 0,
219  L4_FPAGE_MEMORY = 1,
220  L4_FPAGE_IO = 2,
221  L4_FPAGE_OBJ = 3,
222 };
223 
228 {
229  L4_FPAGE_CONTROL_OFFSET_SHIFT = 10,
230  L4_FPAGE_CONTROL_MASK = ~0UL << L4_FPAGE_CONTROL_OFFSET_SHIFT,
231 };
232 
243 {
246 
251 
258 };
259 
260 
265 {
268 
271 
274 
277 };
278 
279 
283 enum
284 {
287 
290 };
291 
292 
293 
305 L4_INLINE l4_fpage_t
306 l4_fpage(l4_addr_t address, unsigned int size, unsigned char rights) L4_NOTHROW;
307 
314 L4_INLINE l4_fpage_t
316 
323 L4_INLINE l4_fpage_t
325 
326 
337 L4_INLINE l4_fpage_t
338 l4_iofpage(unsigned long port, unsigned int size) L4_NOTHROW;
339 
340 
353 L4_INLINE l4_fpage_t
354 l4_obj_fpage(l4_cap_idx_t obj, unsigned int order, unsigned char rights) L4_NOTHROW;
355 
365 L4_INLINE int
367 
368 
402 L4_INLINE l4_umword_t
403 l4_map_control(l4_umword_t spot, unsigned char cache, unsigned grant) L4_NOTHROW;
404 
416 L4_INLINE l4_umword_t
417 l4_map_obj_control(l4_umword_t spot, unsigned grant) L4_NOTHROW;
418 
427 L4_INLINE unsigned
429 
438 L4_INLINE unsigned
440 
451 L4_INLINE unsigned
453 
464 L4_INLINE unsigned long
466 
480 L4_INLINE l4_addr_t
482 
496 L4_INLINE l4_cap_idx_t
498 
512 L4_INLINE unsigned long
514 
524 L4_INLINE l4_fpage_t
525 l4_fpage_set_rights(l4_fpage_t src, unsigned char new_rights) L4_NOTHROW;
526 
538 L4_INLINE int
539 l4_fpage_contains(l4_fpage_t fpage, l4_addr_t addr, unsigned size) L4_NOTHROW;
540 
557 L4_INLINE unsigned char
558 l4_fpage_max_order(unsigned char order, l4_addr_t addr,
559  l4_addr_t min_addr, l4_addr_t max_addr,
560  l4_addr_t hotspot L4_DEFAULT_PARAM(0));
561 
562 /*************************************************************************
563  * Implementations
564  *************************************************************************/
565 
566 L4_INLINE unsigned
568 {
569  return (f.raw & L4_FPAGE_RIGHTS_MASK) >> L4_FPAGE_RIGHTS_SHIFT;
570 }
571 
572 L4_INLINE unsigned
574 {
575  return (f.raw & L4_FPAGE_TYPE_MASK) >> L4_FPAGE_TYPE_SHIFT;
576 }
577 
578 L4_INLINE unsigned
580 {
581  return (f.raw & L4_FPAGE_SIZE_MASK) >> L4_FPAGE_SIZE_SHIFT;
582 }
583 
584 L4_INLINE unsigned long
586 {
587  return (f.raw & L4_FPAGE_ADDR_MASK) >> L4_FPAGE_ADDR_SHIFT;
588 }
589 
590 L4_INLINE unsigned long
592 {
593  return (f.raw & L4_FPAGE_ADDR_MASK) >> L4_FPAGE_ADDR_SHIFT;
594 }
595 
596 L4_INLINE l4_addr_t
598 {
599  return f.raw & L4_FPAGE_ADDR_MASK;
600 }
601 
602 L4_INLINE l4_cap_idx_t
604 {
605  return f.raw & L4_FPAGE_ADDR_MASK;
606 }
607 
609 L4_INLINE l4_fpage_t
610 __l4_fpage_generic(unsigned long address, unsigned int type,
611  unsigned int size, unsigned char rights) L4_NOTHROW;
612 
613 L4_INLINE l4_fpage_t
614 __l4_fpage_generic(unsigned long address, unsigned int type,
615  unsigned int size, unsigned char rights) L4_NOTHROW
616 {
617  l4_fpage_t t;
619  | ((type << L4_FPAGE_TYPE_SHIFT) & L4_FPAGE_TYPE_MASK)
620  | ((size << L4_FPAGE_SIZE_SHIFT) & L4_FPAGE_SIZE_MASK)
621  | ((address ) & L4_FPAGE_ADDR_MASK);
622  return t;
623 }
624 
625 L4_INLINE l4_fpage_t
626 l4_fpage_set_rights(l4_fpage_t src, unsigned char new_rights) L4_NOTHROW
627 {
628  l4_fpage_t f;
629  f.raw = ((L4_FPAGE_TYPE_MASK | L4_FPAGE_SIZE_MASK | L4_FPAGE_ADDR_MASK) & src.raw)
630  | ((new_rights << L4_FPAGE_RIGHTS_SHIFT) & L4_FPAGE_RIGHTS_MASK);
631  return f;
632 }
633 
634 L4_INLINE l4_fpage_t
635 l4_fpage(l4_addr_t address, unsigned int size, unsigned char rights) L4_NOTHROW
636 {
637  return __l4_fpage_generic(address, L4_FPAGE_MEMORY, size, rights);
638 }
639 
640 L4_INLINE l4_fpage_t
641 l4_iofpage(unsigned long port, unsigned int size) L4_NOTHROW
642 {
643  return __l4_fpage_generic(port << L4_FPAGE_ADDR_SHIFT, L4_FPAGE_IO, size, L4_FPAGE_RW);
644 }
645 
646 L4_INLINE l4_fpage_t
647 l4_obj_fpage(l4_cap_idx_t obj, unsigned int order, unsigned char rights) L4_NOTHROW
648 {
649  static_assert((unsigned long)L4_CAP_SHIFT >= L4_FPAGE_ADDR_SHIFT,
650  "Capability index does not fit into fpage.");
651  return __l4_fpage_generic(obj, L4_FPAGE_OBJ, order, rights);
652 }
653 
654 L4_INLINE l4_fpage_t
655 l4_fpage_all(void) L4_NOTHROW
656 {
657  return __l4_fpage_generic(0, 0, L4_WHOLE_ADDRESS_SPACE, 0);
658 }
659 
660 L4_INLINE l4_fpage_t
661 l4_fpage_invalid(void) L4_NOTHROW
662 {
663  return __l4_fpage_generic(0, 0, 0, 0);
664 }
665 
666 
667 L4_INLINE int
669 {
670  return l4_fpage_rights(fp) & L4_FPAGE_W;
671 }
672 
673 L4_INLINE l4_umword_t
674 l4_map_control(l4_umword_t snd_base, unsigned char cache, unsigned grant) L4_NOTHROW
675 {
676  return (snd_base & L4_FPAGE_CONTROL_MASK)
677  | ((l4_umword_t)cache << 4) | L4_ITEM_MAP | grant;
678 }
679 
680 L4_INLINE l4_umword_t
681 l4_map_obj_control(l4_umword_t snd_base, unsigned grant) L4_NOTHROW
682 {
683  return l4_map_control(snd_base, 0, grant);
684 }
685 
686 L4_INLINE int
687 l4_fpage_contains(l4_fpage_t fpage, l4_addr_t addr, unsigned log2size) L4_NOTHROW
688 {
689  l4_addr_t fa = l4_fpage_memaddr(fpage);
690  return (fa <= addr)
691  && (fa + (1UL << l4_fpage_size(fpage)) >= addr + (1UL << log2size));
692 }
693 
694 L4_INLINE unsigned char
695 l4_fpage_max_order(unsigned char order, l4_addr_t addr,
696  l4_addr_t min_addr, l4_addr_t max_addr,
697  l4_addr_t hotspot)
698 {
699  while (order < 30 /* limit to 1GB flexpages */)
700  {
701  l4_addr_t mask;
702  l4_addr_t base = l4_trunc_size(addr, order + 1);
703  if (base < min_addr)
704  return order;
705 
706  if (base + (1UL << (order + 1)) - 1 > max_addr - 1)
707  return order;
708 
709  mask = ~(~0UL << (order + 1));
710  if (hotspot == ~0UL || ((addr ^ hotspot) & mask))
711  break;
712 
713  ++order;
714  }
715 
716  return order;
717 }
Identify a message item as map item.
Definition: consts.h:189
Object-type specific right.
Definition: __l4_fpage.h:248
Whole address space size.
Definition: __l4_fpage.h:93
l4_fpage_t l4_iofpage(unsigned long port, unsigned int size) L4_NOTHROW
Create an IO-port flex page.
Definition: __l4_fpage.h:641
Read and interface specific &#39;W&#39; right for capability flex-pages.
Definition: __l4_fpage.h:178
Interface specific &#39;S&#39; right for capability flex-pages.
Definition: __l4_fpage.h:155
Object-type specific right.
Definition: __l4_fpage.h:249
l4_umword_t fpage
Raw value.
Definition: __l4_fpage.h:84
l4_fpage_consts
L4 flexpage structure.
Definition: __l4_fpage.h:57
Interface specific &#39;W&#39; right for capability flex-pages.
Definition: __l4_fpage.h:145
Read-write-execute flex page.
Definition: __l4_fpage.h:116
unsigned long l4_fpage_page(l4_fpage_t f) L4_NOTHROW
Return the page part from a flex page.
Definition: __l4_fpage.h:585
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:591
Read and interface specific &#39;S&#39; right for capability flex-pages.
Definition: __l4_fpage.h:185
Mapping is reference-counted (default).
Definition: __l4_fpage.h:244
L4_obj_fpage_ctl
Flex-page map control for capabilities (snd_base)
Definition: __l4_fpage.h:242
Send-flex-page types.
Definition: __l4_fpage.h:100
Flexpage type size (memory, IO port, obj...)
Definition: __l4_fpage.h:65
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:257
Object-type specific right.
Definition: __l4_fpage.h:247
l4_fpage_t fpage
Source flex-page descriptor.
Definition: __l4_fpage.h:102
Cacheability option to enable caches for the mapping.
Definition: __l4_fpage.h:270
L4_cap_fpage_rights
Cap-flex-page rights.
Definition: __l4_fpage.h:136
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:687
Delete right for capability flex-pages.
Definition: __l4_fpage.h:171
Don&#39;t increase the reference counter.
Definition: __l4_fpage.h:245
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 compiler related defines.
l4_fpage_t l4_fpage_invalid(void) L4_NOTHROW
Get an invalid flex page.
Definition: __l4_fpage.h:661
Read right for capability flex-pages.
Definition: __l4_fpage.h:162
Read, &#39;S&#39;, and delete right for capability flex-pages.
Definition: __l4_fpage.h:210
unsigned l4_fpage_rights(l4_fpage_t f) L4_NOTHROW
Return rights from a flex page.
Definition: __l4_fpage.h:567
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:635
Read-execute flex page.
Definition: __l4_fpage.h:115
Flexpage type shift (memory, IO port, obj...)
Definition: __l4_fpage.h:60
Whole I/O address space size.
Definition: __l4_fpage.h:286
Page address shift.
Definition: __l4_fpage.h:62
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:573
Read-write flex page.
Definition: __l4_fpage.h:114
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:695
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:603
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
L4_fpage_rights
Flex-page rights.
Definition: __l4_fpage.h:109
L4_fpage_type
Flex-page type.
Definition: __l4_fpage.h:216
Enable the cacheability option in a send flex page.
Definition: __l4_fpage.h:267
Cacheability option to disable caching for the mapping.
Definition: __l4_fpage.h:276
l4_umword_t raw
Raw value.
Definition: __l4_fpage.h:85
Flexpage size size (log2-based)
Definition: __l4_fpage.h:66
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:597
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:681
Read-only flex page.
Definition: __l4_fpage.h:113
All Object-type specific right bits.
Definition: __l4_fpage.h:250
Mask to get the flexpage rights.
Definition: __l4_fpage.h:70
Maximum I/O port address.
Definition: __l4_fpage.h:289
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:674
l4_fpage_cacheability_opt_t
Flex-page cacheability option.
Definition: __l4_fpage.h:264
L4 flexpage type.
Definition: __l4_fpage.h:83
L4_fpage_control
Flex-page map control flags.
Definition: __l4_fpage.h:227
Read, write, and delete right for capability flex-pages.
Definition: __l4_fpage.h:204
unsigned l4_fpage_size(l4_fpage_t f) L4_NOTHROW
Return size from a flex page.
Definition: __l4_fpage.h:579
int l4_is_fpage_writable(l4_fpage_t fp) L4_NOTHROW
Test if the flex page is writable.
Definition: __l4_fpage.h:668
Access permissions shift.
Definition: __l4_fpage.h:59
l4_umword_t snd_base
Offset in receive window (send base)
Definition: __l4_fpage.h:101
Access permissions size.
Definition: __l4_fpage.h:64
Read, interface specific &#39;W&#39;, and &#39;S&#39; rights for capability flex-pages.
Definition: __l4_fpage.h:192
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:626
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:655
Full rights for capability flex-pages.
Definition: __l4_fpage.h:198
Executable flex page.
Definition: __l4_fpage.h:111
Read right for capability flex-pages.
Definition: __l4_fpage.h:161
Writable flex page.
Definition: __l4_fpage.h:112
Flexpage size shift (log2-based)
Definition: __l4_fpage.h:61
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:647
Cacheability option to enable buffered writes for the mapping.
Definition: __l4_fpage.h:273
Page address size.
Definition: __l4_fpage.h:67
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:186
#define L4_MWORD_BITS
Size of machine words in bits.
Definition: l4int.h:33