Re: Convert urb to skbuff
On Mon, Nov 29, 2010 at 5:17 PM, sugnan prabhu sugnan.pra...@gmail.com wrote: Hello, I am trying to write a kernel module which is the combination of the usb driver and a network driver, now whenever the data is recieved by the usb driver it will be in struct urb, but the data that is required by the net driver is sk_buff, now how do i convert a urb to sk_buff, i found something similar is being done in the phonet protocol, but i couldnt understand, howexactly this is being done. Can someone explain this code. drivers/net/usb/cdc-phonet.c -- static void rx_complete(struct urb *req) { struct net_device *dev = req-context; struct usbpn_dev *pnd = netdev_priv(dev); struct page *page = virt_to_page(req-transfer_buffer); struct sk_buff *skb; unsigned long flags; int status = req-status; switch (status) { case 0: spin_lock_irqsave(pnd-rx_lock, flags); skb = pnd-rx_skb; if (!skb) { skb = pnd-rx_skb = netdev_alloc_skb(dev, 12); if (likely(skb)) { /* Can't use pskb_pull() on page in IRQ */ memcpy(skb_put(skb, 1), page_address(page), 1); skb_add_rx_frag(skb, skb_shinfo(skb)-nr_frags, page, 1, req-actual_length); page = NULL; } } else { skb_add_rx_frag(skb, skb_shinfo(skb)-nr_frags, page, 0, req-actual_length); page = NULL; } if (req-actual_length PAGE_SIZE) pnd-rx_skb = NULL; /* Last fragment */ else skb = NULL; spin_unlock_irqrestore(pnd-rx_lock, flags); if (skb) { skb-protocol = htons(ETH_P_PHONET); skb_reset_mac_header(skb); __skb_pull(skb, 1); skb-dev = dev; dev-stats.rx_packets++; dev-stats.rx_bytes += skb-len; netif_rx(skb); } goto resubmit; case -ENOENT: case -ECONNRESET: case -ESHUTDOWN: req = NULL; break; case -EOVERFLOW: dev-stats.rx_over_errors++; dev_dbg(dev-dev, RX overflow\n); break; case -EILSEQ: dev-stats.rx_crc_errors++; break; } dev-stats.rx_errors++; resubmit: if (page) netdev_free_page(dev, page); if (req) rx_submit(pnd, req, GFP_ATOMIC); } The URB struct doesn't contain the actual transfered data rather it contains a pointer to the data, the transfer_buffer element. The code basically copies data from the transfer buffer to the sk buff. The virt_to_page / page_address will return the virtual address of the start of the transfer_buffer page. -- James Bond -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
all the kernel apis some where
Hi list I was having this question as we have some 200 system calls in C similarly is there a list of kernel APIs that kernel provides to device driver developers or other sort of people/ -- http://www.infibeam.com/Books/linux-kernel-api-lambert-m-surhone/9786132143969.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: how is a device detected
On Tue, Nov 23, 2010 at 3:07 AM, Yuchen Liao lycdra...@gmail.com wrote: AFAIK, in the device_add() function (in driver/base/core.c), kernel will invoke device_create_file() function to create the uevent file; (The kobj is also added in this device_add() function by invoke kobject_add() function) In user space, the udevd is listening the NETLINK_KOBJECT_EVENT to get the uevent event. Then it will find a match udev rule under the /etc/udev/rules.d/. It will make changes according to the rule(Like create the device file under /dev). Every device when it is register, it will create a uevent file(by this way, can trigger a hotplug event), can write a add or remove command to add or remove a device. When starting computer, kernel will register a lot of devices, but the udev(in user space) is not start. After it start, it will scan the sysfs, to get all the uevent file, and write add into it. In this way, the event been triggered. I'm not so sure that I'm right. Please correct me if there is anything wrong. Thank you~ Hi thanks your explanation was very good. I have been doing some research on this aspect and replying you after so many days it is helpful. What I came across was some thing known as pci-core for PCI devices and USB core for USB devices. So that is one thing I surely want to understand. My objective by this exercise is to be able to write a kernel which is working on bare metal.(I just want a small set of code which can work) So I want to understand it more.If some one has more thoughts here then share it please. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: kernel build on ubuntu 10.04 fails, buffer overflow detected
On Tue, Nov 30, 2010 at 4:50 PM, Robert P. J. Day rpj...@crashcourse.ca wrote: hi, one of the people working thru my kernel programming course reports the following kernel build error trying to build the kernel on ubuntu 10.04: http://pastebin.com/myKCcZ0X i'm going to check it out later but if anyone knows off-hand what might be happening there, fill me in. thanks. rday My suggestion is lib/tls/i686/cmov/libc.so.6 he might have symlinked the above to some thing. Just ask for where is the above library pointing to. I hope it is a symlink and that is the only cause of error. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
importance of microcontrollers for Kernel Programming
Hi list, was going through some relevant links docs as usual. Curious to know how much of microcontrollers does a kernel developer understands. Is there some resource which the list would suggest? How can some one write their own kernel and not follow the one which is written via Linus. -- James Bond -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: which are board support packages in kernel
On Mon, Nov 29, 2010 at 12:05 PM, John Mahoney jmaho...@waav.com wrote: You probably want to read a book on x86 assembly language, but the kernel uses a special version of the language which does not have the same syntax as how I first learned x86 assembly. The kernel uses special gcc inline asm assemble to embed the code within c code. Yea I have read the type of things you just mentioned some where in code. You can do a lot in the kernel without ever touching the arch directory and it tends to be some of the most complex and close to the metal code. I would stick to drivers and the non-arch specific code first. I understand it just that I am hungry for it :) So I can't resist any more. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Debugging kernel modules
On Mon, Nov 29, 2010 at 3:06 PM, sugnan prabhu sugnan.pra...@gmail.com wrote: Hello, Can some one tell, whats the best way to kernel module, i want to get value of sk_buff data structure for running kernel. Kernel is not a userspace application to attach gdb. Though people have used kgdb but my suggestion would be to use in your program printk statements and check it manually. That is how 80% of people debug it. Any thing else is just a show off. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Convert urb to skbuff
On Mon, Nov 29, 2010 at 5:17 PM, sugnan prabhu sugnan.pra...@gmail.com wrote: Hello, I am trying to write a kernel module which is the combination of the usb driver and a network driver, now whenever the data is recieved by the usb driver it will be in struct urb, but the data that is required by the net driver is sk_buff, now how do i convert a urb to sk_buff, My reply is not a direct answer of your question but it might help you to understand. In USB driver the read and write is done via making calls to file operations which are same for character drivers. I.e. the USB end points is some thing you need to understand. For a USB driver the device will be reading and writing to the endpoints. Hence you need to have char driver which can create all this for you. i found something similar is being done in the phonet protocol, but i couldnt understand, howexactly this is being done. Can someone explain this code. drivers/net/usb/cdc-phonet.c -- static void rx_complete(struct urb *req) { struct net_device *dev = req-context; struct usbpn_dev *pnd = netdev_priv(dev); struct page *page = virt_to_page(req-transfer_buffer); struct sk_buff *skb; unsigned long flags; int status = req-status; switch (status) { case 0: spin_lock_irqsave(pnd-rx_lock, flags); skb = pnd-rx_skb; if (!skb) { skb = pnd-rx_skb = netdev_alloc_skb(dev, 12); if (likely(skb)) { /* Can't use pskb_pull() on page in IRQ */ memcpy(skb_put(skb, 1), page_address(page), 1); skb_add_rx_frag(skb, skb_shinfo(skb)-nr_frags, page, 1, req-actual_length); page = NULL; } The above is for receiving end (usually rx functions are for receive) } else { skb_add_rx_frag(skb, skb_shinfo(skb)-nr_frags, page, 0, req-actual_length); page = NULL; } if (req-actual_length PAGE_SIZE) pnd-rx_skb = NULL; /* Last fragment */ else skb = NULL; spin_unlock_irqrestore(pnd-rx_lock, flags); if (skb) { skb-protocol = htons(ETH_P_PHONET); skb_reset_mac_header(skb); __skb_pull(skb, 1); skb-dev = dev; dev-stats.rx_packets++; dev-stats.rx_bytes += skb-len; netif_rx(skb); } goto resubmit; case -ENOENT: case -ECONNRESET: case -ESHUTDOWN: req = NULL; break; case -EOVERFLOW: dev-stats.rx_over_errors++; dev_dbg(dev-dev, RX overflow\n); break; case -EILSEQ: dev-stats.rx_crc_errors++; break; } dev-stats.rx_errors++; resubmit: if (page) netdev_free_page(dev, page); if (req) rx_submit(pnd, req, GFP_ATOMIC); } I don't think what you are asking is actually linked to the code you posted. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: which are board support packages in kernel
On Tue, Nov 30, 2010 at 2:06 AM, John Mahoney jmaho...@waav.com wrote: On Mon, Nov 29, 2010 at 7:09 AM, Bond jamesbond.2...@gmail.com wrote: On Mon, Nov 29, 2010 at 12:05 PM, John Mahoney jmaho...@waav.com wrote: You probably want to read a book on x86 assembly language, but the kernel uses a special version of the language which does not have the same syntax as how I first learned x86 assembly. The kernel uses special gcc inline asm assemble to embed the code within c code. Yea I have read the type of things you just mentioned some where in code. You can do a lot in the kernel without ever touching the arch directory and it tends to be some of the most complex and close to the metal code. I would stick to drivers and the non-arch specific code first. I understand it just that I am hungry for it :) So I can't resist any more. Here is some decent free material. Not the best learning material, but it gets the job done. http://www.intel.com/products/processor/manuals/ He he thanks :-) -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
which are board support packages in kernel
I wanted to understand which files are related to board support packages in Linux Kernel. I specially want to understand intel architecture related files. So which files should I be looking,and where do I begin? -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: which are board support packages in kernel
On Mon, Nov 29, 2010 at 3:23 AM, John Mahoney jmaho...@waav.com wrote: The 32 bit and 64 bit were consolidated a while ago see http://lwn.net/Articles/242439/ Thanks for the links. I am a bit new to this sort of things. What else other than kernel code should I be reading to understand such stuff? -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
where are sample codes of LDD 3 book
Hi,can any one give a link to ftp site where I can get the sample codes of LDD 3rd edition book. A chapter of Block Device Driver talks about it and says that such codes exist online. I want a link to that. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: C programming resource
On Tue, Nov 23, 2010 at 11:07 AM, Sameer Rahmani lxsam...@gmail.com wrote: Hi, i'm not a C programmer , but i have a medium level of C programming knowledge that i think its not enough for spend time on kernel source. so could you people guide me for choosing a good resource for improving my C programming knowledge? I am in a similar situation as you are.Believe me the question you asked I have asked here. For people like you and me here is a document which will be put on the wiki page of this list http://www.spinics.net/lists/newbies/msg41296.html As far as your question goes I totally agree that many a times I have found data structures,typedefs,macros defined in the kernel sources which you may not find else where on the planet easily. I read the C book Kerninghan Ritchie and what ever was available to me (which were considered as good books on C in my locality) but still I found things difficult to understand. As far as your question goes if you are interested to understand the C programming things used in Kernel I would suggest pick up a project or some code and try to start understanding it.This will improve a lot of your C. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
how does macro to get base address register in configuration space works
I am trying to understand working of pci_resource_start function So I browsed code via cscope and searched for string pci_resource_start and got following in pci.h #define pci_resource_start(dev, bar)((dev)-resource[(bar)].start) I am not able to understand how does this above macro works. How does it above macro gets appropriate base address register in configuration space? -- -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
how is a device detected
Hi, in some of the books I am reading I find a text which mentions MODULE_DEVICE_TABLE () macro makes a user defined structure available in the module image so that the module can be loaded on demand if the card is hotplugged. I am not clear with how is this detection happening inside the kernel. How does the kernel detects the presence of a particular device?( I am not referring to the probe function defined in many drivers) -- Most of the free documentation and device driver books are not worth reading. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: guidelines, faqs and dos and don'ts document
On Sat, Nov 20, 2010 at 1:14 AM, John Mahoney jmaho...@waav.com wrote: Bond I think you are a prime example of someone who walks the line between asking legit questions and asking dubious questions. I think your intentions are good and you really are trying to learn, but you ask far too many questions far too quickly. Also, I think you should I read that book of device drivers which is and read it for at least many years and not once many many times.I could not write a single driver out of it. Which I recently wrote by writing some other recent docs and then with the understanding developed from them. If there is some thing like my previous question for a structure in super IO chips such things I do not see commonly being used. I looked at a similar code in vlc media player and found that such a structure was not known to many many experienced kernel level programmers and they found it difficult to understand. If some one is asking a question via a typedef in a function pointer or structure initialization which he never found any where else on this planet other than the kernel then what wrong is he doing.That book does not covers such things.See it is very good to give lecture to any one who asked question to do blah blah but to understand his problem and give a solution to some thing specific is not an easy thing. Recent example was my character device question where the driver was dropping characters out of it. I could not understand the reason behind it some one even blocked me from his mails and one guy actually solved that problem. When you are learning some thing then asking questions even the silliest ones is not wrong. At least some one who is asking is attempting his level best( upon his understanding) to understand irrespective of the fact that community does not appreciates that. I did read K R after getting busted here and I do not see any one else other than me asking such C questions and to the best of my knowledge I did not found any thing the people who suggest to read K R themselves do not read that book but will give suggestion to read. KR was written for C in very old times to help people beginning with programming or what ever reason it does not cover often the way Data structures are initialized in kernel specific areas.Or some other relevant stuff.My point is rather than giving some one such a lecture it will be better to just make a doc with relevant structs,typedefs and such other tricks which are used in kernel many a times which might not be commonly found on the wiki and give a link to that may be if such a thing is present some one whose questions appear silly would before asking read that doc and will get his answers from there. -- Most of the free documentation and kernel books are not worth reading. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: guidelines, faqs and dos and don'ts document
On Sat, Nov 20, 2010 at 2:23 PM, John Mahoney jmaho...@waav.com wrote: On Sat, Nov 20, 2010 at 2:08 PM, John Mahoney jmaho...@waav.com wrote: Just remember, most people here are doing this for free, so be polite and make sure your not asking obvious questions. Ok I personally feel your questions and attitude have improved. I was not trying to single one person out, I apologize for that. You don't need to apologize.I understand the concern of the people on this list. I do agree that too obvious questions should not come on the list.Before I proceed I apologize for being rude. But what I want to explain is I did read the docs and K R when you people pointed me to read. I admit that to an extent my understanding was not correct and the things which might have been too obvious for any one were not that obvious for me. Here is my situation I did read that book for developing device drivers by the famous guy and I do appreciate the presence of such a book. But after reading it for many many many times and not once (this happened over years) I lost my interest in developing drivers or reading that book again and again.My heart sank after seeing that book. Frustrated over and again with same content I saw some recent things on this list which did helped me to understand and the day I understood those concepts I have not turned back yet. My point is some one who genuinely has read the docs and books and still could not understand what will you do with him,block him from your mailing list or give him a pointer to this doc which is being discussed here that will not serve the purpose. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: mouse commands
On Thu, Nov 18, 2010 at 8:05 PM, Mulyadi Santosa mulyadi.sant...@gmail.com wrote: It seems to me like this: 1. Send E , 5 , E then 5 consecutively and what does that E5 do? -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: structure for Super IO chip detection
On Fri, Nov 19, 2010 at 1:37 PM, hiren panchasara hiren.panchas...@gmail.com wrote: My only attempt was to encourage culture of trying code out for such pure programming questions. Your encouragement does not make any sense,I could not understand how is that going to work what do I program. Any how now I understood the concept. -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: guidelines, faqs and dos and don'ts document
On Fri, Nov 19, 2010 at 11:13 PM, Alison Chaiken alchai...@gmail.com wrote: Anuz, I think your document is right on-target. I would just add, Don't ask for help with basic C programming. Yes, there are lots of idioms in the kernel that are not found elsewhere in C, and asking about those is on-topic, but questioners should not (intentionally) ask questions that will be answered by consulting KR. It would be a difficult task to mention what structures or data types occur again and again which are not present in K R to make a wiki page on kernelnewbies and point to it but this would be worth than making a lecture note and when some one asks some question which is a common fault then give them a 5 page lecture to read that doc. I do not see any value in such a doc most of the people would be happy with a guide of how to ask questions smart way. Also, readers should not ask questions relevant to particular boards or drivers. Those questions should be asked (if at all) on specialist mailing lists. If I am aware of what I am asking why would I be a kernel newbie. Why don't you make relevant pages to point to some guides like crashcourse.ca and some simple things which make a newbie a safer dive rather than saying him to jump to I2C and discuss some thing. Sorry if I am too harsh here but I mean it. -- Most of the free documentation and kernel books are not worth reading. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
mouse commands
Hi,as mentioned on this link http://books.google.co.in/books?id=Boo57V0IOq0Cpg=PA140lpg=PA140dq=xc/programs/Xserver/hw/xfree86/os-support/shared/posix_tty.csource=blots=pwIuaVO7T5sig=qcB-fhT4qb0M36BYvf2CM3uNYFohl=enei=be3kTKS6D47fcZKxoeUKsa=Xoi=book_resultct=resultresnum=3ved=0CCUQ6AEwAg#v=onepageq=xc%2Fprograms%2FXserver%2Fhw%2Fxfree86%2Fos-support%2Fshared%2Fposix_tty.cf=false the author mentions a code snippet what are the commands passed to mouse to which he is trying to explain poll ,select system calls. -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
structure for Super IO chip detection
On this link http://lxr.free-electrons.com/source/drivers/parport/parport_pc.c?v=2.6.29#L97 they defined a structure superio_struct and initialized as superios[NR_SUPERIOS] = { {0,},}; I am not able to understand above initialization has what is it getting initialized to. What I deduce till now is superios is a structure array of struct superio_struct and NR_SUPERIOS is defined as 3 hence an array of structure of size 3 but superios[0]=?? superios[1]=?? superios[2]=?? I had a look at following links http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/designators.htm http://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html https://www.acrc.bris.ac.uk/RedHat/rhel-gcc-en-4/designated-inits.html also checked the C books available with me. This part is not clear to me as to what these individual members are initialized to. -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: structure for Super IO chip detection
On Thu, Nov 18, 2010 at 10:56 PM, hiren panchasara hiren.panchas...@gmail.com wrote: Please put it into a small c prog and try it yourself. You will come to know in a minute. I am not able to understand what program do I make to put thats why I asked. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
what is int 0x15 service and function number 0xe820
On the following link http://books.google.co.in/books?id=Boo57V0IOq0Cpg=PA20lpg=PA20dq=Real+mode+initialization+code+uses+the+BIOS+int+0x15+service+with+function+number+0xe820(hence+the+stringBIOS-e820+in+the+preceding+message)+to+obtain+the+system+memory+map.source=blots=pwHDiPT3V0sig=rHrY6I3UYdT0glPbnj13lmRFqu0hl=enei=1AfhTMyfEoSqvQPJxMToDgsa=Xoi=book_resultct=resultresnum=3ved=0CCMQ6AEwAg#v=onepageqf=false following text is mentioned Real mode initialization code uses the BIOS int 0x15 service with function number 0xe820(hence the string BIOS-e820 in the preceding message) to obtain the system memory map. What is int 0x15 service and function number 0xe820 where can I read more about it? -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: load balancing
On Tue, Nov 9, 2010 at 2:21 AM, Andrzej andkar...@gmail.com wrote: You should read this: http://lartc.org/howto/lartc.rpdb.multiple-links.html#AEN298 BTW: I dont think that is right place to ask that questions. It's kernel like group...better idea is ask for help in this case in linux-like forums... Search for IPTABLE multiple internet connections. http://linux-ip.net/html/adv-multi-internet.html and yes this is not the place to ask these type of questions. This grp is for Kernel Developers not firewall builders or sys admins. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: BIOS Vs. Linux
2010/11/4 अनुज anu...@gmail.com: Hi list, I am just exploring how much the linux is dependent on BIOS. I wanted to know : 1. Which information linux uses from BIOS ( some sort of tables like MP tables, ACPI tables) and for what purpose? 2. Whether linux uses BIOS routines to program and initialize the different chips (e.g. IOAPIC, PIR, PCI devices etc.) or not? What is IOAPIC,PIR,ACPI table or MP table? -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
how to define id table
Hi, can any one tell me how is following type of structure defined? static DEFINE_PCI_DEVICE_TABLE(rtl8139_pci_tbl) = { {0x10ec, 0x8139, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, {0x10ec, 0x8138, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, {0x1113, 0x1211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, {0x1500, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, {0x4033, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, {0x1186, 0x1300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, {0x1186, 0x1340, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, What do these 0x1186 and PCI_ANY_ID etc mean in above type of structure also this type of definition of a structure where {},{} is used I am not clear with this approach. -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Char Driver
http://kerneltrap.org/mailarchive/linux-kernel-newbies/2010/9/25/6838336 on the above link there was some fight but that link is an excellent resource for you. Venkataram Tummula has debugged that driver and it will help you a lot. Read the technical thing and check this page also http://www.freesoftwaremagazine.com/articles/drivers_linux On Tue, Nov 2, 2010 at 6:40 AM, Victor Rodriguez vm.ro...@gmail.com wrote: Hi all I have a doubt I have checked the Char Driver from Linux Device Drivers 3rd edition and I can not understand how does the char driver is register in the newst way, I just have done by the Linux Kernel Module programing guide example http://tldp.org/LDP/lkmpg/2.6/html/x569.html with the function int init_module(void) { Major = register_chrdev(0, DEVICE_NAME, fops); if (Major 0) { printk(KERN_ALERT Registering char device failed with %d\n, Major); return Major; } printk(KERN_INFO I was assigned major number %d. To talk to\n, Major); printk(KERN_INFO the driver, create a dev file with\n); printk(KERN_INFO 'mknod /dev/%s c %d 0'.\n, DEVICE_NAME, Major); printk(KERN_INFO Try various minor numbers. Try to cat and echo to\n); printk(KERN_INFO the device file.\n); printk(KERN_INFO Remove the device file and module when done.\n); return SUCCESS; } but the new way is with alloc_chrdev_region and struct cdev *my_cdev = cdev_alloc( ); my_cdev-ops = my_fops; but i can not see any good and easy example on the internet Does anybody has seen any one ? One more thing After insert the module on the kernel I need to run mknod in order to make the node to interact with cat and echo instructions Is there another automatic way to do that ? I have read a litle bit from udev, but I wonder how does the /dev char drivers are created when linux start ? Thanks for all the help Sincerely yours Victor Rodriguez -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Why to not mark struct pci_driver
http://lxr.linux.no/#linux+v2.6.36/Documentation/PCI/pci.txt#L197 What is meant by marking strcut pci_driver as the above link says not to mark it. -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
typdef in iw_handler.h
I have used typedef in my C programs previously many times. So it is not new to me For example consider following typedef struct var { int data1; int data2; char data3; }; typedef struct var newtype; then we can use newtype instead of struct var. Now see this typedef int (*iw_handler)(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra); above is line number 314 in include/net/iw_handler.h I was not able to understand what is being typedef'd here? -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: USB driver (hello usb driver)
On Sun, Oct 24, 2010 at 9:24 PM, Greg KH g...@kroah.com wrote: Yes, look at the hid driver blacklist. so that it checks my driver and if it doesn't find it, then pass it to the usbhid? If your driver is loaded first, yes, you can do that. You can unbind the device from the hid driver by hand through sysfs and then load your driver for testing. Okay, i found my device in /dev/bus/usb/devices/usb6/6-1. When I nano idVendor, i see the correct vendor, and when i nano idProduct, i see the correct product. So it's definately there, but I think the problem is that usbhid is catching it before my module does. how would i unload the device and test like you stated? -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
config.gz equivalent
I am reading a book in which it said me to do gunzip -c /proc/config.gz | more then I found config.gz missing on my system. On this link I tried a command http://www.linuxforums.org/forum/gentoo-linux/65684-cant-find-proc-config-gz.html cat /boot/config-2.6.28-11-generic | grep -i ikconfig # CONFIG_IKCONFIG is not set so it turns out config.gz is not there on my system. Is there an equivalent file of config.gz on the system. -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: config.gz equivalent
On Sun, Oct 24, 2010 at 7:43 PM, Kfir Lavi lavi.k...@gmail.com wrote: gunzip -c /proc/config.gz | more If you did cat /boot/config-2.6.28-11-generic | grep -i ikconfig and got # CONFIG_IKCONFIG is not set your config is the file: /boot/config-2.6.28-11-generic You mean to say /proc/config.gz or /boot/config-2.6.28-11-generic are same things. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: USB driver (hello usb driver)
On Sun, Oct 24, 2010 at 9:24 PM, Greg KH g...@kroah.com wrote: You can see if it is, look in sysfs, or in /sys/kernel/usb/devices I do not have any such directory on my system. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: USB driver (hello usb driver)
On Fri, Oct 22, 2010 at 6:01 AM, Greg KH g...@kroah.com wrote: On Wed, Oct 20, 2010 at 10:49:33PM +0530, Bond wrote: So, I got it to recognize the driver in the kernel, but it refuses to probe. No matter that vendor/product id combination I use for any of the devices I've tested. Are you using device ids of existing devices that already have drivers bound to them? If so, don't do that :) IT's a game pad so it might be bound to the joystick service? is there a way to supercede the usbhid driver? so that it checks my driver and if it doesn't find it, then pass it to the usbhid? -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Learning Memory management and process management.
On Thu, Oct 21, 2010 at 12:53 PM, prabhu prab...@msys-tech.com wrote: HI All, I am new to Kernel newbies. Last month i have started to learn linux kernel. I have struggled to understand the relation between memory and the process. I would be grateful to you if some one provide the answers/reference document to the below question. How the kernel determine processor architecture. That means at what point of the kernel understand the processor architecture and start working on architecture based operations? I have no idea of this. How the process pass the data into the processor and get the output? Does any relation exists b/w file-system and the page table in hardware address ? There are functions copy_from_user and copy_to_user these are the functions which pass on data from user space to kernel space. You can use a command strace try to run it as follows strace firefox on terminal you will see a lot of output. How the kernel load new memory area from the physical disk to RAM. Does processor involved in this operation? How the processor intimate the page fault exception to the kernel . which register get involved in this operation? How the process restart the operation after load the required pages into the memory? Does processor have separate memory for storing instruction and data. If yes, what would be the size ? What is the relation between GDT and LDT. Does each processor have its own GDT and LDT?. If so how the process details are organized by the kernel where is it stored in the memory and how the process identifies this? what is the default memory space will be allocated to this table. Any information related to processor architecture detail and working would be helpful for me to understand overall structure. I know a book Linux Kernel Primer if you can get it ,it might help you. Above questions may be unrelated or stupid. If so sorry for the inconvenience. No question is stupid and when in doubt it is better to ask and get ridiculed at least you will learn some thing. Thanks, Prabhu -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
USB driver (hello usb driver)
So, I got it to recognize the driver in the kernel, but it refuses to probe. No matter that vendor/product id combination I use for any of the devices I've tested. bond.c [code] #include linux/module.h #include linux/kernel.h #include linux/init.h #include linux/usb.h #define AUTHOR bond #define DESC Device Driver for the bond #define VENDOR 0x06A3 #define DEVICE 0xF622 MODULE_LICENSE(GPL); MODULE_AUTHOR(AUTHOR); MODULE_DESCRIPTION(DESC); static struct usb_device_id bond_table [] = { { USB_DEVICE(VENDOR, DEVICE) }, { } }; MODULE_DEVICE_TABLE(usb, bond_table); int bond_probe(struct usb_interface *intf, const struct usb_device_id *id) { printk(KERN_INFO bond_PROBE); return 0; } void bond_disconnect(struct usb_interface *intf) { printk(KERN_INFO bond_DISCONNECT); } static struct usb_driver bond_driver = { name:bond, id_table:bond_table, probe:bond_probe, disconnect:bond_disconnect, }; static int __init init_cci(void) { int result = usb_register(bond_driver); if(result 0) { printk(KERN_INFO usb_register failed. err #%d, result); return -1; } printk(KERN_INFO INIT_bond); return 0; } module_init(init_cci); static void __exit exit_cci(void) { printk(KERN_INFO EXIT_bond); usb_deregister(bond_driver); } module_exit(exit_cci); [/code]modinfo bond.ko lsusb lsmod dmesg dmesg when plugging in device modprobe bond/bond.ko/bond Any ideas on this matter would be great. Thank you. -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Tools Device Drivers
On Sat, Oct 16, 2010 at 10:23 PM, Mulyadi Santosa mulyadi.sant...@gmail.com wrote: Also, I want to study Device Drivers.What should be my starting point.I know,I should peep into the drivers folders and thats what I did ...but the kernel world is so vast deep that I got confused. Buddy who so ever you are you need to get your hands dirty on code. I think you better start with kernel janitorial.. I have not tried the kernel janitorial my self so can not comment. But the best way to learn is pick a project and start working. You will get a lot of errors and along with them you will learn. That is how it works. -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
where LIST_HEAD is used
Hi, every one I want to see where LIST_HEAD is used, may be for any work que or any device driver can some one point me to which file should I look to see how LIST_HEAD macro is used. -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
link list implementation in linux kernel easy question syntax not clear
Hi,in http://lxr.linux.no/#linux+v2.6.18/include/linux/list.h following section of code there is a structure which is defined as struct list_head { struct list_head *next, *prev; }; It is used in another file as #define LIST_HEAD_INIT(name) { (name), (name) } #define LIST_HEAD(name) \ struct list_head name = LIST_HEAD_INIT(name) static inline void INIT_LIST_HEAD(struct list_head *list) { list-next = list; list-prev = list; } I came across a book where the code is given as follows in an example include/linux/list.h struct list_head { struct list_head *next,*prev; }; #define LIST_HEAD_INIT(name) {(name),(name)} #define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name) #define INIT_LIST_HEAD(prt) do {\ (ptr)-next = (ptr);(ptr)-prev= (ptr);\ }while(0) I was not able to understand above code segment. I am aware of what a #define is but still I could not understand above thing. Can some one help in understanding with some example. Not related to Linux Kernel a normal example where I can make a link list with above defined way. -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: link list implementation in linux kernel easy question syntax not clear
On Sat, Oct 9, 2010 at 12:27 PM, Manish Katiyar mkati...@gmail.com wrote: On Fri, Oct 8, 2010 at 11:38 PM, Bond jamesbond.2...@gmail.com wrote: Hi,in http://lxr.linux.no/#linux+v2.6.18/include/linux/list.h following section of code there is a structure which is defined as struct list_head { struct list_head *next, *prev; }; It is used in another file as #define LIST_HEAD_INIT(name) { (name), (name) } #define LIST_HEAD(name) \ struct list_head name = LIST_HEAD_INIT(name) static inline void INIT_LIST_HEAD(struct list_head *list) { list-next = list; list-prev = list; } I came across a book where the code is given as follows in an example include/linux/list.h struct list_head { struct list_head *next,*prev; }; #define LIST_HEAD_INIT(name) {(name),(name)} #define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name) #define INIT_LIST_HEAD(prt) do {\ (ptr)-next = (ptr);(ptr)-prev= (ptr);\ }while(0) I was not able to understand above code segment. I am aware of what a #define is but still I could not understand above thing. Can some one help in understanding with some example. Not related to Linux Kernel a normal example where I can make a link list with above defined way. http://kernelnewbies.org/FAQ/LinkedLists I read that link but could not understand much out of it. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: segmentation question
Sorry for interrupting in between. On Sat, Oct 2, 2010 at 3:08 AM, Sri Ram Vemulpali sri.ram.gm...@gmail.comwrote: Hi All, I am developing segmentation for my kernel. In that process I choose to divide whole memory in to fixed size segments. So a 4GB memory can be divided in to 8192 segments. So I initialize segment descriptors in to the GTD What is GTD Where are you reading all this can you give some link I also want to try.
Re: my kmalloc implementation
No not glibc I want a link to heap implementation in glibc On Sat, Oct 2, 2010 at 10:05 PM, Dave Hylands dhyla...@gmail.com wrote: Hi Bond, On Sat, Oct 2, 2010 at 2:34 AM, Bond jamesbond.2...@gmail.com wrote: On Sat, Oct 2, 2010 at 1:13 PM, Dave Hylands dhyla...@gmail.com wrote: Hi Bond, Sending to the list this time... glibc has a fairly sophisticated heap... Look at glibc alternatives. Each one will have a heap. Hey Dave thanks for this information. I do want to have a look. Can you give me some link? I just googled using the words glibs alternatives. The first page that came back is this one: http://en.wikipedia.org/wiki/GNU_C_Library which has several alternatives listed. -- Dave Hylands Shuswap, BC, Canada http://www.DaveHylands.com/ -- http://vger.kernel.org/vger-lists.html -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: my kmalloc implementation
Wouldn't a sparse matrix implementation of this be a better thing. I don't have a link. But you'd initialize doing something like this: uint8_t data[256]; free_list = 0; for ( i = 1; i 256; i++ ) { // Add Each byte to the free list. data[i] = free_list; free_list = i; } Finding a free entry would be something like: if ( free_list != 0 ) { uint8_t *avail = data[free_list]; free_list = *avail; *avail = 0; return avail; } and freeing would be something like this: index = freePtr - data; data[index] = free_list; free_list = index; --
my kmalloc implementation
I have to write my own kmalloc. I am not given any sort of Kernel API to assign or delete memory. Suppose I have 4GB of memory on Ram. Some of which is filled and some of which is not filled. My question is what data structure do I need to maintain in order to be able to assign memory to any userspace program when the program requests some bytes of memory which can be 1 or more. My logic for this implementation was to maintain a hashtable. For example 1-- points to all the memory addresses which are 1 byte and free 2-- points to all the memory addresses which are 2 byte and free 3-- points to all the memory addresses which are 3 byte and free 4-- points to all the memory addresses which are 4 byte and free . . . . . . . n-- points to all the memory addresses which are n byte and free How can I improve the above schema because to know the location where 1byte memory is free I will maintain a pointer which can be u64 or u32 which itself is costlier than the free memory itself. So what should I be doing to be able to do above.
Re: my kmalloc implementation
On Tue, Sep 28, 2010 at 11:59 AM, Dave Hylands dhyla...@gmail.com wrote: Hi Bond, So user mode programs don't allocate memory using kmalloc. I believe that they wind up calling __get_free_pages. There are many data structures that can be used. The kernel provides 3 different implementations of kmalloc, called, slab, slub and slob. It all depends on you design criteria. The simplest is to maintain a linked list of free spaces. It's simple, but suffers performance issues and fragmentation issues. You could use a bitmap (one bit per byte). Or you could maintain a indexed free list, where an 8-bit index is used. I googled above thing http://www.google.co.in/search?sourceid=chromeclient=ubuntuchannel=csie=UTF-8q=index+free+list but indexed free list I could not find any where. Can you give some link to what you are referring to. The 8-bit index would be stored using the free memory itself. You'd need to have a separate list for every 256 bytes, but that would have very low overhead. On Tue, Sep 28, 2010 at 12:15 PM, John Mahoney jmaho...@waav.com wrote: I would start by reading how it is already done...is that cheating. http://lxr.free-electrons.com/source/mm/page_alloc.c I am not that competent that I could understand that code which is given on that link. Before posting here I had looked that link.I want to understand what data structure or mechanism is used to do that.So once I get that thing with a simple program I surely will finish that link which you also pointed out. On Tue, Sep 28, 2010 at 12:15 PM, Manish Katiyar mkati...@gmail.com wrote: Bond, You might want to look at the example of malloc at the end of KnR. Can you tell me which page or chapter you are referring to? I was not able to find or missed what you suggested.
Re: character device driver reading only last character of buffer
On Sun, Sep 26, 2010 at 9:41 AM, Bond jamesbond.2...@gmail.com wrote: On Sun, Sep 26, 2010 at 3:43 AM, Venkatram Tummala venkatram...@gmail.com wrote: Hey buddy, i took the module code in your first post modified it to make it work . I am attaching the code. I am sure that it will not work the thing what I asked the question. If you are to copy only 1 byte that even my code has been doing. There is no improvement in your code. You are also giving memory_buffer = kmalloc(1, GFP_KERNEL); memset(memory_buffer, 0, 1); but since you were smart not to paste the code as I did or rather say it was my problem so I am trying to understand so no one is giving lecture to you to read what malloc is or start making programs for insertion sort. You people are free to kick me out of the list but make sure when some one asks a question you do not give them fundas give them some thing which actually works your code does not work what in what I am trying to do.
Re: character device driver reading only last character of buffer
On Sun, Sep 26, 2010 at 12:10 PM, Venkatram Tummala venkatram...@gmail.comwrote: Yes, it is possible to pass in 0 for register_chrdev. Please be clear what you want to achieve, from your subject line the post. The subject line the first few lines of the post indicates that That is not my fault if you do not read the thread for one character even I was able to make it. you need something which prints only the last character. And you go on creating a rucus around here. Who is creating rucus me or people giving me non sensical lecture to read malloc they hide their incompetency by giving lecture to Google. I have updated the code attached it. This can only read write 10 characters. Now, please dont tell us that it is not you wanted or it doesn't work. Please spare us. Your code is giving me some error I did Step 1) mknod /dev/bond c 0 0 Step 2) chmod 666 /dev/bond Step 3) insmod bond.ko Step 4) r...@bond:~# lsmod | grep bond bond2031 0 Step5) echo -n abcde /dev/bond gives me error *bash: /dev/bond: No such device or address *Step 6) where* *as I can see ls -l /dev/bond* *crw-rw-rw- 1 root root 0, 0 2010-09-26 12:14 /dev/bond in your code you have done in memory_read *f_pos = *f_pos + count; why have you done this? What purpose it serves?
Re: regarding synchronization code
On Sat, Sep 25, 2010 at 10:34 PM, Sri Ram Vemulpali sri.ram.gm...@gmail.com wrote: I am just saying I know inline keyword. But what is always_inline. I wonder why you were not given any lecture to Google etc as I get in my other threads.
Re: character device driver reading only last character of buffer
On Sun, Sep 26, 2010 at 12:30 PM, Venkatram Tummala venkatram...@gmail.comwrote: Do a cat /proc/devices|grep DEVICENAME. This will get you the number. I am getting two numbers here b...@bond:~/programming/venkatrama$ cat /proc/devices | grep bond 60 bond 250 bond which one should I use. Then do mknod /dev/bond c NUMBER in /proc/devices 0 . zero in register_chrdev(..) is not the device number. It indicates a dynamic number. http://www.fsl.cs.sunysb.edu/kernel-api/re941.html how is major number then assigned. How is the name of device then decided excerpts from the above link say The name of this device has nothing to do with the name of the device in /dev. It only helps to keep track of the different owners of devices. If your module name has only one type of devices it's ok to use e.g. the name of the module here. how do I make sure that if I am writing to device /dev/bond then bond module is being used in your code you have done in memory_read *f_pos = *f_pos + count; why have you done this? What purpose it serves? It updates the file pointer. Your program has worked I used 60 in mknod out of two outputs which came in cat /proc/device | grep bond
Re: character device driver reading only last character of buffer
On Sun, Sep 26, 2010 at 1:00 PM, Venkatram Tummala venkatram...@gmail.comwrote: Try writing a user space file handling program in C. I repeat what other have already said before. Before starting kernel development, you need to know the user space basics. I have done what you are saying in user space not once many times. Since you have been able to debug my code so I am mentioning I have made programs to insert ,delete a node in a link list ,reverse a link list,stack que implementations via link list,binary search trees, algorithms mentioned in the graphs chapter of Coreman book I have programmed, I have made socket programs which can read and write data to a socket stream (very basic network programming done) used seek,lseek methods in user space. The first read comes in with a *f_pos of 0. If you dont update the file pointer, the user space program will keep reading from f_pos 0 indefinitely. As file pointer is at offset 0 always because you dont update *f_pos, every read(..) called by user space will succeed. So, your command cat /dev/bond will never return. user space programs generally look for a specific return code to know that it is the end of the file. Thanks a lot for this one I was not clear on this part.
Re: character device driver reading only last character of buffer
On Sun, Sep 26, 2010 at 1:04 PM, Bond jamesbond.2...@gmail.com wrote: The first read comes in with a *f_pos of 0. If you dont update the file pointer, the user space program will keep reading from f_pos 0 indefinitely. As file pointer is at offset 0 always because you dont update *f_pos, every read(..) called by user space will succeed. So, your command cat /dev/bond will never return. user space programs generally look for a specific return code to know that it is the end of the file. That is the reason in strace I was getting mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2a2f03b000 write(1, abcde, 5)= 1 write(1, bcde, 4) = 1 write(1, cde, 3) = 1 write(1, de, 2) = 1 write(1, e, 1)= 1 close(1)= 0 munmap(0x7f2a2f03b000, 4096)= 0 close(2)= 0 exit_group(0) = ? What should I be reading to the thing you just mentioned in the above paragraph about updating file pointer f_pos meaniing what is happening each time when a user space call to read is done.
Re: character device driver reading only last character of buffer
On Sun, Sep 26, 2010 at 1:07 PM, Bond jamesbond.2...@gmail.com wrote: will never return. user space programs generally look for a specific return code to know that it is the end of the file. Are you referring to \0
Re: copy_to_user() and copy_from_user(): confusing code
On Sun, Sep 26, 2010 at 6:07 PM, Chetan Nanda chetanna...@gmail.com wrote: doesn't metter .. i need bright students too :-) :)
Re: copy_to_user() and copy_from_user(): confusing code
On Sun, Sep 26, 2010 at 4:53 PM, Chetan Nanda chetanna...@gmail.com wrote: Exactly what I was trying to indicate Given the fact you wanted to explain the same thing I fear you are not a good teacher.
Re: character device driver reading only last character of buffer
On Fri, Sep 24, 2010 at 10:51 PM, Mulyadi Santosa mulyadi.sant...@gmail.com wrote: When a senior member like Greg Freemyer respond like that, it must be Rather than giving me lecture here show me how this error can be fixed and let him prove if he deserves respect I do not have any problem in that,.
Re: copy_to_user() and copy_from_user(): confusing code
On Fri, Sep 24, 2010 at 5:41 PM, sri bskmo...@gmail.com wrote: what part is not able to understand? Here is a program I wrote but it is dropping characters though I gave 14 bytes to kmalloc and buffer but still the program is unable to read and write as I expect it to do. I did an strace on the program and have posted the log at the end #include linux/init.h #include linux/module.h #include linux/kernel.h /* printk() */ #include linux/slab.h /* kmalloc() */ #include linux/fs.h /* everything... */ #include linux/errno.h /* error codes */ #include linux/types.h /* size_t */ #include linux/proc_fs.h #include linux/fcntl.h /* O_ACCMODE */ #include asm/system.h /* cli(), *_flags */ #include asm/uaccess.h /* copy_from/to_user */ MODULE_LICENSE(Dual BSD/GPL); int bond_open(struct inode *inode, struct file *filp); int bond_release(struct inode *inode, struct file *filp); ssize_t bond_read(struct file *filp, char *buf, size_t count, loff_t *f_pos); ssize_t bond_write(struct file *filp, char *buf, size_t count, loff_t *f_pos); void bond_exit(void); int bond_init(void); struct file_operations bond_fops = { read: bond_read, write: bond_write, open: bond_open, release: bond_release }; module_init(bond_init); module_exit(bond_exit); int bond_major = 60; char *bond_buffer; int bond_init(void) { int result; result = register_chrdev(bond_major, bond, bond_fops); if (result 0) { printk(KERN_ALERT memory: cannot obtain major number %d\n, bond_major); return result; } bond_buffer = kmalloc(14, GFP_KERNEL); if (!bond_buffer) { result = -ENOMEM; goto fail; } memset(bond_buffer, 0, 14); printk(KERN_ALERT Inserting bond module\n); return 0; fail: bond_exit(); return result; } void bond_exit(void) { unregister_chrdev(bond_major, bond); if (bond_buffer) { kfree(bond_buffer); } printk( KERN_ALERT Removing bond module\n); } int bond_open(struct inode *inode, struct file *filp) { return 0; } int bond_release(struct inode *inode, struct file *filp) { return 0; } ssize_t bond_read(struct file *filp, char *buf, size_t count, loff_t *f_pos) { copy_to_user(buf,bond_buffer,count14 ? count:14); /* if (*f_pos == 0) { *f_pos+=1; return 1; } else { return 0; }*/ } ssize_t bond_write( struct file *filp, char *buf, size_t count, loff_t *f_pos) { // char *tmp; //tmp=buf+count-1; copy_from_user(bond_buffer,buf,count14 ? count : 14); return 1; } Here is the Makefile ifeq ($(KERNELRELEASE),) KERNELDIR ?= /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) .PHONY: build clean build: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules clean: rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c rm -rf modules.order Module.symvers else $(info Building with KERNELRELEASE =${KERNELRELEASE}) obj-m := bond.o endif and here is the strace mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2a2f03b000 write(1, abcde, 5)= 1 write(1, bcde, 4) = 1 write(1, cde, 3) = 1 write(1, de, 2) = 1 write(1, e, 1)= 1 close(1)= 0 munmap(0x7f2a2f03b000, 4096)= 0 close(2)= 0 exit_group(0) = ? so copy_from_user and copy_to_write are not doing what I expect them to do this is not clear to me.
Re: character device driver reading only last character of buffer
On Sat, Sep 25, 2010 at 8:36 PM, ptchinster ptchins...@archlinux.us wrote: Yup. Thank you for placing where i got it, i didn't save info when i saved this source. It didn't even compiled on my machine.
Re: character device driver reading only last character of buffer
running an strace on the program gave me mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2a2f03b000 write(1, abcde, 5)= 1 write(1, bcde, 4) = 1 write(1, cde, 3) = 1 write(1, de, 2) = 1 write(1, e, 1)= 1 close(1)= 0 munmap(0x7f2a2f03b000, 4096)= 0 close(2)= 0 exit_group(0) = ? any suggestions here on the list are not working and people are giving me lectures. You people show me some real code rather than speaking non sense.
Re: character device driver reading only last character of buffer
Since you people think me to be a newbie or moron or some thing like copy pasting the code so I am explaining each and every line of it what it is doing but still lectures are lectures and funda's don't work show me real thing or else do not reply. #include linux/init.h #include linux/module.h #include linux/kernel.h /* printk() */ #include linux/slab.h /* kmalloc() */ #include linux/fs.h /* everything... */ #include linux/errno.h /* error codes */ #include linux/types.h /* size_t */ #include linux/proc_fs.h #include linux/fcntl.h /* O_ACCMODE */ #include asm/system.h /* cli(), *_flags */ #include asm/uaccess.h /* copy_from/to_user */ The section declared above is used to include header files. MODULE_LICENSE(Dual BSD/GPL); MODULE_LICENSE is an exported symbol. int bond_open(struct inode *inode, struct file *filp); int bond_release(struct inode *inode, struct file *filp); ssize_t bond_read(struct file *filp, char *buf, size_t count, loff_t *f_pos); ssize_t bond_write(struct file *filp, char *buf, size_t count, loff_t *f_pos); just above defined four functions which will be used in structure file_operations which is of type defined in fs.h void bond_exit(void); int bond_init(void); my init and exit modules of code. struct file_operations bond_fops = { .read = bond_read, .write = bond_write, .open = bond_open, .release = bond_release declared as above as per new C99 rules so that rest of the file_operations which are not defined be declared NULL }; above operations corresponding to the system calls an application can apply to a file : file operations as in fs.h module_init(bond_init); module_exit(bond_exit); my init and exit modules int bond_major = 60; there is another way alloc_chrdrv but I am using register_chrdrv so defining the major number char *bond_buffer; device buffer to store data when user programs access it int bond_init(void) { int result; result = register_chrdev(bond_major, bond, bond_fops); if (result 0) { printk(KERN_ALERT memory: cannot obtain major number %d\n, bond_major); return result; } bond_buffer = kmalloc(14, GFP_KERNEL); giving 14 bytes to buffer three types GFP_KERNEL,GFP_ATOMIC one more I forgot if (!bond_buffer) { result = -ENOMEM; goto fail; } in case of error above will stop execution memset(bond_buffer, 0, 14); filling all the bytes of memory Claros pointed me here that if I ever used malloc function in my life so mentioning this was important for him. printk(KERN_ALERT Inserting bond module\n); return 0; fail: bond_exit(); return result; same when returns a -ve value if fail to register the major number 60 } void bond_exit(void) { unregister_chrdev(bond_major, bond); if (bond_buffer) { kfree(bond_buffer); } printk( KERN_ALERT Removing bond module\n); } just above is a clean up module when driver exits or unloads int bond_open(struct inode *inode, struct file *filp) { return 0; } will be needed when a process opens the file int bond_release(struct inode *inode, struct file *filp) { return 0; } when releasing device driver ssize_t bond_read(struct file *filp, char *buf, size_t count, loff_t *f_pos) { copy_to_user(buf,bond_buffer,count14 ? count:14); This function works as given here http://www.gnugeneration.com/mirrors/kernel-api/r4299.html and an example of this in the current kernel is linux-2.6/drivers/char/snsc.c they implemented a function scdrv_write I implemented bond_write both implementations are different do you people get that or still some lecture is missing. } ssize_t bond_write( struct file *filp, char *buf, size_t count, loff_t *f_pos) { copy_from_user(bond_buffer,buf,count14 ? count : 14); from the userspace buf copy the bytes whose total number is equal to count to bond_buffer return 1; } The above fundas and lectures do not work.You people give lectures or show attitude but only if the code works.
Re: character device driver reading only last character of buffer
On Sun, Sep 26, 2010 at 3:43 AM, Venkatram Tummala venkatram...@gmail.comwrote: Hey buddy, i took the module code in your first post modified it to make it work . I am attaching the code. It works on the latest kernel 2.6.35. If you are using any other kernel, you may have to change the file_operations function pointers (memory_read memory_write signatures) by looking at struct file_operations in include/linux/fs.h. Rest assured, the code does exactly what you want it do. I am also using 2.6.35 and it did not worked on my machine. echo -n somehing /dev/bond where as ls -l /dev/bond crw-rw-rw- 1 root root 60, 0 2010-09-26 09:32 /dev/bond exists. I see you modified the read and write functions and added __user to datatypes. more over here ssize_t memory_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos) { if (*f_pos != 0) return 0; copy_to_user(buf,memory_buffer,1); if(*f_pos == 0) *f_pos = *f_pos + 1; return 1; } you are always returning one byte on reading how can you say that the code will write complete thing on successful call of memory_read similarly on memory_write you are returning one byte where as I am trying to attempt to write more than one byte at one time if I give a string something it is 8 bytes so in that case memory_read will always return the number of bytes as 1 which I do not want. Since on my machine it gave me error so I am not in a position to verify what you are saying.
Re: copy_to_user() and copy_from_user(): confusing code
On Sat, Sep 25, 2010 at 11:06 PM, Chetan Nanda chetanna...@gmail.comwrote: as per my understanding (may be wrong), issue is not with the copy_to/from_user. May be with the return values from bond_read/write function. Drivers read/write should return the number of bytes read or written. Agreed that was a mistake in my code. On Sat, Sep 25, 2010 at 7:34 PM, Bond jamesbond.2...@gmail.com wrote: mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2a2f03b000 write(1, abcde, 5)= 1 write(1, bcde, 4) = 1 write(1, cde, 3) = 1 write(1, de, 2) = 1 write(1, e, 1)= 1 close(1)= 0 munmap(0x7f2a2f03b000, 4096)= 0 close(2)= 0 exit_group(0) = ? Can you say any thing about the strace log above as why did I got the above output.
Re: character device driver reading only last character of buffer
On Sun, Sep 26, 2010 at 3:43 AM, Venkatram Tummala venkatram...@gmail.comwrote: This will print the the last character of the string you wrote. If you would have read the thread from my first post printing the last character is not my objective I am trying to print the complete string. As a side note, please spare us all with all this non-sense. We have better things to do in our life. Please try your level best to understand things before asking the kernel mailing list. If this BS continues, i am afraid you will get yourself kicked out of the mailing list. Please do yourself a favour by not posting such crap. Venkatram Tummala Please read the thread before giving a lecture on kernel newbies.
Re: character device driver reading only last character of buffer
Your code /* Registering device */ result = register_chrdev(0, bond, bond_fops); registers the device with major number 0.Is that possible ? On Sun, Sep 26, 2010 at 10:16 AM, Bond jamesbond.2...@gmail.com wrote: On Sun, Sep 26, 2010 at 3:43 AM, Venkatram Tummala venkatram...@gmail.com wrote: This will print the the last character of the string you wrote. If you would have read the thread from my first post printing the last character is not my objective I am trying to print the complete string. As a side note, please spare us all with all this non-sense. We have better things to do in our life. Please try your level best to understand things before asking the kernel mailing list. If this BS continues, i am afraid you will get yourself kicked out of the mailing list. Please do yourself a favour by not posting such crap. Venkatram Tummala Please read the thread before giving a lecture on kernel newbies.
Re: error in a compiling simple character device driver
On Mon, Sep 20, 2010 at 3:31 PM, sri bskmo...@gmail.com wrote: Bond, that worked. But can you explain why that change worked? No I can not explain why did it worked.
character device driver reading only last character of buffer
I wrote a small hello world type of character device driver. When I type echo -n abcdef /dev/bond and do a cat /dev/bond then only last f of above input abcdef is displayed rest nothing is displayed. I asked this question earlier and some people suggested me some modifications I have done and experimented all that but I am unable to catch the error. Can some one point out the error? Here is the code /* Necessary includes for device drivers */ #include linux/init.h //#include linux/config.h #include linux/module.h #include linux/kernel.h /* printk() */ #include linux/slab.h /* kmalloc() */ #include linux/fs.h /* everything... */ #include linux/errno.h /* error codes */ #include linux/types.h /* size_t */ #include linux/proc_fs.h #include linux/fcntl.h /* O_ACCMODE */ #include asm/system.h /* cli(), *_flags */ #include asm/uaccess.h /* copy_from/to_user */ MODULE_LICENSE(Dual BSD/GPL); /* Declaration of memory.c functions */ int memory_open(struct inode *inode, struct file *filp); int memory_release(struct inode *inode, struct file *filp); ssize_t memory_read(struct file *filp, char *buf, size_t count, loff_t *f_pos); ssize_t memory_write(struct file *filp, char *buf, size_t count, loff_t *f_pos); void memory_exit(void); int memory_init(void); /* Structure that declares the usual file */ /* access functions */ struct file_operations memory_fops = { read: memory_read, write: memory_write, open: memory_open, release: memory_release }; /* Declaration of the init and exit functions */ module_init(memory_init); module_exit(memory_exit); /* Global variables of the driver */ /* Major number */ int memory_major = 60; /* Buffer to store data */ char *memory_buffer; int memory_init(void) { int result; /* Registering device */ result = register_chrdev(memory_major, bond, memory_fops); if (result 0) { printk(KERN_ALERT memory: cannot obtain major number %d\n, memory_major); return result; } /* Allocating memory for the buffer */ memory_buffer = kmalloc(1, GFP_KERNEL); if (!memory_buffer) { result = -ENOMEM; goto fail; } memset(memory_buffer, 0, 10); printk(KERN_ALERT Inserting bond module\n); return 0; fail: memory_exit(); return result; } void memory_exit(void) { /* Freeing the major number */ unregister_chrdev(memory_major, bond); /* Freeing buffer memory */ if (memory_buffer) { kfree(memory_buffer); } printk( KERN_ALERT Removing bond module\n); } int memory_open(struct inode *inode, struct file *filp) { /* Success */ return 0; } int memory_release(struct inode *inode, struct file *filp) { /* Success */ return 0; } ssize_t memory_read(struct file *filp, char *buf, size_t count, loff_t *f_pos) { /* Transfering data to user space */ copy_to_user(buf,memory_buffer,10); /* Changing reading position as best suits */ if (*f_pos == 0) { *f_pos+=1; return 1; } else { return 0; } } ssize_t memory_write( struct file *filp, char *buf, size_t count, loff_t *f_pos) { char *tmp; tmp=buf+count-1; copy_from_user(memory_buffer,tmp,10); return 1; }
Re: copy_to_user() and copy_from_user(): confusing code
Even I am facing the same so some one can elaborate a bit. On Thu, Sep 23, 2010 at 11:56 PM, mohit verma mohit89m...@gmail.com wrote: hi all, i many times tried to understand the coding of copy_to_user() and copy_from_user() functions (frequently used in kernel ). but each time at get stuck at the assembly coding. can someone elaborate on this section ,please?
Re: character device driver reading only last character of buffer
On Thu, Sep 23, 2010 at 11:47 PM, Carlo Caione carlo.cai...@gmail.com wrote: Have you ever used malloc() in user space? Man, I don't want to be rude, but what you need is to code in user space before putting your hands in kernel space. Since you mentioned so I am posting a program this uses malloc.You can see it,I have myself checked and it is working. You do show the attitude but it would be good if you show some attitude on the code I posted. #include stdio.h #include stdlib.h struct node { struct node *next, *prev; int data; } *start, *prv; void add_element(int e); void read_list (); static int j = 0; int main() { int i, element, choice; choice = 1; struct node *temp; start = NULL; while (choice == 1) { printf(What do you want 0 exit 1 to add\n); scanf(%d, choice); if (choice == 0) break; printf(Enter data to be entered\n); scanf(%d, element); add_element(element); } read_list(); } void add_element(int e) { // printf(\n printing from function %d\n, e); struct node *temp; if (j == 0) { start = (struct node *)malloc(sizeof(struct node)); start-data = e; //printf(the data entered is %d \n, start-data); prv=start;//is necessary since in otherwise case prv is pointing to some garbage value } if(j!=0){ temp = (struct node *)malloc(sizeof(struct node)); temp-data = e; prv-next = temp; temp-next=NULL; prv=temp;//since prv is global pointer if I do not do this step then next time when new memory is allocated prv is still pointing to start or previous pointer what ever the value was so new temp declaration will not have much effect } j++; } void read_list() { struct node *temp; temp = start; while (temp) { printf( %d -- , temp-data); temp = temp-next; } } On Thu, Sep 23, 2010 at 11:58 PM, Manish Katiyar mkati...@gmail.com wrote: Did you really want to allocate 1 byte ? if (!memory_buffer) { result = -ENOMEM; goto fail; } memset(memory_buffer, 0, 10); And then write 10 bytes on it without expecting to cause corruptions ? I had made that change that you said but it had not worked. On Fri, Sep 24, 2010 at 12:19 AM, Greg Freemyer greg.freem...@gmail.com wrote: I'm putting you in my autodelete list, so I won't be responding to you again. You are free to put where ever you want but it would be good if you show your attitude on code not on me. This is a newbie list and no one can stop us from asking if we are in problem there are much better people here than you. On Fri, Sep 24, 2010 at 12:34 AM, Bond jamesbond.2...@gmail.com wrote: I changed that part /* Necessary includes for device drivers */ #include linux/init.h //#include linux/config.h #include linux/module.h #include linux/kernel.h /* printk() */ #include linux/slab.h /* kmalloc() */ #include linux/fs.h /* everything... */ #include linux/errno.h /* error codes */ #include linux/types.h /* size_t */ #include linux/proc_fs.h #include linux/fcntl.h /* O_ACCMODE */ #include asm/system.h /* cli(), *_flags */ #include asm/uaccess.h /* copy_from/to_user */ MODULE_LICENSE(Dual BSD/GPL); /* Declaration of memory.c functions */ int memory_open(struct inode *inode, struct file *filp); int memory_release(struct inode *inode, struct file *filp); ssize_t memory_read(struct file *filp, char *buf, size_t count, loff_t *f_pos); ssize_t memory_write(struct file *filp, char *buf, size_t count, loff_t *f_pos); void memory_exit(void); int memory_init(void); /* Structure that declares the usual file */ /* access functions */ struct file_operations memory_fops = { read: memory_read, write: memory_write, open: memory_open, release: memory_release }; /* Declaration of the init and exit functions */ module_init(memory_init); module_exit(memory_exit); /* Global variables of the driver */ /* Major number */ int memory_major = 60; /* Buffer to store data */ char *memory_buffer; int memory_init(void) { int result; /* Registering device */ result = register_chrdev(memory_major, bond, memory_fops); if (result 0) { printk(KERN_ALERT memory: cannot obtain major number %d\n, memory_major); return result; } /* Allocating memory for the buffer */ memory_buffer = kmalloc(10, GFP_KERNEL); if (!memory_buffer) { result = -ENOMEM; goto fail; } memset(memory_buffer, 0, 10); printk(KERN_ALERT Inserting bond module\n); return 0; fail: memory_exit(); return result; } void memory_exit(void) { /* Freeing the major number */ unregister_chrdev(memory_major, bond); /* Freeing buffer memory */ if (memory_buffer) { kfree(memory_buffer); } printk( KERN_ALERT Removing bond module\n); } int memory_open(struct inode *inode, struct file *filp) { /* Success
Re: character device driver reading only last character of buffer
I changed that part /* Necessary includes for device drivers */ #include linux/init.h //#include linux/config.h #include linux/module.h #include linux/kernel.h /* printk() */ #include linux/slab.h /* kmalloc() */ #include linux/fs.h /* everything... */ #include linux/errno.h /* error codes */ #include linux/types.h /* size_t */ #include linux/proc_fs.h #include linux/fcntl.h /* O_ACCMODE */ #include asm/system.h /* cli(), *_flags */ #include asm/uaccess.h /* copy_from/to_user */ MODULE_LICENSE(Dual BSD/GPL); /* Declaration of memory.c functions */ int memory_open(struct inode *inode, struct file *filp); int memory_release(struct inode *inode, struct file *filp); ssize_t memory_read(struct file *filp, char *buf, size_t count, loff_t *f_pos); ssize_t memory_write(struct file *filp, char *buf, size_t count, loff_t *f_pos); void memory_exit(void); int memory_init(void); /* Structure that declares the usual file */ /* access functions */ struct file_operations memory_fops = { read: memory_read, write: memory_write, open: memory_open, release: memory_release }; /* Declaration of the init and exit functions */ module_init(memory_init); module_exit(memory_exit); /* Global variables of the driver */ /* Major number */ int memory_major = 60; /* Buffer to store data */ char *memory_buffer; int memory_init(void) { int result; /* Registering device */ result = register_chrdev(memory_major, bond, memory_fops); if (result 0) { printk(KERN_ALERT memory: cannot obtain major number %d\n, memory_major); return result; } /* Allocating memory for the buffer */ memory_buffer = kmalloc(10, GFP_KERNEL); if (!memory_buffer) { result = -ENOMEM; goto fail; } memset(memory_buffer, 0, 10); printk(KERN_ALERT Inserting bond module\n); return 0; fail: memory_exit(); return result; } void memory_exit(void) { /* Freeing the major number */ unregister_chrdev(memory_major, bond); /* Freeing buffer memory */ if (memory_buffer) { kfree(memory_buffer); } printk( KERN_ALERT Removing bond module\n); } int memory_open(struct inode *inode, struct file *filp) { /* Success */ return 0; } int memory_release(struct inode *inode, struct file *filp) { /* Success */ return 0; } ssize_t memory_read(struct file *filp, char *buf, size_t count, loff_t *f_pos) { /* Transfering data to user space */ copy_to_user(buf,memory_buffer,count10 ? count:10); /* Changing reading position as best suits */ /* if (*f_pos == 0) { *f_pos+=1; return 1; } else { return 0; }*/ } ssize_t memory_write( struct file *filp, char *buf, size_t count, loff_t *f_pos) { char *tmp; copy_from_user(memory_buffer,tmp,count10 ? count : 10); return 1; } The above also did not worked when I had posted this in the first post I have changed kmalloc and copy_from_user, copy_to_user as some of you above have suggested to have a buffer size type of thing but it also did not worked.
what are various files in /sys/bus/pci/devices/0000:00:00.0
What is the meaning of various files in directory /sys/bus/pci/devices/:00:00.0 broken_parity_status config driver firmware_node local_cpulist modalias numa_node remove resource subsystem_device uevent class device enable irqlocal_cpus msi_bus power rescan subsystem subsystem_vendor vendor in LKN only vendor and device fields have been explained.
Re: my driver is dropping characters
On Wed, Sep 15, 2010 at 10:34 PM, matthias mensch0...@googlemail.comwrote: Hi, the problem is your bond_buffer and how you handle read and writes from it. (see below) Hi thanks I have read and re read the code and many other man pages from internet. ssize_t bond_read(struct file *filp, char *buf, size_t count, loff_t *f_pos) { /* Transfering data to user space */ copy_to_user(buf,bond_buffer,1); you just copy one byte to the buffer instead of count. Yes you are right here but I am not getting as how do I get the exact location from where I will copy data from kernel space to user space. /* Changing reading position as best suits */ if (*f_pos == 0) { *f_pos+=1; return 1; } else { return 0; } }; ssize_t bond_write(struct file *filp, char *buf, size_t count, loff_t *f_pos) { char *tmp; tmp=buf+count-1; copy_from_user(bond_buffer,tmp,1); you just copy the last byte from buf (buf+count-1) to your bond_buffer. you should copy count bytes, starting by buf. Right I am not clear as how will I get the location of the region where user has written some thing in the above error you pointed out so that I can copy the complete characters you mentioned.
Re: my driver is dropping characters
On Sat, Sep 18, 2010 at 8:17 PM, Greg Freemyer greg.freem...@gmail.comwrote: Stealing someone's analogy, it's like race car mechanics discussing the finer points of setting up the fuel injection system and you're asking What is fuel injection anyway? Ha ha that was quite nice explanation.Any way. I did try to read man page of kmalloc but there is no man entry for that.
Re: my driver is dropping characters
On Sat, Sep 18, 2010 at 8:17 PM, Greg Freemyer greg.freem...@gmail.comwrote: your first problem is you only have a 1 char buffer, so until you fix that, the rest has no chance of working. bond_buffer = kmalloc(1, GFP_KERNEL); Ok I got your point have Googled this and got some relevant thing. Had read about it in LDD chapter 3.
Re: where is usb_interface defined
On Sun, Sep 19, 2010 at 2:23 AM, Bond jamesbond.2...@gmail.com wrote: On Sun, Sep 19, 2010 at 12:35 AM, Greg KH g...@kroah.com wrote: I suggest you use a tool like 'grep', 'ack', 'cgvg', 'ctags', or 'cscope' for future questions like this. They are all good at finding I have used csope but what to search that I am not clear. For example on that page you used a function dev_info http://www.kroah.com/linux/talks/ols_2005_driver_tutorial/mgp00010.html I used cscope and got at least 28 lines not sure if struct dev_info { mdk_rdev_t *rdev; sector_tend_sector; }; is the structure you are pointing to. I have read your book LDD first 5 chapters and still reading more. Is this dev in your presentation same as described in your book.
my driver is dropping characters
I wrote my hello world type of character device driver.(First driver that I wrote) I created a device as follows mknod /dev/bond c 60 0 and then tried to write something to that device as follows echo -n abcde /dev/bond cat /dev/bond will show me the last e of entered abcde above but will drop abcd. I can see the last character which was passed on to as argument to echo but not the previous characters. Any idea what improvement should I make. Here is the code. #include linux/init.h #include linux/module.h #include linux/kernel.h /* printk() */ #include linux/slab.h /* kmalloc() */ #include linux/fs.h /* everything... */ #include linux/errno.h /* error codes */ #include linux/types.h /* size_t */ #include linux/proc_fs.h #include linux/fcntl.h /* O_ACCMODE */ #include asm/system.h /* cli(), *_flags */ #include asm/uaccess.h /* copy_from/to_user */ /* Declaration of memory.c functions */ int bond_open(struct inode *inode, struct file *filp) { return 0;}; int bond_release(struct inode *inode, struct file *filp){ return 0;}; ssize_t bond_read(struct file *filp, char *buf, size_t count, loff_t *f_pos) { /* Transfering data to user space */ copy_to_user(buf,bond_buffer,1); /* Changing reading position as best suits */ if (*f_pos == 0) { *f_pos+=1; return 1; } else { return 0; } }; ssize_t bond_write(struct file *filp, char *buf, size_t count, loff_t *f_pos) { char *tmp; tmp=buf+count-1; copy_from_user(bond_buffer,tmp,1); return 1; } ; void bond_exit(void); int bond_init(void); /* Structure that declares the usual file */ /* access functions */ struct file_operations bond_fops = { read: bond_read, write: bond_write, open: bond_open, release: bond_release }; /* Global variables of the driver */ /* Major number */ int bond_major = 60; /* Buffer to store data */ char *bond_buffer; static int bond_init(void) { printk(1 Hello bond new driver!\n); int result; /* Registering device */ result = register_chrdev(bond_major, bond, bond_fops); if (result 0) { printk( 1memory: cannot obtain major number %d\n, bond_major); return result; } /* Allocating memory for the buffer */ bond_buffer = kmalloc(1, GFP_KERNEL); if (!bond_buffer) { result = -ENOMEM; goto fail; } memset(bond_buffer, 0, 1); printk(1Inserting bond module\n); return 0; fail: bond_exit(); return result; return 0; } static void bond_exit(void) { printk(1 Bye, bond world\n); /* Freeing the major number */ unregister_chrdev(bond_major, bond); /* Freeing buffer memory */ if (bond_buffer) { kfree(bond_buffer); } printk(1Removing bond module\n); } module_init(bond_init); module_exit(bond_exit);
Re: question about linked list implementation in kernel.h
On Tue, Sep 14, 2010 at 1:27 AM, Jan Ceuleers jan.ceule...@computer.orgwrote: On 11/09/10 17:49, Bond wrote: (type *)( (char *)__mptr - offsetof(type,member) );}) there a subtraction has been done why is this subtraction done? Not having read any of the documentation, what comes to mind is this: if __mptr is a pointer to the member of a structure, the above expression returns a pointer to the first byte of the containing structure, typecast to the type of the structure. Example: typedef struct { int a; char b; } test_t; test_t test; Now assume that __mptr is a pointer to test.b, then the above expression returns a pointer to test, i.e. a pointer to the structure that b is a member of. Jan Hi, Jan no problem I am clear with the original question that I had asked with Manohar.
Re: adding semaphores to my device driver
On Tue, Sep 14, 2010 at 10:31 PM, Greg Freemyer greg.freem...@gmail.comwrote: I think a mutex will do what you need. Have you looked at: Documentation/mutex-design.txt You should find the Documentation folder at the top level of your kernel source tree. The mutex calls are at the bottom of the file. Ok. Look around at the kernel source for some example uses. Especially where to call mutex_init(). You obviously don't want to call that in your write() routine. Why not in write routine? I discussed this thing with a friend he suggested to implement this in write routine() .
Re: difference between read permission and executing permission
On Sat, Sep 11, 2010 at 10:58 PM, Parmenides mobile.parmeni...@gmail.comwrote: Hi, For a specified directory, we can go through it when the kernel parsing path, though we can not read it. Hi can you be a bit more elaborate on this part I am also trying to understand what you asked.
Re: usb driver binding to the device
On Sat, Sep 11, 2010 at 11:31 PM, Josh Cartwright jo...@linux.com wrote: To 'bind' to a device means that your driver is asserting control of the device. You mean to say the driver is trying to take control of the device. On the previous slide, a USB device ID table was created that lists the IDs of the devices the driver supports. Do you mean to say that it is possible that same driver support multiple devices? I have no clue of it. When your driver registers to the USB core (via usb_register()), Can you point me which slide in the presentation I gave link is meaning this type of thing. the core code looks at the list of unclaimed devices and your provided ID table and calls your probe() for any matches. Your probe() callback is responsible for returning 0 if it wants to 'bind' to the device, otherwise you return an error. Is 0 for success. I see a structure static struct usb_driver { .owner : .name : .probe : .disconnect : .id_connect : } I am not clear as how this structure has mapped to functions. What my understanding of writing a device driver till now from my search on Internet is reserve a set of major and minor number define a file_operations structure associating to function pointers we need to define operations corresponding to system calls an application can apply if I were to take above three points then on the link http://www.kroah.com/linux/talks/ols_2005_driver_tutorial/index.html which slide is doing that?
Re: question about linked list implementation in kernel.h
On Sat, Sep 11, 2010 at 10:09 PM, Manish Katiyar mkati...@gmail.com wrote: If you want some more details about this macro. http://www.spinics.net/lists/linux-usb-devel/msg11766.html Thanks but Manohars explanation was perfect for newbies like me.
Re: usb driver binding to the device
On Sun, Sep 12, 2010 at 9:21 PM, Josh Cartwright jo...@linux.com wrote: Again, you can look through the slides. Also you should read LDD3, as it covers alot of your questions. I am reading that book. That book does talk about having a high level driver which is an interface to the system calls but it does not talks about Bus Star operations such as with different IO controllers on different architectures.
hello world module error
I created a small hello world module for programming make -C /lib/modules/2.6.32-24-generic/build M=/home/bond/rrr modules make[1]: Entering directory `/usr/src/linux-headers-2.6.32-24-generic' make[1]: *** No rule to make target `rrr'. Stop. make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-24-generic' make: *** [build] Error 2 what could be the error following is Makefile ifeq ($(KERNELRELEASE),) KERNELDIR ?= /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) .PHONY: build clean build: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules clean: rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c rm -rf modules.order Module.symvers else $(info Building with KERNELRELEASE =${KERNELRELEASE}) obj-m := program.o endif and following is the program /* Necessary includes for device drivers */ #include linux/init.h #include linux/module.h #include linux/kernel.h /* printk() */ static int bond_init(void) { printk(KERN_ALERT Hello, world\n); return 0; } static void bond_exit(void) { printk (KERN_ALERT Good by cruel world\n); } module_init(bond_init); module_exit(bond_exit); MODULE_AUTHOR(bond); MODULE_LICENSE(GPL);
Re: a problem in a character driver code
Ok by now I have been able to fix this problem. 1) config.h has been dropped from 2.6.19 series of kernels so that was one error 2) the program was kept in a directory whose directory name had a blank space in between this was also giving me errors 3) I had tried the functions with my name rather than memory_open,memory_read,memory_release I am not clear if this type of use is wrong. On Sun, Sep 12, 2010 at 7:52 PM, Bond jamesbond.2...@gmail.com wrote: = /* Necessary includes for device drivers */ #include linux/init.h #include linux/config.h config.h has been dropped from 2.6.19 series of kernels so that was one error #include linux/module.h #include linux/kernel.h /* printk() */ #include linux/slab.h /* kmalloc() */ #include linux/fs.h /* everything... */ #include linux/errno.h /* error codes */ #include linux/types.h /* size_t */ #include linux/proc_fs.h #include linux/fcntl.h /* O_ACCMODE */ #include asm/system.h /* cli(), *_flags */ #include asm/uaccess.h /* copy_from/to_user */ /* Declaration of memory.c functions */ int bond_open(struct inode *inode, struct file *filp) { return 0;}; I had tried the functions with my name rather than memory_open,memory_read,memory_release I am not clear if this type of use is wrong. The driver is working but it if I do echo -n abcdefg /dev/memory then on doing cat /dev/memory only last g is coming and all previous words which I gave abcdef are dropped out any idea on what might be the error.
Re: hello world module error
On Mon, Sep 13, 2010 at 6:47 AM, Mulyadi Santosa mulyadi.sant...@gmail.comwrote: to dig further by your own. Hint: use make V=1 yes the directory name had a blank space
question about linked list implementation in kernel.h
I read I was going through include/linux/kernel.h encountered following code #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)-member ) *__mptr = (ptr);\ in above code I am not clear with (type *)0 how is it working any link?
Re: question about linked list implementation in kernel.h
On Sat, Sep 11, 2010 at 6:22 PM, Carlo Caione carlo.cai...@gmail.comwrote: First link on google: Its not that I had not searched it did search but I had searched typedef and type and I kept reading links related to that only. What to be searched is not that obvious when some one is not clear. http://www.kroah.com/log/linux/container_of.html Any how thanks for link.
Re: question about linked list implementation in kernel.h
On Sat, Sep 11, 2010 at 6:22 PM, Carlo Caione carlo.cai...@gmail.comwrote: http://www.kroah.com/log/linux/container_of.html I am not able to understand a single bit of the explanaition on the above link. They have assumed I programmed PCI buses which I have not.
usb driver binding to the device
Hi, I was going through a tutorial given here http://www.kroah.com/linux/talks/ols_2005_driver_tutorial/mgp00010.html I could not understand what did it means to bind to device as it is shown in this function on above link.
Re: question about linked list implementation in kernel.h
On Sat, Sep 11, 2010 at 9:12 PM, Bond jamesbond.2...@gmail.com wrote: http://crashcourse.ca/introduction-linux-kernel-programming/intermission-lets-talk-about-linked-lists-and-containerof-free Robert (type *)( (char *)__mptr - offsetof(type,member) );}) there a subtraction has been done why is this subtraction done? Manohar I am going through your doc.
Re: question about linked list implementation in kernel.h
On Sat, Sep 11, 2010 at 9:15 PM, Manohar Vanga manohar.va...@gmail.comwrote: I just made a small example (with comments) to play around with :-) Let me know if you feel something is wrong in my explanations (I'm still learning as well!) Hope it helps! Manohar I just happen to understand great great work man.It is clear completely. Awesome explanation I am copy pasting from the file you gave I hope you don't mind. #include stdio.h #include stdlib.h #define offsetof(TYPE, MEMBER) ((size_t) ((TYPE *)0)-MEMBER) /* * The first line gets the type of the member inside the structure. It does * this by casting a NULL pointer to the structure type and using the GCC * typeof() extension. * * The second line evaluates to a value of the address of the containing * structure. This is done using the value of the member pointer and * subtracting the offset of the member from its own address. * * eg. if a member is at address 10 and is at an offset of 4 bytes into * the struture, the containing structure's pointer is at address (10 - 4) = 6 */ #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)-member ) *__mptr = (ptr);\ (type *)( (char *)__mptr - offsetof(type,member) );}) struct test { int a; }; /* * Given the pointer to a member inside a structure, retreive its containing * structure pointer */ void test_func(int *ptr) { /* You can see the output of this macro using: gcc -E cont.c */ struct test *container = container_of(ptr, struct test, a); printf(Retreived pointer: %x\n, (unsigned int)container); printf(Value: %d\n, container-a); } int main() { struct test *t = malloc(sizeof(struct test)); t-a = 5; printf(Structure pointer: %x\n, (unsigned int)t); printf(Value: %d\n, t-a); test_func(t-a); free(t); /* * This is how a block is evaluated to a value (explains how the macro * works. See output from gcc -E cont.c. */ int val = ({5 + 5;}); printf(Block value: %d\n, val); }
Re: knowledge sharing
On Fri, Sep 10, 2010 at 10:34 AM, Michael Blizek mic...@michaelblizek.twilightparadox.com wrote: I would recommend to make yourself familiar with some topics (non exhaustive): - in Documentation/ read CodingStyle, ManagementStyle, SubmittingPatches - locking: spinlock, mutex, atomic ops - interrupt context, sleepable context, syscall context (+copy_{from|to}_user) - workqueues, timer, delayed_work - kmem_cache (also known as slab cache): do to create caches and allocate memory - kref - struct list_head, offset_of, container_of - take a look at http://kernelnewbies.org/KernelHackingTools and http://lxr.linux.no/ - If you are interested in some low-level x86 details, go to developer.amd.com , Docs Articles, Developer Guides Manuals, Manuals and look at AMD64 Architecture Programmer's Manual Volume 2: System Programming - lwn.net, especially the kernel page of the weekly edition, to get informed on what is going on; New articles are subscriber-only for 1 week. Then look at some projects which look interesting. Open the code and try to understand. When you find something that you think can need your help, ask if you can participate. -Michi -- That was a good list.
Re: Integer Division on 32 Bit Machines
On Fri, Sep 10, 2010 at 10:08 AM, arshad hussain arshad.su...@gmail.comwrote: I agree with Silesh 100% here. Thanks. Rather than agreeing with Silesh show some real suggestion to original posters question. I have a habit of understanding what other people ask and try to understand what they have problem.
Re: knowledge sharing
I am not asking to teach C programming or user space programming or even device driver programming. Please read the first post to understand what I asked.
Re: knowledge sharing
On Thu, Sep 9, 2010 at 11:44 AM, Anuz Pratap Singh Tomar chambilketha...@gmail.com wrote: I am just trying to help,. and I understand what you are asking completely. but nevermind. Sure thanks.
Re: knowledge sharing
On Thu, Sep 9, 2010 at 12:01 PM, Tayade, Nilesh nilesh.tay...@netscout.comwrote: There is a lot of material available opensource. That exactly is the problem.Which one to read and which one not to read. To be able to search some thing you need to be aware of what to be searched. And then practice. practice what? Suppose I decided I want to write a driver for my monitor of my computer. Now will that be some thing good to start with. I just want to know some thing kick off.
Re: regarding do_irq
On Thu, Sep 9, 2010 at 12:04 PM, Dave Hylands dhyla...@gmail.com wrote: The kernel has the notion of going idle. This happens whenever there is nothing to do. Hi Dave from your message I want to ask going idle suppose I am having a Linux box on my system. Then display manager,polling and other things are constantly happening which are being handled by the CPU so when does the kernel goes idle I am not able to understand how can kernel be idle.
Re: knowledge sharing
On Thu, Sep 9, 2010 at 11:30 AM, Anuz Pratap Singh Tomar chambilketha...@gmail.com wrote: Finish all exercises of KnR. Have you yourself done that. pick up practical C programming book learn some user space programming My question is not about C programming. using either Robert love's book Did you ever read that book? get source code of older kernels say 1.0 and look into it or may be get Tannebaum's minix book: not may people will agree to this, but i find this book very useful. Even I do not agree.
Re: knowledge sharing
On Thu, Sep 9, 2010 at 12:39 PM, Tayade, Nilesh nilesh.tay...@netscout.comwrote: I just want to know some thing kick off. Suggestion - google. Something to kick off- start from what operating system really is. No please suggest some thing I am not clear with starting to what do I start with.
Re: knowledge sharing
On Thu, Sep 9, 2010 at 12:44 PM, Mulyadi Santosa mulyadi.sant...@gmail.comwrote: On Thu, Sep 9, 2010 at 13:54, Bond jamesbond.2...@gmail.com wrote: Sure thanks. Try to join kernel janitor ... Thanks for the link http://sourceforge.net/projects/kernel-janitor/ http://sourceforge.net/projects/kernel-janitor/
Re: regarding do_irq
On Thu, Sep 9, 2010 at 1:10 PM, Dave Hylands dhyla...@gmail.com wrote: Well, check your CPU usage. It's probably less than 100%. Let's say it's at 46%. That means that the system is spending 54% of its time doing nothing or being idle. From a macroscopic level, it looks like the CPU is busy. But from a microscopic level, the kernel is spending 540 millseconds out of every second waiting for something to happen. Those 540 milliseconds are when the kernel is idle. -- Dave Hylands Shuswap, BC, Canada http://www.DaveHylands.com/ Thanks .