From 5970bb5987be04dbc3498b264d14c7ef28194ad6 Mon Sep 17 00:00:00 2001 From: Russell King Date: Sun, 21 Oct 2012 15:07:10 +0100 Subject: Initial libbmm git checkin --- .gitignore | 27 ++ Android.mk | 36 +++ COPYRIGHT | 510 +++++++++++++++++++++++++++++++++++++ Makefile.am | 24 ++ autogen.sh | 5 + bmm_lib.c | 379 +++++++++++++++++++++++++++ bmm_lib.h | 100 ++++++++ bmm_lib.pmem.c | 287 +++++++++++++++++++++ bmm_test.c | 462 +++++++++++++++++++++++++++++++++ configure.ac | 39 +++ debian/changelog | 64 +++++ debian/compat | 1 + debian/control | 35 +++ debian/copyright | 26 ++ debian/libbmm-dev.install | 4 + debian/libbmm0u.install | 3 + debian/libbmm0u.postinst | 46 ++++ debian/libbmm0u.postinst.debhelper | 5 + debian/libbmm0u.postrm | 38 +++ debian/libbmm0u.postrm.debhelper | 5 + debian/rules | 34 +++ etc/init.d/bmm | 49 ++++ etc/udev/rules.d/99-bmm.rules | 1 + libbmm.pc.in | 9 + 24 files changed, 2189 insertions(+) create mode 100644 .gitignore create mode 100644 Android.mk create mode 100644 COPYRIGHT create mode 100644 Makefile.am create mode 100755 autogen.sh create mode 100644 bmm_lib.c create mode 100644 bmm_lib.h create mode 100644 bmm_lib.pmem.c create mode 100644 bmm_test.c create mode 100644 configure.ac create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/libbmm-dev.install create mode 100644 debian/libbmm0u.install create mode 100644 debian/libbmm0u.postinst create mode 100644 debian/libbmm0u.postinst.debhelper create mode 100644 debian/libbmm0u.postrm create mode 100644 debian/libbmm0u.postrm.debhelper create mode 100755 debian/rules create mode 100755 etc/init.d/bmm create mode 100644 etc/udev/rules.d/99-bmm.rules create mode 100644 libbmm.pc.in diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f56359b --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +.deps/ +.libs/ +Makefile +Makefile.in +aclocal.m4 +autom4te.cache/ +build-aux/ +config.log +config.status +configure +libtool +m4/ +*.lo +*.o +*.la +*.pc +bmm_test +debian/*.log +debian/*.substvars +debian/libbmm-dev/ +debian/libbmm0u/ +debian/libbmm0u-dbg/ +debian/tmp/ +debian/*.dirs +debian/*.shlibs +debian/*.symbols +debian/files diff --git a/Android.mk b/Android.mk new file mode 100644 index 0000000..5fba807 --- /dev/null +++ b/Android.mk @@ -0,0 +1,36 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +ifeq ($(BOARD_USE_PMEM_TO_SIMULATE_BMM), true) +LOCAL_SRC_FILES := \ + bmm_lib.pmem.c +else +LOCAL_SRC_FILES := \ + bmm_lib.c +endif + +LOCAL_MODULE := libbmm + +LOCAL_SHARED_LIBRARIES := libutils + +LOCAL_PRELINK_MODULE := false + +include $(BUILD_SHARED_LIBRARY) + +COMPILE_BMM_TEST := true + +ifeq ($(COMPILE_BMM_TEST), true) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + bmm_test.c + +LOCAL_MODULE := bmmtest + +LOCAL_SHARED_LIBRARIES += libbmm + +include $(BUILD_EXECUTABLE) + +endif diff --git a/COPYRIGHT b/COPYRIGHT new file mode 100644 index 0000000..2d2d780 --- /dev/null +++ b/COPYRIGHT @@ -0,0 +1,510 @@ + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations +below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it +becomes a de-facto standard. To achieve this, non-free programs must +be allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control +compilation and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at least + three years, to give the same user the materials specified in + Subsection 6a, above, for a charge no more than the cost of + performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply, and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License +may add an explicit geographical distribution limitation excluding those +countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms +of the ordinary General Public License). + + To apply these terms, attach the following notices to the library. +It is safest to attach them to the start of each source file to most +effectively convey the exclusion of warranty; and each file should +have at least the "copyright" line and a pointer to where the full +notice is found. + + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or +your school, if any, to sign a "copyright disclaimer" for the library, +if necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James + Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..e7fa10d --- /dev/null +++ b/Makefile.am @@ -0,0 +1,24 @@ +ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} +AM_CFLAGS = $(WARN_CFLAGS) + +libbmm_la_LTLIBRARIES = libbmm.la +libbmm_ladir = $(libdir) +libbmm_la_LDFLAGS = -avoid-version -no-undefined -shrext .so.@ABI_VERSION@ \ + -export-symbols-regex "bmm_*" +libbmm_la_SOURCES = bmm_lib.c + +libbmm_laincludedir = $(includedir) +libbmm_lainclude_HEADERS = bmm_lib.h + +pkgconfigdir = @pkgconfigdir@ +pkgconfig_DATA = libbmm.pc + +bin_PROGRAMS = bmm_test +bmm_test_SOURCES = bmm_test.c +bmm_test_LDADD = libbmm.la + +dataudevdir = @udevrulesdir@ +dataudev_DATA = etc/udev/rules.d/99-bmm.rules + +datainitdir = @initdir@ +datainit_DATA = etc/init.d/bmm diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..601ef8b --- /dev/null +++ b/autogen.sh @@ -0,0 +1,5 @@ +#!/bin/sh +aclocal +libtoolize +automake --add-missing +autoconf diff --git a/bmm_lib.c b/bmm_lib.c new file mode 100644 index 0000000..043c6c8 --- /dev/null +++ b/bmm_lib.c @@ -0,0 +1,379 @@ +/* + * bmm_lib.c + * + * Buffer Management Module + * + * User level BMM Defines/Globals/Functions + * + * Li Li (lea.li@marvell.com) + + *(C) Copyright 2007 Marvell International Ltd. + * All Rights Reserved + */ + +#include +#include +#include +#include +#include +#include + +#include "bmm_lib.h" + +//#define DEBUG + +#ifdef DEBUG + #define pr_debug(fmt, arg...) printf(fmt, ##arg) +#else + #define pr_debug(fmt, arg...) do { } while(0) +#endif + +static int bmm_fd = 0; + +int bmm_init() +{ + /* attempt to open the BMM driver */ + if(bmm_fd <= 0) + bmm_fd = open(BMM_DEVICE_FILE, O_RDWR); + + /* if the open failed, try to mount the driver */ + if(bmm_fd < 0 ) { + system("mknod /dev/bmm c 10 94\n"); + bmm_fd = open(BMM_DEVICE_FILE, O_RDWR); + } + + pr_debug("BMM device fd: %d", bmm_fd); + + return bmm_fd; +} + +void bmm_exit() +{ + if(bmm_fd > 0) + close(bmm_fd); + bmm_fd = 0; +} + +void *bmm_malloc(unsigned long size, int attr) +{ + int ret; + void *vaddr; + ioctl_arg_t io; + + if(size == 0) + return NULL; + + if(bmm_init() < 0) + return NULL; + + /* obsolete, only for back-compatible */ + if ((attr & BMM_ATTR_NONBUFFERABLE)&&(attr & BMM_ATTR_NONCACHEABLE)) + attr = BMM_ATTR_NONCACHED; + + if ((!(attr & BMM_ATTR_NONBUFFERABLE))&&(attr & BMM_ATTR_NONCACHEABLE)) + attr = BMM_ATTR_WRITECOMBINE; + + io.input = size; + io.output = 0; + io.arg = attr; + ret = ioctl(bmm_fd, BMM_MALLOC, &io); + if(ret < 0 || io.output == 0) + return NULL; + + pr_debug("bmm_malloc return paddr = 0x%08lx\n", io.output); + + vaddr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, bmm_fd, io.output); + return ((int)vaddr == -1) ? NULL : vaddr; +} + +void bmm_free(void *vaddr) +{ + unsigned long size; + ioctl_arg_t io; + + if(bmm_init() < 0) + return; + + size = bmm_get_mem_size(vaddr); + munmap(vaddr, size); + + io.input = (unsigned long)vaddr; + io.output = 0; + io.arg = 0; + ioctl(bmm_fd, BMM_FREE, &io); +} + +void *bmm_attach(void *paddr, unsigned long len) +{ + void *vaddr; + + if(len == 0) + return NULL; + + if(bmm_init() < 0) + return NULL; + + vaddr = mmap(0, len, PROT_READ | PROT_WRITE, MAP_SHARED, bmm_fd, (unsigned long)paddr); + + return ((int)vaddr == -1) ? NULL : vaddr; +} + +void bmm_detach(void *vaddr, unsigned long len) +{ + if(bmm_init() < 0) + return; + + munmap(vaddr, len); +} + +void *bmm_get_vaddr(void *paddr) +{ + int ret; + ioctl_arg_t io; + + if(bmm_init() < 0) + return NULL; + + io.input = (unsigned long)paddr; + io.output = 0; + io.arg = 0; + ret = ioctl(bmm_fd, BMM_GET_VIRT_ADDR, &io); + if(ret < 0) + return NULL; + + return (void *)io.output; +} + +void *bmm_get_kern_paddr(void *vaddr, unsigned long size) +{ + int ret; + ioctl_arg_t io; + + if(bmm_init() < 0) + return NULL; + + io.input = (unsigned long)vaddr; + io.length = (unsigned long)size; + io.output = 0; + io.arg = 0; + ret = ioctl(bmm_fd, BMM_GET_KERN_PHYS_ADDR, &io); + if(ret < 0) + return NULL; + + return (void *)io.output; +} + +void *bmm_get_paddr(void *vaddr) +{ + int ret; + ioctl_arg_t io; + + if(bmm_init() < 0) + return NULL; + + io.input = (unsigned long)vaddr; + io.output = 0; + io.arg = 0; + ret = ioctl(bmm_fd,BMM_GET_PHYS_ADDR, &io); + if(ret < 0) + return NULL; + + return (void *)io.output; +} + +unsigned long bmm_get_mem_size(void *vaddr) +{ + int ret; + ioctl_arg_t io; + + if(bmm_init() < 0) + return 0; + + io.input = (unsigned long)vaddr; + io.output = 0; + io.arg = 0; + ret = ioctl(bmm_fd,BMM_GET_MEM_SIZE, &io); + if(ret < 0) + return 0; + + return io.output; +} + +int bmm_get_mem_attr(void *vaddr) +{ + int ret; + ioctl_arg_t io; + + if(bmm_init() < 0) + return 0; + + io.input = (unsigned long)vaddr; + io.output = 0; + io.arg = 0; + ret = ioctl(bmm_fd, BMM_GET_MEM_ATTR, &io); + if(ret < 0) + return 0; + + return (int)io.output; +} + +int bmm_set_mem_attr(void *vaddr, int attr) +{ + int ret; + ioctl_arg_t io; + + if(bmm_init() < 0) + return 0; + + io.input = (unsigned long)vaddr; + io.output = 0; + io.arg = attr; + ret = ioctl(bmm_fd, BMM_SET_MEM_ATTR, &io); + if(ret < 0) + return 0; + + return (int)io.output; +} + +unsigned long bmm_get_total_space() +{ + int ret; + ioctl_arg_t io; + + if(bmm_init() < 0) + return 0; + + io.input = 0; + io.output = 0; + io.arg = 0; + ret = ioctl(bmm_fd, BMM_GET_TOTAL_SPACE, &io); + if(ret < 0) + return 0; + + return io.output; +} + +unsigned long bmm_get_free_space() +{ + int ret; + ioctl_arg_t io; + + if(bmm_init() < 0) + return 0; + + io.input = 0; + io.output = 0; + io.arg = 0; + ret = ioctl(bmm_fd, BMM_GET_FREE_SPACE, &io); + if(ret < 0) + return 0; + + return io.output; +} + +unsigned long bmm_get_allocated_space() +{ + int ret; + ioctl_arg_t io; + + if(bmm_init() < 0) + return 0; + + io.input = 0; + io.output = 0; + io.arg = 0; + ret = ioctl(bmm_fd, BMM_GET_ALLOCATED_SPACE, &io); + if(ret < 0) + return 0; + + return io.output; +} + +void bmm_flush_cache(void *vaddr, int dir) +{ + ioctl_arg_t io; + + if(bmm_init() < 0) + return; + + io.input = (unsigned long)vaddr; + io.output = 0; + io.arg = dir; + ioctl(bmm_fd, BMM_FLUSH_CACHE, &io); +} + +void *bmm_dma_memcpy(void *dest, const void *src, size_t n) +{ + int ret; + ioctl_arg_t io; + + if(bmm_init() < 0) + return 0; + + io.input = (unsigned long)src; + io.output = (unsigned long)dest; + io.length = (unsigned long)n; + io.arg = 0; + ret = ioctl(bmm_fd, BMM_DMA_MEMCPY, &io); + if(ret < 0) + return 0; + + return dest; +} + +void bmm_dma_sync() +{ + ioctl_arg_t io; + + if(bmm_init() < 0) + return; + + io.input = 0; + io.output = 0; + io.arg = 0; + ioctl(bmm_fd, BMM_DMA_SYNC, &io); +} + +void bmm_flush_cache_range(void *start, size_t size, int direction) +{ + ioctl_arg_t io; + + if(bmm_init() < 0) + return; + + io.input = (unsigned long)start; + io.length = size; + io.output = 0; + io.arg = direction; + ioctl(bmm_fd, BMM_CONSISTENT_SYNC, &io); +} + +void bmm_flush_user(void *start, long size, int direction) +{ + ioctl_arg_t io; + + if (bmm_init() < 0) + return; + if (size <= 0) + return; + + io.input = (unsigned long)start; + io.length = size; + io.output = 0; + io.arg = direction; + ioctl(bmm_fd, BMM_SYNC_USER, &io); +} + +void bmm_dump() +{ + ioctl_arg_t io; + + if(bmm_init() < 0) + return; + + io.input = 0; + io.output = 0; + io.arg = 0; + ioctl(bmm_fd, BMM_DUMP, &io); +} + diff --git a/bmm_lib.h b/bmm_lib.h new file mode 100644 index 0000000..56e4a3c --- /dev/null +++ b/bmm_lib.h @@ -0,0 +1,100 @@ +/* + * bmm_lib.h + * + * Buffer Management Module + * + * User level BMM Defines/Globals/Functions + * + * Li Li (lea.li@marvell.com) + + *(C) Copyright 2007 Marvell International Ltd. + * All Rights Reserved + */ + +#if !defined (__BMM_LIB_H__) +#define __BMM_LIB_H__ + +#define BMM_MINOR (94) + +typedef struct { + unsigned long input; /* the starting address of the block of memory */ + unsigned long output; /* the starting address of the block of memory */ + unsigned long length; /* the length of the block of memory */ + unsigned long arg; /* the arg of cmd */ +} ioctl_arg_t; + +#define BMEM_IOCTL_MAGIC 'G' +/* ioctl commands */ +#define BMM_MALLOC _IOWR(BMEM_IOCTL_MAGIC, 0, ioctl_arg_t) +#define BMM_FREE _IOWR(BMEM_IOCTL_MAGIC, 1, ioctl_arg_t) +#define BMM_GET_VIRT_ADDR _IOWR(BMEM_IOCTL_MAGIC, 2, ioctl_arg_t) +#define BMM_GET_PHYS_ADDR _IOWR(BMEM_IOCTL_MAGIC, 3, ioctl_arg_t) +#define BMM_GET_MEM_ATTR _IOWR(BMEM_IOCTL_MAGIC, 4, ioctl_arg_t) +#define BMM_SET_MEM_ATTR _IOWR(BMEM_IOCTL_MAGIC, 5, ioctl_arg_t) +#define BMM_GET_MEM_SIZE _IOWR(BMEM_IOCTL_MAGIC, 6, ioctl_arg_t) +#define BMM_GET_TOTAL_SPACE _IOWR(BMEM_IOCTL_MAGIC, 7, ioctl_arg_t) +#define BMM_GET_FREE_SPACE _IOWR(BMEM_IOCTL_MAGIC, 8, ioctl_arg_t) +#define BMM_FLUSH_CACHE _IOWR(BMEM_IOCTL_MAGIC, 9, ioctl_arg_t) +#define BMM_DMA_MEMCPY _IOWR(BMEM_IOCTL_MAGIC, 10, ioctl_arg_t) +#define BMM_DMA_SYNC _IOWR(BMEM_IOCTL_MAGIC, 11, ioctl_arg_t) +#define BMM_CONSISTENT_SYNC _IOWR(BMEM_IOCTL_MAGIC, 12, ioctl_arg_t) +#define BMM_DUMP _IOWR(BMEM_IOCTL_MAGIC, 13, ioctl_arg_t) +#define BMM_GET_ALLOCATED_SPACE _IOWR(BMEM_IOCTL_MAGIC, 14, ioctl_arg_t) +#define BMM_GET_KERN_PHYS_ADDR _IOWR(BMEM_IOCTL_MAGIC, 15, ioctl_arg_t) +#define BMM_SYNC_USER _IOWR(BMEM_IOCTL_MAGIC, 16, ioctl_arg_t) + + +/* ioctl arguments: memory attributes */ +#define BMM_ATTR_DEFAULT (0) /* cacheable bufferable */ +#define BMM_ATTR_WRITECOMBINE (1 << 0) /* non-cacheable & bufferable */ +#define BMM_ATTR_NONCACHED (1 << 1) /* non-cacheable & non-bufferable */ + +/* Note: extra attributes below are not supported yet! */ +#define BMM_ATTR_HUGE_PAGE (1 << 2) /* 64KB page size */ +#define BMM_ATTR_WRITETHROUGH (1 << 3) /* implies L1 Cacheable */ +#define BMM_ATTR_L2_CACHEABLE (1 << 4) /* implies L1 Cacheable */ + +/* obsolete */ +#define BMM_ATTR_NONBUFFERABLE (1 << 5) /* non-bufferable */ +#define BMM_ATTR_NONCACHEABLE (1 << 6) /* non-cacheable */ + +/* ioctl arguments: cache flush direction */ +#define BMM_DMA_BIDIRECTIONAL (0) /* DMA_BIDIRECTIONAL */ +#define BMM_DMA_TO_DEVICE (1) /* DMA_TO_DEVICE */ +#define BMM_DMA_FROM_DEVICE (2) /* DMA_FROM_DEVICE */ +#define BMM_DMA_NONE (3) /* DMA_NONE */ + +#define BMM_DEVICE_FILE "/dev/bmm" + +#if defined (__cplusplus) +extern "C" { +#endif + +int bmm_init(); +void bmm_exit(); +void *bmm_malloc(unsigned long size, int attr); +void bmm_free(void *vaddr); +void *bmm_attach(void *paddr, unsigned long len); +void bmm_detach(void *vaddr, unsigned long len); +void *bmm_get_vaddr(void *paddr); +void *bmm_get_paddr(void *vaddr); +void *bmm_get_kern_paddr(void *vaddr, unsigned long size); +int bmm_get_mem_attr(void *vaddr); +int bmm_set_mem_attr(void *vaddr, int attr); /* Not supported yet */ +unsigned long bmm_get_mem_size(void *vaddr); +unsigned long bmm_get_total_space(); +unsigned long bmm_get_free_space(); +unsigned long bmm_get_allocated_space(); +void bmm_flush_cache(void *vaddr, int dir); +void *bmm_dma_memcpy(void *dest, const void *src, size_t n); /* Obsolete */ +void bmm_dma_sync(); /* Obsolete */ +void bmm_flush_cache_range(void *start, size_t size, int direction); +void bmm_flush_user(void *start, long size, int direction); +void bmm_dump(); /* for debugging */ + +#if defined (__cplusplus) +} +#endif + +#endif /* __BMM_LIB_H__ */ + diff --git a/bmm_lib.pmem.c b/bmm_lib.pmem.c new file mode 100644 index 0000000..cb74a11 --- /dev/null +++ b/bmm_lib.pmem.c @@ -0,0 +1,287 @@ +/* + * bmm_lib.c + * + * Buffer Management Module for vMeta + * + * based on Android PMEM + * + * Steve Guo (steve.guo@marvell.com) + + *(C) Copyright 2007 Marvell International Ltd. + * All Rights Reserved + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define LOG_TAG "bmm-lib" +#include + +#include "bmm_lib.h" + +//#define DEBUG + +#ifdef DEBUG + #define pr_debug(fmt, arg...) LOGD(fmt, ##arg) +#else + #define pr_debug(fmt, arg...) do { } while(0) +#endif + +#define pr_error(fmt, arg...) LOGE(fmt, ##arg) +#define NO_IMPLEMENTED LOGE("%s is not implemented yet.", __FUNCTION__) + +#define PMEM_DEVICE_FILE "/dev/pmem_adsp" + + +/* We recorded all malloced physical address into a list. Due to the implementation of +pmem, we can only open a new file to malloc some memory and close it to free memory. So +we also record the opened fd associated with physical and virtual address map. */ +struct memory_item +{ + int fd; + void *paddr; + void *vaddr; + int size; + struct memory_item *next; +}; + +static struct memory_item *header = NULL; + +int bmm_init() +{ + pr_debug("bmm_init"); + header = NULL; + return 0; +} + +void bmm_exit() +{ + struct memory_item *cur = header; + struct memory_item *next = NULL; + pr_debug("bmm_exit"); + while(cur != NULL) + { + next = cur->next; + munmap(cur->vaddr, cur->size); + close(cur->fd); + free(cur); + cur = next; + } +} + +void *bmm_malloc(unsigned long size, int attr) +{ + void *vaddr; + int pmem_fd = 0; + struct memory_item *item = NULL; + struct pmem_region region; + int ret; + + if(size == 0) + return NULL; + + pr_debug("bmm_malloc %d", size); + + /* attempt to open the PMEM driver */ + pmem_fd = open(PMEM_DEVICE_FILE, O_RDWR); + if(pmem_fd <=0) + { + pr_error("cannot open %s file", PMEM_DEVICE_FILE); + return NULL; + } + + vaddr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, pmem_fd, 0); + if((int)vaddr == -1) + { + pr_error("mmap %d failed, most likely no memory", size); + close(pmem_fd); + return NULL; + } + + ret = ioctl(pmem_fd, PMEM_GET_PHYS, ®ion); + if(ret != 0) + { + pr_error("call PMEM_GET_PHYS failed"); + munmap(vaddr, size); + close(pmem_fd); + return NULL; + } + + item = (struct memory_item*)malloc(sizeof(struct memory_item)); + memset(item, 0 , sizeof(struct memory_item)); + item->fd = pmem_fd; + item->paddr = (void*)region.offset; + item->vaddr = vaddr; + item->size = size; + + if(header == NULL) + { + header = item; + } + else + { + item->next = header; + header = item; + } + return vaddr; +} + +void bmm_free(void *vaddr) +{ + pr_debug("bmm_free"); + struct memory_item *cur = header; + struct memory_item *prev = NULL; + struct memory_item *next = NULL; + while(cur != NULL) + { + next = cur->next; + if(cur->vaddr == vaddr) + { + munmap(cur->vaddr, cur->size); + close(cur->fd); + if(prev == NULL) + { + header = next; + } + else + { + prev->next = next; + } + free(cur); + return; + } + prev = cur; + cur = next; + } +} + +void *bmm_attach(void *paddr, unsigned long len) +{ + NO_IMPLEMENTED; + return NULL; +} + +void bmm_detach(void *vaddr, unsigned long len) +{ + NO_IMPLEMENTED; +} + +void *bmm_get_vaddr(void *paddr) +{ + pr_debug("bmm_get_vaddr"); + struct memory_item *cur = header; + while(cur != NULL) + { + if(cur->paddr == paddr) + return cur->vaddr; + cur = cur->next; + } + return NULL; +} + +void *bmm_get_paddr(void *vaddr) +{ + pr_debug("bmm_get_paddr"); + struct memory_item *cur = header; + while(cur != NULL) + { + if(cur->vaddr == vaddr) + return cur->paddr; + cur = cur->next; + } + return NULL; +} + +unsigned long bmm_get_mem_size(void *vaddr) +{ + struct memory_item *cur = header; + while(cur != NULL) + { + if(cur->vaddr == vaddr) + return cur->size; + cur = cur->next; + } + return 0; +} + +int bmm_get_mem_attr(void *vaddr) +{ + NO_IMPLEMENTED; + return 0; +} + +int bmm_set_mem_attr(void *vaddr, int attr) +{ + NO_IMPLEMENTED; + return 0; +} + +unsigned long bmm_get_total_space() +{ + int pmem_fd = 0; + struct pmem_region region; + int ret; + + /* attempt to open the PMEM driver */ + pmem_fd = open(PMEM_DEVICE_FILE, O_RDWR); + if(pmem_fd <=0) + { + pr_error("cannot open %s file", PMEM_DEVICE_FILE); + return 0; + } + + ret = ioctl(pmem_fd, PMEM_GET_TOTAL_SIZE, ®ion); + if(ret != 0) + { + pr_error("call PMEM_GET_TOTAL_SIZE failed"); + close(pmem_fd); + return 0; + } + close(pmem_fd); + return region.len; +} + +unsigned long bmm_get_free_space() +{ + NO_IMPLEMENTED; + return 0; +} + +unsigned long bmm_get_allocated_space() +{ + NO_IMPLEMENTED; + return 0; +} + +void bmm_flush_cache(void *vaddr, int dir) +{ + NO_IMPLEMENTED; +} + +void *bmm_dma_memcpy(void *dest, const void *src, size_t n) +{ + NO_IMPLEMENTED; + return NULL; +} + +void bmm_dma_sync() +{ + NO_IMPLEMENTED; +} + +void bmm_flush_cache_range(void *start, size_t size, int direction) +{ + NO_IMPLEMENTED; +} + +void bmm_dump() +{ + NO_IMPLEMENTED; +} + diff --git a/bmm_test.c b/bmm_test.c new file mode 100644 index 0000000..27b2dd1 --- /dev/null +++ b/bmm_test.c @@ -0,0 +1,462 @@ +/* + * bmm_test.c + * + * Buffer Management Module + * + * User test application + * + * Li Li (lea.li@marvell.com) + + *(C) Copyright 2007 Marvell International Ltd. + * All Rights Reserved + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "bmm_lib.h" + +static int debug = 0; + +int test_count = 0; +int pass_count = 0; +int fail_count = 0; + +#define PRINT_TEST_NAME printf("Testing %d: %s()\n", test_count++, __FUNCTION__) +#define PRINT_TEST_RESULT(x) \ + do { \ + if(!x) \ + pass_count++, printf("\tPassed.\n"); \ + else \ + fail_count++, printf("\tFailed.\n"); \ + } while(0) +#define PRINT_TEST_RESULTS() printf("Passed/Failed = %d/%d\n", pass_count, fail_count) + +int test_bmm_init() +{ + int ret; + + PRINT_TEST_NAME; + + ret = bmm_init(); + printf("\tbmm_init() return %d\n", ret); + + return (ret <= 0); +} + +int test_bmm_get_space() +{ + unsigned long total_size; + unsigned long free_size; + + PRINT_TEST_NAME; + + total_size = bmm_get_total_space(); + free_size = bmm_get_free_space(); + + printf("\tbmm_get_total_space() return %ldKB\n", total_size/1024); + printf("\tbmm_get_free_space() return %ldKB\n", free_size/1024); + + return (total_size <= 0 || total_size != free_size); +} + +int test_bmm_malloc(unsigned long size, int attr) +{ + void *vaddr; + unsigned long allocated_size1, free_size1; + unsigned long allocated_size2, free_size2; + unsigned long allocated_size3, free_size3; + int off = 0; + PRINT_TEST_NAME; + + allocated_size1 = bmm_get_allocated_space(); + free_size1 = bmm_get_free_space(); + vaddr = bmm_malloc(size, attr); + if(vaddr == NULL) { + printf("\tno enough memory\n"); + return -1; + } + for(off = 0; off < size; off += 1024*1024){ + void *get_paddr = bmm_get_paddr(vaddr+off); + void *get_vaddr = bmm_get_vaddr(get_paddr); + int get_attr = bmm_get_mem_attr(get_vaddr); + printf("\toff = 0x%x, vaddr=0x%p, get_vaddr=0x%p, get_paddr=0x%p\n", off, vaddr+off, get_vaddr, get_paddr); + printf("\tset_attr=0x%x, get_attr=0x%x\n", attr, get_attr); + if(vaddr+off != get_vaddr) + return -1; + } + + allocated_size2 = bmm_get_allocated_space(); + free_size2 = bmm_get_free_space(); + bmm_free(vaddr); + allocated_size3 = bmm_get_allocated_space(); + free_size3 = bmm_get_free_space(); + + printf("\tbmm_malloc(%ldKB) return 0x%08lx\n", size/1024, (unsigned long)vaddr); + printf("\tbmm_get_allocated_space() return %ldKB %ldKB %ldKB\n", + allocated_size1/1024, allocated_size2/1024, allocated_size3/1024); + printf("\tbmm_get_free_space() return %ldKB %ldKB %ldKB\n", + free_size1/1024, free_size2/1024, free_size3/1024); + + return ((int)vaddr <= 0 || + allocated_size2 - allocated_size1 != size || + allocated_size1 != allocated_size3 || + free_size1 - free_size2 != size || + free_size1 != free_size3); +} + +int test_bmm_dma_memcpy(unsigned long size) +{ + char *src; + char *dst; + unsigned long i; + unsigned long free_size1; + unsigned long free_size2; + unsigned long free_size3; + int ret = 0; + + PRINT_TEST_NAME; + + free_size1 = bmm_get_free_space(); + src = bmm_malloc(size, BMM_ATTR_DEFAULT); + dst = bmm_malloc(size, BMM_ATTR_DEFAULT); + memset(src, 0, size); + memset(dst, 0, size); + free_size2 = bmm_get_free_space(); + if(src == NULL) { + printf("\tno enough memory\n"); + return -1; + } + if(dst == NULL) { + printf("\tno enough memory\n"); + bmm_free(src); + return -2; + } + for(i=0; i 1) { + debug = 1; + if(!strcmp(argv[1], "dump")) { + ret = test_bmm_get_space(); + PRINT_TEST_RESULT(ret); + bmm_dump(); + return 0; + } + } + + printf("%s running with pid=%d/%x\n", argv[0], pid, pid); + + if(debug) + bmm_dump(); + + ret = test_bmm_init(); + PRINT_TEST_RESULT(ret); + + ret = test_bmm_get_space(); + PRINT_TEST_RESULT(ret); + + n = 8; + for(i=1; i<=n; i++) { + ret = test_bmm_malloc(i*1024*1024, BMM_ATTR_DEFAULT); + PRINT_TEST_RESULT(ret); + } + for(i=n; i>=1; i--) { + ret = test_bmm_malloc(i*1024*1024, BMM_ATTR_NONCACHED); + PRINT_TEST_RESULT(ret); + } + + n = 8; + for(i=1; i<=n; i++) { + ret = test_bmm_share(i*1024*1024); + PRINT_TEST_RESULT(ret); + } + +#if 0 + n = 128; + for(i=1; i<=n; i++) { + ret = test_bmm_dma_memcpy(i*4096); + PRINT_TEST_RESULT(ret); + } + + n = 4; + for(i=1; i<=n; i++) { + ret = test_bmm_dma_memcpy(i*1024*1024); + PRINT_TEST_RESULT(ret); + } + + n = 128; + for(i=1; i<=n; i++) { + ret = test_bmm_dma_memcpy_range(i*4096); + PRINT_TEST_RESULT(ret); + } +#endif + n = 1; + ret = test_bmm_flush_user(n*1024*1024); + PRINT_TEST_RESULT(ret); + PRINT_TEST_RESULTS(); + + if(debug) + bmm_dump(); + + bmm_exit(); + + if(debug) + bmm_dump(); + + return 0; +} + diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..d8cbe23 --- /dev/null +++ b/configure.ac @@ -0,0 +1,39 @@ +AC_PREREQ([2.63]) +AC_INIT([libbmm], [1.0.0], [], [libbmm]) +AC_CONFIG_SRCDIR([Makefile.am]) +AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_AUX_DIR([build-aux]) +AM_INIT_AUTOMAKE([1.10 foreign dist-bzip2]) +AM_MAINTAINER_MODE([enable]) + +ABI_VERSION=0u +ABI_REVISION=1 +AC_SUBST(ABI_VERSION) +AC_SUBST(ABI_REVISION) + +# Enable quiet compiles on automake 1.11. +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) + +# Check for programs +AC_PROG_CC + +AC_USE_SYSTEM_EXTENSIONS + +# Initialize libtool +LT_PREREQ([2.2]) +LT_INIT + +pkgconfigdir=${libdir}/pkgconfig +AC_SUBST(pkgconfigdir) + +udevrulesdir=/lib/udev/rules.d +AC_SUBST(udevrulesdir) + +initdir=${sysconfdir}/init.d +AC_SUBST(initdir) + +AC_CONFIG_FILES([ + Makefile + libbmm.pc +]) +AC_OUTPUT diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..761bb02 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,64 @@ +marvell-libbmm (0.2.0-0ubuntu1~ppa8.rmk1) precise; urgency=low + + * Convert to autotools + + -- Russell King Sun, 21 Oct 2012 14:39:54 +0100 + +marvell-libbmm (0.2.0-0ubuntu1~ppa8) karmic; urgency=low + + * Add symbol bmm_flush_user in libbmm0u.symbols + + -- jun Sat, 05 Mar 2011 01:39:06 +0800 + +marvell-libbmm (0.2.0-0ubuntu1~ppa7) lucid; urgency=low + + * Support HIGHMEM in module + + -- Li Li Sat, 04 Sep 2010 14:02:54 +0800 + +marvell-libbmm (0.2.0-0ubuntu1~ppa6) lucid; urgency=low + + * Import code to LP/BZR lp:~adana-team/adana/marvell-libbmm + + -- Li Li Wed, 28 Jul 2010 11:34:33 +0800 + +marvell-libbmm (0.2.0-0ubuntu1~ppa5) lucid; urgency=low + + * Fix ioctl magic number + * Fix incompatible obsolete attributes + + -- Li Li Fri, 04 Jun 2010 15:21:44 +0800 + +marvell-libbmm (0.2.0-0ubuntu1~ppa4) lucid; urgency=low + + * Properly fix udev rule installation so bmm gets proper permissions + + -- Michael Casadevall Fri, 26 Mar 2010 14:00:53 -0400 + +marvell-libbmm (0.2.0-0ubuntu1~ppa3) lucid; urgency=low + + * Fix init.d scripts to properly install and remove. + + -- Michael Casadevall Thu, 25 Mar 2010 13:06:43 -0400 + +marvell-libbmm (0.2.0-0ubuntu1~ppa2) lucid; urgency=low + + * versionify soname - we are at libbmm.so.0u.1 now + + change binary package to libbmm0u and libbmm-dev + + fix depends of -dev package in control + + add API_VERSION and API_REVISION variables to Makefile_general + + produce proper versioned soname lib and links using API_VERSION + and API_REVISION from above in Makefile_general + + install _all_ libbmm.so* in the libbmm0u package as we need the + unversioned .so link for compatibility reasons with legacy upstream + dependencies that look for that soname + + use libbmm0u.symbols file to track API/ABI; use -c4 for + dpkg-gensymbols to fail if symbols are out of sync + + -- Alexander Sack Sun, 21 Mar 2010 03:13:12 +0100 + +marvell-libbmm (0.2.0-0ubuntu1~ppa1) lucid; urgency=low + + * Initial Release (LP: #XXXXXX) + + -- Michael Casadevall Thu, 18 Mar 2010 12:40:16 -0400 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +7 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..6d0eabd --- /dev/null +++ b/debian/control @@ -0,0 +1,35 @@ +Source: marvell-libbmm +Priority: extra +Maintainer: Michael Casadevall +XSBC-Original-Maintainer: Li Li +Build-Depends: debhelper (>= 7) +Standards-Version: 3.9.1 +Section: libs +Vcs-Bzr: https://code.launchpad.net/~adana-team/adana/marvell-libbmm + +Package: libbmm-dev +Section: libdevel +Architecture: armel armhf +Depends: libbmm0u (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} +Description: Block/buffer memory management + Header files, static library and unit test case for BMM + +Package: libbmm0u +Section: libs +Architecture: armel armhf +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: Block/buffer memory management + Allocate, manage and share large block of physical continuous memory + +Package: libbmm0u-dbg +Section: debug +Priority: extra +Architecture: linux-any +Depends: + libbmm0u (= ${binary:Version}), + ${misc:Depends}, + ${shlibs:Depends}, +Multi-Arch: same +Description: Block/buffer memory management + . + This package provides debugging symbols for the libbmm0u package. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..525a0de --- /dev/null +++ b/debian/copyright @@ -0,0 +1,26 @@ +This package was debianized by Lea Li on +Tue, 01 Sep 2009 12:22:13 +0800. + +Upstream Author(s): + + Zhangfei Gao + +Copyright: + + + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see . */ + +On Debian systems, the complete text of the GNU Lesser General Public License +can be found in `/usr/share/common-licenses/LGPL-2.1'. + diff --git a/debian/libbmm-dev.install b/debian/libbmm-dev.install new file mode 100644 index 0000000..417c3c1 --- /dev/null +++ b/debian/libbmm-dev.install @@ -0,0 +1,4 @@ +debian/tmp/usr/include/*.h +debian/tmp/usr/lib/*.a +debian/tmp/usr/lib/pkgconfig/*.pc +debian/tmp/usr/bin/bmm_test diff --git a/debian/libbmm0u.install b/debian/libbmm0u.install new file mode 100644 index 0000000..00c88de --- /dev/null +++ b/debian/libbmm0u.install @@ -0,0 +1,3 @@ +debian/tmp/etc/init.d/bmm +debian/tmp/lib/udev/rules.d +debian/tmp/usr/lib/*.so* diff --git a/debian/libbmm0u.postinst b/debian/libbmm0u.postinst new file mode 100644 index 0000000..327c102 --- /dev/null +++ b/debian/libbmm0u.postinst @@ -0,0 +1,46 @@ +#!/bin/sh +# postinst script for #PACKAGE# +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `configure' +# * `abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-remove' +# * `abort-deconfigure' `in-favour' +# `removing' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + configure) + if [ -x /etc/init.d/bmm ]; then + update-rc.d bmm defaults >/dev/null + fi + + if [ -x /usr/sbin/invoke-rc.d ] ; then + invoke-rc.d bmm start || true + fi + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/libbmm0u.postinst.debhelper b/debian/libbmm0u.postinst.debhelper new file mode 100644 index 0000000..3d89d3e --- /dev/null +++ b/debian/libbmm0u.postinst.debhelper @@ -0,0 +1,5 @@ +# Automatically added by dh_makeshlibs +if [ "$1" = "configure" ]; then + ldconfig +fi +# End automatically added section diff --git a/debian/libbmm0u.postrm b/debian/libbmm0u.postrm new file mode 100644 index 0000000..a0a15df --- /dev/null +++ b/debian/libbmm0u.postrm @@ -0,0 +1,38 @@ +#!/bin/sh +# postrm script for #PACKAGE# +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `remove' +# * `purge' +# * `upgrade' +# * `failed-upgrade' +# * `abort-install' +# * `abort-install' +# * `abort-upgrade' +# * `disappear' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + update-rc.d -f bmm remove >/dev/null + ;; + + *) + echo "postrm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/debian/libbmm0u.postrm.debhelper b/debian/libbmm0u.postrm.debhelper new file mode 100644 index 0000000..7f44047 --- /dev/null +++ b/debian/libbmm0u.postrm.debhelper @@ -0,0 +1,5 @@ +# Automatically added by dh_makeshlibs +if [ "$1" = "remove" ]; then + ldconfig +fi +# End automatically added section diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..87cc2ca --- /dev/null +++ b/debian/rules @@ -0,0 +1,34 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +# Debian build system is horrid - hack around it to ensure that the autoconf +# stuff is properly up to date +build: configure Makefile.in + +Makefile.in: Makefile.am + ./autogen.sh + +configure: autogen.sh configure.ac + ./autogen.sh + +override_dh_auto_install: + dh_auto_install --destdir=debian/tmp + +override_dh_install: + find debian/tmp -name '*.la' -delete + dh_install --fail-missing + +override_dh_strip: + dh_strip -plibbmm0u --dbg-package=libbmm0u-dbg + dh_strip -s --remaining-packages + +%: + dh $@ diff --git a/etc/init.d/bmm b/etc/init.d/bmm new file mode 100755 index 0000000..65777e6 --- /dev/null +++ b/etc/init.d/bmm @@ -0,0 +1,49 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: bmm +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Loads the bmm_drv on dove +# Description: This is required for libbmm and HW acclerated codecs +### END INIT INFO + +# Minimal initscript for modprobing bmm_drv + +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin +NAME=bmm + +set -e + + +#!/bin/sh +if [ -f /lib/modules/bmm.ko ]; then + insmod /lib/modules/bmm.ko bmm_size_mb=96 +else + #bmm_drv in Dove kernel is a bit different + modprobe bmm_drv bmm_size_mb=96 +fi + +case "$1" in + start) + ;; + stop) + ;; + force-stop) + ;; + force-reload) + ;; + restart) + ;; + status) + ;; + *) + N=/etc/init.d/$NAME + # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2 + echo "Usage: $N {start|stop|restart|force-reload|status|force-stop}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/etc/udev/rules.d/99-bmm.rules b/etc/udev/rules.d/99-bmm.rules new file mode 100644 index 0000000..0278802 --- /dev/null +++ b/etc/udev/rules.d/99-bmm.rules @@ -0,0 +1 @@ +KERNEL=="bmm|bmm[0-9]", MODE="0666" diff --git a/libbmm.pc.in b/libbmm.pc.in new file mode 100644 index 0000000..a0fbb33 --- /dev/null +++ b/libbmm.pc.in @@ -0,0 +1,9 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libbmm +Description: Buffer Management Library +Version: @PACKAGE_VERSION@ +Libs: -L${libdir} -lbmm -- cgit