tailieunhanh - LINUX DEVICE DRIVERS 3rd edition phần 7

Một cách sử dụng điển hình của các rào cản bộ nhớ trong một trình điều khiển thiết bị có thể có này Lưu ý rằng quá trình người sử dụng luôn có thể sử dụng mremap để mở rộng bản đồ của nó, có thể quá khứ cuối của khu vực thiết bị vật lý. Nếu lái xe của bạn không xác định một phương pháp nopage | Kobject initialization This book has presented a number of types with simple mechanisms for initialization at compile or runtime. The initialization of a kobject is a bit more complicated especially when all of its functions are used. Regardless of how a kobject is used however a few steps must be performed. The first of those is to simply set the entire kobject to 0 usually with a call to memset. Often this initialization happens as part of the zeroing of the structure into which the kobject is embedded. Failure to zero out a kobject often leads to very strange crashes further down the line it is not a step you want to skip. The next step is to set up some of the internal fields with a call to kobject_init void kobject_init struct kobject kobj Among other things kobject_init sets the kobject s reference count to one. Calling kobject_init is not sufficient however. Kojjjcct usess must at a minimum stt the name of the kobject this is the name that is used in sysfs entries. If you dig through the kernel source you can find the code that copies a string directly into the kob-ject s name field but that approach should be avoided. Instead use int kobject_set_name struct kobject kobj const char format . This function takes a printk-style variable argument list. Believe it or not át is actually possible for this operation to fail it may try to allocate memory conscientious code should check the return value and react accordingly. The other kobject fields that should be set diseetly or indi thy by the createa are ktype kset and parent. We will get to these later in this chapter. Reference count manipulation One of the key functions of a kobject is to serve as a reference counter for the object in which it is embedded. As long as references to the object exist the object aand the code that supports it must continue to exist. The low-level functions for manipulating a kobject s reference counts are struct kobject kobject_get struct kobject kobj void kobject_put struct .

TỪ KHÓA LIÊN QUAN