include/linux/gfp.h

本文档详细介绍了Linux内核中用于内存分配的gfp_t标志,包括不同区域修饰符和行为修饰符的含义,如__GFP_DMA、__GFP_WAIT、__GFP_NOFAIL等,以及如何根据这些标志进行内存分配操作。
摘要由CSDN通过智能技术生成

#ifndef __LINUX_GFP_H
#define __LINUX_GFP_H

#include <linux/mmzone.h>
#include <linux/stddef.h>
#include <linux/linkage.h>
#include <linux/topology.h>
#include <linux/mmdebug.h>

struct vm_area_struct;

/* Plain integer GFP bitmasks. Do not use this directly. */
#define ___GFP_DMA  0x01u
#define ___GFP_HIGHMEM  0x02u
#define ___GFP_DMA32  0x04u
#define ___GFP_MOVABLE  0x08u
#define ___GFP_WAIT  0x10u
#define ___GFP_HIGH  0x20u
#define ___GFP_IO  0x40u
#define ___GFP_FS  0x80u
#define ___GFP_COLD  0x100u
#define ___GFP_NOWARN  0x200u
#define ___GFP_REPEAT  0x400u
#define ___GFP_NOFAIL  0x800u
#define ___GFP_NORETRY  0x1000u
#define ___GFP_MEMALLOC  0x2000u
#define ___GFP_COMP  0x4000u
#define ___GFP_ZERO  0x8000u
#define ___GFP_NOMEMALLOC 0x10000u
#define ___GFP_HARDWALL  0x20000u
#define ___GFP_THISNODE  0x40000u
#define ___GFP_RECLAIMABLE 0x80000u
#define ___GFP_KMEMCG  0x100000u
#define ___GFP_NOTRACK  0x200000u
#define ___GFP_NO_KSWAPD 0x400000u
#define ___GFP_OTHER_NODE 0x800000u
#define ___GFP_WRITE  0x1000000u
/* If the above are modified, __GFP_BITS_SHIFT may need updating */

/*
 * GFP bitmasks..
 *
 * Zone modifiers (see linux/mmzone.h - low three bits)
 *
 * Do not put any conditional on these. If necessary modify the definitions
 * without the underscores and use them consistently. The definitions here may
 * be used in bit comparisons.
 */
#define __GFP_DMA ((__force gfp_t)___GFP_DMA)
#define __GFP_HIGHMEM ((__force gfp_t)___GFP_HIGHMEM)
#define __GFP_DMA32 ((__force gfp_t)___GFP_DMA32)
#define __GFP_MOVABLE ((__force gfp_t)___GFP_MOVABLE)  /* Page is movable */
#define GFP_ZONEMASK (__GFP_DMA|__GFP_HIGHMEM|__GFP_DMA32|__GFP_MOVABLE)
/*
 * Action modifiers - doesn't change the zoning
 *
 * __GFP_REPEAT: Try hard to allocate the memory, but the allocation attempt
 * _might_ fail.  This depends upon the particular VM implementation.
 *
 * __GFP_NOFAIL: The VM implementation _must_ retry infinitely: the caller
 * cannot handle allocation failures.  This modifier is deprecated and no new
 * users should be added.
 *
 * __GFP_NORETRY: The VM implementation must not retry indefinitely.
 *
 * __GFP_MOVABLE: Flag that this page will be movable by the page migration
 * mechanism or reclaimed
 */
#define __GFP_WAIT ((__force gfp_t)___GFP_WAIT) /* Can wait and reschedule? */
#define __GFP_HIGH ((__force gfp_t)___GFP_HIGH) /* Should access emergency pools? */
#define __GFP_IO ((__force gfp_t)___GFP_IO) /* Can start physical IO? */
#define __GFP_FS ((__force gfp_t)___GFP_FS) /* Can call down to low-level FS? */
#define __GFP_COLD ((__force gfp_t)___GFP_COLD) /* Cache-cold page required */
#define __GFP_NOWARN ((__force gfp_t)___GFP_NOWARN) /* Suppress page allocation failure warning */
#define __GFP_REPEAT ((__force gfp_t)___GFP_REPEAT) /* See above */
#define __GFP_NOFAIL ((__force gfp_t)___GFP_NOFAIL) /* See above */
#define __GFP_NORETRY ((__force gfp_t)___GFP_NORETRY) /* See above */
#define __GFP_MEMALLOC ((__force gfp_t)___GFP_MEMALLOC)/* Allow access to emergency reserves */
#define __GFP_COMP ((__force gfp_t)___GFP_COMP) /* Add compound page metada

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include <linux/module.h> #include <linux/fs.h> #include <linux/gpio.h> // 各种gpio的数据结构及函数 #include <linux/cdev.h> #include <linux/init.h> //__init __exit 宏定义声明 #include <linux/device.h> //class devise声明 #include <linux/uaccess.h> //copy_from_user 的头文件 #include <linux/types.h> //设备号 dev_t 类型声明 #include <linux/ioctl.h> MODULE_LICENSE("Dual BSD/GPL"); #define IOCTL_GPIO_OFF 0 /*灭*/ #define IOCTL_GPIO_ON 1 /*亮*/ #define DEVICE_NAME "beepctrl_caiyuxin" static struct class *ioctrl_class; #define BEEP_MAJOR 0 /*预设的主设备号*/ static int BEEP_major = BEEP_MAJOR; /*BEEP设备结构体*/ struct BEEP_dev { struct cdev cdev; /*cdev结构体*/ }; struct BEEP_dev *BEEP_devp; /*设备结构体指针*/ // 定义三色BEEP的GPIO引脚 static const struct gpio beeps[] = { // { 2, GPIOF_OUT_INIT_HIGH, "BEEP_RED" }, // { 3, GPIOF_OUT_INIT_HIGH, "BEEP_GREEN" }, { 25, GPIOF_OUT_INIT_HIGH, "BEEP" }, }; int BEEP_open(struct inode *inode, struct file *filp)//打开设备节点 { // int i; // printk(KERN_INFO " beeps opened\n"); // for(i=0;i<3;i++) // { // gpio_set_value(beeps[i].gpio, 0); // } return 0; } static long int BEEP_ioctl(struct file *filp,unsigned int cmd, unsigned long arg) { //ioctl函数接口 if (arg > sizeof(beeps)/sizeof(unsigned long)) { return -EINVAL; } printk("arg,cmd: %ld %d\n", arg, cmd); switch(cmd) { case IOCTL_GPIO_OFF:// 设置指定引脚的输出电平为0,由电路图可知,输出0时为灭 gpio_set_value(beeps[arg].gpio, 0); break; case IOCTL_GPIO_ON: gpio_set_value(beeps[arg].gpio, 1); break; default: return -EINVAL; } return 0; } int BEEP_release(struct inode *inode, struct file *filp)//释放设备节点 { int i; printk(KERN_INFO "BEEPs driver successfully close\n"); for(i=0;i<3;i++) { gpio_set_value(beeps[i].gpio, 0); } return 0; } static const struct file_operations BEEP_fops = { .owner = THIS_MODULE, .open = BEEP_open, .release = BEEP_release, .unlocked_ioctl = BEEP_ioctl, /* 实现主要控制功能*/ }; /*初始化并注册cdev*/ static void BEEP_setup
06-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值