~ubuntu-core-dev/ubuntu/natty/grub2/natty

« back to all changes in this revision

Viewing changes to debian/hwmatch.lua

  • Committer: Colin Watson
  • Date: 2011-03-30 00:26:07 UTC
  • Revision ID: cjwatson@canonical.com-20110330002607-579c4te8aqjrrbd7
Rewrite hwmatch.lua in C.  Drop lua grub-extras module.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!lua
2
 
 
3
 
matches_file = grub.getenv("matches_file")
4
 
class_match = tonumber(grub.getenv("class_match"))
5
 
 
6
 
match = 0
7
 
 
8
 
function test_device(bus, dev, func, pciid, subpciid, class)
9
 
   baseclass = bit.rshift(class, 24)
10
 
 
11
 
   if (class_match and class_match ~= baseclass) then return end
12
 
 
13
 
   vendor = bit.band(0xffff, pciid)
14
 
   device = bit.rshift(pciid, 16)
15
 
   subvendor = bit.band(0xffff, subpciid)
16
 
   subdevice = bit.rshift(subpciid, 16)
17
 
   subclass = bit.band(0xff, bit.rshift(class, 16))
18
 
 
19
 
   id = string.format("v%04xd%04xsv%04xsd%04xbc%02xsc%02x",
20
 
                      vendor,
21
 
                      device,
22
 
                      subvendor,
23
 
                      subdevice,
24
 
                      baseclass,
25
 
                      subclass)
26
 
 
27
 
   matches = grub.file_open(matches_file)
28
 
 
29
 
   while (not grub.file_eof(matches)) do
30
 
      line = grub.file_getline(matches)
31
 
      if (line ~= "" and string.find(id, string.format("^%s$", line))) then
32
 
         match = 1
33
 
         return 1
34
 
      end
35
 
   end
36
 
end
37
 
 
38
 
if (grub.file_exist(matches_file)) then
39
 
   grub.enum_pci(test_device)
40
 
end
41
 
 
42
 
grub.setenv("match", match)