相关的操作 任何设备驱动程序都可以使用下列三个函数来进 行资源的请求和释放 >request resource,allocate resource,release resource 00190: 米米 00191: request resource request and reserve an I/O or memory resource 00192: 米 @root:root resource descriptor 00193: @new:resource descriptor desired by caller 00194: 米 00195: Returns o for success,negative error code on error. 00196: 00197: int request resource(struct resource *root,struct resource *new) 00198: 00199: struct resource *conflict; 00200: 00201: write_lock(&resource_lock); 00202: conflict =_request_resource(root,new); 00203: write_unlock(&resource_lock); 00204: return conflict ?EBUSY 0; 00205: 验室 ∠UZOIIII4 LIlIuX Uo AllalysI I∠IIUo EMBEDDED SYSTEM LABORATORY SUZHOU INSTITUTE FON ADVANCED STUDY OF USTC
2023/7/14 Linux OS Analysis 12/105 相关的操作 ❖任何设备驱动程序都可以使用下列三个函数来进 行资源的请求和释放 ➢request_resource、allocate_resource、release_resource
00142:/Return the conflict entry if you can't request it 00143:static struct resource *requestresource(struct resource *root,struct resource *new) 00144:{ 00145: resource size t start new->start; 00146: resource size t end new->end; 00147: struct resource *tmp,**p; 00148: 00149: if (end start) 00150: return root; 00151: if (start root->start) 00152: return root; 00153: if (end root->end) 00154: return root; 00155: p=&root->child; 00156: for (;;) 00157: tmp *p; 00158: if (tmp tmp->start end){ 00159: new->sibling tmp; 00160: *p new; 00161: new->parent root; 00162: return NULL; 00163: 00164: p =&tmp->sibling; 00165: if (tmp->end start) 00166: continue; 00167: return tmp; 00168: } 00169 :}end request resource EMBEDDED SYSTEM LABORATORY SUZHOU INSTITUTE FON ADVANCED STUDY OF USTC
2023/7/14 Linux OS Analysis 13/105
00335: /米米 00336: allocate_resource-allocate empty slot in the resource tree given range alignment 00337:* @root:root resource descriptor 00338:@new:resource descriptor desired by caller 00339:@size:requested resource region size 00340:@min:minimum size to allocate 00341:@max:maximum size to allocate 00342: @align:alignment requested,in bytes 00343:@alignf:alignment function,optional,called if not NULL 00344: 米 @alignf_data:arbitrary data to pass to the @alignf function 00345: 米 00346: int allocate resource(struct resource *root,struct resource *new, 00347: resource size t size,resource_size_t min, 00348: resource_size_t max,resource_size_t align, 00349: void (*alignf)(void *struct resource 00350: resource size t,resource size t), 00351: void*alignfdata) 00352: 00353: int err; 00354: 00355: write_lock(&resource_lock); 00356: err find_resource(root,new,size,min,max,align,alignf,alignf_data); 00357: if (err >=0&&request_resource(root,new)) 00358: err =-EBUSY; 00359: write_unlock(&resource_lock); 00360: return err; 00361: 20Z311114 Linux OS Analysis 14/105 EMBEDDED SYSTEM LABORATORY SUZHOU INSTITUTE FON ADVANCED STUDY OF USTC
2023/7/14 Linux OS Analysis 14/105
00290: 米 00291: Find empty slot in the resource tree given range and alignment. 00292: */ 00293: static int find resource(struct resource *root,struct resource *new, 00294: resource size t size,resource_size_t min, 00295: resource_size_t max,resource_size_t align, 00296: void (*alignf)(void *struct resource 00297: resource_size_t,resource_size_t), 00298: void *alignf_data) 00299: 00300: struct resource *this root->child; 00301: 00302: new->start root->start; 00303: /米 00304: Skip past an allocated resource that starts at o,since the assignment 00305: of this->start-1 to new->end below would cause an underflow. 00306: 米 00307: if (this &this->start ==0) 00308: new->start this->end 1; 00309: this this->sibling; 00310: 00311: for(;;){ 00312: if (this) 00313: new->end this->start-1; 00314: else 00315: new->end root->end; 00316: if (new->start min) 00317: new->start min; 00318: if (new->end max) 00319: new->end max; 00320: new->start ALIGN(new->start,align); 统实验室 00321: if (alignf) M LABORATORY CEO STUDY OF USTC 00322: alignf(alignf_data,new,size,align);
2023/7/14 Linux OS Analysis 15/105
00323: if (new->start new->end &new->end-new->start >size-1){ 00324: new->end new->start size-1; 00325: return 0; 00326: 2 00327: if (this) 00328: break; 00329: new->start this->end +1; 00330: this this->sibling; 00331: }?end for;i? 00332: return EBUSY; 00333: end find resource 嵌入式系统实验室 2023/7/14 Linux OS Analysis 16/105 EMBEDDED SYSTEM LABORATORY SUZHOU INSTITUTE FON ADVANCED STUDY OF USTC
2023/7/14 Linux OS Analysis 16/105