Linux对I/O端口资源的管理(1)

Linux对I/O端口资源的管理(1)》摘要: int get_resource_list(struct resource *root, char *buf, int size) { char *fmt; int retval; fmt = " %08lx-%08lx : %s "; if (root->end fmt = " %04lx-%04lx : %s "; read_lock(resource…

int get_resource_list(struct resource *root, char *buf, int size)

{

char *fmt;

int retval;

fmt = " %08lx-%08lx : %s

";

if (root->end < 0x10000)

fmt = " %04lx-%04lx : %s

";

read_lock(&resource_lock);

retval = do_resource_list(root->child, fmt, 8, buf, buf + size) - buf;

read_unlock(&resource_lock);

return retval;

}

可以看出,该函数主要通过调用内部静态函数do_resource_list()来实现其功能,其源代码如下:

/*

* This generates reports for /proc/ioports and /proc/iomem

*/

static char * do_resource_list(struct resource *entry, const char *fmt,

int offset, char *buf, char *end)

{

if (offset < 0)

offset = 0;

while (entry) {

const char *name = entry->name;

unsigned long from, to;

if ((int) (end-buf) < 80)

return buf;

from = entry->start;

to = entry->end;

if (!name)

name = "";

buf += sprintf(buf, fmt + offset, from, to, name);

if (entry->child)

buf = do_resource_list(entry->child, fmt, offset-2, buf, end);

entry = entry->sibling;

}

return buf;

}

函数do_resource_list()主要通过一个while{}循环以及递归嵌套调用来实现,较为简单,这里就不在详细解释了。

3.3 管理I/O Region资源

Linux将基于I/O映射方式的I/O端口和基于内存映射方式的I/O端口资源统称为“I/O区域”(I/O Region)。I/O Region仍然是一种I/O资源,因此它仍然可以用resource结构类型来描述。下面我们就来看看Linux是如何管理I/O Region的。

3.3.1 I/O Region的分配

在函数__request_resource()的基础上,Linux实现了用于分配I/O区域的函数__request_region(),如下:

你的位置:电脑故障网 >> 操作系统 >> Linux/Unix >> Linux对I/O端口资源的管理(1)