source: mainline/generic/include/mm/frame.h@ e07fe0c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e07fe0c was b87f418, checked in by Jakub Jermar <jakub@…>, 20 years ago

Send in some improvements.

  • Property mode set to 100644
File size: 4.4 KB
RevLine 
[f761f1eb]1/*
2 * Copyright (C) 2005 Jakub Jermar
[30187eb]3 * Copyright (C) 2005 Sergey Bondari
[f761f1eb]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef __FRAME_H__
31#define __FRAME_H__
32
33#include <arch/types.h>
[2b50d7c]34#include <typedefs.h>
[7b43e11]35#include <list.h>
36#include <synch/spinlock.h>
[6e8b3c8]37#include <mm/buddy.h>
[f761f1eb]38
[d43d2f7]39#define ONE_FRAME 0
40
[f761f1eb]41#define FRAME_KA 1 /* skip frames conflicting with user address space */
42#define FRAME_PANIC 2 /* panic on failure */
43
[30187eb]44#define FRAME2ADDR(zone, frame) ((zone)->base + ((frame) - (zone)->frames) * FRAME_SIZE)
45#define ADDR2FRAME(zone, addr) (&((zone)->frames[((addr) - (zone)->base) / FRAME_SIZE]))
[61e6c39]46#define FRAME_INDEX(zone, frame) ((index_t)((frame) - (zone)->frames))
[328f2934]47#define FRAME_INDEX_VALID(zone, index) (((index) >= 0) && ((index) < ((zone)->free_count + (zone)->busy_count)))
[b87f418]48#define IS_BUDDY_ORDER_OK(index, order) ((~(((__native) -1) << (order)) & (index)) == 0)
49#define IS_BUDDY_LEFT_BLOCK(zone, frame) (((FRAME_INDEX((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
50#define IS_BUDDY_RIGHT_BLOCK(zone, frame) (((FRAME_INDEX((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
[30187eb]51
[328f2934]52#define ZONE_BLACKLIST_SIZE 3
[6e8b3c8]53
[e456008]54struct zone {
55 link_t link; /**< link to previous and next zone */
[7b43e11]56
[e158717]57 spinlock_t lock; /**< this lock protects everything below */
58 __address base; /**< physical address of the first frame in the frames array */
59 frame_t *frames; /**< array of frame_t structures in this zone */
[eef75f6]60 count_t free_count; /**< number of free frame_t structures */
61 count_t busy_count; /**< number of busy frame_t structures */
[6e8b3c8]62
[30187eb]63 buddy_system_t * buddy_system; /**< buddy system for the zone */
[7b43e11]64 int flags;
65};
66
67struct frame {
[4457455]68 count_t refcount; /**< tracking of shared frames */
[30187eb]69 __u8 buddy_order; /**< buddy system block order */
[4457455]70 link_t buddy_link; /**< link to the next free block inside one order */
[adecf496]71};
[7b43e11]72
[328f2934]73struct region {
74 __address base;
75 size_t size;
76};
77
78extern region_t zone_blacklist[];
79extern count_t zone_blacklist_count;
80extern void frame_region_not_free(__address base, size_t size);
81extern void zone_create_in_region(__address base, size_t size);
82
[e456008]83extern spinlock_t zone_head_lock; /**< this lock protects zone_head list */
84extern link_t zone_head; /**< list of all zones in the system */
[7b43e11]85
[84dd253]86extern void zone_init(void);
87extern zone_t *zone_create(__address start, size_t size, int flags);
88extern void zone_attach(zone_t *zone);
[f761f1eb]89
90extern void frame_init(void);
[84dd253]91extern void frame_initialize(frame_t *frame, zone_t *zone);
[328f2934]92__address frame_alloc(int flags, __u8 order);
[f761f1eb]93extern void frame_free(__address addr);
[30187eb]94zone_t * get_zone_by_frame(frame_t * frame);
[f761f1eb]95
[6e8b3c8]96/*
97 * Buddy system operations
98 */
[594a468]99link_t * zone_buddy_find_buddy(buddy_system_t *b, link_t * buddy);
100link_t * zone_buddy_bisect(buddy_system_t *b, link_t * block);
101link_t * zone_buddy_coalesce(buddy_system_t *b, link_t * buddy_l, link_t * buddy_r);
102void zone_buddy_set_order(buddy_system_t *b, link_t * block, __u8 order);
103__u8 zone_buddy_get_order(buddy_system_t *b, link_t * block);
[328f2934]104void zone_buddy_mark_busy(buddy_system_t *b, link_t * block);
[6e8b3c8]105
[e456008]106/*
107 * TODO: Implement the following functions.
108 */
109extern frame_t *frame_reference(frame_t *frame);
110extern void frame_release(frame_t *frame);
111
[f761f1eb]112#endif
Note: See TracBrowser for help on using the repository browser.